Audacity records at wrong clock rate

Help for Audacity on GNU/Linux.
Forum rules
ImageThis forum is for Audacity on GNU/Linux.
Please state:
  • which version of Linux you are using,
  • the exact three-section version number of Audacity from Help menu > About Audacity,
  • whether you installed your distribution's release, PPA version, or compiled Audacity from source code.

Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade (see https://www.audacityteam.org/download/).
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.
Andrew4096
Posts: 8
Joined: Wed Sep 12, 2012 9:21 pm
Operating System: Please select

Audacity records at wrong clock rate

Post by Andrew4096 » Sun Nov 04, 2012 6:53 am

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. :evil: 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?

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

Re: Audacity records at wrong clock rate

Post by steve » Sun Nov 04, 2012 3:34 pm

Andrew4096 wrote:This should not be so. :evil: 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.
Andrew4096 wrote:Audacity 2.0.3 on Linux
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?
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Andrew4096
Posts: 8
Joined: Wed Sep 12, 2012 9:21 pm
Operating System: Please select

Re: Audacity records at wrong clock rate

Post by Andrew4096 » Mon Nov 05, 2012 7:18 am

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.

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

Re: Audacity records at wrong clock rate

Post by steve » Mon Nov 05, 2012 8:25 am

You would probably be best to use the release version - the source code is available here: http://code.google.com/p/audacity/downl ... =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:

Code: Select all

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:

Code: Select all

./configure

Code: Select all

make
The "make" should complete with no errors.

Check that it has built correctly by typing:

Code: Select all

./audacity
If Audacity runs, shut it down and install:

Code: Select all

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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Gale Andrews
Quality Assurance
Posts: 41761
Joined: Fri Jul 27, 2007 12:02 am
Operating System: Windows 10

Re: Audacity records at wrong clock rate

Post by Gale Andrews » Mon Nov 05, 2012 8:38 am

Andrew4096 wrote: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.
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
________________________________________FOR INSTANT HELP: (Click on Link below)
* * * * * Tips * * * * * Tutorials * * * * * Quick Start Guide * * * * * Audacity Manual

Andrew4096
Posts: 8
Joined: Wed Sep 12, 2012 9:21 pm
Operating System: Please select

Re: Audacity records at wrong clock rate

Post by Andrew4096 » Mon Nov 05, 2012 8:09 pm

Gale Andrews wrote: 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.
Thanks for the link. I was having difficulty finding evidence that anyone else was seeing this problem.
Gale Andrews wrote: 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.
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.
Gale Andrews wrote: 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.
The menu reports the following:

Code: Select all

==============================
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.)
Gale Andrews wrote: 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?
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.

Andrew4096
Posts: 8
Joined: Wed Sep 12, 2012 9:21 pm
Operating System: Please select

Re: Audacity records at wrong clock rate

Post by Andrew4096 » Mon Nov 05, 2012 8:22 pm

steve wrote:You would probably be best to use the release version - the source code is available here: http://code.google.com/p/audacity/downl ... =2&q=linux

Now that you have successfully built Audacity once, building it again should be easy.
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.

autark
Posts: 31
Joined: Sun Dec 12, 2010 10:05 am
Operating System: Please select

Re: Audacity records at wrong clock rate

Post by autark » Mon Nov 05, 2012 8:56 pm

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:

Code: Select all

==============================
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

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

Re: Audacity records at wrong clock rate

Post by steve » Mon Nov 05, 2012 9:02 pm

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:

Code: Select all

==============================
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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

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

Re: Audacity records at wrong clock rate

Post by steve » Mon Nov 05, 2012 9:07 pm

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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)

Post Reply