diff options
Diffstat (limited to 'plugins/dfsound')
-rw-r--r-- | plugins/dfsound/adsr.c | 11 | ||||
-rw-r--r-- | plugins/dfsound/alsa.c | 63 | ||||
-rw-r--r-- | plugins/dfsound/externals.h | 21 | ||||
-rw-r--r-- | plugins/dfsound/freeze.c | 54 | ||||
-rw-r--r-- | plugins/dfsound/psemuxa.h | 4 | ||||
-rw-r--r-- | plugins/dfsound/stdafx.h | 4 |
6 files changed, 99 insertions, 58 deletions
diff --git a/plugins/dfsound/adsr.c b/plugins/dfsound/adsr.c index e4873df..79f593c 100644 --- a/plugins/dfsound/adsr.c +++ b/plugins/dfsound/adsr.c @@ -46,6 +46,10 @@ void InitADSR(void) // INIT ADSR RateTableAdd[lcv] = ((7 - (lcv&3)) << 16) / denom;
RateTableSub[lcv] = ((-8 + (lcv&3)) << 16) / denom;
+
+ // XXX: this is wrong, we need more bits..
+ if (RateTableAdd[lcv] == 0)
+ RateTableAdd[lcv] = 1;
}
}
@@ -67,12 +71,13 @@ static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR if (s_chan[ch].bStop) // should be stopped:
{ // do release
val = RateTableSub[s_chan[ch].ADSRX.ReleaseRate * 4];
+
if (s_chan[ch].ADSRX.ReleaseModeExp)
{
for (; ns < ns_to; ns++)
{
EnvelopeVol += ((long long)val * EnvelopeVol) >> (15+16);
- if (EnvelopeVol < 0)
+ if (EnvelopeVol <= 0)
break;
ChanBuf[ns] *= EnvelopeVol >> 21;
@@ -84,7 +89,7 @@ static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR for (; ns < ns_to; ns++)
{
EnvelopeVol += val;
- if (EnvelopeVol < 0)
+ if (EnvelopeVol <= 0)
break;
ChanBuf[ns] *= EnvelopeVol >> 21;
@@ -92,7 +97,7 @@ static void MixADSR(int ch, int ns, int ns_to) // MIX ADSR }
}
- if (EnvelopeVol < 0)
+ if (EnvelopeVol <= 0)
goto stop;
goto done;
diff --git a/plugins/dfsound/alsa.c b/plugins/dfsound/alsa.c index 58900cc..1c02d37 100644 --- a/plugins/dfsound/alsa.c +++ b/plugins/dfsound/alsa.c @@ -24,24 +24,58 @@ static snd_pcm_t *handle = NULL; static snd_pcm_uframes_t buffer_size; +static void alsa_finish(void); + // SETUP SOUND static int alsa_init(void) { snd_pcm_hw_params_t *hwparams; snd_pcm_status_t *status; + snd_ctl_t *ctl_handle = NULL; + snd_ctl_card_info_t *info; unsigned int pspeed; int pchannels; int format; unsigned int buffer_time = 100000; unsigned int period_time = buffer_time / 4; + const char *alsa_name = "default"; + const char *name; + int retval = -1; int err; + name = getenv("ALSA_NAME"); + if (name != NULL) + alsa_name = name; + + snd_ctl_card_info_alloca(&info); + if ((err = snd_ctl_open(&ctl_handle, alsa_name, 0)) < 0) { + printf("control open: %s\n", snd_strerror(err)); + } + else if ((err = snd_ctl_card_info(ctl_handle, info)) < 0) { + printf("control info: %s\n", snd_strerror(err)); + snd_ctl_card_info_clear(info); + } + if (ctl_handle != NULL) + snd_ctl_close(ctl_handle); + + name = snd_ctl_card_info_get_name(info); + if (name != NULL) { + if (strcasecmp(name, "PulseAudio") == 0) { + // PulseAudio's ALSA emulation is known to be broken.. + printf("alsa: refusing to run under PulseAudio's emulation\n"); + return -1; + } + else { + printf("alsa: using '%s', set ALSA_NAME to change\n", name); + } + } + pchannels=2; pspeed = 44100; format = SND_PCM_FORMAT_S16; - if ((err = snd_pcm_open(&handle, "default", + if ((err = snd_pcm_open(&handle, alsa_name, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK)) < 0) { printf("Audio open error: %s\n", snd_strerror(err)); @@ -51,7 +85,7 @@ static int alsa_init(void) if((err = snd_pcm_nonblock(handle, 0))<0) { printf("Can't set blocking moded: %s\n", snd_strerror(err)); - return -1; + goto out; } snd_pcm_hw_params_alloca(&hwparams); @@ -59,60 +93,65 @@ static int alsa_init(void) if((err=snd_pcm_hw_params_any(handle, hwparams))<0) { printf("Broken configuration for this PCM: %s\n", snd_strerror(err)); - return -1; + goto out; } if((err=snd_pcm_hw_params_set_access(handle, hwparams, SND_PCM_ACCESS_RW_INTERLEAVED))<0) { printf("Access type not available: %s\n", snd_strerror(err)); - return -1; + goto out; } if((err=snd_pcm_hw_params_set_format(handle, hwparams, format))<0) { printf("Sample format not available: %s\n", snd_strerror(err)); - return -1; + goto out; } if((err=snd_pcm_hw_params_set_channels(handle, hwparams, pchannels))<0) { printf("Channels count not available: %s\n", snd_strerror(err)); - return -1; + goto out; } if((err=snd_pcm_hw_params_set_rate_near(handle, hwparams, &pspeed, 0))<0) { printf("Rate not available: %s\n", snd_strerror(err)); - return -1; + goto out; } if((err=snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, 0))<0) { printf("Buffer time error: %s\n", snd_strerror(err)); - return -1; + goto out; } if((err=snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, 0))<0) { printf("Period time error: %s\n", snd_strerror(err)); - return -1; + goto out; } if((err=snd_pcm_hw_params(handle, hwparams))<0) { printf("Unable to install hw params: %s\n", snd_strerror(err)); - return -1; + goto out; } snd_pcm_status_alloca(&status); if((err=snd_pcm_status(handle, status))<0) { printf("Unable to get status: %s\n", snd_strerror(err)); - return -1; + goto out; } buffer_size = snd_pcm_status_get_avail(status); - return 0; + retval = 0; + +out: + if (retval != 0) + alsa_finish(); + return retval; } // REMOVE SOUND diff --git a/plugins/dfsound/externals.h b/plugins/dfsound/externals.h index 28dab57..2f3028e 100644 --- a/plugins/dfsound/externals.h +++ b/plugins/dfsound/externals.h @@ -58,24 +58,6 @@ // ADSR INFOS PER CHANNEL
typedef struct
{
- int AttackModeExp;
- long AttackTime;
- long DecayTime;
- long SustainLevel;
- int SustainModeExp;
- long SustainModeDec;
- long SustainTime;
- int ReleaseModeExp;
- unsigned long ReleaseVal;
- long ReleaseTime;
- long ReleaseStartTime;
- long ReleaseVol;
- long lTime;
- long lVolume;
-} ADSRInfo;
-
-typedef struct
-{
unsigned char State:2;
unsigned char AttackModeExp:1;
unsigned char SustainModeExp:1;
@@ -215,11 +197,10 @@ extern int decode_pos; extern SPUCHAN s_chan[];
extern REVERBInfo rvb;
-extern unsigned long dwNoiseVal;
extern unsigned short spuCtrl;
extern unsigned short spuStat;
extern unsigned short spuIrq;
-extern unsigned long spuAddr;
+extern unsigned int spuAddr;
extern int bSpuInit;
extern unsigned int dwNewChannel;
extern unsigned int dwChannelOn;
diff --git a/plugins/dfsound/freeze.c b/plugins/dfsound/freeze.c index ec097c5..0601bf5 100644 --- a/plugins/dfsound/freeze.c +++ b/plugins/dfsound/freeze.c @@ -29,6 +29,24 @@ typedef struct
{
+ int AttackModeExp;
+ int AttackTime;
+ int DecayTime;
+ int SustainLevel;
+ int SustainModeExp;
+ int SustainModeDec;
+ int SustainTime;
+ int ReleaseModeExp;
+ unsigned int ReleaseVal;
+ int ReleaseTime;
+ int ReleaseStartTime;
+ int ReleaseVol;
+ int lTime;
+ int lVolume;
+} ADSRInfo;
+
+typedef struct
+{
int State;
int AttackModeExp;
int AttackRate;
@@ -40,9 +58,9 @@ typedef struct int ReleaseModeExp;
int ReleaseRate;
int EnvelopeVol;
- long lVolume;
- long lDummy1;
- long lDummy2;
+ int lVolume;
+ int lDummy1;
+ int lDummy2;
} ADSRInfoEx_orig;
typedef struct
@@ -58,9 +76,9 @@ typedef struct int SB[32+32]; // Pete added another 32 dwords in 1.6 ... prevents overflow issues with gaussian/cubic interpolation (thanx xodnizel!), and can be used for even better interpolations, eh? :)
int sval;
- unsigned char * pStart; // start ptr into sound mem
- unsigned char * pCurr; // current pos in sound mem
- unsigned char * pLoop; // loop ptr in sound mem
+ int iStart; // start ptr into sound mem
+ int iCurr; // current pos in sound mem
+ int iLoop; // loop ptr in sound mem
int bOn; // is channel active (sample playing?)
int bStop; // is channel stopped (sample _can_ still be playing, ADSR Release phase)
@@ -128,9 +146,9 @@ static void save_channel(SPUCHAN_orig *d, const SPUCHAN *s, int ch) d->spos = s->spos;
d->sinc = s->sinc;
memcpy(d->SB, s->SB, sizeof(d->SB));
- d->pStart = (unsigned char *)((regAreaGet(ch,6)&~1)<<3);
- d->pCurr = s->pCurr;
- d->pLoop = s->pLoop;
+ d->iStart = (regAreaGet(ch,6)&~1)<<3;
+ d->iCurr = 0; // set by the caller
+ d->iLoop = 0; // set by the caller
d->bOn = !!(dwChannelOn & (1<<ch));
d->bStop = s->bStop;
d->bReverb = s->bReverb;
@@ -168,9 +186,8 @@ static void load_channel(SPUCHAN *d, const SPUCHAN_orig *s, int ch) d->spos = s->spos;
d->sinc = s->sinc;
memcpy(d->SB, s->SB, sizeof(d->SB));
- d->pCurr = (void *)((long)s->pCurr & 0x7fff0);
- d->pLoop = (void *)((long)s->pLoop & 0x7fff0);
- if (s->bOn) dwChannelOn |= 1<<ch;
+ d->pCurr = (void *)((long)s->iCurr & 0x7fff0);
+ d->pLoop = (void *)((long)s->iLoop & 0x7fff0);
d->bStop = s->bStop;
d->bReverb = s->bReverb;
d->iLeftVolume = s->iLeftVolume;
@@ -191,6 +208,8 @@ static void load_channel(SPUCHAN *d, const SPUCHAN_orig *s, int ch) d->ADSRX.ReleaseModeExp = s->ADSRX.ReleaseModeExp;
d->ADSRX.ReleaseRate = s->ADSRX.ReleaseRate;
d->ADSRX.EnvelopeVol = s->ADSRX.EnvelopeVol;
+ if (s->bOn) dwChannelOn |= 1<<ch;
+ else d->ADSRX.EnvelopeVol = 0;
}
////////////////////////////////////////////////////////////////////////
@@ -234,14 +253,11 @@ long CALLBACK SPUfreeze(uint32_t ulFreezeMode,SPUFreeze_t * pF) for(i=0;i<MAXCHAN;i++)
{
- if(!(s_chan[i].prevflags&2))
- dwChannelOn&=~(1<<i);
-
save_channel(&pFO->s_chan[i],&s_chan[i],i);
- if(pFO->s_chan[i].pCurr)
- pFO->s_chan[i].pCurr-=(unsigned long)spuMemC;
- if(pFO->s_chan[i].pLoop)
- pFO->s_chan[i].pLoop-=(unsigned long)spuMemC;
+ if(s_chan[i].pCurr)
+ pFO->s_chan[i].iCurr=s_chan[i].pCurr-spuMemC;
+ if(s_chan[i].pLoop)
+ pFO->s_chan[i].iLoop=s_chan[i].pLoop-spuMemC;
}
return 1;
diff --git a/plugins/dfsound/psemuxa.h b/plugins/dfsound/psemuxa.h index 84c6260..402d273 100644 --- a/plugins/dfsound/psemuxa.h +++ b/plugins/dfsound/psemuxa.h @@ -8,7 +8,7 @@ typedef struct
{
- long y0, y1;
+ int y0, y1;
} ADPCM_Decode_t;
typedef struct
@@ -21,7 +21,7 @@ typedef struct short pcm[16384];
} xa_decode_t;
-long xa_decode_sector( xa_decode_t *xdp,
+int xa_decode_sector( xa_decode_t *xdp,
unsigned char *sectorp,
int is_first_sector );
diff --git a/plugins/dfsound/stdafx.h b/plugins/dfsound/stdafx.h index d40344f..8993bb3 100644 --- a/plugins/dfsound/stdafx.h +++ b/plugins/dfsound/stdafx.h @@ -32,9 +32,9 @@ #undef CALLBACK #define CALLBACK -#define DWORD unsigned long +#define DWORD unsigned int #define LOWORD(l) ((unsigned short)(l)) -#define HIWORD(l) ((unsigned short)(((unsigned long)(l) >> 16) & 0xFFFF)) +#define HIWORD(l) ((unsigned short)(((unsigned int)(l) >> 16) & 0xFFFF)) #ifndef INLINE #define INLINE static inline |