@@ -350,22 +350,20 @@ void Decode(XmaPlayback *playback) {
350350 uint32_t o = 0 ;
351351 if (playback->av_frame_ ->nb_samples != 0 ) {
352352 for (uint32_t i = 0 ; i < kSamplesPerFrame ; i++) {
353- for (uint32_t j = 0 ; j <= uint32_t ( true ) ; j++) {
353+ for (uint32_t j = 0 ; j < playback-> av_frame_ -> ch_layout . nb_channels ; j++) {
354354 // Select the appropriate array based on the current channel.
355355 auto in = reinterpret_cast <const float *>(samples[j]);
356356
357- if (in != nullptr ) {
358- // Raw samples sometimes aren't within [-1, 1]
359- float scaled_sample = clamp_float (in[i], -1 .0f , 1 .0f ) * scale;
357+ // Raw samples sometimes aren't within [-1, 1]
358+ float scaled_sample = clamp_float (in[i], -1 .0f , 1 .0f ) * scale;
360359
361- // Convert the sample and output it in big endian.
362- auto sample = static_cast <int16_t >(scaled_sample);
363- out[o++] = ByteSwap (sample);
364- }
360+ // Convert the sample and output it in big endian.
361+ auto sample = static_cast <int16_t >(scaled_sample);
362+ out[o++] = ByteSwap (sample);
365363 }
366364 }
367365 }
368- playback->current_frame_remaining_subframes_ = 4 << 1 ;
366+ playback->current_frame_remaining_subframes_ = 4 * playback-> channelCount ;
369367
370368 if (!packet_info.isLastFrameInPacket ()) {
371369 const uint32_t next_frame_offset =
@@ -427,7 +425,7 @@ void Consume(XmaPlayback *playback) {
427425 (int8_t )playback->subframes );
428426
429427 const int8_t raw_frame_read_offset =
430- ((kBytesPerFrameChannel / kOutputBytesPerBlock ) << 1 ) - // is stereo
428+ ((kBytesPerFrameChannel / kOutputBytesPerBlock ) * playback-> channelCount )
431429 playback->current_frame_remaining_subframes_ ;
432430 // + data->subframe_skip_count;
433431
@@ -472,7 +470,7 @@ void DecoderThreadFunc(XmaPlayback *playback) {
472470
473471 uint8_t *current_input_buffer = playback->GetCurrentInputBuffer ();
474472
475- const int32_t minimum_subframe_decode_count = (playback->subframes * 2 ) - 1 ;
473+ const int32_t minimum_subframe_decode_count = (playback->subframes * playback-> channelCount ) - 1 ;
476474
477475 size_t output_capacity =
478476 playback->output_buffer_block_count * kOutputBytesPerBlock ;
@@ -673,7 +671,7 @@ uint32_t XMAPlaybackQueryAvailableData(XmaPlayback *playback, uint32_t stream) {
673671 available_blocks = offset_write - write_buffer_offset_read;
674672 }
675673 uint32_t total_bytes = (available_blocks << 8 ) + available_bytes;
676- uint32_t bytes_per_sample = 1 + 1 ; // TODO: find all channels and refactor
674+ uint32_t bytes_per_sample = playback-> channelCount ;
677675 debug_printf (" samples accessed: %d\n " , total_bytes >> bytes_per_sample);
678676 return total_bytes >> bytes_per_sample;
679677}
@@ -715,7 +713,7 @@ uint32_t XMAPlaybackAccessDecodedData(XmaPlayback *playback, uint32_t stream,
715713 available_blocks = offset_write - write_buffer_offset_read;
716714 }
717715 uint32_t total_bytes = (available_blocks << 8 ) + available_bytes;
718- uint32_t bytes_per_sample = 1 + 1 ; // TODO: find all channels and refactor
716+ uint32_t bytes_per_sample = playback-> channelCount ;
719717 debug_printf (" samples accessed: %d\n " , total_bytes >> bytes_per_sample);
720718 return total_bytes >> bytes_per_sample;
721719}
@@ -735,7 +733,7 @@ uint32_t XMAPlaybackConsumeDecodedData(XmaPlayback *playback, uint32_t stream,
735733 partial_bytes_read);
736734 ;
737735 *data = (uint32_t *)__builtin_bswap32 (addr);
738- uint32_t bytes_per_sample = 1 + 1 ;
736+ uint32_t bytes_per_sample = playback-> channelCount ;
739737 uint32_t bytes_desired = maxSamples << bytes_per_sample;
740738 if (partial_bytes_read) {
741739 if (bytes_desired < 256 - partial_bytes_read) {
0 commit comments