Cog/Audio/Chain/BufferChain.m

135 lines
1.9 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"
#import "AudioSource.h"
#import "CoreAudioUtils.h"
2006-01-20 12:34:02 -03:00
@implementation BufferChain
- (id)initWithController:(id)c
{
self = [super init];
if (self)
{
controller = c;
streamURL = nil;
userInfo = nil;
2006-04-12 22:51:22 -04:00
inputNode = nil;
2006-01-20 12:34:02 -03:00
}
return self;
}
- (void)buildChain
{
[inputNode release];
2006-04-12 22:51:22 -04:00
inputNode = [[InputNode alloc] initWithController:self previous:nil];
2006-01-20 12:34:02 -03:00
finalNode = inputNode;
2006-01-20 12:34:02 -03:00
}
- (BOOL)open:(NSURL *)url withOutputFormat:(AudioStreamBasicDescription)outputFormat
{
[self setStreamURL:url];
2006-01-20 12:34:02 -03:00
[self buildChain];
id<CogSource> source = [AudioSource audioSourceForURL:url];
if (![source open:url])
{
NSLog(@"Couldn't open source...");
return NO;
}
if (![inputNode openURL:url withSource:source outputFormat:outputFormat])
2006-04-12 22:51:22 -04:00
return NO;
2006-01-20 12:34:02 -03:00
return YES;
}
- (void)launchThreads
{
DBLog(@"LAUNCHING THREAD FOR INPUT");
[inputNode launchThread];
}
- (void)setUserInfo:(id)i
{
[i retain];
[userInfo release];
userInfo = i;
}
- (id)userInfo
{
return userInfo;
}
- (void)dealloc
{
[userInfo release];
2006-04-12 22:51:22 -04:00
[inputNode release];
2006-05-07 09:19:23 -04:00
[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
2007-02-17 12:42:59 -03:00
[[inputNode readLock] lock];
[[inputNode writeLock] lock];
//Signal so its waiting when we unlock
[[inputNode semaphore] signal];
2006-09-02 12:09:20 -04:00
[inputNode resetBuffer];
2007-02-17 12:42:59 -03:00
[[inputNode writeLock] unlock];
[[inputNode readLock] unlock];
2006-04-02 16:03:12 -04:00
}
2006-04-12 22:51:22 -04:00
- (void)endOfInputReached
{
[controller endOfInputReached:self];
2006-04-12 22:51:22 -04:00
}
2006-01-20 12:34:02 -03:00
- (id)finalNode
{
return finalNode;
}
- (NSURL *)streamURL
2006-04-12 22:51:22 -04:00
{
return streamURL;
2006-04-12 22:51:22 -04:00
}
- (void)setStreamURL:(NSURL *)url
{
[url retain];
[streamURL release];
streamURL = url;
}
2006-01-20 12:34:02 -03:00
- (void)setShouldContinue:(BOOL)s
{
[inputNode setShouldContinue:s];
}
@end