f2e-spec
f2e-spec copied to clipboard
Invalid sample rate when trying to use Webcam's microphone
Do you want to request a feature or report a bug?
Bug
What did you do?
pasuspender performous- in GUI select USB webcam as a microphone input
- get error: Some device failed to open
- on CLI read:
audio/error: Audio device 'dev="USB Device 0x46d:0x9a4: Audio" mics=green': Pa_OpenStream failed: Invalid sample rate
Output of performous --version: (What version of Performous are you using?)
Performous 1.1+
What is your environment & configuration (arguments, platform, ...)?
- Ubuntu 18.04.1 LTS
- Webcam Logitech QuickCam E 3500
cat /proc/asound/card0/usbmixer
USB Mixer: usb_id=0x046d09a4, ctrlif=2, ctlerr=1
Card: USB Device 0x46d:0x9a4 at usb-0000:00:1a.0-1.4, high speed
Unit: 5
Control: name="Mic Capture Volume", index=0
Info: id=5, control=2, cmask=0x0, channels=1, type="S16"
Volume: min=6080, max=8768, dBmin=2375, dBmax=3425
Unit: 5
Control: name="Mic Capture Switch", index=0
Info: id=5, control=1, cmask=0x0, channels=1, type="INV_BOOLEAN"
Volume: min=0, max=1, dBmin=0, dBmax=0
cat /proc/asound/card0/stream0
USB Device 0x46d:0x9a4 at usb-0000:00:1a.0-1.4, high speed : USB Audio
Capture:
Status: Stop
Interface 3
Altset 1
Format: S16_LE
Channels: 1
Endpoint: 6 IN (ASYNC)
Rates: 16000
Data packet interval: 1000 us
Can you try and check whether it's actually our problem and not portaudio's?
according to http://portaudio.com/docs/v19-doxydocs/api_overview.html this can very well be the case:
PortAudio doesn't provide sample rate conversion if you request a sample rate that is not supported by the native audio API
i wonder if it's possible to workaround this by editing asoundrc.
libswresample provides resampling...
the error message is coming from SetApproximateSampleRate defined in portaudio as @Lord-Kamina suggested. recompiling portaudio changing RATE_MAX_DEVIATE_RATIO 100 to RATE_MAX_DEVIATE_RATIO 1 in portaudio/src/hostapi/alsa/pa_linux_alsa.c makes the error go away at the cost of pitch detection going off by half-tone approximately. this makes the webcam microphone practically unusable.
personally I wouldn't want to use a webcam microphone. a webcam mic is a condensor mic designed to pick up the entire room at not-so-great audio quality (it's mainly for phone calls, if you can be understood it's good enough). so it will pick up the music causing it to be even more inaccurate.
I'd advice you to get a nice cheap dynamic microphone like the behringer XM8500, and a cheap USB audio interface for it (something like this or this) this will give you far greater accuracy. also a dynamic mic only captures whats straight in front of it, so it will filter out all environment noise.
thanks for the tip. my current setup is internal hda intel (realtek alc888) soundcard + external usb axagon 7.1 soundcard (https://www.axagon.eu/en/produkty/ada-71). first microphone is of logitech webcam c525, the 2nd is philips sbc me570. nothing fancy but it works pretty reliably and there's really nothing to complain when it comes to responsiveness or detection accuracy.
having the 3rd microphone working would be just a nice bonus. also performous advertises itself as being 'usable even with laptop or webcam microphones'. for c525 i fully agree but not so much when it comes to quickCam e 3500 or my really ancient logitech quickzoom webcam.
another idea is to filter out input devices not capable of providing streams near 44.1 kHz in the devices menu.
or we should use avresample for devices that can't go near 44.1kHz. and yes theoretically you could use a webcam mic. but being able to use one doesn't mean you should.

Something I thought I'd mention, if you want something cheap I very much recommend something like the Samsom R21S (Pretty decent Shure clones that are sold in packs of three.) you can connect them to a singstar adapter or something fancier if you like. There was a pretty basic external interface on amazom that looked very good.
it would be great to collect all singing equipment tips and put it into wiki section. it will be far more visible than here. btw reading through the wiki i've stumbled across the following on https://github.com/performous/performous/wiki/Audio-configuration:
rate - Sample rate in Hz. Default is 48000.
surely enough it's not doing anything (but showing the old error again) so i don't really if this key has any meaning at all nowadays.
so an audio equipment wiki? sounds like a plan! I do think i should make it have 3 categories basic, advanced and over-the-top I'm in that last category :confounded: I have an X32 producer with SD8 stagebox and 14 microphones.... the equipment is capable of 38 mic's at once.....
edit: made a first version, feel free to edit: https://github.com/performous/performous/wiki/Audio-equipment-guide
wiki page looks very nice, i will add my notes directly to it as commens/documentation page is not supported.
back to the issue. i have decided to test my current setup with ultrastardx and after initial hurdles i've come to the point where all 3 inputs - that is including the problematic webcam works. interesting thing to mention is that ultrastardx also depends on portaudio so they somehow managed to deal with different sample rates (maybe thanks to sdl2 libs?)
i'll place the quick answers here, will integrate it in the audio guide later:
Q: what is a "SingStar adapter" and will it work in Linux?
Singstar was a karaoke game for the playstation 2, it came with an USB audio interface (3,5mm mono jack to USB) and 2 microphones, performous is originally built to support this.
Q: let's say I am fine with not echoing my voice how do these USB interfaces work?
An USB interface basically takes any analog audio source and converts it to USB. when plugging it into your PC it will appear as a second sound card, which you can use to record and playback audio over. All analog is basically the same, you can convert any analog audio plug to another one through adapters.
Will I get another capture-only USB soundcard?
don't know how to answer this, it basically depends on how many microphones you want to hook up to a pc. also the xenyx 302USB is not capture only. it has 1 playback channel.
How's the support of operating system?
While I do reccommend checking the compability online, most, if not all USB audio interfaces are configured as HID (Human Interface device) which means they follow the USB standard and are supported by all operating systems. while I didn't test all sound cards I did test these, and they work perfectly with linux: Sweex 7.1CH USB sound card anything behringer (X802USB, X2442USB, X32) _> they even state on their site they officially support it. usually they have a single driver download for windows and a message that mac/linux don't need drivers. hercules DJ RMX MK2 (DJ panel with build-in sound card)
keep in mind that pro-audio is more mac-oriented than windows since WASAPI is pretty shitty. and in my experience, anything non-apple that works on a mac, works on linux.
Will using Linux make me feel like a 2nd class citizen?
absolutely not, linux has some of the best pro-audio tools out there, ever heard of JACK(Jack audio connection kit)? it allows you to route any audio source (from a sound card or application) to any output (be it a program or some speakers)
JACK is a bit hard to set up, but it does allow you to echo your mic to your speakers without much delay or distortion, something performous can't do on it's own.
there's even a distro called ubuntu-studio, completely focussed on pro-audio.
Here's a shot with my X32 Producer connected to JACK:

Q: why do I need USB input?
sorry my bad, USB out for the mixer, USB in for the PC. already answered driver support.
thank you, finally getting a grip of it now :-) one thing that is still a bit unclear to me
Keep in mind that most of these mixers only have a single stereo USB output (if any) so they may still require additional USB audio interfaces if you plan to use performous' pitch recognition.
a single stereo USB output still allows me to route two microphones (2x mono) into performous for analysis, right?
this might sound confusing, so you might need to see this at first: https://www.youtube.com/watch?v=S-ue9wdvcpE https://www.youtube.com/watch?v=9BWj8gQNdT0
a single stereo USB output still allows me to route two microphones (2x mono) into performous for analysis, right?
technically yes, practically no.
I've only had experience with the xenyx X2442USB in this regard, what it did was pretty lame:
it had a 2-track in/output (RCA) the 2-track out just mirrored the main mix, the 2tr-in could be routed to either the main mix or to your headphones, nothing else, and it had no volume knob so I used to use my laptop's headphone jack and just used a cable to connect it to a standard mixing channel.
fragment from the manual:

