Cog/Sound/BufferChain.m

108 lines
1.8 KiB
Mathematica
Raw Normal View History

2006-01-20 12:34:02 -03:00
//
// BufferChain.m
2006-01-20 12:34:02 -03:00
// CogNew
//
// Created by Vincent Spader on 1/4/06.
// Copyright 2006 Vincent Spader. All rights reserved.
2006-01-20 12:34:02 -03:00
//
#import "BufferChain.h"
#import "OutputNode.h"
@implementation BufferChain
- (id)initWithController:(id)c
{
self = [super init];
if (self)
{
soundController = c;
2006-04-12 22:51:22 -04:00
playlistEntry = nil;
inputNode = nil;
converterNode = nil;
2006-01-20 12:34:02 -03:00
}
return self;
}
- (void)buildChain
{
[inputNode release];
[converterNode release];
2006-04-12 22:51:22 -04:00
inputNode = [[InputNode alloc] initWithController:self previous:nil];
converterNode = [[ConverterNode alloc] initWithController:self previous:inputNode];
2006-01-20 12:34:02 -03:00
finalNode = converterNode;
}
2006-04-12 22:51:22 -04:00
- (BOOL)open:(PlaylistEntry *)pe
2006-01-20 12:34:02 -03:00
{
2006-04-12 22:51:22 -04:00
[pe retain];
[playlistEntry release];
NSLog(@"THEY ARE THE SAME?!");
playlistEntry = pe;
2006-01-20 12:34:02 -03:00
[self buildChain];
2006-04-12 22:51:22 -04:00
NSLog(@"Filename in bufferchain: %@, %i %i", [pe filename], playlistEntry, pe);
if (![inputNode open:[playlistEntry filename]])
return NO;
2006-01-20 12:34:02 -03:00
[converterNode setupWithInputFormat:(AudioStreamBasicDescription)[inputNode format] outputFormat:[[soundController output] format] ];
return YES;
}
- (void)launchThreads
{
DBLog(@"LAUNCHING THREAD FOR INPUT");
[inputNode launchThread];
DBLog(@"LAUNCHING THREAD FOR CONVERTER");
[converterNode launchThread];
}
- (void)dealloc
{
NSLog(@"Releasing playlistEntry: %i", [playlistEntry retainCount]);
2006-04-12 22:51:22 -04:00
[playlistEntry release];
[inputNode release];
2006-05-07 09:19:23 -04:00
[converterNode release];
[super dealloc];
}
2006-04-02 16:03:12 -04:00
- (void)seek:(double)time
{
2006-04-13 10:47:28 -04:00
NSLog(@"SEEKING IN BUFFERCHIAN");
2006-04-02 16:03:12 -04:00
[inputNode seek:time];
2006-04-13 10:47:28 -04:00
2006-04-02 16:03:12 -04:00
[converterNode resetBuffer];
2006-09-02 12:09:20 -04:00
[inputNode resetBuffer];
2006-04-02 16:03:12 -04:00
}
2006-04-12 22:51:22 -04:00
- (void)endOfInputReached
{
[soundController endOfInputReached:self];
}
2006-01-20 12:34:02 -03:00
- (id)finalNode
{
return finalNode;
}
2006-04-12 22:51:22 -04:00
- (PlaylistEntry *)playlistEntry
{
return playlistEntry;
}
2006-01-20 12:34:02 -03:00
- (void)setShouldContinue:(BOOL)s
{
[inputNode setShouldContinue:s];
[converterNode setShouldContinue:s];
}
@end