diff options
Diffstat (limited to 'examples/say.c')
-rw-r--r-- | examples/say.c | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/examples/say.c b/examples/say.c index 19dcb08..e0aea9a 100644 --- a/examples/say.c +++ b/examples/say.c @@ -41,13 +41,14 @@ static void usage(int argc, char **argv, const char *message, ...) { } static int16_t sine_sample(xas_synth *synth, synth_sine *sine) { - int16_t ret; static float tau = 2.0f * M_PI; + int16_t ret; + if (sine->flags & SYNTH_STATUS_ON) { ret = (int16_t)roundf((INT16_MAX >> 2) * sinf(sine->phase)); - sine->phase += tau / (synth->sample_rate / sine->frequency); + sine->phase += tau / (synth->format.sample_rate / sine->frequency); if (sine->phase > tau) { sine->phase -= tau; @@ -80,9 +81,14 @@ int main(int argc, char **argv) { *synth_r, *output; - size_t sample_rate = 44100, - buffer_size = 735, - duration_frames = 3600, + xas_audio_format format = { + .channels = XAS_AUDIO_STEREO, + .sample_size = XAS_AUDIO_PCM_16_BIT, + .sample_rate = 44100 + }; + + size_t buffer_size = 735, + duration_frames = 3600, i; if (argc != 2) { @@ -90,24 +96,17 @@ int main(int argc, char **argv) { } if ((vox = xas_vox_new("/usr/bin/text2wave", - XAS_AUDIO_PCM_16_BIT, - sample_rate, - buffer_size, - NULL)) == NULL) { + format, + buffer_size)) == NULL) { goto error_vox_new; } - if ((bank = xas_bank_new(XAS_AUDIO_PCM_16_BIT, - 44100, - 2646000, - 4)) == NULL) { + if ((bank = xas_bank_new(format, 2646000, 4)) == NULL) { goto error_bank_new; } if ((output = xas_riff_new_file(argv[1], - XAS_AUDIO_STEREO, - XAS_AUDIO_PCM_16_BIT, - sample_rate, + format, O_WRONLY | O_CREAT | O_TRUNC)) == NULL) { goto error_riff_new_file; } @@ -120,28 +119,23 @@ int main(int argc, char **argv) { goto error_bank_stream_new; } - if ((synth_l = xas_synth_new(XAS_AUDIO_PCM_16_BIT, - sample_rate, - buffer_size, - (xas_synth_callback_sample)sine_sample, + if ((synth_l = xas_synth_new((xas_synth_callback_sample)sine_sample, (xas_synth_callback_cleanup)sine_cleanup, + format, + buffer_size, &sine_channels[0])) == NULL) { goto error_synth_new_l; } - if ((synth_r = xas_synth_new(XAS_AUDIO_PCM_16_BIT, - sample_rate, - buffer_size, - (xas_synth_callback_sample)sine_sample, + if ((synth_r = xas_synth_new((xas_synth_callback_sample)sine_sample, (xas_synth_callback_cleanup)sine_cleanup, + format, + buffer_size, &sine_channels[1])) == NULL) { goto error_synth_new_r; } - if ((mixer = xas_mixer_new(XAS_AUDIO_STEREO, - XAS_AUDIO_PCM_16_BIT, - sample_rate, - buffer_size)) == NULL) { + if ((mixer = xas_mixer_new(format, buffer_size)) == NULL) { goto error_mixer_new; } |