Returns and clears the last error. Returns NULL if there is no error.
Initializes the library — this must be called before any other function is used.
samplerate
should be the samplerate used by your output device.
Sets a lock event handler. A lock handler must be set if the library will be used from multiple threads. See events.
Sets the master gain — this is the overall volume of the resultant audio
outputted by cm_process()
. This is 1
by default.
Processes and mixes all the current streams and outputs the result to dst
.
This function always outputs signed 16bit stereo interlaced. len
is the number
of samples to process, this should always be an even number.
Creates a new source using the information stored in info
. All fields of the
info
struct should be set:
Type | Field | Description |
---|---|---|
cm_EventHandler | handler | Event handler for stream |
void* | udata | User value passed to event handler in event |
int | samplerate | Native samplerate of stream |
int | length | Length in frames |
NULL is returned if an error occurs.
Loads the given file into memory and creates a source from it; NULL is returned
if an error occurs. If you want to create several sources using the same audio
data, the file should be loaded into memory and cm_new_source_from_mem()
should be used instead.
Creates a source using the file data stored in memory, the library does not own
the data
and will not free it when it is destroyed. NULL is returned if an
error occurs.
Frees all resources a source was using, if the source is playing it is stopped immediately. This should be called on a source when you are done with it; the source is no longer valid once it is destroyed.
Returns the length in seconds of the source's audio data.
Returns the current playhead position of the source in seconds.
Returns the current play state of the source, this can be one of the following:
CM_STATE_PLAYING
CM_STATE_PAUSED
CM_STATE_STOPPED
Sets the gain (volume) of the source. For example: 0.5
will make it quieter,
2
will make it louder. 1
is the default.
Sets the left-right panning of the source — -1
is fully-left, 1
is
fully-right, 0
is centered (default).
Sets the playback pitch (speed) of the source; by default this is 1
. 2
is
one octave higher, 0.5
is one octave lower.
Enables looping playback if loop
is non-zero. By default looping is disabled.
Plays the source. If the source is already playing this function has no effect;
call cm_stop()
before calling this function to play it from the beginning.
Pauses the source's playback. This stops playback without losing the current
position, calling cm_play()
will continue playing where it left off.
Stops playing and rewinds the stream's play position back to the beginning.
All event handlers are passed a pointer to a cm_Event
, the type
field of
the event is set to one of the following:
Passed to the lock handler set by cm_set_lock()
when the lock should be
acquired.
Passed to the lock handler set by cm_set_lock()
when the lock should be
released.
Passed to a source's event handler when that source is going to be destroyed. Any additional resources the source is using should be cleaned up when this event is received.
Passed to a source's event handler when more audio samples are required. The
buffer
field should be filled with the number of audio samples specified by
the length
field. The audio written should always be signed 16bit stereo
interlaced. If the stream reaches the end before it has filled the buffer it
should loop back to the beginning and continue writing to the buffer until it is
filled.
The audio written to the buffer will automatically be resampled by the library
on playback if the samplerate differs from the one passed to cm_init()
.
Passed to a source's event handler when the stream should rewind to the beginning.