diff --git a/src/output/Internal.hxx b/src/output/Internal.hxx index 4f84fe0f5..b7c83b7b5 100644 --- a/src/output/Internal.hxx +++ b/src/output/Internal.hxx @@ -475,7 +475,7 @@ private: */ bool WaitForDelay(); - bool PlayChunk(const MusicChunk *chunk); + bool PlayChunk(const MusicChunk &chunk); /** * Plays all remaining chunks, until the tail of the pipe has diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx index 6129ddcbf..f5a579fd8 100644 --- a/src/output/OutputThread.cxx +++ b/src/output/OutputThread.cxx @@ -312,37 +312,34 @@ AudioOutput::WaitForDelay() } static ConstBuffer -ao_chunk_data(AudioOutput *ao, const MusicChunk *chunk, +ao_chunk_data(AudioOutput &ao, const MusicChunk &chunk, Filter *replay_gain_filter, unsigned *replay_gain_serial_p) { - assert(chunk != nullptr); - assert(!chunk->IsEmpty()); - assert(chunk->CheckFormat(ao->in_audio_format)); + assert(!chunk.IsEmpty()); + assert(chunk.CheckFormat(ao.in_audio_format)); - ConstBuffer data(chunk->data, chunk->length); + ConstBuffer data(chunk.data, chunk.length); - (void)ao; - - assert(data.size % ao->in_audio_format.GetFrameSize() == 0); + assert(data.size % ao.in_audio_format.GetFrameSize() == 0); if (!data.IsEmpty() && replay_gain_filter != nullptr) { replay_gain_filter_set_mode(*replay_gain_filter, - ao->replay_gain_mode); + ao.replay_gain_mode); - if (chunk->replay_gain_serial != *replay_gain_serial_p) { + if (chunk.replay_gain_serial != *replay_gain_serial_p) { replay_gain_filter_set_info(*replay_gain_filter, - chunk->replay_gain_serial != 0 - ? &chunk->replay_gain_info + chunk.replay_gain_serial != 0 + ? &chunk.replay_gain_info : nullptr); - *replay_gain_serial_p = chunk->replay_gain_serial; + *replay_gain_serial_p = chunk.replay_gain_serial; } try { data = replay_gain_filter->FilterPCM(data); } catch (const std::runtime_error &e) { FormatError(e, "\"%s\" [%s] failed to filter", - ao->name, ao->plugin.name); + ao.name, ao.plugin.name); return nullptr; } } @@ -351,21 +348,21 @@ ao_chunk_data(AudioOutput *ao, const MusicChunk *chunk, } static ConstBuffer -ao_filter_chunk(AudioOutput *ao, const MusicChunk *chunk) +ao_filter_chunk(AudioOutput &ao, const MusicChunk &chunk) { ConstBuffer data = - ao_chunk_data(ao, chunk, ao->replay_gain_filter_instance, - &ao->replay_gain_serial); + ao_chunk_data(ao, chunk, ao.replay_gain_filter_instance, + &ao.replay_gain_serial); if (data.IsEmpty()) return data; /* cross-fade */ - if (chunk->other != nullptr) { + if (chunk.other != nullptr) { ConstBuffer other_data = - ao_chunk_data(ao, chunk->other, - ao->other_replay_gain_filter_instance, - &ao->other_replay_gain_serial); + ao_chunk_data(ao, *chunk.other, + ao.other_replay_gain_filter_instance, + &ao.other_replay_gain_serial); if (other_data.IsNull()) return nullptr; @@ -380,7 +377,7 @@ ao_filter_chunk(AudioOutput *ao, const MusicChunk *chunk) if (data.size > other_data.size) data.size = other_data.size; - float mix_ratio = chunk->mix_ratio; + float mix_ratio = chunk.mix_ratio; if (mix_ratio >= 0) /* reverse the mix ratio (because the arguments to pcm_mix() are reversed), but @@ -389,14 +386,14 @@ ao_filter_chunk(AudioOutput *ao, const MusicChunk *chunk) case */ mix_ratio = 1.0 - mix_ratio; - void *dest = ao->cross_fade_buffer.Get(other_data.size); + void *dest = ao.cross_fade_buffer.Get(other_data.size); memcpy(dest, other_data.data, other_data.size); - if (!pcm_mix(ao->cross_fade_dither, dest, data.data, data.size, - ao->in_audio_format.format, + if (!pcm_mix(ao.cross_fade_dither, dest, data.data, data.size, + ao.in_audio_format.format, mix_ratio)) { FormatError(output_domain, "Cannot cross-fade format %s", - sample_format_to_string(ao->in_audio_format.format)); + sample_format_to_string(ao.in_audio_format.format)); return nullptr; } @@ -407,30 +404,30 @@ ao_filter_chunk(AudioOutput *ao, const MusicChunk *chunk) /* apply filter chain */ try { - return ao->filter_instance->FilterPCM(data); + return ao.filter_instance->FilterPCM(data); } catch (const std::runtime_error &e) { FormatError(e, "\"%s\" [%s] failed to filter", - ao->name, ao->plugin.name); + ao.name, ao.plugin.name); return nullptr; } } inline bool -AudioOutput::PlayChunk(const MusicChunk *chunk) +AudioOutput::PlayChunk(const MusicChunk &chunk) { assert(filter_instance != nullptr); - if (tags && gcc_unlikely(chunk->tag != nullptr)) { + if (tags && gcc_unlikely(chunk.tag != nullptr)) { const ScopeUnlock unlock(mutex); try { - ao_plugin_send_tag(this, *chunk->tag); + ao_plugin_send_tag(this, *chunk.tag); } catch (const std::runtime_error &e) { FormatError(e, "Failed to send tag to \"%s\" [%s]", name, plugin.name); } } - auto data = ConstBuffer::FromVoid(ao_filter_chunk(this, chunk)); + auto data = ConstBuffer::FromVoid(ao_filter_chunk(*this, chunk)); if (data.IsNull()) { Close(false); @@ -508,7 +505,7 @@ AudioOutput::Play() n = 0; } - if (!PlayChunk(chunk)) + if (!PlayChunk(*chunk)) break; pipe.Consume(*chunk);