Skip to content
reduz edited this page Feb 23, 2014 · 9 revisions

Sample

####Inherits: Resource ####Category: Core

Brief Description

Audio Sample (sound) class.

Member Functions

Numeric Constants

  • FORMAT_PCM8 = 0 - 8-Bits signed little endian PCM audio.
  • FORMAT_PCM16 = 1 - 16-Bits signed little endian PCM audio.
  • FORMAT_IMA_ADPCM = 2 - Ima-ADPCM Audio.
  • LOOP_NONE = 0 - No loop enabled.
  • LOOP_FORWARD = 1 - Forward looping (when playback reaches loop end, goes back to loop begin)
  • LOOP_PING_PONG = 2 - Ping-Pong looping (when playback reaches loop end, plays backward untilloop begin). Not available in all platforms.

Description

Sample provides an audio sample class, containing audio data, together with some information for playback, such as format, mix rate and loop. It is used by sound playback routines.

Member Function Description

  • void create ( int format, bool stereo, int length )

Create new data for the sample, with format "format" (see FORMAT_* enum), stereo hint, and length in frames (not samples or bytes!) "frame". Calling create overrides previous existing data if it exists. Stereo samples are interleaved pairs of left and right (in that order) points

  • int get_format ( ) const

Return the sample format (see FORMAT_* enum).

  • bool is_stereo ( ) const

Return true if the sample was created stereo.

  • int get_length ( ) const

Return the sample length in frames.

Set sample data. Data must be little endian, no matter the host platform, and exactly as long to fit all frames. Example, if data is Stereo, 16 bits, 256 frames, it will be 1024 bytes long.

Return sample data. Data will be endian, no matter with the host platform, and exactly as long to fit all frames. Example, if data is Stereo, 16 bits, 256 frames, it will be 1024 bytes long.

  • void set_mix_rate ( int hz )

Set the mix rate for the sample (expected playback frequency).

  • int get_mix_rate ( ) const

Return the mix rate for the sample (expected playback frequency).

  • void set_loop_format ( int format )

Set the loop format, see LOOP_* enum

  • int get_loop_format ( ) const

Return the loop format, see LOOP_* enum.

  • void set_loop_begin ( int pos )

Set the loop begin position, it must be a valid frame and less than the loop end position.

  • int get_loop_begin ( ) const

Return the loop begin position.

  • void set_loop_end ( int pos )

Set the loop end position, it must be a valid frame and greater than the loop begin position.

  • int get_loop_end ( ) const

Return the loop begin position.

Clone this wiki locally