Probabalistic Music Generation
From ECE Department Wiki
Contents |
Project Overview
Probablisitic Music GenerationMembers
Advisor
Additional Help
Technical Documents
Hardware/Troubleshooting
===Board Development===Our first goal as far as hardware went was to get an operational DSP board. The board we used was started by the DSP Scholar Team and was pushed along by the Probabilistic Music Generation senior design group. We came into the project having to lead and help trouble shoot the existing board.
Known problems with the first board 1. The biggest problem that occurred was with power and ground. During layout the netlists where not properly labeled and most of the 5 V, 3.3 V, 1.9 V and ground lines were not connected together. Many of the troubles with the board are solved by simply connecting the proper pins to power and ground.
2. The next biggest issue with the board is that there was no external crystal for the DSP. It was thought that the DSP had an internal fully functional oscillator but this is not the case. You need to have an external crystal from 28Mhz to 30Mhz. It is also possible to use an oscillator if you do not want to use the internal oscillator.
3. The reset pin was not connected to anything. It needs to be high (3.3 volts) for normal operation and grounded for reset.
4. Darlington array had com pin connected to ground. This will cause the 8 LEDs to remain on no matter what you do to the inputs. The Com pin should either be a NC or to power.
5. The codec was originally going to be clocked off of the DSP clock output that can be clocked at multiples of the system clock on the DSP. This unfortunately will not work for our case because of the multiples in which the clock out is available in. We need a more exact clock, more specifically we need a 11.2986 MHz oscillator to clock our binary counter which in turn creates two clocks for the McBSP and the DSP. These clocks run at 44.1 kHz and 1.412325 MHz.
6. There are issues with planes and analog signals. To separate the planes there are plane obstructs between a analog ground and digital ground. To eliminate ground ground loops connect the ground planes where traces cross the boarder.
7. The Filter that follows the CODEC was designed to have a 4 KHz cut-off frequency. We redesigned it for 24 kHz.
8. 1.9 volt power up delay. The Power supply on the main board has an enable pin for the 3.3 V and 1.9 V line. We want to power up the 3.3 V line first to allow all the peripherals to be functional before we power up the DSP core. The delay is a voltage divider that waits for the 3.3 V line to get to 2.8 V before the 1.9 V line is enabled.
===Schematics===
We have two separate boards one that is always powered and controls the main board and the main board. The Daughter board is shown below. The Daughter board has the button interface, soft power on/off, reset, and battery/wall wart circuitry on it.
The main board is the board that has our processor and supporting components on it.
Software/Programming
All of our code was written in Code Composer Studio. We wrote our code to run on the TI 2812 DSP.
Most of the coding involved setting up the DSP and initializing all of the peripheral devices. After we got the DSP running in a stable condition, we integrated our algorithms into our code. Below is most of the code used in our project.
Algorithm Development
Markov Chains
The first part of the algorithm is finding a way to produce random music. This was done through Markov Chains. The idea is that based on the current state there is a probability of several next states to happen.
Take this musical example.
| A | B | C | |
|---|---|---|---|
| A | 50% | 40% | 10% |
| B | 10% | 10% | 80% |
| C | 0% | 60% | 40% |
Lets say you are on an A note. There is a 50% chance of repeating the note and playing an A again, 40% of a B, and a 10% chance of a C. When you roll the dice, you end up with a B. Now with your B. You do this over again, and perhaps end up with a C.
What you get is string of notes that are shaped by the probabilities of the table. (For more information check out Midi Analysis-Table generation below).
Initial this is how we generated our music at first, we based the next note off of the previous. From this we can begin to expand, lets base the next note off of the previous two notes. Again looking at the table...
| A | B | |
|---|---|---|
| AA | 30% | 70% |
| AB | 10% | 90% |
| BA | 0% | 100% |
| BB | 50% | 50% |
In AB case, A the last note and B is the current note. It has a 10% chance of a A 90% chance of a B as the next note. This will began to produce more phrased music.
Our Design
We used a First Order Table for duration. It is a 5 by 5 duration probability table. The notes are whole, half, quarter, eighth, and a eighth note triplet.
We used a Second Order Table for pitch. It is a 36 by 36 by 36 pitch probability table. The 1st dimension is two notes ago, 2nd is last note, and the 3rd is the next note to be played.
Analysis
Probability Table Analysis
To develop these tables we used midi analysis. This was aided by a free MIDI toolbox[1]. We use the toolbox to change each MIDI file into a note table. This table was analyzed for two note transitions. There was some checking to make make sure the analysis was correct. If a note was more then one measure from the last note then it was not counted. If multiple notes are played at the same time then those transitions are weighed less. This transition table was turned in a probability table; the more times a transition happened the greater the probability of it.
Analysis of Musical Instruments
We wanted to provide different options for instruments beside a pure sine wave. To do this we analyzed music clips from actual instruments to learn which harmonics are involved and how they act over time. For example, some instruments have higher harmonics in the initial attack of the instrument and these decay faster then the fundamental. If we can characterize these envelopes then we can try to accurately reproduce music.
Now lets look at how these harmonics act over time.
Now to reproduce the note follow these harmonic envelopes. It is a good attempt to produces a instrument that is similar sounding.
