USB Audio Clicking Noise

Teenfor3

Well-known member
I am using USB Audio out from teensy 3.2 to PC USB port for playing or recording on the PC.

The Audio all plays with good sound except a low level click about 4 or 5 times per second ..... This is estimate from what I hear because I cannot see any glitches in the audio waveform when viewed in Audacity but I can still hear the clicks when I play it back. It is a low freq click and is easiest heard when playing a high freq sound. The sketch is playing a continuous 2000 Hz tone. I hear the clicks on the USB audio but not on the DAC Audio. The output wavform looks a perfect sine wave but must have some discontinuity somewhere.....any ideas how to isolate the problem??



Code:
#include <Audio.h>
#include <Wire.h>
//#include <SPI.h>
//#include <SD.h>
//#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveformSine   sine1;          //xy=244,163
AudioOutputUSB           usb1;           //xy=557,160
AudioConnection          patchCord1(sine1, 0, usb1, 0);
AudioConnection          patchCord2(sine1, 0, usb1, 1);
// GUItool: end automatically generated code

AudioOutputAnalog     dac1;
AudioConnection          patchCord3(sine1, 0, dac1, 0);

 int freq = 2000;
  
void setup() {
  // put your setup code here, to run once:

sine1.frequency(freq);
sine1.amplitude(0.4);

AudioMemory(80);
//delay(500);

}

void loop() {
  // put your main code here, to run repeatedly:
//freq = freq + 100;
//sine1.frequency(freq);
//while(1);
//delay(500);
//if (freq >= 2000) freq = 100;
}
 
Which operating system is running on the PC?

If it's Linux, is it running pulseaudio, jackd, or something else as its audio system?
 
I compiled and uploaded the sketch on a windows XP (I know it is old and needs replaced) but it compiles OK, tried latest Arduino 1.8.7 and teensy 1.44 and also 1.8.5

I don't have any standalone USB audio device like USB speaker to try it with, so run Audacity on XP and recorded teensy USB output, all looks OK but I hear a low level continuous clicking.

I also plugged Teensy (that was programmed from XP PC) into USB port on a windows 10 laptop and get same clicking on playback.

I will try compile and upload from windows 10 machine and see if any difference..?
 
I tried compiling and uploading from a windows 10 PC..... just same problem....... compilesuploads OK, but still clicks in Audio although otherwise sounds good and looks good in Audacity.

I discovered that in order to get USB Audio (does not matter which PC compiles) I need AudioOutputAnalog declared. If it is commented out in my earlier code .... USB has no Audio out.

I only need line ....... AudioOutputAnalog dac1; ........I dont need any connection to it setup.......Why..??




Code:
// this needed for USB out......why...???

AudioOutputAnalog     dac1;
AudioConnection          patchCord3(sine1, 0, dac1, 0);



Code:
// or this needed for USB Audio out.......Why....??

AudioOutputAnalog     dac1;
//AudioConnection          patchCord3(sine1, 0, dac1, 0);
 
Because the audio library needs a kind of "Heartbeat" at the sampling frequency. Since the whole audio library is event driven (buffer consumed->load next buffer) to update the whole audio object network, you need an object which constantly pulls audio samples. The USB audio output can't pull, it needs to be pushed. So you need another (dummy) object like AudioOutputAnalog to keep the machine running.
 
Thanks Theremingenier, I actually see that mentioned in the GUI documentation, but I didn't know what it meant. Yes, that gets USB working consistently, but what about the clicks, I still get the clicks. I am compiling and uploading on a Pentium dual core running windows 10 Arduino 1.8.7 and TeensyDuino 1.44. It all compiles and looks OK when recorded in Audacity and Zoomed in. My win 10 also allows me access to listen to input and play out from PC over analog PC speakers, I still get the clicks here. I have tried a brand new teensy3.2 connected to nothing except the USB and still same get clicks. Just wondering is any one else able to test the code in my earlier post as see if clicks are heard...???. I have now tried on 3 PCs and with 2 teensy3.2 and still same.
 
Did you ever try using a „true“ USB Audio device to check? I think the “problem” comes from the recording software which forces a precise sampling rate of 44100Hz. The Teensy outputs digital audio at 44117Hz sampling rate, because it’s the closest value which can be obtained by integer division of the Teensy’s bus clock of 48MHz. A normal USB audio device will easily sync on that because it is within the specified tolerance. But if a non-adaptive recording software insists on consuming only and precisely 44100 samples per second, there will be 17 samples remaining each second and slowly fill up a buffer. When the latter overflows, it will be dropped and the buffering restarted with a clean buffer which you hear as a click.
I have a mixing desk from Behringer which has USB audio inputs. It will self-adapt and play click free with all sampling rates from 44020 to 44180Hz. So, I think that your issue is in fact a non-issue, but your test setup does not reflect a real world use case and give you false positives.
Some people have encountered similar issues with inflexible USB sound drivers on embedded Linux systems.
 
