mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2024-12-22 13:25:33 +00:00
sio_sine: add phase wrap around
closes #110 Thanks to @iskunk for the fix.
This commit is contained in:
parent
323fb1aa27
commit
6703021eba
|
@ -95,7 +95,8 @@ static void write_callback(struct SoundIoOutStream *outstream,
|
||||||
*ptr = sample;
|
*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))) {
|
if ((err = soundio_outstream_end_write(outstream))) {
|
||||||
fprintf(stderr, "%s\n", soundio_strerror(err));
|
fprintf(stderr, "%s\n", soundio_strerror(err));
|
||||||
|
|
|
@ -77,13 +77,13 @@ static void write_callback(struct SoundIoOutStream *outstream, int frame_count_m
|
||||||
double pitch = 440.0;
|
double pitch = 440.0;
|
||||||
double radians_per_second = pitch * 2.0 * PI;
|
double radians_per_second = pitch * 2.0 * PI;
|
||||||
for (int frame = 0; frame < frame_count; frame += 1) {
|
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) {
|
for (int channel = 0; channel < layout->channel_count; channel += 1) {
|
||||||
write_sample(areas[channel].ptr, sample);
|
write_sample(areas[channel].ptr, sample);
|
||||||
areas[channel].ptr += areas[channel].step;
|
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 = soundio_outstream_end_write(outstream))) {
|
||||||
if (err == SoundIoErrorUnderflow)
|
if (err == SoundIoErrorUnderflow)
|
||||||
|
|
Loading…
Reference in a new issue