what the USB did was route these 2 connection points to your PC. your PC will see a sound card with stereo input (main mix of the mixer) and stereo output (which goes to the 2tr channel)
so you can send 2 mics to this USB recorder, for this you have to use the PAN knob:
if you put 1 knob completely to the left, and one completely to the right, you basically have a 2 channel recording.
well why you don't want this:
since the USB recorder is your main mix, if you also route your music through here you're recording your stereo music on top of your mono microphones, this can be solved by jumping through hoops like for example routing your music/mics to a subgroup and connecting your speakers to that but it's far from ideal. the best way to fix this is to use a direct output:

A direct output basically takes the result from a single channel strip and outputs it to there, so you have only the microphone sound after amplification and equalization. then you can use a USB recorder to record this signal for performous' pitch recognition while keeping the main mix for your speakers.
i am clearly missing something. on one hand you are saying usb interface is a must for pitch detection to work, on the other you're making it clear i don't want to use it because it's mixed with music track. instead i should route direct output ports into performous. but how? do i need to use a usb port with that many line-ins? or is a usb recorder another hw device that goes between a mixer and a pc?
whether it's mixed with the music track all depends on how you connect your mixer. you can use a mixer with USB functionality as an audio interface (use panning) but then it's the same as a normal usb audio interface: you can't echo your voice over the speakers, which defeats the whole purpose of a mixer. if you want to echo your voice over the speakers AND have pitch recognition you need an audio mixer to mix the music through your own voice (which is why you have a mixer) and find some way of seperately recording the microphone channels to your PC like so:

follow the arrows to see the sound path. as mentioned in my previous post, this particular board (x2442) has an USB soundcard but it's pretty lame. this board does have direct outputs which you can use with seperate USB audio interfaces. that's why I recommend something like a XENYX UFX1604 or a digital mixer since they record ALL channels over USB (so you can simply select your mic in performous without using direct-outputs and other sound cards) but I'm well aware that these mixers come at a pretty steep price.... (UFX1604 = €300,- and an x32 is €1200,-)
Most of this stuff is a little difficult to explain by text. it's usually easier to just take someone to one of our karaoke sessions and show them how it's all set-up.
i really appreciate your patience in doing this 'for dummies' (=me) tutorial. the first thought when i saw usb next to mixer name was: okay, so i can use this to output mics to PC. turns out that this is possible but only with $500+ (UFX1604 on amazon is $599) mixers, usually you'll use it to send music track from performous to mixer. fair enough.
in your diagram - red colour. when you say "These channels should go to your PC". then what you have in mind is a PC soundcard with a ideally more than one mic input, right? most cards i was able to find only support 2 mics input so for more than two players you're going to have to go for multiple cards.
that basically means that for if your goal is mixing voices with music and pitch recognition you basically have these options:
- microphone pass-through cheap but laggy, not recommended
- basic mixer (with or without USB - you can still send music track from performous via line-in) with direct output for each microphone may require multiple soundcard as mic ins are pretty scarcely found on soundcards
- more advanced (+ more expensive) mixer with multitrack USB outputs
maybe we could extend wiki with approximate costs for each solution
"These channels should go to your PC". then what you have in mind is a PC soundcard with a ideally more than one mic input, right?
yeah, most soundcards only have 2 inputs, but it doesn't really matter, you can stack multiple cards extending your pc's inputs as much as you like. must usb audio interfaces have a combined XLR/JACK input so with a 6,35mm JAC-JACK cable you can easily dump any output channel there from your mixer.
the cheapest mixer setup with pitch analysis is probably the behringer Xenyx 1002b with possibly a single USB sound card. the 1002b has 2 aux-sends/fx-sends which can be used as "direct out" for 2 microphones.
aux sends / fx-sends (different mixers use different labels but they're practically the same) are basically seperate mono mixes, used for on-stage speakers, but when you only route 1 channel to an fx-send it basically behaves like a direct-out with a volume knob. connect those to your pc's line-in or a USB sound card and you're done.
really appreciate your patience in doing this 'for dummies
no problem, mixers are for most people pretty overwhelming, but they're actually pretty easy to understand. most mixers have a 100+ knobs, but most of those knobs have the same functions, only for different inputs or outputs. once you get how sound is routed through the board, you start to understand that you basically only have to learn 10 different "knob functions" to understand the entire board. It takes a while before you get it :wink:
based on your suggestion i went into Behringer 1002b, added 2x Numark WM200 Dj microphone. i am quite happy with this setup although a few open questions remain:
- what's the difference between master-out and 2-track output (besides the connectors)?
- on sound-card how safe is it to feed mic input with line-out and vice versa? or is this just about the level of interference?
- also is it okay to plug a piano keyboard output into xlr microphone input on mixer?
what's the difference between master-out and 2-track output (besides the connectors)?
short answer basically nothing. long answer: 1002b is a bit of an exception in this regard, it routes the 2tr input to a full channel (9/10) normally (like on a xenyx 802) it only comes with 2 buttons, "2tr-to ctrl room" and "2tr to main" when pressing "2 tr to main" it isn't echoed over the 2tr out. but again this does not apply to the 1002b.
on sound-card how safe is it to feed mic input with line-out and vice versa? or is this just about the level of interference?
oh it's completely safe, you just need to make sure the levels are correct.

you should amp it in a way that when you scream really loud into the mic, it stays 1 or 2 bars below it's maximum. also it's better to amplify on the mixer than on the PC. to avoid any signal noise you want as much voltage through those lines as possible without distorting the sound. (see https://en.wikipedia.org/wiki/Clipping_(audio)) this way your signal-to-noise ratio will stay nice and low.
also is it okay to plug a piano keyboard output into xlr microphone input on mixer?
you could do that but I'd recommend using the line in 1/4" JACK. the XLR socket has a microphone pre-amp in front of it which you have to turn down completely to avoid clipping. the 1/4" jack however, bypasses the mic amp meaning it will be "normal line level"
did you know you can use the MON send and FX-send as outputs for your PC's sound card?
aand thank you, again. yes, i am using MON send and FX-send to feed line-in and let performous do the pitch analysis as you suggested before. i do not really want anything but the microphone signal to go there.
i think the issue is coming to an end. to summarize a little bit:
- using microphones integrated into webcams for performous is a bad idea (reasons outlined in the audio guide wiki entry) and having these devices report sample rates distant from 44/48 kHz is just another warning
- if user really insists on using them and performous reports an "invalid sample rate" error, ultrastar dx may be a way to go
- a single dynamic microphone is a sane minimum, if you want more karaoke feel get a mixer (and maybe bigger screen and speakers too) - tips in wiki again
thank you all involved for providing response - i learned quite a lot in the process. if nobody else has nothing to add, i'd close the issue soon.
here's a workaround that worked for me. may serve in cases where user wants to test such setup or has no other option at hand.
- disable pulseaudio
systemctl --user mask pulseaudio.socket pulseaudio --kill - plug in webcam and find out its hw address
here the address iscat /proc/asound/cards 0 [Intel ]: HDA-Intel - HDA Intel HDA Intel at 0xfdff8000 irq 30 1 [NVidia ]: HDA-Intel - HDA NVidia HDA NVidia at 0xfcffc000 irq 17 2 [C525 ]: USB-Audio - HD Webcam C525 HD Webcam C525 at usb-0000:00:1a.7-1, high speed 3 [U0x46d0x8b3 ]: USB-Audio - USB Device 0x46d:0x8b3 USB Device 0x46d:0x8b3 at usb-0000:02:00.0-1.1, full speedhw:3 - install and run jack audio connection kit + qjackctl
- run
alsa_inpassing it the alsa address of webcamalsa_in -d hw:3 -c 1 -j webcam - run performous and set both input and output audio device to
system - in Connections window of qjackctl link webcam -> capture_1 output port with PortAudio client's (performous) in_0 input port.

- in
alsamixerlower mic sensitivity (minimum setting worked for me) - use headphones if possible
Searching for an answer on how to fix this 'error'. Our config.xml supports that you supply the samplerate. So for example if you configured your samplerate of an audio device to be 44100Hz you'll get an invalid sample rate exception as Performous is trying to open the device with 48000hz per default. This is a mismatch and thus leading to the error.
In our config.xml you can supply some stringvalues for audiodevices like this:
<entry name="audio/devices" type="string_list">
<stringvalue>dev="YourDeviceNameAsRegocnizedByPerformous" out=2 in=2 rate=44100</stringvalue>
</entry>
So now performous knows it needs to be opened with 44100Hz. It's not ideal but it's a work around.
Reopening this issue as it's still a thing within the latest master. Tested on Windows. The workaround is described above
TODO
- [ ] Figure out a way to use the OS applied samplerate of the device.
- [ ] Change https://github.com/performous/performous/blob/master/game/audio.cc#L464 to be dynamic based on OS provided samplerate
- [ ] Change https://github.com/performous/performous/blob/master/game/audio.hh#L137 to be dynamic based on OS provided samplerate