Audacity records at wrong clock rate

Audacity 2.0.3 on Linux is recording — or playing back — at the wrong clock rate, resulting in faster-than-normal playback. I verified this by timing a recording session of streaming audio (a YouTube video) of known length with a stopwatch. The length of the recording as shown by Audacity was several seconds shorter than the actual time of the source material. By noting the time difference, I was able to work out the speed ratio. Using this information, I was able to use the Effect / Change speed… tool to slow down the recording so that the pitch sounded normal again, i.e, the same as the source material, and the length of the recording matched. By experimenting I found I need to change the playback speed -8.125%, which precisely matches the difference between a clock rate of 48 kHz and 44.1 kHz. In all cases the play-at-speed control was set to 1.000.

If I set the Project Rate (lower left corner of main window) to 48000 Hz, I capture a 60 second stereo recording at 48000 Hz that ends up about 3 seconds short on Audacity’s track time scale once I stop recording. If I play back this capture, the tempo is too fast and the pitch is too high. Also, the rate in the track window shows 48000 Hz, the same as the project rate during the recording. If I then open the track menu and in the Set Rate item change the sampling rate to 44100 Hz, the time scale is instantly corrected to the same as the source material and the pitch and tempo sound normal. I can then proceed to export the track as a WAV or MP3 file and it sounds as it should with any other player.

This should not be so. :imp: If one records something with Audacity with the play-at-speed set to 1, it should play back precisely as it sounded originally, without having to apply a speed or sampling rate change, which may introduce sampling errors and distortion in the waveform.

Any ideas how to fix this? Is it a bug in Audacity?

You are quite right, that should not be so.

Audacity 2.0.3 has not been released yet. Do you have an alpha version installed? If so, did you build it from the source code or where did you get it?
Alpha versions are not recommended for production work, though we do like to hear from people that are testing them.

Which version of Linux?
What sort of sound card?
Are you using PulseAudio?
Are you using Jack?

I’m running Ubuntu Linux 10.04 LTS “Lucid Lynx”. The Lucid Lynx repository offers only Audacity 1.3.12-2. I recall seeing on the Audacity site that the 1.x series is no longer supported, and since I was seeing various issues with it went looking for a 2.x release in .deb format that I could install. Not being able to readily find a .deb installer backport for Ubuntu 10.04, I decided to try compiling in place from source code, which I succeeded in doing. At the moment I’m not quite sure how I ended up with Audacity 2.0.3-alpha-Sep 12 2012, except that it came from the Audacity site.

I now have Jack installed, but when I first noticed the problem in Audacity, I didn’t. Jack was installed only last week while I was fiddling with trying to get Rosegarden to play back MIDI files. I start Jack manually to run Rosegarden, but when I’m finished I shut down Rosegarden and Jack manually. Anyway, with Audacity running, System Monitor doesn’t show any process named “jack” running, so I don’t think that’s an issue.

I’m not quite sure what the sound card or sound subsystem is. The machine is an IBM ThinkCentre M51 type 8145-KUF with embedded sound subsystem on the mainboard that I bought used from an industrial distributor sans owner’s manual. I just recently pressed it into service when my Shuttle XPC bit the dust, so I’m still not fully familiar with it.

The System Monitor does show that “pulseaudio” is running. That must have been installed by default from the Live CD when I set up Ubuntu on this machine.

You would probably be best to use the release version - the source code is available here: http://code.google.com/p/audacity/downloads/detail?name=audacity-minsrc-2.0.2.tar.bz2&can=2&q=linux

Now that you have successfully built Audacity once, building it again should be easy.
I’d suggest that you uninstall your current version first - in a Terminal window, navigate to the folder where your existing source code is, then enter:

sudo make uninstall

Then unpack the new source files into a new folder (anywhere convenient).
Navigate to that folder in a terminal window.
Enter the following commands:

./configure



make

The “make” should complete with no errors.

Check that it has built correctly by typing:

./audacity

If Audacity runs, shut it down and install:

sudo make install

Before you launch Audacity, let’s remove your old configuration files.
Go to ~/audacity-data/ and delete the file audacity.cfg

