|
Post by honkytonk on Aug 15, 2022 9:00:59 GMT
Hello everyone, I would like to record clicks, so I did this:
NOMAINWIN mapw=400: maph= 300 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "when leftButtonDown [scanne]" #w.g, "down;fill darkpink;color white;backcolor darkpink" #w.g, "font courrier 15 bold" wait [scanne] tic=tic+1 #w.g, "place 20 80": #w.g, "\ ";str$(tic) ' print tic wait [closeHelp] CLOSE #w END
But as we can see, the mouse click does not detect close clicks (< 500ms). How can close events be detected ? Thank you for.
EDIT: mainwin or nomainwin
|
|
|
Post by tsh73 on Aug 15, 2022 10:15:03 GMT
>>But as we can see, the mouse click does not detect close clicks (< 500ms). no we can't Because you do not output time in ms 'NOMAINWIN mapw=400: maph= 300 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "when leftButtonDown [scanne]" '#w.g, "when leftButtonUp [scanne]" #w.g, "down;fill darkpink;color white;backcolor darkpink" #w.g, "font courrier 15 bold" wait [scanne] tic=tic+1 #w.g, "place 20 80": #w.g, "\ ";str$(tic) lastT=t 'save old time t=time$("ms") 'get new time print t-lastT 'print the diff ' print tic wait [closeHelp] CLOSE #w END
Now we can I see that clicking shows difference about 3xx ms while clicking and simultaneously moving prodices values of 1xx Now, my moused Double click speed in Windows set to middle velue www.google.com/search?q=moused+Double+click+speed+in+WindowsIf I set it Fast I got more 2xx values If I set it Slow I got more 3xx values - actually same as "middle" position (now, just reset to normal where it was before)
|
|
|
Post by tsh73 on Aug 15, 2022 10:20:26 GMT
Now, button in ordinary window reacts with 1xx time
' Form created with the help of Freeform-J v.261006 ' Generated on Aug 15, 2022 at 13:17:57
' nomainwin
WindowWidth = 550 WindowHeight = 410
UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
button #main.button1, "Button Caption", [button1Click], UL, 26, 16, 122, 25 open "untitled" for window as #main print #main, "trapclose [quit.main]"
print #main, "font ms_sans_serif 10"
wait
[quit.main] Close #main END
[button1Click] 'Perform action for the button named 'button1' lastT=t 'save old time t=time$("ms") 'get new time print t-lastT 'print the diff wait wait
|
|
|
Post by honkytonk on Aug 15, 2022 10:49:28 GMT
That's perfect, thank you very much. The goal is to follow the sound and light ticks of a radioactivity detector and count them over a period of time. For information: Natural radioactivity triggers 20 to 22 rounds per minute
|
|
|
Post by tsh73 on Aug 16, 2022 6:20:05 GMT
Then you react on key press, say space, you'll get 1xx minimal time or 32-47 ms then autorepeat turns on ;)
'NOMAINWIN mapw=400: maph= 300 WindowWidth=mapw+15: WindowHeight=maph+40 UpperLeftX = 10: UpperLeftY = 20 GRAPHICBOX #w.g, 5, 5, mapw, maph OPEN "Help" FOR window_nf AS #w #w, "TRAPCLOSE [closeHelp]" #w.g, "when characterInput [scanne]" #w.g, "setfocus" '#w.g, "when leftButtonUp [scanne]" #w.g, "down;fill darkpink;color white;backcolor darkpink" #w.g, "font courrier 15 bold" wait [scanne] tic=tic+1 #w.g, "place 20 80": #w.g, "\ ";str$(tic) lastT=t 'save old time t=time$("ms") 'get new time print t-lastT 'print the diff ' print tic wait [closeHelp] CLOSE #w END
|
|
|
Post by Rod on Aug 16, 2022 6:35:29 GMT
You could record the sounds and later analyse the .wav file.
|
|
|
Post by honkytonk on Aug 16, 2022 6:56:30 GMT
You could record the sounds and later analyse the .wav file. Oh yes, good idea, but can we analyze sound with Jb or LB?
|
|
|
Post by honkytonk on Aug 16, 2022 7:15:19 GMT
@ tsh73: Spacebar works great too, I take both. @ Rod: If you know a way to analyze a ".wav", I'm interested.
|
|
|
Post by Rod on Aug 16, 2022 11:32:50 GMT
Well you can record the sound with any PC based recorder that creates .wav files or you can record it with Liberty using API. The .wav file is just a sequence of bytes defining the amplitude of the sound wave. So you could parse out clicks. But what aspects of the clicks are you interested in. Amplitude, time between, frequency, moving average of frequency of clicks over time? So many aspects to it. If you had a .wav recording to share I am sure you would get help coding analysis.
This is Liberty BASIC code that opens two audio streams from the same source, one to record and one to analyse almost real time. It lets you see the possibilities.
' This reads the mciSendString 'level' status and *** ' display's it in a graphic box. *** ' Feel free to use this code or modify in any way for *** ' your application. *** '************************************************************** 'modified by Rod using code by Richard and Chris to set the audio 'format and read the high and low level response
' nomainwin WindowWidth = 450 WindowHeight = 130 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
graphicbox #1.left, 23, 50, 400, 20 graphicbox #1.right, 23, 75, 400, 20
button #1.button1,"Start recording",[startRecording], UL, 25, 5, 120, 25 button #1.button2,"Stop recording",[stopRecording], UL, 160, 5, 120, 25
open "Vu meter" for window_nf as #1 #1.left "down; fill white; flush" #1.left "backcolor green" #1.right "down; fill white; flush" #1.right "backcolor green" #1 "font ms_sans_serif 10" #1 "trapclose [quit]" wait
[startRecording] 'set the .wav recording format bitspersample = 16 channels = 2 samplespersec = 44100 alignment = bitspersample * channels / 8 bytespersec = alignment * samplespersec
params$ = " bitspersample " + STR$(bitspersample)+_ " channels " + STR$(channels) +_ " alignment " + STR$(alignment) + _ " samplespersec " + STR$(samplespersec) + _ " bytespersec " + STR$(bytespersec)
'we open two devices, one to listen and one to record 'open wav audio to listen to the wavaudio r$=mciSendString$("open new type waveaudio alias wav") r$=mciSendString$("set wav "+params$)
'open myRecording to record sound from mic r$=mciSendString$("open new type waveaudio alias myRecording") r$=mciSendString$("set myRecording "+params$) r$=mciSendString$("record myRecording") 'start the recording
timer 50, [readVolume] wait
[readVolume] #1.left "discard ; backcolor white" #1.left "boxfilled 400 25 ; backcolor green" #1.right "discard ; backcolor white" #1.right "boxfilled 400 25; backcolor green" r$=mciSendString$("status wav level") level = val(r$) left = hiWord(level) right = loWord(level) print left,right n=400/256^2 nl=left*n nr=right*n normLevel = (val(r$) * 400)/128 #1.left "boxfilled ";nl;" 20; discard" #1.right "boxfilled ";nr;" 20; discard" wait
[stopRecording] timer 0 #1.left "fill white ; discard" #1.right "fill white ; discard" r$=mciSendString$("close wav") r$=mciSendString$("close myRecording") goto [waitLoop] wait
[quit] 'End the program timer 0 r$=mciSendString$("close wav") r$=mciSendString$("close myRecording") close #1 end
Function mciSendString$(s$) 'Buffer will contain a return string from 'the function, if there is one. buffer$=space$(1024)+chr$(0) calldll #winmm,"mciSendStringA",s$ as ptr,buffer$ as ptr,_ 1028 as long, 0 as long, r as long 'truncate returned string at null character buffer$=left$(buffer$, instr(buffer$, chr$(0)) - 1) if r>0 then mciSendString$="error" else mciSendString$=buffer$ end if End Function
Function hiWord(num) hiWord = int( num / (256^2)) End Function
Function loWord(num) loWord = num AND hexdec("FFFF") End Function
|
|
|
Post by Rod on Aug 16, 2022 11:40:16 GMT
Some simple code to break open a .wav, get the header info and allow access to the sound data.
filedialog "Open wav file", "*.wav", fileName$ open fileName$ for input as #wav 'the wavfileheader wav$ = Input$(#wav,lof(#wav)) print "ChunkID =";mid$(wav$,1,4) 'always RIFF print "ChunkSize =";value(mid$(wav$,5,4)) print "Format =";mid$(wav$,9,4) print "Sub1ID =";mid$(wav$,13,4) print "Sub1Size =";value(mid$(wav$,17,4)) print "AudioFormat =";value(mid$(wav$,21,2)) print "NumChannels =";value(mid$(wav$,23,2)) print "SampleRate =";value(mid$(wav$,25,4)) print "ByteRate =";value(mid$(wav$,29,4)) print "BlockAlign =";value(mid$(wav$,33,2)) print "bitPerSample=";value(mid$(wav$,35,2)) print "Sub2ID =";mid$(wav$,37,4) print "Sub2Size =";value(mid$(wav$,41,4)) print print "Sound Data" for n= 0 to 20 print value(mid$(wav$,45+n,1)) next wait
function value(x$) select case len(x$) case 1 value = asc(x$) case 2 value=asc(mid$(x$,1,1)) value=value+(asc(mid$(x$,2,1))*256) case 4 value=asc(mid$(x$,1,1)) value=value+(asc(mid$(x$,2,1))*256) value=value+(asc(mid$(x$,3,1))*65536) value=value+(asc(mid$(x$,4,1))*16777216) end select end function
|
|
|
Post by honkytonk on Aug 16, 2022 17:00:58 GMT
Thanks Rod, I will study your codes I put an example wav there--->: libertybasic.fr/upload/the-wave.zipI think that by better locating the beeper the sound (volume) should be better
|
|
|
Post by tenochtitlanuk on Aug 16, 2022 19:17:43 GMT
This looks fun. I'm sure I've an old Geiger tube somewhere- just got to build a circuit for it- or a modern semiconductor sensor! For interest, I tried a 'dog clicker' that makes a click as you push and another when you release... In Linux a one-liner command 'arecord -t wav -d 10 -vv mon2.wav' executed from the terminal records for 10 seconds. Haven't tried calling it or an equivalent from Windows/LB. The resulting file ran as input to my LB audio analyser on diga.me.uk . Liberty BASIC allows 'calldll' and other helpful additions. Do you look at the LB forum as well as the JB one?
|
|
|
Post by marshawn on Aug 16, 2022 19:33:15 GMT
can you draw and also play that pictured wave (or any other arbitrary wave) in JB? that would be neat
|
|
|
Post by Rod on Aug 16, 2022 20:24:53 GMT
There are so many possibilities, yes we can draw, yes we can analyse but what is it we want to know about the clicks. Amplitude, frequency, over what timescale? how much precision, Microseconds, milliseconds seconds? Or much longer clicks per hour?
What is the goal.
|
|
|
Post by tenochtitlanuk on Aug 16, 2022 20:28:01 GMT
I added about 10 lines to Rod's wave analysis program. ( I included saving the amplitude as a csv file- which loads into a spreadsheet, but the OpenOffice spreadsheet was very slow in displaying this long file. Bit of a dead end) You certainly need to average the bursts of sound- I used calculating absolute values and averaging each new value with the three previous ones. This show the +/- waves made unidirectional with 'abs('. .. and this show the smoothed result which is now easier to analyse.
|
|