Tscope5
audio1.c

read and play a sample from a file

#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
unsigned int l = ts5_get_sample_length(test);
printf("sample length: %u\n", l);
unsigned int f = ts5_get_sample_frequency(test);
printf("sample frequence: %u\n", f);
double t = (double)l/f;
printf("sample time: %f\n", t);
// play
do {
} while (ts5_get_sample_status(test));
// play slower
do {
} while (ts5_get_sample_status(test));
// play silently
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);
ts5_wait(0.5);
// free the sample
return 0;
}