Launch Audacity.
Set the recording input and the playback output to “default” and try recording something. The project rate will be 44100 Hz by default.

As a binary, it did not come from http://audacityteam.org/ .

There is a bug open that alleges the reverse case (records too slow, but the difference is again explained by the ratio between 44100 Hz and 48000 Hz):
http://bugzilla.audacityteam.org/show_bug.cgi?id=585 .

I’m quite sceptical at the moment because another audio recording application on his machine has the same fault (and I cannot reproduce the problem yet on an Ubuntu 12.04 netbook but I have not tried hard as I use Windows for actual work).

Have you tried Ardour or some other recording app? If the sound device is recording (or playing) at the wrong clock speed, then Audacity will do so. Retest in Audacity after quitting Audacity and deleting audacity.cfg as Steve suggests.

Can you also post the information from Help > Audio Device Info as that may show some light on the rates PortAudio thinks your device supports.

Now, the bug reporter’s apparent workaround to record at the correct length is:

  1. Set Project Rate to 48000
  2. Tracks → Add New → Stereo Track
  3. Set Project Rate to 44100
  4. Record

He says simply launching Audacity, setting the project rate to 48000 Hz rather than 44100 Hz then recording does not help (nor should it with a correctly functioning device that supports both rates).

But if the workaround works, that worries me a little (making the same assumption about the device). 48000 Hz project rate should record at 48000 Hz and the same length into a new track, whether a track is present at another rate or not.

I wonder if he means he is append-recording into the same track (SHIFT + R)? And what should happen in that case? In current HEAD (Windows or Linux), if the project rate exceeds the track rate, append recording sees the cursor move at the correct speed, but the recorded waveform gets in advance of the cursor so records an excessive length. The reverse is true (recording too short) if the project rate is less than the track rate being recorded into. This isn’t new - it exists in 1.3.6 too.

This is not an issue for me on Windows or Linux if I record into a new track at a project rate different to that of an existing track on the screen.

Leaving that to one side for now, can you please test what happens if you try the workaround suggested in the bug report, but in reverse:

  1. Set Project Rate to 44100
  2. Tracks > Add New > Stereo Track
  3. Set Project Rate to 48000
  4. Record

Do you record at the correct speed?



Gale

Thanks for the link. I was having difficulty finding evidence that anyone else was seeing this problem.

Other than Audacity, I’ve been able to record streaming audio with a simple utility called “outRec”, a GUI (Graphical User Interface) written in Gambas for the “pa-clone” script. The utility works quite well for capturing “What-You-Hear”, and the WAV files that it produces play back at the correct tempo and pitch with Totem Movie Player, outRec, OcenAudio, Audacious, Audacity, Rhythmbox, etc. I prefer not to use it, though, because in its current state it lacks input gain controls and level meters, and the resulting recordings are at a low level, requiring post-processing with an audio editor to bring the levels up. This numerical amplitude scaling of low-level recordings introduces errors that I’d rather avoid for maximum recording quality, due to limited numerical resolution inherent in digitized waveforms.

The menu reports the following:

==============================
Default capture device number: 6
Default playback device number: 6
==============================
Device ID: 0
Device name: Intel ICH6: Intel ICH6 (hw:0,0)
Host name: ALSA
Input channels: 2
Output channels: 0
Low Input Latency: 0.011610
Low Output Latency: -1.000000
High Input Latency: 0.046440
High Output Latency: -1.000000
Supported Rates:
==============================
Device ID: 1
Device name: Intel ICH6: Intel ICH6 - MIC ADC (hw:0,1)
Host name: ALSA
Input channels: 2
Output channels: 0
Low Input Latency: 0.010667
Low Output Latency: -1.000000
High Input Latency: 0.042667
High Output Latency: -1.000000
Supported Rates:
==============================
Device ID: 2
Device name: Intel ICH6: Intel ICH6 - MIC2 ADC (hw:0,2)
Host name: ALSA
Input channels: 2
Output channels: 0
Low Input Latency: 0.010667
Low Output Latency: -1.000000
High Input Latency: 0.042667
High Output Latency: -1.000000
Supported Rates:
==============================
Device ID: 3
Device name: Intel ICH6: Intel ICH6 - ADC2 (hw:0,3)
Host name: ALSA
Input channels: 2
Output channels: 0
Low Input Latency: 0.010667
Low Output Latency: -1.000000
High Input Latency: 0.042667
High Output Latency: -1.000000
Supported Rates:
==============================
Device ID: 4
Device name: Intel ICH6: Intel ICH6 - IEC958 (hw:0,4)
Host name: ALSA
Input channels: 0
Output channels: 2
Low Input Latency: -1.000000
Low Output Latency: 0.010667
High Input Latency: -1.000000
High Output Latency: 0.042667
Supported Rates:
    48000
