gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Announcements And Comments > Sonic AS, GBA/DS Midi player

#170549 - Ruben - Thu Oct 01, 2009 6:46 pm

Well, that was quick xD

Long story short, I got bored a few days ago, so I wrote out the whole music engine in assembler, got bored again, and ported it to the DS just cos I can =D

Sonic AS has 16 channels polyphony for the DS, and variable polyphony on the GBA. It has support for variable music players, and the DS version can handle PCM8/16 and ADPCM data, as it uses the hardware channels. The GBA version can also have either nearest neighbour interpolation (that is, no interpolation; this is fast), or linear interpolation, with .23 fixed point accuracy, which can be toggled by changing the variables in sasInternal.inc.
Since it's written in all assembler, the memory footprint is rather low.

All processing is done on the ARM7 side, with the ARM9 simply signaling to play/stop, etc.

As per usual, it comes with all sources, assets, etc., and yeah.
You can get it here.

I think that's the final music player I will code, as I am finally happy with it, so yeah, no more spam from Aik-kun. ^_^'
_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#170571 - UglyMike - Fri Oct 02, 2009 10:15 pm

Hmmmmmmmmmmmmm,

I didn't see an obvious way to load music files other than the "FFII Fight 1". Anything I'm missing?

#170574 - Ruben - Sat Oct 03, 2009 4:23 am

Left/Right changes the song ^_^'
_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#170575 - hacker013 - Sat Oct 03, 2009 11:29 am

on the first view it is great *played the demo ;)* but can I also play sound effects with it ?
_________________
Let the nds be with you.

#170576 - Ruben - Sat Oct 03, 2009 11:53 am

Yes, sound effects can be played back as song data (remember, it has a variable amount of music players ;)), which allows for more 'flexible' effects. Alternatively, you can add your own function that sets up a channel to play a single sound.

Personally, I prefer the 'song' method because it allows more 'tricks' and stuff, but yeah.

EDIT:

I got bored so I wrote the code for a single sound effect ^_^'

Code:
@ DS Version
    push    {r4}
    ldr     r1, =sasChan        @ &chan[0]
    mov     r2, #0x10
#if ALLCHAN_UNLOCK
    mov     r3, r1              @ aux_chan
#else
    mov     r3, #0x00           @ aux_chan
#endif
1:  ldrb    r4, [r1]
    lsr     r4, r4, #0x01       @ if(chan->stat == off)
    bcc     .LChanReady         @   goto chan_ok
    lsr     r4, #0x04
    cmp     r4, #sasRelease
    bne     2f
    mov     r3, r1
2:  add     r1, #SAS_CHANSIZE
    sub     r2, #0x01
    bhi     1b
    mov     r1, r3
#if !ALLCHAN_UNLOCK
    beq     .LNoChan4FX
#endif

    mov     r2, #sasOn + sasNoteOn
    strb    r2, [r1]
    ldr     r2, [r0, #0x04]
    lsr     r2, #0x0A
    str     r2, [r1, #0x04]
    mov     r2, #0x00
    mov     r3, #0x00
    mov     r4, #0x00
    add     r1, #0x10
    stmia   r1!, {r0,r2-r4}

.LNoChan4FX:
    pop     {r4}
    bx      lr

@ GBA Version
    push    {r4}
    ldr     r1, =sasChan        @ &chan[0]
    ldr     r2, =sasVar
    ldrb    r2, [r2, #0x02]
#if ALLCHAN_UNLOCK
    mov     r3, r1              @ aux_chan
#else
    mov     r3, #0x00           @ aux_chan
#endif
1:  ldrb    r4, [r1]
    lsr     r4, r4, #0x01       @ if(chan->stat == off)
    bcc     .LChanReady         @   goto chan_ok
    lsr     r4, #0x04
    cmp     r4, #sasRelease
    bne     2f
    mov     r3, r1
2:  add     r1, #SAS_CHANSIZE
    sub     r2, #0x01
    bhi     1b
    mov     r1, r3
#if !ALLCHAN_UNLOCK
    beq     .LNoChan4FX
#endif

    mov     r2, #sasOn + sasNoteOn
    strb    r2, [r1]
    ldr     r2, [r0, #0x04]
    lsr     r2, #0x0A
    str     r2, [r1, #0x0C]
    mov     r2, #0x00
    mov     r3, #0x00
    mov     r4, #0x00
    add     r1, #0x20
    stmia   r1!, {r0,r2-r4}

.LNoChan4FX:
    pop     {r4}
    bx      lr


However, this code is untested so.. =P
_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#170577 - hacker013 - Sat Oct 03, 2009 12:08 pm

can you give an example because i don't understand the asm :(
_________________
Let the nds be with you.

#170578 - Ruben - Sat Oct 03, 2009 12:15 pm

Well.. create a file called "sasSFX.s" (in the case of the DS, stick it into the ARM7 source). In this file, paste this...

Code:
/**********************************************\
 *            _______       _______           *
 *           / _____/ _____/ _____/           *
 *           \_____ \/ __  \_____ \           *
 *           /______/__||__/______/           *
 *                                            *
 *                  Sonic AS                  *
 *       Copyright (C) 2009 Ruben Nunez       *
 *                                            *
\**********************************************/

#include <sasInternal.inc>

/**********************************************/

.global sasSFX

/**********************************************/

.text
.align
.thumb
.thumb_func

sasSFX:
    @ Paste the code above in here (get
    @ rid of these lines, too

.align
.size sasSFX, .-sasSFX

/**********************************************\
 * EOF                                        *
\**********************************************/


If this is for the DS, you will also need an ARM9 function to signal it to play, so make another file named "sasSFX.s" and put it in the ARM9 source. Paste this in it...

Code:
/**********************************************\
 *            _______       _______           *
 *           / _____/ _____/ _____/           *
 *           \_____ \/ __  \_____ \           *
 *           /______/__||__/______/           *
 *                                            *
 *                  Sonic AS                  *
 *       Copyright (C) 2009 Ruben Nunez       *
 *                                            *
\**********************************************/

#include <sasInternal.inc>

/**********************************************/

.global sasSFX

/**********************************************/

.text
.align
.thumb
.thumb_func

sasSFX:
   mov      r1, #SAS_FIFOSFX
   lsl      r1, #0x1C
   orr      r1, r0
   mov      r0, #SAS_FIFOCHAN
   ldr      r2, =fifoSendValue32
   bx      r2

.align
.size sasSFX, .-sasSFX

/**********************************************\
 * EOF                                        *
\**********************************************/


To make this work, you have to add this line to the sasInternal.inc file

Code:
#define SAS_FIFOCHAN    ( 8)
#define SAS_FIFOPLAY    ( 1)
#define SAS_FIFOSTOP    ( 2)
#define SAS_FIFOSTOPALL ( 3)
#define SAS_FIFOSFX     ( 4) //! Add this line!


Then you can call this function by adding this line to the sasLib.h file...
Code:
//! sasStopAll(void)
//! Stops all players.
void sasStopAll(void);

//! Add this!
//! sasSFX(const sasWave_t *Wave)
//! Plays \var Wave as an SFX.
void sasSFX(const sasWave_t *Wave);


EDIT:

Shoot, if it's for the DS, you also have to modify the jump table in the ARM7 "sasComm7.s" file

Code:
   .word   0
   .word   sasPlay
   .word   sasStop
   .word   sasStopAll
   .word   sasSFX @ Add this!

_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#170776 - brando132 - Mon Oct 19, 2009 11:48 pm

Is there any way to load your own songs?

#170779 - Ruben - Tue Oct 20, 2009 9:21 am

Sure. You simply use the mid2sas program included in the bin/sfx/mid folder. Once you have your song in a .s file, you place it some place in the ARM[9] source, add it to the song table, and away you go =)
_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#170782 - hacker013 - Tue Oct 20, 2009 5:47 pm

can I also load it from fat or not O_o ?
_________________
Let the nds be with you.

#170787 - Ruben - Tue Oct 20, 2009 7:18 pm

Er, well, I suppose I could modify the sources a fair bit for the DS (this is for the DS, right?) to allow file-access, which should be fun, IMO.

As a matter of interest, did you get the SFX code working? Drop me a line if not and still need to get it working.

EDIT:

Oh, and the sources have been modified a bit, and the GBA mixing code has been re-written, which gives a faster mixing and mixdown speed (at the small cost of no clipping, but it's hardly needed anyway *shrug*).
_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#170790 - hacker013 - Tue Oct 20, 2009 10:10 pm

i'm still trying to get it compiled with my project, because of a wierd reason i don't know, th .s files for de arm7 can't include .h files so this engine doesn't compile O_o
_________________
Let the nds be with you.

#170791 - Ruben - Tue Oct 20, 2009 10:12 pm

Well, I'll have a quick look over my latest sources, add the SFX function and update the DS sources to include support for reading files.
_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#170860 - Ruben - Sat Oct 24, 2009 1:18 am

Well, I've been trying to upload but filefactory is failing on me >_>'

But just so you know:

-DS runs with variable channel count (to allow stuff like libnds sound)
-GBA mixer code has been heavily optimized
-Music code has been revised
-Fixed pitch bend stuff
-Added SFX code

I think I'm going to make new 'demonstration' files, but in the meantime you can download the sources for Sonic AS v1.1 here.

EDIT:

I made a new GBA demonstration file (as I'm far more 'fluent' with GBA than DS), you can get it here.

It includes all sources for it, plus somewhat revised sound code and a song not written by me to show that it works with other Midi files, too. I'll start work on the DS demonstration+upgrade soon. ^_^'
_________________
I'm 18 and have Asperger's, so if I don't get something at first, just bear with me. *nod*

#170866 - keldon - Sat Oct 24, 2009 11:56 am

Have you considered mediafire?

p.s. I also have unlimited space on my server and can set up ftp access for your own site. It could be something like ruben_super_genius.konelabs.org (or whatever you decide on) ;)

#170868 - Ruben - Sat Oct 24, 2009 12:07 pm

Ah yes, Mediafire. I would've used that, but for some reason the upload stalls when it reaches 100%, which is why I started using filefactory ;)

Quote:
It could be something like ruben_super_genius.konelabs.org

Lol! I'm not sure if I should be amused.. or scared. =P
Either way, that would be good, thanks. Can I add you to MSN and we can talk there?

#170871 - Ruben - Sat Oct 24, 2009 1:21 pm

Okie doke, DS version done. I didn't bother at *all* with the samples because I'm REALLY tired (it's 11:20pm here and I only got 6 hours sleep, been awake since 7am). You can get it here.

#171046 - mukunda - Thu Oct 29, 2009 7:42 am

Cool sounding! and written in tasty asm too :)

#171047 - Ruben - Thu Oct 29, 2009 8:05 am

Hehe, yes it is. ^_^'

I've been thinking of re-writing the Midi converter, but keep forgetting (damn short term memory -_-) and right now it's too hot to do that (I can't concentrate in the heat). After that I may add some minor tweaks to the code and make v1.2. The next thing after that would be to add pattern compression which the music player already supports, but not the converter. =P

#171050 - keldon - Thu Oct 29, 2009 10:05 am

Ruben wrote:
Hehe, yes it is. ^_^'

I've been thinking of re-writing the Midi converter, but keep forgetting (damn short term memory -_-) and right now it's too hot to do that (I can't concentrate in the heat). After that I may add some minor tweaks to the code and make v1.2. The next thing after that would be to add pattern compression which the music player already supports, but not the converter. =P


Do you mind?

#171071 - Ruben - Fri Oct 30, 2009 12:00 am

13*C.... *drools* Wanna trade?