cog/Audio/Chain/BufferChain.m

192 lines
3.1 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;
rgInfo = nil;
2006-04-13 02:51:22 +00:00
inputNode = nil;
converterNode = nil;
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 withRGInfo:(NSDictionary *)rgi
{
[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;
}
2007-10-14 18:12:15 +00:00
if (![inputNode openWithSource:source])
2006-04-13 02:51:22 +00:00
return NO;
if (![converterNode setupWithInputFormat:propertiesToASBD([inputNode properties]) outputFormat:outputFormat])
return NO;
[self setRGInfo:rgi];
// 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;
NSLog(@"Input Properties: %@", [inputNode properties]);
if (![converterNode setupWithInputFormat:propertiesToASBD([inputNode properties]) outputFormat:outputFormat])
return NO;
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];
[converterNode launchThread];
2006-01-20 15:34:02 +00:00
}
- (void)setUserInfo:(id)i
{
[i retain];
[userInfo release];
userInfo = i;
}
- (id)userInfo
{
return userInfo;
}
- (void)setRGInfo:(NSDictionary *)rgi
{
[rgi retain];
[rgInfo release];
rgInfo = rgi;
[converterNode setRGInfo:rgi];
}
- (NSDictionary *)rgInfo
{
return rgInfo;
}
- (void)dealloc
{
[rgInfo release];
[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
{
long frame = time * [[[inputNode properties] objectForKey:@"sampleRate"] floatValue];
[inputNode seek:frame];
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!");
}
- (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