Tscope5
|
Definitions of audio functions. More...
Go to the source code of this file.
Functions | |
Audio parameters | |
The parameters of the audio output device (sound card) can be set using the functions below. The audio gain (amplification factor) can be changed at any time. All other functions functions in this group have to be called before the audio subsystem is loaded (i.e. before the first sample is loaded and played) and their settings remain unchanged until the end of the program. The parameter functions also define the settings for samples that are created with ts5_alloc_sample(). | |
unsigned int | ts5_set_audio_samplerate (unsigned int samplerate) |
Set the requested samplerate for the audio system. More... | |
unsigned int | ts5_get_audio_samplerate () |
Get the sample rate of the audio system. More... | |
unsigned int | ts5_set_audio_channels (unsigned int channels) |
Set the requested number of channels for the audio system. More... | |
unsigned int | ts5_get_audio_channels () |
Get the number of channels of the audio system. More... | |
int | ts5_set_audio_depth (int depth) |
Set the sample depth for the audio system. More... | |
int | ts5_get_audio_depth () |
Get the sample depth of the audio system. More... | |
double | ts5_set_audio_gain (double gain) |
Set the gain (amplification factor) of the audio system. More... | |
double | ts5_get_audio_gain () |
Get the gain of the audio system. More... | |
Loading samples | |
Samples can either be read from a file, or empty samples can be generated. Empty samples can be used for generating simple sounds or for recording vocal responses. Most samples (samples that contain less than 2^24 sample values) can be read completely into memory using ts5_read_sample(). Longer samples should be loaded with ts5_read_long_sample(). These will be streamed (i.e. they will be divided in parts that are read when necessary). | |
TS5_SAMPLE * | ts5_alloc_sample (double length) |
Create an empty sample. More... | |
TS5_SAMPLE * | ts5_read_sample (const char *file) |
Open a sample from a file. More... | |
TS5_SAMPLE * | ts5_read_long_sample (const char *file) |
Open a long sample from a file. More... | |
void | ts5_write_sample (const char *file, TS5_SAMPLE *sample) |
Write a sample. More... | |
void | ts5_free_sample (TS5_SAMPLE *sample) |
Free the memory used by a sample. More... | |
Playing samples | |
Audio samples can be played using the functions below. Playing a sample will not block the flow of your program. Once a sample starts playing the function call following ts5_play_sample() will be executed immediately. | |
void | ts5_play_sample (TS5_SAMPLE *sample) |
Start playing a sample. More... | |
void | ts5_pause_sample (TS5_SAMPLE *sample) |
Pause playing a sample. More... | |
void | ts5_stop_sample (TS5_SAMPLE *sample) |
Stop playing a sample. More... | |
int | ts5_get_sample_status (TS5_SAMPLE *sample) |
Query whether a sample is playing. More... | |
Manipulating sample data | |
The data of a sample can be accessed with the ts5_get_sample_data_pointer() function. This way, the user can generate simple sounds such as sine waves, white noise, etc. The process is as follows:
See audio02.c for an example that shows how this works. | |
void * | ts5_get_sample_data_pointer (TS5_SAMPLE *sample) |
Get acces to a sample's data. More... | |
Recording samples | |
Audio samples can be recorded using the functions below. The user must explicilty start the recording system by calling ts5_start_audio_recorder(). During long breaks in the program (not intertrial intervals) the user can stop the audio recorder to save resources, then start the recorder again when the program continues. Recording is a two-step process:
See audio03.c for an example that shows how this works. | |
void | ts5_start_audio_recorder () |
Start the audio recorder. More... | |
void | ts5_stop_audio_recorder () |
Stop the audio recorder. More... | |
void | ts5_flush_audio_recorder () |
Flush the audio recorder buffer. More... | |
void | ts5_record_sample (TS5_SAMPLE *sample) |
Start recording a sample. More... | |
int | ts5_get_sample_fragments (TS5_SAMPLE *sample) |
Update the sample buffer when recording. More... | |
Software voice key | |
The audio recorder can be used as a software voice key. The user has to explicitly start an audio recording to start the voice key and update the sample buffer with ts5_get_sample_fragments(). The ts5_detect_voice_onsets() function will then detect voice onsets and offsets and notify the timer functions of each onset or offset that is detected. See timer.c for more information about response registration. See audio04.c for an example that shows how the software voice key works. | |
int | ts5_define_voicekey_button (int button) |
Define the software voice key as a response button. More... | |
void | ts5_detect_voice_onsets (TS5_SAMPLE *sample) |
Detect voice onsets in a sample. More... | |
double | ts5_set_voicekey_treshold (double treshold) |
Set the voice key treshold. More... | |
double | ts5_get_voicekey_treshold () |
Get the voice key treshold. More... | |
double | ts5_set_voicekey_rise_delay (double rise_delay) |
Set the voice key rise delay. More... | |
double | ts5_get_voicekey_rise_delay () |
Get the voice key rise delay. More... | |
double | ts5_set_voicekey_drop_delay (double drop_delay) |
Set the voice key drop delay. More... | |
double | ts5_get_voicekey_drop_delay () |
Get the voice key drop delay. More... | |
Sample parameters | |
For each sample the parameters can be queried/set using the functions below:
| |
unsigned int | ts5_get_sample_samplerate (TS5_SAMPLE *sample) |
Get the sample rate of a sample. More... | |
unsigned int | ts5_get_sample_channels (TS5_SAMPLE *sample) |
Get the number of channels of a sample. More... | |
int | ts5_get_sample_depth (TS5_SAMPLE *sample) |
Get the sample depth of a sample. More... | |
double | ts5_get_sample_length (TS5_SAMPLE *sample) |
Get the length of a sample. More... | |
double | ts5_set_sample_position (TS5_SAMPLE *sample, double position) |
Set the playback position of a sample. More... | |
double | ts5_get_sample_position (TS5_SAMPLE *sample) |
Get the playback position of a sample. More... | |
double | ts5_set_sample_speed (TS5_SAMPLE *sample, double speed) |
Set the playback speed of a sample. More... | |
double | ts5_get_sample_speed (TS5_SAMPLE *sample) |
Get the playback speed of a sample. More... | |
double | ts5_set_sample_gain (TS5_SAMPLE *sample, double gain) |
Set the playback gain of a sample. More... | |
double | ts5_get_sample_gain (TS5_SAMPLE *sample) |
Get the playback gain of a sample. More... | |
double | ts5_set_sample_pan (TS5_SAMPLE *sample, double pan) |
Set the playback pan of a sample. More... | |
double | ts5_get_sample_pan (TS5_SAMPLE *sample) |
Get the playback pan of a sample. More... | |
int | ts5_set_sample_playmode (TS5_SAMPLE *sample, int playmode) |
Set the playmode of a sample. More... | |
int | ts5_get_sample_playmode (TS5_SAMPLE *sample) |
Get the playmode of a sample. More... | |
Definitions of audio functions.
Definition in file audio.c.
unsigned int ts5_set_audio_samplerate | ( | unsigned int | samplerate | ) |
Set the requested samplerate for the audio system.
samplerate | The samplerate. Can be TS5_11025, TS5_22050 or TS5_44100. |
This function has to be called before the (automatic) installation of the audio system.
Once the audio system is installed, the sample rate of the system cannot be changed.
This is only a request, the audio driver can choose non-matching values. Query the audio system after installation with ts5_get_audio_samplerate() for the actual sample rate.
This function also influences the sample rate of samples made by ts5_alloc_sample().
The default samplerate is TS5_44100.
unsigned int ts5_get_audio_samplerate | ( | ) |
unsigned int ts5_set_audio_channels | ( | unsigned int | channels | ) |
Set the requested number of channels for the audio system.
channels | The number of channels. Can be TS5_MONO or TS5_STEREO. |
This function has to be called before the (automatic) installation of the audio system.
Once the audio system is installed, the number of channels of the system cannot be changed.
This is only a request, the audio driver can choose non-matching values. Query the audio system after installation with ts5_get_audio_channels() for the actual number of channels.
This function also influences the number of channels of samples made by ts5_alloc_sample().
The default number of channels is TS5_STEREO.
unsigned int ts5_get_audio_channels | ( | ) |
int ts5_set_audio_depth | ( | int | depth | ) |
Set the sample depth for the audio system.
depth | The sample depth. Can be TS5_INTEGER or TS5_FLOAT. |
This function has to be called before the (automatic) installation of the audio system.
Once the audio system is installed, the sample depth of the system cannot be changed.
This is only a request, the audio driver can choose non-matching values. Query the audio system after installation with ts5_get_audio_depth() for the actual sample depth.
This function also influences the sample depth of samples made by ts5_alloc_sample().
The default sample depth is TS5_FLOAT.
int ts5_get_audio_depth | ( | ) |
double ts5_set_audio_gain | ( | double | gain | ) |
double ts5_get_audio_gain | ( | ) |
TS5_SAMPLE* ts5_alloc_sample | ( | double | length | ) |
Create an empty sample.
length | Length of the sample in seconds. |
A Sample's samplerate, channels and depth are set by ts5_set_audio_samplerate(), ts5_set_audio_channels() and ts5_set_audio_depth()
TS5_SAMPLE* ts5_read_sample | ( | const char * | file | ) |
TS5_SAMPLE* ts5_read_long_sample | ( | const char * | file | ) |
void ts5_write_sample | ( | const char * | file, |
TS5_SAMPLE * | sample | ||
) |
void ts5_free_sample | ( | TS5_SAMPLE * | sample | ) |
void ts5_play_sample | ( | TS5_SAMPLE * | sample | ) |
void ts5_pause_sample | ( | TS5_SAMPLE * | sample | ) |
void ts5_stop_sample | ( | TS5_SAMPLE * | sample | ) |
int ts5_get_sample_status | ( | TS5_SAMPLE * | sample | ) |
void* ts5_get_sample_data_pointer | ( | TS5_SAMPLE * | sample | ) |
void ts5_start_audio_recorder | ( | ) |
void ts5_stop_audio_recorder | ( | ) |
void ts5_flush_audio_recorder | ( | ) |
void ts5_record_sample | ( | TS5_SAMPLE * | sample | ) |
int ts5_get_sample_fragments | ( | TS5_SAMPLE * | sample | ) |
int ts5_define_voicekey_button | ( | int | button | ) |
Define the software voice key as a response button.
button | Number of the button (buttons are counted from 1). |
Give a positive number for the button if you want to monitor button press events, a negative number if you want to monitor button release events.
void ts5_detect_voice_onsets | ( | TS5_SAMPLE * | sample | ) |
double ts5_set_voicekey_treshold | ( | double | treshold | ) |
double ts5_get_voicekey_treshold | ( | ) |
double ts5_set_voicekey_rise_delay | ( | double | rise_delay | ) |
double ts5_get_voicekey_rise_delay | ( | ) |
double ts5_set_voicekey_drop_delay | ( | double | drop_delay | ) |
double ts5_get_voicekey_drop_delay | ( | ) |
unsigned int ts5_get_sample_samplerate | ( | TS5_SAMPLE * | sample | ) |
unsigned int ts5_get_sample_channels | ( | TS5_SAMPLE * | sample | ) |
int ts5_get_sample_depth | ( | TS5_SAMPLE * | sample | ) |
double ts5_get_sample_length | ( | TS5_SAMPLE * | sample | ) |
double ts5_set_sample_position | ( | TS5_SAMPLE * | sample, |
double | position | ||
) |
double ts5_get_sample_position | ( | TS5_SAMPLE * | sample | ) |
double ts5_set_sample_speed | ( | TS5_SAMPLE * | sample, |
double | speed | ||
) |
double ts5_get_sample_speed | ( | TS5_SAMPLE * | sample | ) |
double ts5_set_sample_gain | ( | TS5_SAMPLE * | sample, |
double | gain | ||
) |
double ts5_get_sample_gain | ( | TS5_SAMPLE * | sample | ) |
double ts5_set_sample_pan | ( | TS5_SAMPLE * | sample, |
double | pan | ||
) |
double ts5_get_sample_pan | ( | TS5_SAMPLE * | sample | ) |
int ts5_set_sample_playmode | ( | TS5_SAMPLE * | sample, |
int | playmode | ||
) |