I am definitely not an expert in music theory. I just gave myself a crash course via google and it seems to have been enough so far.
I am also new to Love, and also to Lua but I have been doing software development for many years, much of it in signal processing, so it's not entirely foreign.
The original I took mostly as inspiration, and didn't end up using much of the code. I hereby release "mgen" v 0.1 under the MIT license for anyone to use and/or modify for any purpose, but with no warranty.
Comments or questions welcome
Musical: automatic music generation
Re: Musical: automatic music generation
- Attachments
-
- mgen_v0.1.love
- (2.22 KiB) Downloaded 212 times
Re: Musical: automatic music generation
do you know it's AWESOME ? <3Jamie wrote:Comments or questions welcome
Current work : Isömap
Re: Musical: automatic music generation
Very well done. And so simple.Jamie wrote:Comments or questions welcome
I am missing the 6th cord (A C E, "a minor") which is very common on a c-major scale. Try the following cadence: "66445511"
I have a couple of suggestions from a musicians point of view (in case you like to play around with it):
- As far as I understood your code, at each time you have a fixed chord and from this you randomly select (one or three) notes and play these. You will probably get a more balanced sound if you divide the three voices in to a high voice, a middle voice and bass voice (or even make four voices like in a classical choir). Each voice should have it's own tonal range from which it selects notes. That way the highest voice will most probably create something like a melody.
- The bass voice should almost always play the bass note (if the chord is a 5, the bass voice should play the 5, not the 7 or 2)
- To create a greater variety of melodies, you can allow the top voice to play notes that are not contained in the chord. However this should only happen on offbeats (that is the 2nd and 4th beat of each bar).
- Maybe you want to add rythmic patterns. By that I mean instead of playing a note at all four beats in a bar (like "1111") you can define a pattern like "1101" or "1010" or whatever you imagine and let the top voice only play a note on the beats marked with 1.
Check out my blog on gamedev
Re: Musical: automatic music generation
Great suggestions, this is just the kind of thing I need, from someone who knows more about music. I'll try these things. Thanks!micha wrote:I am missing the 6th cord (A C E, "a minor") which is very common on a c-major scale. Try the following cadence: "66445511"
I have a couple of suggestions from a musicians point of view (in case you like to play around with it):
- As far as I understood your code, at each time you have a fixed chord and from this you randomly select (one or three) notes and play these. You will probably get a more balanced sound if you divide the three voices in to a high voice, a middle voice and bass voice (or even make four voices like in a classical choir). Each voice should have it's own tonal range from which it selects notes. That way the highest voice will most probably create something like a melody.
- The bass voice should almost always play the bass note (if the chord is a 5, the bass voice should play the 5, not the 7 or 2)
- To create a greater variety of melodies, you can allow the top voice to play notes that are not contained in the chord. However this should only happen on offbeats (that is the 2nd and 4th beat of each bar).
- Maybe you want to add rythmic patterns. By that I mean instead of playing a note at all four beats in a bar (like "1111") you can define a pattern like "1101" or "1010" or whatever you imagine and let the top voice only play a note on the beats marked with 1.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Musical: automatic music generation
Interesting stuff, Jamie. I might use some of that code for my game.
If you want to do more with mgen (and keep us informed) it might be a good idea to start a new thread for it, so people don't get confused and things.
It might take me a few months (six or so) before I'm able to work on this again, though, depending on how busy I'll be.
If you want to do more with mgen (and keep us informed) it might be a good idea to start a new thread for it, so people don't get confused and things.
Cool. You have a background in music theory? (Or music practice? )Tesselode wrote:I can help you with musical stuff if you want.
It might take me a few months (six or so) before I'm able to work on this again, though, depending on how busy I'll be.
Help us help you: attach a .love.
Re: Musical: automatic music generation
I know enough music theory to make things that sound nice.Robin wrote:Interesting stuff, Jamie. I might use some of that code for my game.
If you want to do more with mgen (and keep us informed) it might be a good idea to start a new thread for it, so people don't get confused and things.
Cool. You have a background in music theory? (Or music practice? )Tesselode wrote:I can help you with musical stuff if you want.
It might take me a few months (six or so) before I'm able to work on this again, though, depending on how busy I'll be.
Re: Musical: automatic music generation
I'm very impressed! Maybe add a setting where it generates a random song and then loops over and over again, instead of keeping it nonstop random.Jamie wrote:
Comments or questions welcome
Re: Musical: automatic music generation
That's so awesome! I extracted your mgen code into its own script to make it more modular and then wrote a short loop for it to play...Jamie wrote:I hereby release "mgen" v 0.1 under the MIT license for anyone to use and/or modify for any purpose, but with no warranty.
- Attachments
-
- mgen_obeytown.love
- A small example of mgen being used to play "Obeytown"
- (2.29 KiB) Downloaded 176 times
Have you met the Child of Winter?
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Musical: automatic music generation
Let me start by saying that I love everything procedural, so I'm loving what I see on this thread
Now, I'd like to report a small issue. I don't know how to explain this well, since I lack the required vocabulary. So bare with me.
On the file the OP (musical.love) I'm getting very annoying 'static flicks' at the end of most notes. They sound like a PC speaker when you turn it off, only less audible. But they're very distracting nonetheless.
On the other two (mgen*.love) I'm getting the notes very well, with no static.
This is on a Mac, in case it helps.
Now, I'd like to report a small issue. I don't know how to explain this well, since I lack the required vocabulary. So bare with me.
On the file the OP (musical.love) I'm getting very annoying 'static flicks' at the end of most notes. They sound like a PC speaker when you turn it off, only less audible. But they're very distracting nonetheless.
On the other two (mgen*.love) I'm getting the notes very well, with no static.
This is on a Mac, in case it helps.
When I write def I mean function.
Re: Musical: automatic music generation
I believe the soft tick sounds are due to the sample ending 'abruptly'. If the waveform ends at a point where the sin function has not returned to zero, then it has a discontinuity at the end where it effectively jumps to zero. It doesn't occur at the beginning of the notes because since sin() starts from zero, the waveform won't have a discontinuity at the beginning. The magnitude of the discontinuity at the end will depend on whether the sample length is close to an even multiple of the period, which I think is why it appears on some notes and not on others.kikito wrote:Let me start by saying that I love everything procedural, so I'm loving what I see on this thread
Now, I'd like to report a small issue. I don't know how to explain this well, since I lack the required vocabulary. So bare with me.
On the file the OP (musical.love) I'm getting very annoying 'static flicks' at the end of most notes. They sound like a PC speaker when you turn it off, only less audible. But they're very distracting nonetheless.
On the other two (mgen*.love) I'm getting the notes very well, with no static.
This is on a Mac, in case it helps.
Within mgen, I have an extra smoothing at the beginning and end, where the attack and decay is not instantaneous, but goes from zero to full amplitude over a small but nonzero interval at the beginning and the end. The envelope function specifies this behavior and by default it has a quick ramp from 0 to 100% over 1/10th of the note duration.
Within musical.zip, if you replace 'instrument' with the following, it smooths out the discontinuity and the ticks go away:
Code: Select all
local function instrument(t, len, freq)
local pct = t/len
local env = math.min(1, pct*100, 100-100*pct)
return env * (.5 * sin(c * t * freq) + .3 * sin(c * t * (freq + 1)) + .3 * sin(c * t * (freq - 1)))
end
-Jamie
Who is online
Users browsing this forum: Google [Bot] and 6 guests