2005-06-02 14:16:43 -04:00
|
|
|
//
|
|
|
|
// VorbisFile.m
|
|
|
|
// zyVorbis
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 1/22/05.
|
2005-07-02 17:02:06 -04:00
|
|
|
// Copyright 2005 Vincent Spader All rights reserved.
|
2005-06-02 14:16:43 -04:00
|
|
|
//
|
|
|
|
|
2007-02-24 17:36:27 -03:00
|
|
|
#import "VorbisDecoder.h"
|
2005-06-02 14:16:43 -04:00
|
|
|
|
|
|
|
|
2007-02-24 17:36:27 -03:00
|
|
|
@implementation VorbisDecoder
|
2005-06-02 14:16:43 -04:00
|
|
|
|
2007-02-24 17:36:27 -03:00
|
|
|
- (BOOL)open:(NSURL *)url
|
2005-06-02 14:16:43 -04:00
|
|
|
{
|
2007-02-24 17:36:27 -03:00
|
|
|
inFd = fopen([[url path] UTF8String], "rb");
|
2005-06-02 14:16:43 -04:00
|
|
|
if (inFd == 0)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
if (ov_open(inFd, &vorbisRef, NULL, 0) != 0)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
vorbis_info *vi;
|
|
|
|
|
|
|
|
vi = ov_info(&vorbisRef, -1);
|
2007-02-28 23:56:42 -03:00
|
|
|
|
2005-06-02 14:16:43 -04:00
|
|
|
bitsPerSample = vi->channels * 8;
|
2007-02-24 17:36:27 -03:00
|
|
|
bitrate = (vi->bitrate_nominal/1000.0);
|
|
|
|
channels = vi->channels;
|
2005-06-02 14:16:43 -04:00
|
|
|
frequency = vi->rate;
|
2007-02-28 23:56:42 -03:00
|
|
|
NSLog(@"INFO: %i", bitsPerSample);
|
|
|
|
|
2007-03-01 00:02:30 -03:00
|
|
|
length = ((double)ov_pcm_total(&vorbisRef, -1) * 1000.0)/frequency;
|
2005-06-02 14:16:43 -04:00
|
|
|
|
2007-02-28 23:56:42 -03:00
|
|
|
NSLog(@"Ok to go WITH OGG.");
|
2005-06-02 14:16:43 -04:00
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)fillBuffer:(void *)buf ofSize:(UInt32)size
|
|
|
|
{
|
|
|
|
int numread;
|
|
|
|
int total = 0;
|
|
|
|
|
|
|
|
numread = ov_read(&vorbisRef, &((char *)buf)[total], size - total, 0, bitsPerSample/8, 1, ¤tSection);
|
2007-02-28 23:56:42 -03:00
|
|
|
while (total != size && numread != 0)
|
2005-06-02 14:16:43 -04:00
|
|
|
{
|
2007-02-28 23:56:42 -03:00
|
|
|
if (numread > 0) {
|
|
|
|
total += numread;
|
2005-06-02 14:16:43 -04:00
|
|
|
|
2007-02-28 23:56:42 -03:00
|
|
|
}
|
2005-06-02 14:16:43 -04:00
|
|
|
numread = ov_read(&vorbisRef, &((char *)buf)[total], size - total, 0, bitsPerSample/8, 1, ¤tSection);
|
|
|
|
}
|
2007-02-28 23:56:42 -03:00
|
|
|
|
2005-06-02 14:16:43 -04:00
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)close
|
|
|
|
{
|
|
|
|
ov_clear(&vorbisRef);
|
|
|
|
}
|
|
|
|
|
2005-06-06 13:47:29 -04:00
|
|
|
- (double)seekToTime:(double)milliseconds
|
2005-06-02 14:16:43 -04:00
|
|
|
{
|
|
|
|
ov_time_seek(&vorbisRef, (double)milliseconds/1000.0);
|
2005-06-05 14:52:35 -04:00
|
|
|
|
|
|
|
return milliseconds;
|
2005-06-02 14:16:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-24 17:36:27 -03:00
|
|
|
- (NSDictionary *)properties
|
|
|
|
{
|
|
|
|
return [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[NSNumber numberWithInt:channels], @"channels",
|
|
|
|
[NSNumber numberWithInt:bitsPerSample], @"bitsPerSample",
|
|
|
|
[NSNumber numberWithFloat:frequency], @"sampleRate",
|
|
|
|
[NSNumber numberWithDouble:length], @"length",
|
|
|
|
[NSNumber numberWithInt:bitrate], @"bitrate",
|
|
|
|
nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSArray *)fileTypes
|
|
|
|
{
|
|
|
|
return [NSArray arrayWithObjects:@"ogg",nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-02 14:16:43 -04:00
|
|
|
@end
|