我正在尝试同时播放声音和记录来自压电传感器的电压输出。为此,我将我的声卡模拟输出连接到扬声器,并将我的声卡模拟输入连接到压电传感器。在
当我录下来自传感器的信号但没有播放声音时,它工作得很好。但是,当我在录音过程中播放声音时,我可以看到我正在播放的声音在传感器的信号中,就好像声音板的输出和输入是连接在一起的。最奇怪的是,即使我拔下传感器,输出信号仍然存在于录音中。在
换句话说,问题是:我开始录音,当我开始播放声音时,它会出现在传感器的信号中(即使在扬声器关闭的情况下)。在
我只使用ALSA,没有安装pulseaudio。我使用python(和pyaudio)来生成声音信号,将信号写入声音板输出,并从声音板输入读取数据。我也做了大胆的测试,但结果是一样的。我还用录音带测试:$ arecord --channel=1 --rate=128000 --format=S32_LE Test.wav
然后:
^{pr2}$
然后停止了录音。当我玩的时候测试.wav,播放文件的所有声音信号都在那里。在
我知道这听起来很明显,但我想说的是,在设置的任何地方都没有连接麦克风。在
以下是一些信息:
======================
盒子:$ uname -a
Linux MalfattiTux 4.1.12-gentoo #3 SMP Thu Jan 21 17:24:27 BRST x86_64 Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz GenuineIntel GNU/Linux
音频板:$ lspci | grep -i audio
00:03.0 Audio device: Intel Corporation Xeon E3-1200 v3/4th Gen Core Processor HD Audio Controller (rev 06)
00:1b.0 Audio device: Intel Corporation 8 Series/C220 Series Chipset High Definition Audio Controller (rev 05)## Heading ##
输出设备:$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: HDMI [HDA Intel HDMI], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: HDMI [HDA Intel HDMI], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 0: ALC3239 Analog [ALC3239 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: PCH [HDA Intel PCH], device 1: ALC3239 Digital [ALC3239 Digital]
Subdevices: 1/1
Subdevice #0: subdevice #0
输入设备:$ arecord -l
**** List of CAPTURE Hardware Devices ****
card 1: PCH [HDA Intel PCH], device 0: ALC3239 Analog [ALC3239 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
要播放和录制的Python代码(最小工作示例):import array
import pyaudio
import random
Rate = 128000
SoundPulseDur = 5 # in seconds
print('Generating sound pulse...')
SoundNoise = [random.random() for _ in range(round(Rate*SoundPulseDur))]
SoundPulse = [SoundNoise[ElI]*2-1 for ElI,ElV in enumerate(SoundNoise)]
SoundPulse[-1] = 0
print('Interleaving channels...')
SoundList = [0]*(2*len(SoundPulse))
for _ in range(len(SoundPulse)):
SoundList[_ *2] = SoundPulse[_]
SoundList[_ *2+1] = 0
Sound = array.array('f')
Sound.fromlist(SoundList)
Sound = bytes(Sound)
print('Generating sound objects...')
# Output
p = pyaudio.PyAudio()
Stimulation = p.open(format=pyaudio.paFloat32,
channels=2,
rate=Rate,
output=True)
# Input
q = pyaudio.PyAudio()
InOn = False
RecStop = True
def InCallBack(in_data, frame_count, time_info, status):
if InOn:
global SoundRec
SoundRec.append(in_data)
if RecStop:
InFlag = pyaudio.paComplete
else:
InFlag = pyaudio.paContinue
return(None, InFlag)
Reading = q.open(format=pyaudio.paFloat32,
channels=1,
rate=Rate,
input=True,
output=False,
stream_callback=InCallBack)
SoundRec = []
Reading.start_stream()
RecStop = False; InOn = True
Stimulation.write(Sound)
InOn = False; RecStop = True
Reading.stop_stream()