I created a small html parsing library that I didnt know what to do with. Create a bot? To what end could I, or anyone, benefit from a bot? Instead, I decided on the most pointless idea: Scrape craigslist ads to generate music. So, I created a basic chiptune-like system that would generate songs from these scraped ads. After porting to C# and implementing inside unity, this is what I have created.
For each ad, it will determine if it will use a major or minor scale. Then, it will decide on a heptatonic scale from a western diatonic scale pattern where, if minor, will be in its "natural minor" form.
Once the scale's tonic gets decided, a 1 octave table gets created for each frequency of notes based on an 88 key piano. The final octave gets decided in a range of +2 and -2 from the 4th octave of the piano - this range is fairly arbitrary because certain waveforms at higher pitches sound.... terribly screechy.
Finally, the ad will generate the actual phrasing of the song based on 2, 4, 8, or 16 4/4 measure phrases in 2 forms: a bridge and a melody. A bridge is a beat-only phrase that can be 2 or 4 measures that will set a new beat style for the melody phrase - which can be 8 or 16 measures.
Beats are hard set to ensure some level of sanity when listening. As of right now, there are 6 possible beat patterns that I created.
The melody is generated based on each character in every word of the ad posting. In simple terms: 1 character means 1 note. There are exceptions based on ad length and the algorithm used to ensure songs wont be too long - which could take waaay tooooo looooong to generate. But, each note is essentially an index into the scale table that was generated(or a rest), and a note's time step(quarter, eighth, sixteenth, etc), and the notes final length as a subset of the time step.
There are 4 audio layers that are used in each song: Low, Mid, High, Melody. Low, Mid, and High are reserved for beats, and melody is for the actual song melody. This gives me 4 channels of audio of which that I wanted to set. Each layer is given its own waveform pattern. I have utilized the classic 8-bit waveform patterns for simplicity: Sin, Sawtooth, Triangle, and Square, and then I played around and found that adding a Concave and Convex Triangle adds a nice variety.
Each note is compiled into the raw sample data that is sent to your audio hardware to be played. This is where using unity has it's advantages because I can just treat the raw data as if it is an uncompressed wav and just fill the buffer with the data and hit play. The sample rate used is 44100hz and I generate sound waves based on the speed of sound in air at 68 degrees at sea level - this is what the temperature was outside according to google at the time :)
Testing wave patterns: https://www.desmos.com/calculator
Creating different beat types: https://splice.com/sounds/beatmaker