Streaming music with libnds

Discussion in 'NDS - Emulation and Homebrew' started by corenting, Apr 26, 2011.

Apr 26, 2011

Streaming music with libnds by corenting at 7:35 PM (1,485 Views / 0 Likes) 2 replies

  1. corenting
    OP

    Member corenting Insert random cool title here

    Joined:
    Jul 17, 2008
    Messages:
    288
    Location:
    Paris
    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... [​IMG] 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.
     
  2. sulfyr

    Newcomer sulfyr Newbie

    Joined:
    Jul 3, 2010
    Messages:
    8
    Country:
    Denmark
    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 [​IMG]
     
  3. corenting
    OP

    Member corenting Insert random cool title here

    Joined:
    Jul 17, 2008
    Messages:
    288
    Location:
    Paris
    Country:
    France
    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).
     

Share This Page