Hi everyone,
I'm changing FCLK with the following code:
This works, except that sometimes it causes the sound thread to lock on the next write() to "/dev/dsp". I have tried the code from the LCD tweaker and it does exactly the same thing.
No problem, I thought, I'll just shut down the sound before changing the clock and reinitialise it afterwards. This fixed the crash problem, but now the sound is sometimes at the wrong frequency, is silent or generally corrupt after the clock has been changed. Here's the code I'm using to change it: (I'm using ryleh's minimal lib BTW)
I've tried re-initialising the sound several times (even every iteration of the audio thread) or adding delays between setting the clock and opening "/dev/dsp" but to no avail.
Any help, suggestions or ideas would be really appreciated!
Thanks,
James.
I'm changing FCLK with the following code:
Code:
#define SYSTEM_CLOCK 2457600
tmp = (new_clock*1000000) / SYSTEM_CLOCK;
tmp = (tmp-8)<<8;
gp2x_memregs[0x910>>1] = tmp | 4;
while(gp2x_memregs[0x902>>1] & 1);
This works, except that sometimes it causes the sound thread to lock on the next write() to "/dev/dsp". I have tried the code from the LCD tweaker and it does exactly the same thing.
No problem, I thought, I'll just shut down the sound before changing the clock and reinitialise it afterwards. This fixed the crash problem, but now the sound is sometimes at the wrong frequency, is silent or generally corrupt after the clock has been changed. Here's the code I'm using to change it: (I'm using ryleh's minimal lib BTW)
Code:
#define SYSTEM_CLOCK 2457600
void CPU_SetClock(unsigned int new_clock)
{
if (new_clock != curr_clock)
{
unsigned int tmp, store;
int re_init_audio = 0;
curr_clock = new_clock;
tmp = (new_clock*1000000) / SYSTEM_CLOCK;
tmp = (tmp-8)<<8;
// make sure sound interrupt doesn't happen just after the clock has been changed
store = gp2x_sound_pausei;
gp2x_sound_pausei = 1;
if (gp2x_dev[3])
{
close(gp2x_dev[3]);
gp2x_dev[3] = 0;
re_init_audio = 1;
}
gp2x_memregs[0x910>>1] = tmp | 4;
while(gp2x_memregs[0x902>>1] & 1);
if (re_init_audio)
{
int rate = 44100, bits = 16, stereo = 1, frag = 0x80000|9;
gp2x_dev[3] = open("/dev/dsp", O_WRONLY);
gp2x_sound_volume(100,100);
ioctl(gp2x_dev[3], SNDCTL_DSP_SPEED, &rate);
ioctl(gp2x_dev[3], SNDCTL_DSP_SETFMT, &bits);
ioctl(gp2x_dev[3], SNDCTL_DSP_STEREO, &stereo);
ioctl(gp2x_dev[3], SNDCTL_DSP_SETFRAGMENT, &frag);
}
gp2x_sound_pausei = store;
}
}
I've tried re-initialising the sound several times (even every iteration of the audio thread) or adding delays between setting the clock and opening "/dev/dsp" but to no avail.
Any help, suggestions or ideas would be really appreciated!
Thanks,
James.