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 > No sound on DS, Help!

#43278 - newbiecoders - Sat May 21, 2005 11:32 am

Help! Can someone send me some source code in the template format for compiling in Win32 with sound. I have tried absolutely everything and on DS hardware (using Flashme) I just can't get anything to come out the speaker. I know it says to "play a wave file" etc but is that a .wav file converted to a .o file or what!? Also I am having problems using the multi loader, all I get is two blank screens. Please help!!!!

Last edited by newbiecoders on Mon May 23, 2005 2:04 am; edited 1 time in total

#43385 - PhoenixSoft - Sun May 22, 2005 10:29 pm

Notice that 200 people have read your thread without replying to it. Is this because they don't know the answer? No. It is because you are being so rude about the question. Maybe if you took out all of those !s someone would consider answering your question.

#43397 - Darkain - Mon May 23, 2005 1:44 am

we'd also be more helpful if you posted in-topic threads, instead of starting new ones. if you are having issues w/ the multi-loader, try DESCRIBING what the issue is, and posting it in the multi-loader thread. i cant just read your mind to figure out whats wrong with it. ;)
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#43401 - newbiecoders - Mon May 23, 2005 2:07 am

Sorry, my English is bad! I'm using a win32 environment and am unable to play sounds at all. If anyone could send me a template with just one sound in, that plays I would be really really grateful. Sorry if I came across as rude. I'm just really really frustrated by the sound not working. Its the only thing I need to do. Thanks in advance...

#43402 - Darkain - Mon May 23, 2005 2:10 am

if you are using an emulator, that is probably your problem
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#43404 - newbiecoders - Mon May 23, 2005 2:18 am

Sorry no. I'm actually using flashme. I try and play a sound and there is total silence. Sorry to be vague:

This is the code used at the beginning in the arm7 directory main.c:

SOUND_CR = SCHANNEL_ENABLE | SOUND_VOL(0x3F) ;


SCHANNEL_CR(0) = SOUND_ENABLE | SOUND_VOL(0x3F);
SCHANNEL_TIMER(0) = SOUND_FREQ(22050);
SCHANNEL_SOURCE(0) = (u32)GETRAW(ROCKHIT);
SCHANNEL_LENGTH(0) = GETRAWSIZE(ROCKHIT) >> 2;

Regards[/code]

#43405 - Darkain - Mon May 23, 2005 2:22 am

SCHANNEL_ENABLE and SOUND_ENABLE are swapped
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#43406 - newbiecoders - Mon May 23, 2005 2:44 am

Sorry mate. Still not working! This is my arm7 main.c source though:

Code:

//////////////////////////////////////////////////////////////////////
// Simple ARM7 stub (sends RTC, TSC, and X/Y data to the ARM 9)
// -- joat
// -- modified by Darkain and others
//////////////////////////////////////////////////////////////////////

#include <NDS/NDS.h>

#include <NDS/ARM7/BIOS.h>
#include <NDS/ARM7/touch.h>
#include <NDS/ARM7/clock.h>

#include "shine.h"

//////////////////////////////////////////////////////////////////////


#define TOUCH_CAL_X1 (*(vs16*)0x027FFCD8)
#define TOUCH_CAL_Y1 (*(vs16*)0x027FFCDA)
#define TOUCH_CAL_X2 (*(vs16*)0x027FFCDE)
#define TOUCH_CAL_Y2 (*(vs16*)0x027FFCE0)
#define SCREEN_WIDTH    256
#define SCREEN_HEIGHT   192
s32 TOUCH_WIDTH  = TOUCH_CAL_X2 - TOUCH_CAL_X1;
s32 TOUCH_HEIGHT = TOUCH_CAL_Y2 - TOUCH_CAL_Y1;
s32 TOUCH_OFFSET_X = ( ((SCREEN_WIDTH -60) * TOUCH_CAL_X1) / TOUCH_WIDTH  ) - 28;
s32 TOUCH_OFFSET_Y = ( ((SCREEN_HEIGHT-60) * TOUCH_CAL_Y1) / TOUCH_HEIGHT ) - 28;


//////////////////////////////////////////////////////////////////////


void startSound(int sampleRate, const void* data, uint32 bytes, u8 channel=0, u8 vol=0x7F,  u8 pan=63, u8 format=0) {
  SCHANNEL_TIMER(channel)  = SOUND_FREQ(sampleRate);
  SCHANNEL_SOURCE(channel) = (uint32)data;
  SCHANNEL_LENGTH(channel) = bytes;
  SCHANNEL_CR(channel)     = SOUND_ENABLE | SOUND_ONE_SHOT | SOUND_VOL(vol) | SOUND_PAN(pan) | (format==1?SOUND_8BIT:SOUND_16BIT);
}


s8 getFreeSoundChannel() {
  for (int i=0; i<16; i++) {
    if ( (SCHANNEL_CR(i) & SOUND_ENABLE) == 0 ) return i;
  }
  return -1;
}


//////////////////////////////////////////////////////////////////////


