aboutsummaryrefslogtreecommitdiff
path: root/backends
diff options
context:
space:
mode:
authorWon Star2005-12-17 06:12:28 +0000
committerWon Star2005-12-17 06:12:28 +0000
commita36c5781c18dc7c58225c55e341d951331f24579 (patch)
treed7cbeffeef4ee7e9c7991927ae17c06b02ee7701 /backends
parent5e8b2637fcccbfc3d1ec165e2e0545a1349350cc (diff)
downloadscummvm-rg350-a36c5781c18dc7c58225c55e341d951331f24579.tar.gz
scummvm-rg350-a36c5781c18dc7c58225c55e341d951331f24579.tar.bz2
scummvm-rg350-a36c5781c18dc7c58225c55e341d951331f24579.zip
Some tweaks on the GP32 sound code.
svn-id: r19800
Diffstat (limited to 'backends')
-rw-r--r--backends/gp32/gp32_osys.cpp21
-rw-r--r--backends/gp32/gp32std_sound.cpp107
-rw-r--r--backends/gp32/gp32std_sound.h18
3 files changed, 102 insertions, 44 deletions
diff --git a/backends/gp32/gp32_osys.cpp b/backends/gp32/gp32_osys.cpp
index 37f8a318a5..f4a86635c8 100644
--- a/backends/gp32/gp32_osys.cpp
+++ b/backends/gp32/gp32_osys.cpp
@@ -636,7 +636,6 @@ bool OSystem_GP32::setSoundCallback(SoundProc proc, void *param) {
NP("OSys::setSoundCallback()");
GPSOUNDBUF gpSoundBuf;
- PCM_SR sampleFreq;
if (ConfMan.hasKey("output_rate"))
_samplesPerSec = ConfMan.getInt("output_rate");
@@ -658,31 +657,19 @@ bool OSystem_GP32::setSoundCallback(SoundProc proc, void *param) {
switch(_samplesPerSec) {
case 44100:
- sampleFreq = PCM_S44;
- break;
case 22050:
- sampleFreq = PCM_S22;
- break;
case 11025:
- sampleFreq = PCM_S11;
break;
default:
- _samplesPerSec = 22050;
- sampleFreq = PCM_S22;
+ _samplesPerSec = 11025;
}
- gpSoundBuf.freq = sampleFreq;
- gpSoundBuf.format = PCM_16BIT;
+ gpSoundBuf.freq = _samplesPerSec;
+ gpSoundBuf.format = 16;
+ gpSoundBuf.channels = 2;
gpSoundBuf.samples = samples;
gpSoundBuf.userdata = param;
gpSoundBuf.callback = proc;
-// gpSoundBuf.pollfreq = 2 * (SAMPLES_PER_SEC / gpSoundBuf.samples);
- gpSoundBuf.pollfreq = 2 * 4 * (SAMPLES_PER_SEC / gpSoundBuf.samples); // FIXME?
- // Frequency of the timer interrupt which polls the playing position
- // recommended value: 2*(playingfreq in Hz/GPSOUNDBUF.samples)
- //s.samplesize; // Size of one sample (8bit mono->1, 16bit stereo->4) - don't touch this
-
- GpPcmInit(gpSoundBuf.freq, gpSoundBuf.format);
gp_soundBufStart(&gpSoundBuf);
// For Safety...
diff --git a/backends/gp32/gp32std_sound.cpp b/backends/gp32/gp32std_sound.cpp
index 2bef7aac3a..c235cc0af8 100644
--- a/backends/gp32/gp32std_sound.cpp
+++ b/backends/gp32/gp32std_sound.cpp
@@ -42,16 +42,61 @@ static GPSOUNDBUF soundBuf;
// polls the current playing position within the buffer.
static void soundTimer() {
+ unsigned int sampleshiftVal = soundBuf.samples << shiftVal;
unsigned int t = (((unsigned int)(*soundPos) - (unsigned int)buffer) >> shiftVal) >= soundBuf.samples ? 1 : 0;
if (t != frame) {
- unsigned int offs = ((frame == 1) ? (soundBuf.samples << shiftVal) : 0);
- soundBuf.callback(soundBuf.userdata, (uint8 *)((unsigned int)buffer + offs), soundBuf.samples << shiftVal);
+ unsigned int offs = ((frame == 1) ? (sampleshiftVal) : 0);
+ //memset((uint8 *)buffer + offs, 0, sampleshiftVal);
+ soundBuf.callback(soundBuf.userdata, (uint8 *)((unsigned int)buffer + offs), sampleshiftVal);
frame = t;
+ {
+ // Play silence
+ register uint16 *d = (uint16 *)((uint8 *)buffer + offs); // alignment-safe
+ register uint32 max = (uint32)((uint8 *)buffer + offs + sampleshiftVal);
+ do {
+ *d++ ^= 0x8000; // 1
+ *d++ ^= 0x8000; // 2
+ *d++ ^= 0x8000; // 3
+ *d++ ^= 0x8000; // 4
+ *d++ ^= 0x8000; // 5
+ *d++ ^= 0x8000; // 6
+ *d++ ^= 0x8000; // 7
+ *d++ ^= 0x8000; // 8
+ *d++ ^= 0x8000; // 9
+ *d++ ^= 0x8000; // 10
+ *d++ ^= 0x8000; // 11
+ *d++ ^= 0x8000; // 12
+ *d++ ^= 0x8000; // 13
+ *d++ ^= 0x8000; // 14
+ *d++ ^= 0x8000; // 15
+ *d++ ^= 0x8000; // 16
+ *d++ ^= 0x8000; // 17
+ *d++ ^= 0x8000; // 18
+ *d++ ^= 0x8000; // 19
+ *d++ ^= 0x8000; // 20
+ *d++ ^= 0x8000; // 21
+ *d++ ^= 0x8000; // 22
+ *d++ ^= 0x8000; // 23
+ *d++ ^= 0x8000; // 24
+ *d++ ^= 0x8000; // 25
+ *d++ ^= 0x8000; // 26
+ *d++ ^= 0x8000; // 27
+ *d++ ^= 0x8000; // 28
+ *d++ ^= 0x8000; // 29
+ *d++ ^= 0x8000; // 30
+ *d++ ^= 0x8000; // 31
+ *d++ ^= 0x8000; // 32
+ } while((uint32)d < max);
+ }
}
}
int gp_soundBufStart(GPSOUNDBUF *sb) {
int bufferSize = 0;
+
+ PCM_SR gpFreq = PCM_S11;
+ PCM_BIT gpFormat = PCM_16BIT;
+
frame = 0;
// Copy the structure
@@ -60,39 +105,63 @@ int gp_soundBufStart(GPSOUNDBUF *sb) {
// Calculate size of a single sample in bytes
// and a corresponding shift value
shiftVal = 0;
- switch (soundBuf.freq) {
- case PCM_S11:
- break;
- case PCM_S22:
+
+ switch(soundBuf.format) {
+ case 8:
+ gpFormat = PCM_8BIT;
break;
- case PCM_S44:
+ case 16:
+ gpFormat = PCM_16BIT;
shiftVal++;
break;
- case PCM_M11:
+ }
+
+ switch(soundBuf.freq) {
+ case 11025:
+ if (soundBuf.channels == 2) {
+ gpFreq = PCM_S11;
+ shiftVal++;
+ } else
+ gpFreq = PCM_M11;
break;
- case PCM_M22:
+ case 22050:
+ if (soundBuf.channels == 2) {
+ gpFreq = PCM_S22;
+ shiftVal++;
+ } else
+ gpFreq = PCM_M22;
break;
- case PCM_M44:
- shiftVal++;
+ case 44100:
+ if (soundBuf.channels == 2) {
+ gpFreq = PCM_S44;
+ shiftVal++;
+ } else
+ gpFreq = PCM_M44;
break;
}
- if (soundBuf.format == PCM_16BIT)
- shiftVal++;
- soundBuf.samplesize = 1 << shiftVal;
+ soundBuf.samplesize = 1 << shiftVal;
+
// Allocate memory for the playing buffer
bufferSize = soundBuf.samplesize * soundBuf.samples * 2;
buffer = malloc(bufferSize);
- memset(buffer, 0, bufferSize);
+
+ // Clear the buffer
+ uint16 *tmpBuf = (uint16 *)buffer;
+ for(int i = 0; i < bufferSize / 2; i++)
+ tmpBuf[i] = 0x8000;
+
+ // Frequency of the timer interrupt which polls the playing position
+ soundBuf.pollfreq = 4 * (2 * soundBuf.freq) / soundBuf.samples;
// Set timer interrupt
if (GpTimerOptSet(GP32_TIMER_AUDIO_IDX, soundBuf.pollfreq, 0, soundTimer) == GPOS_ERR_ALREADY_USED) {
- NP(" Timer is already used... kill timer");
+ GPDEBUG(" Timer is already used... kill timer");
GpTimerKill(GP32_TIMER_AUDIO_IDX);
}
GpTimerSet(GP32_TIMER_AUDIO_IDX);
- // Start playing
- GpPcmInit(soundBuf.freq, soundBuf.format);
+
+ GpPcmInit(gpFreq, gpFormat);
GpPcmPlay((unsigned short *)buffer, bufferSize, 1);
GpPcmLock((unsigned short *)buffer, (int *)&idx_buf, (unsigned int *)&soundPos);
@@ -100,8 +169,8 @@ int gp_soundBufStart(GPSOUNDBUF *sb) {
}
void gp_soundBufStop() {
+ GpTimerKill(GP32_TIMER_AUDIO_IDX);
GpPcmStop();
GpPcmRemove((unsigned short *)buffer);
- GpTimerKill(GP32_TIMER_AUDIO_IDX);
free(buffer);
}
diff --git a/backends/gp32/gp32std_sound.h b/backends/gp32/gp32std_sound.h
index 90613029a2..41851490b7 100644
--- a/backends/gp32/gp32std_sound.h
+++ b/backends/gp32/gp32std_sound.h
@@ -29,14 +29,16 @@
typedef void SoundProc(void *param, byte *buf, int len);
typedef struct TGPSOUNDBUF {
- PCM_SR freq; // Taken from gpmm.h
- PCM_BIT format; // Taken from gpmm.h
- unsigned int samples; // Buffer length (in samples)
- void *userdata; // Userdata which gets passed to the callback function
- SoundProc *callback; // Callback function (just like in SDL)
- unsigned int pollfreq; // Frequency of the timer interrupt which polls the playing position
- // recommended value: 2*(playingfreq in Hz/GPSOUNDBUF.samples)
- unsigned int samplesize; // Size of one sample (8bit mono->1, 16bit stereo->4) - don't touch this
+ int32 freq;
+ uint16 format;
+ uint16 samples; // Buffer length (in samples)
+ uint16 channels;
+ uint16 padding; // Fix alignment problem
+ void *userdata; // Userdata which gets passed to the callback function
+ SoundProc *callback; // Callback function (just like in SDL)
+ unsigned int pollfreq; // Frequency of the timer interrupt which polls the playing position
+ // recommended value: 2*(playingfreq in Hz/GPSOUNDBUF.samples)
+ unsigned int samplesize; // Size of one sample (8bit mono->1, 16bit stereo->4) - don't touch this
} GPSOUNDBUF;
int gp_soundBufStart(GPSOUNDBUF *sb);