8-bit music?

Go To Last Post
27 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is there any way to easily use an AVR to make 8-bit music that is powerful enough to go through standard headphones?

thanks in advance,
green6552

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can build a R-2R ladder using a bunch of resistors and an op-amp. Then the output of the op-amp should be enough to drive a pair of headphones.
Zoltan

Last Edited: Thu. Jan 24, 2008 - 02:56 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Or simply use the pwm feature and a series resistor should give enough signal level.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

8-bit PCM telephony signals use A or mu law companding to have smaller quantization steps (thus more detail) for quiet sounds than large amplitude ones. This matches human hearing which is also logarithmic, and gives acceptable quality for a given information bandwidth.
A linear 8-bit representation of music fed directly into an ordinary d-a is likely to sound noisy.

The PWM output idea has more legs.

Edit: So there are at least two issues to consider.
1. Can music be stored in 8-bit per sample with enough information content to reproduce in an acceptable quality.
2. How to capture and reproduce the music.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Folks are used to hearing 16 bit music, but I bet you could take a a couple of your favorite songs and use an audio editor to convert to mono, 10 or 12 bits and 32khz and save a couple of these on an sd card. Now the cool part... read the fat files from the sd card and play the pcm on the OCR1A output. Saving the music as 12bit doesnt save any space on the sd card... still takes 2 bytes per 12 bit sample, but the 12bit pcm will be a little faster than 16 bit and will sound better. I know telephones use ulaw, but can you run music through that? Sort of compresses it doesnt it? Whats it sounds like? The other option is save your favorite songs as MP3s and use one of those VS101 MP3 decoder chips to play the music.

Imagecraft compiler user

Last Edited: Thu. Jan 24, 2008 - 03:52 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I highly recommend some form of analog circuitry at the back end, to both clean up the signal, and give you control over the amplitude. The speaker in your PC is driven from a 5V square wave, now imagine strapping that speaker to your ear... it's going to be REALLY loud. So to protect your hearing please add some form of attenuation, even if it's as simple as an adjustable pot.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The best way to make quality music with an AVR is to use the AVR to drive a small, inexpensive, high-quality MIDI synthesizer. The best synth, (or rather, tone module - a synth without the keyboard) would be the Yamaha MU-5. This little box is a little smaller than the size of a VHS cassette, has a powered headphone output, and has the full General MIDI instrument set in excellent quality Yamaha XG voices. They are often found on eBay in the Musical Instrument:Synthesizer section for about $30-$40 US. Another excellent low-cost small-size option is the BOSS DS-330 for about $40-$50 or a Roland Sound Canvas unit. These tone modules can always be resold on eBay for what you paid for them.

Then, download MIDI files for the music that you wish to present. This is getting difficult to do because the various global corporations that have deluded themselves into believing that they 'own' music have started threatening jail and fines to anyone who puts MIDI files on the web. But MIDI files can still be found for all types of music.

Third, and this is the hard part, you need to write a program for the AVR that reads the MIDI file and sends the notes to the tone module at the right times. Windows has a single API that plays a MIDI file, but it is do-it-yourself for the AVR. No one seems to have done it before or posted any code application for playing a MIDI file from an AVR. The hardware is trival.

The AVR is a rather difficult platform to use to make music with because its internal resources are too limited. You can, as the other responders, have suggested, configure the AVR to output an 8-bit waveform using a stand-alone DAC, a R-2R ladder, or PWM.

At best this will output a simple repeating waveform, a very brief sound burst, or a selectable repeating complex waveform such as DTMF telephone tones. But making music this way requires a lot of memory that the AVR doesn't have. And attaching a serial EEPROM to hold sound waveform data is unlikely to work well if at all because the I2C 2-wire bus that these chips use is not fast enough for quality music beyond the level of an annoying ring tone.

MIDI files can sound great and can store classical symphonic scores in about 15K bytes per minute of sound. These files can be stored in the unused AVR program memory.

I believe that this is the only realistic way to make music of any length or quality when using (indirectly) an AVR microcontroller.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Direct R-2R ladder OR direct PWM with simple low-pass filter won't drive a low impedance earphone. You would need a driver (often but not always op-amp) to drive any load.

I think you would be REALLY disappointed with 8-bit results.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't forget there are ics like the sta013 and vs1001 out there that have successfully been controlled by AVRs to decode mp3/ogg vorbis streaming from SD cards.

There are plenty of examples on the net for this.

There are not cost or size prohibitive to use.

The Procyon C library even includes routines to control the STA013 and the SD Card access.

For the added complexity you get mp3/ogg vorbis output.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Look at Chan's excellent music project "Wavetable Melody Generator" based on an ATtiny45, with the intention
of sounding like a music box. Your own music can be taken from a score to create a lookup table of notes and
timing. Chan has provided an .mp3 sound file of Beethoven's Für Elise as played by the project.

http://elm-chan.org/works/mxb/report_e.html

Stan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now that I have taken further look into this, it does not really sound like the sort of thing for a quick starter project. Both because it takes a lot of experience, and the fact that some of the parts I have no idea if our local radio shack carries them.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Radio Shack is questionable at best for components. Take a look at Mouser and Digikey, they are 2 great online shops for ordering components.

