22 May '13 - 09:35 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: TCP / UDP speex voice streaming with SDL_net  (Read 380 times)
Miisas
Posts: 2


« on: 6 Sep '12 - 23:36 »
Reply with quoteQuote

Hi.

I'm working on this voice chat -alike application, where two users simply talk to each other through microphone, using speex codec.

I've managed to make a working connection between server and client with both, TCP and UDP connections with SDL_net.

The problem I have here is that my incoming audio buffer seems to run out of data very fast.
If I first stream, like, 1 second of audio before starting to play it back, I can then play it back like second or two before my incoming buffer has ran out of data.

I'm kinda beginner in live audio streaming through tcp / udp sockets so any tips are helpful.

Send:
BOOL CALLBACK RecordProc(HRECORD handle,const void *buffer,DWORD length,void *user) {
return TRUE;
}

void CALLBACK EncodeProc(
    HENCODE handle,
    DWORD channel,
    const void *buffer,
    DWORD length,
    void *user
) {
memcpy(recbuffer + readyoffset,buffer,length);
readyoffset = readyoffset + length;
}
HRECORD rec = BASS_RecordStart(11025,1,BASS_RECORD_PAUSE,&RecordProc,0);
HENCODE encoder = BASS_Encode_Start(rec, "speexenc -n --comp 1 - -", BASS_ENCODE_NOHEAD, EncodeProc, 0);
BASS_ChannelPlay(rec,FALSE);

Receive (store to buffer:):
if (SDLNet_UDP_Recv(sender, p)) {
    memcpy(recbuffer + offset,(char *)p->data,p->len);
offset = offset + p->len;
SDLNet_FreePacket(p);
p = NULL;
if (!(p = SDLNet_AllocPacket(512))) {
}
}
Receive (copy from incoming buffer to bass buffer):
DWORD CALLBACK MyFileReadProc(void *buffer, DWORD length, void *user)
{
if( takeoffset > offset + length ) {
//TODO: Return fixed size
if( takeoffset == offset ) {
// mem totally empty
underrun = true;
cout <<"Buffer underrun"<<endl;
return 0;
}/*
cout <<"Buffer underrun too close"<<endl;
                return 0;
} else {
memcpy(buffer,recbuffer + takeoffset,length);
takeoffset = takeoffset + length;
return length;
}

}
As you can see, right now I stop feeding data when I cant return full length buffer.

Logged
Ian @ un4seen
Administrator
Posts: 15259


« Reply #1 on: 7 Sep '12 - 17:19 »
Reply with quoteQuote

Assuming that you are using the buffered file system (eg. STREAMFILE_BUFFER) in your BASS_StreamCreateFileUser call, the FILEREADPROC function returning 0 indicates to BASS that it has reached the end of the file and there is no more data to come. If there is more data to come, the FILEREADPROC should wait for some to arrive. You could use an event to signal when data is available, eg. your "Receive (store to buffer:)" code calls SetEvent and the FILEREADPROC calls WaitForSingleObject to wait for that (when there is no data available). Your FILECLOSEPROC should also call SetEvent in that case, to cancel the wait.

Note the FILEREADPROC can return less than requested, just not 0 (unless it has reached the end).
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines