Home » Questions » Custom streaming with raw pcm data received through the net

0

0

Hi everyone…faced another kind of problem I can’t figure out myself…
Recently I’ve been working on a network voice chatting program which can send and receive raw pcm data in sockets. I found a sample program(server-client, socket programming, buffers of raw data) which worked fine, and began to modify it a little bit with fmod streaming functions(only the playback part). I searched for similar topics in the forum and found out that I should use the custom stream as written in ‘stream2’ example. Just for the player thread, I suppose it’s like this : define a streamcallback fumction -> make a custom stream and set the user parameter as a pointer to the received block of audio data(8 bit, mono, 22050Hz in my case). And here’s my code.
[code:2vpvbe57]
signed char F_CALLBACKAPI streamcallback(FSOUND_STREAM *stream, void *buff, int len, void *param)
{
LPWAVEHDR inHdr = (LPWAVEHDR) param;
LPSTR copiedBuf = (LPSTR) buff;
memcpy(copiedBuf, inHdr->lpData, len);
//len = supposed to be 2000 here
//should store the created data to buff
return 1;
}[/code:2vpvbe57]

Whenever the client receives a data block and it seems to contain the actual sound data, these two functions are called:
[code:2vpvbe57]
LRESULT PlaySound2::OnStartPlaying(WPARAM wParam, LPARAM lParam)
{ //wParam has the length info(2000 here)
MMRESULT mmReturn = 0; //lParam is the received wave header
wavHdr = (LPWAVEHDR)lParam; //wavHdr is a member variable of player thread
if(Playing==TRUE)
return FALSE; //this flag is checked before calling,

}
[/code:2vpvbe57]
When run, I can only hear a strange noise. It sounds a little bit different when I speak to the microphone, but it’s all noise anyway. I guess something might be wrong in my way of feeding the data to the stream or the order that fmod functions appear, but not sure of anything. Can anybody help me find what I did wrong…?

stream = FSOUND_Stream_Create(streamcallback, len, FSOUND_8BITS | FSOUND_UNSIGNED | FSOUND_MONO, 8000, (void *)wavHdr);
(I changed the sampling rate after posting, to 8000)
I think this is what you said, is it correct…?
I tried FSOUND_SIGNED and FSOUND_UNSIGNED but none worked…
What else could be thought causing the trouble…? Do you have any other recommendation…?

Wow…now the loud noise has gone, but what happens is, for example, if I say ‘blah’ like 3 times, it repeats a little broken ‘blah’ about 10 times.
I feel like getting closer, thanks so much…do you have any ideas on what I should do more…?