output/ao: round write_size down to a multiple of the frame size
This commit is contained in:
parent
be65c7d5d0
commit
67a8eedca0
1
NEWS
1
NEWS
|
@ -13,6 +13,7 @@ ver 0.21 (not yet released)
|
||||||
* output
|
* output
|
||||||
- alsa: non-blocking mode
|
- alsa: non-blocking mode
|
||||||
- alsa: change "dop" and "allowed_formats" settings at runtime
|
- alsa: change "dop" and "allowed_formats" settings at runtime
|
||||||
|
- ao: fix crash bug due to partial frames
|
||||||
- shout: support the Shine encoder plugin
|
- shout: support the Shine encoder plugin
|
||||||
- sndio: remove support for the broken RoarAudio sndio emulation
|
- sndio: remove support for the broken RoarAudio sndio emulation
|
||||||
* mixer
|
* mixer
|
||||||
|
|
|
@ -52,6 +52,8 @@ class AoOutput final : AudioOutput, SafeSingleton<AoInit> {
|
||||||
ao_option *options = nullptr;
|
ao_option *options = nullptr;
|
||||||
ao_device *device;
|
ao_device *device;
|
||||||
|
|
||||||
|
size_t frame_size;
|
||||||
|
|
||||||
AoOutput(const ConfigBlock &block);
|
AoOutput(const ConfigBlock &block);
|
||||||
~AoOutput();
|
~AoOutput();
|
||||||
|
|
||||||
|
@ -162,6 +164,8 @@ AoOutput::Open(AudioFormat &audio_format)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
frame_size = audio_format.GetFrameSize();
|
||||||
|
|
||||||
format.rate = audio_format.sample_rate;
|
format.rate = audio_format.sample_rate;
|
||||||
format.byte_format = AO_FMT_NATIVE;
|
format.byte_format = AO_FMT_NATIVE;
|
||||||
format.channels = audio_format.channels;
|
format.channels = audio_format.channels;
|
||||||
|
@ -180,8 +184,18 @@ AoOutput::Close() noexcept
|
||||||
size_t
|
size_t
|
||||||
AoOutput::Play(const void *chunk, size_t size)
|
AoOutput::Play(const void *chunk, size_t size)
|
||||||
{
|
{
|
||||||
if (size > write_size)
|
assert(size % frame_size == 0);
|
||||||
size = write_size;
|
|
||||||
|
if (size > write_size) {
|
||||||
|
/* round down to a multiple of the frame size */
|
||||||
|
size = (write_size / frame_size) * frame_size;
|
||||||
|
|
||||||
|
if (size < frame_size)
|
||||||
|
/* no matter how small "write_size" was
|
||||||
|
configured, we must pass at least one frame
|
||||||
|
to libao */
|
||||||
|
size = frame_size;
|
||||||
|
}
|
||||||
|
|
||||||
/* For whatever reason, libao wants a non-const pointer.
|
/* For whatever reason, libao wants a non-const pointer.
|
||||||
Let's hope it does not write to the buffer, and use the
|
Let's hope it does not write to the buffer, and use the
|
||||||
|
|
Loading…
Reference in New Issue