# RakVoice Class Reference

Voice compression and transmission interface. More...

`#include <RakVoice.h>`

Inheritance diagram for RakVoice:

List of all members.

## Public Member Functions
void | Init (unsigned short speexSampleRate, unsigned bufferSizeBytes)
| Starts RakVoice.
void | SetEncoderComplexity (int complexity)
| Changes encoder complexity Specifying higher values might help when encoding non-speech sounds.
void | SetVAD (bool enable)
| Enables or disables VAD (Voice Activity Detection) Enabling VAD can help reduce the amount of data transmitted, by automatically disabling outgoing data, when no voice is detected. Don't turn this off or the receive buffer fills up and you eventually get very long delays!!
void | SetNoiseFilter (bool enable)
| Enables or disables the noise filter.
void | SetVBR (bool enable)
| Enables or disables VBR VBR is variable bitrate. Uses less bandwidth but more CPU if on.
int | GetEncoderComplexity (void)
| Returns the complexity of the encoder.
bool | IsVADActive (void)
| Returns current state of VAD.
bool | IsNoiseFilterActive ()
| Returns the current state of the noise filter.
bool | IsVBRActive ()
| Returns the current state of VBR.
void | Deinit (void)
| Shuts down RakVoice.
void | RequestVoiceChannel (RakNetGUID recipient)
| Opens a channel to another connected system You will get ID_RAKVOICE_OPEN_CHANNEL_REPLY on success.
void | CloseVoiceChannel (RakNetGUID recipient)
| Closes an existing voice channel. Other system will get ID_RAKVOICE_CLOSE_CHANNEL.
void | CloseAllChannels (void)
| Closes all existing voice channels Other systems will get ID_RAKVOICE_CLOSE_CHANNEL.
bool | SendFrame (RakNetGUID recipient, void *inputBuffer)
| Sends voice data to a system on an open channel.
bool | IsSendingVoiceDataTo (RakNetGUID recipient)
| Returns if we are currently sending voice data, accounting for voice activity detection.
void | ReceiveFrame (void *outputBuffer)
| Gets decoded voice data, from one or more remote senders.
int | GetSampleRate (void) const
int | GetBufferSizeBytes (void) const
bool | IsInitialized (void) const
RakPeerInterface * | GetRakPeerInterface (void) const
unsigned | GetBufferedBytesToSend (RakNetGUID guid) const
unsigned | GetBufferedBytesToReturn (RakNetGUID guid) const
void | SetLoopbackMode (bool enabled)
bool | IsLoopbackMode (void) const
virtual void | Update (void)
| Update is called every time a packet is checked for .
virtual PluginReceiveResult | OnReceive (Packet *packet)
virtual void | OnClosedConnection (SystemAddress systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)

## Detailed Description

Voice compression and transmission interface.

## Member Function Documentation

void RakVoice::CloseVoiceChannel | ( | RakNetGUID | recipient | ) |

Closes an existing voice channel. Other system will get ID_RAKVOICE_CLOSE_CHANNEL.

Parameters:

  `[in]` | recipient | Which system to close a channel with

unsigned RakVoice::GetBufferedBytesToReturn | ( | RakNetGUID | guid | ) | const

How many bytes are on the read buffer, waiting to be passed to a call to ReceiveFrame This should remain at a fairly small near-constant size as incoming data is read out at the same rate as outgoing data from the remote system

Parameters:

  `[in]` | guid | The system to query, or UNASSIGNED_SYSTEM_ADDRESS for the sum of all channels.

Returns:
  Number of bytes on the read buffer.

unsigned RakVoice::GetBufferedBytesToSend | ( | RakNetGUID | guid | ) | const

How many bytes are on the write buffer, waiting to be passed to a call to RakPeer::Send (internally) This should remain at a fairly small near-constant size as outgoing data is sent to the Send function

Parameters:

  `[in]` | guid | The system to query, or UNASSIGNED_SYSTEM_ADDRESS for the sum of all channels.

Returns:
  Number of bytes on the write buffer

int RakVoice::GetBufferSizeBytes | ( | void |  | ) | const

Returns the buffer size in bytes, as passed to Init

Returns:
  buffer size in bytes

int RakVoice::GetEncoderComplexity | ( | void |  | ) |

Returns the complexity of the encoder.

Precondition:
  Only applies to encoder.

Returns:
  a value from 0 to 10.

RakPeerInterface* RakVoice::GetRakPeerInterface | ( | void |  | ) | const

Returns the RakPeerInterface that the object is attached to.

Returns:
  the respective RakPeerInterface, or NULL not attached.

Reimplemented from PluginInterface2.

int RakVoice::GetSampleRate | ( | void |  | ) | const

Returns the value sample rate, as passed to Init

Returns:
  the sample rate

void RakVoice::Init | ( | unsigned short | speexSampleRate,
|  | unsigned | bufferSizeBytes |
| ) |  |  |

