0

I am trying to create a voice chat using SFML. Program records 1 second-long parts with a SoundbufferRecorder.

when I test the code below, console shows this: Failed to load sound file from memory

void receiveData()
{
   received_data = false;
   unsigned short port;
   if (serwer) port = s_port;
   else port = k_port;  
   Packet p;
   socket.receive(p, ip, port); 
   bufferfrommemory.loadFromMemory(p.getData(), p.getDataSize());
   received_data= true;
}

void sendData()
{
  unsigned short port;
  if (serwer) port = k_port;
  else port = s_port;       
  const sf::SoundBuffer& buffer = recorder.getBuffer();
  const sf::Int16* samples = buffer.getSamples();
  std::size_t count = buffer.getSampleCount();
  Packet p;
  p.append(samples, count);
  socket.send(p, ip, port);
}
void playIt() 
{
  Sound g;
  g.setBuffer(bufferfrommemory);
  g.play();
}

Thanks in advance for any help.

Patrick
  • 1
  • 1
  • There's some surrounding code that you didn't include that might make a difference here. I am guessing that either you might be calling `playIt` before you call `receiveData` in some cases, or you might somehow accidentally deallocate or clear the buffer before you're trying to play it back. Can you expand this sample so that it can be copied/pasted and compiled without adding any extra code? – Merlyn Morgan-Graham Jul 22 '16 at 21:58
  • You might also have set the socket to not be "blocking", in which case `receive` might not actually wait for data to come back, and the buffer would be empty, but you aren't checking for that case before you try to load that non-existent data as a sound file. See: http://www.sfml-dev.org/documentation/2.0/classsf_1_1TcpSocket.php#aa655352609bc9804f2baa020df3e7331 – Merlyn Morgan-Graham Jul 22 '16 at 22:01

0 Answers0