Problems with sound
Posted: Mon Jul 25, 2011 12:22 pm
Right first the disclaimer. I know very little about sound and I'm just experimenting.
I'm playing around with the sound registers and FIFO, just seeing what I can do.
The code below runs fine and produces sound but when I remove the iprintf I just get silence.
Can someone please explain why and how to rectify this?
Thanks.
Ok, here's the code.
ARM7
ARM9
I'm playing around with the sound registers and FIFO, just seeing what I can do.
The code below runs fine and produces sound but when I remove the iprintf I just get silence.
Can someone please explain why and how to rectify this?
Thanks.
Ok, here's the code.
ARM7
Code: Select all
#include <nds.h>
#include <dswifi7.h>
#include <nds/bios.h>
#define SAMPLE_RATE 22050
unsigned int buffer_size;
unsigned int snd_buffer[110];
void PlaySound(void)
{
unsigned int t1;
t1=fifoGetValue32(FIFO_USER_01);
snd_buffer[buffer_size++]=t1;
if(buffer_size > 100)
{
SCHANNEL_TIMER(0) = SOUND_FREQ(SAMPLE_RATE);
SCHANNEL_SOURCE(0) = (uint32)snd_buffer;
SCHANNEL_LENGTH(0) = buffer_size >> 2;
SCHANNEL_CR(0) = SCHANNEL_ENABLE | SOUND_ONE_SHOT | SOUND_FORMAT_16BIT | SOUND_VOL(0x7F);
SCHANNEL_TIMER(1) = SOUND_FREQ(SAMPLE_RATE);
SCHANNEL_SOURCE(1) = (uint32)snd_buffer;
SCHANNEL_LENGTH(1) = buffer_size >> 2;
SCHANNEL_CR(1) = SCHANNEL_ENABLE | SOUND_ONE_SHOT | SOUND_FORMAT_16BIT | SOUND_VOL(0x7F);
SCHANNEL_TIMER(2) = SOUND_FREQ(SAMPLE_RATE);
SCHANNEL_SOURCE(2) = (uint32)snd_buffer;
SCHANNEL_LENGTH(2) = buffer_size >> 2;
SCHANNEL_CR(2) = SCHANNEL_ENABLE | SOUND_ONE_SHOT | SOUND_FORMAT_16BIT | SOUND_VOL(0x7F);
SCHANNEL_TIMER(3) = SOUND_FREQ(SAMPLE_RATE);
SCHANNEL_SOURCE(3) = (uint32)snd_buffer;
SCHANNEL_LENGTH(3) = buffer_size >> 2;
SCHANNEL_CR(3) = SCHANNEL_ENABLE | SOUND_ONE_SHOT | SOUND_FORMAT_16BIT | SOUND_VOL(0x7F);
buffer_size=0;
}
}
void VblankHandler(void)
{
Wifi_Update();
}
void VcountHandler(void)
{
inputGetAndSend();
}
int main()
{
powerOn(POWER_SOUND);
readUserSettings();
irqInit();
fifoInit();
initClockIRQ();
SetYtrigger(80);
installWifiFIFO();
installSoundFIFO();
installSystemFIFO();
irqSet(IRQ_VCOUNT, VcountHandler);
irqSet(IRQ_VBLANK, VblankHandler);
irqEnable(IRQ_VBLANK | IRQ_VCOUNT | IRQ_NETWORK);
REG_SOUNDCNT = SOUND_ENABLE | SOUND_VOL(0x7F);
REG_SOUNDBIAS = 0x200;
buffer_size=0;
while(1)
{
if(fifoCheckValue32(FIFO_USER_01))PlaySound();
}
return 0;
}
Code: Select all
#include <nds.h>
#include <stdio.h>
int main(void)
{
consoleDemoInit();
int b=0;
while(1)
{
if(fifoSendValue32(FIFO_USER_01, b * 8192))iprintf("On it's way");
b++;
if(b > 1)b=0;
}
return 0;
}