Welcome, Guest. Please login or register.

Author Topic: Programming "Chip Tunes"  (Read 1722 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show all replies
Re: Programming "Chip Tunes"
« on: March 26, 2005, 01:02:39 AM »
I might be going mental, but I seem to recall reading someplace in the amiga hardware manuals that paula could be configured in such a way that one channel could modulate the volume or period of another. The latter idea is the basis for FM synthesis AFAIK.

Anyway, one way to create great 'chip' tunes is to use musicline. It actually uses the 'short loop' idea of your normal chip tune, but it has some software filters and other operations that make it a little bit special.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show all replies
Re: Programming "Chip Tunes"
« Reply #1 on: March 26, 2005, 01:08:03 AM »
From the hardware manual:

"To provide more complex audio effects, you can use one audio channel to modulate another. This increases the range and type of effects that can be produced. You can modulate a channel's frequency or  amplitude , or do both types of modulation on a channel at the same time.

Amplitude  modulation affects the  volume  of the waveform. It is often used to produce vibrato or tremolo effects. Frequency modulation affects the  period  of the waveform. Although the basic waveform itself remains the same, the pitch is increased or decreased by frequency modulation.

The system uses one channel to modulate another when you attach two channels. The attach bits in the ADKCON register control how the data from an audio channel is interpreted (see the table below). Normally, each channel produces sound when it is enabled. If the "attach"  bit for an audio channel is set, that channel ceases to produce sound and its data is used to modulate the sound of the next higher-numbered channel. When a channel is used as a modulator, the words in its data set are no longer
treated as two individual bytes. Instead, they are used as "modulator" words. The data words from the modulator channel are written into the corresponding registers of the modulated channel each time the  period register  of the modulator channel times out."

I read that as meaning one channel can modulate the pitch / amplitude of another. The above use seems to be describing a basic LFO, but if you can perform this modulation at normal audio frequencies, you have the basis of an FM synth.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show all replies
Re: Programming "Chip Tunes"
« Reply #2 on: March 26, 2005, 01:18:29 PM »
@boing

That was from the hardware manuals as found on  the Dev CD2.1. Theyr'e HTML format - you shouldn't have much trouble finding it - just start in the audio hardware section :-)
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show all replies
Re: Programming "Chip Tunes"
« Reply #3 on: March 26, 2005, 01:31:40 PM »
Quote

>The data words from the modulator channel are written into the corresponding registers
>of the modulated channel each time the period register of the modulator channel times out."


I read that as meaning the following:

Suppose channel 0 is the modulator and channel 1 the modulated channel.

Channel 0 has playback period of its own, just as it would if it were playing a sample. Instead of feeding the data to the DAC, here the data is fed to the period register of the other channel and that this happens at the basic playback period of the modulator channel.

The "each time the period register of the modulator channel times out" part just seems to be a needlessly long way of confirming this.

Therefore, if your modulator channel has a period equivalent to 5kHz playback, it will update the period register of the modulated channel 5000 times a second. Note that this isn't yet the basic requirement for FM synthesis as it could be writing the same value to the modulated channels period register 5000 times a second, therefore changing nothing.

One thing which seems to be the case here is that building an FM synth would be quite difficult. Rather than simple frequecny modulation, you would be performing period modulation (period is proportional to the inverse of the frequency) meaning your modulator waveform would have to be appropriately encoded.

The bit about data words rather than bytes just means that the 16-bit elements fetched by the modulator channel now represent a register field rather than a pair of 8-bit samples. The period register has a 16 bit resolution, so you can envisage your modulator waveform as an 8-bit sine wave, converted into a 16-bit period value.

This of course means that you need to start with some fixed wafevorms that you can encode in this fashion.

It looks difficult overall. Difficult, perhaps impractical, but not impossible.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show all replies
Re: Programming "Chip Tunes"
« Reply #4 on: March 26, 2005, 02:28:35 PM »
@piru

Yep, that's exactly how it's done.

Regarding the precision, AFAIK, the 14-bit resoulution comes from the fact that the overall volume of each channel has only 6-bit resolution. This means that one channel can only be at most 64x louder (ignoring the non-linearity for the moment) than any other.

The 'left shift' of the most significant byte, which is effctively achieved by the channel volume, for the overall sample word is therefore only 6 bit.

The remark about the effective precision of the minor channel (ie when played at minimum volume) is also true as far as I recall.

So it all comes down to playing the most significant 8 bits in the major channel and the next most significant 6 bits in the minor channel and the least significant 2 bits simply are not reproduced.

If the channel volume were 8 bit, you'd be able to reproduce the almost full 16-bit dynamic range with this trick, playing the most significant byte at volume 0xFF and the least significant at 0x01 - assuming the minor channel had sufficient resolution at this volume, of course.

As it goes, the effective volume difference of the major and minor channels are actually more than the 6 bit seperation implies. This is down to the non-linearity of the DAC and the reason that calibrated output routines exist.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show all replies
Re: Programming "Chip Tunes"
« Reply #5 on: March 26, 2005, 02:42:25 PM »
@Piru

Hey, here's a silly idea for you. According to the HW manual, one channel can directly modulate the volume of another.

Suppose we encoded 16-bit data into a simple float-like format with a signed 8-bit mantissa and an unsigned 6 bit exponent.

We could split it into 2 buffers. The first buffer contains the 6 bit exponent data, being read for channel 0. This is then used to modulate the volume of channel 1, which is reading the 8-bit data.

Both channels are using the exact same period, so you get to reproduce 14-bit data again.

If both chip ram buffers are being read via DMA (as you would expect) you can do this at a low overhead in terms of CPU interrupts etc.

Encoding from normal 16-bit data to the required format could be achieved using a simple LUT - you can even do calibration for non-linearity when making this table.

Of course this all hinges on the assumption that the hardware channels would be perfectly in sync and remain so.
int p; // A
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show all replies
Re: Programming "Chip Tunes"
« Reply #6 on: March 26, 2005, 03:32:56 PM »
@minator

I've studied FM synthesis in some detail in the past. There is fundamentally nothing different about the vibrato effect and FM other than the ratio of modulator/carrier frequency and the strength of the modulation. Vibrato effects (pitch based - tremelo is volume based) occur when the modulation strength is both very small (modifying the pitch of a note by a few cents) and the frequencty of the modulation is *much* lower than the carrier wave (ie a few Hz).

If you increase the modulation frequency until it is the same order of magnitude as the carrier wave, you start to get your FM synthesis effects.

If you look at the spectrum, you see more and more sidebands beginning to converge around your carrier frequency as your modulator frequency increases.

When your modulator frequency is a rational fraction (or multiple) of your carrier frequency, you get nice waveforms that are rich in harmonics and resemble other commonly encountered waveforms, eg square, sawtooth etc.

As you change that to non rational frequencies you get more complex frequencies that can sound anything from very disharmonic to metallic.

The documentation says that one channel can be used to modulate the period (of which frequency is a function) of another. I see no reason why this could not be used to create a basic 2 operator FM synthesis. As I said it would be a bit more complex, but I don't see a reason it could not be done.

If you have a 22kHz sample waveform (comprising 16-bit period values) derived from a 1kHz tone as your modulation and a 22kHz sample waveform of the same 1kHz tone as normal samplesas your carrier, I see no reason why, with appropriate programming, one could not correctly modulate the other.
int p; // A