diff --git a/src/core/libraries/ajm/ajm_at9.cpp b/src/core/libraries/ajm/ajm_at9.cpp index 50c0e944..280c6be7 100644 --- a/src/core/libraries/ajm/ajm_at9.cpp +++ b/src/core/libraries/ajm/ajm_at9.cpp @@ -65,7 +65,6 @@ void AjmAt9Decoder::GetCodecInfo(void* out_info) { } void AjmAt9Decoder::Decode(const AjmJobInput* input, AjmJobOutput* output) { - LOG_TRACE(Lib_Ajm, "Decoding with instance {} in size = {}", index, input->buffer.size()); Atrac9CodecInfo codec_info; Atrac9GetCodecInfo(handle, &codec_info); @@ -125,16 +124,18 @@ void AjmAt9Decoder::Decode(const AjmJobInput* input, AjmJobOutput* output) { } } } else { - written = - write_output({pcm_buffer.data(), std::min(pcm_buffer.size(), samples_remain)}); - total_decoded_samples += codec_info.frameSamples; + const auto pcm_size = std::min(pcm_buffer.size(), samples_remain); + const auto nsamples = pcm_size / codec_info.channels; + written = write_output({pcm_buffer.data(), pcm_size}); + total_decoded_samples += nsamples; if (gapless.total_samples != 0) { - gapless_decoded_samples += codec_info.frameSamples; + gapless_decoded_samples += nsamples; } } num_frames += 1; if ((num_frames % codec_info.framesInSuperframe) == 0) { + num_frames = 0; if (superframe_bytes_remain) { if (output->p_stream) { output->p_stream->input_consumed += superframe_bytes_remain; @@ -156,10 +157,9 @@ void AjmAt9Decoder::Decode(const AjmJobInput* input, AjmJobOutput* output) { } } - if (gapless.total_samples != 0 && gapless_decoded_samples >= gapless.total_samples) { - if (flags.gapless_loop) { - ResetCodec(); - } + if (flags.gapless_loop && gapless.total_samples != 0 && + gapless_decoded_samples >= gapless.total_samples) { + ResetCodec(); } if (output->p_stream) { diff --git a/src/core/libraries/ajm/ajm_at9.h b/src/core/libraries/ajm/ajm_at9.h index 919314f2..2885158e 100644 --- a/src/core/libraries/ajm/ajm_at9.h +++ b/src/core/libraries/ajm/ajm_at9.h @@ -25,11 +25,8 @@ struct AjmSidebandDecAt9CodecInfo { }; struct AjmAt9Decoder final : AjmInstance { - void* handle; - bool decoder_initialized = false; - std::fstream file; - int length; - u8 config_data[ORBIS_AT9_CONFIG_DATA_SIZE]; + void* handle{}; + u8 config_data[ORBIS_AT9_CONFIG_DATA_SIZE]{}; u32 superframe_bytes_remain{}; u32 num_frames{}; diff --git a/src/core/libraries/ajm/ajm_mp3.cpp b/src/core/libraries/ajm/ajm_mp3.cpp index 71b3fd3b..1f4b76c1 100644 --- a/src/core/libraries/ajm/ajm_mp3.cpp +++ b/src/core/libraries/ajm/ajm_mp3.cpp @@ -74,6 +74,7 @@ void AjmMp3Decoder::Reset() { int ret = avcodec_open2(c, codec, nullptr); ASSERT_MSG(ret >= 0, "Could not open codec"); total_decoded_samples = 0; + gapless_decoded_samples = 0; } void AjmMp3Decoder::Decode(const AjmJobInput* input, AjmJobOutput* output) { @@ -138,13 +139,12 @@ void AjmMp3Decoder::Decode(const AjmJobInput* input, AjmJobOutput* output) { if (frame->format != AV_SAMPLE_FMT_S16) { frame = ConvertAudioFrame(frame); } - const auto frame_samples = frame->ch_layout.nb_channels * frame->nb_samples; - const auto size = frame_samples * sizeof(u16); + const auto size = frame->ch_layout.nb_channels * frame->nb_samples * sizeof(u16); if (gapless.skipped_samples < gapless.skip_samples) { - gapless.skipped_samples += frame_samples; + gapless.skipped_samples += frame->nb_samples; if (gapless.skipped_samples > gapless.skip_samples) { const u32 nsamples = gapless.skipped_samples - gapless.skip_samples; - const auto start = frame_samples - nsamples; + const auto start = frame->nb_samples - nsamples; write_output({reinterpret_cast(frame->data[0]), nsamples}); gapless.skipped_samples = gapless.skip_samples; total_decoded_samples += nsamples; @@ -154,9 +154,9 @@ void AjmMp3Decoder::Decode(const AjmJobInput* input, AjmJobOutput* output) { } } else { write_output({reinterpret_cast(frame->data[0]), size >> 1}); - total_decoded_samples += frame_samples; + total_decoded_samples += frame->nb_samples; if (gapless.total_samples != 0) { - gapless_decoded_samples += frame_samples; + gapless_decoded_samples += frame->nb_samples; } } av_frame_free(&frame);