As the title may suggest, I am using the PortAudio library to record audio input in order to send the data across a network to another machine where the audio will be played back. This is as a precursor to creating a basic voice chat program.
At the moment I have the audio being captured correctly & the data is being sent to a "server" program (currently running on the same machine (but the results are the same when it is not). The server program then just echo's the data back to where it came from so that it can be played back.
The problem I am having is that the data received back from the server seems to be of 1/2 the length of the data sent to the server i.e. when the data is played back, the audio (which is correct) is only 1 second instead of two.
This is how the data is sent from where it is recorded. Each piece of data is sent, and should be received back straight away to be stored so that it can be played back later:
floatData outData;
for (int i = 0; i < mData.maxFrameIndex; i++)
{
outData.dataSample = mData.recordedSamples[i];
send( mConnectSocket, (char*)&outData, sizeof(floatData), NULL );
//Receive the data send, which is echo'd back from the server straight away.
Receive( i );
}
closesocket( mConnectSocket );
WSACleanup();
Here is how it's sent received & sent back from the server:
int iRecvResult = 0;
floatData inData;
do
{
iRecvResult = recv( mConnectSocket, (char*)&inData, sizeof(floatData), NULL );
if (iRecvResult > 0)
{
// Send the data straight back again.
iRecvResult = send( mConnectSocket, (char*)&inData, sizeof(floatData), NULL );
if( iRecvResult < 0 )
{
break;
}
}
} while (iRecvResult > 0);
closesocket( mConnectSocket );
WSACleanup();
And this is how the data is received back at the original sender:
int iRecvResult = 0;
floatData inData;
iRecvResult = recv( mConnectSocket, (char*)&inData, sizeof(floatData), NULL );
mRecvData.recordedSamples[index] = inData.dataSample;
I don't know why only 1/2 the data is being received back, it all gets sent without any problems. I supposed I could playback the data on the server side of things to make sure that it's all getting there 100%, but I was wondering if anyone could shed any light on any possible theories.
Thanks in advance.