cog/Sound/SoundFile/VorbisFile.m

80 lines
1.4 KiB
Matlab
Raw Normal View History

2005-06-02 18:16:43 +00:00
//
// VorbisFile.m
// zyVorbis
//
// Created by Vincent Spader on 1/22/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 "VorbisFile.h"
@implementation VorbisFile
- (BOOL)open:(const char *)filename
{
inFd = fopen(filename, "rb");
if (inFd == 0)
return NO;
if (ov_open(inFd, &vorbisRef, NULL, 0) != 0)
return NO;
return [self readInfo];
}
- (BOOL)readInfo
{
vorbis_info *vi;
vi = ov_info(&vorbisRef, -1);
2006-06-19 00:39:41 +00:00
bitrate = (int)(vi->bitrate_nominal/1000.0);
2005-06-02 18:16:43 +00:00
channels = vi->channels;
bitsPerSample = vi->channels * 8;
frequency = vi->rate;
totalSize = ov_pcm_total(&vorbisRef, -1) * channels * bitsPerSample/8;
// DBLog(@"Ok to go WITH OGG.");
return YES;
}
- (BOOL)readInfo:(const char *)filename
{
2005-06-29 15:28:20 +00:00
[self open:filename]; //automatically invokes readInfo
return YES;
2005-06-02 18:16:43 +00:00
}
- (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, &currentSection);
while (total != size && numread > 0)
{
total += numread;
numread = ov_read(&vorbisRef, &((char *)buf)[total], size - total, 0, bitsPerSample/8, 1, &currentSection);
}
return total;
}
- (void)close
{
ov_clear(&vorbisRef);
}
2005-06-06 17:47:29 +00:00
- (double)seekToTime:(double)milliseconds
2005-06-02 18:16:43 +00:00
{
ov_time_seek(&vorbisRef, (double)milliseconds/1000.0);
return milliseconds;
2005-06-02 18:16:43 +00:00
}
@end