cog/Audio/Chain/OutputNode.m

175 lines
3.0 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.0;
sampleRatio = 0.0;
paused = YES;
started = NO;
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];
[self resetBuffer];
2007-05-26 22:13:11 +00:00
amountPlayed = time;
2006-04-02 20:03:12 +00:00
}
2006-01-20 15:34:02 +00:00
- (void)process
{
paused = NO;
[output start];
2006-01-20 15:34:02 +00:00
}
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];
}
- (void)incrementAmountPlayed:(long)count
{
amountPlayed += (double)count * sampleRatio;
}
- (void)resetAmountPlayed
{
amountPlayed = 0;
}
- (void)endOfInputPlayed
{
[controller endOfInputPlayed];
}
- (BOOL)chainQueueHasTracks
{
return [controller chainQueueHasTracks];
}
- (double)secondsBuffered
{
return (double)([buffer bufferedLength]) / (format.mSampleRate * format.mBytesPerPacket);
}
2006-01-20 15:34:02 +00:00
- (int)readData:(void *)ptr amount:(int)amount
{
@autoreleasepool {
int n;
[self setPreviousNode:[[controller bufferChain] finalNode]];
2006-01-20 15:34:02 +00:00
n = [super readData:ptr amount:amount];
2007-07-11 01:20:32 +00:00
/* if (n == 0) {
DLog(@"Output Buffer dry!");
}
2007-07-11 01:20:32 +00:00
*/
2006-01-20 15:34:02 +00:00
return n;
}
}
2006-01-20 15:34:02 +00:00
- (double)amountPlayed
{
return amountPlayed;
2006-01-20 15:34:02 +00:00
}
- (AudioStreamBasicDescription) format
{
return format;
}
- (void)setFormat:(AudioStreamBasicDescription *)f
{
format = *f;
// Calculate a ratio and add to double(seconds) instead, as format may change
// double oldSampleRatio = sampleRatio;
sampleRatio = 1.0 / (format.mSampleRate * format.mBytesPerPacket);
BufferChain *bufferChain = [controller bufferChain];
if (bufferChain)
{
ConverterNode *converter = [bufferChain converter];
if (converter)
{
// This clears the resampler buffer, but not the input buffer
// We also have to jump the play position ahead accounting for
// the data we are flushing
#if 0
// We no longer need to do this, because outputchanged converter
// now uses the RefillNode to slap the previous samples into
// itself
if (oldSampleRatio)
amountPlayed += oldSampleRatio * [[converter buffer] bufferedLength];
#endif
[converter setOutputFormat:format];
[converter inputFormatDidChange:[bufferChain inputFormat]];
}
}
2006-01-20 15:34:02 +00:00
}
- (void)close
{
[output stop];
}
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;
}
2022-01-16 15:32:47 +00:00
- (void)beginEqualizer:(AudioUnit)eq
{
[controller beginEqualizer:eq];
}
- (void)refreshEqualizer:(AudioUnit)eq
{
[controller refreshEqualizer:eq];
}
2022-01-16 15:32:47 +00:00
- (void)endEqualizer:(AudioUnit)eq
{
[controller endEqualizer:eq];
}
2006-01-20 15:34:02 +00:00
@end