void InterruptHandler(void) {
  static int heartbeat = 0;

  if (IF & IRQ_VBLANK) {
    uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0, batt=0, aux=0;
    int t1=0, t2=0;
    uint32 temp=0;
    uint8 ct[sizeof(IPC->curtime)];


    // Update the heartbeat
    heartbeat++;

    // Read the X/Y buttons and the /PENIRQ line
    but = XKEYS;
    if (!(but & 0x40)) {
      // Read the touch screen
      x = touchRead(TSC_MEASURE_X);
      y = touchRead(TSC_MEASURE_Y);
      xpx = ( ((SCREEN_WIDTH -60) * x) / TOUCH_WIDTH  ) - TOUCH_OFFSET_X;
      ypx = ( ((SCREEN_HEIGHT-60) * y) / TOUCH_HEIGHT ) - TOUCH_OFFSET_Y;
      z1 = touchRead(TSC_MEASURE_Z1);
      z2 = touchRead(TSC_MEASURE_Z2);
    }

    batt = touchRead(TSC_MEASURE_BATTERY);
    aux  = touchRead(TSC_MEASURE_AUX);

    // Read the time
    rtcGetTime((uint8 *)ct);
    BCDToInteger((uint8 *)&(ct[1]), 7);

    // Read the temperature
    temp = touchReadTemperature(&t1, &t2);

    // Update the IPC struct
    IPC->heartbeat = heartbeat;
    IPC->buttons   = but;
    IPC->touchX    = x;
    IPC->touchY    = y;
    IPC->touchXpx  = xpx;
    IPC->touchYpx  = ypx;
    IPC->touchZ1   = z1;
    IPC->touchZ2   = z2;
    IPC->battery   = batt;
    IPC->aux       = aux;

    for(u32 i=0; i<sizeof(ct); i++) {
      IPC->curtime[i] = ct[i];
    }

    IPC->temperature = temp;
    IPC->tdiode1 = t1;
    IPC->tdiode2 = t2;





  }

  // Acknowledge interrupts
  IF = IF;
}


//////////////////////////////////////////////////////////////////////
void LoadBin(const void * src, uint32 dst, int size) {
  uint32 * ram = (uint32 *)dst;
  uint32 * rom = (uint32 *)src;
  for (; size > 0; size -= 4) { *ram++ = *rom++; }
}

int main(int argc, char ** argv) {
  // Reset the clock if needed
  rtcReset();




  IPC->soundData = 0;

  // Set up the interrupt handler
  IME = 0;
  IRQ_HANDLER = &InterruptHandler;
  IE = IRQ_VBLANK;
  IF = ~0;
  DISP_SR = DISP_VBLANK_IRQ;
  IME = 1;

  //enable sound
  powerON(POWER_SOUND);
  SCHANNEL_CR(0) = SOUND_ENABLE | SOUND_ONE_SHOT | SOUND_VOL(0x7F) | SOUND_PAN(63) | SOUND_8BIT);

  SCHANNEL_CR(0) = SCHANNEL_ENABLE | SOUND_VOL(0x7F);
  SCHANNEL_TIMER(0) = SOUND_FREQ(22050);
  SCHANNEL_SOURCE(0) = (u32)GETRAW(shine);
  SCHANNEL_LENGTH(0) = GETRAWSIZE(shine) >> 2;




  // Keep the ARM7 out of main RAM
  while (1) swiWaitForVBlank();
  return 0;
}


shine is a binary file from audio_sampler. Although I tried a PCM wave converted into a .o file earlier.

Thanks in advance.

#43409 - Darkain - Mon May 23, 2005 3:24 am

you didnt enable the sound on the system before you started to play audio:


SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F);


just shove this near the begining of your main function before you play any sounds. you only gotta call this once.
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#43785 - newbiecoders - Thu May 26, 2005 8:15 pm

Thanks Darkain, you're a legend! I finally fixed the issue. One last thing. I'm using the audio_sample example and I don't know how to convert the wave files to the bin files that actually play through the DS (such as shine.bin etc). Now I have a wav file, what do I do with it to get it into the right format.

#43791 - Darkain - Thu May 26, 2005 8:27 pm

i'm using WaveStudio, that allows me to save WAV(E) files as raw PCM data w/o their headers. i'm not sure what everyone else is using.
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS

#43797 - newbiecoders - Thu May 26, 2005 9:02 pm

Sorry to be a pain in the arse, but the sound I convert to raw, unsigned 8bit in Soundforge is just giving a very short split second burst of incorrect sound. Plus the file I've converted does not look at all similar in textpad to the sound shine.bin, which looks like a hex/bin file. Thanks in advance.

#43801 - josath - Thu May 26, 2005 9:28 pm

it's not gonna look the same in a text editor, they are both binary files not meant to be viewed as text. since they are raw, they should have no identifiable strings also.

#43804 - newbiecoders - Thu May 26, 2005 10:15 pm

Fair enough but I think I'm ending up with the wrong converted file, i'd have thought soundforge would convert it right!

#43806 - doublec - Thu May 26, 2005 10:37 pm

Try using Sox:

http://sox.sourceforge.net/

The following should convert a wav file to raw format:

sox test.wav test.raw

Chris.

#43826 - tepples - Fri May 27, 2005 2:23 am

But what kind of raw? Signed or unsigned? 8- or 16-bit? Linear PCM or IMA ADPCM or something proprietary?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#43828 - doublec - Fri May 27, 2005 2:28 am

You can specify or it will base it on the input file. See here:

http://linuxcommand.org/man_pages/soxexam1.html

#43829 - josath - Fri May 27, 2005 2:28 am

try different ones until it works?
what i know is you need standard plain raw mono linear pcm. as for 8bit vs 16bit, you can do either as long as you set the sound register correctly, and for sample rate, you can do any, again set the register correctly.

#43858 - newbiecoders - Fri May 27, 2005 10:55 am

Thanks guys. Funnily enough, the format that converts straight to the right format is aiff! Waves were playing incorrectly and I found that the aiff files are perfect.

#43859 - Darkain - Fri May 27, 2005 10:56 am

could be signed vs unsigned problem as well, and correct bit-depth... 2 most common problems ive seen. :)
_________________
-=- Darkain Dragoon -=-
http://www.darkain.com
DarkStar for Nintendo DS