Skip to content

Commit 77bd32e

Browse files
"preallocated" memory for malloc() changed to 0x20000 (for open cubic player)
1 parent 3a2c601 commit 77bd32e

File tree

7 files changed

+63
-52
lines changed

7 files changed

+63
-52
lines changed

History.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
v1.4, 14.4.2024
2+
v1.4, 20.4.2024
33

44
- added 16-bit protected-mode variant vsbhda16.exe.
55
- reworked HDA initialization code

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ A_DEBUG_FLAGS=-D_DEBUG -Fl$*
4949
!else
5050
OUTD=ow
5151
OUTD16=ow16
52-
C_DEBUG_FLAGS=-D_LOG
52+
C_DEBUG_FLAGS=
5353
A_DEBUG_FLAGS=
5454
!endif
5555

src/MAIN.C

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ static int freq = 22050; /* default value for AU_setrate() */
8181

8282
uint8_t bOMode = 1; /* 1=output DOS, 2=direct, 4=debugger */
8383

84-
#ifdef _LOG
85-
extern uint32_t dwMaxBytes;
86-
#endif
87-
8884
#if PREMAPDMA
8985
uint32_t MAIN_MappedBase; /* linear address mapped ISA DMA region (0x000000 - 0xffffff) */
9086
#endif
@@ -201,9 +197,6 @@ static void ReleaseRes( void )
201197
if( gvars.pm ) {
202198
PTRAP_Uninstall_PM_PortTraps();
203199
}
204-
#ifdef _LOG
205-
printf("max PCM buffer usage: %u\n", dwMaxBytes );
206-
#endif
207200

208201
return;
209202
}
@@ -461,11 +454,12 @@ int main(int argc, char* argv[])
461454
if ( gvars.vol != VOL_DEFAULT )
462455
printf("Volume=%u\n", gvars.vol );
463456

464-
/* temp alloc a 64 kB buffer so it will belong to THIS client. Any dpmi memory allocation
465-
* while another client is active will result in problems, since that memory is released when
466-
* the client exits. This is best done before SNDISR_InstallISR() is called.
457+
/* temp alloc a 64 kB chunk of memory. This will ensure that mallocs done while sound is playing won't
458+
* need another DPMI memory allocation. A dpmi memory allocation while another client is active will
459+
* result in problems, since that memory is released when that client exits.
460+
* This temp alloc is best done before SNDISR_InstallISR() is called.
467461
*/
468-
if (p = malloc( 0x10000 ) )
462+
if (p = malloc( 0x20000 ) ) /* 64 kB seems not enough for open cube player */
469463
free( p );
470464

471465
bISR = SNDISR_InstallISR(PIC_IRQ2VEC( AU_getirq( hAU ) ), &SNDISR_Interrupt );

src/SB.H

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
#define SB_MIXERREG_INPUTFILTER 0x0C /* SBPro only */
5454
#define SB_MIXERREG_MODEFILTER 0x0E /* SBPro only - bit 1:Stereo select, bit 5: Filter output */
55+
#define SB_MIXERREG_MODEFILTER_STEREO 2
5556

5657
/* the following regs are 3 bits for SBPro [1-3, 5-7], 4 bit [0-3, 4-7] for SB16 */
5758
#define SB_MIXERREG_VOICESTEREO 0x04 /* SBPro+, DAC level, 3/4 bit L & R */

src/SNDISR.C

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static uint32_t ISR_DMA_Size = 0;
5050
*/
5151
uint32_t ISR_DMA_MappedAddr = 0;
5252

53-
#ifdef _LOG
53+
#ifdef _LOGBUFFMAX
5454
uint32_t dwMaxBytes = 0;
5555
#endif
5656

