I don't exactly know what's wrong with this, but it doesn't play any sound. I'm fairly certain it should play something, since it outputs stuff that doesn't seem totally constant. Can anybody point me in the right direction? Using latest SFML snapshot in Visual Studio 2008. Static linking.
This is my third attempt, all ended up like this.
Server
int main(int argc, char* argv[])
{
CanNet::TCPSocket server;
CanNet::TCPSocket* client = NULL;
CanNet::Buffer buff;
sf::SoundBuffer sndBuffer;
sf::Sound sndPlay(sndBuffer);
short buffer[8000];
bool connected = false;
CanNet::Startup();
server.Listen("1337");
FILE* fOut = fopen("received.dat", "w");
while (1)
{
if (!connected)
{
// Wait for connections
client = server.Accept();
if (client != NULL)
{
std::cout << "Client Connected!" << std::endl;
connected = true;
}
} else {
int size = client->Receive(buff);
if (size > 0)
{
sndPlay.Stop();
buff.Read(&buffer, size);
fwrite(&buffer, size, 1, fOut);
sndBuffer.LoadFromSamples(&buffer[0], size / 2, 1, 8000);
sndPlay.Play();
}
}
Sleep(1);
}
fclose(fOut);
server.Close();
CanNet::Shutdown();
return 0;
}
Client
int main(int argc, char* argv[])
{
CanNet::TCPSocket sock;
CanNet::Buffer buff;
sf::SoundBufferRecorder sndRec;
sf::SoundBuffer sndBuffer = sndRec.GetBuffer();
CanNet::Startup();
if (!sock.Connect("127.0.0.1", "1337"))
{
sock.Close();
std::cout << "Unable to connect." << std::endl;
CanNet::Shutdown();
return 0;
}
sndRec.Start(8000);
while (1)
{
if (!sock.IsConnected())
{
std::cout << "Lost connection." << std::endl;
break;
}
// Do shit.
Sleep(16); // ~60fps.
sndRec.Stop();
sndBuffer = sndRec.GetBuffer();
buff.Clear();
buff.Write((void*)sndBuffer.GetSamples(), sndBuffer.GetSamplesCount() * 2); // 1 sample = 2 bytes
sock.Send(buff);
sndRec.Start(8000);
}
sndRec.Stop();
sock.Close();
CanNet::Shutdown();
return 0;
}
Custom made networking system. I also have An internal OpenAL call failed in soundbuffer.cpp (308) : AL_INVALID_VALUE, a numeric argument is out of range
in the server.