AVR Microcontroller
projects and tutorials
Site under construction....

avr-sound

Published on 3. August 2018
avr-sound on Github

avr-sound TL;DR
  • Currently for AtMega328P only!!!
  • Initialise the library with F_CPU and sample rate of your choose
    (check this list for safer samplerates)
  • put stuff in the buffer and tell what is its frequency in your sample rate
  • choose another frequency - what do you want to play with waveform
  • timer plays the tone automatically in background timer interrupt
  • up to three(3) sounds with same waveform at a time!
  • MIDI note numbers to Hz calculation
  • example code with polyphonic sound and waveform generation (3 waveforms) included!
  • Approximate note processing speed: one note in (F_CPU as MHz) / 3 ms; 16MHz -> 5ms
  • If with 16MHz clock speed, you put 12 notes per second with 3-sound-polyphony, time consumption is 180ms = ~18% MCU power - DISCLAIMER: this is a rough approximation, but you can test it. This is surprisingly fast!
To do
  • Sound effects

Here is how it sounds:

I had an idea of creating an 8-bit chiptune synth with MIDI, SD Card reader, Music player and so on... The project seems to be very large and I have already done some revisions to the original one, so I decided to build this in easy way - module by module - so the whole project won't be so complicated.

So the first interesting piece is - of course - an audio library for AVR, and to be correct, yet only for AtMega328P. (You can use this straight with your Arduino also, but I haven't tested it because I like to do things "hard way" ;) ).

If you use my library, please give me some feedback to vp@wdr.fi.
Feel free to contribute @ GitHub! Thank you!