0

I am attempting to record in stereo using a pair of stereo headphones, this Stereo USB soundcard:

http://www.ebay.co.uk/itm/261343188737?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

and my laptop. I am using the USB soundcard as I eventually want to get this working on my raspberry pi. I am using pyalsaaudio and the following code:

import matplotlib
import alsaaudio, wave, numpy

inp = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, 'plughw:CARD=Device')
inp.setchannels(2)
inp.setrate(44100)
inp.setformat(alsaaudio.PCM_FORMAT_S16_LE)
inp.setperiodsize(1024)


i = int(raw_input('How many samples of recording?'))
amplitude = []

while i > 0:
    l, data = inp.read()
    a = numpy.fromstring(data, dtype='int16')
    amplitude.extend(abs(a))
    i -= 1

print amplitude

I want each headphone to be a separate channels, ie. left headphone = channel 1, right headphone = channel 2 but so far I have only got what appears to be a mono recording, (when I make a sound in to jsut one headphone I get for example (245, 321, 678, 672, 478, 456) as the resulting data when I am expecting for interleaved audio data something like (245, 21, 678, 25, 567, 12) ie. a small reading from one channel and a large one from the other.

arecord -L returns:

default Playback/recording through the PulseAudio sound server

sysdefault:CARD=PCH HDA Intel PCH, ALC270 Analog Default Audio Device

front:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog Front speakers

surround40:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog 4.0 Surround output to Front and Rear speakers

surround41:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog 4.1 Surround output to Front, Rear and Subwoofer speakers

surround50:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog 5.0 Surround output to Front, Center and Rear speakers

surround51:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog 5.1 Surround output to Front, Center, Rear and Subwoofer speakers

surround71:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers

dmix:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog Direct sample mixing device

dsnoop:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog Direct sample snooping device

hw:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog Direct hardware device without any conversions

plughw:CARD=PCH,DEV=0 HDA Intel PCH, ALC270 Analog Hardware device with all software conversions

sysdefault:CARD=Device USB PnP Sound Device, USB Audio Default Audio Device

front:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio Front speakers

surround40:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio 4.0 Surround output to Front and Rear speakers

surround41:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio 4.1 Surround output to Front, Rear and Subwoofer speakers

surround50:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio 5.0 Surround output to Front, Center and Rear speakers

surround51:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio 5.1 Surround output to Front, Center, Rear and Subwoofer speakers

surround71:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers

iec958:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio IEC958 (S/PDIF) Digital Audio Output

dmix:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio Direct sample mixing device

dsnoop:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio Direct sample snooping device

hw:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio Direct hardware device without any conversions

plughw:CARD=Device,DEV=0 USB PnP Sound Device, USB Audio Hardware device with all software conversions

Not completely certain which of these are relevant...

PCH is the built in sound card on my laptop, Device is the USB soundcard. I am starting to doubt that the USB soundcard is actually capable of stereo recording as when I run alsamixer I cannot adjust the left and right channels for the mic individually.

On that basis I would first like to get the stereo recording working on my laptops's soundcard, but I am not sure how to specify to use the headphones plugged into the headphone/mic port on my laptop to record rather than the built in laptop mic - In general I cannot work out how to record using a specific device on a soundcard.

I am not sure quite what to try next as I am new to alsa and pyalsaaudio. Any advice on how to make this work would be appreciated.

  • Forget `aplay`; try to get this to work with `arecord`. Is this device actually capable of recording from two microphones at the same time? – CL. Jan 10 '14 at 21:50
  • I didn't make any reference to aplay... What I am trying to do is record in stereo from ONE pair of stereo headphones and then I will separate the channels. The USB soundcard says it can record in stereo but in reality it may or may not be able to do this. My laptop soundcard should certainly be able to record in stereo but I haven't had any luck with that either... – user2961850 Jan 10 '14 at 21:57
  • Sorry, I got confused by the device list because most are playback-only devices. Most sound cards have a single capture device and select the recording source with mixer controls. Please note that all microphones input jacks are mono unless explicitly constructed for stereo mics. – CL. Jan 11 '14 at 08:40

0 Answers0