How to improve audio quality for sound effects

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.

Reply to
pozz
Loading thread data ...

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.

Reply to
Robert Wessel

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)?

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.

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"!
Reply to
Don Y

Il 14/05/2015 08:15, Robert Wessel ha scritto:

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?

Ok, thank you. I will check.

Reply to
pozz

Il 14/05/2015 08:45, Don Y ha scritto:

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.

Sincerely I don't know. Anyway the user is in front of the electronic device, that is a touch panel mounted on a wall.

Similar to an Android mobile phone when you touch a button (and you have the sound effects enabled, of course).

Of course, I need public-domain or similar sound effects.

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?).

Yes, I know. In fact I'm finding very simple and short sound effects.

Reply to
pozz

Beep, boop, click are possible with a monophonic synthesizer. The Windows-style "TaDa" is homophonic requiring a bit more complexity in the synthesis.

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

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.

Each of these are easy to do with just a monophonic square wave synthesizer. How you control *volume* is a separate issue...

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.)

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

Reply to
Don Y

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.

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
Reply to
Tim Wescott

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.

formatting link
formatting link

formatting link

--
Les Cargill
Reply to
Les Cargill

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.

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.

Ok, thank you for your suggestion.

There a fixed-po "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.

Reply to
pozz

They are 882000 bytes for 20 seconds, but I'm talking about a MCU with

512kB of internal Flash memory :-)

Yes, of course. I don't use a strictly speaking makefile, but some scripts on my platform that automagically generates C files.

I use sox for sound conversions.

Thank you.

Reply to
pozz

go check the libraries from mbed.org. They should have codecs of many formats ready for your CPU. There should be at least the decoder for mp3, since I used it (in another CPU though).

Bye Jack

--
Yoda of Borg am I! Assimilated shall you be! Futile resistance is, hmm?
Reply to
Jack

Op Thu, 14 May 2015 09:34:38 +0200 schreef pozz :

Bad excuse. How do you know how to configure your I/O pins if you can't read simple circuit diagrams? How can you communicate with your hardware engineer?

--
(Remove the obvious prefix to reply privately.) 
Gemaakt met Opera's e-mailprogramma: http://www.opera.com/mail/
Reply to
Boudewijn Dijkstra

I couldn't find anything useful. The only things I found is related to an external MP3 decoder IC, so the decoding process is *not* performed directly by the MCU.

Reply to
pozz

Yes, just be a bit flexible about the sounds. E.g. beep is a sine or even a square wave, boop is a lower frequency beep, click is a short pulse, tada is a chord (three simultaneous beeps of different frequencies) followed by a different chord, etc. This stuff can all be done with a few dozen bytes of program space. You can get other effects like sirens by playing a tone while sweeping the frequency back and forth. Look into how old audio synthesizers worked. Before that, it was done completely with analog circuits like voltage-controlled oscillators.

Reply to
Paul Rubin

Then you're back to synthesizing sounds.

I suspect that a system that lets you specify several components, and within that lets you specify the frequency and envelope of each component, should give you a bunch of different sounds to play with.

--

Tim Wescott 
Wescott Design Services 
http://www.wescottdesign.com
Reply to
Tim Wescott

You don't even need *that* much (for the samples the OP claimed).

I implemented a "sound device" in an old 8b machine:

SAMPLE: VOLUME 8 TEMPO 60 SCALE4: PLAY C4 1 PLAY D4 1 PLAY E4 1 PLAY F4 1 PLAY G4 1 PLAY A4 1 PLAY B4 1 PLAY C5 3 DONE

would play an ascending scale, holding the final note for a longer period of time, while:

STACCATO4: STACCATO TEMPO 100 CALL SCALE4 DONE

would play the same at a brisker tempo and with a staccato effect.

I was only generating squarewaves (through a hefty low pass) but the same approach could generate sine waves and, running multiple instances of the "device" mapped to the same driver would allow for polyphonic effects (volume would have to be mapped back into the sample stream to allow for each to have a different intensity).

CMUSIC provides some excellent ideas re: how you could organize arbitrary effects (hint: *pull* samples to the output device instead of *pushing* them through)

Reply to
Don Y

Echh! Okay then :) I just knew the Coretex had .5 GB available.

Ach. Good.

Well, I got one answer right anyway. :)

--
Les Carfgill
Reply to
Les Cargill

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.