|
Post by Rod on May 4, 2020 6:43:59 GMT -5
This is in response to a question on another forum. It was about using the keyboard or mouse to output morse code. The problem was latency. Re running a .wav file took time. This just leaves the .wav running and blips the volume on and off.
I post it here because it uses API and also I discovered that if you use winmm and waveOutSetVol() Windows remembers the volume setting even after the program ends. So you can switch off your audio forever, inadvertently. The trick is to set it back on before you close. Ideally you should use waveOutGetVol() to record the current volume on startup and leave it that way on exit.
But I think the morse works well. son.wav is just a 440hz tone that loops. Press Space bar to output morse, press Esc to quit. No latency, or very little.
'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 svajoklis on May 4, 2020 7:24:55 GMT -5
It would be interesting to define patterns for different letters and have it output those on typing, though you would have to time the keypresses, so that next one comes just after the previous ends.
Or it could buffer text, so for example you start typing text and it immediately (or after some delay) starts outputting morse code from what it finds in the buffer even before you finish typing!
|
|
timur77
Junior Member
Someday I will tell my grandsons that I am older than the Internet. And it will blow their brain.
Posts: 79
|
Post by timur77 on May 4, 2020 12:18:17 GMT -5
I worked with Morse in the service. Last time, we used third-party programs to generate morse code, where we typed text in a window and then started the generation. But the reception was usually carried out by ear due to the presence of interference on the air. Typical oscillation frequency from 1000 to 2000 Hz.
440 Hz, as far as I know, this is "A" of the third octave, rather low for Morse.
|
|
|
Post by honkytonk on May 5, 2020 4:00:57 GMT -5
I worked with Morse in the service. Last time, we used third-party programs to generate morse code, where we typed text in a window and then started the generation. But the reception was usually carried out by ear due to the presence of interference on the air. Typical oscillation frequency from 1000 to 2000 Hz. 440 Hz, as far as I know, this is "A" of the third octave, rather low for Morse. The carrier frequency of the sound signal is unimportant, since it can transmit in Morse code with light or only silences (knock and short silence knock and long silence).
|
|
|
Post by Rod on May 5, 2020 5:42:01 GMT -5
Much simpler solution found by tracking the key press and key release events. This tracks the Ctrl key.
'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
|
|
|
Post by svajoklis on May 5, 2020 6:31:57 GMT -5
|
|