From f32632abd018e36ac3e0e63cbf17dbef2acc55ba Mon Sep 17 00:00:00 2001 From: vspader Date: Fri, 12 May 2006 00:34:56 +0000 Subject: [PATCH] Fixed seeking --- Playlist/PlaylistController.m | 2 +- Sound/SoundFile/CoreAudioFile.h | 1 + Sound/SoundFile/CoreAudioFile.m | 19 ++++++++++++++----- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index f3d62321d..8ec31e92f 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -10,7 +10,7 @@ #import "PlaylistEntry.h" #import "Shuffle.h" -extern NSArray * getCoreAudioExtensions(); +#import "CoreAudioUtils.h" @implementation PlaylistController diff --git a/Sound/SoundFile/CoreAudioFile.h b/Sound/SoundFile/CoreAudioFile.h index f975aeafb..90f08b2c8 100644 --- a/Sound/SoundFile/CoreAudioFile.h +++ b/Sound/SoundFile/CoreAudioFile.h @@ -32,6 +32,7 @@ SInt64 _totalPackets; UInt32 _maxPacketSize; + UInt32 _framesPerPacket; AudioConverterRef _converter; void *_convBuf; diff --git a/Sound/SoundFile/CoreAudioFile.m b/Sound/SoundFile/CoreAudioFile.m index 527253447..651bcbcc7 100644 --- a/Sound/SoundFile/CoreAudioFile.m +++ b/Sound/SoundFile/CoreAudioFile.m @@ -224,12 +224,14 @@ OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPac channels = asbd.mChannelsPerFrame; frequency = asbd.mSampleRate; + _framesPerPacket = asbd.mFramesPerPacket; + // mBitsPerChannel will only be set for lpcm formats if(0 == bitsPerSample) { bitsPerSample = 16; } - totalSize = _totalPackets * asbd.mFramesPerPacket *channels * (bitsPerSample/8); + totalSize = _totalPackets * asbd.mFramesPerPacket *channels * (bitsPerSample/8); isBigEndian = YES; isUnsigned = NO; @@ -331,11 +333,18 @@ OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32 *ioNumberDataPac - (double) seekToTime:(double)milliseconds { - [_countLock lock]; - _packetCount = ((milliseconds / 1000.f) * frequency); - [_countLock unlock]; + double newTime; - return YES; + NSLog(@"Seeking to: %lf", milliseconds); + NSLog(@"Max frames: %lli", _totalPackets); + [_countLock lock]; + _packetCount = ((milliseconds / 1000.f) * frequency)/_framesPerPacket; + NSLog(@"Seeking in coreaudio: %lli", _packetCount); + [_countLock unlock]; + + newTime = ((_packetCount * _framesPerPacket)/frequency)*1000.0; + + return newTime; } @end