==============================
Device ID: 5
Device name: pulse
Host name: ALSA
Input channels: 32
Output channels: 32
Low Input Latency: 0.011610
Low Output Latency: 0.011610
High Input Latency: 0.046440
High Output Latency: 0.046440
Supported Rates:
    8000
    9600
    11025
    12000
    15000
    16000
    22050
    24000
    32000
    44100
    48000
    88200
    96000
    192000
==============================
Device ID: 6
Device name: default
Host name: ALSA
Input channels: 32
Output channels: 32
Low Input Latency: 0.011610
Low Output Latency: 0.011610
High Input Latency: 0.046440
High Output Latency: 0.046440
Supported Rates:
    8000
    9600
    11025
    12000
    15000
    16000
    22050
    24000
    32000
    44100
    48000
    88200
    96000
    192000
==============================
Device ID: 7
Device name: /dev/dsp
Host name: ALSA
Input channels: 16
Output channels: 0
Low Input Latency: 0.011610
Low Output Latency: 0.000000
High Input Latency: 0.046440
High Output Latency: 0.000000
Supported Rates:
==============================
Selected capture device: 3 - Intel ICH6: Intel ICH6 - ADC2 (hw:0,3)
Selected playback device: 6 - default
Supported Rates:
    48000
Unable to open Portmixer

To be able to record “What-You-Hear” on my machine, I had to select “Intel ICH6: Intel ICH6-ADC2 (hw:0,3) Mix:0” from the menu in the main Audacity window, from a list of 34 options. I can’t say that I’ve tried every source exhaustively, but it took quite a while of trial-and-error to get even one to work. All others that I tried either produced a flat-line recording or caused Audacity to hang. (This shouldn’t be so hard.)

It doesn’t work. When I perform the steps above, then click the Record button in Audacity, it opens a new track at a sample rate of 48000, records a second or so of extremely choppy audio in that track, then recording stops. In fact, it seems I can only record with Audacity when the project window is empty; I click on the Record button, and this action creates a new track window with the Project Rate sampling rate, but with the attendant incorrect, fast tempo and high pitch when played back in Audacity.

It wasn’t easy. In fact, it took close to half an hour to compile and install on this IBM ThinkCentre with 3GHz Pentium processor. I walked away and had lunch while waiting for it to finish. (Thanks for the information on replacing the current installation; I’ll probably make use of it when I do actually update to a stable release, if I’m still running Lucid Lynx and no .deb backport to this Ubuntu release is available.)

I’m inclined to wait before replacing the current 2.0.3-alpha installation, since on 2012-09-28 Per Ångström reported essentially the same issue with 2.0.1-alpha in Bug #585. If the problem is present in 2.0.1-alpha and 2.0.3-alpha, it would seem that the intermediate 2.0.2 release didn’t fix it. Besides, replacing the current installation may just confuse issues, as it introduces a new variable.

Hi, I’m the author of that bug report.

I still don’t know whose fault it is, but almost all of my recordings nowadays are being done at 44,1 kHz while the hardware apparently outputs at 48 kHz, giving rise to recordings that are longer than the recording time and with a noticeable low pitch. I think the problem started when I changed my Linux distribution some time ago, so it’s probably a case of Audacity and the audio subsystem not communicating properly. All my recordings are done using Pulse Audio’s “Monitor of Analog Built-in Stereo”.

I have given up trying to find work-arounds in Audacity, since that’s too error-prone and time-consuming. Instead I use a script I have written that simply rewrites the frequency information directly in the Wave file. That way I don’t have to go through the slow resampling step.

It doesn’t seem to matter whether I’m starting on a fresh recording or appending. I have occasionally been lucky to record at the correct speed, but I haven’t found a repeatable pattern.

Still, I’m surprised that Audacity doesn’t notice that the recording is going at the wrong speed. That other recording application I tested is so simple that I wouldn’t expect anything of it, but I had higher hopes of Audacity.

Here is my device info:

==============================
Default capture device number: 10
Default playback device number: 10
==============================
Device ID: 0
Device name: HDA Intel: ALC262 Analog (hw:0,0)
Host name: ALSA
Input channels: 2
Output channels: 2
Low Input Latency: 0,011610
Low Output Latency: 0,011610
High Input Latency: 0,046440
High Output Latency: 0,046440
Supported Rates:
    44100
    48000
    96000
    192000
==============================
Device ID: 1
Device name: HDA Intel: ALC262 Digital (hw:0,3)
Host name: ALSA
Input channels: 0
Output channels: 2
Low Input Latency: -1,000000
Low Output Latency: 0,011610
High Input Latency: -1,000000
High Output Latency: 0,046440
Supported Rates:
    44100
    48000
    96000
    192000
==============================
Device ID: 2
Device name: sysdefault
Host name: ALSA
Input channels: 128
Output channels: 128
Low Input Latency: 0,042653
Low Output Latency: 0,042653
High Input Latency: 0,046440
High Output Latency: 0,046440
Supported Rates:
    8000
    9600
    11025
    16000
    22050
    32000
    44100
    48000
    88200
==============================
Device ID: 3
Device name: front
Host name: ALSA
Input channels: 0
Output channels: 2
Low Input Latency: -1,000000
Low Output Latency: 0,011610
High Input Latency: -1,000000
High Output Latency: 0,046440
Supported Rates:
    44100
    48000
    96000
    192000
==============================
Device ID: 4
Device name: surround40
Host name: ALSA
Input channels: 0
Output channels: 2
Low Input Latency: -1,000000
Low Output Latency: 0,011610
High Input Latency: -1,000000
High Output Latency: 0,046440
Supported Rates:
    44100
    48000
    96000
    192000
==============================
Device ID: 5
Device name: surround51
Host name: ALSA
Input channels: 0
Output channels: 2
Low Input Latency: -1,000000
Low Output Latency: 0,011610
High Input Latency: -1,000000
High Output Latency: 0,046440
Supported Rates:
    44100
    48000
    96000
    192000
==============================
Device ID: 6
Device name: surround71
Host name: ALSA
Input channels: 0
Output channels: 2
Low Input Latency: -1,000000
Low Output Latency: 0,011610
High Input Latency: -1,000000
High Output Latency: 0,046440
Supported Rates:
    44100
    48000
    96000
    192000
==============================
Device ID: 7
Device name: hdmi
Host name: ALSA
Input channels: 0
Output channels: 2
Low Input Latency: -1,000000
Low Output Latency: 0,011610
High Input Latency: -1,000000
High Output Latency: 0,046440
Supported Rates:
    44100
    48000
    96000
    192000
==============================
Device ID: 8
Device name: pulse
Host name: ALSA
Input channels: 32
Output channels: 32
Low Input Latency: 0,011610
Low Output Latency: 0,011610
High Input Latency: 0,046440
High Output Latency: 0,046440
Supported Rates:
    8000
    9600
    11025
    12000
    15000
    16000
    22050
    24000
    32000
    44100
    48000
    88200
    96000
    192000
==============================
Device ID: 9
Device name: dmix
Host name: ALSA
Input channels: 0
Output channels: 2
Low Input Latency: -1,000000
Low Output Latency: 0,042667
High Input Latency: -1,000000
High Output Latency: 0,042667
Supported Rates:
    48000
