2006-01-20 15:34:02 +00:00
|
|
|
//
|
2006-04-02 15:44:08 +00:00
|
|
|
// OutputNode.m
|
2006-01-20 15:34:02 +00:00
|
|
|
// Cog
|
|
|
|
//
|
2006-09-04 18:46:18 +00:00
|
|
|
// Created by Vincent Spader on 8/2/05.
|
|
|
|
// Copyright 2005 Vincent Spader. All rights reserved.
|
2006-01-20 15:34:02 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "OutputNode.h"
|
|
|
|
#import "OutputCoreAudio.h"
|
2007-02-24 20:36:27 +00:00
|
|
|
#import "AudioPlayer.h"
|
|
|
|
#import "BufferChain.h"
|
2006-01-20 15:34:02 +00:00
|
|
|
|
|
|
|
@implementation OutputNode
|
|
|
|
|
|
|
|
- (void)setup
|
|
|
|
{
|
2006-04-02 15:44:08 +00:00
|
|
|
amountPlayed = 0;
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
output = [[OutputCoreAudio alloc] initWithController:self];
|
|
|
|
|
|
|
|
[output setup];
|
|
|
|
}
|
|
|
|
|
2006-04-02 20:03:12 +00:00
|
|
|
- (void)seek:(double)time
|
|
|
|
{
|
2007-10-03 20:23:14 +00:00
|
|
|
// [output pause];
|
2007-05-26 22:13:11 +00:00
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
amountPlayed = time*format.mBytesPerFrame*(format.mSampleRate);
|
2006-04-02 20:03:12 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
- (void)process
|
|
|
|
{
|
|
|
|
[output start];
|
|
|
|
}
|
|
|
|
|
2006-01-29 14:57:48 +00:00
|
|
|
- (void)pause
|
|
|
|
{
|
|
|
|
[output pause];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resume
|
|
|
|
{
|
|
|
|
[output resume];
|
|
|
|
}
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
- (int)readData:(void *)ptr amount:(int)amount
|
|
|
|
{
|
2006-04-02 15:44:08 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
int n;
|
2008-02-16 02:46:19 +00:00
|
|
|
[self setPreviousNode:[[controller bufferChain] finalNode]];
|
2006-01-20 15:34:02 +00:00
|
|
|
|
|
|
|
n = [super readData:ptr amount:amount];
|
2006-04-02 15:44:08 +00:00
|
|
|
if (endOfStream == YES)
|
2006-01-20 15:34:02 +00:00
|
|
|
{
|
2006-04-02 15:44:08 +00:00
|
|
|
amountPlayed = 0;
|
|
|
|
[controller endOfInputPlayed]; //Updates shouldContinue appropriately?
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
2007-05-26 12:44:01 +00:00
|
|
|
|
2007-07-11 01:20:32 +00:00
|
|
|
/* if (n == 0) {
|
2007-05-26 12:44:01 +00:00
|
|
|
NSLog(@"Output Buffer dry!");
|
|
|
|
}
|
2007-07-11 01:20:32 +00:00
|
|
|
*/
|
2006-04-02 15:44:08 +00:00
|
|
|
amountPlayed += n;
|
|
|
|
|
|
|
|
[pool release];
|
2006-01-20 15:34:02 +00:00
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
return n;
|
|
|
|
}
|
2006-01-20 15:34:02 +00:00
|
|
|
|
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
- (double)amountPlayed
|
|
|
|
{
|
2007-11-24 20:16:27 +00:00
|
|
|
return (amountPlayed/format.mBytesPerFrame)/(format.mSampleRate);
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (AudioStreamBasicDescription) format
|
|
|
|
{
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFormat:(AudioStreamBasicDescription *)f
|
|
|
|
{
|
|
|
|
format = *f;
|
|
|
|
}
|
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
- (void)close
|
|
|
|
{
|
|
|
|
[output stop];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[output release];
|
2007-02-24 20:36:27 +00:00
|
|
|
|
|
|
|
[super dealloc];
|
2006-04-02 15:44:08 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
- (void)setVolume:(double) v
|
|
|
|
{
|
|
|
|
[output setVolume:v];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setShouldContinue:(BOOL)s
|
|
|
|
{
|
|
|
|
[super setShouldContinue:s];
|
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
// if (s == NO)
|
|
|
|
// [output stop];
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
@end
|