CoreAudio input: Optimized file size reporting to cache the file size on open, so file input isn't seeking as much

CQTexperiment
Christopher Snowhill 2021-08-25 01:57:05 -07:00
parent a1a0bd2db4
commit 5b73336cb0
2 changed files with 5 additions and 9 deletions

View File

@ -29,6 +29,7 @@
@interface CoreAudioDecoder : NSObject <CogDecoder>
{
@public long _lastPosition;
@public long _fileSize;
id<CogSource> _audioSource;
AudioFileID _audioFile;
ExtAudioFileRef _in;

View File

@ -61,15 +61,7 @@ static SInt64 getSizeProc(void* clientData) {
NSObject* _handle = (__bridge NSObject *)(clientData);
CoreAudioDecoder * __unsafe_unretained pSelf = (id) _handle;
id<CogSource> source = pSelf->_audioSource;
SInt64 size;
[source seek:0 whence:SEEK_END];
size = [source tell];
[source seek:pSelf->_lastPosition whence:SEEK_SET];
return size;
return pSelf->_fileSize;
}
@implementation CoreAudioDecoder
@ -114,6 +106,9 @@ static SInt64 getSizeProc(void* clientData) {
_audioSource = source;
_lastPosition = [source tell];
[source seek:0 whence:SEEK_END];
_fileSize = [source tell];
[source seek:_lastPosition whence:SEEK_SET];
err = AudioFileOpenWithCallbacks((__bridge void *)self, readProc, 0, getSizeProc, 0, 0, &_audioFile);
if(noErr != err) {