mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
work around pops in recording start
https://anki.tenderapp.com/discussions/ankidesktop/26005-when-recording-sound-on-mbp on my machine, the pops start around sample 2048 of a 44.1khz recording, and only for the first recording after the audio hardware has gone to sleep
This commit is contained in:
parent
ea5f8eed36
commit
39c0a57b13
2 changed files with 10 additions and 2 deletions
|
|
@ -288,8 +288,9 @@ class _Recorder:
|
||||||
|
|
||||||
class PyAudioThreadedRecorder(threading.Thread):
|
class PyAudioThreadedRecorder(threading.Thread):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, startupDelay):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
self.startupDelay = startupDelay
|
||||||
self.finish = False
|
self.finish = False
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
@ -297,6 +298,7 @@ class PyAudioThreadedRecorder(threading.Thread):
|
||||||
p = pyaudio.PyAudio()
|
p = pyaudio.PyAudio()
|
||||||
|
|
||||||
rate = int(p.get_default_input_device_info()['defaultSampleRate'])
|
rate = int(p.get_default_input_device_info()['defaultSampleRate'])
|
||||||
|
wait = int(rate * self.startupDelay)
|
||||||
|
|
||||||
stream = p.open(format=PYAU_FORMAT,
|
stream = p.open(format=PYAU_FORMAT,
|
||||||
channels=PYAU_CHANNELS,
|
channels=PYAU_CHANNELS,
|
||||||
|
|
@ -305,6 +307,8 @@ class PyAudioThreadedRecorder(threading.Thread):
|
||||||
input_device_index=PYAU_INPUT_INDEX,
|
input_device_index=PYAU_INPUT_INDEX,
|
||||||
frames_per_buffer=chunk)
|
frames_per_buffer=chunk)
|
||||||
|
|
||||||
|
stream.read(wait)
|
||||||
|
|
||||||
data = b""
|
data = b""
|
||||||
while not self.finish:
|
while not self.finish:
|
||||||
try:
|
try:
|
||||||
|
|
@ -325,6 +329,9 @@ class PyAudioThreadedRecorder(threading.Thread):
|
||||||
|
|
||||||
class PyAudioRecorder(_Recorder):
|
class PyAudioRecorder(_Recorder):
|
||||||
|
|
||||||
|
# discard first 250ms which may have pops/cracks
|
||||||
|
startupDelay = 0.25
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
for t in recFiles + [processingSrc, processingDst]:
|
for t in recFiles + [processingSrc, processingDst]:
|
||||||
try:
|
try:
|
||||||
|
|
@ -334,7 +341,7 @@ class PyAudioRecorder(_Recorder):
|
||||||
self.encode = False
|
self.encode = False
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.thread = PyAudioThreadedRecorder()
|
self.thread = PyAudioThreadedRecorder(startupDelay=self.startupDelay)
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ def getAudio(parent, encode=True):
|
||||||
mb.setEscapeButton(but)
|
mb.setEscapeButton(but)
|
||||||
t = time.time()
|
t = time.time()
|
||||||
r.start()
|
r.start()
|
||||||
|
time.sleep(r.startupDelay)
|
||||||
QApplication.instance().processEvents()
|
QApplication.instance().processEvents()
|
||||||
while not mb.clickedButton():
|
while not mb.clickedButton():
|
||||||
txt =_("Recording...<br>Time: %0.1f")
|
txt =_("Recording...<br>Time: %0.1f")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue