Author Topic: play command on linux doing weird thing on qb64 1.15  (Read 3712 times)

0 Members and 1 Guest are viewing this topic.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
play command on linux doing weird thing on qb64 1.15
« on: June 22, 2021, 05:02:14 am »
just a question:

on qb64 1.15 linux i have got a little routine as below

x=0
do
play a$(x),b$(x)
x=x+1
if x>719 then x=0
while inkey$="" loop
end

when i press a key it exits like it should but the problem with this it continues to play the two voice music on my pc speaker

i want it to imediatly stop play though. it buffers the music but i dont want it play when i press the key as this is my title screen music.

i want it to play two notes then check key. if key pressed then exit loop. stop playing else loop play next two notes
_delay does not fix

thank you for any advice.
MackyWhite

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: play command on linux doing weird thing on qb64 1.15
« Reply #1 on: June 22, 2021, 07:38:03 am »
Can you post enough of the actual code and put it in a code block?
Shuwatch!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: play command on linux doing weird thing on qb64 1.15
« Reply #2 on: June 22, 2021, 07:50:25 am »
just a question:

on qb64 1.15 linux i have got a little routine as below

x=0
do
play a$(x),b$(x)
x=x+1
if x>719 then x=0
while inkey$="" loop
end

when i press a key it exits like it should but the problem with this it continues to play the two voice music on my pc speaker

i want it to imediatly stop play though. it buffers the music but i dont want it play when i press the key as this is my title screen music.

i want it to play two notes then check key. if key pressed then exit loop. stop playing else loop play next two notes
_delay does not fix

thank you for any advice.

How about playing a note or 2 of the string, and if key isn't pressed on loop around then play some more...
continue until a key is pressed.

BTW, your code isn't even showing you polling for keypress???

Try

do
     k$ = inkey$
    'play some stuff
loop until len(k$)

« Last Edit: June 22, 2021, 07:54:15 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: play command on linux doing weird thing on qb64 1.15
« Reply #3 on: June 22, 2021, 08:41:13 am »
Kid tested and approved:
Code: QB64: [Select]
  1. Cls: Print "Frosty the Snow Man"
  2. pp = 1
  3. P$ = "t140o2p4g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."
  4. P$ = P$ + "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4f4g2."
  5. P$ = P$ + "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2."
  6. P$ = P$ + "g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."
  7. P$ = P$ + "c4a4a4o3c4c4o2b4a4g4e4f4a4g4f4e2."
  8. P$ = P$ + "e8e8d4d4g4g4b4b4o3d4d8o2b8o3d4c4o2b4a4g4p4"
  9. P$ = P$ + "g2g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g8g2."
  10. P$ = P$ + "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2.p4"
  11.     k$ = InKey$
  12.     b$ = Mid$(P$, pp, 1)
  13.     pp = pp + 1
  14.     While InStr("0123456789", Mid$(P$, pp, 1)) And pp <= Len(P$)
  15.         b$ = b$ + Mid$(P$, pp, 1)
  16.         pp = pp + 1
  17.     Wend
  18.     Print b$
  19.     If b$ <> "." Then Play b$
  20.  
  21.  
  22.     If pp > Len(P$) Then pp = 1
  23.  
  24.  

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: play command on linux doing weird thing on qb64 1.15
« Reply #4 on: June 22, 2021, 08:59:36 am »
i will post the code block tomorrow.

its pretty much a

get file with music data

open "musicdatavoice one",into music1$(): open "musicdatavoice two"into music2$()

all data is "o? n" for both

stored in music1$(i) and music2$(i)

i then have a loop

n = current position of note in music1 and music2

loop begin
play music1$(n),music2$(n)
check if key pressed. key pressed so end
if not n=n+1 but if n=719 n=1
goto loop begin

either way i will paste my code tomorrow.

play "MB AND MF" the same in qb64. both play as background.... needs to be played in foreground so stops when key is pressed

but the music continues to play... music should stop


i am playing tune as polysynth not mono. works great except for not stop playing when key pressed

all music is playing in background. no foreground. (need foreground) not buffered.
MackyWhite

FellippeHeitor

  • Guest
Re: play command on linux doing weird thing on qb64 1.15
« Reply #5 on: June 22, 2021, 09:18:05 am »
The way PLAY, BEEP, SOUND, _SNDRAW, or any sound command really, are implemented, is that they push data into a sound buffer that gets output to the sound card. The only way to stop a PLAY/SOUND buffer is by letting it end or by actually closing your program with SYSTEM.

