[Scummvm-cvs-logs] CVS: scummvm/backends/gp32 gp32_osys.cpp,1.2,1.3 gp32std_sound.cpp,1.1,1.2 gp32std_sound.h,1.1,1.2
Won star
wonst719 at users.sourceforge.net
Fri Dec 16 22:13:01 CET 2005
Update of /cvsroot/scummvm/scummvm/backends/gp32
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28315
Modified Files:
gp32_osys.cpp gp32std_sound.cpp gp32std_sound.h
Log Message:
Some tweaks on the GP32 sound code.
Index: gp32_osys.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/gp32/gp32_osys.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- gp32_osys.cpp 4 Dec 2005 08:49:08 -0000 1.2
+++ gp32_osys.cpp 17 Dec 2005 06:12:27 -0000 1.3
@@ -636,7 +636,6 @@
NP("OSys::setSoundCallback()");
GPSOUNDBUF gpSoundBuf;
- PCM_SR sampleFreq;
if (ConfMan.hasKey("output_rate"))
_samplesPerSec = ConfMan.getInt("output_rate");
@@ -658,31 +657,19 @@
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...
Index: gp32std_sound.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/gp32/gp32std_sound.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- gp32std_sound.cpp 27 Nov 2005 02:35:57 -0000 1.1
+++ gp32std_sound.cpp 17 Dec 2005 06:12:28 -0000 1.2
@@ -42,16 +42,61 @@
// 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 @@
// 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 @@
}
void gp_soundBufStop() {
+ GpTimerKill(GP32_TIMER_AUDIO_IDX);
GpPcmStop();
GpPcmRemove((unsigned short *)buffer);
- GpTimerKill(GP32_TIMER_AUDIO_IDX);
free(buffer);
}
Index: gp32std_sound.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/backends/gp32/gp32std_sound.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- gp32std_sound.h 27 Nov 2005 02:35:57 -0000 1.1
+++ gp32std_sound.h 17 Dec 2005 06:12:28 -0000 1.2
@@ -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);
More information about the Scummvm-git-logs
mailing list