ref: 537c864df956af56f4d1997c43871d9186e9795c
parent: 461a411e3c7713ff07aa08ca7fbe6ac26bd78850
author: Jacob Moody <moody@posixcafe.org>
date: Sun Jan 22 18:45:45 EST 2023
pcmconv resampling is not what we need, just do it ourselves.
--- a/i_sound.c
+++ b/i_sound.c
@@ -14,10 +14,10 @@
#include "i_sound.h"
#include "audio_plugin.h"
-#define SAMPLE_FORMAT FMT_S16_NE
#define SAMPLE_ZERO 0
#define SAMPLE_RATE 11025 /* Hz */
#define SAMPLE_CHANNELS 2
+#define TARGET_RATE 44100
#define SAMPLE_TYPE short
@@ -74,11 +74,10 @@
static int steptable[256]; /* Pitch to stepping lookup */
-#define BUF_LEN (256 * 2)
+#define BUF_LEN (256 * 2 * 4)
static int audiofd;
static int audiopid = -1;
-static int convpid = -1;
static QLock audiolk;
@@ -92,21 +91,11 @@
unsigned int sample;
register int dl;
register int dr;
- int pip[2];
+ int i;
end = (SAMPLE_TYPE *) (buf + BUF_LEN);
cend = channel + CHAN_COUNT;
- pipe(pip);
- if((convpid = rfork(RFFDG|RFPROC|RFMEM)) == 0){
- close(pip[0]);
- dup(pip[1], 0);
- dup(audiofd, 1);
- execl("/bin/audio/pcmconv", "-i", "s16r11025", "-o", "s16r44100", nil);
- exits(nil);
- }
- close(pip[1]);
-
for(;;){
begin = (SAMPLE_TYPE *) buf;
while (begin < end){
@@ -139,16 +128,18 @@
}
}
qunlock(&audiolk);
- if (dl > 0x7fff)
- dl = 0x7fff;
- else if (dl < -0x8000)
- dl = -0x8000;
- if (dr > 0x7fff)
- dr = 0x7fff;
- else if (dr < -0x8000)
- dr = -0x8000;
- *begin++ = dl;
- *begin++ = dr;
+ for(i=0; i < TARGET_RATE/SAMPLE_RATE; i++){
+ if (dl > 0x7fff)
+ dl = 0x7fff;
+ else if (dl < -0x8000)
+ dl = -0x8000;
+ if (dr > 0x7fff)
+ dr = 0x7fff;
+ else if (dr < -0x8000)
+ dr = -0x8000;
+ *begin++ = dl;
+ *begin++ = dr;
+ }
}
write(audiofd, buf, BUF_LEN);
}
@@ -157,6 +148,7 @@
void I_SetSfxVolume(int volume)
{
+ USED(volume);
}
// Gets lump nums of the named sound. Returns pointer which will be
@@ -187,6 +179,7 @@
int oldest;
int i;
+ USED(id);
// Find an empty channel, the oldest playing channel, or default to 0.
// Currently ignoring priority.
@@ -300,8 +293,6 @@
// inits all sound stuff
void I_StartupSound (void)
{
- int ok;
-
snd_SfxAvail = false;
if (M_CheckParm("--nosound") || M_CheckParm("-s") || M_CheckParm("-nosound"))
@@ -341,6 +332,7 @@
int *steptablemid;
// We always have CHAN_COUNT channels.
+ USED(channels);
for (j = 0; j < CHAN_COUNT; j++)
{
@@ -378,32 +370,39 @@
int I_RegisterSong(void *data)
{
+ USED(data);
return 0;
}
int I_RegisterExternalSong(const char *nm)
{
+ USED(nm);
return 0;
}
void I_UnRegisterSong(int handle)
{
+ USED(handle);
}
void I_PauseSong(int handle)
{
+ USED(handle);
}
void I_ResumeSong(int handle)
{
+ USED(handle);
}
void I_SetMusicVolume(int volume)
{
+ USED(volume);
}
int I_QrySongPlaying(int handle)
{
+ USED(handle);
return 0;
}
@@ -410,9 +409,11 @@
// Stops a song. MUST be called before I_UnregisterSong().
void I_StopSong(int handle)
{
+ USED(handle);
}
void I_PlaySong(int handle, boolean looping)
{
+ USED(handle); USED(looping);
}