cog/Audio/Chain/BufferChain.m

180 lines
2.8 KiB
Matlab
Raw Normal View History

2006-01-20 15:34:02 +00:00
//
// BufferChain.m
2006-01-20 15:34:02 +00:00
// CogNew
//
// Created by Vincent Spader on 1/4/06.
// Copyright 2006 Vincent Spader. All rights reserved.
2006-01-20 15:34:02 +00:00
//
#import "BufferChain.h"
#import "OutputNode.h"
#import "AudioSource.h"
#import "CoreAudioUtils.h"
2006-01-20 15:34:02 +00:00
@implementation BufferChain
- (id)initWithController:(id)c
{
self = [super init];
if (self)
{
controller = c;
streamURL = nil;
userInfo = nil;
2006-04-13 02:51:22 +00:00
inputNode = nil;
converterNode = nil;
converterLaunched = NO;
2006-01-20 15:34:02 +00:00
}
return self;
}
- (void)buildChain
{
[inputNode release];
[converterNode release];
2006-04-13 02:51:22 +00:00
inputNode = [[InputNode alloc] initWithController:self previous:nil];
converterNode = [[ConverterNode alloc] initWithController:self previous:inputNode];
finalNode = converterNode;
2006-01-20 15:34:02 +00:00
}
- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat
{
[self setStreamURL:url];
2006-01-20 15:34:02 +00:00
[self buildChain];
id<CogSource> source = [AudioSource audioSourceForURL:url];
NSLog(@"Opening: %@", url);
if (![source open:url])
{
NSLog(@"Couldn't open source...");
return NO;
}
[converterNode setOutputFormat:outputFormat];
2007-10-14 18:12:15 +00:00
if (![inputNode openWithSource:source])
2006-04-13 02:51:22 +00:00
return NO;
// return NO;
2006-01-20 15:34:02 +00:00
return YES;
}
- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat
{
NSLog(@"New buffer chain!");
[self buildChain];
if (![inputNode openWithDecoder:[i decoder]])
return NO;
if (![converterNode setupWithInputFormat:propertiesToASBD([inputNode properties]) outputFormat:outputFormat])
return NO;
NSLog(@"Buffer chain made");
[converterNode launchThread];
return YES;
}
2006-01-20 15:34:02 +00:00
- (void)launchThreads
{
NSLog(@"Properties: %@", [inputNode properties]);
2006-01-20 15:34:02 +00:00
[inputNode launchThread];
}
- (void)setUserInfo:(id)i
{
[i retain];
[userInfo release];
userInfo = i;
}
- (id)userInfo
{
return userInfo;
}
- (void)dealloc
{
[userInfo release];
2007-10-13 07:09:46 +00:00
[streamURL release];
2006-04-13 02:51:22 +00:00
[inputNode release];
[converterNode release];
2007-10-13 07:09:46 +00:00
NSLog(@"Bufferchain dealloc");
2006-05-07 13:19:23 +00:00
[super dealloc];
}
2006-04-02 20:03:12 +00:00
- (void)seek:(double)time
{
[inputNode seek:time];
2006-04-02 20:03:12 +00:00
}
- (BOOL)endOfInputReached
{
return [controller endOfInputReached:self];
}
- (BOOL)setTrack: (NSURL *)track
2006-04-13 02:51:22 +00:00
{
return [inputNode setTrack:track];
2006-04-13 02:51:22 +00:00
}
- (void)initialBufferFilled:(id)sender
{
NSLog(@"INITIAL BUFFER FILLED");
[controller launchOutputThread];
}
- (void)inputFormatDidChange:(AudioStreamBasicDescription)format
{
NSLog(@"FORMAT DID CHANGE!");
if (!converterLaunched) {
converterLaunched = YES;
[converterNode inputFormatDidChange:format];
[converterNode launchThread];
}
}
- (InputNode *)inputNode
{
return inputNode;
}
2006-01-20 15:34:02 +00:00
- (id)finalNode
{
return finalNode;
}
- (NSURL *)streamURL
2006-04-13 02:51:22 +00:00
{
return streamURL;
2006-04-13 02:51:22 +00:00
}
- (void)setStreamURL:(NSURL *)url
{
[url retain];
[streamURL release];
streamURL = url;
}
2006-01-20 15:34:02 +00:00
- (void)setShouldContinue:(BOOL)s
{
[inputNode setShouldContinue:s];
[converterNode setShouldContinue:s];
2006-01-20 15:34:02 +00:00
}
@end