simplest method for 32x sound?
Posted: Mon Oct 03, 2022 2:21 am
I've been experimenting with sound on the 32X and nothing I try works. Sometimes I get clicking.
What's the most basic way to get anything out of the 32x sound?
I've got the same commonly used init code.
And after that, I just want to feed the output the simplest way possible. Eventually I'll take a better look at the interrupt driven dma style of playing but right now I just want to play a tone or something.
Maybe I'm being naive and it's not so simple
What's the most basic way to get anything out of the 32x sound?
I've got the same commonly used init code.
Code: Select all
#define SAMPLE_RATE 22050
#define SAMPLE_MIN 2
#define SAMPLE_CENTER 517
#define SAMPLE_MAX 1032
// init the sound hardware
MARS_PWM_MONO = 1;
MARS_PWM_MONO = 1;
MARS_PWM_MONO = 1;
if (MARS_VDP_DISPMODE & MARS_NTSC_FORMAT)
MARS_PWM_CYCLE = (((23011361 << 1) / (SAMPLE_RATE) + 1) >> 1) + 1; // for NTSC clock
else
MARS_PWM_CYCLE = (((22801467 << 1) / (SAMPLE_RATE) + 1) >> 1) + 1; // for PAL clock
MARS_PWM_CTRL = 0x0185; // TM = 1, RTP, RMD = right, LMD = left
unsigned short sample = SAMPLE_MIN;
unsigned short ix;
// ramp up to SAMPLE_CENTER to avoid click in audio (real 32X)
while (sample < SAMPLE_CENTER)
{
for (ix = 0; ix < (SAMPLE_RATE * 2) / (SAMPLE_CENTER - SAMPLE_MIN); ix++)
{
while (MARS_PWM_MONO & 0x8000); // wait while full
MARS_PWM_MONO = sample;
}
sample++;
}
Code: Select all
void main ()
{
while (1)
{
// somehow feed a tone to the audio hardware
// set something to MARS_PWM_MONO, maybe?
}
}