start work on support for stereo samples

This commit is contained in:
Bill Currie 2003-04-08 22:23:16 +00:00
parent d3b6fcbd61
commit dd297bc12a
2 changed files with 47 additions and 8 deletions

View file

@ -33,15 +33,13 @@
#define __snd_render_h
// !!! if this is changed, it must be changed in asm_i386.h too !!!
typedef struct
{
typedef struct portable_samplepair_s {
int left;
int right;
} portable_samplepair_t;
// !!! if this is changed, it much be changed in asm_i386.h too !!!
typedef struct
{
typedef struct sfxcache_s {
int length;
int loopstart;
int speed;
@ -52,8 +50,7 @@ typedef struct
} sfxcache_t;
// !!! if this is changed, it much be changed in asm_i386.h too !!!
typedef struct
{
typedef struct channel_s {
sfx_t *sfx; // sfx number
int leftvol; // 0-255 volume
int rightvol; // 0-255 volume
@ -69,8 +66,7 @@ typedef struct
int oldphase; // phase shift between l-r in samples
} channel_t;
typedef struct
{
typedef struct wavinfo_s {
int rate;
int width;
int channels;
@ -120,6 +116,8 @@ wavinfo_t SND_GetWavinfo (const char *name, byte * wav, int wavlength);
void SND_WriteLinearBlastStereo16 (void);
void SND_PaintChannelFrom8 (channel_t *ch, sfxcache_t *sc, int count);
void SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count);
void SND_PaintChannelStereo8 (channel_t *ch, sfxcache_t *sc, int count);
void SND_PaintChannelStereo16 (channel_t *ch, sfxcache_t *sc, int count);
wavinfo_t GetWavinfo (const char *name, byte *wav, int wavlength);

View file

@ -372,3 +372,44 @@ SND_PaintChannelFrom16 (channel_t *ch, sfxcache_t *sc, int count)
paintbuffer[i + right_phase].right += (sfx[i] * rightvol) >> 8;
}
}
void
SND_PaintChannelStereo8 (channel_t *ch, sfxcache_t *sc, int count)
{
byte *samp;
portable_samplepair_t *pair;
int *lscale, *rscale;
if (ch->leftvol > 255)
ch->leftvol = 255;
if (ch->rightvol > 255)
ch->rightvol = 255;
lscale = snd_scaletable[ch->leftvol >> 3];
rscale = snd_scaletable[ch->rightvol >> 3];
samp = sc->data + ch->pos;
pair = paintbuffer;
while (count-- > 0) {
pair->left += lscale[*samp++];
pair->right += rscale[*samp++];
pair++;
}
}
void
SND_PaintChannelStereo16 (channel_t *ch, sfxcache_t *sc, int count)
{
short *samp;
portable_samplepair_t *pair;
int leftvol = ch->leftvol;
int rightvol = ch->rightvol;
samp = (short *) sc->data + ch->pos * 2;
pair = paintbuffer;
while (count-- > 0) {
pair->left += *samp++ * leftvol;
pair->right += *samp++ * rightvol;
pair++;
}
}