If you use sound files (open with _SNDOPEN, played with _SNDPLAY, etc) - you can use _SNDPAUSE and _SNDSTOP commands.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: play command on linux doing weird thing on qb64 1.15
« Reply #6 on: June 23, 2021, 08:54:39 am »
Dim musicdata$(113): Open "voice1data" For Input As #1: Open "voice2data" For Input As #2: musicdata$(0) = "l10"
For i = 1 To 113: Input #1, v1$: Input #2, v2$: musicdata$(i) = v1$ + "," + v2$: Next i: Close #2: Close #1




Do
    For i = 0 To 113
        Play musicdata$(i)
    Next i
Loop While InKey$ = ""




how do i only get the buffer to play the notes one by one with the keyboard being read so once the keyboard press the key it stops. this is a title music....
MackyWhite

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: play command on linux doing weird thing on qb64 1.15
« Reply #7 on: June 24, 2021, 12:22:56 am »
@bplus

When I play your code, after the first verse and going into the chorus, it gets too fast and un-intelligible.

Does the music commands allow for different note durations? (Such as quarter, half, whole notes? How about metrics like 4/4, 3/4 or 6/8?)
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: play command on linux doing weird thing on qb64 1.15
« Reply #8 on: June 24, 2021, 07:01:06 am »
@bplus

When I play your code, after the first verse and going into the chorus, it gets too fast and un-intelligible.

Does the music commands allow for different note durations? (Such as quarter, half, whole notes? How about metrics like 4/4, 3/4 or 6/8?)

I don't know George about your system, I am on Windows 10 with stable QB64 v1.5 and it plays regular for minutes until I press a key and then it stops.

BTW this is modified from Wiki Play example so that it plays single notes but they are held for different times like whole notes, half notes, quarter...

Here I stuck in a _Limit you can slow it down all you like
Code: QB64: [Select]
  1. Cls: Print "Frosty the Snow Man"
  2. pp = 1
  3. P$ = "t140o2p4g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."
  4. P$ = P$ + "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4f4g2."
  5. P$ = P$ + "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2."
  6. P$ = P$ + "g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g2."
  7. P$ = P$ + "c4a4a4o3c4c4o2b4a4g4e4f4a4g4f4e2."
  8. P$ = P$ + "e8e8d4d4g4g4b4b4o3d4d8o2b8o3d4c4o2b4a4g4p4"
  9. P$ = P$ + "g2g2e4.f8g4o3c2o2b8o3c8d4c4o2b4a8g8g2."
  10. P$ = P$ + "o2b8o3c8d4c4o2b4a8a8g8o3c4o2e8e4g8a8g4f4e4d4c2.p4"
  11.     k$ = InKey$
  12.     b$ = Mid$(P$, pp, 1)
  13.     pp = pp + 1
  14.     While InStr("0123456789", Mid$(P$, pp, 1)) And pp <= Len(P$)
  15.         b$ = b$ + Mid$(P$, pp, 1)
  16.         pp = pp + 1
  17.     Wend
  18.     Print b$
  19.     If b$ <> "." Then Play b$
  20.     If pp > Len(P$) Then pp = 1
  21.     _Limit 6
  22.  

Maybe a problem with Linux version of Play, I know it handles timing different than Windows from past problems reported by johnno56.
« Last Edit: June 24, 2021, 07:14:55 am by bplus »

Offline George McGinn

  • Global Moderator
  • Forum Regular
  • Posts: 210
    • View Profile
    • Resume
Re: play command on linux doing weird thing on qb64 1.15
« Reply #9 on: June 24, 2021, 03:50:36 pm »
@bplus I could very well be my system, either Linux or my Dell or both!
____________________________________________________________________
George McGinn
Theoretical/Applied Computer Scientist
Member: IEEE, IEEE Computer Society
Technical Council on Software Engineering
IEEE Standards Association
American Association for the Advancement of Science (AAAS)

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: play command on linux doing weird thing on qb64 1.15
« Reply #10 on: June 24, 2021, 04:19:18 pm »
It was such a pleasant surprise to be greeted by the mechanical version of Frosty at 6:15am... Worked almost a well as my coffee... I am now fully awake... lol
Logic is the beginning of wisdom.