Reworked Highly Complete to only initialize the respective decoder core when starting playback, which greatly speeds up playlist metadata info retrieval

CQTexperiment
Chris Moeller 2013-09-30 13:35:03 -07:00
parent b002fed263
commit 4d51c93c39
1 changed files with 45 additions and 30 deletions

View File

@ -549,33 +549,9 @@ struct gsf_sound_out : public GBASoundOut
} }
}; };
- (BOOL)open:(id<CogSource>)source - (BOOL)initializeDecoder
{ {
if (![source seekable]) { NSString * decodedUrl = [[[currentSource url] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return NO;
}
currentSource = [source retain];
struct psf_info_meta_state info;
info.info = [NSMutableDictionary dictionary];
info.utf8 = false;
info.tag_length_ms = 0;
info.tag_fade_ms = 0;
info.volume_scale = 0;
NSString * decodedUrl = [[[source url] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
type = psf_load( [decodedUrl UTF8String], &source_callbacks, 0, 0, 0, psf_info_meta, &info );
if (type <= 0)
return NO;
emulatorCore = nil;
emulatorExtra = nil;
sampleRate = 44100;
if ( type == 1 ) if ( type == 1 )
{ {
@ -614,8 +590,6 @@ struct gsf_sound_out : public GBASoundOut
psx_set_refresh( emulatorCore, state.refresh ); psx_set_refresh( emulatorCore, state.refresh );
psx_set_readfile( emulatorCore, virtual_readfile, emulatorExtra ); psx_set_readfile( emulatorCore, virtual_readfile, emulatorExtra );
sampleRate = 48000;
} }
else if ( type == 0x11 || type == 0x12 ) else if ( type == 0x11 || type == 0x12 )
{ {
@ -700,6 +674,40 @@ struct gsf_sound_out : public GBASoundOut
} }
else return NO; else return NO;
return YES;
}
- (BOOL)open:(id<CogSource>)source
{
if (![source seekable]) {
return NO;
}
currentSource = [source retain];
struct psf_info_meta_state info;
info.info = [NSMutableDictionary dictionary];
info.utf8 = false;
info.tag_length_ms = 0;
info.tag_fade_ms = 0;
info.volume_scale = 0;
NSString * decodedUrl = [[[source url] absoluteString] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
type = psf_load( [decodedUrl UTF8String], &source_callbacks, 0, 0, 0, psf_info_meta, &info );
if (type <= 0)
return NO;
emulatorCore = nil;
emulatorExtra = nil;
sampleRate = 44100;
if ( type == 2 )
sampleRate = 48000;
tagLengthMs = info.tag_length_ms; tagLengthMs = info.tag_length_ms;
tagFadeMs = info.tag_fade_ms; tagFadeMs = info.tag_fade_ms;
volumeScale = info.volume_scale; volumeScale = info.volume_scale;
@ -718,6 +726,12 @@ struct gsf_sound_out : public GBASoundOut
- (int)readAudio:(void *)buf frames:(UInt32)frames - (int)readAudio:(void *)buf frames:(UInt32)frames
{ {
if ( !emulatorCore )
{
if (![self initializeDecoder])
return 0;
}
if ( type == 1 || type == 2 ) if ( type == 1 || type == 2 )
{ {
uint32_t howmany = frames; uint32_t howmany = frames;
@ -812,7 +826,8 @@ struct gsf_sound_out : public GBASoundOut
{ {
if (frame < framesRead) { if (frame < framesRead) {
[self close]; [self close];
[self open:currentSource]; if (![self initializeDecoder])
return -1;
} }
if ( type == 1 || type == 2 ) if ( type == 1 || type == 2 )