cog/Sound/InputNode.m

83 lines
1.3 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 Zaphod Beeblebrox on 8/2/05.
// Copyright 2005 __MyCompanyName__. All rights reserved.
//
#import "InputNode.h"
@implementation InputNode
2006-04-13 02:51:22 +00:00
- (BOOL)open:(NSString *)filename
2006-01-20 15:34:02 +00:00
{
2006-04-13 02:51:22 +00:00
NSLog(@"Opening: %@", filename);
2006-01-20 15:34:02 +00:00
soundFile = [SoundFile open:filename];
2006-04-13 02:51:22 +00:00
if (soundFile == nil)
return NO;
/* while (soundFile == nil)
{
NSString *nextSong = [controller invalidSoundFile];
if (nextSong == nil)
return NO;
soundFile = [SoundFile open:nextSong];
}
*/
2006-01-20 15:34:02 +00:00
[soundFile getFormat:&format];
shouldContinue = YES;
2006-04-02 20:03:12 +00:00
shouldSeek = NO;
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;
DBLog(@"Playing file.\n");
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");
2006-04-02 20:03:12 +00:00
[soundFile seekToTime:seekTime];
shouldSeek = NO;
}
2006-01-20 15:34:02 +00:00
amountRead = [soundFile fillBuffer:buf ofSize: chunk_size];
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);
2006-01-20 15:34:02 +00:00
[soundFile close];
}
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;
}
2006-01-20 15:34:02 +00:00
- (AudioStreamBasicDescription) format
{
return format;
}
@end