Так, вопрос к тем, кто компилировал этот MAD.
С выводом все понятно:
Код
static
enum mad_flow output(void *data,
struct mad_header const *header,
struct mad_pcm *pcm)
...
Патчим эту функцию, там внутри все по семплам.
Вот со входным потоком непонятки
Если так (вызов декодера):
Код
char fbuffer[8192];
unsigned int fsize;
int main(void)
{
fsize=4000000; //Сколько-то там
decode((unsigned char const *)fbuffer, fsize);
return 0;
}
Ну и еще мы тут файл открываем, но это опущено...
А далее патчим input:
Код
/*
* This is a private message structure. A generic pointer to this structure
* is passed to each of the callback functions. Put here any data you need
* to access from within the callbacks.
*/
struct buffer {
unsigned char const *start;
unsigned long length;
};
/*
* This is the input callback. The purpose of this callback is to (re)fill
* the stream buffer which is to be decoded. In this example, an entire file
* has been mapped into memory, so we just call mad_stream_buffer() with the
* address and length of the mapping. When this callback is called a second
* time, we are finished decoding.
*/
static
enum mad_flow input(void *data,
struct mad_stream *stream)
{
struct buffer *buffer = data;
if (!buffer->length)
return MAD_FLOW_STOP;
fread(infile,fbuffer,sizeof(fbuffer));
if (buffer->length>=sizeof(fbuffer))
{
mad_stream_buffer(stream, buffer->start, sizeof(fbuffer));
buffer->length-=sizeof(fbuffer);
}
else
{
mad_stream_buffer(stream, buffer->start, buffer->length);
buffer->length=0;
}
return MAD_FLOW_CONTINUE;
}
А тут мы по кусочкам вычитываем из файла и вызываем mad_stream_buffer с вычитанным кусочком... Так стрельнет? В оригинале там маппинг ВСЕГО файла на память, как-то слабо без MMU