Teensy 4.0 - based Audio Guestbook

OK, I've tested with a Kingston 16Gb card I happen to have, and which performs pretty badly on tests. The read and write speeds are OK, but it can have horrible internal delays at times, up to 1.4 seconds. I did a re-format using the official tool, which seems to have got the delays down to "only" 0.8 seconds - still really poor.

I then took a look at what might be done about this, and I think I found a pretty obscure bug in the SPI library, which I've posted about elsewhere on the forum, in case I'm wrong ... has been known to happen ;)

Fortunately I think there's a fix (OK, horrible bodge) you could try, without digging into the library code. You need to change two files in the sketch:

In play_sd_wav.cpp, add the following lines:
Code:
#include <Arduino.h>
#include "play_sd_wav.h"
[COLOR="#FF0000"]// ***** bodge round possible bug *****
#define SPI_HAS_NOTUSINGINTERRUPT 1 
unsigned short AudioUsingSPICount;
// ************************************[/COLOR]
#include "spi_interrupt.h"

In audio-guestbook.ino, increase the audio buffers from 60 to 600:
Code:
  // Audio connections require memory, and the record queue
  // uses this memory to buffer incoming audio.
  AudioMemory([COLOR="#FF0000"]600[/COLOR]);

This should, if my calculations are correct, allow audio interrupts to continue while the slow SD card writes are taking place, and massively increase the buffer available so that incoming audio can be stored during that time. 600 blocks is enough for 1.74 seconds of audio - if your card is slower than that, definitely get another one!
 
built a new board running same code as before but different phone getting clicking with audio on the playback messages any ideas plz
 

Attachments

  • 00005.zip
    417.5 KB · Views: 53
built a new board running same code as before but different phone getting clicking with audio on the playback messages any ideas plz

Is this the "clicking" you mean? Highlighted is the last 0.655s of your file, amplified and zoomed in:
2023-05-23 19_23_05-.jpg

If so, I'm fairly sure it's high-current pulses that occur during SD writes coupling in to the microphone circuitry. See a discussion around post#311 in this very thread. You may improve matters slightly by better shielding and routing of the microphone cable, but I think the best solution (barring a re-layout of the audio shield) is adding wires as shown in my image. Some soldering skillz required here... also, no-one's actually reported that they've tried it successfully. It would be better with insulated wires, of course - less risk of a short!
 
here is the audio file with no one talking you can hear the clicking i have done the same mod as your picture the unit is running on it own battery source

20230524_120208.jpg
 

Attachments

  • 00002.zip
    389 KB · Views: 66
That's definitely the SD card writes - the profile of the clicks is a dead giveaway, as is the repeat every 46ms. I'm not sure if the revision D2 audio adaptor makes a difference - I don't have one to test. The clicks are actually better than many I've seen, so there may be little more you can do with your hardware, apart from maybe adding some capacitors, or trying an SD card which uses less current for writing. The other thing to do would be to use the built-in SD card slot on a Teensy 4.1.

EDIT: or experiment with the routing of the microphone cable near the audio adaptor - maybe there's a route that cancels out the issues from the board itself!
 
On board led blinking

May be I'm wrong, but the noise seems to fit with onboard led blinking while recording. I'm curious to test with onboard led turned off ... but I don't know how to do this !!
 
May be I'm wrong, but the noise seems to fit with onboard led blinking while recording. I'm curious to test with onboard led turned off ... but I don't know how to do this !!
Correct - the SD card's SCK signal is on Teensy pin 13, which is also the built-in LED pin. This is unfortunate, but unavoidable. The only way to turn the LED off is to physically remove it, but that won't help the noise: the SD card takes about 100x the current the LED does, so will swamp any effect from removing the LED.
 
i have changed the mic element away from the MIC Capsule Electret Condenser Microphone and use a spare ear piece from another hand set and clicking reduced by 95% if you turn the mic gain up then it appears again
 
Speaker volume problem

Hi everybody, I have the following issue.
When I use a standard TRS Audio cable, the message is very quiet and it makes no difference if I raise the volume. If I use a TRRS cable, I have to reduce the volume parameter and the greeting is quite loud. But the problem is if I use the TRRS cable there is just background noise on the recording without understanding the recorded message. If I use the TRS cable the greeting is quite but my recording works perfectly.

Does anybody know how I can raise the loudness of the greeting without having background noise on my recording?
 
