0
0

Hi,

I studied some other threads that deal with problems like mine but I still can’t figure out what’s wrong with my code.

I try to record voice (as was also discussed in previous threads). Later, I want to do some encoding on the data, but for now, I just try to play the captured data.

Using the FSOUND_PlaySound(…) function, there is no problem but as I want to encode the data later on, I thought it might be easier to use a stream callback function (or not?).

The problem here is that when the sound is played, I don’t get the microphone sounds but only a cracking noise.

Below is my (VERY basic) code. My guess is that the cracking noise is caused by the streamcallback buffer (void buff) that is played every loop although it is not filled completely (filled mostly with crappy data resulting in cracking noise). My RECORDLEN is 441005 now.

Maybe there are some other things I am doing wrong and I don’t even know if the concept (using a streamcallback) is a good idea in my case. I was hoping somebody would be so kind to help me with this. I know it is very basic but I’ve only been using FMOD for 2 days now.

Many thanks and much appreciation to anyone who tries to help!

(p.s.: I’m sorry for the crappy programming style, the code needs some refactoring)

[code:1wlbgl7p]
signed char F_CALLBACKAPI streamcallback(FSOUND_STREAM *stream, void *buff, int len, void *param)
{
static int prev_recpos = 0;

int recpos = FSOUND_Record_GetPosition();
int diff = (recpos < prev_recpos)? len-prev_recpos+recpos : recpos-prev_recpos ; 

u_int len1, len2 = 0;

void *ptr1, *ptr2;

signed short   *stereo16bitbuffer = (signed short *)buff;
signed short   *samples = (signed short *)param;
FSOUND_SAMPLE  *samp = (FSOUND_SAMPLE*) param;

FSOUND_Sample_Lock(samp, prev_recpos, diff, &ptr1, &ptr2, &len1, &len2);

memcpy(stereo16bitbuffer,ptr1,len1);
memcpy(stereo16bitbuffer,ptr2,len2);

FSOUND_Sample_Unlock(samp, &ptr1, &ptr2, len1, len2);

prev_recpos = recpos;

return 1;

}

int main(void)
{
....

FSOUND_SAMPLE *samp;

samp = FSOUND_Sample_Alloc(FSOUND_UNMANAGED,RECORDLEN,FSOUND_STEREO | FSOUND_16BITS,RECORDRATE,255,128,255);

FSOUND_Sample_SetMode(samp, FSOUND_LOOP_NORMAL);

FSOUND_Record_StartSample(samp, true);

while (!FSOUND_Record_GetPosition()) 
{
    Sleep(10);
}

stream = FSOUND_Stream_Create(streamcallback, RECORDLEN, FSOUND_16BITS | FSOUND_STEREO, 44100, samp);

....

}
[/code:1wlbgl7p]

i also noticed that FSOUND_Stream_GetLength(stream) and FSOUND_Stream_GetLengthMs(stream) always return 0 (failure). Is this normal?

  • You must to post comments
0
0

Ok thanks, that’s clear.

But now I need to know how I can play the captured data without using a stream.

I have a ringbuffer with audio data that needs to be played. The problem is that the buffer keeps getting filled with captured data. I suppose FSOUND_Sample_Upload() needs to be used to put the data in a sample and FSOUND_PlaySound() needs to be used to play that sample. But I don’t see how I can Upload the data if I don’t know how much data there is available. And how can I play a sample that is used over and over again to upload data. Should I loop the sample or not? I don’t really get it 😳

Is it hot outside or should I put an extra fan on my brain? 😕

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.