No I haven't tried a "true" USB Audio device because I haven't got onr and have been Googling and searching the shops and cannot find any, or at least any where the spec. say it takes USB Audio. Most are USB charging only with Bluetooth or 3.5mm Jack. The only thing I see are cheap USB Audio to 3.5mm adaptors, but thought not much point in using these as can just use DAC out. or Audio shield. My idea with USB was.....Maybe give a better quality audio and only one lead would do Power and audio and no need for Audio 3.5mm jack. I will get an adaptor in first instance to see if it proves the USB audio clean from clicks........ or do you know a good speaker....??.......Thanks
 
Just wondering is any one else able to test the code in my earlier post as see if clicks are heard...???

I have a test machine here with Windows 10, but I'm not really a Windows user. I most use Linux. I have no idea exactly what to do for this:


My win 10 also allows me access to listen to input and play out from PC over analog PC speakers, I still get the clicks here.

Maybe you could give some screenshots or photos of exactly what to do to set this up? Remember, I pretty much never use Windows other than to check the Teensyduino software works... so I need very specific steps to follow, so I can get the same result here.

I can tell you I did test on all 3 systems using Audacity. Usually I recorded a sound to Audacity's memory. Then after stopping, I would click Audacity's play button to play whatever was recorded.
 
Yes that is the type of test I am doing, the most basic, Record from USB in Audacity and play it back. Do this on both old XP and the Win10 with same results.
The win 10 sound gives me extra options I can tick box to listen to USB input and Output to speakers and it will play direct from USB to speakers without Audacity.

I also have lubuntu 18.04 running on an old laptop Lenovo 3000 C200, Intel Celeron CPU 430 1.73 Ghz and Audacity on it and same thing, I record in Audacity and play it back and still get clicks. The waveform looks perfect, I cannot see any glitch even when zoomed in. The clicks are "faint" but still there, I tried lower amplitude sound from sinewave to see if clicks would remain as loud, I assume they would remain same if digital generated noise, but clicks also seem lower and still dont see them in Audacity..?????
It doesnt seem to matter what pc I use.
 
Before everybody continues guessing wildly around, I will try to compile and put your sketch on a Teensy 3.2 tonight after work and see how it plays back through my Behringer USB audio equipment and through my MacBook Pro where I run the newest macOS and the newest Audacity release. I'm almost sure that the clicks do not come from the Teensy but from some not up-to-date hardware or software.

I remember having had similar problems around 2011 with a Lenovo notebook running Fedora Linux where Audacity would introduce clicks and distortion when I activated parallel listening and recording. This was later fixed by an improved release of Audacity.
 
Thanks Theremingenieur. I dont think I am doing parallel listening and recording, but maybe with audacity it depends on how it is setup. I simply record from the USB as input and then Play it back with teensy unplugged.......and get clicks.
on the windows 10 PC there is a tickbox in the sound settings to set "Listen" to the input, and I can plug teensy into USB and hear the sound out the speakers without needing Audacity.....and I still get clicks
 
Ok... I get this strange clicking, too, in Audacity. Using VLC to stream the input directly gives even worse results: There is the same clicking "shratatata...shratatata..." and in addition, there is a ghost tone with slowly increasing frequency which clearly results from the 44117 vs 44100 interference because VLC is unable to adapt to the slightly higher input sampling rate.

On the other side, this observation in VLC proves that the clicking is not a sample rate issue since the latter produces that ghost tone. The clicking must be a USB buffer issue, independent of the sampling rate.

