Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions rpcs3/Emu/Cell/Modules/cellMusicDecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ error_code cell_music_decode_read(vm::ptr<void> buf, vm::ptr<u32> startTime, u64

if (dec.decoder.m_size == 0)
{
return CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA;
return {CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA, "m_size=0"};
}

const u64 size_left = dec.decoder.m_size - dec.read_pos;
Expand Down Expand Up @@ -227,34 +227,32 @@ error_code cell_music_decode_read(vm::ptr<void> buf, vm::ptr<u32> startTime, u64
const u64 size_to_read = std::min(reqSize, size_left);
*readSize = size_to_read;

if (size_to_read == 0)
if (size_to_read > 0)
{
return CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA; // TODO: speculative
}

std::memcpy(buf.get_ptr(), &dec.decoder.data[dec.read_pos], size_to_read);

if (size_to_read < reqSize)
{
// Set the rest of the buffer to zero to prevent loud pops at the end of the stream if the game ignores the readSize.
std::memset(vm::static_ptr_cast<u8>(buf).get_ptr() + size_to_read, 0, reqSize - size_to_read);
}
std::memcpy(buf.get_ptr(), &dec.decoder.data[dec.read_pos], size_to_read);

dec.read_pos += size_to_read;
if (size_to_read < reqSize)
{
// Set the rest of the buffer to zero to prevent loud pops at the end of the stream if the game ignores the readSize.
std::memset(vm::static_ptr_cast<u8>(buf).get_ptr() + size_to_read, 0, reqSize - size_to_read);
}

s64 start_time_ms = 0;
dec.read_pos += size_to_read;

if (!dec.decoder.timestamps_ms.empty())
{
start_time_ms = dec.decoder.timestamps_ms.front().second;
s64 start_time_ms = 0;

while (dec.decoder.timestamps_ms.size() > 1 && dec.read_pos >= ::at32(dec.decoder.timestamps_ms, 1).first)
if (!dec.decoder.timestamps_ms.empty())
{
dec.decoder.timestamps_ms.pop_front();
start_time_ms = dec.decoder.timestamps_ms.front().second;

while (dec.decoder.timestamps_ms.size() > 1 && dec.read_pos >= ::at32(dec.decoder.timestamps_ms, 1).first)
{
dec.decoder.timestamps_ms.pop_front();
}
}
}

*startTime = static_cast<u32>(start_time_ms); // startTime is milliseconds
*startTime = static_cast<u32>(start_time_ms); // startTime is milliseconds
}

switch (*position)
{
Expand All @@ -275,11 +273,15 @@ error_code cell_music_decode_read(vm::ptr<void> buf, vm::ptr<u32> startTime, u64
}
default:
{
if (size_to_read == 0)
{
return {CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA, "size_to_read=0"}; // TODO: speculative
}
break;
}
}

cellMusicDecode.trace("cell_music_decode_read(size_to_read=%d, samples=%d, start_time_ms=%d)", size_to_read, size_to_read / sizeof(u64), start_time_ms);
cellMusicDecode.trace("cell_music_decode_read(size_to_read=%d, samples=%d, start_time_ms=%d)", size_to_read, size_to_read / sizeof(u64), *startTime);

return CELL_OK;
}
Expand Down
Loading