|
Post by honkytonk on May 3, 2020 11:48:35 GMT
Good morning all. Look at this:
NOMAINWIN WindowWidth = 600: WindowHeight = 400 UpperLeftX = 10: UpperLeftY = 20 GRAPHICBOX #w.m 5, 5, 585, 360 OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.m, "when leftButtonDown [dow]" #w.m, "when leftButtonUp [up]" #w.m "down;fill darkgreen" wait [dow] playwave, "son.wav",async wait [up] playwave, "" wait [closeHelp] CLOSE #w
"son.wav" is 30 seconds of 440 hertz sine. The minimum time between two tops is: +/- 0.5 seconds (recovery of the "hand" by the program) Question: Is there a way to be more responsive? Thank you for.
|
|
|
Post by Rod on May 3, 2020 12:44:36 GMT
I am not sure I understand the problem yet. On my machine your code can play a tone and stop it within 100ms As soon as I hear the tone and lift off it stops, consistently within 100ms or so. Is it the restart time that is the problem? If it is the length of the file that is causing the problem you might consider looping a very short, say 100ms tone sample. You have to build the tone carefully so that it rolls round quietly and does not have an end of file click. So the sine should start and finish, make the length just long enough to allow that.
But I may not be addressing the correct problem.
|
|
|
Post by honkytonk on May 3, 2020 12:50:23 GMT
Is the restart time (0,5s minimum) Which prohibits fast tops sequence.
|
|
|
Playwave
May 3, 2020 13:10:59 GMT
via mobile
Post by Rod on May 3, 2020 13:10:59 GMT
On Liberty you could leave the tone playing and just change the volume. It’s an API call.
|
|
|
Post by honkytonk on May 3, 2020 13:30:20 GMT
On Liberty you could leave the tone playing and just change the volume. It’s an API call. Ok, i will try with midi and Pause (break).
|
|
|
Playwave
May 3, 2020 13:52:07 GMT
via mobile
Post by Rod on May 3, 2020 13:52:07 GMT
Midi has a few latency issues but it might be a quick fix. I was just thinking of looping a .wav and setting the volume to zero when you want silence.
|
|
|
Post by honkytonk on May 3, 2020 15:03:32 GMT
Midi has a few latency issues but it might be a quick fix. I was just thinking of looping a .wav and setting the volume to zero when you want silence. But how to set the volume of a wav to zero? EDIT: I'm trying to do a morse manipulator for training
|
|
|
Post by Rod on May 3, 2020 19:27:10 GMT
Hmm, I have seen plenty morse trainers that output well timed morse, see diga.me . What I have seen less of is morse key input programs. Probably because of the issues you are finding. Windows interferes, mouse click timing interferes and sound output latency interferes. I am not sure clicking a mouse will ever be like clicking a morse key.
Are you just trying to check the rhythm and timing? Perhaps you just need to check the timing while they follow a well timed morse phrase?
|
|
|
Post by Rod on May 3, 2020 19:35:38 GMT
I also see that some folks use left click to play a dot.wav and right click to play a dash.wav So the tone is not 30s long it is precisely the length of a dot tone and the dash is precisely the length of a dash tone so there is much less to do, play one or the other. Depends on what your training goal is.
|
|
|
Post by honkytonk on May 4, 2020 0:03:26 GMT
I tried this, with: "p.wav" = 250ms; "T.wav" = 750ms), it works well but the problem is the same: Ready time to is too long "Morse.bmp" is morse code image from Wikipédia (put " ' " for go on). The beeps work if we are not in a hurry
NOMAINWIN WindowWidth = 900: WindowHeight = 520 UpperLeftX = 10: UpperLeftY = 10 TEXTBOX #w.point, 75 , 20, 60, 25 TEXTBOX #w.trait, 75 , 60, 60, 25 TEXTBOX #w.sil, 75 , 100, 60, 25 BUTTON #w.txt, "Texte", [texte], UL, 145, 20, 50, 20 TEXTEDITOR #w.te, 400, 335, 450, 120 GRAPHICBOX #w.m 5, 5, 885, 460 OPEN "Morse" FOR window_nf AS #w #w, "TRAPCLOSE [closemorse]" #w.m, "when leftButtonDown [dow]" #w.m, "when leftButtonUp [up]" #w.m, "when rightButtonDown [esp]" #w.m, "down;fill black;color white;backcolor black" #w.m, "size 3" #w.point, "!font courrier 10 bold": #w.trait, "!font courrier 10 bold" #w.sil, "!font courrier 10 bold": #w.txt, "!font courrier 10 bold" #w.te, "!font courrier 10 bold" loadbmp, "morse","morse.bmp": #w.m, "drawbmp morse 5 140" #w.m, "place 10 33": #w.m, "\ point: ": #w.m, "place 10 73": #w.m, "\ Trait: " #w.m, "place 10 113": #w.m, "\ Silence: " point$="250ms": trait$="750ms": sil$="1750ms": #w.point, point$: #w.trait, trait$: #w.sil, sil$ x=300: y=30: xp=345: yp=130: c$="" wait [dow] ta=time$("milliseconds") wait [up] tb=time$("milliseconds") t=tb-ta if t >120 and t < 300 then [point] if t >300 and t < 800 then [trait]
wait [point] playwave, "P.wav",async '(250ms) c$=c$+"p": pt$=str$(t) gosub [printe] wait [trait] playwave, "T.wav",async '(750ms) c$=c$+"t": pt$=str$(t) gosub [printe] wait [printe] yp=yp+20 if yp > 440 then #w.m, "color black" 'black #w.m, "place 345 120": #w.m, "boxfilled 380 450" #w.m, "color white":yp=140 end if #w.m, "place ";xp;" ";yp: #w.m, "\ "; pt$ return wait [esp] c$=c$+" ": pt$="---": gosub [printe] wait [texte] mm$="" for x=1 to len(c$) m$=word$(c$,x) select case m$ case "pt" mm$=mm$+"a" case "tppp" mm$=mm$+"b" case "tptp" mm$=mm$+"c" case "tpp" mm$=mm$+"d" case "p" mm$=mm$+"e" case "pptp" mm$=mm$+"f" case "ttp" mm$=mm$+"g" case "pppp" mm$=mm$+"h" case "pp" mm$=mm$+"i" case "pttt" mm$=mm$+"j" case "tpt" mm$=mm$+"k" case "ptpp" mm$=mm$+"l" case "tt" mm$=mm$+"m" case "tp" mm$=mm$+"n" case "ttt" mm$=mm$+"o" case "pttp" mm$=mm$+"p" case "ttpt" mm$=mm$+"q" case "ptp" mm$=mm$+"r" case "ppp" mm$=mm$+"s" case "t" mm$=mm$+"t" case "ppt" mm$=mm$+"u" case "pppt" mm$=mm$+"v" case "ptt" mm$=mm$+"w" case "tppt" mm$=mm$+"x" case "tptt" mm$=mm$+"y" case "ttpp" mm$=mm$+"z" end select next x #w.te, mm$ wait [pause] 'bloc à mettre où tu veux puisqu'indépendant timer 1, [temps] 'pause en millisecondes wait [temps] timer 0 return [closemorse] unloadbmp, "morse" CLOSE #w END
|
|
|
Post by Rod on May 4, 2020 11:35:05 GMT
This seems to work but you need Liberty BASIC. Also you should note that if you leave the volume set low it will be remembered by Windows. So you must turn it back on when you close the program else you will think your audio is broken, nothing will ever play in Liberty till you open winmm and set it back on.
'open the winmm.dll open "winmm.dll" for dll as #winmm
playwave "son.wav",loop
[keyCheck] if keyState(27)>0 then goto [quit] if keyState(32) >0 then nul=stereo(100,100) if keyState(32) =0 then nul=stereo(0,0) goto [keyCheck]
[quit] playwave "" nul=stereo(100,100) close #winmm print "program ended" end
function keyState(keycode) calldll #user32, "GetAsyncKeyState", _ keycode AS long, _ keyState AS long end function
function stereo(left,right)'set left or right 0 - 100 % left=int(left*655.35) right=int(right*655.35) dwVol=right*65536+left calldll #winmm, "waveOutSetVolume", 0 as long, _ dwVol as long, stereo as long end function
|
|
|
Post by honkytonk on May 4, 2020 16:44:32 GMT
Thank for your code. I stay with Just Basic so that the programs remain accessible to beginners, who generally do not have Liberty.
The latency is not the result of "playwav", it is the event mouse; because I added an option without the sound and the latency persists.
Keyboard is latency free but I can't detect the key up.
|
|
|
Post by Rod on May 4, 2020 19:16:08 GMT
Well some keys issue an event when they are pressed AND when they are released. However we are stretching and stretching. Play with the inkey example that ships with Just BASIC and start looking for the second event. Whether it can toggle a .wav fast enough is questionable.
'INKEY.BAS - how to use the Inkey$ variable open "Inkey$ example" for graphics as #graph #graph, "when characterInput [fetch]" #graph, "setfocus" wait
[fetch] 'a character was typed! key$ = Inkey$ if len(key$)=1 then print "Inkey$ length = ";len(key$);" "; print "ASC value = ";asc(key$);" "; print "Glyph character is ";key$ end if if len(key$)=2 then print "Inkey$ length = ";len(key$);" "; print "First ASC value = ";asc(left$(key$,1));" "; print "Second ASC value = ";asc(right$(key$,1)) if key$=chr$(0)+chr$(16) then print "Shift released" end if wait
|
|
|
Post by honkytonk on May 4, 2020 21:06:57 GMT
This code starts the sound but does not stop it. Because the key lift is not detected, as shown by the elapsed times (noted: ' <----) And tb value We'd have to find a trick to detect the key lift (I did a billion tests.)
'INKEY.BAS - how to use the Inkey$ variable open "Inkey$ example" for graphics as #graph #graph, "when characterInput [fetch]" #graph, "setfocus" wait
[fetch] 'a character was typed! ta=time$("milliseconds") ' <------- key$ = Inkey$ if len(key$)=1 then print "Inkey$ length = ";len(key$);" "; print "ASC value = ";asc(key$);" "; print "Glyph character is ";key$ playwave, "son.wav",async '(30 seconds) end if if len(key$)=2 then print "Inkey$ length = ";len(key$);" "; print "First ASC value = ";asc(left$(key$,1));" "; print "Second ASC value = ";asc(right$(key$,1)) if key$=chr$(0)+chr$(16) then print "Shift released" tb=time$("milliseconds") ' <----- playwave, "" end if end if t =tb-ta print "tb: ";tb;" ta: ";ta;" t: ";t wait
|
|
|
Post by Rod on May 5, 2020 10:34:48 GMT
Ok, I changed the key to the Ctrl key on my PC because the Shift key kept trying to start up Sticky Keys after the fifth press. The Ctrl key seems to be a better option, you could probably use the space bar too. This works for me but I don't know if it is fast enough for you.
'INKEY.BAS - how to use the Inkey$ variable open "Inkey$ example" for graphics as #graph #graph, "when characterInput [fetch]" #graph, "setfocus" wait
[fetch] 'a character was typed!
key$ = Inkey$ if key$=chr$(8)+chr$(17) then playwave "son.wav",async if key$=chr$(0)+chr$(17) then playwave "" wait
|
|