diff --git a/src/audio/os2/SDL_os2audio.c b/src/audio/os2/SDL_os2audio.c index 7b83d2447..f906e892d 100644 --- a/src/audio/os2/SDL_os2audio.c +++ b/src/audio/os2/SDL_os2audio.c @@ -268,7 +268,9 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname, MCI_BUFFER_PARMS stMCIBuffer; ULONG ulRC; ULONG ulIdx; + BOOL new_freq; + new_freq = FALSE; SDL_zero(stMCIAmpOpen); SDL_zero(stMCIBuffer); @@ -350,10 +352,12 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname, if ( this->spec.freq < 8000 ) { this->spec.freq = 8000; + new_freq = TRUE; } else if ( this->spec.freq > 48000 ) { this->spec.freq = 48000; + new_freq = TRUE; } // Setup mixer. @@ -377,6 +381,7 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname, MCI_WAIT | MCI_MIXSETUP_INIT, &pAData->stMCIMixSetup, 0 ); if ( ( ulRC != MCIERR_SUCCESS ) && ( this->spec.freq > 44100 ) ) { + new_freq = TRUE; pAData->stMCIMixSetup.ulSamplesPerSec = 44100; this->spec.freq = 44100; ulRC = mciSendCommand( pAData->usDeviceId, MCI_MIXSETUP, @@ -395,13 +400,22 @@ static int OS2_OpenDevice(_THIS, void *handle, const char *devname, return _MCIError( "MCI_MIXSETUP", ulRC ); } - this->spec.samples = pAData->stMCIMixSetup.ulSamplesPerSec; + if (this->spec.samples == 0 || new_freq == TRUE) { + /* also see SDL_audio.c:prepare_audiospec() */ + /* Pick a default of ~46 ms at desired frequency */ + Uint32 samples = (this->spec.freq / 1000) * 46; + Uint32 power2 = 1; + while (power2 < samples) { + power2 <<= 1; + } + this->spec.samples = power2; + } /* Update the fragment size as size in bytes */ SDL_CalculateAudioSpec( &this->spec ); // Allocate memory buffers - stMCIBuffer.ulBufferSize = (this->spec.freq / 1000) * 100;// this->spec.size; + stMCIBuffer.ulBufferSize = this->spec.size;// (this->spec.freq / 1000) * 100; stMCIBuffer.ulNumBuffers = NUM_BUFFERS; stMCIBuffer.pBufList = &pAData->aMixBuffers;