sio_sine: add phase wrap around

closes #110

Thanks to @iskunk for the fix.
This commit is contained in:
Andrew Kelley 2016-10-23 16:11:58 -04:00
parent 323fb1aa27
commit 6703021eba
2 changed files with 4 additions and 3 deletions

View file

@ -95,7 +95,8 @@ static void write_callback(struct SoundIoOutStream *outstream,
*ptr = sample;
}
}
seconds_offset += seconds_per_frame * frame_count;
seconds_offset = fmodf(seconds_offset +
seconds_per_frame * frame_count, 1.0f);
if ((err = soundio_outstream_end_write(outstream))) {
fprintf(stderr, "%s\n", soundio_strerror(err));

View file

@ -77,13 +77,13 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m
double pitch = 440.0;
double radians_per_second = pitch * 2.0 * PI;
for (int frame = 0; frame < frame_count; frame += 1) {
double sample = sinf((seconds_offset + frame * seconds_per_frame) * radians_per_second);
double sample = sin((seconds_offset + frame * seconds_per_frame) * radians_per_second);
for (int channel = 0; channel < layout->channel_count; channel += 1) {
write_sample(areas[channel].ptr, sample);
areas[channel].ptr += areas[channel].step;
}
}
seconds_offset += seconds_per_frame * frame_count;
seconds_offset = fmod(seconds_offset + seconds_per_frame * frame_count, 1.0);
if ((err = soundio_outstream_end_write(outstream))) {
if (err == SoundIoErrorUnderflow)