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.

Audio > sound using interrupts

#39669 - nico - Mon Apr 11, 2005 8:17 am

Hi,

I set up some code for playing sound effects copying the data with the help of interrupts, as I am using the Xport and I need the GBA to react to other interrupts, and as far as I know if using DMA an interrupt is not processed until DMA is finished.
However, I only get some crappy noise playing. My idea was to set Timer0 to 1024 mode so it gives a signal of 16.387 or so kHz (I dont remember the exact value).
Then, I set the Timer0 counter to 0xfffc, and configured Timer1 so it is called every time Timer0 overflows, namely after 4 cycles. I then update the FIFO_A Register with raw data from an array.

Heres the code:

Code:

if(REG_IF & INT_TM0) {
        REG_IF = INT_TM0;
         
        tm0count++;
         
        REG_SGFIFOA_L = (_test[tm0count*4] & 0xFF) + (_test[tm0count*4+1]<<8 & 0xFF00);
        REG_SGFIFOA_H = (_test[tm0count*4+2] & 0xFF) + (_test[tm0count*4+3]<<8 & 0xFF00);
                 
         }



and in the main function

Code:

REG_SGCNT0_H = 0x0b0F;
   
   REG_SGFIFOA_L = 0;
   REG_SGFIFOA_H = 0;
   REG_SGCNT1 = 0x0080;
   

    REG_TM0D = 0xfffe;  // interrupt every 4x16.387 kHz
    SetTimerMode0(TIME_FREQUENCY_1024 | TIME_ENABLE | TIME_IRQ_ENABLE);
    REG_TM1D = 0xd008;
    SetTimerMode1(TIME_ENABLE | TM_CASCADE | TIME_IRQ_ENABLE ); 

REG_IME = 0x00;   
REG_IE = (INT_TM3 | INT_TM0 | INT_TM1 | INT_CART);   
   REG_IF = 0xffff;                                               // Sets all Flags back
    REG_IME = 1;                                                   // enables Interrupts



any idea what the problem is?

#39671 - ampz - Mon Apr 11, 2005 8:39 am

nico wrote:
and as far as I know if using DMA an interrupt is not processed until DMA is finished.

An interrupt is not processed until the previous interrupt is finished either. The difference is that DMA is many times faster than interrupts.
Each DMA audio transfer will only take a few CPU cycles, while your interrupt routine will probably take something like 100 cycles.