Added -3dB normalized pan law to playptmod
This commit is contained in:
parent
c61b592f71
commit
19af37059f
1 changed files with 16 additions and 4 deletions
|
@ -278,6 +278,7 @@ typedef struct
|
||||||
float *frequencyTable;
|
float *frequencyTable;
|
||||||
float *extendedFrequencyTable;
|
float *extendedFrequencyTable;
|
||||||
unsigned char *sinusTable;
|
unsigned char *sinusTable;
|
||||||
|
int *panTable;
|
||||||
int minPeriod;
|
int minPeriod;
|
||||||
int maxPeriod;
|
int maxPeriod;
|
||||||
int loopCounter;
|
int loopCounter;
|
||||||
|
@ -522,8 +523,8 @@ static void mixerSetChSource(player *p, int ch, const char *src, int length, int
|
||||||
|
|
||||||
static void mixerSetChPan(player *p, int ch, int pan)
|
static void mixerSetChPan(player *p, int ch, int pan)
|
||||||
{
|
{
|
||||||
p->v[ch].panL = 256 - pan;
|
p->v[ch].panL = p->panTable[256 - pan];
|
||||||
p->v[ch].panR = pan;
|
p->v[ch].panR = p->panTable[pan];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mixerSetChVol(player *p, int ch, int vol)
|
static void mixerSetChVol(player *p, int ch, int vol)
|
||||||
|
@ -2744,6 +2745,7 @@ void playptmod_Render(void *_p, short *target, int length)
|
||||||
void *playptmod_Create(int samplingFrequency)
|
void *playptmod_Create(int samplingFrequency)
|
||||||
{
|
{
|
||||||
player *p = (player *) calloc(1, sizeof(player));
|
player *p = (player *) calloc(1, sizeof(player));
|
||||||
|
float norm;
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
|
@ -2770,6 +2772,15 @@ void *playptmod_Create(int samplingFrequency)
|
||||||
for (i = 14; i <= 1712; ++i) // 0..14 will never be looked up, junk is OK
|
for (i = 14; i <= 1712; ++i) // 0..14 will never be looked up, junk is OK
|
||||||
p->extendedFrequencyTable[i] = (float)samplingFrequency / (7093790.0f / (2.0f * (float)i));
|
p->extendedFrequencyTable[i] = (float)samplingFrequency / (7093790.0f / (2.0f * (float)i));
|
||||||
|
|
||||||
|
p->panTable = (int *)malloc(sizeof (int) * 257);
|
||||||
|
norm = 1.0f / sinf(1.0f / (M_PI / 2));
|
||||||
|
for (i = 0; i <= 256; ++i)
|
||||||
|
{
|
||||||
|
float pan = (float)i * 1.0f / 256.0f;
|
||||||
|
|
||||||
|
// -3dB pan law ( pan = sin x/half_pi )
|
||||||
|
p->panTable[i] = 256.0f * sinf((pan) / (M_PI / 2)) * norm;
|
||||||
|
}
|
||||||
p->mixBufferL = (float *)malloc(soundBufferSize * sizeof (float));
|
p->mixBufferL = (float *)malloc(soundBufferSize * sizeof (float));
|
||||||
p->mixBufferR = (float *)malloc(soundBufferSize * sizeof (float));
|
p->mixBufferR = (float *)malloc(soundBufferSize * sizeof (float));
|
||||||
|
|
||||||
|
@ -2873,6 +2884,7 @@ void playptmod_Free(void *_p)
|
||||||
|
|
||||||
free(p->mixBufferL);
|
free(p->mixBufferL);
|
||||||
free(p->mixBufferR);
|
free(p->mixBufferR);
|
||||||
|
free(p->panTable);
|
||||||
free(p->sinusTable);
|
free(p->sinusTable);
|
||||||
free(p->frequencyTable);
|
free(p->frequencyTable);
|
||||||
free(p->extendedFrequencyTable);
|
free(p->extendedFrequencyTable);
|
||||||
|
|
Loading…
Reference in a new issue