cog/Audio/Chain/OutputNode.m

194 lines
3.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 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 "AudioPlayer.h"
#import "BufferChain.h"
#import "OutputAVFoundation.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;
amountPlayedInterval = 0.0;
paused = YES;
started = NO;
intervalReported = NO;
output = [[OutputAVFoundation alloc] initWithController:self];
2006-01-20 15:34:02 +00:00
[output setup];
}
- (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
}
- (void)process {
paused = NO;
[output start];
2006-01-20 15:34:02 +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:(double)seconds {
amountPlayed += seconds;
amountPlayedInterval += seconds;
if(!intervalReported && amountPlayedInterval >= 60.0) {
intervalReported = YES;
[controller reportPlayCount];
}
}
- (void)resetAmountPlayed {
amountPlayed = 0;
}
- (void)resetAmountPlayedInterval {
amountPlayedInterval = 0;
intervalReported = NO;
}
- (BOOL)selectNextBuffer {
return [controller selectNextBuffer];
}
- (void)endOfInputPlayed {
if(!intervalReported) {
intervalReported = YES;
[controller reportPlayCount];
}
[controller endOfInputPlayed];
[self resetAmountPlayedInterval];
}
- (BOOL)chainQueueHasTracks {
return [controller chainQueueHasTracks];
}
- (double)secondsBuffered {
return [buffer listDuration];
}
- (AudioChunk *)readChunk:(size_t)amount {
@autoreleasepool {
[self setPreviousNode:[[controller bufferChain] finalNode]];
AudioChunk *ret = [super readChunk:amount];
/* if (n == 0) {
DLog(@"Output Buffer dry!");
}
*/
return ret;
}
}
2006-01-20 15:34:02 +00:00
- (double)amountPlayed {
return amountPlayed;
2006-01-20 15:34:02 +00:00
}
- (double)amountPlayedInterval {
return amountPlayedInterval;
}
- (AudioStreamBasicDescription)format {
2006-01-20 15:34:02 +00:00
return format;
}
- (uint32_t)config {
return config;
}
- (void)setFormat:(AudioStreamBasicDescription *)f channelConfig:(uint32_t)channelConfig {
2006-01-20 15:34:02 +00:00
format = *f;
config = channelConfig;
// Calculate a ratio and add to double(seconds) instead, as format may change
// double oldSampleRatio = sampleRatio;
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
amountPlayed += [[converter buffer] listDuration];
AudioStreamBasicDescription inf = [bufferChain inputFormat];
uint32_t config = [bufferChain inputConfig];
format.mChannelsPerFrame = inf.mChannelsPerFrame;
format.mBytesPerFrame = ((inf.mBitsPerChannel + 7) / 8) * format.mChannelsPerFrame;
format.mBytesPerPacket = format.mBytesPerFrame * format.mFramesPerPacket;
channelConfig = config;
[converter inputFormatDidChange:[bufferChain inputFormat] inputConfig:[bufferChain inputConfig]];
}
}
2006-01-20 15:34:02 +00:00
}
- (void)close {
[output stop];
output = nil;
}
- (void)setVolume:(double)v {
2006-01-20 15:34:02 +00:00
[output setVolume:v];
}
- (void)setShouldContinue:(BOOL)s {
2006-01-20 15:34:02 +00:00
[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];
2022-01-16 15:32:47 +00:00
}
- (void)refreshEqualizer:(AudioUnit)eq {
[controller refreshEqualizer:eq];
}
- (void)endEqualizer:(AudioUnit)eq {
[controller endEqualizer:eq];
2022-01-16 15:32:47 +00:00
}
2022-01-19 10:08:57 +00:00
- (void)sustainHDCD {
[output sustainHDCD];
2022-01-19 10:08:57 +00:00
}
- (void)restartPlaybackAtCurrentPosition {
[controller restartPlaybackAtCurrentPosition];
}
- (double)latency {
return [output latency];
}
2006-01-20 15:34:02 +00:00
@end