To play 8 bit samples on an OPL2 there is a simple technique to use the test bit to freeze the voltage output from the chip, which can then be controlled by setting the lower 8 bits of the frequency to an 8-bit sample value. 

The original trick was written by Mitsutaka Okazaki.
 
Some background info from Grauw, who helped me get this trick to OPL2. 
 
Details on TEST register and the undocumented bit 2 function
(if 1, resets (and holds, while active) the PG count for Car/Mod at 0 )
 
You can in fact simply write an 8 bit unsigned sample to a channel when the test bit is set (after a bit more preparation) at a proper sample rate and you will hear the sample play. However, the voltage is taken from the sine table on the chip, and that has a slightly different output than you might expect if you were dealing with a linear type of relationship with your unsigned value (you know, $80 being silence, 0 most negative output and 255 most positive). 
The result is that samples may sound slightly different, a bit more "sharp". Grauw took a look at the outputs and constructed a table that accounts for that internal chip look-up. 
 
Here I compare the two methods. The fast, don't look up, just output the sample method, and the Grauw's table method. (Of course, you can convert your samples using Grauw's table before and then still have a fast no-look-up method, but it takes an extra step. 
 
I take a simple approach, play a sample that goes from 0 to 255 and then back to 0 in steps of 1, and that 4 times. I do it without Grauw's conversion and with that conversion. 
 
 
The picture above illustrates how well Grauw's table is doing the trick. Note that the non-converted left wave is a bit louder, but not in proper phase. Where you would expect a maximum (positive or negative) at end of each half of a period, this is the case only after conversion, you see two quarter sines (inverted). So Grauw neatly matched it to the quarter sine output table on the chip. :) 
 
Will you hear a lot difference in the samples? Probably not, especially if you don't know how it should sound. But to the trained ear, there is a slight difference. Nothing to worry about. But we do want things to be perfect. So great work, Grauw! 
 
 
 
 

On the Commodore 64, talking about SID DIGI (sample) play routines, there are many forms. What they all have in common is that they need to use a Timer routine to play samples at a certain rate. The time in cycles that it takes for that Timer interrupt driven sample playback determines the maximum sample rate. 

On a PAL machine, one cycle equals 1.015 microsecond. 

This means, if you wish to have a sample play at 8000 hz (update 8000 times a second), you need to call the sample play routine every 1/8000 = 0.000125 seconds. Or 125 microseconds. This is 125/1.015 = ~123 cycles. Meaning the Timer will need to be set to cause the interrupt at $7b cycles. It also means that the sample playback routine should not spend more than 123 cycles to complete in total, otherwise the next update will start when the previous did not finish yet. Also, if any other stuff needs to be done, like scrollers, graphical stuff, or even a whole game running (for example using other interrupts) things can get tricky if the sample play routine is taking too long, leaving no cycles for other things. 

So let's take a look at some sample playback routines used in the Commodore 64 music scene. 

I. Introduction

If you read a bit about Adlib and the OPL1 or OPL2 chips, many manuals and texts always tell you that you have to wait a number of cycles after a register-select write to the chip, and even more cycles after a register-value write. I also used that in my Edlib music player for the C64 based on that idea. 

When I read through the music player code for the MSX game Xak (that also uses OPL1, the Y8950 or the poor man's version of the OPL2, the YM2413), I noticed that the programmers only waited a bit for the register select output to the YM3812 and did not put any extra waiting loop after register value write. See below for the code. Thus, I went ahead and wanted to know what is the minimum required waiting needed to use the OPL on the C64, and leave more cycles for other coding. Read the whole article by clicking on the Read More button. 

I recently had the honour to give a presentation at X2018 about FM-YAM! I decided to record the same presentation a week later at my home studio for anyone interested that missed the one at X. Check it out here: View the video