Cog/Sound/InputNode.m

85 lines
1.4 KiB
Mathematica
Raw Normal View History

2006-01-20 12:34:02 -03:00
//
// InputNode.m
2006-01-20 12:34:02 -03:00
// Cog
//
// Created by Vincent Spader on 8/2/05.
// Copyright 2005 Vincent Spader. All rights reserved.
2006-01-20 12:34:02 -03:00
//
#import "InputNode.h"
@implementation InputNode
2006-04-12 22:51:22 -04:00
- (BOOL)open:(NSString *)filename
2006-01-20 12:34:02 -03:00
{
2006-04-12 22:51:22 -04:00
NSLog(@"Opening: %@", filename);
2006-01-20 12:34:02 -03:00
soundFile = [SoundFile open:filename];
2006-04-12 22:51:22 -04: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 12:34:02 -03:00
[soundFile getFormat:&format];
shouldContinue = YES;
2006-04-02 16:03:12 -04:00
shouldSeek = NO;
2006-04-12 22:51:22 -04:00
return YES;
2006-01-20 12:34:02 -03:00
}
- (void)process
{
const int chunk_size = CHUNK_SIZE;
2006-04-02 16:03:12 -04:00
char *buf;
2006-01-20 12:34:02 -03:00
int amountRead;
2006-05-07 09:19:23 -04:00
NSLog(@"Playing file: %i", self);
2006-04-02 16:03:12 -04:00
buf = malloc(chunk_size);
2006-01-20 12:34:02 -03:00
while ([self shouldContinue] == YES && [self endOfStream] == NO)
2006-01-20 12:34:02 -03:00
{
2006-04-02 16:03:12 -04:00
if (shouldSeek == YES)
{
2006-04-13 10:47:28 -04:00
NSLog(@"Actually seeking");
2006-04-02 16:03:12 -04:00
[soundFile seekToTime:seekTime];
shouldSeek = NO;
}
2006-01-20 12:34:02 -03:00
amountRead = [soundFile fillBuffer:buf ofSize: chunk_size];
if (amountRead <= 0)
{
endOfStream = YES;
2006-04-03 21:08:21 -04:00
DBLog(@"END OF INPUT WAS REACHED");
2006-01-20 12:34:02 -03:00
[controller endOfInputReached];
2006-04-02 16:03:12 -04:00
break; //eof
2006-01-20 12:34:02 -03:00
}
[self writeData:buf amount:amountRead];
}
2006-04-02 16:03:12 -04:00
free(buf);
2006-01-20 12:34:02 -03:00
[soundFile close];
2006-05-07 09:19:23 -04:00
NSLog(@"CLOSED: %i", self);
2006-01-20 12:34:02 -03:00
}
2006-04-02 16:03:12 -04:00
- (void)seek:(double)time
{
2006-04-13 10:47:28 -04:00
NSLog(@"SEEKING WEEE");
2006-04-02 16:03:12 -04:00
seekTime = time;
shouldSeek = YES;
}
2006-01-20 12:34:02 -03:00
- (AudioStreamBasicDescription) format
{
return format;
}
@end