More thoughts on audio..

A few weeks back, I did a mini music player for the 8k compo. I converted the Unreal SuperHero 3 song to this mini format. It’s not particularly impressive in sound, but I’m proud to have gotten the size down as small as it is. 4300bytes before compression, ~2300bytes after compression. Includes song data and all samples.

But that’s not what I’ve been thinking of lately. I’ve been revisiting some ideas I’ve previously had that I never really explored. Hard sync was one of them. When I original had done hard sync testing, I was turning the channel and volume on/off – which isn’t the best idea for non A revisions of the 6280. After having done audio tests with Ryphecha of Borg… err Mednafen, I was pretty excited to learn of new behavior of the audio chip – that worked on both revisions and without additional sound artifacts.

Here’s a brief introduction to hard sync. The simplest way to make a music note sound, is to have a ‘carrier’ output a tone that resonates at a specific frequency. An oscillator and its waveform output. With hard sync, you have a second oscillator that runs at a different frequency from the ‘carrier’. Instead of outputting a sound, the oscillator ‘resets’ the carriers waveform position when the hard sync oscillator overflows. There are two ways to setup hard sync. One is to have the hard sync OSC slightly below the frequency of the carrier, this will cause it to drift in and out of phase. You get a bending of the carriers sound. You can attach low frequency envelopes to ‘sweep’ or slowly increment/decrement the frequency of either oscillator (hard sync one or the carrier or both). Because of the harshness of the resetting, certain types of waveforms are more forgiving of the aliasing of hard sync. Newer synths and PC soft synths correct the sudden change, but older synths did not. Hard sync was fairly popular with older synths. It’s even used in the SID chip of the C64.

Now, the second setup of hard sync is a little more complex. A note is waveform that resonates at a specific frequency. It’s the speed of the output divided by the size of the cycle (waveform length), that gives the final note frequency. If you run an OSC for the hard sync modulator at higher than the ‘carrier’ OSC, then the carrier OSC never has a chance to finish or complete its waveform cycle. The result is that the hard sync OSC is basically now the new carrier frequency control. Because it now directly controls the length of the waveform, by resetting it earlier than it should. You have a new waveform or cycle size; cycle/speed = note frequency. Here’s the interesting part, if you keep the hard sync OSC fixed, but slightly change the carrier frequency (at a low rate like 20-30hz) – you change the timbre of the sound. This is also where other waveforms come into play. A waveform like Sine now gives a much better results than either saw or square.

How does this relate to the PCE audio? There no such hard sync hardware, true. But there is something you can do to emulate that. It requires the 7khz TIMER interrupt. Using a 16bit phase accumulator with the whole 16bit value as the radix, and overflow as the sync trigger. Phase accumulators are dead easy to do. I’ve used them to do sample-based synth on the PCE. The PCE audio hardware itself provides the carrier. You provide a frequency envelope for both the soft OSC and the PCE’s frequency/period of the channel. The rest should be obvious. Congrats, you now have single channel timbre control. But there is a draw back (isn’t there always?). 7kz is a bit coarse, relatively speaking. The phase accumulator takes care of keeping the oscillation in tune by using the carrier over after roll over, but that doesn’t mean you won’t get some artifacting. Since the base frequency of the PHA is 7khz, the result is obviously going to be a bit dirty. To me, it’s worth the trade off to create a more synthy sound. And the resource is pretty light (not samples to fetch and write, no banks to map, etc). Remember, you’re not going to be playing notes at 7kz, hell not even at 2kz. C-6 is a pretty damn high note, and that’s 1.045khz frequency. The 7khz is there for the phase accumulator. You don’t need to play samples in between each each hard sync OSC overflow, nor in between. That’s pretty damn great, IMO.

The above is pretty solid in approach. But there’s more. There are other synth techniques out there, for creating unique and controllable timbre. One of them is wavetable synthesis. Not to be confused with sample-based synthesis (which is what XM/mod/SPC and such use). Wavetable synth is basically a system similar to the PCE’s audio. You playback small/short waveforms to create a tone. But the difference, is that you change the waveform out overtime. A low frequency envelope controls this. It’s a means to control the timbre of the sound. You can emulate all kinds of sound in this manner, include some FM sounds to even some complex filter sweep sounds. Look up PPG on youtube to get an idea of how this sounds. One the PCE, this could be easily doable if it weren’t for one small thing… you don’t know where the PCE’s channel waveform pointer is – at any point in time. With the exception of when you reset it. I’ve probably mentioned this before, but Bloody Wolf attempts to emulator wavetable synthesis. But it doesn’t now the waveform pointer position, so it just resets it and uploads a new waveform. The drawback is a slight click sound at whatever frequency the low frequency envelope is swapping out channel waveforms. The sound, or instrument, in particular for Bloody Wolf – is the trumpet sound. It’s a sharp saw tooth waveform the gradually changes into a soft edged saw tooth. The low frequency clickyness makes the sound a bit dirty, but it seems to be more forgiving as an trumpet model. That, and there’s a lot of other sounds being played at the same time to help mask this.

The convenient thing for us, is that when you use hard sync as the cycle driving OSC (higher frequency than the actual carrier), is that you always know where the waveform pointer is. Oh… how nice, ehh? What a perfect opportunity to change out the waveform – if you so wanted to. So not only could you control timbre by means of speeding up or down the carrier frequency, but now you have a convenient way to update the waveform. Can you say timbre+frequency filter simulation? I can 😉

Hard sync and/or wavetable synth not your thing? Well, let me introduce you to LA synth. No, it’s not some stupid brand name product or fitness place or even a new shoe. It’s Linear Arithmetic synthesis. The name is totally misleading. The most important part of the idea behind LA synth, is that the attack part of an instrument phase, is the more complicated part to create or replicate. With this idea in mind, the creators of LA synth came up with a system that uses PCM samples for the attack phase, and real time synth for the rest. This idea can work well for the PCE. It also very much so lacks in the attack department of an instrument sound. The attack part of an instrument sound is also very short. This is nice in that it doesn’t take as much space. There’s also another convenient aspect about the attack phase… being that it’s short, there’s almost never any pitch modulation or sliding during this phase. This means you can have a complex attack part for an instrument, then switch over the normal PCE channel waveform output – and still be able to do vibrato, detune, frequency slide, and slide to note. That’s pretty important. The down side, is that the instrument building process becomes more complex.. like a synth. Instead of just tweaking a sound/tone until you found something you like – you take more of a modeling approach. And this unfortunately requires more much experience than simple tone+vol envelope+vibrato or such. Here’s an interesting fact; Batman for the PCE uses a very similar technique to build the bass guitar sound. That’s the output of just the sample channel of Batman. It has the attack part of the guitar, and the loop/tone phase of the guitar. But in that game, they sample for both (they have a loop point for the DDA sample). There isn’t a need for note sliding for such bass playing, so they aren’t limiting themselves. A nice strong pluck sound there too. Notice the almost absence of ‘noise/static’ from the sample too. I’ve ripped all the bass guitar samples with all the corresponding loop points. I’ll provide them as well as some playback code when I get a chance.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: