AudioServer

Inherits: Object

Inherited By: AudioServerSW

Category: Core

Brief Description

Server interface for low level audio access.

Member Functions

void free_rid ( RID rid )
float get_event_voice_global_volume_scale ( ) const
float get_fx_global_volume_scale ( ) const
float get_stream_global_volume_scale ( ) const
RID sample_create ( int format, bool stereo, int length )
RawArray sample_get_data ( RID sample ) const
String sample_get_description ( RID sample ) const
int sample_get_format ( RID sample ) const
int sample_get_length ( RID sample ) const
int sample_get_loop_begin ( RID sample ) const
int sample_get_loop_end ( RID sample ) const
int sample_get_loop_format ( RID sample ) const
int sample_get_mix_rate ( RID sample ) const
bool sample_is_stereo ( RID sample ) const
void sample_set_data ( RID sample, RawArray data )
void sample_set_description ( RID sample, String description )
void sample_set_loop_begin ( RID sample, int pos )
void sample_set_loop_end ( RID sample, int pos )
void sample_set_loop_format ( RID sample, int loop_format )
void sample_set_mix_rate ( RID sample, int mix_rate )
void sample_set_signed_data ( RID sample, RealArray data )
void set_event_voice_global_volume_scale ( float scale )
void set_fx_global_volume_scale ( float scale )
void set_stream_global_volume_scale ( float scale )
RID voice_create ( )
float voice_get_chorus ( RID voice ) const
float voice_get_filter_cutoff ( RID voice ) const
float voice_get_filter_resonance ( RID voice ) const
int voice_get_filter_type ( RID voice ) const
int voice_get_mix_rate ( RID voice ) const
float voice_get_pan ( RID voice ) const
float voice_get_pan_depth ( RID voice ) const
float voice_get_pan_height ( RID voice ) const
float voice_get_reverb ( RID voice ) const
int voice_get_reverb_type ( RID voice ) const
float voice_get_volume ( RID voice ) const
bool voice_is_positional ( RID voice ) const
void voice_play ( RID voice, RID sample )
void voice_set_chorus ( RID voice, float chorus )
void voice_set_filter ( RID voice, int type, float cutoff, float resonance, float gain=0 )
void voice_set_mix_rate ( RID voice, int rate )
void voice_set_pan ( RID voice, float pan, float depth=0, float height=0 )
void voice_set_positional ( RID voice, bool enabled )
void voice_set_reverb ( RID voice, int room, float reverb )
void voice_set_volume ( RID voice, float volume )
void voice_stop ( RID voice )

Numeric Constants

  • SAMPLE_FORMAT_PCM8 = 0 — Sample format is 8 bits, signed.
  • SAMPLE_FORMAT_PCM16 = 1 — Sample format is 16 bits, little-endian, signed.
  • SAMPLE_FORMAT_IMA_ADPCM = 2 — Sample format is IMA-ADPCM compressed.
  • SAMPLE_LOOP_NONE = 0 — Sample does not loop.
  • SAMPLE_LOOP_FORWARD = 1 — Sample loops in forward mode.
  • SAMPLE_LOOP_PING_PONG = 2 — Sample loops in a bidirectional way.
  • FILTER_NONE = 0 — Filter is disabled.
  • FILTER_LOWPASS = 1 — Filter is a resonant lowpass.
  • FILTER_BANDPASS = 2 — Filter is a resonant bandpass.
  • FILTER_HIPASS = 3 — Filter is a resonant highpass.
  • FILTER_NOTCH = 4 — Filter is a notch (band reject).
  • FILTER_BANDLIMIT = 6 — Filter is a bandlimit (resonance used as highpass).
  • REVERB_SMALL = 0 — Small reverb room (closet, bathroom, etc).
  • REVERB_MEDIUM = 1 — Medium reverb room (living room)
  • REVERB_LARGE = 2 — Large reverb room (warehouse).
  • REVERB_HALL = 3 — Large reverb room with long decay.

Description

AudioServer is a low level server interface for audio access. It is in charge of creating sample data (playable audio) as well as its playback via a voice interface.

Member Function Description

  • void free_rid ( RID rid )

Free a RID resource.

  • float get_event_voice_global_volume_scale ( ) const

Return the global scale for event-based stream playback.

  • float get_fx_global_volume_scale ( ) const

Return the global scale for all voices.

  • float get_stream_global_volume_scale ( ) const

Return the global scale for stream playback.

Create an audio sample, return a RID referencing it. The sample will be created with a given format (from the SAMPLE_FORMAT_* enum), a total length (in samples, not bytes), in either stereo or mono.

Even if a stereo sample consists of a left sample and a right sample, it still counts as one sample for length purposes.

Return the sample data as an array of bytes. The length will be the expected length in bytes.

  • String sample_get_description ( RID sample ) const

Return the description of an audio sample. Mainly used for organization.

  • int sample_get_format ( RID sample ) const

Return the format of the audio sample, in the form of the SAMPLE_FORMAT_* enum.

  • int sample_get_length ( RID sample ) const

Return the length in samples (not bytes) of the audio sample. Even if a stereo sample consists of a left sample and a right sample, it still counts as one sample for length purposes.

  • int sample_get_loop_begin ( RID sample ) const

