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