==============================
Device ID: 10
Device name: default
Host name: ALSA
Input channels: 32
Output channels: 32
Low Input Latency: 0,011610
Low Output Latency: 0,011610
High Input Latency: 0,046440
High Output Latency: 0,046440
Supported Rates:
    8000
    9600
    11025
    12000
    15000
    16000
    22050
    24000
    32000
    44100
    48000
    88200
    96000
    192000
==============================
Device ID: 11
Device name: /dev/dsp
Host name: ALSA
Input channels: 16
Output channels: 16
Low Input Latency: 0,011610
Low Output Latency: 0,011610
High Input Latency: 0,046440
High Output Latency: 0,046440
Supported Rates:
==============================
Selected capture device: 8 - pulse
Selected playback device: 8 - pulse
Supported Rates:
    8000
    9600
    11025
    12000
    15000
    16000
    22050
    24000
    32000
    44100
    48000
    88200
    96000
    192000
==============================
Available mixers:
==============================
Available capture sources:
==============================
Available playback volumes:
0 - Master:0
1 - Headphone:0
2 - Speaker:0
3 - PCM:0
4 - Mic:0
5 - Mic Boost:0
6 - Internal Mic:0
7 - Internal Mic Boost:0
==============================
Capture volume is emulated
Playback volume is native

OK, I can see the problem.

You are recording a stream from YouTube?
The audio data most likely has a sample rate of 44100 Hz.

For some reason it appears that your sound card only supports 48 kHz. I don’t know whether this is a hardware issue or a driver issue, but the device info shows for playback:

==============================
Device ID: 4
Device name: Intel ICH6: Intel ICH6 - IEC958 (hw:0,4)
Host name: ALSA
Input channels: 0
Output channels: 2
Low Input Latency: -1.000000
Low Output Latency: 0.010667
High Input Latency: -1.000000
High Output Latency: 0.042667
Supported Rates:
    48000
==============================

So you’re trying to capture a 44.1 kHz audio stream through a device that plays only at 48 kHz.
All the symptoms make sense.

Fortunately you have PulseAudio which can resample on the fly and should be able to let you record streaming media at other rates.

Do you have PulseAudio Volume Control installed (pavucontrol)? If not, you will need to install it - it should be in the repository.

Thanks for your comments autark - you posted while I was typing, but it looks like you have come to pretty much the same conclusion as myself.

Hopefully Andrew4096 will be up and running shortly, and if so, the same method may be useful to yourself.

Steve, is that really pavucontrol you’re talking about, because I can’t find any way to configure the sampling rate or anything similar about my sound system, other than setting input/output levels?

Yes, pavucontrol.
We should be able to set our desired sample rate in Audacity, then let PulseAudio handle the sample rates automagically.

Assuming that you have it installed:

  • Open Audacity
  • Select “pulse” as the recording input
  • Click on the recording meter. By default this should start monitoring the default capture device, which is probably your microphone.
  • Open PulseAudio Volume Control
  • Look in the “Recording” tab of pavucontrol - you should see Audacity listed.
  • Click on the “ALSA capture from:” box and select the “Monitor” option.
  • Close pavucontrol
  • Click on the Audacity recording meter to stop monitoring.
  • Start playing a YouTube video.
  • Click on the recording meter. You should see it responding to the audio that is playing in YouTube.
  • Stop the YouTube video - the Audacity recording meter should show absolute silence.

If that all worked, you should be ready to go.

  • Press the Record button in Audacity
  • Start the video playing.

There are more detailed instructions with pictures for Ubuntu 10 : http://wiki.audacityteam.org/wiki/Stereo_mix_with_Ubuntu_10

So this is despite autark is selecting the pulse device [8] to record from, not [4]?

And as 48000 Hz-only devices used to be quite common on Linux, I presume the old solution of recording at 48000 Hz in Audacity would still work when recording from a non-playback input like a microphone?

See http://forum.audacityteam.org/viewtopic.php?f=20&t=68921 .


Gale

Can we keep on topic please.
I’m trying to help Andrew4096 and it is very confusing to throw in discussions about feature requests or a partial picture of what is happening on another machine.

I’ve split the feature request as you suggest, but I’m also trying to figure out what’s happening on autark’'s machine and lay down some guidance to help not only Andrew4096 but others who may read this later on. I can’t see it would help much at present to split off the behaviour Per sees.