@@ -418,17 +418,23 @@ int SNDISR_Interrupt( struct clientregs _far *clstat )
418418
/* in case there weren't enough samples copied, fill the rest with silence */
419419
for( i = pos; i < samples; i++ )
420420
*(pPCM + i*2+1) = *(pPCM + i*2) = 0;
421+
421422
} else if ( i = VSB_GetDirectCount( &pDirect ) ) {
423+
422424
int count = i;
423425
uint32_t freq = AU_getfreq( hAU );
424-
//uint32_t SB_Rate = VSB_GetSampleRate();
425-
uint32_t SB_Rate = count * freq / 128; /* just a "guess" */
426426

427-
dbgprintf(("isr, direct samples: cnt=%d, samples=%d \n", count, samples ));
427+
/* calc the src frequency by formula:
428+
* x / dst-freq = src-smpls / dst-smpls
429+
* x = src-smpl * dst-freq / dst-smpls
430+
*/
431+
uint32_t SB_Rate = count * freq / samples;
432+
433+
//dbgprintf(("isr, direct samples: cnt=%d, samples=%d, rate%u\n", count, samples, SB_Rate ));
428434
memcpy( pPCM, pDirect, count );
429-
cv_bits_8_to_16( pPCM, count ); /* converts unsigned 8-bit to signed 16-bit */
435+
cv_bits_8_to_16( pPCM, count );
430436
count = cv_rate( pPCM, count, 1, SB_Rate, freq );
431-
cv_channels_1_to_2( pPCM, count);
437+
cv_channels_1_to_2( pPCM, count );
432438
for( i = count; i < samples; i++ )
433439
*(pPCM + i*2+1) = *(pPCM + i*2) = 0;
434440
VSB_ResetDirectCount();
@@ -463,7 +469,7 @@ int SNDISR_Interrupt( struct clientregs _far *clstat )
463469
/* in assembly it's probably easier to handle signed/unsigned shifts */
464470
SNDISR_Mixer( pPCM, pPCMOPL, samples * 2, voicevol, midivol );
465471
#endif
466-
#ifdef _LOG
472+
#ifdef _LOGBUFFMAX
467473
if ( (( pPCMOPL + samples * 2 ) - pPCM ) * sizeof(int16_t) > dwMaxBytes )
468474
dwMaxBytes = (( pPCMOPL + samples * 2 ) - pPCM ) * sizeof(int16_t);
469475
#endif
@@ -474,7 +480,7 @@ int SNDISR_Interrupt( struct clientregs _far *clstat )
474480
if( digital ) {
475481
for( i = 0, pPCMOPL = pPCM; i < samples * 2; i++, pPCMOPL++ ) *pPCMOPL = ( *pPCMOPL * voicevol ) >> 8;
476482
//dbgprintf(("+"));
477-
#ifdef _LOG
483+
#ifdef _LOGBUFFMAX
478484
if ( (( pPCMOPL + samples * 2 ) - pPCM ) * sizeof(int16_t) > dwMaxBytes )
479485
dwMaxBytes = (( pPCMOPL + samples * 2 ) - pPCM ) * sizeof(int16_t);
480486
#endif
@@ -514,6 +520,9 @@ bool SNDISR_UninstallISR( void )
514520
////////////////////////////////
515521
{
516522
/* first uninstall int 31h, then ISR! */
523+
#ifdef _LOGBUFFMAX
524+
printf("max PCM buffer usage: %u\n", dwMaxBytes );
525+
#endif
517526
_hdpmi_UninstallInt31();
518527
return ( _hdpmi_UninstallISR() );
519528
}

src/VSB.C

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static int VSB_HDMA = 5;
4949
#endif
5050
static int VSB_DACSpeaker = 1;
5151
static unsigned int VSB_Bits = 8;
52-
static int VSB_SampleRate = 22050;
52+
static int VSB_SampleRate;
5353
static unsigned int VSB_Samples = 0; /* the length argument after a play command (samples - 1) */
5454
static int VSB_Auto = false; /* auto-initialize mode active */
5555
static int VSB_HighSpeed = 0;
@@ -220,12 +220,13 @@ static void DSP_Reset( uint8_t value )
220220
#else
221221
VSB_MixerRegs[SB_MIXERREG_DMA_SETUP] = (1 << VSB_DMA) & 0xB;
222222
#endif
223-
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] = 0xFD; //mask out stereo
223+
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] = 0x11; //SB Pro: mono, no filter
224224
VSB_MixerRegIndex = 0;
225225
VSB_DSPCMD = -1;
226226
VSB_DSPCMD_Subindex = 0;
227227
DSPDataBytes = 0;
228228
VSB_Started = 0;
229+
VSB_SampleRate = 0;
229230
VSB_Samples = 0;
230231
VSB_Auto = false;
231232
VSB_Signed = false;
@@ -261,6 +262,24 @@ static void DSP_Reset( uint8_t value )
261262
}
262263
}
263264

265+
int VSB_CalcSampleRate( uint8_t value )
266+
///////////////////////////////////////
267+
{
268+
int rc = 0;
269+
int i;
270+
for( i = 0; i < 3; ++i ) {
271+
if(value >= VSB_TimeConstantMapMono[i][0] - 3 && value <= VSB_TimeConstantMapMono[i][0] + 3 ) {
272+
rc = VSB_TimeConstantMapMono[i][1] / VSB_GetChannels();
273+
break;
274+
}
275+
}
276+
if(!rc) {
277+
//rc = 1000000 / ( 256 - value ) / VSB_GetChannels();
278+
rc = 256000000/( 65536 - (value << 8) ) / VSB_GetChannels();
279+
}
280+
return rc;
281+
}
282+
264283
/* write port 2xC */
265284

