Post by Rod on Aug 18, 2022 11:01:53 GMT -5
This popped up on our other forum. Its all to do with radioactivity and listening to and analysing a Geiger counters output. This code just listens to the mic in mono at 8bit sampling. Just a basic start but amazing how easy it was to get to the sound input.
'experimental Radiometer by rodbird@hotmail.com
'uses MMI to stream audio from Mic
'8bit audio is set for faster parsing
'blips from giger counter are heard but
'need parsed, recorded and displayed
'currently samples at 50ms
nomainwin
WindowWidth = 450
WindowHeight = 130
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
graphicbox #1.bar, 23, 50, 400, 20
open "Radiometer" for window_nf as #1
#1.bar "down; fill white; flush"
#1.bar "backcolor green"
#1 "trapclose [quit]"
[startRecording]
'set the .wav recording format
bitspersample = 8
channels = 1
samplespersec = 8000
alignment = bitspersample * channels / 8
bytespersec = alignment * samplespersec
params$ = " bitspersample " + STR$(bitspersample)+_
" channels " + STR$(channels) +_
" alignment " + STR$(alignment) + _
" samplespersec " + STR$(samplespersec) + _
" bytespersec " + STR$(bytespersec)
'open wav audio to listen to the wavaudio
r$=mciSendString$("open new type waveaudio alias wav")
r$=mciSendString$("set wav "+params$)
timer 50, [readVolume]
wait
[readVolume]
#1.bar "discard ; backcolor white"
#1.bar "boxfilled 400 25 ; backcolor green"
r$=mciSendString$("status wav level")
level = val(r$)
'print level
#1.bar "boxfilled ";level;" 20; discard"
wait
[quit] 'End the program
timer 0
r$=mciSendString$("close wav")
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