Homebrew Streaming music with libnds

  • Thread starter Thread starter corenting
  • Start date Start date
  • Views Views 4,379
  • Replies Replies 2

corenting

Well-Known Member
Member
Joined
Jul 17, 2008
Messages
288
Solutions
3
Reaction score
54
Trophies
1
Website
www.corenting.fr
XP
1,077
Country
France
Hello,

I'm working on an AndroDaft (iDaft clone with more songs) port for the DS using libnds + nflib.

But I have a problem...
mad.gif
The background music of "Harder Better Faster Stronger" is too big to fit in the memory
So, I wanted to stream it from the NitroFS using MaxMod. I saw that there is a documentation (on maxmod.org) and one example (in devkitpro's examples). But I don't know how to convert sounds for MaxMod using mmutils. And I don't know if MaxMod will create conflicts with nflib and the sound functions it provides. So if someone can help me with this it will be great.
 
Hi,

You could convert the music into a raw format like 22050hz 16-bit stereo and then stream it manually.

Open the file from nitrofs and create a stream:
Code:
file = fopen("somesong.raw","rb");

mm_stream mystream;
mystream.buffer_length = 1024;
mystream.callback = stream;
mystream.timerÂÂ= MM_TIMER0;
mystream.manual = true;
mystream.sampling_rate = 22050;
mystream.format = MM_STREAM_16BIT_STEREO;
mmStreamOpen(&mystream);

while(1){
ÂÂÂÂ//Read data from the file to the buffer
ÂÂÂÂmmStreamUpdate();
ÂÂÂÂ
ÂÂÂÂ//Do other stuff
}

When the music is stored raw you can just read it directly to the audio buffer:
Code:
mm_word stream(mm_word length, mm_addr dest, mm_stream_formats format){ÂÂÂÂ
ÂÂÂÂsize_t samplesize;
ÂÂÂÂswitch(format){
ÂÂÂÂÂÂÂÂcase MM_STREAM_8BIT_MONO: samplesize = 1; break;
ÂÂÂÂÂÂÂÂcase MM_STREAM_8BIT_STEREO: samplesize = 2; break;
ÂÂÂÂÂÂÂÂcase MM_STREAM_16BIT_MONO: samplesize = 2; break;
ÂÂÂÂÂÂÂÂcase MM_STREAM_16BIT_STEREO: samplesize = 4; break;
ÂÂÂÂ}
ÂÂÂÂ
ÂÂÂÂint res = fread(dest,samplesize,length,file);
ÂÂÂÂif(res){
ÂÂÂÂÂÂÂÂlength = res;
ÂÂÂÂ} else {
ÂÂÂÂÂÂÂÂ//End of file
ÂÂÂÂÂÂÂÂlength = 0;
ÂÂÂÂ}
ÂÂÂÂ
ÂÂÂÂreturn length; //Return the number of samples read
}

I have created a small example that streams music from nitrofs and plays some soundeffects from memory. AndroDaft.nds, source.zip

Hope this helps
smile.gif
 
Thanks you very much for this useful answer. I will try to apply it to my homebrew... Expect a demo soon.

EDIT : It's a bit complicated for me to integrate this in my code... So it will take longer. I'm also looking with other librairies (I know I can do this with PAlib, but I don't want to use PAlib for this project).
 

Site & Scene News

Popular threads in this forum