Hi everybody, I have the following issue.
When I use a standard TRS Audio cable, the message is very quiet and it makes no difference if I raise the volume. If I use a TRRS cable, I have to reduce the volume parameter and the greeting is quite loud. But the problem is if I use the TRRS cable there is just background noise on the recording without understanding the recorded message. If I use the TRS cable the greeting is quite but my recording works perfectly.

Does anybody know how I can raise the loudness of the greeting without having background noise on my recording?

Please post pictures, and ideally a schematic, of the wiring you've used. Note the audio adaptor is not intended to use a TRRS cable - I don't know what happens if you try, but it could easily be a Bad Thing.
 
Hi All,

Im trying to compile the code for this project on a Mac and am getting the below error:
Multiple libraries were found for "SD.h"
/Users/roryhammond/Downloads/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/AudioGuestBook/AudioGuestBook.ino:30:10: fatal error: MTP_Teensy.h: No such file or directory
Used: /private/var/folders/gv/x578ly1n77n3nqw8kkl03cfr0000gn/T/AppTranslocation/D1C7A640-EAE4-461E-B769-74F9B1257145/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/SD
Not used: /private/var/folders/gv/x578ly1n77n3nqw8kkl03cfr0000gn/T/AppTranslocation/D1C7A640-EAE4-461E-B769-74F9B1257145/d/Teensyduino.app/Contents/Java/libraries/SD
30 | #include <MTP_Teensy.h>
| ^~~~~~~~~~~~~~
compilation terminated.
Error compiling for board Teensy 4.0.


This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Can anyone help as im a complete noob to this and would like to use this for my wedding next weekend.facepalm.

Much appreciated!

Rory
 
Yes, on my computer the address is: C:\Arduino Programs\LIBRARIES\MTP_Teensy
Bear in mind that I have changed the Sketchbook location to: C:\Arduino Programs
 
I have now managed to get the whole system working however the Audio messages when I re-listen to the messages they are very quiet.

When I up the mic gain to 35, I can hear the audio better but get a very distinct and consistent "ticking" in the background.

Am I adjusting the wrong parameter OR is this related to the issues others are discussing over the last 2/3 pages of this thread? Im at a bit of a loss as to how to fix !
 
Probably...@h4yn0nnym0u5e is your goto on that one.
Thanks @BriComp!

I have now managed to get the whole system working however the Audio messages when I re-listen to the messages they are very quiet.

When I up the mic gain to 35, I can hear the audio better but get a very distinct and consistent "ticking" in the background.

Am I adjusting the wrong parameter OR is this related to the issues others are discussing over the last 2/3 pages of this thread? Im at a bit of a loss as to how to fix !
https://github.com/h4yn0nnym0u5e/audio-guestbook/tree/feature/doc-01 is my latest effort on this front - if that's not what you're using, it's probably worth a try. A key / recent feature is being able to set microphone (i.e. record), beep, greeting, and playback levels independently, see lines 117 to 124. It's "obviously" vital to get the microphone level right - you should definitely copy test files to your PC and check they're not too quiet to be useful, or so loud there's distortion. Although greeting and playback are both from WAV files on the SD card, I gave them separate mixer channels because you can max out the greeting level for best quality, but if you're suitably cautious with the microphone level the playback of recorded messages will probably sound a bit quieter - you can up the gain on mixer channel 2 to compensate, if you want.

On the subject of the ticking, I'm reasonably convinced that it's associated with bursts of high current during SD card writes. If you look back at post #354 above you'll see a pretty neatly done version of some better power distribution that @carpracing did, based on a suggestion I'd made earlier - if you have the skill I think it's definitely worth trying to do this. He wasn't entirely convinced, but I think with that and careful routing of the microphone cable you'll reduce the ticking significantly. You may also find a different SD card works a bit better, if it uses less current. Another approach is to use the built-in SD card slot on a Teensy 4.1. As the current flow doesn't go through the audio card, the effect is basically eliminated, as far as I can tell. This is a real analogue electronics thing, so if you increase the microphone gain you will also increase the level of the ticking.
 
Thanks @BriComp!


