0

我正在尝试使用 SFML 创建语音聊天。程序使用 SoundbufferRecorder 录制 1 秒长的部分。

当我测试下面的代码时,控制台显示: 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();
}

提前感谢您的帮助。

4

0 回答 0