summaryrefslogtreecommitdiffstats
path: root/examples/test.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/test.c')
-rw-r--r--examples/test.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/examples/test.c b/examples/test.c
index 24e6ba1..1fbd8c4 100644
--- a/examples/test.c
+++ b/examples/test.c
@@ -45,7 +45,7 @@ static int16_t sine_sample(xas_synth *synth, synth_sine *sine) {
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;
@@ -73,8 +73,13 @@ int main(int argc, char **argv) {
{ SYNTH_STATUS_ON, 0.0f, 420 },
};
- size_t sample_rate = 44100,
- buffer_size = 4096,
+ xas_audio_format format = {
+ .channels = XAS_AUDIO_STEREO,
+ .sample_size = XAS_AUDIO_PCM_16_BIT,
+ .sample_rate = 44100
+ };
+
+ size_t buffer_size = 4096,
duration_s = 60,
i;
@@ -83,35 +88,28 @@ int main(int argc, char **argv) {
}
if ((wave = 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;
}
- 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;
}
@@ -129,7 +127,7 @@ int main(int argc, char **argv) {
if ((readlen = xas_audio_stream_read(mixer->output,
&buf,
- sample_rate)) < 0) {
+ buffer_size)) < 0) {
goto error_audio_stream_read;
}