Skip to content

Commit

Permalink
Use s_khz with SDL sound backend
Browse files Browse the repository at this point in the history
And remove s_sdlSpeed
  • Loading branch information
xycaleth committed Jun 9, 2018
1 parent 9736ae6 commit 63e31e8
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 54 deletions.
3 changes: 2 additions & 1 deletion code/client/snd_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
*****************************************************************************/
#include "../server/exe_headers.h"

#include "sdl/sdl_sound.h"
#include "snd_local.h"
#include "cl_mp3.h"
#include "snd_music.h"
Expand Down Expand Up @@ -619,7 +620,7 @@ void S_Init( void ) {
else
{
#endif
r = SNDDMA_Init();
r = SNDDMA_Init(s_khz->integer);

if ( r ) {
s_soundStarted = 1;
Expand Down
23 changes: 0 additions & 23 deletions code/client/snd_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,29 +184,6 @@ typedef struct {
int dataofs; // chunk starts this many bytes from file start
} wavinfo_t;



/*
====================================================================
SYSTEM SPECIFIC FUNCTIONS
====================================================================
*/

// initializes cycling through a DMA buffer and returns information on it
qboolean SNDDMA_Init(void);

// gets the current DMA position
int SNDDMA_GetDMAPos(void);

// shutdown the DMA xfer.
void SNDDMA_Shutdown(void);

void SNDDMA_BeginPainting (void);

void SNDDMA_Submit(void);

//====================================================================

#define MAX_CHANNELS 32
Expand Down
5 changes: 2 additions & 3 deletions codemp/client/snd_dma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*
*****************************************************************************/
#include "sdl/sdl_sound.h"
#include "snd_local.h"
#include "snd_mp3.h"
#include "snd_music.h"
Expand Down Expand Up @@ -436,8 +437,6 @@ void S_SoundInfo_f(void) {
Com_Printf("----------------------\n" );
}



/*
================
S_Init
Expand Down Expand Up @@ -618,7 +617,7 @@ void S_Init( void ) {
else
{
#endif
r = SNDDMA_Init();
r = SNDDMA_Init(s_khz->integer);

if ( r ) {
s_soundStarted = 1;
Expand Down
23 changes: 0 additions & 23 deletions codemp/client/snd_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,29 +180,6 @@ typedef struct wavinfo_s {
int dataofs; // chunk starts this many bytes from file start
} wavinfo_t;



/*
====================================================================
SYSTEM SPECIFIC FUNCTIONS
====================================================================
*/

// initializes cycling through a DMA buffer and returns information on it
qboolean SNDDMA_Init(void);

// gets the current DMA position
int SNDDMA_GetDMAPos(void);

// shutdown the DMA xfer.
void SNDDMA_Shutdown(void);

void SNDDMA_BeginPainting (void);

void SNDDMA_Submit(void);

//====================================================================

#define MAX_CHANNELS 32
Expand Down
17 changes: 13 additions & 4 deletions shared/sdl/sdl_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,23 @@ static void SNDDMA_PrintAudiospec(const char *str, const SDL_AudioSpec *spec)
Com_Printf( " Channels: %d\n", (int) spec->channels );
}

static int SNDDMA_ExpandSampleFrequencyKHzToHz(int khz)
{
switch (khz)
{
default:
case 44: return 44100;
case 22: return 22050;
case 11: return 11025;
}
}

/*
===============
SNDDMA_Init
===============
*/
qboolean SNDDMA_Init(void)
qboolean SNDDMA_Init(int sampleFrequencyInKHz)
{
SDL_AudioSpec desired;
SDL_AudioSpec obtained;
Expand All @@ -148,7 +159,6 @@ qboolean SNDDMA_Init(void)

if (!s_sdlBits) {
s_sdlBits = Cvar_Get("s_sdlBits", "16", CVAR_ARCHIVE_ND);
s_sdlSpeed = Cvar_Get("s_sdlSpeed", "0", CVAR_ARCHIVE);
s_sdlChannels = Cvar_Get("s_sdlChannels", "2", CVAR_ARCHIVE_ND);
s_sdlDevSamps = Cvar_Get("s_sdlDevSamps", "0", CVAR_ARCHIVE_ND);
s_sdlMixSamps = Cvar_Get("s_sdlMixSamps", "0", CVAR_ARCHIVE_ND);
Expand Down Expand Up @@ -176,8 +186,7 @@ qboolean SNDDMA_Init(void)
if ((tmp != 16) && (tmp != 8))
tmp = 16;

desired.freq = (int) s_sdlSpeed->value;
if(!desired.freq) desired.freq = 44100;
desired.freq = SNDDMA_ExpandSampleFrequencyKHzToHz(sampleFrequencyInKHz);
desired.format = ((tmp == 16) ? AUDIO_S16SYS : AUDIO_U8);

// I dunno if this is the best idea, but I'll give it a try...
Expand Down

0 comments on commit 63e31e8

Please sign in to comment.