Hi!
I'm working on a voice chat built with boost::asio and when I'm on the receiving side, I hear a serie of quick "click!" instead of my original wav. I think the issue might be with how I'm marshalling/unmarshalling the data.
Could I have your opinion on this?
Here's how I split it when sending the samples:
// Chopping SoundBuffer into buffer-length char[] filled into mByteBufferQueue
Int16 * mSoundBufferRaw = const_cast<sf::Int16 *>(mSoundBuffer.getSamples());
while(wBufferIndex < mSoundBuffer.getSampleCount())
{
// ... some calculation for mBlocksToConvert
// create char[] buffer
for(unsigned int i = 0; i < mBlocksToConvert; ++i)
{
mByteBuffer[2*i] = 0xFF & static_cast<char>(mSoundBufferRaw[wBufferIndex] >> 8);
mByteBuffer[2*i+1] = 0xFF & static_cast<char>(mSoundBufferRaw[wBufferIndex]);
++wBufferIndex;
}
// fill queue
mByteBufferQueue.push_back(mByteBuffer);
}
This is how it's received and played:
part 1...
std::vector<sf::Int16> wSamples;
for (unsigned int i = 0; i < iBytesReceived; i += 2) {
wSamples.push_back(static_cast<sf::Int16>( (mData[i] << 8) | (0x00FF & mData[i+1]) ));
}
mServerPtr->pushSamples(std::move(wSamples));
part 2...
if((mAudioStream.getStatus() != AudioStream::Playing) && !mSamplesQueue.empty())
{
if(mSoundBuffer.loadFromSamples(
reinterpret_cast<sf::Int16*>(mSamplesQueue.front().data()),
mSamplesQueue.front().size(), 2, 48000)
)
{
mAudioStream.load(mSoundBuffer);
mAudioStream.play();
mSamplesQueue.pop_front();
}
}