Re: streaming audio
Posted: Fri Jun 26, 2009 6:47 pm
buffer_length = 4096 should be fine.
Did you remember to call mmStreamUpdate periodically?
Did you remember to call mmStreamUpdate periodically?
Code: Select all
sys.samp_count = 0;
Code: Select all
s16 * test;
test++;
Code: Select all
#include <nds.h>
#include <filesystem.h>
#include <fat.h>
#include <stdio.h>
#include <stdlib.h>
#include "ivorbiscodec.h"
#include "ivorbisfile.h"
#include <maxmod9.h>
#define OGG_BUFFER_GROOTTE (4096)
OggVorbis_File vf;
u8 channels;
u32 gelezen;
u32 samplecount;
mm_stream mystream;
void Update_OGG_Stream(OggVorbis_File * vf, void * buffer){
int current_section;
gelezen = 0;// we hebben immers nog niks gelezen in deze update
while(gelezen<OGG_BUFFER_GROOTTE){// zolang het gelezen minder is dan de
//buffer grootte
long ret = ov_read(vf,buffer,(OGG_BUFFER_GROOTTE -gelezen), ¤t_section);
if(ret == 0){// EOF
iprintf("eind van de file, kies een andere\n");
ov_clear(vf); // close the ogg file
mmStreamClose(); // colse the stream
break;
}
if (ret < 0) {// there's an error with decoding
iprintf("fout tijdens decoden");
break;
}
else {
buffer +=ret;
gelezen +=ret;
}
}
}
mm_word on_stream_request( mm_word length, mm_addr dest, mm_stream_formats format )
{
int filled = 0;
u8 *target = (u8*)dest;
while( length >= 1024 ) {
length -= 1024;
filled += 1024;
Update_OGG_Stream(&vf, target);
target+=4096 // because it's an u8 pointer now instead of a s16
}
return filled;
}
int main(int argc, char **argv){
fatInitDefault();
FILE * pfile;
pfile = fopen("liedje.ogg", "rb");
consoleDemoInit();
mm_ds_system sys;
sys.mod_count = 0;
sys.samp_count = 0;
sys.mem_bank = 0;
sys.fifo_channel = FIFO_MAXMOD;
mmInit( &sys );
mm_stream mystream;
mystream.sampling_rate = 44100;
mystream.buffer_length = 4096;
mystream.callback = on_stream_request;
mystream.format = MM_STREAM_16BIT_STEREO;
mystream.timer = MM_TIMER0;
mystream.manual = true;
Open_OGG_File(pfile, &vf);
mmStreamOpen(&mystream );
while(1){
mmStreamUpdate(); // update the ogg stream
swiWaitForVBlank();
}
return(0);
}