As for doing this as your first project, yes I agree you should take a step back and try some smaller projects that contain an element of this one first. This way you will build up knowledge. It won't take long, and you'll be ready to take this on.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Okay, I will try some other projects before trying this one. Thanks for your help guys.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

First of all A law and u law is just a 8 bit log of 12 bit. So that will sound like 12 so that is a fine way to save. (the difference is that one of them a lin close to zero and the other is log all the way).
We can't use midi because we then need a midi player.
But reading from a eeprom is not a problem.
with the spi you can get more than 100K byte pr sec (or a SD card) and a 20 KHz update rate will sound fine so it will just take a 20KHz timer interrupt that read a byte and send it out on a port(r2r) or to a DAC.
The only problem is that it will take 1.2 MByte pr minut so a 128MByte SD will hold about 100 min and I think that's fine.
Unless you use one of the very fast PWM's tiny25 or so (where the PWM clk can be 64MHz)I don't think that it will be the way (and the 64MHz have to be the intern clk so 1% out of tune would be a problem).

Jens

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Take a look through the Atmel Application Notes to see the type of projects that are practical, and to get ideas/inspiration. "AVR335: Digital Sound Recorder with AVR and DataFlash" is interesting if audio is your thing.
Have fun.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Radio Shack is questionable at best for components.
I will cast my first vote for the understatement of the year :lol:

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Like Broxbourne says, app note AVR335 is your friend

I play 7200Hz PCM samples using PWM and the 0..3600Hz audio range (aka "telephone quality") actually sounds remarkably good - you want to hear Frank Sinatra from it!

Some issues you'll face is that audio data is large - I use ADPCM to compress it a bit (as AVR @ 8MHz has the guts to decode that on the fly at playback time) but even so you really need to be looking at some form of external data storage for the PCM data unless this is a REALLY big AVR that you are programming. In my case I use Atmel's AT45 DataFlash which is a lovely memory chip to work with.

While our final design has several stages of output filtering on the PWM and then an LM386 for the amplification, while I was developing this I just hung an 8 ohm speaker off the OC1A pin and got something reasonable (though the current involved may not have been great for the AVR - so fine on your dev CPU but not a production solution). There's also a fine art to audio reproduction and "audio cavities" and you'll find that if you put an up turned plastic cup over the speaker you'll get much more power and audio range (a bit like cupping your hands around your mouth when you want to shout to someone in a noisy environment)

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Get hold of a DIL package AVR, and cut all the pins to different lengths. Bear in mind that the good old 12th root of 2 won't help much here - because the pins won't be parallel, so you may have to experiment. Use your fingernail to "ping" these pins next to your ear. Do you hear music, sweet, sweet music? Search for an AVR with tempered steel pins, it will sound better. Attach some magnetic pickups. Congratulations! You've built a tiny Fender Rhodes!

Four legs good, two legs bad, three legs stable.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simple headphone amplifier that could be driven by an AVR. Doesn't solve the other issues, but it's something.
http://tangentsoft.net/audio/cmo...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All Electronics Corp has a 150 ohm cell phone speaker that can be driven to drink by an avr pin.

Rick

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

There's also a fine art to audio reproduction and "audio cavities" and you'll find that if you put an up turned plastic cup over the speaker you'll get much more power and audio range (a bit like cupping your hands around your mouth when you want to shout to someone in a noisy environment)

Sorry but I can’t resist the speaker gets loud because the cup prevent air from just move between the over and under side of the speaker. The two hands aren’t needed to stop air going thru the backdoor I hope. :D

And now to the real thing are there a free ADPCM converter ? (I know that the player is easy to make).

And Rich beat me to it. In intercom systems etc. 150 ohm speakers is very common, but what is the res of a small headset ?

Jens

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Most headphones are 16 ohm nominal impedance, so they need a halfway decent amount of current.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are lots of 600 ohm earphones and, I suspect a bunch or 40 ohm earphones. Get out the meter!

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yeah, there are a lot of headphones ranging from 32 ohm to 600 ohm, I was just saying that the standard, cheap headphones are 16 ohm.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The only problem now would be to get an AVR. The only chip that I could find was a CMOS IC but I do not know if they are the same?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

The only problem now would be to get an AVR. The only chip that I could find was a CMOS IC but I do not know if they are the same?

?!?!?!?!?!?!?!?!?
they are all CMOS and nothing wrong with that.

Jens

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

John_A_Brown wrote:
Get hold of a DIL package AVR, and cut all the pins to different lengths. Bear in mind that the good old 12th root of 2 won't help much here - because the pins won't be parallel, so you may have to experiment. Use your fingernail to "ping" these pins next to your ear. Do you hear music, sweet, sweet music? Search for an AVR with tempered steel pins, it will sound better. Attach some magnetic pickups. Congratulations! You've built a tiny Fender Rhodes!

Hahaha :D sure you can do! Just like that old music box!
I thought this forum is always serious as it was all the time. But this statement really make me laugh. Good job John! :D

KISS - Keep It Simple Stupid!