I'm trying to create a simple program where I detect piano key presses I play on my piano in real time. The idea would be to record e.g. for 0.01-0.02s, find the fourier transform corresponding to frequencies around the notes, check which ones are pressed, and repeat. I don't need anything very fancy, so such a simplistic scheme seems the fastest and easiest for my purposes.
For some reason, however, I can only record one sample when I try using FMOD. I made a short working example based on code from mambazo at https://qa.fmod.com/t/fsound-record-get ... tch/4601/6
Code: Select all
#INCLUDE ONCE "fmod.bi"
' FOR RECORD BUFFERS
const false = 0
' FOR FMOD
const SAMPLINGRATE = 44100
const BUFFERSIZE = 5000
dim as integer RecordBuf
' initialize
if ( FSOUND_Init(44100, 32, 0) = false ) then
print "Can't initialize FMOD"
end 1
end if
RecordBuf = FSOUND_SAMPLE_Alloc (FSOUND_FREE, BUFFERSIZE, FSOUND_NORMAL, SAMPLINGRATE, 255, 128, 255)
if RecordBuf = false then
print "Could not init buffer"
beep
sleep
end
end if
' Start recording
if FSOUND_Record_StartSample ( RecordBuf, 0) = false then
print "Could not start recording in buffer!"
BEEP
sleep
end
else
print "Successfully started recording"
end if
while (FSOUND_Record_GetPosition()) < BUFFERSIZE: wend
print "Finished recording"
' Stop the recording
FSOUND_Record_Stop()
' Start recording again
if FSOUND_Record_StartSample ( RecordBuf, 0) = false then
print "Could not record into buffer again!"
BEEP
sleep
end
else
print "Started recording again!"
end if
while (FSOUND_Record_GetPosition()) < BUFFERSIZE: wend
print "Finished recording"
FSOUND_Record_Stop()
'close fmod
FSOUND_Close
Thanks for any help!
-Tusike