Return the initial loop point of a sample. Only has effect if sample loop is enabled. See sample_set_loop_format.

  • int sample_get_loop_end ( RID sample ) const

Return the final loop point of a sample. Only has effect if sample loop is enabled. See sample_set_loop_format.

  • int sample_get_loop_format ( RID sample ) const

Return the loop format for a sample, as a value from the SAMPLE_LOOP_* enum.

  • int sample_get_mix_rate ( RID sample ) const

Return the mix rate of the given sample.

  • bool sample_is_stereo ( RID sample ) const

Return whether the sample is stereo (2 channels).

Set the sample data for a given sample as an array of bytes. The length must be equal to the sample length expected in bytes or an error will be produced. The byte length can be calculated as follows:

Get the sample length (sample_get_length).

If the sample format is SAMPLE_FORMAT_PCM16, multiply it by 2.

If the sample format is SAMPLE_FORMAT_IMA_ADPCM, divide it by 2 (rounding any fraction up), then add 4.

If the sample is stereo (sample_is_stereo), multiply it by 2.

  • void sample_set_description ( RID sample, String description )

Set the description of an audio sample. Mainly used for organization.

  • void sample_set_loop_begin ( RID sample, int pos )

Set the initial loop point of a sample. Only has effect if sample loop is enabled. See sample_set_loop_format.

  • void sample_set_loop_end ( RID sample, int pos )

Set the final loop point of a sample. Only has effect if sample loop is enabled. See sample_set_loop_format.

  • void sample_set_loop_format ( RID sample, int loop_format )

Set the loop format for a sample from the SAMPLE_LOOP_* enum. As a warning, Ping Pong loops may not be available on some hardware-mixing platforms.

  • void sample_set_mix_rate ( RID sample, int mix_rate )

Change the default mix rate of a given sample.

  • void sample_set_signed_data ( RID sample, RealArray data )

Set the sample data for a given sample as an array of floats. The length must be equal to the sample length or an error will be produced.

For this method, a stereo sample is made from two samples. Thus, in case of a stereo sample, the array length must be twice the length returned by sample_get_length.

Trying to alter a SAMPLE_FORMAT_IMA_ADPCM sample is not supported. It will throw an error to the console, but will not alter the sample data.

  • void set_event_voice_global_volume_scale ( float scale )

Set global scale for event-based stream (EventStream) playback. Default is 1.0.

  • void set_fx_global_volume_scale ( float scale )

Set global scale for all voices (not including streams). Default is 1.0.

  • void set_stream_global_volume_scale ( float scale )

Set global scale for stream playback. Default is 1.0.

  • RID voice_create ( )

Allocate a voice for playback. Voices are persistent. A voice can play a single sample at the same time. See sample_create.

  • float voice_get_chorus ( RID voice ) const

Return the current chorus send for a given voice (0 to 1).

  • float voice_get_filter_cutoff ( RID voice ) const

Return the current filter cutoff (in hz) for a given voice.

  • float voice_get_filter_resonance ( RID voice ) const

Return the current filter resonance for a given voice.

  • int voice_get_filter_type ( RID voice ) const

Return the current selected filter type for a given voice, from the FILTER_* enum.

  • int voice_get_mix_rate ( RID voice ) const

Return the current mix rate for a given voice.

  • float voice_get_pan ( RID voice ) const

Return the current pan for a given voice (-1 to +1 range).

  • float voice_get_pan_depth ( RID voice ) const

Return the current pan depth for a given voice (-1 to +1 range).

  • float voice_get_pan_height ( RID voice ) const

Return the current pan height for a given voice (-1 to +1 range).

  • float voice_get_reverb ( RID voice ) const

Return the current reverb send for a given voice (0 to 1).

  • int voice_get_reverb_type ( RID voice ) const

Return the current reverb type for a given voice from the REVERB_* enum.

  • float voice_get_volume ( RID voice ) const

Return the current volume for a given voice.

  • bool voice_is_positional ( RID voice ) const

Return whether the current voice is positional. See voice_set_positional.

  • void voice_play ( RID voice, RID sample )

Start playback of a given voice using a given sample. If the voice was already playing it will be restarted.

  • void voice_set_chorus ( RID voice, float chorus )

Set chorus send post processing for the voice (from 0 to 1).

Set a resonant filter post processing for the voice. Filter type is a value from the FILTER_* enum.

  • void voice_set_mix_rate ( RID voice, int rate )

Set a different playback mix rate for the given voice.

Change the pan of a currently playing voice and, optionally, the depth and height for a positional/3D sound. Panning values are expressed within the -1 to +1 range.

  • void voice_set_positional ( RID voice, bool enabled )

Set whether a given voice is positional. This is only interpreted as a hint and used for backends that may support binaural encoding.

  • void voice_set_reverb ( RID voice, int room, float reverb )

Set the reverb send post processing for the voice (from 0 to 1) and the reverb type, from the REVERB_* enum.

  • void voice_set_volume ( RID voice, float volume )

Change the volume of a currently playing voice. Volume is expressed as linear gain where 0.0 is mute and 1.0 is default.

  • void voice_stop ( RID voice )

Stop a given voice.