31#import <vorbis/vorbisfile.h>
56- (NSDictionary *)comments;
63- (id)initWithPath:(NSString *)inPath
68 if ([[inPath pathExtension] isEqual:
@"ogg"])
79 if ([[inPath pathExtension] isEqual:
@"ogg"])
87- (size_t)streamToBuffer:(
char *)ioBuffer
93- (BOOL)readCreatingBuffer:(
char **)outBuffer withFrameCount:(
size_t *)outSize
95 if (NULL != outBuffer) *outBuffer = NULL;
96 if (NULL != outSize) *outSize = 0;
136- (id)initWithPath:(NSString *)path
138 if ((
self = [super init]))
142 _name = [[path lastPathComponent] retain];
145 NSArray *components = [path pathComponents];
146 cl = [components count];
147 for (i = 0 ; i < cl ; i++)
149 NSString *component = [components objectAtIndex:i];
150 if ([[[component pathExtension] lowercaseString] isEqualToString:
@"oxz"])
166 file = fopen([path UTF8String],
"rb");
169 err = ov_open_callbacks(file, &
_vf, NULL, 0, OV_CALLBACKS_DEFAULT);
189 range.location = 0; range.length = i+1;
190 NSString *zipFile = [NSString pathWithComponents:[components subarrayWithRange:range]];
191 range.location = i+1; range.length = cl-(i+1);
192 NSString *containedFile = [NSString pathWithComponents:[components subarrayWithRange:range]];
195 const char* zipname = [zipFile UTF8String];
208 const char*
filename = [containedFile UTF8String];
240 ov_callbacks _callbacks = {
246 err = ov_open_callbacks(
self, &
_vf, NULL, 0, _callbacks);
264#ifdef OOLITE_DEBUG_SOUND_FILE_OPENING
276#ifdef OOLITE_DEBUG_SOUND_FILE_OPENING
295 NSMutableDictionary *result =
nil;
296 NSString *comment, *key, *value;
305 result = [NSMutableDictionary dictionaryWithCapacity:count];
306 for (i = 0; i !=
count; ++i)
308 comment = [[NSString alloc] initWithBytesNoCopy:comments->user_comments[i] length:comments->comment_lengths[i] encoding:NSUTF8StringEncoding freeWhenDone:NO];
309 range = [comment rangeOfString:@"="];
310 if (0 != range.length)
312 key = [comment substringToIndex:range.location];
313 value = [comment substringFromIndex:range.location + 1];
320 [result setObject:value forKey:key];
331- (BOOL)readCreatingBuffer:(
char **)outBuffer withFrameCount:(
size_t *)outSize
333 char *buffer = NULL, *dst;
334 size_t sizeInFrames = 0;
338 int frameSize = [
self isStereo] ? 4 : 2;
339 ogg_int64_t totalSizeInFrames;
342 if (NULL != outBuffer) *outBuffer = NULL;
343 if (NULL != outSize) *outSize = 0;
344 if (NULL == outBuffer || NULL == outSize) OK = NO;
348 totalSizeInFrames = ov_pcm_total(&
_vf, -1);
349 assert ((uint64_t)totalSizeInFrames < (uint64_t)SIZE_MAX);
350 sizeInFrames = (size_t)totalSizeInFrames;
355 buffer = malloc(
sizeof (
char) * frameSize * sizeInFrames);
356 if (!buffer) OK = NO;
359 if (OK && sizeInFrames)
361 remaining = (
int)
MIN(frameSize * sizeInFrames, (
size_t)INT_MAX);
368 int toRead =
sizeof(pcmout);
369 if (remaining < toRead)
373 framesRead = ov_read(&
_vf, pcmout, toRead, 0, 2, 1, NULL);
376 if (OV_HOLE == framesRead)
continue;
381 memcpy(dst, &pcmout,
sizeof (
char) * framesRead);
383 remaining -= framesRead;
385 }
while (0 < remaining);
387 sizeInFrames -= remaining;
393 *outSize = sizeInFrames*frameSize;
397 if (buffer) free(buffer);
403- (size_t)streamToBuffer:(
char *)buffer
415 int toRead =
sizeof(pcmout);
416 if (remaining < toRead)
420 framesRead = ov_read(&
_vf, pcmout, toRead, 0, 2, 1, NULL);
423 if (OV_HOLE == framesRead)
continue;
427 memcpy(dst, &pcmout,
sizeof (
char) * framesRead);
428 remaining -= sizeof(char) * framesRead;
429 dst += sizeof(char) * framesRead;
430 streamed += sizeof(char) * framesRead;
431 }
while (0 < remaining);
442 if ((uint64_t)SIZE_MAX < (uint64_t)
size)
size = (ogg_int64_t)SIZE_MAX;
449 return 1 < ov_info(&
_vf, -1)->channels;
455 return [NSString stringWithFormat:@"<%@ %p>{\"%@\", comments=%@}", [
self className], self, _name, [
self comments]];
461 return ov_info(&
_vf, -1)->rate;
474 ov_pcm_seek(&
_vf, 0);
481 ov_callbacks _callbacks = {
487 ov_open_callbacks(
self, &
_vf, NULL, 0, _callbacks);
494 return [[_name retain] autorelease];
503 size_t toRead =
size*nmemb;
504 void *
buf = (
void*)malloc(toRead);
510 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)