Finally I could not do the test with the USB input of my Behringer mixing desk, it accepts only signals from USB hosts :(

Now continuing the investigation.

Edit: Here a zipped mp3 where one can hear these annoying clicks. As a differential diagnose, I used the I2S output instead of the DAC, and a triangle signal instead of a sine with no success. There seems really to be a bug somewhere...
 

Attachments

  • teensytest.mp3.zip
    159.3 KB · Views: 151
Last edited:
More investigations on the Linux Lubuntu 18.04 laptop.

Put Audacity 2.2.1 on it and it recorded and played really bad breakup of audio. Discovered in EDIT, PREFERENCES, RECORDING ther are 2 tick boxes for Playthrough both ticked, I unticked both and it records and plays a lot better........no repetitive clicks at about 3 or 4 times a second but a more faint like "sparkling crackling" at random. So alot of the problem could be PC resources and setup. I am not too sure how I have linux setup, Audacity says ALSA as Audio Host ??...cannot see any settings anywhere...??
Audacity Mic. says Teensy Audio: USB Audio(hw 1, 0). Speakers I set to front for PC speaker out or headphone.
Pulse Audio sound control gives me Teensy Audio and a list of profiles....I picked Digital Stereo Duplex (IEC958)
I also get a problem compiling/uploading to teensy from linux "error sending reboot command to /dev/hidraw1" then I press button on teensy and it uploads OK. but generally have to press button each time I compile.
The status line on the arduino ide says " Teensy 3.2 / 3.1, Audio, 96 MHz (overclocked), Faster, United Kingdom on usb4/4-1"

EDITED........Sorry....I was trying out above with other sounds that were masking the crackling to some extent, when I go back to the clean sine wave as in the code sample above I still get the same clicks. but the linux PC will no record smoothly at all with the Passthrough box ticked.

Edited ....... Just checked the old XP PC ... It will record and play smoothly while recording with the passthrough box ticked....but still get clicks
 
Last edited:
Hi !

I want to test audio library with teensy 3.2 and get the same clicks .... on a W10 and a mac .... same with audacity and internal W10 loopback listener ...

Thanks,

Hugo
 
Up to now, we can state that this problem occurs with different synth and the audioOutputUSB objects. And it can be observed in Win10, macOS 10.14 and Ubuntu 18.04.

Hope that @Paul finds the time to look into that after he will have brought the T4 to market...

Fortunately, the problem is only with the USB audio output, the others (I2S and analog) work well without problems.
 
Thanks for your reply !

So, the same problem will appear if I use USB to PC with line-in audio adaptor ?

And what about PC to USB for output on line out adaptor board ?

Thanks,

Hugo
 
As far as we have discovered the problem, I can only say that if you use the Teensy audio board with its line-in and line-out connectors for audio, you will not have any problem because the Teensy will communicate via I2S with the SGTL5000 codec on the audio board. Best is for the moment to not use USB audio at all until this has been fixed.
 
Ok, I see, but my goal is to use Teensy as an USB audio device (in and out).
I want to order some audio adaptor for my project but if the library contains some bugs, I will not ....

So, waiting for Paul's response !
 
You might already order the audio adapter board since it has nothing to do with USB. It has its own codec and is connected to the Teensy via I2S for audio and via I2C for control.

And it's not the library which has bugs, there is only one object of >30 which has probably a bug.
 
Yes, I have see the board's schematics ! :)

Sure for the library, it's not a criticism of paul's (very great) work ! My apologize if you understand that ! :D

Just, my project is base on the Teensy USB Audio features, and if Paul haven't time yet to find the problem, I have to change my hardware setting, so not order the audio adaptor board.

I would be happy to be able to help correct this problem, if Paul can give us some leads ...

Thanks for all,

Hugo
 
I will do additional tests tonight and produce a sketch which will allow Paul to reproduce the problem, so that we might move on more quickly.
 
My sketch, for simple test (sine wave) :

Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputUSB            usb1;           //xy=132,85
AudioInputI2S            i2s2;           //xy=139,186
AudioSynthWaveformSine   sine1;          //xy=142,134
AudioOutputI2S           i2s1;           //xy=416,83
AudioOutputUSB           usb2;           //xy=423,178
AudioConnection          patchCord1(usb1, 0, i2s1, 0);
AudioConnection          patchCord2(usb1, 1, i2s1, 1);
AudioConnection          patchCord3(i2s2, 1, usb2, 1);
AudioConnection          patchCord4(sine1, 0, usb2, 0);
// GUItool: end automatically generated code


void setup() {
  delay(250);
  AudioMemory(10);
  delay(250);
  
  sine1.amplitude(0.5);
  sine1.frequency(500);
}

void loop() {
  delay(20);
}

And another for loopback audio :
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioInputUSB            usb1;           //xy=132,85
AudioOutputUSB           usb2;           //xy=342,85
AudioOutputI2S           i2s1;           //xy=402,201
AudioConnection          patchCord1(usb1, 0, usb2, 0);
AudioConnection          patchCord2(usb1, 0, i2s1, 0);
AudioConnection          patchCord3(usb1, 1, usb2, 1);
AudioConnection          patchCord4(usb1, 1, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=549,52
// GUItool: end automatically generated code

void setup() {
  delay(250);
  AudioMemory(10);
  delay(250);

  sgtl5000_1.enable();
  sgtl5000_1.inputSelect(AUDIO_INPUT_LINEIN);
  sgtl5000_1.volume(1);
}

void loop() {
  delay(20);
}

Thanks for you testing,

Hugo
 
I think it's not a sample rate problem, but perhaps a buffer problem because when I record USB Input on any software (Audacity, Pro Tools or Digital Performer), waveform are ok .....

But yes, I have try 44.1Khz sample rate, and also 44117Hz (teensy real sample rate)
 
Back
Top