Skip to content

Commit

Permalink
Deal with edge cases where drivers use non-ESS playback route
Browse files Browse the repository at this point in the history
  • Loading branch information
Cacodemon345 committed Mar 5, 2024
1 parent 9f50fae commit 5f47b8b
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/sound/snd_sb_dsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,27 @@ sb_add_data(sb_dsp_t *dsp, uint8_t v)
dsp->sb_read_wp &= 0xff;
}

static unsigned int sb_ess_get_dma_len(sb_dsp_t *dsp)
{
unsigned int r;

r = (unsigned int)ESSreg(0xA5) << 8U;
r |= (unsigned int)ESSreg(0xA4);

/* the 16-bit counter is a "two's complement" of the DMA count because it counts UP to 0 and triggers IRQ on overflow */
return 0x10000U-r;
}

void
sb_start_dma(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len)
{
dsp->sb_pausetime = -1;

if (dsp->ess_reload_len) {
len = sb_ess_get_dma_len(dsp);
dsp->ess_reload_len = 0;
}

if (dma8) {
dsp->sb_8_length = dsp->sb_8_origlength = len;
dsp->sb_8_format = format;
Expand Down Expand Up @@ -392,6 +408,11 @@ sb_start_dma(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len)
void
sb_start_dma_i(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len)
{
if (dsp->ess_reload_len) {
len = sb_ess_get_dma_len(dsp);
dsp->ess_reload_len = 0;
}

if (dma8) {
dsp->sb_8_length = dsp->sb_8_origlength = len;
dsp->sb_8_format = format;
Expand Down Expand Up @@ -419,18 +440,6 @@ sb_start_dma_i(sb_dsp_t *dsp, int dma8, int autoinit, uint8_t format, int len)
memset(dsp->record_buffer, 0, sizeof(dsp->record_buffer));
}


static unsigned int sb_ess_get_dma_len(sb_dsp_t *dsp)
{
unsigned int r;

r = (unsigned int)ESSreg(0xA5) << 8U;
r |= (unsigned int)ESSreg(0xA4);

/* the 16-bit counter is a "two's complement" of the DMA count because it counts UP to 0 and triggers IRQ on overflow */
return 0x10000U-r;
}

void
sb_start_dma_ess(sb_dsp_t* dsp)
{
Expand Down

0 comments on commit 5f47b8b

Please sign in to comment.