I am confused if Andrew and Per are both recording a 44100 Hz stream at 48000 Hz and one recording ends up too fast (Andrew) and one (Per) too slow.

So @autark, when you have time, are you recording from YouTube, as Steve asked?

Does installing pavucontrol, choosing “pulse” as input device in Audacity’s Device Toolbar, setting Audacity project rate to 48000 Hz then recording as Steve described let you record at the correct speed?

Were you recording from the pulse input in Device Toolbar before, when recording was at the wrong speed (and so pulse won’t do on-the-fly-resampling without pavucontrol)? If this a pulse audio limitation it might be better to say so explicitly as I am not sure either way from what’s been written.

Also I still assume that setting Audacity project rate to the sole rate the device supports “should” solve the incorrect speed when recording from mic or line-in (that is, not playing a file). At least it was said to work when this came up in the past.


Gale

@Gale:

are you recording from YouTube, as Steve asked?

I discovered the problem recording from streaming radio (a Flash application, so that’s similar to Youtube). But actually I don’t think the source is relevant, since the Pulse Audio monitor lies as a layer in-between.

Does installing pavucontrol, choosing “pulse” as input device in Audacity’s Device Toolbar, setting Audacity
project rate to 48000 Hz then recording as Steve described let you record at the correct speed?

Yes, today it does.

Were you recording from the pulse input in Device Toolbar before, when recording was at the wrong speed
(and so pulse won’t do on-the-fly-resampling without pavucontrol)?

Yes, I was. Actually, I can’t see I’m doing anything differently now than before. It’s all very confusing.

Thanks, Per. Yes most likely the Flash player defaults to 44100 Hz. If you find using pavucontrol doesn’t solve the problem permanently, please let us know.

If pavucontrol is required to do on-the-fly resampling, I cannot understand why it is not installed by default, especially as one-rate-only devices are not unheard of on Linux.

Do you agree we can close the bug you opened (subject to what Andrew finds when he tests)? Your “feature request” will probably get counted.


Gale

@Gale: Today, my recordings are consistently too slow by the 44.1/48 ratio, regardless of what speed the project is set to, be that 8, 48, or 96 kHz, so today I have to set a different track rate to work around the problem, at the cost of a wildly decreased speed of exporting to FLAC afterwards, as I mentioned in my bug report.

I can only surmise that the successful outcome yesterday was due to the sound system behaving normally, which apparently isn’t the case today. So I think it all comes down to Audacity not being able to detect that the input source is outputting at a different rate than requested.

It should be noted that I have always been using pavucontrol since I started recording from the Pulse Audio monitor, since that functionality can only be enabled using pavucontrol, as far as I can see. My question to Steve was triggered by not finding any sampling-speed options in my version of that tool.

Frankly, I’m a bit wary of making a feature out of this. If this “feature” is buried in a preference somewhere I’m sure nobody will find it. In my mind this kind of detection should be the normal behavior. About my bug report, you can close it, because it’s not likely to lead to anything anyhow.

@Steve: sorry if this was too much off-topic. :wink:

OK, thanks. I assume the export slowness is because your distro build of Audacity uses libsamplerate (see Help > About Audacity: Build Information).

If you build the 2.0.2 tarball, default ./configure will give you libresample which will be much quicker. If you build HEAD (run ./autogen.sh before ./configure at the moment), I think that resampling would now use libsoxr which maybe a bit quicker again. If you build either, you probably want to uninstall your distro build.

Ah, OK, that’s true for monitor of analog mix. So perhaps what Pulse should be doing only works fitfully.

Please see http://forum.audacityteam.org/viewtopic.php?p=196617#p196617 and comment there if you want to.

OK, subject to anything else that looks like an Audacity “bug” coming out of this.

By the way, do you know the URL of the stream you want, or you can sniff the URL out, or get the file from the browser cache? If you know the URL you can dump it with mencoder, I think. This should just give you the 44100 Hz file (if that’s what it is).


Gale

Possible workaround here: http://forum.audacityteam.org/viewtopic.php?f=48&t=76401&start=10#p288145