@@ -195,7 +195,7 @@ error_code cell_music_decode_read(vm::ptr<void> buf, vm::ptr<u32> startTime, u64
195195
196196 if (dec.decoder .m_size == 0 )
197197 {
198- return CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA;
198+ return { CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA, " m_size=0 " } ;
199199 }
200200
201201 const u64 size_left = dec.decoder .m_size - dec.read_pos ;
@@ -227,34 +227,32 @@ error_code cell_music_decode_read(vm::ptr<void> buf, vm::ptr<u32> startTime, u64
227227 const u64 size_to_read = std::min (reqSize, size_left);
228228 *readSize = size_to_read;
229229
230- if (size_to_read == 0 )
230+ if (size_to_read > 0 )
231231 {
232- return CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA; // TODO: speculative
233- }
234-
235- std::memcpy (buf.get_ptr (), &dec.decoder .data [dec.read_pos ], size_to_read);
236-
237- if (size_to_read < reqSize)
238- {
239- // Set the rest of the buffer to zero to prevent loud pops at the end of the stream if the game ignores the readSize.
240- std::memset (vm::static_ptr_cast<u8 >(buf).get_ptr () + size_to_read, 0 , reqSize - size_to_read);
241- }
232+ std::memcpy (buf.get_ptr (), &dec.decoder .data [dec.read_pos ], size_to_read);
242233
243- dec.read_pos += size_to_read;
234+ if (size_to_read < reqSize)
235+ {
236+ // Set the rest of the buffer to zero to prevent loud pops at the end of the stream if the game ignores the readSize.
237+ std::memset (vm::static_ptr_cast<u8 >(buf).get_ptr () + size_to_read, 0 , reqSize - size_to_read);
238+ }
244239
245- s64 start_time_ms = 0 ;
240+ dec. read_pos += size_to_read ;
246241
247- if (!dec.decoder .timestamps_ms .empty ())
248- {
249- start_time_ms = dec.decoder .timestamps_ms .front ().second ;
242+ s64 start_time_ms = 0 ;
250243
251- while ( dec.decoder .timestamps_ms .size () > 1 && dec. read_pos >= :: at32 (dec. decoder . timestamps_ms , 1 ). first )
244+ if (! dec.decoder .timestamps_ms .empty () )
252245 {
253- dec.decoder .timestamps_ms .pop_front ();
246+ start_time_ms = dec.decoder .timestamps_ms .front ().second ;
247+
248+ while (dec.decoder .timestamps_ms .size () > 1 && dec.read_pos >= ::at32 (dec.decoder .timestamps_ms , 1 ).first )
249+ {
250+ dec.decoder .timestamps_ms .pop_front ();
251+ }
254252 }
255- }
256253
257- *startTime = static_cast <u32 >(start_time_ms); // startTime is milliseconds
254+ *startTime = static_cast <u32 >(start_time_ms); // startTime is milliseconds
255+ }
258256
259257 switch (*position)
260258 {
@@ -275,11 +273,15 @@ error_code cell_music_decode_read(vm::ptr<void> buf, vm::ptr<u32> startTime, u64
275273 }
276274 default :
277275 {
276+ if (size_to_read == 0 )
277+ {
278+ return {CELL_MUSIC_DECODE_ERROR_NO_LPCM_DATA, " size_to_read=0" }; // TODO: speculative
279+ }
278280 break ;
279281 }
280282 }
281283
282- 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 );
284+ 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 );
283285
284286 return CELL_OK;
285287}
0 commit comments