Refactoring Music Playback
Updated: Feb 21, 2022
In my post Working on game music... need storage, I had started building game music and ran out of EEPROM space to store the music. Also, my approach to control the music with 6502 assembly was not very dynamic; it required specific calls (and a lot of them) to play back the one example song (well, the portions of it I had done). Now that I have my SD Card working (see the bottom of this post), I essentially have unlimited storage for 6502 assets, including sound effects, sprites, music, etc. I have started refactoring my approach to music.
First, I have developed a utility that allows me to create binary data to represent a song, measure by measure. This utility supports all four programmable sound generators (PSGs) and the three channels per PSG. For the initial prototype, I have simplified it to mirror the left and right audio channels. Later, I can double the size of the form and number of inputs to give that additional flexibility.
In the above utility, you can specify the note and octave and whether or not the note should tie to the next note on that channel. This control can be done per PSG (CH1-6 on the left of the screen). Each screen is a single measure, with support right now of notes that are no faster than 1/12th of the measure in duration. I can change the playback speed per measure. Also, I can save, open, and export the music. When exporting, all options are automatically converted to the appropriate PSG commands, tone frequencies, etc.
Next, I am working on the 6502 code to dynamically play back this binary data. This will result in 6502 assembly code that does not need to change when I want to play different music. Rather, the code is dynamic enough to read the music I have saved in the appropriate binary format on the SD Card. Much of this playback functionality is already in place, as seen here, where the binary data is streamed from a PC to the 6502 and played dynamically by the 6502.
Hopefully, in the coming weeks, I will be able to complete the playback of the first song I was working on (I am not writing the music itself). The biggest unknown for me right now is the overall performance when reading from the SD Card (how fast can the music move before I have issues?). I will post more details when I get farther along.
I was able to implement dynamic playback from SD Card storage. Some tweaking is needed, but overall, seems to be working well.
The above recording was done with a mono microphone, picking up the output of the speakers connected to my sound card. The recording quality isn't great. Previously, when I tried to grab the audio on my PC, directly from the sound card to the PC, the quality was also poor. My PC did not like the amplified signal (too hot). I decided to add an additional connection to my sound card that is a pre-amp line out. Below is a recording using that line out connection directly into my PC.
Here's a recording using the same AY-3-8910 PSGs as above, followed by YM-2149 PSGs (with 2 MHz and 4 MHz oscillators). I'm not sure if I can hear a difference. I'm curious if you can hear a difference. Also, I hear that many of the new, inexpensive AY-3-8910 PSGs (e.g., on Ebay) are actually YM-2149 PSGs labelled as AY-3-8910 PSGs.
And with some wiring clean-up...