Cannot record more than one sample using FMOD

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
Tusike
Posts: 207
Joined: Jan 03, 2008 16:53
Location: Hungary

Cannot record more than one sample using FMOD

Post by Tusike »

Hi!

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
The first recording works fine, but the second one does not start. Am I missing something? Would there be a simpler way for me to go?

Thanks for any help!

-Tusike
Tusike
Posts: 207
Joined: Jan 03, 2008 16:53
Location: Hungary

Re: Cannot record more than one sample using FMOD

Post by Tusike »

Well, in the end I could not manage to figure this out. Instead I'm using a single instance of a looped recording, which seems to work alright, though I expected a little bit better. A better microphone would help, I already had some improvement using an external one instead of the laptop's internal one.

I just wanted a quick program, so the piano key detection itself could definitely use some tuning, but if anyone's interested in how everything come together you're welcome to check it out for reference: https://www.mediafire.com/file/lb5r727h ... o.zip/file

Best,
Tusike
Post Reply