EmbeddedRelated.com
Forums
The 2026 Embedded Online Conference

How to improve audio quality for sound effects

Started by pozz May 14, 2015
In the past I used a simple piezo buzzer to create very simple sound 
effects: beep, beeeeeeeeeep, bip bip bip. Just one tone, but I need only 
one GPIO from the MCU and nothing else.

Now I'd like to improve the audio quality to have a better sound 
effects, when the user press a button on a touch screen, when there's an 
error, when the operation was processed ok.

This is now common on electronic gadgets, from GPS navigators to in-home 
displays and so on.

I have a Cortex-M3 MCU with 10-bits DAC peripheral. I'm able to generate 
samples at a frequency of 44.1kHz, but I prefer to have lower frequency 
to save some Flash memory space, where the audio waveforms will be 
saved. For the same reason, I prefer to save the waveform as 8-bits.

Could you suggest a schematic block or IC to interface the DAC output to 
a small speaker? Could you suggest also the speaker to use (it's a 
wall-mounter touch screen, so the user is in front of the gadget)?

Related to this question, even if not technical: where can I find sound 
effects waverforms? I'm not able to generate them myself and I would 
avoid ingage an expert for similar things.
On Thu, 14 May 2015 07:46:23 +0200, pozz <pozzugno@gmail.com> wrote:

>In the past I used a simple piezo buzzer to create very simple sound >effects: beep, beeeeeeeeeep, bip bip bip. Just one tone, but I need only >one GPIO from the MCU and nothing else. > >Now I'd like to improve the audio quality to have a better sound >effects, when the user press a button on a touch screen, when there's an >error, when the operation was processed ok. > >This is now common on electronic gadgets, from GPS navigators to in-home >displays and so on. > >I have a Cortex-M3 MCU with 10-bits DAC peripheral. I'm able to generate >samples at a frequency of 44.1kHz, but I prefer to have lower frequency >to save some Flash memory space, where the audio waveforms will be >saved. For the same reason, I prefer to save the waveform as 8-bits. > >Could you suggest a schematic block or IC to interface the DAC output to >a small speaker? Could you suggest also the speaker to use (it's a >wall-mounter touch screen, so the user is in front of the gadget)? > >Related to this question, even if not technical: where can I find sound >effects waverforms? I'm not able to generate them myself and I would >avoid ingage an expert for similar things.
Any OpAmp with the required gain and power output? Something like an LM386? The datasheet has several typical circuits. And any typical 8 ohm speaker. You may want to stick with an existing compressed audio format, which will be much smaller than any uncompressed format. Vorbis is OSS, and most audio tools can handle it. Integrating libvorbis is fairly easy for decompressing the stream in your device. libvorbisfile is even simpler. You'll need to research how well that'll fit on an M3, though.
On 5/13/2015 10:46 PM, pozz wrote:
> In the past I used a simple piezo buzzer to create very simple sound effects: > beep, beeeeeeeeeep, bip bip bip. Just one tone, but I need only one GPIO from > the MCU and nothing else. > > Now I'd like to improve the audio quality to have a better sound effects, when > the user press a button on a touch screen, when there's an error, when the > operation was processed ok. > > This is now common on electronic gadgets, from GPS navigators to in-home > displays and so on. > > I have a Cortex-M3 MCU with 10-bits DAC peripheral. I'm able to generate > samples at a frequency of 44.1kHz, but I prefer to have lower frequency to save > some Flash memory space, where the audio waveforms will be saved. For the same > reason, I prefer to save the waveform as 8-bits.
Have you considered algorithmically generating the waveforms at run-time? Are you expecting periodic signals? Or, more "random" sounds? What sort of duration (in units of time)?
> Could you suggest a schematic block or IC to interface the DAC output to a > small speaker? Could you suggest also the speaker to use (it's a wall-mounter > touch screen, so the user is in front of the gadget)?
A lot will depend on how much actual power you want to deliver. And, the sort of "fidelity". If you are just looking for "different noises", you can get away with far cruder designs. What size speaker do you plan on using? If you are looking for low profile (e.g., 5mm) you'll have different fidelity objectives than something with more "throat". The consequence of this is reflected in the amount of power that it is *meaningful* to deliver to the speaker (before distortions become a problem) and, in turn, the overall fidelity you expect.
> Related to this question, even if not technical: where can I find sound effects > waverforms? I'm not able to generate them myself and I would avoid ingage an > expert for similar things.
You can *find* sound effects in lots of places. *Your* problem will be ensuring those you find are available for you to incorporate into a commercial product (i.e., the license terms associated with the files). You haven't indicated what *types* of sound effects you seek. E.g., automobile noises, aircraft takeoff, jack hammer, etc. are considerably different from "sci-fi sound effect #241" or "bong #38" An unsolicited suggestion: don't get too "cute" with annunciators. Folks quickly find them boring. Think, instead, about what they would *welcome* hearing -- not what "sounds cool"!
Il 14/05/2015 08:15, Robert Wessel ha scritto:
> Any OpAmp with the required gain and power output? Something like an > LM386? The datasheet has several typical circuits. And any typical 8 > ohm speaker.
Ok, thank you for your suggestion. I'm a firmware developer, so I don't know and never used this analog ICs. What about the sample frequency? If I use 22kHz or less, probably it can be heared from the speaker. How to filter it?
> You may want to stick with an existing compressed audio format, which > will be much smaller than any uncompressed format. Vorbis is OSS, and > most audio tools can handle it. Integrating libvorbis is fairly easy > for decompressing the stream in your device. libvorbisfile is even > simpler. > > You'll need to research how well that'll fit on an M3, though.
Ok, thank you. I will check.
Il 14/05/2015 08:45, Don Y ha scritto:
> Have you considered algorithmically generating the waveforms at run-time? > Are you expecting periodic signals? Or, more "random" sounds? What sort > of duration (in units of time)?
I'd like to generate some short sound effects: beep, boop, click, tada and so on. The typical sound effects that you can hear using desktop OSes like Windows, when you perform some actions (click on a button, receive a fatal error or a warning and so on). I don't know if there are algorithms to generate those kind of sound effects. Any suggestion? If I have additional memory space, I could think to play some short (5-10s) speech signal. But this isn't a must for my application.
>> Could you suggest a schematic block or IC to interface the DAC output >> to a >> small speaker? Could you suggest also the speaker to use (it's a >> wall-mounter >> touch screen, so the user is in front of the gadget)? > > A lot will depend on how much actual power you want to deliver.
Sincerely I don't know. Anyway the user is in front of the electronic device, that is a touch panel mounted on a wall.
> And, the sort of "fidelity".
Similar to an Android mobile phone when you touch a button (and you have the sound effects enabled, of course).
> If you are just looking for "different noises", > you can get away with far cruder designs. > > What size speaker do you plan on using? If you are looking for low profile > (e.g., 5mm) you'll have different fidelity objectives than something with > more "throat". The consequence of this is reflected in the amount of > power that it is *meaningful* to deliver to the speaker (before distortions > become a problem) and, in turn, the overall fidelity you expect. > >> Related to this question, even if not technical: where can I find >> sound effects >> waverforms? I'm not able to generate them myself and I would avoid >> ingage an >> expert for similar things. > > You can *find* sound effects in lots of places. *Your* problem will be > ensuring those you find are available for you to incorporate into a > commercial product (i.e., the license terms associated with the files).
Of course, I need public-domain or similar sound effects.
> You haven't indicated what *types* of sound effects you seek. E.g., > automobile noises, aircraft takeoff, jack hammer, etc. are considerably > different from "sci-fi sound effect #241" or "bong #38"
I'm finding a sound effect when the user touch a button (a click?). I noticed that the user is encouraged to press again in a short time, if the result of the touch isn't immediate, so at last he makes the actions two times. I'm finding a sound effect for an error operation (booop?), for example when the user types a wrong PIN code. I'm finding a sound effect to play when a requested action is made correctly by the system (blip blip blip). I'm finding a sound signal when the user activate the display, a short "welcome" sound (tada?).
> An unsolicited suggestion: don't get too "cute" with annunciators. > Folks quickly find them boring. Think, instead, about what they would > *welcome* hearing -- not what "sounds cool"!
Yes, I know. In fact I'm finding very simple and short sound effects.
On 5/14/2015 12:47 AM, pozz wrote:
> Il 14/05/2015 08:45, Don Y ha scritto: >> Have you considered algorithmically generating the waveforms at run-time? >> Are you expecting periodic signals? Or, more "random" sounds? What sort >> of duration (in units of time)? > > I'd like to generate some short sound effects: beep, boop, click, tada and so
Beep, boop, click are possible with a monophonic synthesizer. The Windows-style "TaDa" is homophonic requiring a bit more complexity in the synthesis.
> on. The typical sound effects that you can hear using desktop OSes like > Windows, when you perform some actions (click on a button, receive a fatal > error or a warning and so on). > > I don't know if there are algorithms to generate those kind of sound effects. > Any suggestion?
Monophonic synthesis is relatively trivial -- even square waves fed to a low pass filter can be "acceptable" and relatively easy to create on-the-fly. E.g., a "wolf whistle" is just a ramp driving a VCO (a VCO being trivial to implement digitally) When you are looking at polyphonic or homophonic synthesis things get a bit more challenging; you typically need multivalued output capability (i.e., a D/AC instead of just a two-level digital "bit" that you toggle for square waves) and teh ability to run two or more monophonic synthesizers concurrently -- mixing their outputs to drive the D/AC. There have been several "music compilation languages" developed over the years (e.g., CMUSIC) but most are intended to be run on desktop machines. However, they could give you an idea as to what sort of math is required for run-time synthesis -- especially if you hard-coded the specific effects that you wanted (CMUSIC is a "programming language", of sorts, so much more capable than you would need). _Elements of Computer Music_ may be worth reading if you are truly interested in the subject. OTOH, if you just want to hack together some sounds, then WAV synthesis is probably the expedient.
> If I have additional memory space, I could think to play some short (5-10s) > speech signal. But this isn't a must for my application. > >>> Could you suggest a schematic block or IC to interface the DAC output >>> to a >>> small speaker? Could you suggest also the speaker to use (it's a >>> wall-mounter >>> touch screen, so the user is in front of the gadget)? >> >> A lot will depend on how much actual power you want to deliver. > > Sincerely I don't know. Anyway the user is in front of the electronic device, > that is a touch panel mounted on a wall.
If the user is in a reasonably quiet environment and is the *only* person who needs to hear the annunciator, you can do well with a small speaker. If you have an LCD monitor that has built-in speakers, you could give those a test drive to get a feel for fidelity and volume.
>> And, the sort of "fidelity". > > Similar to an Android mobile phone when you touch a button (and you have the > sound effects enabled, of course). > >> If you are just looking for "different noises", >> you can get away with far cruder designs. >> >> What size speaker do you plan on using? If you are looking for low profile >> (e.g., 5mm) you'll have different fidelity objectives than something with >> more "throat". The consequence of this is reflected in the amount of >> power that it is *meaningful* to deliver to the speaker (before distortions >> become a problem) and, in turn, the overall fidelity you expect. >> >>> Related to this question, even if not technical: where can I find >>> sound effects >>> waverforms? I'm not able to generate them myself and I would avoid >>> ingage an >>> expert for similar things. >> >> You can *find* sound effects in lots of places. *Your* problem will be >> ensuring those you find are available for you to incorporate into a >> commercial product (i.e., the license terms associated with the files). > > Of course, I need public-domain or similar sound effects.
Most of the sound effect libraries that I have encountered are licensed for personal use -- not commercial. OTOH, you could probably write to them and request a commercial license. I suspect their primary concern is not wanting you to resell the sound effects (e.g., on a CD) and thus compete directly with their original sales. As you'll be only interested in a few sounds and will be embedding them (where they can't really be considered as "re-sold"), you mayjust have to go through the formalities of getting written approval.
>> You haven't indicated what *types* of sound effects you seek. E.g., >> automobile noises, aircraft takeoff, jack hammer, etc. are considerably >> different from "sci-fi sound effect #241" or "bong #38" > > I'm finding a sound effect when the user touch a button (a click?). I noticed > that the user is encouraged to press again in a short time, if the result of > the touch isn't immediate, so at last he makes the actions two times. > > I'm finding a sound effect for an error operation (booop?), for example when > the user types a wrong PIN code. > > I'm finding a sound effect to play when a requested action is made correctly by > the system (blip blip blip).
Each of these are easy to do with just a monophonic square wave synthesizer. How you control *volume* is a separate issue...
> I'm finding a sound signal when the user activate the display, a short > "welcome" sound (tada?).
This is a "richer" sound requiring more concurrent voices. It would require a real D/AC (to mix the various signals at different points in their respective waveforms) so it's silly NOT to opt for a WAV synthesis approach directly. Then, look at ways of economizing on storage (compression, run-time resampling, etc.)
>> An unsolicited suggestion: don't get too "cute" with annunciators. >> Folks quickly find them boring. Think, instead, about what they would >> *welcome* hearing -- not what "sounds cool"! > > Yes, I know. In fact I'm finding very simple and short sound effects.
When I made my first "electronic doorbell", I played with many prerecorded sounds. At first, the novelty was amusing. But, it doesn't take long to get tedious. I suspect this is similar to the reaction folks have to programmable ring-tones on their cell phones -- "cute" quickly gets boring...
On Thu, 14 May 2015 09:34:38 +0200, pozz wrote:

> Il 14/05/2015 08:15, Robert Wessel ha scritto: >> Any OpAmp with the required gain and power output? Something like an >> LM386? The datasheet has several typical circuits. And any typical 8 >> ohm speaker. > > Ok, thank you for your suggestion. I'm a firmware developer, so I don't > know and never used this analog ICs. > > What about the sample frequency? If I use 22kHz or less, probably it can > be heared from the speaker. How to filter it?
Unless you have severe power constraints or you're already running the processor flat out, you should have plenty of processing available to do up-conversion and filtering in the digital domain. Even so, you'll want to do some low-pass filtering coming out of your DAC channel. How inexpensive do you want the audio circuit to be? If you can stand one op-amp stage in front of your LM386 power stage then you can easily implement a 2nd-order lowpass filter suitable to your sample rate.
>> You may want to stick with an existing compressed audio format, which >> will be much smaller than any uncompressed format. Vorbis is OSS, and >> most audio tools can handle it. Integrating libvorbis is fairly easy >> for decompressing the stream in your device. libvorbisfile is even >> simpler. >> >> You'll need to research how well that'll fit on an M3, though. > > Ok, thank you. I will check.
If libvorbis uses fixed-point arithmetic I suspect you'll be fine. I'm not at all sure of this if it uses floating-point math, however. Be sure to get processor consumption figures once you get it compiling. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
pozz wrote:
> In the past I used a simple piezo buzzer to create very simple sound > effects: beep, beeeeeeeeeep, bip bip bip. Just one tone, but I need only > one GPIO from the MCU and nothing else. > > Now I'd like to improve the audio quality to have a better sound > effects, when the user press a button on a touch screen, when there's an > error, when the operation was processed ok. > > This is now common on electronic gadgets, from GPS navigators to in-home > displays and so on. > > I have a Cortex-M3 MCU with 10-bits DAC peripheral. I'm able to generate > samples at a frequency of 44.1kHz, but I prefer to have lower frequency > to save some Flash memory space, where the audio waveforms will be > saved. For the same reason, I prefer to save the waveform as 8-bits. >
How many seconds of audio do you need? 20 seconds ( seems a lot for beeps ) would be less than one meg @ 44100 8 bit. 88200 bytes. I'd do the samplerate, filtering & word size conversion on a workstation. I'd write a utility on a workstation to convert the samples to a 'C' table struct, then write an open/close/read for them. If you do that and use makefiles, you can have the utility automagically generate the "file system" when the original wave files change. Technically, you're not supposed to use those for commercial work. Your call. I would use CoolEdit myself. You might be able to use Reaper. http://www.mega-nerd.com/SRC/ http://www.mega-nerd.com/libsndfile/
> Could you suggest a schematic block or IC to interface the DAC output to > a small speaker? Could you suggest also the speaker to use (it's a > wall-mounter touch screen, so the user is in front of the gadget)? > > Related to this question, even if not technical: where can I find sound > effects waverforms? I'm not able to generate them myself and I would > avoid ingage an expert for similar things.
https://www.freesound.org/ -- Les Cargill
Il 14/05/2015 22:21, Tim Wescott ha scritto:
> On Thu, 14 May 2015 09:34:38 +0200, pozz wrote: > >> Il 14/05/2015 08:15, Robert Wessel ha scritto: >>> Any OpAmp with the required gain and power output? Something like an >>> LM386? The datasheet has several typical circuits. And any typical 8 >>> ohm speaker. >> >> Ok, thank you for your suggestion. I'm a firmware developer, so I don't >> know and never used this analog ICs. >> >> What about the sample frequency? If I use 22kHz or less, probably it can >> be heared from the speaker. How to filter it? > > Unless you have severe power constraints or you're already running the > processor flat out, you should have plenty of processing available to do > up-conversion and filtering in the digital domain.
Up-conversion? Filtering in digital domain? Yes, I think it could make some calculations in the interrupt. Do you have any example of simple digital-filtering and/or up-conversion? I think I could store the samples at 22kHz and calculate a mean value between two samples for up-conversion to 44kHz. Or use 11kHz and make an up-conversion to 44kHz, calculating additional three intermediate samples with a linear interpolation between two stored samples.
> Even so, you'll want to do some low-pass filtering coming out of your DAC > channel.
Of course, if the samples are outputted at 44kHz, it is simple to filter with a simple low-pass filter. The problem arises if I use low sample frequency.
> How inexpensive do you want the audio circuit to be? If you can stand one > op-amp stage in front of your LM386 power stage then you can easily > implement a 2nd-order lowpass filter suitable to your sample rate.
Ok, thank you for your suggestion.
>>> You may want to stick with an existing compressed audio format, which >>> will be much smaller than any uncompressed format. Vorbis is OSS, and >>> most audio tools can handle it. Integrating libvorbis is fairly easy >>> for decompressing the stream in your device. libvorbisfile is even >>> simpler. >>> >>> You'll need to research how well that'll fit on an M3, though. >> >> Ok, thank you. I will check. > > If libvorbis uses fixed-point arithmetic I suspect you'll be fine. I'm > not at all sure of this if it uses floating-point math, however. Be sure > to get processor consumption figures once you get it compiling.
There a fixed-point (integer) implementation of Vorbis decoder, named Tremor (wiki.xiph.org/Tremor). I think the main problem with this is the memory requirements. LPC1769, the MCU I'm using, has a total of 64kB SRAM, but I use it for emWin graphical libraries, so I don't have too much free space. The Tremor web page says: "Systems with much less then 250KB of codec memory should probably use the slower low memory branch, and should take care to fail gracefully if a call to malloc fails. This will result in the overwhelming majority of Vorbis files decoding correctly." This is the only solution I see, but I don't think it's good for playing just some simple sound effects.
Il 15/05/2015 01:42, Les Cargill ha scritto:
> pozz wrote: >> In the past I used a simple piezo buzzer to create very simple sound >> effects: beep, beeeeeeeeeep, bip bip bip. Just one tone, but I need only >> one GPIO from the MCU and nothing else. >> >> Now I'd like to improve the audio quality to have a better sound >> effects, when the user press a button on a touch screen, when there's an >> error, when the operation was processed ok. >> >> This is now common on electronic gadgets, from GPS navigators to in-home >> displays and so on. >> >> I have a Cortex-M3 MCU with 10-bits DAC peripheral. I'm able to generate >> samples at a frequency of 44.1kHz, but I prefer to have lower frequency >> to save some Flash memory space, where the audio waveforms will be >> saved. For the same reason, I prefer to save the waveform as 8-bits. >> > > How many seconds of audio do you need? 20 seconds ( seems a lot for > beeps ) would be less than one meg @ 44100 8 bit. 88200 bytes.
They are 882000 bytes for 20 seconds, but I'm talking about a MCU with 512kB of internal Flash memory :-)
> I'd do the samplerate, filtering & word size conversion on a > workstation. I'd write a utility on a workstation to convert the > samples to a 'C' table struct, then write an open/close/read > for them. > > If you do that and use makefiles, you can have the utility > automagically generate the "file system" when the original wave > files change.
Yes, of course. I don't use a strictly speaking makefile, but some scripts on my platform that automagically generates C files.
> Technically, you're not supposed to use those for commercial > work. Your call. I would use CoolEdit myself. You might be able > to use Reaper. > > > http://www.mega-nerd.com/SRC/ > http://www.mega-nerd.com/libsndfile/
I use sox for sound conversions.
>> Could you suggest a schematic block or IC to interface the DAC output to >> a small speaker? Could you suggest also the speaker to use (it's a >> wall-mounter touch screen, so the user is in front of the gadget)? >> >> Related to this question, even if not technical: where can I find sound >> effects waverforms? I'm not able to generate them myself and I would >> avoid ingage an expert for similar things. > > https://www.freesound.org/ >
Thank you.
The 2026 Embedded Online Conference