This is my first post in this community and already I am grateful to be part of this group. I am experienced with a few projects about home automation, CNC and a bicycle trainer using only UNOs.
This time I am looking to build a sound generator to drive something loud like a coaxial speaker around 30-50W. I've already tested my code with the output on a UNO on both a piezo speaker but also amplified clean on a guitar amp with a full range driver. It sounds ok-ish on the piezo and terrible on the powerful amp. I understand that the UNO having no DAC is not the right board so I am looking for something else.
I hear good things about the ESP32 yet I've never used one, however it does not seem too complicated. The problem I have is the choice of the amp, as the I2S versions are generally low power. I am going to be driving this experiment inside a car. It's not going to be an audiophile usage rather I am trying to see if I can adjust the driving experience.
I came across the TPA3118 amplified that seems to be able to deliver 60W yet it's so tiny and cheap. Maybe I do not need the 60W, way less and it would be nice to have something with a potentiometer. I am looking for a mono amplifier but also a stereo could do either bridged or not.
I understand that the ESP32 is going to have good quality audio. Can you recommend something for my project? I thank you in advance!
It did not decided yet, maybe in the future it will be an active cancelling device, yet first option would be to play "fake" engine noise in a kit electric car.
The choice of amplifier is unrelated to sound generation, so separate those parts of the project until you decide what you want to do.
Generally speaking, the faster and more powerful the micro, the more options you have for generating sound. That is the hardest part of the project, so start there.
There are some pretty good audio libraries for the Teensy series of Arduino-compatible microprocessors, most if not all of which have DACs.
I believe the sound generation part is already decent, I could try to connect headphones to the UNO to hear the result and the piezo speaker may seem to improve things, but the guitar amp shows how bad things really are. Right now I do not think it's due to the algorithm, rather the hardware. I could be very wrong.
I am a bit confused by the fact the the amplifier is unrelated to the project, as the arduino will use an analog output for the speaker/amplifier while for instance with the ESP32 I would need to use an I2S compatible amplifier.
The Teensy is something totally new to me so it's adding more confusion to my cause :). I say this in the good way, because there's always something new to learn.
Right now I am so excited to go on the Arduino way, that I cannot wait to see a decent output. Also, I like the fact that both an Arduino and a TP3118 would use a 12V power input, while for instance with a ESP32 I need to run it on 3.3V while the amplifier may need 12V.
The ESP32 is a very poor choice for audio projects. Among other problems, the ADC is so seriously flawed as to be nearly useless, and the ADCs are only 8 bits wide.
OK ... I understood it would be a huge step up from the Arduino. So, then what to use? I will check Teensy, but I still need a pretty powerful amp. This student project car is a track car, it has no cabin, it's fully open so I need to simulate an exhaust. The speaker will be enclosed in a stainless steel ball with a port. That's why I thought I should choose a bit of a powerful amplifier than the regular ones used around 3W, although real 3W could be loud.
Budget is not so much an issue, yet I do not want to spend hundreds on the project. Maybe a few hundreds in the end, but not more :).
In this project the only input will be the throttle pedal which is basically a potentiometer which does not really need much finesse. The synthesized sound is not replayed from an mp3 rather a waveform. Bluetooth is nice and wifi as well to be used as a configuration device but not more. The requirement is focused on audio output quality at some higher output only.
CD quality could already be an overkill, the output is pretty much bass/midrange and it will be anyway tuned by the enclosure.
Tell us more about this "synthesized sound". The more complex the processing, the more processing power back end will be needed behind the DAC.
Is it hypothetical at the moment, or have you already designed and coded it?
BTW, external DAC modules and ICs are available for almost any processor. A good one will also include an on board analog reconstruction filter, which is not present on a bare MCU board.
Must this processor also perform other tasks, and/or operate addition hardware in addition to sound generation?
So the TPA3118 needs an 8 ohm speaker and a 24V power supply. Have you seen the sorts of packages the chips come in? Can you handle the surface mount spacing it has. Yes you can hand solder it but you have to have a high level of soldering skill to do this.
What sort of sound generator? A square wave is simplest but using an I2S interface for a square wave is going to be overkill.
Is it going to be a repetitive waveform, or some sort of audio sample?
If you say so, but the definition of "good" is subjective.
It’s quite repetitive, as it is an exhaust sound of a 4cyl or 8cyl engine. It is already coded and as said before it sounds good on the UNO arduino with a piezo speaker but very bad on the amplifier. I do not have other ways to test now but my guess is that it’s the lack of fidelity of the UNO replay that is masked by the piezo speaker.
Obviously, it’s a square wave, what else to play with an UNO?
This is the amplifier, already soldered: TPA3118 Mono Amplifier Module Pinout, Features & Datasheet. According to the specs it can handle 4.5-24 DC power and 4/8ohm speakers. So, my guess it may do fine at 12V with a 4ohm speaker of higher SPL. Not sure what you mean with the “implications of a class D amplifier”.
There is no obvious about it. You can play any shape waveform you like with an Arduino Uno. This waveform is a mixture where it is part sawtooth and part sin wave, produced on an Arduino Uno.
You can also use pure sin, triangle and sawtooth wave forms, or any other arbitrary waveform. Even sampled waveforms can be produced with the right software on an Arduino Uno.
This is an Arduino saying Yes / No (my voice) on a button press.
PWM is not a square wave, it is a rectangular wave with a variable mark / space ratio. The restoration filter on the PWM turns it into an analogue signal, which if you use a class D amplifier turns it back into PWM which is then turned back into analogue by the inductance filter of the speaker coil.
My examples all used PWM, all be it at a much higher frequency than the default frequency.
Mike, thank you! My explanation was dodgy.
I am aware of the issues with a class D in terms of volume control, yet I hoped running that amp at lower voltage would yield the right output power.
What would you recommend? I would like to run it on the battery and maybe later on a termic engine car, thus an alternator, so 12-14.4V. An arduino could also run at that voltage yet it’s a bit high. I can sort out the Arduino power supply to run on 5V.