Some WMA cleanup, more to come.

CQTexperiment
areff 2008-03-01 14:11:30 +00:00
parent d7826ee144
commit e5187b9a48
2 changed files with 13 additions and 11 deletions

View File

@ -16,7 +16,7 @@
{ {
id<CogSource> source; id<CogSource> source;
void *sampleBuffer; void *sampleBuffer;
int numSamples; int numFrames;
int samplePos; int samplePos;
AVFormatContext *ic; AVFormatContext *ic;

View File

@ -25,20 +25,20 @@
const char *filename = [[[source url] path] UTF8String]; const char *filename = [[[source url] path] UTF8String];
ic = NULL; ic = NULL;
numSamples = 0; numFrames = 0;
samplePos = 0; samplePos = 0;
sampleBuffer = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE); sampleBuffer = av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE);
// register all available codecs // register all available codecs
av_register_all(); av_register_all();
NSLog(@"lolbots: %s", filename);
err = av_open_input_file(&ic, filename, NULL, 0, NULL); err = av_open_input_file(&ic, filename, NULL, 0, NULL);
if (err < 0) if (err < 0)
{
NSLog(@"Opening .WMA file failed horribly: %d", err); NSLog(@"Opening .WMA file failed horribly: %d", err);
return NO;
}
for(i = 0; i < ic->nb_streams; i++) { for(i = 0; i < ic->nb_streams; i++) {
c = &ic->streams[i]->codec; c = &ic->streams[i]->codec;
@ -89,7 +89,8 @@
bitrate = ic->bit_rate; bitrate = ic->bit_rate;
bitsPerSample = c->channels * 8; bitsPerSample = c->channels * 8;
totalFrames = c->sample_rate * (ic->duration/1000000LL); totalFrames = c->sample_rate * (ic->duration/1000000LL);
frequency = 0; frequency = c->sample_rate;
seekable = YES;
return YES; return YES;
@ -117,10 +118,10 @@
while (frames > 0) while (frames > 0)
{ {
if (samplePos < numSamples) if (samplePos < numFrames)
{ {
int samplesLeft; int samplesLeft;
samplesLeft = numSamples - samplePos; samplesLeft = numFrames - samplePos;
if (samplesLeft > frames) if (samplesLeft > frames)
samplesLeft = frames; samplesLeft = frames;
@ -135,14 +136,14 @@
{ {
if (av_read_frame(ic, &framePacket) < 0) if (av_read_frame(ic, &framePacket) < 0)
{ {
NSLog(@"Uh oh..."); NSLog(@"Uh oh... av_read_frame returned negative");
break; break;
} }
size = framePacket.size; size = framePacket.size;
inbuf_ptr = framePacket.data; inbuf_ptr = framePacket.data;
len = avcodec_decode_audio(c, (void *)sampleBuffer, &numSamples, len = avcodec_decode_audio(c, (void *)sampleBuffer, &numFrames,
inbuf_ptr, size); inbuf_ptr, size);
if (len < 0) if (len < 0)
@ -151,7 +152,7 @@
if (out_size <= 0) if (out_size <= 0)
continue; continue;
numSamples /= bytesPerFrame; numFrames /= bytesPerFrame;
samplePos = 0; samplePos = 0;
// the frame packet needs to be freed before we av_read_frame a new one // the frame packet needs to be freed before we av_read_frame a new one
@ -167,6 +168,7 @@
- (long)seek:(long)frame - (long)seek:(long)frame
{ {
NSLog(@"frame: %ld", frame);
return 0; return 0;
} }