Close
0%
0%

FM-synth, two voice, Markov sequence, music box

A Markov sequencer, with fractal 1/f transition probabilities, is combined with a two-voice, 16-bit FM synthesizer, running on a 8-bit MCU.

Similar projects worth following
Traditional music boxes play one or two tunes very well, but are not very interactive. Put differently, they have a high quality of synthesis, but a fixed-pattern note sequencer and fixed tonal quality. I wanted to build a device which would play an interesting music-like note sequence, which constantly changed and evolved, with settable timbre, tempo, and beat.


To synthesize nice sounding musical notes you need to control spectral content of the note, the rise time (attack), fall time (decay), and the change in spectral content during attack and decay. Also it is nice to have at least two independent musical voices. And all of this has to be done using the modest arithmetic capability of an 8-bit microcontroller. We use Atmel atmega-series MCUs. The scheme used for the attack and decay envelope was to generate the product of two exponentials, a saturating rise exponential and an exponential decay. The process to convert this complicated sounding envelope into fixed point shifts and adds (and one integer multiply) will be covered below. The spectral content of the notes was enriched using FM modulation, which is widely used for musical and special effects. Since directly computing sine waveforms is also mathematically heavy, direct digital synthesis (DDS) was used to produce waveforms. The DDS scheme explained below is used to generate both the FM modulating sine wave signal and the fundamental sine wave for the musical note.

WINAVR GCC program. (Circuit Cellar version) For Markov music box running on atmega644 or atmega1284 at 16 MHz. Pin B.3 is the PWM output connected through a 10,000 radian/sec lowpass filter to amplified speakers. Port C is hooked to 8 pushbuttons which control transition matrix, tempo, beat pattern, and timbre for each voice.

Published in Circuit Cellar Magazine, #272, pp 28-32, March 2013  (Manuscript) Full algorithm details are in the manuscript.

Examples


References
Markov Music Box Examples and code:
http://people.ece.cornell.edu/land/courses/ece4760...
ml
Auto-Composing Piano, Chaorong Chen and Siyu Zhan
http://people.ece.cornell.edu/land/courses/ece4760...
sz259/index.html and


Tunes from students: Fur Elise:
http://people.ece.cornell.edu/land/courses/ece4760...
Pitch Structure of Melodic Lines: An Interface between Physics and Perception, Jorge E. Useche
and Rafael G. Hurtado, http://palm.mindmodeling.org/cogsci2011/papers/08...

  • Optimizing DSP

    Bruce Land10/03/2018 at 15:07 0 comments

    This build started with optimizing DSP operations on 8-bit Atmel MCU. floating point is too slow, so i designed 16-bit fixed point arithmetic with optimized assembly language inline multiply. Exponential rise-fall dynamics are hard to calculate directly, but are the impulse response of first order ODEs, which can be converted to a single add and shift operation. Thus envelope generation reduces to a few shifts, adds, and two fixed point multiplies.

    The amplitude envelope chosen is the product of two exponentials, a relatively fast rise and slow fall of the form: a(t) = A*exp(-t/τfall)*(1-exp(-t/τrise)) To generate this envelope at 8 KHz with no floating point, some rearrangement of the math and a few simplifications were done. First we note that the differential equation with solution equal to the desired exponential exp(-t/k) is dy/dt = -k*x. Then we quantize the differential equation to a difference equation using an Euler approximation with time step equal to the sample time ∆t, and where n denotes the current sample and n+1 the updated value. [x(n+1) - x(n)]/∆t = -k*x(n)

    rearranging gives x(n+1) = x(n) - ∆t*k*x(n)

    Next, we allow k to be only a negative power of two, say 2^-p ,

    (corresponding a time constant greater than the sample time), and scale k so that ∆t equals one, then we can rewrite the difference equation to x(n+1) = x(n) - (x(n)>>p)

View project log

Enjoy this project?

Share

Discussions

mosaicmerc wrote 02/08/2016 at 21:06 point

Saw your stuff in C. Cellar...GREAT!....PIC is my chip of choice as well.!

  Are you sure? yes | no

Bruce Land wrote 02/09/2016 at 12:28 point

Thanks. The PIC32 is very nice.

  Are you sure? yes | no

Bruce Land wrote 02/04/2016 at 12:48 point

Very true.  It might be more compelling with a order 2 or 3 markov system, but the state transition table gets BIG fast.

  Are you sure? yes | no

danjovic wrote 02/03/2016 at 15:59 point

Amazing! You can use your synthesizer to generate background tune for video games. The mood could change based on the average color of the screen or as how fast you're pressing buttons on the gamepad. It could work as well while you are on hold in calling centers, then the algorithm could use some aspects of the voice like pitch of spectral distribution to generate the notes. 

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates