LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-14-2011, 10:53 AM   #1
lashlarue
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Rep: Reputation: Disabled
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!
 
Old 07-14-2011, 01:55 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Strong suggestion: look into the "ALSA" library:

http://www.linuxjournal.com/article/6735

http://www.alsa-project.org/main/index.php/Main_Page
 
Old 07-14-2011, 02:22 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 07-14-2011, 02:37 PM   #4
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,237

Rep: Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322Reputation: 5322
Quote:
Originally Posted by paulsm4 View Post
Strong suggestion: look into the "ALSA" library:
Eh, I'd say go up a level and use gstreamer.

These should give you some ideas:

http://stackoverflow.com/questions/4...mp-as-raw-file
http://stackoverflow.com/questions/6...over-a-network
 
Old 07-18-2011, 10:56 AM   #5
lashlarue
LQ Newbie
 
Registered: Jul 2011
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks for the replies -- I'm in a situation where I need to use OSS drivers -- I'm developing code off site where I don't have all the hardware for the real-time recording system which uses OSS drivers. Since USB microphones are cheap, I thought I would be able to fake out the real-time recording software to read my USB microphone ( /dev/dsp2) instead of trying to read from uninstalled NI PC-6509 IO board. Guess I can't test my stuff until I go back onsite and install my code on the real-time recorder.

THanks!
 
Old 08-05-2011, 04:50 AM   #6
TimothyEBaldwin
Member
 
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
You can use the OSS API with ALSA driver, using either the in kernel shim, or the aoss program.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie seeks in setting up D-Link wireless usb wua 1340 with ndiswrapper FJK Linux - Wireless Networking 3 10-29-2009 08:19 PM
microphone works in oss but not in alsa galle Linux - Hardware 3 03-15-2007 10:00 AM
usb microphone storywizard SUSE / openSUSE 0 08-16-2006 11:00 PM
Microphone not working with oss linuxmandrake Linux - Hardware 0 11-08-2005 11:06 AM
Laptop with KDE- OSS/ALSA - seeks help High-gain Linux - Laptop and Netbook 2 12-20-2004 04:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration