QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: thelowerrhythm on June 05, 2020, 06:21:16 pm
-
Beginner here, messing around with this simple sequencer. I first posted about not being able to get the sound to stop at the end (after key press), and I *sort of* figured that out. However, it only works when the cycle rate (variable R) is high (slow) enough. For example, it works as intended when cycle rate is 8, but not when .1.
2 PRINT "±±±±± ²²²²²² °°°°°°" 4 PRINT "±±±±± ² ² °°°°°°" 6 PRINT "±±±±± ²²²²²² °°°°°°" PRINT "8 step waveform generator for toned sequences" PRINT "or drones at faster speeds (lower cycle)." PRINT "Input frequencies in Hz from 40 - 16000." PRINT "Press any key to stop sequence."
INPUT "CYCLE RATE(.023+): ", R
PRINT "Generating Tone A" PRINT "Generating Tone B" PRINT "Generating Tone C" PRINT "Generating Tone D" PRINT "Generating Tone E" PRINT "Generating Tone F" PRINT "Generating Tone G" PRINT "Generating Tone H"
X = 1
INPUT "Enter Q / q to EXIT, anything else to RESTART: ", I$
-
I am no musician or an expert in using QB64, but my first guesses would be... Your DO..LOOP is continuously queuing sound commands and when you press a key, "Hey! Get to the end of the queue." and when the sounds are finished playing, the loop ends. That's what happened on my machine. As to a solution... I may not be the best choice to ask... No. That's not correct. I 'am not' the best person to ask.
Here is a link to Terry's "simple" piano... (I would hate to see a complicated one... lol) https://www.qb64.org/forum/index.php?topic=2537.msg117793#msg117793
Based on Terry's experience with sound, I would point you in his direction... I apologise for not be able to be of help.
-
I'm nowhere even near being a novice, so there's that. It's doing what it is supposed to do for you, but it only happens for me at higher cycle rates (=slower sequences). When it's sped up a keypress doesn't end the sound, and when the software restarts its still playing. Not sure why the different cycle speeds would make a difference. Maybe when it's going really fast it isn't pausing to see if its supposed to stop? I don't even know if that makes sense.
-
Hi thelowerrhythm
please say me
1. why do you like spaghetti code versus modular code?
2. do you try to make a flowchart or mindmap of your code to follow the flow? at a first rapid look it seems that you make a chain of SOUNDs statements so you can stop sound at the end of the chain....
3. if you like use the SOUND keyword, have you seen the difference between QB and QB64? https://www.qb64.org/wiki/index.php/SOUND (https://www.qb64.org/wiki/index.php/SOUND)
Good Coding
-
Hi thelowerrhythm
please say me
1. why do you like spaghetti code versus modular code?
2. do you try to make a flowchart or mindmap of your code to follow the flow? at a first rapid look it seems that you make a chain of SOUNDs statements so you can stop sound at the end of the chain....
3. if you like use the SOUND keyword, have you seen the difference between QB and QB64? https://www.qb64.org/wiki/index.php/SOUND (https://www.qb64.org/wiki/index.php/SOUND)
Good Coding
I thought spaghetti too but he is just checking each input before moving to next, not so bad.
Yeah wiki says sound duration is in units of 1/18 of sec as I understood it. So why .023 as lowest accepted, shouldn't it be 1 as Sound cant do any less?
Could put pauses between sounds to hear what is what.
For all this:
INPUT "Enter Q / q to EXIT, anything else to RESTART: ", I$
2 lines:
INPUT "Enter Q / q to EXIT, anything else to RESTART: ", I$
But then you cant say GOTO 666 (twice!) ;-))
-
Try this:
Maybe you ask: Why SOUND output is different than _SNDRAW? Its, because SOUND create stereo output but SNDRAW contains stereo bug.
Now is possible using sound lenght less than 1.
2 PRINT "±±±±± 222222 °°°°°°" 4 PRINT "±±±±± 2 2 °°°°°°" 6 PRINT "±±±±± 222222 °°°°°°" PRINT "8 step waveform generator for toned sequences" PRINT "or drones at faster speeds (lower cycle)." PRINT "Input frequencies in Hz from 40 - 16000." PRINT "Press any key to stop sequence."
INPUT "CYCLE RATE(.023+): ", R
SOUND2 S1, R
PRINT "Generating Tone A" SOUND2 S2, R
PRINT "Generating Tone B" SOUND2 S3, R
PRINT "Generating Tone C" SOUND2 S4, R
PRINT "Generating Tone D" SOUND2 S5, R
PRINT "Generating Tone E" SOUND2 S6, R
PRINT "Generating Tone F" SOUND2 S7, R
PRINT "Generating Tone G" SOUND2 S8, R
PRINT "Generating Tone H"
X = 1
INPUT "Enter Q / q to EXIT, anything else to RESTART: ", I$
l = lenght / 18
u = u + s
plsam = plsam + 1
DO UNTIL _SNDRAWLEN = 0:
LOOP 'comment this row and play in background. BUT, if you call often SNDRAW, is this very memory offensive, therefore is very recomended controlling SNDRAW cache using SNDRAWLEN!
-
@bplus
I thought spaghetti too but he is just checking each input before moving to next, not so bad.
yes so I like SOS trough the lines 6-10
1. but also if thelowerrhythm uses finely the GOTO to creates loops that control data input he has put a first error with GOTO 4 that must be converted into GOTO 1 at first control of input data.
4 PRINT "±±±±± 2 2 °°°°°°" 6 PRINT "±±±±± 222222 °°°°°°" PRINT "8 step waveform generator for toned sequences" PRINT "or drones at faster speeds (lower cycle)." PRINT "Input frequencies in Hz from 40 - 16000." PRINT "Press any key to stop sequence."
2. But the user cannot stop the cycle of input data... better to use a default value if user mystype the value...
I hate how INPUT going to head of line letting shift to up the screen output
3. the single chain of sounds (sound S1, R....sound R8,R) in the loop cannot be interrupted!
PRINT "Generating Tone A" PRINT "Generating Tone B" PRINT "Generating Tone C" PRINT "Generating Tone D" PRINT "Generating Tone E" PRINT "Generating Tone F" PRINT "Generating Tone G" PRINT "Generating Tone H"
4. pressing a key the sound doesn't stop until the buffer of sound becomes void
in my MOD it is possible if SOUND 0,0 would work fine.
5. all sounds have the same duration of time, so little variation of sound generated
6. what is it?
it seems this
.... so here my version of this spaghetti program.
NameTone$ = "ABCDEFGH"
2 PRINT "±±±±± ²²²²²² °°°°°°" 4 PRINT "±±±±± ² ² °°°°°°" 6 PRINT "±±±±± ²²²²²² °°°°°°" PRINT "8 step waveform generator for toned sequences" PRINT "or drones at faster speeds (lower cycle)." PRINT "Input frequencies in Hz from 40 - 16000." PRINT "Press any key to stop sequence." IF S
(a
) = 0 THEN S
(a
) = 40 ' user press Enter to use default value INPUT "CYCLE RATE(.023+): ", R
PRINT "Generating Tone " + MID$(NameTone$
, a
, 1) IF a
= 8 THEN a
= 1 'infinite loop SOUND 0, 0 ' this statement doesn't work INPUT "Enter Q / q to EXIT, anything else to RESTART: ", I$
Enjoy Coding Basic
-
@TempodiBasic again an admirable amount of detail analysis but some of your changes strike me as odd too. For instance:
IF S
(a
) = 0 THEN S
(a
) = 40 ' user press Enter to use default value
I think it cruel and unusual punishment to redo all inputs if you make a mistake with one.
Oh wait, I confused line 1 in qb64 code and line 1 in GOTO code, you only go back to just after start of loop.
OK bad example, (mostly... ;)
I do like how you made half a dozen plus variables into one array, no, I love that!
OK what about this line:
SOUND 0, 0 ' this statement doesn't work
Why put it in when you know it doesn't work?
Oh well practice makes perfect.
B+ to both of you :)
Oh I just figured out SOS dahhh... cant see the forest for the trees. bplus getting old, no I never ran the dang code! ;-))
-
@Petr your reply #5 sounds great and looks like drawing keeps going with sound, nice one!
-
Hi Bplus
glad to enjoy you.
but do you must think that this is my spaghetti code... not a modular code :-))
all changes are to shrink the number of line not to save RAM or modularity
I thank you for feedback, so with practice I can improve my coding.
@Petr
great new _SOUND function for QB64 with a third parameter optional "_DONTWAIT" while in default it is _WAIT
this is your prototype at my eyes
CONST P_WAIT
= -1 , P_DONTWAIT
= 0 l = lenght / 18
u = u + s
plsam = plsam + 1
if PWait
then DO UNTIL _SNDRAWLEN = 0:
LOOP 'comment this row and play in background. BUT, if you call often SNDRAW, is this very memory offensive, therefore is very recomended controlling SNDRAW cache using SNDRAWLEN!
here in the original spaghetti code
CONST P_WAIT
= -1, P_DONTWAIT
= 0
2 PRINT "±±±±± 222222 °°°°°°" 4 PRINT "±±±±± 2 2 °°°°°°" 6 PRINT "±±±±± 222222 °°°°°°" PRINT "8 step waveform generator for toned sequences" PRINT "or drones at faster speeds (lower cycle)." PRINT "Input frequencies in Hz from 40 - 16000." PRINT "Press any key to stop sequence."
INPUT "CYCLE RATE(.023+): ", R
SOUND2 S1, R, P_DONTWAIT
PRINT "Generating Tone A" SOUND2 S2, R, P_WAIT
PRINT "Generating Tone B" SOUND2 S3, R, P_DONTWAIT
PRINT "Generating Tone C" SOUND2 S4, R, P_WAIT
PRINT "Generating Tone D" SOUND2 S5, R, P_DONTWAIT
PRINT "Generating Tone E" SOUND2 S6, R, P_WAIT
PRINT "Generating Tone F" SOUND2 S7, R, P_DONTWAIT
PRINT "Generating Tone G" SOUND2 S8, R, P_WAIT
PRINT "Generating Tone H"
X = 1
INPUT "Enter Q / q to EXIT, anything else to RESTART: ", I$
l = lenght / 18
u = u + s
plsam = plsam + 1
IF PWait
THEN DO UNTIL _SNDRAWLEN = 0:
LOOP 'comment this row and play in background. BUT, if you call often SNDRAW, is this very memory offensive, therefore is very recomended controlling SNDRAW cache using SNDRAWLEN!
-
@bplus
nothing is perfect but all is perfectable...
about
OK what about this line:
Code: QB64: [Select]
SOUND 0, 0 ' this statement doesn't work
Why put it in when you know it doesn't work?
it is just to note that for a major backward compatibility to QBasic this point can be adjusted....
so I imagine that someone with C/C++ knowledge not so dusted like mine must open the box of SOUND and see what it can do...
Do who gives me a SVITOL https://cdn.manomano.com/sbloccante-spray-svitol-P-7201249-13997303_1.jpg (https://cdn.manomano.com/sbloccante-spray-svitol-P-7201249-13997303_1.jpg) or WD40 https://it.rs-online.com/web/p/lubrificanti/1247168?cm_mmc=IT-PLA-DS3A-_-google-_-PLA_IT_IT_Pulizia_e_manutenzione_Whoop-_-(IT:Whoop!)+Lubrificanti-_-1247168&matchtype=&pla-333453465826&gclid=CjwKCAjw5vz2BRAtEiwAbcVIL5-Z65gZPbkrVjPGJbFI4I-ABihHCHsBkFZcPY5E37rduthnX_jNBBoCDWcQAvD_BwE&gclsrc=aw.ds (https://it.rs-online.com/web/p/lubrificanti/1247168?cm_mmc=IT-PLA-DS3A-_-google-_-PLA_IT_IT_Pulizia_e_manutenzione_Whoop-_-(IT:Whoop!)+Lubrificanti-_-1247168&matchtype=&pla-333453465826&gclid=CjwKCAjw5vz2BRAtEiwAbcVIL5-Z65gZPbkrVjPGJbFI4I-ABihHCHsBkFZcPY5E37rduthnX_jNBBoCDWcQAvD_BwE&gclsrc=aw.ds)for my C/C++?
-
LOL well I know WD40 works great on locks, never knew about C/C++ code.
Since started study of sound in this thread, I tried an app experimenting with spacing sound out, see SOS program here: https://www.qb64.org/forum/index.php?topic=2692.0
As important as frequency and duration is to sound, so is the spacing between SOUNDs, might try making a tool that includes spacing with the 2 given parameters.