Open main menu

Difference between revisions of "AGI/Specifications/Sound"

Wikify and fill in differences from SGML. Work complete
(Syntax highlighing)
(Wikify and fill in differences from SGML. Work complete)
Line 113: Line 113:


Follows an excerpt of the Apple II Sound and Music FAQ, version 1.7.
Follows an excerpt of the Apple II Sound and Music FAQ, version 1.7.
===Technical Specs for the GS Ensoniq chip===
===Technical Specs for the GS Ensoniq chip===


Line 137: Line 138:
==Sound in other platforms==
==Sound in other platforms==


According to Paul Lunga, sound in the Macintosh and Tandy versions of the AGI games are pretty much the same as the PCjr version (three sound channels plus noise). AIFF files of AGI music in these platforms are available at http://agi.helllabs.org/sound.
According to Paul Lunga, sound in the Macintosh and Tandy versions of the AGI games are pretty much the same as the PCjr version (three sound channels plus noise). AIFF files of AGI music in these platforms are available at [http://agi.helllabs.org/sound http://agi.helllabs.org/sound].


<span id="PCJrFormat"></span>
<span id="PCJrFormat"></span>
Line 356: Line 357:
</pre>
</pre>


The patch number is mapped to a sound sample stored in the sierrastandard file in a more complicated way. The IIgs interpreter uses the patch number as a lookup into a list of instrument definitions, which are stored in a format used by an API called the "Note Synthesizer".
The patch number is mapped to a sound sample stored in the '''sierrastandard''' file in a more complicated way. The IIgs interpreter uses the patch number as a lookup into a list of instrument definitions, which are stored in a format used by an API called the "Note Synthesizer".


For example, here's instrument 0 from Police Quest, as dumped out of the pq.sys16 file:
For example, here's instrument 0 from Police Quest, as dumped out of the '''pq.sys16''' file:


<pre>
<pre>
Line 381: Line 382:
Basically the Note Synth API groups 2 5503 voices together to make 1 voice, and this has all the data you need to control it. Let me rephrase some info from my dusty old "IIgs Toolbox Reference, Volume 3".
Basically the Note Synth API groups 2 5503 voices together to make 1 voice, and this has all the data you need to control it. Let me rephrase some info from my dusty old "IIgs Toolbox Reference, Volume 3".


The envelope is first: for each segment there's a breakpoint (target volume, which is on a logarithmic scale in 6 decibel units) and an Increment (a 8.8 fixed point number telling how much to adjust the volume on each tick). For instance, if the first segment had BP = 1 and Inc = 0x0001, it would take 256 ticks for the volume to reach 1. The rel seg tells which segment of the envelope is the final one. Ticks in the Note Synth default to 100 Hz, although the AGI interpreter may well have used a different value -- I'll have to check.
The envelope is first: for each segment there's a breakpoint (target volume, which is on a logarithmic scale in 6 decibel units) and an Increment (a 8.8 fixed point number telling how much to adjust the volume on each tick). For instance, if the first segment had BP = 1 and Inc = 0x0001, it would take 256 ticks for the volume to reach 1. The ''rel seg'' tells which segment of the envelope is the final one. Ticks in the Note Synth default to 100 Hz, although the AGI interpreter may well have used a different value -- I'll have to check.


Bend range is the number of semitones the instrument will be bent by if a pitch wheel message at maximum deflection in either direction is encountered. For this instrument, that's 3 semitones in each direction.
''Bend range'' is the number of semitones the instrument will be bent by if a pitch wheel message at maximum deflection in either direction is encountered. For this instrument, that's 3 semitones in each direction.


Vib Dep and Vib Spd aren't being dumped properly yet (minor bug in my utility), but they specify the depth and speed of an optional vibrato effect.
''Vib Dep'' and ''Vib Spd'' aren't being dumped properly yet (minor bug in my utility), but they specify the depth and speed of an optional vibrato effect.


A wave count and B wave count tell how many wavelists there are for each 5503 voice. If there's more than 1 wavelist you compare the note being started with the top value in each wavelist and if top is greater than or equal to the note you're starting you use that wavelist. In this case there's only 1 possible wavelist so top is naturally 0x7f, the highest possible numbered MIDI note.
''A wave coun''t and ''B wave count'' tell how many wavelists there are for each 5503 voice. If there's more than 1 wavelist you compare the note being started with the ''top'' value in each wavelist and if ''top'' is greater than or equal to the note you're starting you use that wavelist. In this case there's only 1 possible wavelist so top is naturally 0x7f, the highest possible numbered MIDI note.


Once you've picked a wavelist using the note, the other information is all there. Wave address is the offset in 256-byte pages into the 64k sierrastandard image (ie, (Wave Address)<<8 gives a true offset). In this case the wave starts 0x5000 bytes into the image. For size you mask off all but the lowest 3 bits and it gives you the basic wave size as follows:
Once you've picked a wavelist using the note, the other information is all there. Wave address is the offset in 256-byte pages into the 64k '''sierrastandard''' image (ie, (Wave Address)<<8 gives a true offset). In this case the wave starts 0x5000 bytes into the image. For size you mask off all but the lowest 3 bits and it gives you the basic wave size as follows:


Case the wave starts 0x5000 bytes into the image: For size you mask off all but the lowest 3 bits and it gives you the basic wave size as follows:
Case the wave starts 0x5000 bytes into the image: For size you mask off all but the lowest 3 bits and it gives you the basic wave size as follows:
Line 404: Line 405:
Note that if a zero is encountered in the wave before that size you still stop at the zero.
Note that if a zero is encountered in the wave before that size you still stop at the zero.


Mode is the 5503 oscillator mode for the voice in the bits 1 and 2. The lowest bit (bit 0) is a "halt" flag. 0 is looping, 1 is oneshot (play once), 2 is sync/AM (which nobody uses, but I'll try to explain it if they actually are), and 3 is swap (oscillator 0 plays once, generates an IRQ, and oscillator 1 starts automatically. If oscillator 1 is also in swap mode, it will play once, generate and IRQ, and auto-start oscillator 0 again. If oscillator 1 is loop mode it will just loop continuously - this setup is often used to have a sampled "attack" on an instrument followed by a loop.
''Mode'' is the 5503 oscillator mode for the voice in the bits 1 and 2. The lowest bit (bit 0) is a "halt" flag. 0 is looping, 1 is oneshot (play once), 2 is sync/AM (which nobody uses, but I'll try to explain it if they actually are), and 3 is swap (oscillator 0 plays once, generates an IRQ, and oscillator 1 starts automatically. If oscillator 1 is also in swap mode, it will play once, generate and IRQ, and auto-start oscillator 0 again. If oscillator 1 is loop mode it will just loop continuously - this setup is often used to have a sampled "attack" on an instrument followed by a loop.


The top 4 bits of the mode is the stereo channel where even numbers are right and odd numbers are left, I believe (no real harm in reversing them).
The top 4 bits of the mode is the stereo channel where even numbers are right and odd numbers are left, I believe (no real harm in reversing them).
Line 420: Line 421:
* h - halt bit. 0 to start the oscillator, 1 to halt it. This is handled specially in swap mode.
* h - halt bit. 0 to start the oscillator, 1 to halt it. This is handled specially in swap mode.


relPitch is the fine-tune value in 8.8 fixed point, given in semitones.
''relPitch'' is the fine-tune value in 8.8 fixed point, given in semitones.


So you'd then start 2 voices using the appropriate A and B wavelist entries and handle them accordingly.
So you'd then start 2 voices using the appropriate A and B wavelist entries and handle them accordingly.
Line 426: Line 427:
The full structures look like this: (there is no structure padding on the IIgs - all bytes are jammed right together!)
The full structures look like this: (there is no structure padding on the IIgs - all bytes are jammed right together!)


In Police Quest these structures start at offset 0x8469 in PQ.SYS16. (The same offset is used for KQ1 --CM) I can't find any of my other old disks with AGI games to locate their offsets. PQ only defines 28 instruments.
In Police Quest these structures start at offset 0x8469 in PQ.SYS16. ''(The same offset is used for KQ1 --CM)'' I can't find any of my other old disks with AGI games to locate their offsets. PQ only defines 28 instruments.


<pre>
<pre>
Line 477: Line 478:


Then of course you could always convert the AGI SOUND to a MIDI file and play that which will sound a hundred times better :)
Then of course you could always convert the AGI SOUND to a MIDI file and play that which will sound a hundred times better :)
Calculating frequencies when playing notes on a sound card
 
===Calculating frequencies when playing notes on a sound card===


My program reads in the duration as a 16 bit word. It then loads the two following bytes and calculates the frequency as follows:
My program reads in the duration as a 16 bit word. It then loads the two following bytes and calculates the frequency as follows: