Complete beginner on sound programming

For anything related to sound (YM2612, PSG, Z80, PCM...)

Moderator: BigEvilCorporation

Post Reply
lorix
Newbie
Posts: 4
Joined: Sat Aug 30, 2014 12:37 pm
Location: Italy

Complete beginner on sound programming

Post by lorix » Sat Aug 30, 2014 1:13 pm

Hi everyone. I started programming for Megadrive last year, and after learning assembly and some basics concepts of the hardware I tried fixing some bugs for the Sonic the Hedgehog games using the disassemblies on github. Months later I disassembled a game successfully through Exodus (great tool), and I labelled and aligned everything properly so that the game won't break even if data is shifted. I even released a simple hack of it.

The problem is I wanted to fix some bugs related to sound, but I don't know anything about it. I tried reading some documents, I looked on the Sonic Retro website (they have some tutorial pages for music hacking), but it was too hard, and besides they use a lot of technical words. How did you start learning about sound? What documents or tools are there for complete beginners? I don't expect anyone to hold my hand and this is probably a hard subject per se, but at least I would like some hints about where to start.

Thank you.

twosixonetwo
Very interested
Posts: 58
Joined: Tue Feb 25, 2014 3:38 pm

Post by twosixonetwo » Sat Aug 30, 2014 6:11 pm

Can you name some specific things that made you trouble understanding?
I guess recreating sounds with FM synthesis is one of the most unintuitive thing in sound programming for the mega drive, but for your first tests you could limit yourself to basic sine-waves. Also sample output is not so easy to get to sound good, so this wouldn't be the first thing I would look into...

lorix
Newbie
Posts: 4
Joined: Sat Aug 30, 2014 12:37 pm
Location: Italy

Post by lorix » Sat Aug 30, 2014 7:34 pm

What tools would you recommend in making basic sine waves? If it's too complicated for old consoles like the megadrive, isn't there a more general program to help me out with this so that I can test?

To be honest, I tried googling a lot for documents about audio/sound programming in general or programs to try things out, but it's hard to find something beginner-friendly. As I said in my previous post, I don't think that will make things much easier, but it would be a start. Maybe I'll just have to do it by trial and error. [/quote]

twosixonetwo
Very interested
Posts: 58
Joined: Tue Feb 25, 2014 3:38 pm

Post by twosixonetwo » Sun Aug 31, 2014 1:40 pm

lorix wrote:What tools would you recommend in making basic sine waves?
The Mega Drive :D
The Mega Drive gives zou access to two sound chips: The YM2612 and the PSG SN76489.
The first gives you 6 voices (channels), so without further trickery you can play 6 notes on the YM2612 at the same time. The way these notes sound is controlled by many parameters: Each voice consists of 4 sine-oscillators which modulate each others phase. This means, the amplitude of one oscillator shifts the wave of another oscillator thereby deforming it and creating overtones.
This is pretty unintuitive at first, which is why I thougth playing around with sine-waves first might be the easiest thing to do: if you set the YM2612 up, so that the oscillators don't modulate each other, you pretty much limit the output to sinewaves.

Basically what you want to do if you want sound from the YM2612 that isn't sample output is this:

1. Setup the registers of the YM2612 that controll the sound for the channel.
2. Setup the frequency registers for the channel.
3. Set a key-on.

Now the YM2612 should play a note.

Here are some register writes which produce a sound:

Code: Select all

part
|
|    register
|    |        
|    |     value
|    |     |
v    v     v
0, 0x22, 0x00  // Global: LFO disable
0, 0xB0, 0x30  // Algorithm, Feedback <- pure sine wave
0, 0x3C, 0x01  // Operator 4.MUL = 1
0, 0xB4, 0xC0  // Stereo output
0, 0x44, 0x7F  // Mute operator 3  <- pure sine wave
0, 0x4C, 0x00  // Max volume for operator 4
0, 0x5C, 0x1F  // Operator 4.AR = shortest
0, 0x6C, 0x06  // Operator 4.D1R= 6
0, 0x7C, 0x1F  // Operator 4.D2R= 31
0, 0x8C, 0xFF  // Operator 4.SL = 15 / Operator4. RR=15
0, 0xA4, 0x3F  // Frequency MSB
0, 0xA0, 0xFF  // Frequency LSB
0, 0x28, 0x00  // KEY OFF
0, 0x28, 0xF0  // KEY ON
Note that you have to wait for a short period of time in between writes to the YM2612.

lorix
Newbie
Posts: 4
Joined: Sat Aug 30, 2014 12:37 pm
Location: Italy

Post by lorix » Sun Aug 31, 2014 3:12 pm

Thanks for the input. I'll try this out :)

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests