Repository: nvaccess/nvda

Issue:
Log too verbose with last alpha
### Steps to reproduce:

* Set log level to DEBUG
* Perform some actions
* Press NVDA+F1 to open the log
* Press many times upArrow to review the log.

### Actual behavior:

The following lines can be found regularly and often in the log:

> ```DEBUG - synthDrivers.oneCore.SynthDriver.cancel (10:53:42.998) - MainThread (7200):
> Cancelling
> DEBUG - synthDrivers.oneCore.SynthDriver._callback (10:53:43.008) - Dummy-22 (18476):
> Done pushing audio
> DEBUG - synthDrivers.oneCore.SynthDriver._processQueue (10:53:43.008) - Dummy-22 (18476):
> Calling sync on audio player
> DEBUG - nvwave.WavePlayer._isPreferredDeviceOpen (10:53:43.008) - MainThread (7200):
> preferred device: WAVE_MAPPER current device name: WAVE_MAPPER (id: -1)
> DEBUG - synthDrivers.oneCore.SynthDriver._processQueue (10:53:43.008) - Dummy-22 (18476):
> Calling idle on audio player
> DEBUG - nvwave.WavePlayer._isPreferredDeviceOpen (10:53:43.008) - Dummy-22 (18476):
> preferred device: WAVE_MAPPER current device name: WAVE_MAPPER (id: -1)
> DEBUG - synthDrivers.oneCore.SynthDriver._processQueue (10:53:43.008) - Dummy-22 (18476):
> Queue empty, done processing```

### Expected behavior:

The log does not contain so much information regarding audio player so that the log can be read more easily when debugging. Maybe a solution would be to have a specific log option in advanced panel for this type of debug messages.

### System configuration
#### NVDA installed/portable/running from source:
From source

#### NVDA version:

Last alpha (commit f33664ec4935872e95f3add083a1e0ee96499832)

#### Windows version:

Windows 10

#### Name and version of other software in use when reproducing the issue:
N/A
#### Other information about your system:

### Other questions
#### Does the issue still occur after restarting your computer?
Yes
#### Have you tried any other versions of NVDA? If so, please report their behaviors.
2020.2 is OK. These appeared in last alpha only.

#### If addons are disabled, is your problem still occuring?

Yes

#### Did you try to run the COM registry fixing tool in NVDA menu / tools?
No



Discussion:
@feerrenrut: I think that you have introduced these debug messages.
Is it expected to have so much such messages? Thanks.

These log messages were left in since this change was made quite close to when we plan to release. If there were any problems with the nvWave changes, this would help us to rectify quickly. I certainly agree that longer term these messages are not very useful and quite noisy. I'd accept a change to put these messages behind an nvWave logging flag (in advanced settings panel). This change will likely have to target beta.

Resolving patch:
diff --git a/source/config/configSpec.py b/source/config/configSpec.py
--- a/source/config/configSpec.py
+++ b/source/config/configSpec.py
@@ -244,6 +244,7 @@
 	vision = boolean(default=false)
 	speech = boolean(default=false)
 	speechManager = boolean(default=false)
+	nvwave = boolean(default=false)
 
 [uwpOcr]
 	language = string(default="")
diff --git a/source/gui/settingsDialogs.py b/source/gui/settingsDialogs.py
--- a/source/gui/settingsDialogs.py
+++ b/source/gui/settingsDialogs.py
@@ -2456,6 +2456,7 @@ def __init__(self, parent):
 			"vision",
 			"speech",
 			"speechManager",
+			"nvwave",
 		]
 		# Translators: This is the label for a list in the
 		#  Advanced settings panel
diff --git a/source/nvwave.py b/source/nvwave.py
--- a/source/nvwave.py
+++ b/source/nvwave.py
@@ -119,6 +119,9 @@ def _winmm_errcheck(res, func, args):
 	func.errcheck = _winmm_errcheck
 
 
+def _isDebugForNvWave():
+	return config.conf["debugLog"]["nvwave"]
+
 class WavePlayer(garbageHandler.TrackedObject):
 	"""Synchronously play a stream of audio.
 	To use, construct an instance and feed it waveform audio using L{feed}.
@@ -230,10 +233,11 @@ def _setCurrentDevice(self, preferredDevice: typing.Union[str, int]) -> None:
 	def _isPreferredDeviceOpen(self) -> bool:
 		if self._waveout is None:
 			return False
-		log.debug(
-			f"preferred device: {self._preferredDeviceName}"
-			f" current device name: {self._outputDeviceName} (id: {self._outputDeviceID})"
-		)
+		if _isDebugForNvWave():
+			log.debug(
+				f"preferred device: {self._preferredDeviceName}"
+				f" current device name: {self._outputDeviceName} (id: {self._outputDeviceID})"
+			)
 		return self._outputDeviceName == self._preferredDeviceName
 
 	def _isPreferredDeviceAvailable(self) -> bool:
@@ -243,10 +247,12 @@ def _isPreferredDeviceAvailable(self) -> bool:
 		"""
 		for ID, name in _getOutputDevices():
 			if name == self._preferredDeviceName:
-				log.debug("preferred Device is Available")
+				if _isDebugForNvWave():
+					log.debug("preferred Device is Available")
 				return True
 
-		log.debug("preferred Device is not available")
+		if _isDebugForNvWave():
+			log.debug("preferred Device is not available")
 		return False
 
 	def open(self):
@@ -257,11 +263,12 @@ def open(self):
 		with self._waveout_lock:
 			if self._waveout:
 				return
-			log.debug(
-				f"Calling winmm.waveOutOpen."
-				f" outputDeviceName: {self._outputDeviceName}"
-				f" outputDeviceID: {self._outputDeviceID}"
-			)
+			if _isDebugForNvWave():
+				log.debug(
+					f"Calling winmm.waveOutOpen."
+					f" outputDeviceName: {self._outputDeviceName}"
+					f" outputDeviceID: {self._outputDeviceID}"
+				)
 			wfx = WAVEFORMATEX()
 			wfx.wFormatTag = WAVE_FORMAT_PCM
 			wfx.nChannels = self.channels
@@ -281,13 +288,15 @@ def open(self):
 						CALLBACK_EVENT
 					)
 			except WindowsError:
-				log.debug(
-					f"Error opening"
-					f" outputDeviceName: {self._outputDeviceName}"
-					f" with id: {self._outputDeviceID}"
-				)
+				if _isDebugForNvWave():
+					log.debug(
+						f"Error opening"
+						f" outputDeviceName: {self._outputDeviceName}"
+						f" with id: {self._outputDeviceID}"
+					)
 				if self._outputDeviceID != WAVE_MAPPER:
-					log.debug(f"Falling back to WAVE_MAPPER")
+					if _isDebugForNvWave():
+						log.debug(f"Falling back to WAVE_MAPPER")
 					self._setCurrentDevice(WAVE_MAPPER)
 					self.open()
 				else:
@@ -429,12 +438,14 @@ def _idleUnbuffered(self):
 				if not self._waveout:
 					return
 				if self.closeWhenIdle:
-					log.debug("Closing due to idle.")
+					if _isDebugForNvWave():
+						log.debug("Closing due to idle.")
 					self._close()  # Idle so no need to call stop.
 				else:
 					with self._global_waveout_lock:
 						if not self._isPreferredDeviceOpen() and self._isPreferredDeviceAvailable():
-							log.debug("Attempt re-open of preferred device.")
+							if _isDebugForNvWave():
+								log.debug("Attempt re-open of preferred device.")
 							self._close()  # Idle so no need to call stop.
 							self._setCurrentDevice(self._preferredDeviceName)
 							self.open()


Test patch: