cog/Audio/Chain/InputNode.m

103 lines
1.7 KiB
Matlab
Raw Normal View History

2006-01-20 15:34:02 +00:00
//
// InputNode.m
2006-01-20 15:34:02 +00:00
// Cog
//
// Created by Vincent Spader on 8/2/05.
// Copyright 2005 Vincent Spader. All rights reserved.
2006-01-20 15:34:02 +00:00
//
#import "InputNode.h"
#import "BufferChain.h"
#import "Plugin.h"
2006-01-20 15:34:02 +00:00
@implementation InputNode
- (BOOL)openURL:(NSURL *)url withSource:(id<CogSource>)source
2006-01-20 15:34:02 +00:00
{
NSLog(@"Opening: %@", url);
decoder = [AudioDecoder audioDecoderForURL:url];
[decoder retain];
NSLog(@"Got decoder...%@", decoder);
if (decoder == nil)
2006-04-13 02:51:22 +00:00
return NO;
if (![decoder open:source])
{
NSLog(@"Couldn't open decoder...");
return NO;
}
/* while (decoder == nil)
2006-04-13 02:51:22 +00:00
{
NSURL *nextStream = [controller invalidDecoder];
if (nextStream == nil)
2006-04-13 02:51:22 +00:00
return NO;
decoder = [AudioDecoder audioDecoderForURL:nextStream];
[decoder open:nextStream];
2006-04-13 02:51:22 +00:00
}
*/
shouldContinue = YES;
2006-04-02 20:03:12 +00:00
shouldSeek = NO;
2006-04-13 02:51:22 +00:00
NSLog(@"OPENED");
2006-04-13 02:51:22 +00:00
return YES;
2006-01-20 15:34:02 +00:00
}
- (void)process
{
const int chunk_size = CHUNK_SIZE;
2006-04-02 20:03:12 +00:00
char *buf;
2006-01-20 15:34:02 +00:00
int amountRead;
2006-05-07 13:19:23 +00:00
NSLog(@"Playing file: %i", self);
2006-04-02 20:03:12 +00:00
buf = malloc(chunk_size);
2006-01-20 15:34:02 +00:00
while ([self shouldContinue] == YES && [self endOfStream] == NO)
2006-01-20 15:34:02 +00:00
{
2006-04-02 20:03:12 +00:00
if (shouldSeek == YES)
{
2006-04-13 14:47:28 +00:00
NSLog(@"Actually seeking");
[decoder seekToTime:seekTime];
2006-04-02 20:03:12 +00:00
shouldSeek = NO;
}
amountRead = [decoder fillBuffer:buf ofSize: chunk_size];
2006-01-20 15:34:02 +00:00
if (amountRead <= 0)
{
endOfStream = YES;
2006-04-04 01:08:21 +00:00
DBLog(@"END OF INPUT WAS REACHED");
2006-01-20 15:34:02 +00:00
[controller endOfInputReached];
2006-04-02 20:03:12 +00:00
break; //eof
2006-01-20 15:34:02 +00:00
}
[self writeData:buf amount:amountRead];
}
2006-04-02 20:03:12 +00:00
free(buf);
[decoder close];
2006-05-07 13:19:23 +00:00
NSLog(@"CLOSED: %i", self);
2006-01-20 15:34:02 +00:00
}
2006-04-02 20:03:12 +00:00
- (void)seek:(double)time
{
2006-04-13 14:47:28 +00:00
NSLog(@"SEEKING WEEE");
2006-04-02 20:03:12 +00:00
seekTime = time;
shouldSeek = YES;
}
- (void)dealloc
{
[decoder release];
[super dealloc];
}
- (NSDictionary *) properties
2006-01-20 15:34:02 +00:00
{
return [decoder properties];
2006-01-20 15:34:02 +00:00
}
@end