2005-06-06 17:47:29 +00:00
|
|
|
//
|
|
|
|
// WavPackFile.m
|
|
|
|
// Cog
|
|
|
|
//
|
2005-07-02 21:02:06 +00:00
|
|
|
// Created by Vincent Spader on 6/6/05.
|
|
|
|
// Copyright 2005 Vincent Spader All rights reserved.
|
2005-06-06 17:47:29 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "WavPackFile.h"
|
|
|
|
|
|
|
|
|
|
|
|
@implementation WavPackFile
|
|
|
|
|
|
|
|
- (BOOL)open:(const char *)filename
|
|
|
|
{
|
|
|
|
int open_flags = 0;
|
|
|
|
char error[80];
|
|
|
|
|
|
|
|
wpc = WavpackOpenFileInput(filename, error, open_flags, 0);
|
|
|
|
if (!wpc)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
channels = WavpackGetNumChannels(wpc);
|
2005-06-29 15:28:20 +00:00
|
|
|
// bitsPerSample = WavpackGetBitsPerSample(wpc);
|
|
|
|
bitsPerSample = 32;
|
|
|
|
|
|
|
|
frequency = WavpackGetSampleRate(wpc);
|
2005-06-06 17:47:29 +00:00
|
|
|
|
|
|
|
int samples;
|
|
|
|
samples = WavpackGetNumSamples(wpc);
|
|
|
|
totalSize = samples * channels * 4;
|
|
|
|
|
|
|
|
bitRate = (int)(WavpackGetAverageBitrate(wpc, TRUE)/1000.0);
|
|
|
|
|
2005-06-29 15:28:20 +00:00
|
|
|
//isBigEndian = YES;
|
2005-06-06 17:47:29 +00:00
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)readInfo:(const char *)filename
|
|
|
|
{
|
2005-06-29 15:28:20 +00:00
|
|
|
[self open:filename]; //does the same damn thing
|
|
|
|
|
|
|
|
return YES;
|
2005-06-06 17:47:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
|
|
|
|
{
|
|
|
|
int numsamples;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
numsamples = size/4/channels;
|
|
|
|
// DBLog(@"NUM SAMPLES: %i %i", numsamples, size);
|
|
|
|
n = WavpackUnpackSamples(wpc, buf, numsamples);
|
|
|
|
|
|
|
|
n *= 4*channels;
|
|
|
|
|
2005-06-29 15:28:20 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < n/2; i++)
|
|
|
|
{
|
|
|
|
// ((UInt32 *)buf)[i] = CFSwapInt32LittleToHost(((UInt32 *)buf)[i]);
|
|
|
|
((UInt16 *)buf)[i] = CFSwapInt16LittleToHost(((UInt16 *)buf)[i]);
|
|
|
|
}
|
|
|
|
|
2005-06-06 17:47:29 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (double)seekToTime:(double)milliseconds
|
|
|
|
{
|
|
|
|
int sample;
|
|
|
|
sample = (frequency/2)*(milliseconds/1000.0);
|
2005-06-30 16:13:22 +00:00
|
|
|
|
2005-06-06 17:47:29 +00:00
|
|
|
WavpackSeekSample(wpc, sample);
|
|
|
|
|
|
|
|
return milliseconds;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)close
|
|
|
|
{
|
|
|
|
WavpackCloseFile(wpc);
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|