diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 33e9dceaa..def543d63 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -281,7 +281,7 @@ shouldsign_t ShouldSignChallenge(uint8_t *message) if ((max(now, then) - min(now, then)) > 60*15) return SIGN_BADTIME; - // ____ _____ ___ ____ _ + // ____ _____ ___ ____ _ // / ___|_ _/ _ \| _ \| | // \___ \ | || | | | |_) | | // ___) || || |_| | __/|_| @@ -2436,6 +2436,11 @@ static void CL_ConnectToServer(void) joinedIP[0] = '\0'; // And empty this for good measure regardless of whether or not we actually used it. + // Enable sound input/microphone in netgames, activating the microphone device. + if (netgame) + { + S_SoundInputSetEnabled(true); + } } static void Command_connect(void) @@ -2502,6 +2507,8 @@ static void Command_connect(void) { CONS_Alert(CONS_ERROR, M_GetText("There is no server identification with this network driver\n")); D_CloseConnection(); + + S_SoundInputSetEnabled(false); return; } } @@ -3659,6 +3666,7 @@ void D_QuitNetGame(void) K_ClearClientPowerLevels(); G_ObliterateParties(); K_ResetMidVote(); + S_SoundInputSetEnabled(false); DEBFILE("===========================================================================\n" " Log finish\n" @@ -7376,9 +7384,6 @@ void NetVoiceUpdate(void) return; } - // This necessarily runs every frame, not every tic - S_SoundInputSetEnabled(true); - UINT32 bytes_dequed = 0; do { diff --git a/src/menus/options-voice.cpp b/src/menus/options-voice.cpp index 8f02fad5f..7f3a8ba00 100644 --- a/src/menus/options-voice.cpp +++ b/src/menus/options-voice.cpp @@ -72,6 +72,24 @@ static boolean input_routine(INT32) return false; } +static void init_routine(void) +{ + if (!netgame) + { + S_SoundInputSetEnabled(true); + } +} + +static boolean quit_routine(void) +{ + if (!netgame) + { + S_SoundInputSetEnabled(false); + } + + return true; +} + menu_t OPTIONS_VoiceDef = { sizeof (OPTIONS_Voice) / sizeof (menuitem_t), &OPTIONS_MainDef, @@ -85,7 +103,7 @@ menu_t OPTIONS_VoiceDef = { draw_routine, M_DrawOptionsCogs, tick_routine, - NULL, - NULL, + init_routine, + quit_routine, input_routine, }; diff --git a/src/sdl/new_sound.cpp b/src/sdl/new_sound.cpp index 3ded71879..1fa9deea2 100644 --- a/src/sdl/new_sound.cpp +++ b/src/sdl/new_sound.cpp @@ -198,7 +198,6 @@ static void (*music_fade_callback)(); static SDL_AudioDeviceID g_device_id; static SDL_AudioDeviceID g_input_device_id; -static boolean g_input_device_paused; void* I_GetSfx(sfxinfo_t* sfx) { @@ -999,14 +998,14 @@ void I_UpdateAudioRecorder(void) boolean I_SoundInputIsEnabled(void) { - return g_input_device_id != 0 && !g_input_device_paused; + return g_input_device_id != 0; } boolean I_SoundInputSetEnabled(boolean enabled) { if (g_input_device_id == 0 && enabled) { - if (SDL_GetNumAudioDevices(true) == 0) + if (!sound_started || SDL_GetNumAudioDevices(true) == 0) { return false; } @@ -1023,21 +1022,17 @@ boolean I_SoundInputSetEnabled(boolean enabled) CONS_Alert(CONS_WARNING, "Failed to open input audio device: %s\n", SDL_GetError()); return false; } - g_input_device_paused = true; - } - - if (enabled && g_input_device_paused) - { SDL_PauseAudioDevice(g_input_device_id, SDL_FALSE); - g_input_device_paused = false; } - else if (!enabled && !g_input_device_paused) + else if (g_input_device_id != 0 && !enabled) { SDL_PauseAudioDevice(g_input_device_id, SDL_TRUE); SDL_ClearQueuedAudio(g_input_device_id); - g_input_device_paused = true; + SDL_CloseAudioDevice(g_input_device_id); + g_input_device_id = 0; } - return !g_input_device_paused; + + return enabled; } UINT32 I_SoundInputDequeueSamples(void *data, UINT32 len)