GP32 Sound Loop With Gppcmplay


fdave

Final Dave
Joined
Apr 20, 2004
Messages
331
Website
www.finalburn.com
Hi folks,

I'm writing some sound code and I have this so far:

Code:
static int SoundLen=0;
static unsigned short *SoundWave=NULL;

int SoundInit()
{
  SoundLen=735*4; // In samples

  // Allocate circular buffer:
  SoundWave=(unsigned short *)malloc(SoundLen<<2); if (SoundWave==NULL) return 1;
  memset(SoundWave,0,SoundLen<<2);

  SoundWave[0]=0x4000; //test

  GpPcmInit(PCM_M44,PCM_16BIT);
  GpPcmPlay(SoundWave,SoundLen<<2,1);
  return 0;
}

int SoundExit()
{
  GpPcmStop();

  if (SoundWave) free(SoundWave);
  SoundWave=NULL; SoundLen=0;

  return 0;
}

I have a bit of sound, though it does change. Did I do something wrong?


Anyway, my real question is this, I want to poll the current position of the sound loop, and thought this function might do it:
Code:
int SoundPoll()
{
  int idx=0;
  unsigned int addr=0;

  GpPcmLock(SoundWave,&idx,&addr);

  return addr;
}

But it always returns the same thing, 0xc0985a4. Any ideas?
 
Ah doh - it's an address you pass to Lock. Still have the interference in the Rom menu though, and when going to the game. Is that because of the graphics re-init maybe?

Code:
static int SoundLen=0;
static unsigned short *SoundWave=NULL;
static volatile int *SoundPos=0;

int SoundInit()
{
  int idx=0;

  SoundLen=735*4; // In samples

  // Allocate circular buffer:
  SoundWave=(unsigned short *)malloc(SoundLen<<2); if (SoundWave==NULL) return 1;
  memset(SoundWave,0,SoundLen<<2);

  GpPcmInit(PCM_M44,PCM_16BIT);
  GpPcmPlay(SoundWave,SoundLen<<2,1);
  GpPcmLock(SoundWave,&idx,(unsigned int *)&SoundPos);
  return 0;
}

int SoundExit()
{
  GpPcmStop();

  if (SoundWave) free(SoundWave);
  SoundWave=NULL; SoundLen=0;

  return 0;
}

int SoundPoll()
{
  if (SoundPos==NULL) return 0;
  
  return *SoundPos-(int)SoundWave;
}
 
maybe nothing but...

GpPcmPlay(SoundWave,SoundLen<<2,1); are you sure you need it to play looped?

not that I can follow your code as well as I should be able to...
 
fdave: Take a look at the sound looping code in BOR. It starts up with a blank buffer to start with, and just fills it in as and when necessary.
 
maybe nothing but...

GpPcmPlay(SoundWave,SoundLen<<2,1); are you sure you need it to play looped?

not that I can follow your code as well as I should be able to...


For a circular buffer, yes, pretty sure ;-)

Anyone else had interference of their sound loop before, or is it just me?

Will take a look at the BOR code at some point... whereabouts is it?
 
Last edited by a moderator:
It's in the beta test section, along with the latest fxe. Doesn't use the SDK though, so might not be what you want.
 
Explain the interference a bit more, do you mean the gp32 sound bug (distorted scratchy sound), or is the loop just stopping?

-Craig

www.gbax.com
 
Are you sure it's a bug craig? I always thought it was due to starvation of memory bus bandwidth, as described in the arm docs?
 
Back
Top