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
|
|
|
//
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
#import "MonkeysAudioDecoder.h"
|
2008-02-08 00:08:56 +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
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
@implementation MonkeysAudioDecoder
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2007-03-04 18:20:23 +00:00
|
|
|
- (BOOL)open:(id<CogSource>)s
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
int n;
|
2007-03-04 18:20:23 +00:00
|
|
|
sourceIO = new SourceIO(s);
|
2007-03-04 18:41:43 +00:00
|
|
|
|
|
|
|
[self setSource:s];
|
|
|
|
|
2007-03-04 18:20:23 +00:00
|
|
|
decompress = CreateIAPEDecompressEx(sourceIO, &n);
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
if (decompress == NULL)
|
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
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);
|
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
totalFrames = decompress->GetInfo(APE_INFO_TOTAL_BLOCKS);
|
2005-06-30 16:13:22 +00:00
|
|
|
|
2007-03-04 18:20:23 +00:00
|
|
|
[self willChangeValueForKey:@"properties"];
|
|
|
|
[self didChangeValueForKey:@"properties"];
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
- (int)readAudio:(void *)buf frames:(UInt32)frames
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
int numread;
|
2007-11-24 20:16:27 +00:00
|
|
|
|
|
|
|
n = decompress->GetData((char *)buf, frames, &numread);
|
2005-06-02 18:16:43 +00:00
|
|
|
if (n != ERROR_SUCCESS)
|
|
|
|
{
|
2007-02-24 20:36:27 +00:00
|
|
|
NSLog(@"ERROR: %i", n);
|
2005-06-02 18:16:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2007-11-24 20:16:27 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
return numread;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)close
|
|
|
|
{
|
|
|
|
// DBLog(@"CLOSE");
|
|
|
|
if (decompress)
|
|
|
|
delete decompress;
|
2007-03-04 18:20:23 +00:00
|
|
|
if (sourceIO)
|
|
|
|
delete sourceIO;
|
|
|
|
|
|
|
|
[source release];
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
decompress = NULL;
|
2007-03-04 18:20:23 +00:00
|
|
|
sourceIO = NULL;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
- (long)seek:(long)frame
|
2005-06-02 18:16:43 +00:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
// DBLog(@"HELLO: %i", int(frequency*((double)milliseconds/1000.0)));
|
2007-11-24 20:16:27 +00:00
|
|
|
r = decompress->Seek(frame);
|
2005-06-05 18:52:35 +00:00
|
|
|
|
2007-11-24 20:16:27 +00:00
|
|
|
return frame;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
2007-03-04 18:41:43 +00:00
|
|
|
- (void)setSource:(id<CogSource>)s
|
|
|
|
{
|
|
|
|
[s retain];
|
|
|
|
[source release];
|
|
|
|
source = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id<CogSource>)source
|
|
|
|
{
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
- (NSDictionary *)properties
|
|
|
|
{
|
|
|
|
return [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithInt:channels],@"channels",
|
|
|
|
[NSNumber numberWithInt:bitsPerSample],@"bitsPerSample",
|
|
|
|
[NSNumber numberWithFloat:frequency],@"sampleRate",
|
2007-11-24 20:16:27 +00:00
|
|
|
[NSNumber numberWithDouble:totalFrames],@"totalFrames",
|
2007-05-27 15:11:30 +00:00
|
|
|
[NSNumber numberWithBool:[source seekable]], @"seekable",
|
2007-03-05 00:36:12 +00:00
|
|
|
@"host",@"endian",
|
2007-02-24 20:36:27 +00:00
|
|
|
nil];
|
|
|
|
}
|
|
|
|
|
2007-03-04 18:41:43 +00:00
|
|
|
|
2007-02-24 20:36:27 +00:00
|
|
|
+ (NSArray *)fileTypes
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObject:@"ape"];
|
|
|
|
}
|
|
|
|
|
2007-10-14 18:39:58 +00:00
|
|
|
+ (NSArray *)mimeTypes
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects:@"audio/x-ape", nil];
|
|
|
|
}
|
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
@end
|