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
|
|
|
|
2013-10-11 12:03:55 +00:00
|
|
|
#import "Logging.h"
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
@implementation OutputNode
|
|
|
|
|
|
|
|
- (void)setup
|
|
|
|
{
|
2022-01-13 07:17:07 +00:00
|
|
|
amountPlayed = 0.0;
|
|
|
|
sampleRatio = 0.0;
|
2013-10-21 05:04:09 +00:00
|
|
|
|
|
|
|
paused = YES;
|
2022-01-15 06:46:41 +00:00
|
|
|
started = NO;
|
2006-04-02 15:44:08 +00:00
|
|
|
|
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];
|
2022-01-15 06:46:41 +00:00
|
|
|
[self resetBuffer];
|
2007-05-26 22:13:11 +00:00
|
|
|
|
2022-01-13 07:17:07 +00:00
|
|
|
amountPlayed = time;
|
2006-04-02 20:03:12 +00:00
|
|
|
}
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
- (void)process
|
|
|
|
{
|
2013-10-21 05:04:09 +00:00
|
|
|
paused = NO;
|
2022-01-15 06:46:41 +00:00
|
|
|
[output start];
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
2006-01-29 14:57:48 +00:00
|
|
|
- (void)pause
|
|
|
|
{
|
2013-10-21 05:04:09 +00:00
|
|
|
paused = YES;
|
2006-01-29 14:57:48 +00:00
|
|
|
[output pause];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resume
|
|
|
|
{
|
2013-10-21 05:04:09 +00:00
|
|
|
paused = NO;
|
2006-01-29 14:57:48 +00:00
|
|
|
[output resume];
|
|
|
|
}
|
|
|
|
|
2022-01-15 06:46:41 +00:00
|
|
|
- (void)incrementAmountPlayed:(long)count
|
|
|
|
{
|
|
|
|
amountPlayed += (double)count * sampleRatio;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resetAmountPlayed
|
|
|
|
{
|
|
|
|
amountPlayed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)endOfInputPlayed
|
|
|
|
{
|
|
|
|
[controller endOfInputPlayed];
|
|
|
|
}
|
|
|
|
|
2022-01-15 10:09:26 +00:00
|
|
|
- (BOOL)chainQueueHasTracks
|
2022-01-15 06:46:41 +00:00
|
|
|
{
|
2022-01-15 10:09:26 +00:00
|
|
|
return [controller chainQueueHasTracks];
|
2022-01-15 06:46:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|
|
|
|
{
|
2016-05-05 20:05:39 +00:00
|
|
|
@autoreleasepool {
|
|
|
|
int n;
|
|
|
|
[self setPreviousNode:[[controller bufferChain] finalNode]];
|
2006-01-20 15:34:02 +00:00
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
n = [super readData:ptr amount:amount];
|
2013-10-18 12:33:38 +00:00
|
|
|
|
2007-07-11 01:20:32 +00:00
|
|
|
/* if (n == 0) {
|
2013-10-11 12:03:55 +00:00
|
|
|
DLog(@"Output Buffer dry!");
|
2007-05-26 12:44:01 +00:00
|
|
|
}
|
2007-07-11 01:20:32 +00:00
|
|
|
*/
|
2006-01-20 15:34:02 +00:00
|
|
|
|
2016-05-05 20:05:39 +00:00
|
|
|
return n;
|
|
|
|
}
|
2006-04-02 15:44:08 +00:00
|
|
|
}
|
2006-01-20 15:34:02 +00:00
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
- (double)amountPlayed
|
|
|
|
{
|
2022-01-13 07:17:07 +00:00
|
|
|
return amountPlayed;
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (AudioStreamBasicDescription) format
|
|
|
|
{
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFormat:(AudioStreamBasicDescription *)f
|
|
|
|
{
|
|
|
|
format = *f;
|
2022-01-13 07:17:07 +00:00
|
|
|
// Calculate a ratio and add to double(seconds) instead, as format may change
|
2022-01-14 03:43:18 +00:00
|
|
|
// double oldSampleRatio = sampleRatio;
|
2022-01-13 07:17:07 +00:00
|
|
|
sampleRatio = 1.0 / (format.mSampleRate * format.mBytesPerPacket);
|
2022-01-13 05:31:22 +00:00
|
|
|
BufferChain *bufferChain = [controller bufferChain];
|
|
|
|
if (bufferChain)
|
|
|
|
{
|
|
|
|
ConverterNode *converter = [bufferChain converter];
|
2022-01-13 07:17:07 +00:00
|
|
|
if (converter)
|
2022-01-13 05:31:22 +00:00
|
|
|
{
|
2022-01-13 07:17:07 +00:00
|
|
|
// 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
|
2022-01-14 03:43:18 +00:00
|
|
|
#if 0
|
|
|
|
// We no longer need to do this, because outputchanged converter
|
|
|
|
// now uses the RefillNode to slap the previous samples into
|
|
|
|
// itself
|
2022-01-13 07:17:07 +00:00
|
|
|
if (oldSampleRatio)
|
|
|
|
amountPlayed += oldSampleRatio * [[converter buffer] bufferedLength];
|
2022-01-14 03:43:18 +00:00
|
|
|
#endif
|
2022-01-13 05:31:22 +00:00
|
|
|
[converter setOutputFormat:format];
|
|
|
|
[converter inputFormatDidChange:[bufferChain inputFormat]];
|
|
|
|
}
|
|
|
|
}
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
2006-04-02 15:44:08 +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];
|
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
// if (s == NO)
|
|
|
|
// [output stop];
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
2013-10-21 05:04:09 +00:00
|
|
|
|
|
|
|
- (BOOL)isPaused
|
|
|
|
{
|
|
|
|
return paused;
|
|
|
|
}
|
2022-01-16 15:32:47 +00:00
|
|
|
|
|
|
|
- (void)beginEqualizer:(AudioUnit)eq
|
|
|
|
{
|
|
|
|
[controller beginEqualizer:eq];
|
|
|
|
}
|
|
|
|
|
2022-01-18 04:43:08 +00:00
|
|
|
- (void)refreshEqualizer:(AudioUnit)eq
|
|
|
|
{
|
|
|
|
[controller refreshEqualizer:eq];
|
|
|
|
}
|
|
|
|
|
2022-01-16 15:32:47 +00:00
|
|
|
- (void)endEqualizer:(AudioUnit)eq
|
|
|
|
{
|
|
|
|
[controller endEqualizer:eq];
|
|
|
|
}
|
2022-01-19 10:08:57 +00:00
|
|
|
|
|
|
|
- (void)sustainHDCD
|
|
|
|
{
|
|
|
|
[output sustainHDCD];
|
|
|
|
}
|
2006-01-20 15:34:02 +00:00
|
|
|
@end
|