Tscope5
Main Page
Related Pages
Files
Examples
audio03.c
////////////////////////////////////////////////////////////////////////////////
//
// __ ______
// / /_______________ ____ ___ / ____/
// / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
// / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
// \__/____/\___/\____/ .___/\___/ /_____/
// /_/
//
// audio03.c
// - Record an audio sample.
// - Save it to a file.
////////////////////////////////////////////////////////////////////////////////
#include <tscope5.h>
#include <stdio.h>
int
main()
{
// install a display
ts5_install_display
();
// define the escape key
ts5_define_keyboard_button
(TS5_KEY_ESCAPE);
// set some audio parameters
// default is CD quality but that's
// probably overkill
ts5_set_audio_samplerate
(TS5_22050);
ts5_set_audio_channels
(TS5_STEREO);
// start the audio recorder
ts5_start_audio_recorder
();
// allocate an audio sample
TS5_SAMPLE *test =
ts5_alloc_sample
(10.0);
// fixation point
ts5_printf
(0.0, 0.0,
"+"
);
ts5_flip_display
();
ts5_wait
(0.5);
// blank
ts5_clear_display
();
ts5_flip_display
();
ts5_wait
(0.5);
// stimulus
ts5_clear_display
();
ts5_printf
(0.0, 0.0,
"tscope is de max"
);
// display the stimulus, start timing and start recording
ts5_flip_display
();
ts5_flush_responses
();
ts5_record_sample
(test);
// record until the buffer is full or
// until the user presses escape
while
(!
ts5_get_sample_fragments
(test) && !
ts5_check_response
(NULL, NULL)) {
// here you can do whatever you want
// the recording buffer is around 10 seconds
};
// save the recording
ts5_write_sample
(
"test.wav"
, test);
ts5_free_sample
(test);
// stop the audio recorder
ts5_stop_audio_recorder
();
return
0;
}