[APU] Set first frame offset for next buffer + Note about edgecase

This commit is contained in:
Gliniak 2022-12-13 22:57:36 +01:00
parent e00feb7b0f
commit b2dd489151
2 changed files with 26 additions and 0 deletions

View File

@ -715,6 +715,8 @@ void XmaContext::Decode(XMA_CONTEXT_DATA* data) {
if (!reuse_input_buffer) { if (!reuse_input_buffer) {
if (is_streaming) { if (is_streaming) {
SwapInputBuffer(data); SwapInputBuffer(data);
data->input_buffer_read_offset =
GetPacketFirstFrameOffset(data);
} else { } else {
is_stream_done_ = true; is_stream_done_ = true;
} }
@ -726,6 +728,9 @@ void XmaContext::Decode(XMA_CONTEXT_DATA* data) {
} }
} }
packet = current_input_buffer + packet_idx * kBytesPerPacket; packet = current_input_buffer + packet_idx * kBytesPerPacket;
// TODO(Gliniak): There might be an edge-case when we're in packet 26/27
// and GetPacketFrameOffset returns that there is no data in this packet
// aka. FrameOffset is set to more than 0x7FFF-0x20
offset = offset =
xma::GetPacketFrameOffset(packet) + packet_idx * kBitsPerPacket; xma::GetPacketFrameOffset(packet) + packet_idx * kBitsPerPacket;
} }
@ -765,6 +770,23 @@ void XmaContext::Decode(XMA_CONTEXT_DATA* data) {
} }
} }
uint32_t XmaContext::GetPacketFirstFrameOffset(const XMA_CONTEXT_DATA* data) {
uint32_t first_frame_offset = kBitsPerHeader;
uint8_t* in0 = data->input_buffer_0_valid
? memory()->TranslatePhysical(data->input_buffer_0_ptr)
: nullptr;
uint8_t* in1 = data->input_buffer_1_valid
? memory()->TranslatePhysical(data->input_buffer_1_ptr)
: nullptr;
uint8_t* current_input_buffer = data->current_buffer ? in1 : in0;
if (current_input_buffer) {
first_frame_offset = xma::GetPacketFrameOffset(current_input_buffer);
}
return first_frame_offset;
}
size_t XmaContext::GetNextFrame(uint8_t* block, size_t size, size_t XmaContext::GetNextFrame(uint8_t* block, size_t size,
size_t bit_offset) { size_t bit_offset) {
// offset = xma::GetPacketFrameOffset(packet); // offset = xma::GetPacketFrameOffset(packet);

View File

@ -196,6 +196,10 @@ class XmaContext {
void Decode(XMA_CONTEXT_DATA* data); void Decode(XMA_CONTEXT_DATA* data);
int PrepareDecoder(uint8_t* packet, int sample_rate, bool is_two_channel); int PrepareDecoder(uint8_t* packet, int sample_rate, bool is_two_channel);
// This method should be used ONLY when we're at the last packet of the stream
// and we want to find offset in next buffer
uint32_t GetPacketFirstFrameOffset(const XMA_CONTEXT_DATA* data);
Memory* memory_ = nullptr; Memory* memory_ = nullptr;
uint32_t id_ = 0; uint32_t id_ = 0;