Skip to content

Commit

Permalink
Enable SDL audio capture for SDL 2.0.5 and newer
Browse files Browse the repository at this point in the history
The version check is required for supporting macOS PPC with SDL 2.0.1
and Travis-CI (Ubuntu Trusty) with SDL 2.0.2.

The client now requires SDL 2.0.5 runtime if compiled against SDL 2.0.5
or newer.
  • Loading branch information
zturtleman committed Apr 26, 2018
1 parent 45af259 commit 92935df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
26 changes: 15 additions & 11 deletions code/sdl/sdl_snd.c
Expand Up @@ -47,11 +47,11 @@ static int dmasize = 0;

static SDL_AudioDeviceID sdlPlaybackDevice;

#ifdef USE_VOIP
#if defined USE_VOIP && SDL_VERSION_ATLEAST( 2, 0, 5 )
#define USE_SDL_AUDIO_CAPTURE

static SDL_AudioDeviceID sdlCaptureDevice;
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
static cvar_t *s_sdlCapture;
#endif
static float sdlMasterGain = 1.0f;
#endif

Expand Down Expand Up @@ -96,7 +96,7 @@ static void SNDDMA_AudioCallback(void *userdata, Uint8 *stream, int len)
if (dmapos >= dmasize)
dmapos = 0;

#ifdef USE_VOIP
#ifdef USE_SDL_AUDIO_CAPTURE
if (sdlMasterGain != 1.0f)
{
int i;
Expand Down Expand Up @@ -283,8 +283,7 @@ qboolean SNDDMA_Init(void)
dmasize = (dma.samples * (dma.samplebits/8));
dma.buffer = calloc(1, dmasize);

#ifdef USE_VOIP
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
#ifdef USE_SDL_AUDIO_CAPTURE
// !!! FIXME: some of these SDL_OpenAudioDevice() values should be cvars.
s_sdlCapture = Cvar_Get( "s_sdlCapture", "1", CVAR_ARCHIVE | CVAR_LATCH );
if (!s_sdlCapture->integer)
Expand All @@ -310,10 +309,9 @@ qboolean SNDDMA_Init(void)
Com_Printf( "SDL capture device %s.\n",
(sdlCaptureDevice == 0) ? "failed to open" : "opened");
}
#endif
#endif

sdlMasterGain = 1.0f;
#endif

Com_Printf("Starting SDL audio callback...\n");
SDL_PauseAudioDevice(sdlPlaybackDevice, 0); // start callback.
Expand Down Expand Up @@ -349,13 +347,15 @@ void SNDDMA_Shutdown(void)
sdlPlaybackDevice = 0;
}

#ifdef USE_SDL_AUDIO_CAPTURE
if (sdlCaptureDevice)
{
Com_Printf("Closing SDL audio capture device...\n");
SDL_CloseAudioDevice(sdlCaptureDevice);
Com_Printf("SDL audio capture device closed.\n");
sdlCaptureDevice = 0;
}
#endif

SDL_QuitSubSystem(SDL_INIT_AUDIO);
free(dma.buffer);
Expand Down Expand Up @@ -391,7 +391,7 @@ void SNDDMA_BeginPainting (void)
#ifdef USE_VOIP
void SNDDMA_StartCapture(void)
{
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
#ifdef USE_SDL_AUDIO_CAPTURE
if (sdlCaptureDevice)
{
SDL_ClearQueuedAudio(sdlCaptureDevice);
Expand All @@ -402,7 +402,7 @@ void SNDDMA_StartCapture(void)

int SNDDMA_AvailableCaptureSamples(void)
{
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
#ifdef USE_SDL_AUDIO_CAPTURE
// divided by 2 to convert from bytes to (mono16) samples.
return sdlCaptureDevice ? (SDL_GetQueuedAudioSize(sdlCaptureDevice) / 2) : 0;
#else
Expand All @@ -412,7 +412,7 @@ int SNDDMA_AvailableCaptureSamples(void)

void SNDDMA_Capture(int samples, byte *data)
{
#if 0 // !!! FIXME: reenable after updating prebuild SDL libraries to 2.0.8!
#ifdef USE_SDL_AUDIO_CAPTURE
// multiplied by 2 to convert from (mono16) samples to bytes.
if (sdlCaptureDevice)
{
Expand All @@ -427,15 +427,19 @@ void SNDDMA_Capture(int samples, byte *data)

void SNDDMA_StopCapture(void)
{
#ifdef USE_SDL_AUDIO_CAPTURE
if (sdlCaptureDevice)
{
SDL_PauseAudioDevice(sdlCaptureDevice, 1);
}
#endif
}

void SNDDMA_MasterGain( float val )
{
#ifdef USE_SDL_AUDIO_CAPTURE
sdlMasterGain = val;
#endif
}
#endif

12 changes: 12 additions & 0 deletions code/sys/sys_local.h
Expand Up @@ -23,10 +23,22 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../qcommon/q_shared.h"
#include "../qcommon/qcommon.h"

#ifndef DEDICATED
#ifdef USE_LOCAL_HEADERS
# include "SDL_version.h"
#else
# include <SDL_version.h>
#endif

// Require a minimum version of SDL
#define MINSDL_MAJOR 2
#define MINSDL_MINOR 0
#if SDL_VERSION_ATLEAST( 2, 0, 5 )
#define MINSDL_PATCH 5
#else
#define MINSDL_PATCH 0
#endif
#endif

// Console
void CON_Shutdown( void );
Expand Down

0 comments on commit 92935df

Please sign in to comment.