what should go in a music engine?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
what should go in a music engine?
by on (#159257)
Recently, I rewrote my music engine... and it got me to thinking.

What do you guys consider standard features of an all-purpose music engine for a game. I actually removed pitch shifts (other than vibrato) because I never use them. And I considered adding an echo effect, but that would take up a huge chunk of RAM space (possibly).

Currently, I have all channels available to music, and sound effects available on SQ2, Noise, and DMC. And only have volume envelopes on the Square Channels.

Another consideration, is I don't have a good way to generate data. Currently, I just type it in. I suppose I could write a script to turn a Famitracker text export to work with my engine, but to be honest, I never liked the Famitracker interface. I think, ideally, a good engine should have ease of imputing new data in mind... Which would mean another rewrite, since my engine is not designed for ease of use in mind.

Oh, I think I stop there. I could go on...
Re: what should go in a music engine?
by on (#159267)
My music engine has sound effects on all four tone channels. Drums are considered sound effects: each of 25 drums in a kit has one or two sound effect IDs associated with it. For example, a kick drum might have both a triangle and a noise component. Each sound effect is a list of 2-byte records, with a (duty, volume) value in the first byte and a semitone number in the second.

It also has a primitive priority system. If I start a sound effect on sq1 while sq1 has a sound effect running, it'll spill to sq2. If I start a sound effect on sq1 while both sq1 and sq2 have a sound effect running, it'll spill to whichever channel has fewer bytes left in the current sound effect. If I start a sound effect on a channel that has more bytes left than the length of the sound effect I'm starting, it won't start at all. Finally, the sound effect and musical instrument on each channel are compared every frame for whichever is louder.

An instrument's envelope consists of an attack, which is structured very similarly to a sound effect but with a transpose value instead of an absolute pitch, followed by a volume ramp down.

Because a pattern can be started on any row (not just the first in an "order"), I can set up some channels to loop faster than others (e.g. SMB1 drums), and I can play only the beginning of one pattern with another pattern as its end.
Re: what should go in a music engine?
by on (#159507)
Put duty cycles and volume control together.
Re: what should go in a music engine?
by on (#159511)
@Dwedit

I have that.

I think my current weakness is Sound Fx, and ease of use.

I have this crazy idea of making (one day) a Mario Paint style NES game that can save a song (SRAM) in a usable format for a music engine. In my mind, all you should have to do (to import the song into a game), would be slapping a label "Song1:" with .incbin to the saved song data. But, I think I will need to write a script to parse the saved song, first, into a .asm file with pseudo-labels generated. Or something like that.

Anyway, another project that will get done "in the distant future".
Re: what should go in a music engine?
by on (#159515)
Is your engine meant for game programmers or meant for musicians?
Re: what should go in a music engine?
by on (#159518)
Currently, it's meant for me.

But, eventually I want to get it to a point where it can work as a tool that other people might want to use. Anyway, I'm speaking hypothetically.

And, that's why I was asking what features and special effects it should have.
Re: what should go in a music engine?
by on (#160869)
I've decided to abandon all work on my own music engine, now that I've figured out how to do 95% of what I want with Famitone2...

Volume column, can be simulated by having extra instruments who's volume pattern peaks at 8 (or 4) rather than F.

Tremolo, done by looping a volume pattern '| f e d c b c d e'

Vibrato, done by looping a pitch pattern '| -2 -1 1 2 2 1 -1 -2'

Arpeggio can also be done with a looped pitch pattern... '| -30 -40 70'
(or maybe several, since they will be out of tune as you go up or down on the base note)

Pitch bends, looped pitch pattern '| 0 -1'

I think Famitone2 uses fewer bytes to store data (not counting sound fx) than mine.

And, I finally figured out how to utilize an external MIDI keyboard without tearing my hair out. Apparently, in Famitracker, press 'insert' to bump everything below the highlighted point down one.(needed, because I thought I'd have to cut/paste every note after keying them in). [and 'backspace' to bump everything below highlighted point up one, (will delete the line above highlighted line)].