C Programmer seeks help reading USB Microphone with OSS
Can anyone help this software developer figure out how to read a stream of input from my Logitech USB microphone and output it to a separate USB speaker? Been googling for days and can't find an answer. Very new to Linux and don't understand OSS/MIXERS enough to solve problem.
Plugged in my microphone into one USB port, the speaker into another.
run lsusb and they show as follows:
Bus 001 Device 002: ID 046d:0a0b Logitech, Inc.
Bus 002 Device 002: ID 0556:0001 Asahi Kasei Microsystems Co., Ltd AK5370 I/F A/D Converter.
run ossinfo and they show up there, too.
Device object 2: usb05560001-0 USB sound device
Device object 4: usb046d0a0b-0 USB sound device
Mixer device 0: USB sound device (Mixer 0 of device object 2)
Mixer device 1: USB sound device (Mixer 0 of device object 4)
USB sound device rec /dev/oss/usb05560001-1/pcmin0
USB sound device play /dev/oss/usb046d0a0b-1/pcm0
ls /dev/* and they show up there, too, where:
/dev/dsp0 -> /dev/oss/usb046d0a0b-pcm0
/dev/dsp2 -> /dev/oss/usb05560001-1/pcmin0
/dev/mixer0 -> /dev/oss/usb046d0a0b-0/mix0
/dev/mixer2 -> /dev/oss/usb05560001-0/mix0
I make sure sound is on:
%sudo soundon
OSS is already loaded
run my C application (I can provide the source later if needed), but basically it does the following:
int mic = open("/dev/dsp2", O_RDONLY);
int mmx = open("/dev/mixer2", O_RDONLY);
int spk = open("/dev/dsp0", O_WRONLY);
int smx = open("/dev/mixer0", O_WRONLY);
sends IOCTL commands for the microphone to subdivide by 2, reset, sync, set format to AFMT_S16LE, stereo to 0 (mono), speed to 44100. Even tried enabling input trigger. Used these same settings for speaker where appropriate.
Try to read mic data into buffer of 44100 bytes, and it blocks.
state = read( mic, &sound_buffer, sizeof(sound_buffer));
If I use ioctl to set it to non-blocking, state always returns -1.
(NOTE: Reading two bytes at a time in a loopcount of 20 works, but if I change the loop to 200, it blocks...)
To write to the speaker, I just do a simple write (but I haven't heard anything out of it yet, unless I pump a wav file to it "cat tone.wav > /dev/dev2"):
write( spk, &sound_buffer, state );
Any help would be great. Thanks!
|