Starts RakVoice.

Parameters:

  `[in]` | speexSampleRate | 8000, 16000, or 32000
  `[in]` | bufferSizeBytes | How many bytes long inputBuffer and outputBuffer are in SendFrame and ReceiveFrame are. Should be your sample size * the number of samples to encode at once.

bool RakVoice::IsInitialized | ( | void |  | ) | const

Returns true or false, indicating if the object has been initialized

Returns:
  true if initialized, false otherwise.

bool RakVoice::IsLoopbackMode | ( | void |  | ) | const

Returns true or false, indicating if the loopback mode is enabled

Returns:
  true if enabled, false otherwise.

bool RakVoice::IsNoiseFilterActive | ( |  | ) |

Returns the current state of the noise filter.

Precondition:
  Only applies to encoder.

Returns:
  true if the noise filter is active, false otherwise.

bool RakVoice::IsSendingVoiceDataTo | ( | RakNetGUID | recipient | ) |

Returns if we are currently sending voice data, accounting for voice activity detection.

Parameters:

  `[in]` | Which | system to check

Returns:
  If we are sending voice data for the specified system

bool RakVoice::IsVADActive | ( | void |  | ) |

Returns current state of VAD.

Precondition:
  Only applies to encoder.

Returns:
  true if VAD is enable, false otherwise

bool RakVoice::IsVBRActive | ( |  | ) |

Returns the current state of VBR.

Precondition:
  Only applies to encoder.

Returns:
  true if VBR is active, false otherwise.

virtual void RakVoice::OnClosedConnection | ( | SystemAddress | systemAddress,
|  | RakNetGUID | rakNetGUID,
|  | PI2_LostConnectionReason | lostConnectionReason |
| ) |  |  | `[virtual]`

Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system

Parameters:

  `[in]` | systemAddress | The system whose connection was closed
  `[in]` | rakNetGuid | The guid of the specified system
  `[in]` | lostConnectionReason | How the connection was closed: manually, connection lost, or notification of disconnection

Reimplemented from PluginInterface2.

virtual PluginReceiveResult RakVoice::OnReceive | ( | Packet * | packet | ) | `[virtual]`

OnReceive is called for every packet.

Parameters:

  `[in]` | packet | the packet that is being returned to the user

Returns:
  True to allow the game and other plugins to get this message, false to absorb it

Reimplemented from PluginInterface2.

void RakVoice::ReceiveFrame | ( | void * | outputBuffer | ) |

Gets decoded voice data, from one or more remote senders.

Parameters:

  `[out]` | outputBuffer | The voice data. The size of outputBuffer should be what was specified as bufferSizeBytes in Init

void RakVoice::RequestVoiceChannel | ( | RakNetGUID | recipient | ) |

Opens a channel to another connected system You will get ID_RAKVOICE_OPEN_CHANNEL_REPLY on success.

Parameters:

  `[in]` | recipient | Which system to open a channel to

bool RakVoice::SendFrame | ( | RakNetGUID | recipient,
|  | void * | inputBuffer |
| ) |  |  |

Sends voice data to a system on an open channel.

Precondition:
  recipient must refer to a system with an open channel via RequestVoiceChannel

Parameters:

  `[in]` | recipient | The system to send voice data to
  `[in]` | inputBuffer | The voice data. The size of inputBuffer should be what was specified as bufferSizeBytes in Init

void RakVoice::SetEncoderComplexity | ( | int | complexity | ) |

Changes encoder complexity Specifying higher values might help when encoding non-speech sounds.

Parameters:

  `[in]` | complexity | 0 to 10. The higher the value, the more CPU it needs. Recommended values are from 2 to 4.

void RakVoice::SetLoopbackMode | ( | bool | enabled | ) |

Enables/disables loopback mode

Parameters:

  `[in]` | true | to enable, false to disable

void RakVoice::SetNoiseFilter | ( | bool | enable | ) |

Enables or disables the noise filter.

Precondition:
  Only applies to encoder.

Parameters:

  `[in]` | enable | true to enable, false to disable.

void RakVoice::SetVAD | ( | bool | enable | ) |

Enables or disables VAD (Voice Activity Detection) Enabling VAD can help reduce the amount of data transmitted, by automatically disabling outgoing data, when no voice is detected. Don't turn this off or the receive buffer fills up and you eventually get very long delays!!

Precondition:
  Only applies to encoder.

Parameters:

  `[in]` | enable | true to enable, false to disable. True by default

void RakVoice::SetVBR | ( | bool | enable | ) |

Enables or disables VBR VBR is variable bitrate. Uses less bandwidth but more CPU if on.

Precondition:
  Only applies to encoder.

Parameters:

  `[in]` | enable | true to enable VBR, false to disable

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

- d:/RakNet-3.x/DependentExtensions/RakVoice.h