266285
static void DSP_Write( uint8_t value )
@@ -330,7 +349,7 @@ static void DSP_Write( uint8_t value )
330349
ISR_adpcm_state.useRef = true;
331350
ISR_adpcm_state.step = 0;
332351
VSB_Bits = (value == SB_DSP_2BIT_OUT_AUTO) ? 2 : (value == SB_DSP_3BIT_OUT_AUTO) ? 3 : 4;
333-
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] &= ~0x2;
352+
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] &= ~SB_MIXERREG_MODEFILTER_STEREO;
334353
VSB_Silent = false;
335354
VSB_Started = true; //start transfer here
336355
VSB_Pos = 0;
@@ -405,8 +424,10 @@ static void DSP_Write( uint8_t value )
405424
/* bit 4 of value: 1=signed */
406425
VSB_Signed = ( ( value & 0x10 ) ? true : false );
407426
/* bit 5 of value: 1=stereo */
408-
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] &= ~2;
409-
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] |= ( ( value & 0x20 ) ? 2 : 0 );
427+
if ( value & 0x20 )
428+
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] |= SB_MIXERREG_MODEFILTER_STEREO;
429+
else
430+
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] &= ~SB_MIXERREG_MODEFILTER_STEREO;
410431
VSB_DSPCMD_Subindex++;
411432
break;
412433
case 1:
@@ -425,21 +446,14 @@ static void DSP_Write( uint8_t value )
425446
int i;
426447
switch( VSB_DSPCMD ) {
427448
case SB_DSP_SET_TIMECONST: /* 40 */
428-
VSB_SampleRate = 0;
429449
#if !LATERATE
430-
for( i = 0; i < 3; ++i ) {
431-
if(value >= VSB_TimeConstantMapMono[i][0]-3 && value <= VSB_TimeConstantMapMono[i][0]+3) {
432-
VSB_SampleRate = VSB_TimeConstantMapMono[i][1] / VSB_GetChannels();
433-
break;
434-
}
435-
}
436-
if(VSB_SampleRate == 0)
437-
VSB_SampleRate = 256000000/( 65536 - (value << 8) ) / VSB_GetChannels();
438-
//VSB_SampleRate = 1000000 / ( 256 - value ) / VSB_GetChannels();
450+
VSB_SampleRate = VSB_CalcSampleRate( value );
451+
dbgprintf(("DSP_Write: time constant=%X, rate=%u\n", value, VSB_SampleRate ));
439452
#else
453+
VSB_SampleRate = 0;
440454
bTimeConst = value;
441-
#endif
442455
dbgprintf(("DSP_Write: time constant=%X\n", value ));
456+
#endif
443457
VSB_DSPCMD_Subindex = 2; //only 1byte
444458
break;
445459
case SB_DSP_8BIT_DIRECT: /* 10 */
@@ -480,8 +494,8 @@ static void DSP_Write( uint8_t value )
480494
ISR_adpcm_state.useRef = (VSB_DSPCMD & 1 );
481495
ISR_adpcm_state.step = 0;
482496
VSB_Bits = (VSB_DSPCMD <= SB_DSP_2BIT_OUT_1) ? 2 : (VSB_DSPCMD >= SB_DSP_3BIT_OUT_1_NREF) ? 3 : 4;
483-
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] &= ~0x2; /* reset stereo */
484-
VSB_Started = true; //start transfer here
497+
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] &= ~SB_MIXERREG_MODEFILTER_STEREO; /* reset stereo */
498+
VSB_Started = true;
485499
VSB_Silent = false;
486500
VSB_Signed = false;
487501
VSB_Pos = 0;
@@ -505,7 +519,7 @@ static void DSP_Write( uint8_t value )
505519
VSB_Samples = value;
506520
else {
507521
VSB_Samples |= value << 8; /* the value is #samples-1! */
508-
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] &= ~0x2; /* reset stereo */
522+
VSB_MixerRegs[SB_MIXERREG_MODEFILTER] &= ~SB_MIXERREG_MODEFILTER_STEREO; /* reset stereo */
509523
VSB_Signed = false;
510524
VSB_Bits = 8;
511525
VSB_Pos = 0;
@@ -717,24 +731,16 @@ int VSB_IsSigned()
717731
int VSB_GetChannels()
718732
/////////////////////
719733
{
720-
return (VSB_MixerRegs[SB_MIXERREG_MODEFILTER] & 0x2) ? 2 : 1;
734+
/* MIXERREG_MODEFILTER is for SB Pro only, but in vsbhda also set for sb16 */
735+
return (VSB_MixerRegs[SB_MIXERREG_MODEFILTER] & SB_MIXERREG_MODEFILTER_STEREO) ? 2 : 1;
721736
}
722737

723738
int VSB_GetSampleRate()
724739
///////////////////////
725740
{
726741
#if LATERATE
727-
if ( !VSB_SampleRate ) {
728-
for(int i = 0; i < 3; ++i) {
729-
if( bTimeConst >= VSB_TimeConstantMapMono[i][0]-3 && bTimeConst <= VSB_TimeConstantMapMono[i][0]+3) {
730-
VSB_SampleRate = VSB_TimeConstantMapMono[i][1] / VSB_GetChannels();
731-
break;
732-
}
733-
}
734-
if( VSB_SampleRate == 0 )
735-
VSB_SampleRate = 256000000/( 65536 - ( bTimeConst << 8) ) / VSB_GetChannels();
736-
//VSB_SampleRate = 1000000 / ( 256 - bTimeConst ) / VSB_GetChannels();
737-
}
742+
if ( !VSB_SampleRate )
743+
VSB_SampleRate = VSB_CalcSampleRate( bTimeConst );
738744
#endif
739745
return VSB_SampleRate;
740746
}

startup/SBRK.ASM

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
;--- simple __brk()
33
;--- assemble with -zcw
4+
;--- DPMI memory allocation must be done while program is current client!
45

56
.386
67
.model ?MODEL

0 commit comments

Comments
 (0)