cog/Plugins/MonkeysAudio/MonkeysAudioDecoder.mm

116 lines
2.1 KiB
Plaintext
Raw Normal View History

2005-06-02 18:16:43 +00:00
//
// MonkeysFile.m
// zyVorbis
//
// Created by Vincent Spader on 1/30/05.
2005-07-02 21:02:06 +00:00
// Copyright 2005 Vincent Spader All rights reserved.
2005-06-02 18:16:43 +00:00
//
#import "MonkeysAudioDecoder.h"
2005-06-02 18:16:43 +00:00
#import "MAC/ApeInfo.h"
2006-04-17 02:18:09 +00:00
#import "MAC/CharacterHelper.h"
2005-06-02 18:16:43 +00:00
@implementation MonkeysAudioDecoder
2005-06-02 18:16:43 +00:00
- (BOOL)open:(id<CogSource>)s
2005-06-02 18:16:43 +00:00
{
int n;
sourceIO = new SourceIO(s);
[self setSource:s];
decompress = CreateIAPEDecompressEx(sourceIO, &n);
2005-06-02 18:16:43 +00:00
if (decompress == NULL)
{
NSLog(@"ERROR OPENING FILE");
2005-06-02 18:16:43 +00:00
return NO;
}
frequency = decompress->GetInfo(APE_INFO_SAMPLE_RATE);
bitsPerSample = decompress->GetInfo(APE_INFO_BITS_PER_SAMPLE);
channels = decompress->GetInfo(APE_INFO_CHANNELS);
length = ((double)decompress->GetInfo(APE_INFO_TOTAL_BLOCKS)*1000.0)/frequency;
[self willChangeValueForKey:@"properties"];
[self didChangeValueForKey:@"properties"];
2005-06-02 18:16:43 +00:00
return YES;
}
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
{
int n;
int numread;
int blockAlign = decompress->GetInfo(APE_INFO_BLOCK_ALIGN);
n = decompress->GetData((char *)buf, size/blockAlign, &numread);
if (n != ERROR_SUCCESS)
{
NSLog(@"ERROR: %i", n);
2005-06-02 18:16:43 +00:00
return 0;
}
numread *= blockAlign;
return numread;
}
- (void)close
{
// DBLog(@"CLOSE");
if (decompress)
delete decompress;
if (sourceIO)
delete sourceIO;
[source release];
2005-06-02 18:16:43 +00:00
decompress = NULL;
sourceIO = NULL;
2005-06-02 18:16:43 +00:00
}
- (double)seekToTime:(double)milliseconds
2005-06-02 18:16:43 +00:00
{
int r;
// DBLog(@"HELLO: %i", int(frequency*((double)milliseconds/1000.0)));
r = decompress->Seek(int(frequency*((double)milliseconds/1000.0)));
return milliseconds;
2005-06-02 18:16:43 +00:00
}
- (void)setSource:(id<CogSource>)s
{
[s retain];
[source release];
source = s;
}
- (id<CogSource>)source
{
return source;
}
- (BOOL)seekable
{
return [source seekable];
}
- (NSDictionary *)properties
{
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:channels],@"channels",
[NSNumber numberWithInt:bitsPerSample],@"bitsPerSample",
[NSNumber numberWithFloat:frequency],@"sampleRate",
[NSNumber numberWithDouble:length],@"length",
2007-03-05 00:36:12 +00:00
@"host",@"endian",
nil];
}
+ (NSArray *)fileTypes
{
return [NSArray arrayWithObject:@"ape"];
}
2005-06-02 18:16:43 +00:00
@end