RakVoice Class Reference
[RakVoice Subsystem]

RakVoice voice communication library. More...

#include <RakVoice.h>

Inheritance diagram for RakVoice:

RakVoiceInterface List of all members.

Public Member Functions

 RakVoice ()
 Default constructor.
virtual ~RakVoice ()
 Destructor.
void Init (int samplingRate, int bitsPerSample, RakPeerInterface *_peer)
int GetFrameSize (void) const
void Disconnect (PlayerID id)
void SetBlockSize (int _blockSize)
void Deinit (void)
 Frees all memory used. Call this before shutting down.
void EncodeSoundPacket (char *input, PlayerID recipient)
void DecodeAndQueueSoundPacket (char *data, int length)
bool GetSoundPacket (char *output, PlayerID *sender)
int GetNextSoundPacketSize (void)
int GetOutputBufferSize (void)

Private Member Functions

void Init (int samplingRate, int bitsPerSample)
CoderStateWithPlayerIDMapStruct * CreateCoderStateWithPlayerIDMapStruct (int samplingRate, PlayerID playerId, bool decoder)
void * CreateCoderState (int samplingRate, bool decoder)
CoderStateWithPlayerIDMapStruct * GetCoderFromPlayerID (unsigned short sr, PlayerID id, bool decoder)

Private Attributes

bool init
PlayerID targetedSendRecipient [RAK_VOICE_INPUT_LIST_BUFFER_SIZE]
speex_encoding_type inputList [RAK_VOICE_INPUT_LIST_BUFFER_SIZE][MAX_FRAME_SIZE]
int writeCursor
int readCursor
unsigned char bps
int frame_size
BasicDataStructures::Queue<
PCMDataStruct * > 
PCMQueue
 Queue of PCMDataStruct , which is the data waiting to be copied to the user for playback.
BasicDataStructures::Queue<
PCMDataStruct * > 
PCMQueuePool
 Queue of PCMDataStruct, used to prevent needless reallocations of PCMDataStruct.
BasicDataStructures::List<
CoderStateWithPlayerIDMapStruct * > 
coderStateList
 All the coders and decoders, oen per player.
SimpleMutex PCMQueueMutex
 Used to lock PCMQueue.
SimpleMutex coderStateListMutex
RakPeerInterfacepeer
 Copy of _peer passed to Init().
unsigned short sampleRate
 Copy of samplingRate passed to Init().
int blockSize
 Must be a multiple of frame_size.
SpeexBits bits

Friends

void * rakVoiceThread (void *arguments)
 Thread that will continually run, processing voice data.

Classes

struct  PCMDataStruct

Detailed Description

RakVoice voice communication library.

RakVoice is a set of functions that uses an instance of RakPeer to transfer, encode, and decode voice packets. I use speex to handle the encoding and decoding part. The sample uses port-audio for record and playback. You can use anything you want and the system is not tied to port-audio in any way. Bandwidth usage is extraordinarily low, in the hundreds of bytes per second. If you were to use this with RakNet's secure communication capability, you can have secure peer to peer voice communications over the internet.

Remarks:
What I've done here is the minimal set of functionality for voice communication. If you plan to use this in a game, you will probably want to expand on the system.
See also:
main.cpp


Member Function Documentation

void RakVoice::DecodeAndQueueSoundPacket char *  data,
int  length
[virtual]
 

When you get a packet with the type ID_VOICE_PACKET, pass the packet data and length to this function. This function will decode the data and put it in the internal queue, or simply relay the data if this is the server and the target is not the server

Parameters:
[in] data Packet::data
[in] length Packet::length
See also:
NetworkTypes.h

Implements RakVoiceInterface.

void RakVoice::Disconnect PlayerID  id  )  [virtual]
 

Whenever a player disconnects RakVoice needs to know about it. Otherwise we will be using old values for our encoding.

Parameters:
[in] id PlayerID of the player who has disconnected.

Implements RakVoiceInterface.

void RakVoice::EncodeSoundPacket char *  input,
PlayerID  recipient
[virtual]
 

Pass your raw sound data to this function. This function will encode and send in another thread the data as a packet Because of the way encoding works, you cannot broadcast voice data.

Parameters:
[in] input A byte array of block size containing the raw voice data. this must be equal in size to the current blockSize, whatever you passed to SetBlockSize()
[in] recipient The targeted peer or UNASSIGNED_PLAYER_ID if you want to send to the server as a client.

Implements RakVoiceInterface.

int RakVoice::GetFrameSize void   )  const [virtual]
 

Precondition:
You must have called Init first Gets the frame size.
Note:
It is best to send input to EncodeSoundData that matches this frame size
Returns:
The frame size used by the encoder, in bytes

Implements RakVoiceInterface.

int RakVoice::GetNextSoundPacketSize void   )  [virtual]
 

Returns the size, in bytes, of the next sound packet, or 0 for nothing left

Returns:
The size, in bytes, of the next sound packet, or 0 for nothing left

Implements RakVoiceInterface.

int RakVoice::GetOutputBufferSize void   )  [virtual]
 

This will tell you the total number of bytes waiting to be copied out via the function DecodeAndQueueSoundPacket()

Returns:
Returns the number of remaining byte in the buffer.

Implements RakVoiceInterface.

bool RakVoice::GetSoundPacket char *  output,
PlayerID sender
[virtual]
 

This will get the next sound packet and copy it to output. By sound packet, I mean decompressed sound data, not network datagram

Parameters:
[out] output The resulting raw sound voice data
[in] sender Who sent this voice data
Return values:
true Data was copied to output, of the same length you passed to SetBlockSize
false No sound packets are waiting.

Implements RakVoiceInterface.

void RakVoice::Init int  samplingRate,
int  bitsPerSample,
RakPeerInterface _peer
[virtual]
 

Call this first.

Parameters:
[in] samplingRate Self-explanatory
[in] bitsPerSample Self-explanatory
[in] _peer The instance of RakPeer to use for sends

Implements RakVoiceInterface.

void RakVoice::SetBlockSize int  _blockSize  )  [virtual]
 

Sets the block size that EncodeSoundPacket will read and GetSoundPacket will write. If you don't call this, it will default to GetFrameSize(). It is reset every call to Init.

Precondition:
Must have called Init first
Parameters:
[in] _blockSize The size of each block that you want to process at a time. Each network packet will have this size before compression. It must be a multiple of frame_size. The best _blockSize is what would be compressed to slightly under your MTU. You can safely assume the compression rate is 50% (actually it's closer to 75%).

Implements RakVoiceInterface.


The documentation for this class was generated from the following files:
Generated on Mon Mar 20 20:32:56 2006 for RakNet by  doxygen 1.4.6-NO