https://github.com/h4yn0nnym0u5e/audio-guestbook/tree/feature/doc-01 is my latest effort on this front - if that's not what you're using, it's probably worth a try. A key / recent feature is being able to set microphone (i.e. record), beep, greeting, and playback levels independently, see lines 117 to 124. It's "obviously" vital to get the microphone level right - you should definitely copy test files to your PC and check they're not too quiet to be useful, or so loud there's distortion. Although greeting and playback are both from WAV files on the SD card, I gave them separate mixer channels because you can max out the greeting level for best quality, but if you're suitably cautious with the microphone level the playback of recorded messages will probably sound a bit quieter - you can up the gain on mixer channel 2 to compensate, if you want.

On the subject of the ticking, I'm reasonably convinced that it's associated with bursts of high current during SD card writes. If you look back at post #354 above you'll see a pretty neatly done version of some better power distribution that @carpracing did, based on a suggestion I'd made earlier - if you have the skill I think it's definitely worth trying to do this. He wasn't entirely convinced, but I think with that and careful routing of the microphone cable you'll reduce the ticking significantly. You may also find a different SD card works a bit better, if it uses less current. Another approach is to use the built-in SD card slot on a Teensy 4.1. As the current flow doesn't go through the audio card, the effect is basically eliminated, as far as I can tell. This is a real analogue electronics thing, so if you increase the microphone gain you will also increase the level of the ticking.

Thanks so much for this! Really appreciate the explanation.

I see the two mixers in my code:

mixer.gain(0, 1.0f);
mixer.gain(1, 1.0f);

Would adjusting the gain on one of those improve the audio level (when I replay on my laptop) without increasing the ticking or is one tied to the other?
 
This suggests you do not have the latest version I've committed - please see the link in post #369. You should have these lines in the sketch file if you have the correct version:
Code:
  // ----- Level settings -----
  sgtl5000_1.micGain(39); // set to suit your microphone
  sgtl5000_1.volume(0.5); // overall speaker volume

  mixer.gain(0, 0.1f); // beeps
  mixer.gain(1, 0.1f); // greeting
  mixer.gain(2, 1.0f); // message playback
  // --------------------------

The only thing that will affect the volume when you copy a file to your laptop and play it is the sgtl5000_1.micGain(39); one. I'd expect that to affect everything equally, the audio picked up by the microphone and the ticking. Only better power connections and / or cable routing and / or lower current SD card is going to affect the relative level of the ticking.

The mixer.gain() and sgtl5000_1.volume(0.5) lines only affect what you hear on the phone speaker / earpiece.
 
This suggests you do not have the latest version I've committed - please see the link in post #369. You should have these lines in the sketch file if you have the correct version:
Code:
  // ----- Level settings -----
  sgtl5000_1.micGain(39); // set to suit your microphone
  sgtl5000_1.volume(0.5); // overall speaker volume

  mixer.gain(0, 0.1f); // beeps
  mixer.gain(1, 0.1f); // greeting
  mixer.gain(2, 1.0f); // message playback
  // --------------------------

The only thing that will affect the volume when you copy a file to your laptop and play it is the sgtl5000_1.micGain(39); one. I'd expect that to affect everything equally, the audio picked up by the microphone and the ticking. Only better power connections and / or cable routing and / or lower current SD card is going to affect the relative level of the ticking.

The mixer.gain() and sgtl5000_1.volume(0.5) lines only affect what you hear on the phone speaker / earpiece.


Thanks so much for all the insight.

One last question, can I run the CPU speed at 150mhz to make it drain my power bank less?
 
Thanks so much for all the insight.

One last question, can I run the CPU speed at 150mhz to make it drain my power bank less?
I believe you can, yes. That’s certainly @DD4WH’s recommendation, and he’s actually built one of these - I’ve just tweaked the software!
 
When I pickup my handset, it goes quiet when my greeting should be playing then no beep and it starts like a clicking noise for when it is recording (I noticed the clicking noise is still there when I push the handset switch down as well). It creates files for when it's supposed to be recording but there is no audio when I listen to the file. Any suggestions on what the issue might be?

We are having the same problem on ours. Did you ever get a response/fix for this? I looked through the forum and could not find one.

TIA
 
On TEENSY 4.0 with Audio Shield
Running Arduino IDE Version: 2.1.1, File, Examples, Audio, HardwareTesting, PassThroughStereo...
Latency appears to be about 6.3 ms from input to output.
This amount of latency is not acceptable for real time processing.
Yellow trace - Input waveform.
Magenta Trace - Output waveform.
I must be diligent to measure this every time I settle on some code to do a task on the Audio Stream to determine if the code affects the latency timing.

PXL_20230718_115858904 (2).jpg
 
Back
Top