Fixed up Vorbis Decoder and modified MAD to use new source system.
parent
934840ace5
commit
eb5ee1586d
|
@ -29,7 +29,7 @@
|
||||||
int _outputAvailable;
|
int _outputAvailable;
|
||||||
int _fileSize;
|
int _fileSize;
|
||||||
|
|
||||||
FILE *_inFd;
|
id<CogSource> _source;
|
||||||
|
|
||||||
BOOL _seekSkip;
|
BOOL _seekSkip;
|
||||||
|
|
||||||
|
|
|
@ -156,9 +156,9 @@ int parse_headers(struct xing *xing, struct lame *lame, struct mad_bitptr ptr, u
|
||||||
|
|
||||||
frames = 0;
|
frames = 0;
|
||||||
|
|
||||||
fseek(_inFd, 0, SEEK_END);
|
[_source seek:0 whence:SEEK_END];
|
||||||
_fileSize = ftell(_inFd);
|
_fileSize = [_source tell];
|
||||||
fseek(_inFd, 0, SEEK_SET);
|
[_source seek:0 whence:SEEK_SET];
|
||||||
|
|
||||||
BOOL done = NO;
|
BOOL done = NO;
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ int parse_headers(struct xing *xing, struct lame *lame, struct mad_bitptr ptr, u
|
||||||
remainder = stream.bufend - stream.next_frame;
|
remainder = stream.bufend - stream.next_frame;
|
||||||
|
|
||||||
memcpy (buffer, stream.this_frame, remainder);
|
memcpy (buffer, stream.this_frame, remainder);
|
||||||
len = fread(buffer + remainder, 1, BUFFER_SIZE - remainder, _inFd);
|
len = [_source read:buffer + remainder amount:BUFFER_SIZE - remainder];
|
||||||
|
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
break;
|
break;
|
||||||
|
@ -271,24 +271,24 @@ int parse_headers(struct xing *xing, struct lame *lame, struct mad_bitptr ptr, u
|
||||||
|
|
||||||
bitrate /= 1000;
|
bitrate /= 1000;
|
||||||
|
|
||||||
fseek(_inFd, 0, SEEK_SET);
|
[_source seek:0 whence:SEEK_SET];
|
||||||
|
|
||||||
return frames != 0;
|
return frames != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)open:(NSURL *)url
|
- (BOOL)open:(id<CogSource>)source
|
||||||
{
|
{
|
||||||
|
[source retain];
|
||||||
|
[_source release];
|
||||||
|
_source = source;
|
||||||
|
|
||||||
/* First the structures used by libmad must be initialized. */
|
/* First the structures used by libmad must be initialized. */
|
||||||
mad_stream_init(&_stream);
|
mad_stream_init(&_stream);
|
||||||
mad_frame_init(&_frame);
|
mad_frame_init(&_frame);
|
||||||
mad_synth_init(&_synth);
|
mad_synth_init(&_synth);
|
||||||
mad_timer_reset(&_timer);
|
mad_timer_reset(&_timer);
|
||||||
|
|
||||||
_inFd = fopen([[url path] UTF8String], "r");
|
|
||||||
if (!_inFd)
|
|
||||||
return NO;
|
|
||||||
|
|
||||||
bitsPerSample = 16;
|
bitsPerSample = 16;
|
||||||
|
|
||||||
return [self scanFileFast:YES useXing:YES];
|
return [self scanFileFast:YES useXing:YES];
|
||||||
|
@ -442,7 +442,7 @@ static inline signed int scale (mad_fixed_t sample)
|
||||||
remainder = 0;
|
remainder = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = fread(_inputBuffer+remainder, 1, INPUT_BUFFER_SIZE-remainder, _inFd);
|
len = [_source read:_inputBuffer+remainder amount:INPUT_BUFFER_SIZE-remainder];
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
{
|
{
|
||||||
eof = YES;
|
eof = YES;
|
||||||
|
@ -527,7 +527,7 @@ static inline signed int scale (mad_fixed_t sample)
|
||||||
|
|
||||||
- (void)close
|
- (void)close
|
||||||
{
|
{
|
||||||
fclose(_inFd);
|
[_source close];
|
||||||
|
|
||||||
mad_synth_finish(&_synth);
|
mad_synth_finish(&_synth);
|
||||||
mad_frame_finish(&_frame);
|
mad_frame_finish(&_frame);
|
||||||
|
@ -546,7 +546,7 @@ static inline signed int scale (mad_fixed_t sample)
|
||||||
mad_timer_set(&_timer, seconds, 0, 0);
|
mad_timer_set(&_timer, seconds, 0, 0);
|
||||||
new_position = ((double) seconds / (double) total_seconds) * _fileSize;
|
new_position = ((double) seconds / (double) total_seconds) * _fileSize;
|
||||||
|
|
||||||
fseek(_inFd, new_position, SEEK_SET);
|
[_source seek:new_position whence:SEEK_SET];
|
||||||
mad_stream_sync(&_stream);
|
mad_stream_sync(&_stream);
|
||||||
_stream.error = MAD_ERROR_BUFLEN;
|
_stream.error = MAD_ERROR_BUFLEN;
|
||||||
_stream.sync = 0;
|
_stream.sync = 0;
|
||||||
|
@ -572,6 +572,12 @@ static inline signed int scale (mad_fixed_t sample)
|
||||||
nil];
|
nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)seekable
|
||||||
|
{
|
||||||
|
return [_source seekable];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+ (NSArray *)fileTypes
|
+ (NSArray *)fileTypes
|
||||||
{
|
{
|
||||||
return [NSArray arrayWithObjects:@"mp3",nil];
|
return [NSArray arrayWithObjects:@"mp3",nil];
|
||||||
|
|
|
@ -11,13 +11,13 @@
|
||||||
|
|
||||||
@implementation MADPropertiesReader
|
@implementation MADPropertiesReader
|
||||||
|
|
||||||
- (NSDictionary *)propertiesForURL:(NSURL *)url
|
+ (NSDictionary *)propertiesForSource:(id<CogSource>)source
|
||||||
{
|
{
|
||||||
NSDictionary *properties;
|
NSDictionary *properties;
|
||||||
MADDecoder *decoder;
|
MADDecoder *decoder;
|
||||||
|
|
||||||
decoder = [[MADDecoder alloc] init];
|
decoder = [[MADDecoder alloc] init];
|
||||||
if (![decoder open:url])
|
if (![decoder open:source])
|
||||||
{
|
{
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
OggVorbis_File vorbisRef;
|
OggVorbis_File vorbisRef;
|
||||||
int currentSection;
|
int currentSection;
|
||||||
|
int lastSection;
|
||||||
|
|
||||||
BOOL seekable;
|
BOOL seekable;
|
||||||
int bitsPerSample;
|
int bitsPerSample;
|
||||||
|
|
|
@ -81,26 +81,26 @@ long sourceTell(void *datasource)
|
||||||
int total = 0;
|
int total = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
lastSection = currentSection;
|
||||||
numread = ov_read(&vorbisRef, &((char *)buf)[total], size - total, 0, bitsPerSample/8, 1, ¤tSection);
|
numread = ov_read(&vorbisRef, &((char *)buf)[total], size - total, 0, bitsPerSample/8, 1, ¤tSection);
|
||||||
if (numread > 0) {
|
if (numread > 0) {
|
||||||
total += numread;
|
total += numread;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (currentSection != lastSection) {
|
||||||
|
vorbis_info *vi;
|
||||||
|
vi = ov_info(&vorbisRef, -1);
|
||||||
|
|
||||||
|
bitsPerSample = vi->channels * 8;
|
||||||
|
bitrate = (vi->bitrate_nominal/1000.0);
|
||||||
|
channels = vi->channels;
|
||||||
|
frequency = vi->rate;
|
||||||
|
|
||||||
|
NSLog(@"Format changed...");
|
||||||
|
}
|
||||||
|
|
||||||
} while (total != size && numread != 0);
|
} while (total != size && numread != 0);
|
||||||
|
|
||||||
if (numread == 0) {
|
|
||||||
char **ptr=ov_comment(&vorbisRef,-1)->user_comments;
|
|
||||||
vorbis_info *vi=ov_info(&vorbisRef,-1);
|
|
||||||
while(*ptr){
|
|
||||||
NSLog(@"%s\n",*ptr);
|
|
||||||
++ptr;
|
|
||||||
}
|
|
||||||
NSLog(@"Bitstream is %d channel, %ldHz\n",vi->channels,vi->rate);
|
|
||||||
NSLog(@"Decoded length: %ld samples\n",
|
|
||||||
(long)ov_pcm_total(&vorbisRef,-1));
|
|
||||||
NSLog(@"Encoded by: %s\n\n", ov_comment(&vorbisRef,-1)->vendor);
|
|
||||||
NSLog(@"Spewed out crap...");
|
|
||||||
}
|
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue