Hello!
I am currently developing a voip like application for my car-puter(minipc in my car). On roadtrips it is nice to be able to speak with the other families we travel with using the car's internal stereo system. I am currently in a state where I can see the info recieved but not hear the sound. I hear some clicking thou! Any ideas to what could be wrong?
Good to know:
I have a UDPSocket(named "Socket") as a global variable to simulate sending between computers.
My Recorder:
class NetworkRecorder : public sf::SoundBufferRecorder
{
public:
void setPort(unsigned short outport)
{
port = outport;
}
private:
virtual bool OnProcessSamples(const sf::Int16* samples, std::size_t sampleCount)
{
//std::cout << "NumSamples: " << sampleCount << " time: " << clock.GetElapsedTime() << std::endl;
packet.Clear();
packet.Append(samples,sampleCount * sizeof(sf::Int16));
sf::Sleep(20);
Socket.Send(packet,"127.0.0.1",port);
return true;
}
//Vars
unsigned short port;
sf::Clock clock;
sf::Packet packet;
};
My Reciever:
class NetworkStreamer : public sf::SoundStream
{
public :
bool Open(unsigned short prt)
{
port = prt;
while(Socket.Bind(prt))
{
};
// Initialize the stream -- important!
Initialize(1, SAMPLECOUNT);
return true;
}
private :
virtual bool OnGetData(Chunk& data)
{
//Recieve UDP data and add to stream
sf::Packet packet;
std::cout << "Got Data \n";
Socket.Receive(packet,adr,recieveport);
data.NbSamples = packet.GetDataSize()/sizeof(sf::Int16*);
data.Samples = reinterpret_cast<const sf::Int16*>(packet.GetData());
for(int i = 0;i < data.NbSamples;i+=5)
{
std::cout << data.Samples[i] << "\n";
}
// Return true to continue playing
return true;
}
virtual void OnSeek(sf::Uint32 timeOffset)
{
// Allways play the latest recieved
// Change the current position in the stream source
}
//Vars
unsigned short port;
sf::UdpSocket Socket;
sf::IpAddress adr;
unsigned short recieveport;
};
The main parts:
void recieveloop(unsigned short port)
{
sf::Clock clock;
NetworkStreamer stream;
stream.Open(port);
stream.Play();
while(1 || clock.GetElapsedTime() < 2000)
{
}
}
int main()
{
unsigned short outport,inport;
outport = 2000;
inport = 2000;
if (sf::SoundBufferRecorder::IsAvailable())
{
NetworkRecorder Recorder;
Recorder.Start(SAMPLECOUNT);
Recorder.setPort(outport);
sf::Thread Thread(&recieveloop,inport);
Thread.Launch();
sf::Clock clock;
while( 1 || clock.GetElapsedTime() < 20000)
{
}
Recorder.Stop();
}
return EXIT_SUCCESS;
}
Also another thought:
Is there a way to send the data to multiple IP's or simply out in the air? Seeing as I don't wan't to hardcode the destinations...