Post by Rod on Sept 22, 2018 6:56:27 GMT -5
I also found this in my archives, its a vu meter using mcisendstring.
'**************************************************************
' Hank Doyle October, 2010
' VU meter for reading audio inputs from the sound card ***
' 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)
'log scale
nl = 116 * log(left + 1) - 800
nr = 116 * log(right + 1) - 800
'record high for persistence
'and lower it slowly
nlh=nlh-10
if nl>nlh then nlh=nl
nrh=nrh-10
if nr>nrh then nrh=nr
'display green for exact reading
'display yellow for historic high
#1.left "backcolor yellow ; boxfilled ";nlh;" 20"
#1.right "backcolor yellow ; boxfilled ";nrh;" 20"
#1.left "backcolor green ; boxfilled ";nl;" 20"
#1.right "backcolor green ; boxfilled ";nr;" 20"
wait
[stopRecording]
timer 0
#1.left "fill white"
#1.right "fill white"
r$=mciSendString$("close wav")
r$=mciSendString$("close myRecording")
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