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.

DS development > Popping sounds in streaming.. [Solved]

#149642 - sowee - Wed Jan 23, 2008 5:59 am

I set up streaming code using vblank, fifo, and a timer, theres a counter for every time the code runs through the vblank but it seems to stop at 5...i've been debugging for a while now and can't seem to find the problem

my arm7 main method:
Code:
readUserSettings();
   powerON(POWER_SOUND);
   writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE ) | PM_SOUND_AMP );
   SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F);

   irqInit();
   initClockIRQ();

   SetYtrigger(80);
   
   irqSet(IRQ_VCOUNT , VcountHandler);
   irqSet(IRQ_VBLANK, VblankHandler);
   irqSet(IRQ_FIFO_NOT_EMPTY, SoundFifoHandler);
   irqEnable(IRQ_VBLANK);
   irqEnable(IRQ_VCOUNT);
   irqEnable(IRQ_FIFO_NOT_EMPTY);

   REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR | IPC_FIFO_RECV_IRQ;
   
   SoundSetTimer(0);
   while (1) swiWaitForVBlank();


vblankHandler does this:
Code:
   if(sharedSoundControl->stream.cmd & INIT)
   {
      SoundSetTimer(sharedSoundControl->stream.period);
      sharedSoundControl->stream.cmd &= ~INIT;
   }
   else if(sharedSoundControl->stream.cmd & MIXING)
   {
      sharedSoundControl->stream.inswapandmix++;
      SoundSwapAndMix();
   }
   if(sharedSoundControl->stream.cmd & MIX)
   {
      StreamSound(&sharedSoundControl->stream);
      sharedSoundControl->stream.cmd &= ~MIX;
      sharedSoundControl->stream.cmd |= MIXING;
   }


and SoundFifoHandler does this:
Code:
u32 command;

   if (!(REG_IPC_FIFO_CR & IPC_FIFO_RECV_EMPTY))
   {
      command = REG_IPC_FIFO_RX;
      
      switch(command)
      {
      case FIFO_NONE:
         break;
      case MIXCOMPLETE_ONARM9:
         sharedSoundControl->stream.soundcursor += sharedSoundControl->stream.numsamples;
         if(sharedSoundControl->stream.bits_per_sample == 8)
            while (sharedSoundControl->stream.soundcursor > sharedSoundControl->stream.buffersize) sharedSoundControl->stream.soundcursor -= sharedSoundControl->stream.buffersize;
         else
            while (sharedSoundControl->stream.soundcursor > (sharedSoundControl->stream.buffersize >> 1)) sharedSoundControl->stream.soundcursor -= (sharedSoundControl->stream.buffersize >> 1);
         break;
      }
   }


while SoundSetTimer is:
Code:

void SoundSetTimer(int period)
{
   if(!period)
   {
      TIMER0_DATA = 0;
      TIMER0_CR = 0;
      TIMER1_DATA = 0;
      TIMER1_CR = 0;
   }
   else
   {
      TIMER0_DATA = 0x10000 - (period * 2);
      TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1;

      TIMER1_DATA = 0;
      TIMER1_CR = TIMER_ENABLE | TIMER_CASCADE | TIMER_DIV_1;
   }
}


My problem seems to be that it gets stuck such that it never enters SoundSwapAndMix() so my program keeps on streaming garbage (popping sound).

The relevant code in my arm9 main method is this:
Code:

   irqSet(IRQ_VBLANK, VBlankHandler);
   irqSet(IRQ_FIFO_NOT_EMPTY, FifoHandler);
   irqEnable(IRQ_VBLANK);
   irqEnable(IRQ_FIFO_NOT_EMPTY);
   
   REG_IPC_FIFO_CR = IPC_FIFO_ENABLE | IPC_FIFO_SEND_CLEAR | IPC_FIFO_RECV_IRQ;


where VBlankHandler just increments a variable for me to check that it runs continuosly...and that variable gets stuck at 5!
FifoHandler looks the same as the one in arm7 and calls a MixSound method when notified with UPDATE_ONARM9 from arm7...and this also never happens.. i don't get what the problem is, can someone help me?


Last edited by sowee on Tue Feb 05, 2008 5:27 am; edited 4 times in total

#150217 - sowee - Thu Jan 31, 2008 1:19 pm

just recycling an old thread i have..
*EDIT*
I don't know if this info helps..but it seems when the vblankhandlers of both processors are active, the problem occurs..am i doing something wrong with the vblank interrupt?? i don't get it..

#150225 - GPFerror - Thu Jan 31, 2008 6:02 pm

looks like your using the same sound streaming code i'm using so maybe the problem is your soundmixing routine is taking to long and another irq is being fired before its done. What I did in mine was shut of irq's while its mixing and then turn them back on, when there done.

here is my fifo handler on arm9, the REG_IME = 0; and REG_IME = 1; is what I had to add.

Code:
void FiFoHandler(void)
{
   
   u32 command;
   while ( !(REG_IPC_FIFO_CR & (IPC_FIFO_RECV_EMPTY)) )
   {
      
      command = REG_IPC_FIFO_RX;

      switch(command)
      {
      case FIFO_NONE:
         break;
      case UPDATEON_ARM9:
         //printf("FiFoHandler\n");
         REG_IME = 0;
         MixSound();
         REG_IME = 1;
         SendCommandToArm7(MIXCOMPLETE_ONARM9);
         break;
      }
   }
}


Troy(GPF)
http://gpf.dcemu.co.uk

#150253 - sowee - Fri Feb 01, 2008 4:14 am

Tried putting REG_IME=0 and REG_IME=1 but to no avail, i still have the same problem :(, I tried checking whether mixsound gets called even once, but it doesn't even enter mixsound... maybe i'm doing something wrong with the arm7 portion?

#150263 - sowee - Fri Feb 01, 2008 8:52 am

Ok..another update, it seems theres a problem with the method i use to fill the ring buffer, without this method the vblank and fifo portions seem to work fine and my counters keep on counting... What i wanted to do was to stream from a file but i seem to be doing something wrong. I used fseek to track the current position and just update the current position so next time i fseek it would be after the ones already read, the program seems to lock up because of this

*EDIT*
i could get the music to play now...but theres an awful lot of popping sounds, 1 second pop at the start, and then the music plays...then popping begins to start, accumulating till the end, until in the end theres only popping sounds after the music is done playing ehehehe :P once it loops again though the popping stops, then re-accumulate, any ideas? this is my revised fillringbuffer method

*EDIT*
edit again, it seems fseek is too slow, so i just kept the file open, now theres just one loud pop everytime the music starts, but while its playing theres no popping sound hehe anyone have any idea why theres a pop at the start? :-?