cog/Sound/OutputNode.m

110 lines
1.6 KiB
Matlab
Raw Normal View History

2006-01-20 15:34:02 +00:00
//
// OutputNode.m
2006-01-20 15:34:02 +00:00
// Cog
//
// Created by Zaphod Beeblebrox on 8/2/05.
// Copyright 2005 __MyCompanyName__. All rights reserved.
//
#import "OutputNode.h"
#import "OutputCoreAudio.h"
@implementation OutputNode
- (void)setup
{
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
{
amountPlayed = time*format.mBytesPerFrame*(format.mSampleRate/1000.0);
}
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
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
2006-01-20 15:34:02 +00:00
int n;
previousNode = [[controller bufferChain] finalNode];
n = [super readData:ptr amount:amount];
// NSLog(@"N: %i %i", n, endOfStream);
if (endOfStream == YES)
2006-01-20 15:34:02 +00:00
{
2006-04-04 01:08:21 +00:00
DBLog(@"End of stream reached: %i", endOfStream);
amountPlayed = 0;
[controller endOfInputPlayed]; //Updates shouldContinue appropriately?
2006-04-04 01:08:21 +00:00
DBLog(@"End of stream reached: %i", endOfStream);
// return (n + [self readData:ptr amount:(amount-n)]);
2006-01-20 15:34:02 +00:00
}
amountPlayed += n;
[pool release];
2006-01-20 15:34:02 +00:00
return n;
}
2006-01-20 15:34:02 +00:00
- (double)amountPlayed
{
2006-01-20 15:34:02 +00:00
return (amountPlayed/format.mBytesPerFrame)/(format.mSampleRate/1000.0);
2006-01-20 15:34:02 +00:00
}
- (AudioStreamBasicDescription) format
{
return format;
}
- (void)setFormat:(AudioStreamBasicDescription *)f
{
format = *f;
}
- (void)close
{
[output stop];
}
- (void)dealloc
{
[output release];
}
2006-01-20 15:34:02 +00:00
- (void)setVolume:(double) v
{
[output setVolume:v];
}
- (void)setShouldContinue:(BOOL)s
{
[super setShouldContinue:s];
// if (s == NO)
// [output stop];
2006-01-20 15:34:02 +00:00
}
@end