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 "MonkeysFile.h"
|
|
|
|
#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 MonkeysFile
|
|
|
|
|
|
|
|
- (BOOL)open:(const char *)filename
|
|
|
|
{
|
|
|
|
int n;
|
2006-04-17 02:18:09 +00:00
|
|
|
str_utf16 *chars = NULL;
|
|
|
|
|
|
|
|
chars = GetUTF16FromUTF8((const unsigned char *)filename);
|
|
|
|
if(chars == NULL)
|
|
|
|
return NO;
|
2005-06-02 18:16:43 +00:00
|
|
|
|
2006-04-17 02:18:09 +00:00
|
|
|
decompress = CreateIAPEDecompress(chars, &n);
|
|
|
|
free(chars);
|
2005-06-02 18:16:43 +00:00
|
|
|
|
|
|
|
if (decompress == NULL)
|
|
|
|
{
|
|
|
|
DBLog(@"ERROR OPENING FILE");
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
frequency = decompress->GetInfo(APE_INFO_SAMPLE_RATE);
|
|
|
|
bitsPerSample = decompress->GetInfo(APE_INFO_BITS_PER_SAMPLE);
|
|
|
|
channels = decompress->GetInfo(APE_INFO_CHANNELS);
|
|
|
|
|
|
|
|
totalSize = decompress->GetInfo(APE_INFO_TOTAL_BLOCKS)*bitsPerSample/8*channels;
|
2005-06-30 16:13:22 +00:00
|
|
|
|
2005-06-02 18:16:43 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)readInfo:(const char *)filename
|
|
|
|
{
|
2005-06-29 15:28:20 +00:00
|
|
|
return [self open:filename];
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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)
|
|
|
|
{
|
|
|
|
DBLog(@"ERROR: %i", n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
numread *= blockAlign;
|
|
|
|
// DBLog(@"READ DATA: %i", numread);
|
|
|
|
|
|
|
|
// DBLog(@"NUMREAD: %i", numread);
|
|
|
|
return numread;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)close
|
|
|
|
{
|
|
|
|
// DBLog(@"CLOSE");
|
|
|
|
if (decompress)
|
|
|
|
delete decompress;
|
|
|
|
|
|
|
|
decompress = NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-05 18:52:35 +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)));
|
2005-06-05 18:52:35 +00:00
|
|
|
|
|
|
|
return milliseconds;
|
2005-06-02 18:16:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|