Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

# RakVoice Class Reference
[RakVoice Subsystem The RakVoice Subsytem]

RakVoice Class declaration. More...

`#include <RakVoice.h>`

Inheritance diagram for RakVoice:

List of all members.

## Public Member Functions
| RakVoice ()
virtual | ~RakVoice ()
void | Init (int samplingRate, int bitsPerSample, RakPeerInterface *_peer)
int | GetFrameSize (void) const
void | Disconnect (PlayerID id)
void | SetBlockSize (int _blockSize)
void | Deinit (void)
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][160]
int | writeCursor
int | readCursor
unsigned char | bps
SpeexBits | bits
int | frame_size
BasicDataStructures::Queue< PCMDataStruct * > | PCMQueue
BasicDataStructures::Queue< PCMDataStruct * > | PCMQueuePool
BasicDataStructures::List< CoderStateWithPlayerIDMapStruct * > | coderStateList
SimpleMutex | PCMQueueMutex
SimpleMutex | coderStateListMutex
RakPeerInterface * | peer
unsigned short | sampleRate
int | blockSize
## Friends
void * | rakVoiceThread (void *arguments)
## Classes
struct | PCMDataStruct
| Raw Data to encode or to play. More...

## Detailed Description

RakVoice Class declaration.

The RakVoice class provide services for the RakVoice subsystem. You will not directly used RakVoice object. Instead you will use RakVoiceInterface object provided by the RakVoiceFactory class.

## Constructor & Destructor Documentation

RakVoice::RakVoice | ( |  | ) |

| Default constructor

RakVoice::~RakVoice | ( |  | ) | `[virtual]`

| Destructor

## Member Function Documentation

void * RakVoice::CreateCoderState | ( | int | samplingRate,
|  | bool | decoder
| ) | `[private]`

| Creates encoders and decoders

CoderStateWithPlayerIDMapStruct * RakVoice::CreateCoderStateWithPlayerIDMapStruct | ( | int | samplingRate,
|  | PlayerID | playerId,
|  | bool | decoder
| ) | `[private]`

| Creates encoders and decoders

void RakVoice::DecodeAndQueueSoundPacket | ( | char * | data,
|  | int | length
| ) | `[virtual]`

  | When you get a packet with the type ID_VOICE_PACKET, Pass the data and length to this function. This 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:
  | data | byte data from the Packet object
  | length | size of data from the Packet object too.
Implements RakVoiceInterface.

void RakVoice::Deinit | ( | void |  | ) | `[virtual]`

| Call this before shutting down Implements RakVoiceInterface.

void RakVoice::Disconnect | ( | PlayerID | id | ) | `[virtual]`

  | Whenever a player disconnects we need to know about it. Otherwise we will be using old values for our encoding. Passing an id that has never been used is ok, it will be ignored. Parameters:
  | id | discard this player from the RakVoice communication group.
Implements RakVoiceInterface.

void RakVoice::EncodeSoundPacket | ( | char * | input,
|  | PlayerID | recipient
| ) | `[virtual]`

  | When you have raw sound data, pass it to this function. Input must be of size blockSize that you specified in Init This will encode and send in another thread the data as a packet Because of the way encoding works, you cannot broadcast voice data. You must specify a recipient If you want to send to everyone, you have to call this once for each recipient Use UNASSIGNED_PLAYER_ID to send to the server (if you are a client). Parameters:
  | input | a byte array of block size containing the raw voice data.
  | recipient | the targeted peer or UNASSIGNED_PLAYER_ID if you want to send to the server beeing a client.
Implements RakVoiceInterface.

CoderStateWithPlayerIDMapStruct * RakVoice::GetCoderFromPlayerID | ( | unsigned short | sr,
|  | PlayerID | id,
|  | bool | decoder
| ) | `[private]`

| Retrieve the coder struct for a player

int RakVoice::GetFrameSize | ( | void |  | ) | const`[virtual]`

| Valid to call after a call to Init. Returns the frame size used by the encoder in bytes 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]`

| Gives you 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 in the output buffer 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 data packet and write it to output Returns false if no packets are waiting. The originator of the packet is written to sender Parameters:
  | output | The resulting raw voice data
  | sender | The sender of this data
Returns: false if no packets are waiting Implements RakVoiceInterface.

void RakVoice::Init | ( | int | samplingRate,
|  | int | bitsPerSample
| ) | `[private]`

  | Internal initialisation procedure Parameters:
  | samplingRate | the rate to use
  | bitsPerSample | the bits to use per sample

void RakVoice::Init | ( | int | samplingRate,
|  | int | bitsPerSample,
|  | RakPeerInterface * | _peer
| ) | `[virtual]`

  | Call this before using voice packets. Use the server version to send packets through the server, client version to send packets through the client _blockSize is 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%). Parameters:
  | samplingRate | The rate to use, the higher the better quality and the bigger the size of the data ...
  | bitsPerSample | The number of bits used for one
  | _peer | RakPeer to use for communication it might be a peer, a server or a client.
Implements RakVoiceInterface.

void RakVoice::SetBlockSize | ( | int | _blockSize | ) | `[virtual]`

  | Set the block size that EncodeSoundPacket will read and GetSoundPacket will write. If you don't call this, it will default to GetFrameSize() You should only call this after calling Init. It is reset every call to Init. This must be a multiple of GetFrameSize(). Parameters:
  | _blockSize | The size of a RakVoice packet.
Implements RakVoiceInterface.

## Friends And Related Function Documentation

void* rakVoiceThread | ( | void * | arguments | ) | `[friend]`

| RakVoice Thread function to use

## Member Data Documentation

SpeexBits RakVoice::bits`[private]`

int RakVoice::blockSize`[private]`

| Must be a multiple of frame_size

unsigned char RakVoice::bps`[private]`

| bits per sample

BasicDataStructures::List<CoderStateWithPlayerIDMapStruct*> RakVoice::coderStateList`[private]`

| List of coder. Each party involved in the voice communication requires one coder state

SimpleMutex RakVoice::coderStateListMutex`[private]`

| Prevent multiple access to the PCM pool

int RakVoice::frame_size`[private]`

| Frame size

bool RakVoice::init`[private]`

| true if a previous call to init occured

speex_encoding_type RakVoice::inputList[RAK_VOICE_INPUT_LIST_BUFFER_SIZE][160]`[private]`

BasicDataStructures::Queue<PCMDataStruct*> RakVoice::PCMQueue`[private]`

| Store PCM Data

SimpleMutex RakVoice::PCMQueueMutex`[private]`

| Prevent multiple access at the same time to PCM queue

BasicDataStructures::Queue<PCMDataStruct*> RakVoice::PCMQueuePool`[private]`

| Pool of PCM Data ready to be used

RakPeerInterface* RakVoice::peer`[private]`

| Communication end point to use

int RakVoice::readCursor`[private]`

| The position of the next reading operation

unsigned short RakVoice::sampleRate`[private]`

| ample rate

PlayerID RakVoice::targetedSendRecipient[RAK_VOICE_INPUT_LIST_BUFFER_SIZE]`[private]`

| Encoding calls are buffered to this input list The thread will then parse this list to actually create the encoded data and send it through the network

int RakVoice::writeCursor`[private]`

| The position of the next writing operation

The documentation for this class was generated from the following files:

- Projects/raknet/include/rakvoice/RakVoice.h
- Projects/raknet/Source/RakVoice/RakVoice.cpp