mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
0e2297af28
Renamed the CSFML directory to c Renamed the DSFML directory to d --> bindings must now be updated to match the new organization! git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1630 4e206d99-4929-0410-ac5d-dfc041789085
73 lines
1.5 KiB
D
73 lines
1.5 KiB
D
module client;
|
|
|
|
import util;
|
|
|
|
|
|
// Specialization of audio recorder for sending recorded audio
|
|
// data through the network
|
|
class NetworkRecorder : SoundRecorder
|
|
{
|
|
public:
|
|
|
|
// Constructor
|
|
this(SocketTCP Socket)
|
|
{
|
|
mySocket = Socket;
|
|
}
|
|
|
|
~this()
|
|
{
|
|
delete mySocket;
|
|
}
|
|
protected:
|
|
override bool onStart()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
override void onStop()
|
|
{
|
|
|
|
}
|
|
|
|
override bool onProcessSamples(short[] samples)
|
|
{
|
|
// Pack the audio samples into a network packet
|
|
Packet PacketOut = new Packet();
|
|
PacketOut.set(AudioData);
|
|
PacketOut.append((cast(byte*)samples.ptr)[0..samples.length * short.sizeof]);
|
|
// Send the audio packet to the server
|
|
return mySocket.send(PacketOut) == SocketStatus.DONE;
|
|
}
|
|
|
|
SocketTCP mySocket; ///< Socket used to communicate with the server
|
|
}
|
|
|
|
void runClient(IPAddress adr, int port)
|
|
{
|
|
// Create a TCP socket for communicating with server
|
|
SocketTCP Socket = new SocketTCP();
|
|
|
|
// Connect to the specified server
|
|
if (!Socket.connect(port, adr))
|
|
return;
|
|
|
|
// Wait for user input...
|
|
Cout("Press enter to start recording audio").newline;
|
|
Cin.get();
|
|
|
|
// Create a instance of our custom recorder
|
|
NetworkRecorder Recorder = new NetworkRecorder(Socket);
|
|
|
|
// Start capturing audio data
|
|
Recorder.start(44100);
|
|
Cout("Press enter to stop recording audio").newline;
|
|
Cin.get();
|
|
Recorder.stop();
|
|
|
|
// Send a "end-of-stream" packet
|
|
Packet PacketOut = new Packet();
|
|
PacketOut.set(EndOfStream);
|
|
Socket.send(PacketOut);
|
|
}
|