Seeking works?
parent
192af8cb46
commit
ee3c01aaed
|
@ -129,7 +129,7 @@
|
||||||
double time;
|
double time;
|
||||||
time = [positionSlider doubleValue];
|
time = [positionSlider doubleValue];
|
||||||
|
|
||||||
if ([sender tracking] == NO) // check if user stopped sliding before playing audio
|
// if ([sender tracking] == NO) // check if user stopped sliding before playing audio
|
||||||
[soundController seekToTime:time];
|
[soundController seekToTime:time];
|
||||||
|
|
||||||
[self updateTimeField:time];
|
[self updateTimeField:time];
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
- (id)initWithController:(id)c;
|
- (id)initWithController:(id)c;
|
||||||
- (void)buildChain;
|
- (void)buildChain;
|
||||||
- (BOOL)open:(const char *)filename;
|
- (BOOL)open:(const char *)filename;
|
||||||
|
- (void)seek:(double)time;
|
||||||
|
|
||||||
- (void)launchThreads;
|
- (void)launchThreads;
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,13 @@
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)seek:(double)time
|
||||||
|
{
|
||||||
|
[inputNode seek:time];
|
||||||
|
[inputNode resetBuffer];
|
||||||
|
[converterNode resetBuffer];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (id)finalNode
|
- (id)finalNode
|
||||||
{
|
{
|
||||||
|
|
|
@ -185,8 +185,8 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
|
||||||
{
|
{
|
||||||
return [self convert:dest amount:amount];
|
return [self convert:dest amount:amount];
|
||||||
}
|
}
|
||||||
if (err != noErr)
|
// if (err != noErr)
|
||||||
NSLog(@"Converter error: %i", err);
|
// NSLog(@"Converter error: %i", err);
|
||||||
|
|
||||||
return ioData.mBuffers[0].mDataByteSize;
|
return ioData.mBuffers[0].mDataByteSize;
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -19,9 +19,14 @@
|
||||||
AudioStreamBasicDescription format;
|
AudioStreamBasicDescription format;
|
||||||
|
|
||||||
SoundFile *soundFile;
|
SoundFile *soundFile;
|
||||||
|
|
||||||
|
BOOL shouldSeek;
|
||||||
|
double seekTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)process;
|
- (void)process;
|
||||||
- (AudioStreamBasicDescription) format;
|
- (AudioStreamBasicDescription) format;
|
||||||
|
- (void)seek:(double)time;
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -18,33 +18,47 @@
|
||||||
[soundFile getFormat:&format];
|
[soundFile getFormat:&format];
|
||||||
|
|
||||||
shouldContinue = YES;
|
shouldContinue = YES;
|
||||||
|
shouldSeek = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)process
|
- (void)process
|
||||||
{
|
{
|
||||||
const int chunk_size = CHUNK_SIZE;
|
const int chunk_size = CHUNK_SIZE;
|
||||||
char buf[chunk_size];
|
char *buf;
|
||||||
int amountRead;
|
int amountRead;
|
||||||
|
|
||||||
DBLog(@"Playing file.\n");
|
DBLog(@"Playing file.\n");
|
||||||
|
buf = malloc(chunk_size);
|
||||||
|
|
||||||
while ([self shouldContinue] == YES && [self endOfStream] == NO)
|
while ([self shouldContinue] == YES && [self endOfStream] == NO)
|
||||||
{
|
{
|
||||||
|
if (shouldSeek == YES)
|
||||||
|
{
|
||||||
|
[soundFile seekToTime:seekTime];
|
||||||
|
shouldSeek = NO;
|
||||||
|
}
|
||||||
|
|
||||||
amountRead = [soundFile fillBuffer:buf ofSize: chunk_size];
|
amountRead = [soundFile fillBuffer:buf ofSize: chunk_size];
|
||||||
if (amountRead <= 0)
|
if (amountRead <= 0)
|
||||||
{
|
{
|
||||||
endOfStream = YES;
|
endOfStream = YES;
|
||||||
NSLog(@"END OF INPUT WAS REACHED");
|
NSLog(@"END OF INPUT WAS REACHED");
|
||||||
[controller endOfInputReached];
|
[controller endOfInputReached];
|
||||||
[soundFile close];
|
break; //eof
|
||||||
return; //eof
|
|
||||||
}
|
}
|
||||||
[self writeData:buf amount:amountRead];
|
[self writeData:buf amount:amountRead];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
[soundFile close];
|
[soundFile close];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)seek:(double)time
|
||||||
|
{
|
||||||
|
seekTime = time;
|
||||||
|
shouldSeek = YES;
|
||||||
|
}
|
||||||
|
|
||||||
- (AudioStreamBasicDescription) format
|
- (AudioStreamBasicDescription) format
|
||||||
{
|
{
|
||||||
return format;
|
return format;
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
@interface Node : NSObject {
|
@interface Node : NSObject {
|
||||||
VirtualRingBuffer *buffer;
|
VirtualRingBuffer *buffer;
|
||||||
Semaphore *semaphore;
|
Semaphore *semaphore;
|
||||||
|
NSLock *readLock;
|
||||||
|
NSLock *writeLock;
|
||||||
|
|
||||||
id previousNode;
|
id previousNode;
|
||||||
id controller;
|
id controller;
|
||||||
|
@ -33,12 +35,16 @@
|
||||||
|
|
||||||
- (void)launchThread;
|
- (void)launchThread;
|
||||||
|
|
||||||
|
- (NSLock *)readLock;
|
||||||
|
- (NSLock *)writeLock;
|
||||||
|
|
||||||
- (id)previousNode;
|
- (id)previousNode;
|
||||||
|
|
||||||
- (BOOL)shouldContinue;
|
- (BOOL)shouldContinue;
|
||||||
- (void)setShouldContinue:(BOOL)s;
|
- (void)setShouldContinue:(BOOL)s;
|
||||||
|
|
||||||
- (VirtualRingBuffer *)buffer;
|
- (VirtualRingBuffer *)buffer;
|
||||||
|
- (void)resetBuffer; //WARNING! DANGER WILL ROBINSON!
|
||||||
|
|
||||||
- (Semaphore *)semaphore;
|
- (Semaphore *)semaphore;
|
||||||
|
|
||||||
|
|
33
Sound/Node.m
33
Sound/Node.m
|
@ -17,6 +17,8 @@
|
||||||
{
|
{
|
||||||
buffer = [[VirtualRingBuffer alloc] initWithLength:BUFFER_SIZE];
|
buffer = [[VirtualRingBuffer alloc] initWithLength:BUFFER_SIZE];
|
||||||
semaphore = [[Semaphore alloc] init];
|
semaphore = [[Semaphore alloc] init];
|
||||||
|
readLock = [[NSLock alloc] init];
|
||||||
|
writeLock = [[NSLock alloc] init];
|
||||||
|
|
||||||
controller = c;
|
controller = c;
|
||||||
previousNode = p;
|
previousNode = p;
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
int amountToCopy, availOutput;
|
int amountToCopy, availOutput;
|
||||||
int amountLeft = amount;
|
int amountLeft = amount;
|
||||||
|
|
||||||
|
[writeLock lock];
|
||||||
while (shouldContinue == YES && amountLeft > 0)
|
while (shouldContinue == YES && amountLeft > 0)
|
||||||
{
|
{
|
||||||
availOutput = [buffer lengthAvailableToWriteReturningPointer:&writePtr];
|
availOutput = [buffer lengthAvailableToWriteReturningPointer:&writePtr];
|
||||||
|
@ -56,6 +59,7 @@
|
||||||
amountLeft -= amountToCopy;
|
amountLeft -= amountToCopy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[writeLock unlock];
|
||||||
|
|
||||||
return (amount - amountLeft);
|
return (amount - amountLeft);
|
||||||
}
|
}
|
||||||
|
@ -68,15 +72,17 @@
|
||||||
|
|
||||||
- (void)threadEntry:(id)arg
|
- (void)threadEntry:(id)arg
|
||||||
{
|
{
|
||||||
|
[self retain];
|
||||||
|
|
||||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||||
DBLog(@"In thread entry");
|
DBLog(@"In thread entry");
|
||||||
[self retain];
|
|
||||||
|
|
||||||
[self process];
|
[self process];
|
||||||
|
|
||||||
[self release];
|
|
||||||
|
|
||||||
[pool release];
|
[pool release];
|
||||||
|
|
||||||
|
[self release];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)readData:(void *)ptr amount:(int)amount
|
- (int)readData:(void *)ptr amount:(int)amount
|
||||||
|
@ -85,6 +91,7 @@
|
||||||
int amountToCopy;
|
int amountToCopy;
|
||||||
int availInput;
|
int availInput;
|
||||||
|
|
||||||
|
[readLock lock];
|
||||||
availInput = [[previousNode buffer] lengthAvailableToReadReturningPointer:&readPtr];
|
availInput = [[previousNode buffer] lengthAvailableToReadReturningPointer:&readPtr];
|
||||||
|
|
||||||
if (availInput <= amount && [previousNode endOfStream] == YES)
|
if (availInput <= amount && [previousNode endOfStream] == YES)
|
||||||
|
@ -110,6 +117,7 @@
|
||||||
|
|
||||||
[[previousNode semaphore] signal];
|
[[previousNode semaphore] signal];
|
||||||
}
|
}
|
||||||
|
[readLock unlock];
|
||||||
|
|
||||||
return amountToCopy;
|
return amountToCopy;
|
||||||
}
|
}
|
||||||
|
@ -140,6 +148,27 @@
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)resetBuffer
|
||||||
|
{
|
||||||
|
[readLock lock];
|
||||||
|
[writeLock lock];
|
||||||
|
|
||||||
|
[buffer empty];
|
||||||
|
|
||||||
|
[writeLock unlock];
|
||||||
|
[readLock unlock];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSLock *)readLock
|
||||||
|
{
|
||||||
|
return readLock;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSLock *)writeLock
|
||||||
|
{
|
||||||
|
return writeLock;
|
||||||
|
}
|
||||||
|
|
||||||
- (Semaphore *)semaphore
|
- (Semaphore *)semaphore
|
||||||
{
|
{
|
||||||
return semaphore;
|
return semaphore;
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
- (void)setup;
|
- (void)setup;
|
||||||
- (void)process;
|
- (void)process;
|
||||||
- (void)close;
|
- (void)close;
|
||||||
|
- (void)seek:(double)time;
|
||||||
|
|
||||||
- (int)readData:(void *)ptr amount:(int)amount;
|
- (int)readData:(void *)ptr amount:(int)amount;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,12 @@
|
||||||
[output setup];
|
[output setup];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)seek:(double)time
|
||||||
|
{
|
||||||
|
amountPlayed = time*format.mBytesPerFrame*(format.mSampleRate/1000.0);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
- (void)process
|
- (void)process
|
||||||
{
|
{
|
||||||
[output start];
|
[output start];
|
||||||
|
|
|
@ -90,6 +90,12 @@
|
||||||
- (void)seekToTime:(double)time
|
- (void)seekToTime:(double)time
|
||||||
{
|
{
|
||||||
//Need to reset everything's buffers, and then seek?
|
//Need to reset everything's buffers, and then seek?
|
||||||
|
/*HACK TO TEST HOW WELL THIS WOULD WORK*/
|
||||||
|
[bufferChain seek:time];
|
||||||
|
[output seek:time];
|
||||||
|
|
||||||
|
|
||||||
|
/*END HACK*/
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVolume:(double)v
|
- (void)setVolume:(double)v
|
||||||
|
|
|
@ -65,6 +65,10 @@
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
NSLog(@"DEALLOCATING VORBIS");
|
||||||
|
}
|
||||||
- (void)close
|
- (void)close
|
||||||
{
|
{
|
||||||
ov_clear(&vorbisRef);
|
ov_clear(&vorbisRef);
|
||||||
|
|
Loading…
Reference in New Issue