33#import <vorbis/vorbisfile.h>
54- (NSDictionary*)comments;
60- (id)initWithPath:(NSString*)inPath
65 if ([[inPath pathExtension] isEqual:
@"ogg"]) {
74 if ([[inPath pathExtension] isEqual:
@"ogg"]) {
80- (size_t)streamToBuffer:(
char*)ioBuffer
85- (BOOL)readCreatingBuffer:(
char**)outBuffer withFrameCount:(
size_t*)outSize
87 if (NULL != outBuffer)
124- (id)initWithPath:(NSString*)path
126 if ((
self = [super init])) {
129 _name = [[
path lastPathComponent] retain];
132 NSArray* components = [
path pathComponents];
134 for (i = 0; i < cl; i++) {
135 NSString* component = [
components objectAtIndex:i];
136 if ([[[component pathExtension] lowercaseString] isEqualToString:
@"oxz"]) {
149 file = fopen([path UTF8String],
"rb");
151 err = ov_open_callbacks(file, &
_vf, NULL, 0, OV_CALLBACKS_DEFAULT);
168 range.length = i + 1;
169 NSString* zipFile = [
NSString pathWithComponents:[
components subarrayWithRange:range]];
170 range.location = i + 1;
171 range.length = cl - (i + 1);
172 NSString* containedFile = [
NSString pathWithComponents:[
components subarrayWithRange:range]];
174 const char* zipname = [
zipFile UTF8String];
175 if (zipname != NULL) {
206 ov_callbacks _callbacks = {
212 err = ov_open_callbacks(
self, &
_vf, NULL, 0, _callbacks);
228#ifdef OOLITE_DEBUG_SOUND_FILE_OPENING
238#ifdef OOLITE_DEBUG_SOUND_FILE_OPENING
255 NSMutableDictionary* result =
nil;
256 NSString *comment, *key, *value;
264 for (i = 0; i !=
count; ++i) {
265 comment = [[
NSString alloc] initWithBytesNoCopy:comments->user_comments[
i] length:comments->comment_lengths[
i] encoding:NSUTF8StringEncoding freeWhenDone:NO];
266 range = [
comment rangeOfString:@"="];
267 if (0 != range.length) {
268 key = [
comment substringToIndex:range.location];
269 value = [
comment substringFromIndex:range.location + 1];
274 [
result setObject:value forKey:key];
284- (BOOL)readCreatingBuffer:(
char**)outBuffer withFrameCount:(
size_t*)outSize
286 char *buffer = NULL, *dst;
287 size_t sizeInFrames = 0;
291 int frameSize = [
self isStereo] ? 4 : 2;
292 ogg_int64_t totalSizeInFrames;
295 if (NULL != outBuffer)
299 if (NULL == outBuffer || NULL == outSize)
303 totalSizeInFrames = ov_pcm_total(&
_vf, -1);
304 assert((uint64_t)totalSizeInFrames < (uint64_t)SIZE_MAX);
305 sizeInFrames = (size_t)totalSizeInFrames;
309 buffer = malloc(
sizeof(
char) * frameSize * sizeInFrames);
314 if (OK && sizeInFrames) {
315 remaining = (
int)
MIN(frameSize * sizeInFrames, (
size_t)INT_MAX);
321 int toRead =
sizeof(pcmout);
322 if (remaining < toRead) {
325 framesRead = ov_read(&
_vf, pcmout, toRead, 0, 2, 1, NULL);
326 if (framesRead <= 0) {
327 if (OV_HOLE == framesRead)
333 memcpy(dst, &pcmout,
sizeof(
char) * framesRead);
335 remaining -= framesRead;
337 }
while (0 < remaining);
339 sizeInFrames -= remaining;
344 *outSize = sizeInFrames * frameSize;
352- (size_t)streamToBuffer:(
char*)buffer
363 int toRead =
sizeof(pcmout);
364 if (remaining < toRead) {
367 framesRead = ov_read(&
_vf, pcmout, toRead, 0, 2, 1, NULL);
368 if (framesRead <= 0) {
369 if (OV_HOLE == framesRead)
374 memcpy(dst, &pcmout,
sizeof(
char) * framesRead);
375 remaining -=
sizeof(char) * framesRead;
376 dst +=
sizeof(char) * framesRead;
377 streamed +=
sizeof(char) * framesRead;
378 }
while (0 < remaining);
388 if ((uint64_t)SIZE_MAX < (uint64_t)
size)
389 size = (ogg_int64_t)SIZE_MAX;
395 return 1 < ov_info(&
_vf, -1)->channels;
400 return [
NSString stringWithFormat:@"<%@ %p>{\"%@\", comments=%@}", [
self className],
self, _name, [
self comments]];
405 return ov_info(&
_vf, -1)->rate;
414 ov_pcm_seek(&
_vf, 0);
421 ov_callbacks _callbacks = {
427 ov_open_callbacks(
self, &
_vf, NULL, 0, _callbacks);
433 return [[_name retain] autorelease];
441 size_t toRead =
size * nmemb;
442 void*
buf = (
void*)malloc(toRead);
447 memcpy(ptr,
buf, err);
#define OOAL_STREAM_CHUNK_SIZE
static size_t OOReadOXZVorbis(void *ptr, size_t size, size_t nmemb, void *datasource)
static int OOCloseOXZVorbis(void *datasource)
#define OOLog(class, format,...)
NSString *const kOOLogFileNotFound
NSDictionary * comments()
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
int ZEXPORT unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity)
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *szFileName, uLong fileNameBufferSize, void *extraField, uLong extraFieldBufferSize, char *szComment, uLong commentBufferSize)
int ZEXPORT unzOpenCurrentFile(unzFile file)
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, unsigned len)
unzFile ZEXPORT unzOpen64(const void *path)
int ZEXPORT unzClose(unzFile file)
struct unz_file_info64_s unz_file_info64