cog/Audio/Chain/OutputNode.m

125 lines
1.7 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 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"
#import "AudioPlayer.h"
#import "BufferChain.h"
2006-01-20 15:34:02 +00:00
#import "Logging.h"
2006-01-20 15:34:02 +00:00
@implementation OutputNode
- (void)setup
{
amountPlayed = 0;
paused = YES;
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
{
// [output pause];
2007-05-26 22:13:11 +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
{
paused = NO;
2006-01-20 15:34:02 +00:00
[output start];
}
2006-01-29 14:57:48 +00:00
- (void)pause
{
paused = YES;
2006-01-29 14:57:48 +00:00
[output pause];
}
- (void)resume
{
paused = NO;
2006-01-29 14:57:48 +00:00
[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;
[self setPreviousNode:[[controller bufferChain] finalNode]];
2006-01-20 15:34:02 +00:00
n = [super readData:ptr amount:amount];
amountPlayed += n;
if (endOfStream == YES)
2006-01-20 15:34:02 +00:00
{
amountPlayed = 0;
[controller endOfInputPlayed]; //Updates shouldContinue appropriately?
2006-01-20 15:34:02 +00:00
}
2007-07-11 01:20:32 +00:00
/* if (n == 0) {
DLog(@"Output Buffer dry!");
}
2007-07-11 01:20:32 +00:00
*/
[pool release];
2006-01-20 15:34:02 +00:00
return n;
}
2006-01-20 15:34:02 +00:00
- (double)amountPlayed
{
return (amountPlayed/format.mBytesPerFrame)/(format.mSampleRate);
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];
[super dealloc];
}
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
}
- (BOOL)isPaused
{
return paused;
}
2006-01-20 15:34:02 +00:00
@end