Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions source/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,11 @@ def _setInitialFocus():

def main():
"""NVDA's core main loop.
This initializes all modules such as audio, IAccessible, keyboard, mouse, and GUI. Then it initialises the wx application object and sets up the core pump, which checks the queues and executes functions when requested. Finally, it starts the wx main loop.
"""
This initializes all modules such as audio, IAccessible, keyboard, mouse, and GUI.
Then it initialises the wx application object and sets up the core pump,
which checks the queues and executes functions when requested.
Finally, it starts the wx main loop.
"""
log.debug("Core starting")

ctypes.windll.user32.SetProcessDPIAware()
Expand All @@ -224,6 +227,9 @@ def main():
except:
pass
logHandler.setLogLevelFromConfig()
log.debug("Initializing tones")
import tones
tones.initialize()
try:
lang = config.conf["general"]["language"]
import languageHandler
Expand Down Expand Up @@ -535,6 +541,9 @@ def run(self):
if updateCheck:
_terminate(updateCheck)

# Terminate tones early.
import tones
_terminate(tones)
_terminate(watchdog)
_terminate(globalPluginHandler, name="global plugin handler")
_terminate(gui)
Expand Down
5 changes: 5 additions & 0 deletions source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,11 @@ def onOk(self, evt):
config.conf['audio']['audioDuckingMode']=index
audioDucking.setAudioDuckingMode(index)

# Reinitialize the tones module to update the audio device
import tones
tones.terminate()
tones.initialize()

if self.IsModal():
# Hack: we need to update the synth in our parent window before closing.
# Otherwise, NVDA will report the old synth even though the new synth is reflected visually.
Expand Down
34 changes: 22 additions & 12 deletions source/tones.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#tones.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2007-2017 NV Access Limited, Aleksey Sadovoy
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
# A part of NonVisual Desktop Access (NVDA)
# Copyright (C) 2007-2017 NV Access Limited, Aleksey Sadovoy, Leonard de Ruijter
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.

"""Utilities to generate and play tones"""

Expand All @@ -15,16 +14,27 @@

SAMPLE_RATE = 44100

try:
player = nvwave.WavePlayer(channels=2, samplesPerSec=int(SAMPLE_RATE), bitsPerSample=16, outputDevice=config.conf["speech"]["outputDevice"],wantDucking=False)
except:
log.warning("Failed to initialize audio for tones")
player = None
player = None


def initialize():
global player
try:
player = nvwave.WavePlayer(
channels=2,
samplesPerSec=int(SAMPLE_RATE),
bitsPerSample=16,
outputDevice=config.conf["speech"]["outputDevice"],
wantDucking=False
)
except Exception:
log.warning("Failed to initialize audio for tones", exc_info=True)
player = None

# When exiting, ensure player is deleted before modules get cleaned up.
# Otherwise, WavePlayer.__del__ will fail with an exception.
@atexit.register
def _cleanup():
def terminate():
global player
player = None

Expand All @@ -38,7 +48,7 @@ def beep(hz,length,left=50,right=50):
@type left: integer
@param right: volume of the right channel (0 to 100)
@type right: integer
"""
"""
log.io("Beep at pitch %s, for %s ms, left volume %s, right volume %s"%(hz,length,left,right))
if not player:
return
Expand Down