2006-01-20 15:34:02 +00:00
|
|
|
//
|
2006-04-02 15:44:08 +00:00
|
|
|
// BufferChain.m
|
2006-01-20 15:34:02 +00:00
|
|
|
// CogNew
|
|
|
|
//
|
2006-09-04 18:46:18 +00:00
|
|
|
// 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"
|
2007-03-02 01:36:52 +00:00
|
|
|
#import "AudioSource.h"
|
2007-02-24 20:36:27 +00:00
|
|
|
#import "CoreAudioUtils.h"
|
2006-01-20 15:34:02 +00:00
|
|
|
|
|
|
|
@implementation BufferChain
|
|
|
|
|
|
|
|
- (id)initWithController:(id)c
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
controller = c;
|
|
|
|
streamURL = nil;
|
|
|
|
userInfo = nil;
|
2007-03-02 01:36:52 +00:00
|
|
|
|
2006-04-13 02:51:22 +00:00
|
|
|
inputNode = nil;
|
2007-10-03 20:23:14 +00:00
|
|
|
converterNode = nil;
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)buildChain
|
|
|
|
{
|
2006-04-02 15:44:08 +00:00
|
|
|
[inputNode release];
|
2007-10-03 20:23:14 +00:00
|
|
|
[converterNode release];
|
2006-04-02 15:44:08 +00:00
|
|
|
|
2006-04-13 02:51:22 +00:00
|
|
|
inputNode = [[InputNode alloc] initWithController:self previous:nil];
|
2007-10-03 20:23:14 +00:00
|
|
|
converterNode = [[ConverterNode alloc] initWithController:self previous:inputNode];
|
|
|
|
|
|
|
|
finalNode = converterNode;
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat
|
|
|
|
{
|
2007-03-02 01:36:52 +00:00
|
|
|
[self setStreamURL:url];
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
[self buildChain];
|
2007-03-02 01:36:52 +00:00
|
|
|
|
|
|
|
id<CogSource> source = [AudioSource audioSourceForURL:url];
|
2007-10-12 02:55:59 +00:00
|
|
|
NSLog(@"Opening: %@", url);
|
2007-03-02 01:36:52 +00:00
|
|
|
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;
|
2007-10-03 20:23:14 +00:00
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
if (![converterNode setupWithInputFormat:propertiesToASBD([inputNode properties]) outputFormat:outputFormat])
|
|
|
|
return NO;
|
|
|
|
|
2007-10-12 02:55:59 +00:00
|
|
|
// return NO;
|
2007-11-24 20:16:27 +00:00
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-10-11 02:08:29 +00:00
|
|
|
- (BOOL)openWithInput:(InputNode *)i withOutputFormat:(AudioStreamBasicDescription)outputFormat
|
|
|
|
{
|
|
|
|
NSLog(@"New buffer chain!");
|
|
|
|
[self buildChain];
|
|
|
|
|
|
|
|
if (![inputNode openWithDecoder:[i decoder]])
|
|
|
|
return NO;
|
2007-11-24 20:16:27 +00:00
|
|
|
|
|
|
|
NSLog(@"Input Properties: %@", [inputNode properties]);
|
2007-10-11 02:08:29 +00:00
|
|
|
if (![converterNode setupWithInputFormat:propertiesToASBD([inputNode properties]) outputFormat:outputFormat])
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
- (void)launchThreads
|
|
|
|
{
|
2007-10-11 02:08:29 +00:00
|
|
|
NSLog(@"Properties: %@", [inputNode properties]);
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
[inputNode launchThread];
|
2007-11-24 20:16:27 +00:00
|
|
|
[converterNode launchThread];
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
- (void)setUserInfo:(id)i
|
|
|
|
{
|
|
|
|
[i retain];
|
|
|
|
[userInfo release];
|
|
|
|
userInfo = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)userInfo
|
|
|
|
{
|
|
|
|
return userInfo;
|
|
|
|
}
|
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
[userInfo release];
|
2007-10-13 07:09:46 +00:00
|
|
|
[streamURL release];
|
2006-04-13 02:51:22 +00:00
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
[inputNode release];
|
2007-10-03 20:23:14 +00:00
|
|
|
[converterNode release];
|
2007-10-13 07:09:46 +00:00
|
|
|
|
|
|
|
NSLog(@"Bufferchain dealloc");
|
2006-05-07 13:19:23 +00:00
|
|
|
|
2006-04-02 15:44:08 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2006-04-02 20:03:12 +00:00
|
|
|
- (void)seek:(double)time
|
|
|
|
{
|
2007-11-24 20:16:27 +00:00
|
|
|
long frame = time * [[[inputNode properties] objectForKey:@"sampleRate"] floatValue];
|
|
|
|
|
|
|
|
[inputNode seek:frame];
|
2006-04-02 20:03:12 +00:00
|
|
|
}
|
|
|
|
|
2007-10-11 02:08:29 +00:00
|
|
|
- (BOOL)endOfInputReached
|
|
|
|
{
|
|
|
|
return [controller endOfInputReached:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)setTrack: (NSURL *)track
|
2006-04-13 02:51:22 +00:00
|
|
|
{
|
2007-10-11 02:08:29 +00:00
|
|
|
return [inputNode setTrack:track];
|
2006-04-13 02:51:22 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 02:55:59 +00:00
|
|
|
- (void)initialBufferFilled:(id)sender
|
2007-03-19 00:19:47 +00:00
|
|
|
{
|
2007-10-12 02:55:59 +00:00
|
|
|
NSLog(@"INITIAL BUFFER FILLED");
|
2007-03-19 00:19:47 +00:00
|
|
|
[controller launchOutputThread];
|
|
|
|
}
|
|
|
|
|
2007-10-12 02:55:59 +00:00
|
|
|
- (void)inputFormatDidChange:(AudioStreamBasicDescription)format
|
|
|
|
{
|
|
|
|
NSLog(@"FORMAT DID CHANGE!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-11 02:08:29 +00:00
|
|
|
- (InputNode *)inputNode
|
|
|
|
{
|
|
|
|
return inputNode;
|
|
|
|
}
|
|
|
|
|
2006-01-20 15:34:02 +00:00
|
|
|
- (id)finalNode
|
|
|
|
{
|
|
|
|
return finalNode;
|
|
|
|
}
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
- (NSURL *)streamURL
|
2006-04-13 02:51:22 +00:00
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
return streamURL;
|
2006-04-13 02:51:22 +00:00
|
|
|
}
|
|
|
|
|
2007-03-02 01:36:52 +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];
|
2007-10-03 20:23:14 +00:00
|
|
|
[converterNode setShouldContinue:s];
|
2006-01-20 15:34:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|