#include <csl/cslsample.h>
#include <csl/cslmain.h>
#include <csl/cslutils.h>
#include <csl/cslprivate.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
Functions | |
CslErrorType | csl_sample_new (CslDriver *driver, const char *name, const char *role, const char *title, CslSample **sample_p) |
Create a new sample. More... | |
CslErrorType | csl_sample_new_from_file (CslDriver *driver, const char *name, const char *role, const char *title, CslSample **sample_p) |
Create a sample from a file. More... | |
int | csl_sample_write (CslSample *sample, unsigned int n_bytes, void *bytes) |
Write data into a sample. More... | |
CslErrorType | csl_sample_write_done (CslSample *sample) |
Finish writing data into a sample. More... | |
CslErrorType | csl_sample_play (CslSample *sample) |
Play a sound sample. More... | |
void | csl_sample_release (CslSample *sample) |
Free a sound sample. More... | |
CslErrorType | csl_sample_new_from_cache (CslDriver *driver, const char *name, const char *role, const char *title, CslSample **sample_p) |
Obtain a sample from the sample cache. More... | |
CslErrorType | csl_sample_cache_remove (CslSample *sample) |
Remove a sound sample from the sample cache. More... | |
CslErrorType | csl_sample_cache_add (CslSample *sample) |
Add a sound sample to the sample cache. More... | |
CslBool | csl_sample_is_playing (CslSample *sample) |
Check whether a sample is being played. More... | |
CslErrorType | csl_sample_stop (CslSample *sample) |
Stop playing a sample. More... | |
CslErrorType | csl_sample_wait_done (CslSample *sample) |
Wait until playing a sample is done. More... |
The CSL sample API provides a simple means for playing PCM sound samples. You create samples from files or PCM sound data, and send them to the sound server to be played. You can reuse the sample multiple times and share samples with other apps if they are using the same sound server.
Typical usage will follow these steps:
|
Add a sound sample to the sample cache. This adds a sample to the sample cache. It will remain cached even after calling csl_sample_free until csl_sample_cache_remove is called or the sound server is restarted.
|
|
Remove a sound sample from the sample cache. This tells the library to remove a sample from the sample cache.
|
|
Check whether a sample is being played. This checks whether a sample is currently being played. If you have started a sample multiple times at once, this will return whether at least one of them is still being played.
|
|
Create a new sample. This creates a new (empty) sample which can be played back later. In order to use the sample you need to write PCM data into it using csl_sample_write.
|
|
Obtain a sample from the sample cache. This function attempts to find a sound sample in the sample cache. If found, it returns the sample, otherwise it returns an error status.
|
|
Create a sample from a file. This creates a sample from an existing sound file (e.g. .wav file). It is equivalent to calling csl_sample_new, writing the file contents using csl_sample_write, and then calling csl_sample_finish.
|
|
Play a sound sample. This plays a sound sample. Note that playing a sample will return immediately. You can use csl_sample_is_playing to check whether it is still playing or csl_sample_wait_done to wait until it is done.
|
|
Free a sound sample. This releases the resources associated with a sound sample. You should release a sample when it is no longer required. You must not use the sample after it has been release. A currently playing sample will not be stopped through this function though, use csl_sample_stop if you want that.
|
|
Stop playing a sample. This stops playing a sample (which was started with csl_sample_play) immediately.
|
|
Wait until playing a sample is done. This waits until playing a sample (which was started with csl_sample_play) is done.
|
|
Write data into a sample. This writes PCM data into an empty sample, previously created using csl_sample_new. You can call this function multiple times if desired, and the data will be concatenated together. You indicate that no more data needs to be written by calling csl_sample_finish. The data format is inferred from the name used when the sample is created with csl_sample_new.
|
|
Finish writing data into a sample. This is called after one or more calls to csl_sample_write to indicate that you are finished writing data into the sample. The sample is now ready to be played using csl_sample_play.
|