audacity sometimes won't start when devices change

This section is now closed.
Forum rules
Audacity 1.3.x is now obsolete. Please use the current Audacity 2.x.x package for your distribution or compile Audacity from the source code.
bgravato
Posts: 2098
Joined: Wed Jan 13, 2010 8:56 pm
Operating System: Linux Debian

audacity sometimes won't start when devices change

Post by bgravato » Thu Apr 01, 2010 6:35 pm

Problem: sometimes audacity won't start if the devices change since last time I was using it.

I'm using audacity 1.3.11-beta on Debian lenny/squeeze/sid (mostly squeeze I think).
I have two internal soundcards (motherboard's built-in soundcard and pci-e asus xonar essence stx).
Sometimes I have an external usb preamp connected (art usb dual pre)
Sometimes I'm running jackd, sometimes I'm not.

Sometimes (in a bit erratic way) audacity won't start and I get messages such as this:

Code: Select all

$ audacity
audacity: pcm_plug.c:388: snd_pcm_plug_change_channels: Assertion `snd_pcm_format_linear(slv->format)' failed.
Aborted
In audacity device configuration options I sometimes use alsa as playback device, sometimes I use jack, sometimes the usb device. For recording device it's usually the usb device but I might use different one occasionally.

I usually work around the problem by connecting the usb device if it's not connected before starting audacity. Or I'll start/stop jackd before starting audacity. It has happened sometimes that I have jackd running and I have to stop it to be able to start audacity. Sometimes jackd is not running and I have to start it to be able to start audacity... I think this thing with jack is probably related to .asoundrc configuration, which I sometimes change too. Sometimes I have jack as default device for sound and sometimes I have alsa as default. To add a bit more of awkwardness to my setup the hw number of the soundcards often change between reboots... For example Xonar sometimes is hw0, sometimes it's hw1, and sometimes might even be hw2 (if I have the usb device connected at boot time...)

All this constant changes drive me crazy so I guess they might drive audacity crazy too sometimes and it will refuse to start if it can't find any proper device for playback/recording...
Include as much details as you can in your post (Audacity version, Operating System, Equipment used, etc).
Please post your question in the appropriate forum (regarding audacity version and operating system).

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: audacity sometimes won't start when devices change

Post by steve » Thu Apr 08, 2010 4:45 pm

Audacity saves the last used sound card settings in the audacity.cfg file.

Here's an extract from my current set-up:

Code: Select all

[AudioIO]
RecordingDevice=ALSA: default
Host=ALSA
PlaybackDevice=ALSA: default
RecordChannels=2
This is using ALSA through PulseAudio.
PulseAudio is controlling the "default" devices, so while I'm using PulseAudio I can leave the Audacity settings just like this and only need to make the appropriate changes in PulseAudio mixer.

I have 2 sound cards attached to this computer - the internal sound card and a USB sound card.

If I want to change the playback or the recording device that Audacity uses, I could explicitly set the device in Audacity Preferences (Edit menu > Preferences > Devices", but if I do that it could cause problems the next time I launch Audacity. For example, if I set Audacity Preferences to use "hw:1.0" (the USB device) for playback, but then the next time I launched Audacity I did not have the USB device connected - Audacity would be unable to find the playback device (because it's not there).

Instead of doing that, I leave Audacity set to record from "ALSA: default". Here's the method that I use:

To change the playback device:
1) Launch Audacity.
2) Import or generate some audio data.
3) Play > Pause.
4) Open "PulseAudio Volume Control" and in the Playback section "Move Stream" to the required device.
5) STOP Audacity playback (important)
6) Press PLAY on Audacity - it is now using the new device.

To change the recording device:
1) Launch Audacity.
2) Click on the Record Monitor to start monitoring.
3) Open "PulseAudio Volume Control" and in the Record section "Move Stream" to the required device.
4) Click on the Record Monitor to stop monitoring (important).
5) Start recording with the new device.

I hope this works as well on your computer as it does here - simple, no fuss, reliable.

Now the sticking point - switching to/from Jack audio.

This is a lot more problematic. I've been playing with Jack-enabled PulseAudio on Ubuntu 10.04 (alpha/beta).
In theory this will make switching to Jack just as easy as the above method, but unfortunately I've not managed to get it to work yet :(
To be fair - this is still quite experimental, and I'm trying to run it in a virtual machine using a real-time kernel that is not officially supported by VirtualBox.

Hopefully when Ubuntu 10.04 is officially released and I'm running on real, not virtual, hardware, I'll have more success, but for now, like you, I'm stuck with clumsy workarounds.

As far as I can tell, the problem is that Jack is not (currently) supported by PulseAudio in Ubuntu (9.04/9.10), and both sound servers want exclusive access to the audio device. For Jack to work, it must suspend PulseAudio. So, you start Jack, then open Audacity - it's looking to connect to ALSA through PulseAudio, but it can't because it's been suspended. This gives you two options - either you go into Audacity Preferences and specify explicitly which audio device you want to use (for example "hw:1,0"), or you set Audacity to use Jack. Either way you need to be careful - if Audacity tries to use a device that is not available it will probably lock up or crash.

My current method for switching to Jack:
1) Open Audacity and check the default sample rate, then close Audacity.
2) Start Jack with Jack Control, ensuring that the same sample rate is set.
3) Open Audacity and set the host to Jack.
4) Press the Record button - Jack should automatically connect Audacity's Pulse Audio inputs to the system inputs (clicking on the monitor will crash Audacity because connection to a recording device has not yet been established).
5) Open "Connect" in Jack Control to check that Audacity is connected as expected.

My current method for switching back from Jack to PulseAudio:
This is all with Jack NOT running.
1) Open Audacity
2) In Audacity Preferences select Host:ALSA, Devices: default
3) Restart Audacity

The thing that gives me hope is that this all works very much better than it did a year ago. Jack, PulseAudio, Portaudio and Audacity are all maturing technologies. It looks like it will be PulseAudio that finally pulls all the threads together - it would just be nice if they could get there a bit quicker ;)
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

bgravato
Posts: 2098
Joined: Wed Jan 13, 2010 8:56 pm
Operating System: Linux Debian

Re: audacity sometimes won't start when devices change

Post by bgravato » Thu Apr 08, 2010 9:10 pm

Thanks for the reply steve.

I've never used pulseaudio, but maybe I should give it a try...

I need JACK for idjc (internet dj console), a djing software I use for icecast streaming (and on-the-fly mixing).

I also wish debian would upgrade jack version... they still using a very old version of it (even in sid), which sometimes causes me some troubles that I haven't figure out yet how to solve other that stop/restart jackd... I just checked today and there's a more recent version of jack on debian's experimental branch, so maybe I'll give it a try soon...
Include as much details as you can in your post (Audacity version, Operating System, Equipment used, etc).
Please post your question in the appropriate forum (regarding audacity version and operating system).

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: audacity sometimes won't start when devices change

Post by steve » Fri Apr 09, 2010 2:34 am

The trouble with this kind of thing - they go deep into the system. It's not easy to just add in PulseAudio (and take it out again if it doesn't suit you) unless you really know what you're doing.

I had Jack running with ALSA on my (virtual) test machine running really sweetly, but then completely *@!%cked up jack when I added PulseAudio. Fortunately it was not on my main system, so I can just reinstall - I'm going for a vanilla Gnome/Ubuntu 10.04 with Jack this time (just to see what happens).

Now that I'm getting the hang of it I can say that PulseAudio is good - very good - but make sure that you have everything backed up before you try.

What is it they say about Linux on "DistroWatch"? ... "Put the fun back into computing" :D
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

bgravato
Posts: 2098
Joined: Wed Jan 13, 2010 8:56 pm
Operating System: Linux Debian

Re: audacity sometimes won't start when devices change

Post by bgravato » Fri Apr 09, 2010 10:47 am

Like some ppl might say... Backups? Nah... I prefer to live on the edge!

I've been "playing" around with linux for the last 12 years or so... (personally and professionally) I think I can say I have a fairly good knowledge of how the system works... So I might take the chance of messing up my main system a little more than it already is :)

One thing that has always been a bit of a mystery to me in linux is the way sound works... ALSA/OSS/JACK/PulseAudio/etc... you got so many drivers/architectures that it can drive you crazy... but I'm starting to get the hold of it now, things also seem to start to mature a bit more now, so I guess it's about time to dig deeper into it...

Next week I should be able to post my findings about PulseAudio.
Include as much details as you can in your post (Audacity version, Operating System, Equipment used, etc).
Please post your question in the appropriate forum (regarding audacity version and operating system).

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: audacity sometimes won't start when devices change

Post by steve » Fri Apr 09, 2010 6:17 pm

bgravato wrote:I've been "playing" around with linux for the last 12 years or so... (personally and professionally) I think I can say I have a fairly good knowledge of how the system works...
You shouldn't have told me that - I'll be picking your brains now :D
bgravato wrote:One thing that has always been a bit of a mystery to me in linux is the way sound works...
You're certainly not alone there - I think everyone finds it a mystery. OSS4 seems to be the most straightforward option, but has less hardware support than ALSA and looks to be more limited for music production - the licensing terms may also be a bit problematic for the major Linux distros.

I look forward to reading your findings on PulseAudio.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

bgravato
Posts: 2098
Joined: Wed Jan 13, 2010 8:56 pm
Operating System: Linux Debian

Re: audacity sometimes won't start when devices change

Post by bgravato » Fri Apr 09, 2010 11:35 pm

stevethefiddle wrote:You're certainly not alone there - I think everyone finds it a mystery. OSS4 seems to be the most straightforward option, but has less hardware support than ALSA and looks to be more limited for music production - the licensing terms may also be a bit problematic for the major Linux distros.
Once upon a time... there was OSS... and OSS was the (only) way to go... Then we started to hear about ALSA... Then all of a sudden (well maybe not so sudden) ALSA was the way to go... Then there was EsounD, there was aRts, there was JACK, there was PulseAudio, there was...
Include as much details as you can in your post (Audacity version, Operating System, Equipment used, etc).
Please post your question in the appropriate forum (regarding audacity version and operating system).

bgravato
Posts: 2098
Joined: Wed Jan 13, 2010 8:56 pm
Operating System: Linux Debian

Re: audacity sometimes won't start when devices change

Post by bgravato » Sun Apr 11, 2010 11:42 pm

Steve I just found out I already have pulseaudio installed and running... hehe that might explain the two volume control applets on my gnome toolbar... :)

I'll be taking a look at it's configuration and see what I can figure out about it :)
Include as much details as you can in your post (Audacity version, Operating System, Equipment used, etc).
Please post your question in the appropriate forum (regarding audacity version and operating system).

bgravato
Posts: 2098
Joined: Wed Jan 13, 2010 8:56 pm
Operating System: Linux Debian

Re: audacity sometimes won't start when devices change

Post by bgravato » Mon Apr 12, 2010 10:40 pm

Looks like pulseaudio was only being used by apps that would try to send the audio through esd...

I didn't have pavucontrol installed so I did and I found out that I can select if the input on the xonar is line-in or mic... which I couldn't with any other mixer I tried before (not even alsamixer... so I thought it wasn't supported by the alsa drivers... but apparenty it is...), so that pleased me much :)

Still I don't think I can connect my jack apps (such as idjc) to pulseaudio, but it seems that there's a module to send pulseaudio output to jack... for what I do and my needs I think jack suits me better and is more powerful...

My only problem with jack is that sometimes the playback output sometimes gets all messed up with lots of noise, I haven't found yet why or haven't been able to find a way to reproduce it... I tried to stress it feeding many playback sources to jack now but couldn't break it... but once in a while it does happen (for no apparent reason...)
This problem only affects the playback output, because if I'm streaming and I connect to the stream from other computer the sound is fine... only locally the output audio is all broken... which suggests me this might be some issue regarding the jack-alsa connection and possibly related to sample rate? well just kind of randomly guessing here...
Include as much details as you can in your post (Audacity version, Operating System, Equipment used, etc).
Please post your question in the appropriate forum (regarding audacity version and operating system).

steve
Site Admin
Posts: 81627
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: audacity sometimes won't start when devices change

Post by steve » Mon Apr 12, 2010 11:12 pm

bgravato wrote:I found out that I can select if the input on the xonar is line-in or mic...
Great stuff :D
bgravato wrote:it seems that there's a module to send pulseaudio output to jack...
That's what I've been trying to get working on my virtual test machine - not the best test bed for this kind of thing - no joy so far. I'll start a new topic about it if I get it to work.
bgravato wrote:for what I do and my needs I think jack suits me better and is more powerful...
I use jack on my desktop machine for that same reason, but find the versatility of PulseAudio indispensable on my laptop.
I had trouble getting Audacity to work properly with Jack for years, but now it works great - just wish we had persistent ports rather than ones that disappear every time you click stop.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Locked