Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - elementalsc

Pages: [1]
1
Audio / Re: Sending wav over TCP, serializing problem?
« on: February 28, 2018, 10:24:51 pm »
I took the Custom stream demo from the tutorial, it seems to work fine when loading and playing a buffer in the same program.

Maybe it's not working in the receiving end... other that the serializing thing, I was starting to ask myself if i was correctly "appending" SoundBuffer. I feel like I might simply be playing the same sample over and over.

    if((mAudioStream.getStatus() != AudioStream::Playing) && !mSamplesQueue.empty()) {
      if(mSoundBuffer.loadFromSamples(
        mSamplesQueue.front(),
        BUFFER_SIZE/2, 1, 44100) )
      {
        mAudioStream.load(mSoundBuffer);
        mAudioStream.play();
        mSamplesQueue.pop_front();
      }
    }
 

2
Audio / Re: Sending wav over TCP, serializing problem?
« on: February 28, 2018, 06:34:18 pm »
Quote
What's the point of complicating things instead of simply packing the bytes?

What do you mean by "simply packing the bytes"? I though that splitting int16 into two bytes and streaming them was simple enough... but I guess I'm missing something. How would you do it?

3
Audio / Sending wav over TCP, serializing problem?
« on: February 28, 2018, 06:10:48 pm »
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();
      }
    }
 

Pages: [1]