Tscope5
audio01.c
////////////////////////////////////////////////////////////////////////////////
//
// __ ______
// / /_______________ ____ ___ / ____/
// / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
// / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
// \__/____/\___/\____/ .___/\___/ /_____/
// /_/
//
// audio01.c
// - Read and play a sample from a file.
// - Play with the audio settings.
// - This example does not open a display.
////////////////////////////////////////////////////////////////////////////////
#include <tscope5.h>
#include <stdio.h>
int main()
{
// set audio parameters
ts5_set_audio_depth(TS5_FLOAT);
// read a sample
TS5_SAMPLE *test;
test = ts5_read_sample("marginaal.flac");
// get the sample length and frequency, compute time
double l = ts5_get_sample_length(test);
unsigned int f = ts5_get_sample_samplerate(test);
printf("sample length: %f\n", l);
printf("sample frequency: %u\n", f);
// play the sample, default settings
do {
} while (ts5_get_sample_status(test));
// play it at half speed
do {
} while (ts5_get_sample_status(test));
// play it at half the volume
ts5_set_sample_gain(test, 0.5);
do {
} while (ts5_get_sample_status(test));
ts5_set_sample_gain(test, 1.0);
// play on left channel
ts5_set_sample_pan(test, -1.0);
do {
} while (ts5_get_sample_status(test));
ts5_set_sample_pan(test, 0.0);
// play on right channel
ts5_set_sample_pan(test, 1.0);
do {
} while (ts5_get_sample_status(test));
ts5_set_sample_pan(test, 0.0);
// there is some delay, wait for the sample to really finish
ts5_wait(0.5);
// free the sample
return 0;
}