Tscope5
Main Page
Related Pages
Files
Examples
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_samplerate
(TS5_44100);
ts5_set_audio_channels
(TS5_STEREO);
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
ts5_play_sample
(test);
do
{
}
while
(
ts5_get_sample_status
(test));
// play it at half speed
ts5_set_sample_speed
(test, 0.5);
ts5_play_sample
(test);
do
{
}
while
(
ts5_get_sample_status
(test));
ts5_set_sample_speed
(test, 1.0);
// play it at half the volume
ts5_set_sample_gain
(test, 0.5);
ts5_play_sample
(test);
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);
ts5_play_sample
(test);
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);
ts5_play_sample
(test);
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
ts5_free_sample
(test);
return
0;
}