SGI Audio Tools: Difference between revisions

From N64brew Wiki
Jump to navigation Jump to search
Content added Content deleted
m (Partial work on audio sample compression steps)
(Add MIDI convert/compress)
Line 9: Line 9:
* Linear predictive coding
* Linear predictive coding
* AIFF format
* AIFF format
* the PATH environment variable (for program quick access)
If you're a bit unfamiliar, a quick search or Wikipedia skim should suffice.
If you're a bit unfamiliar, a quick search, tutorial, or Wikipedia skim should suffice.


This article assumes you have the SGI Audio Tools as part of the Nintendo 64 SDK. The programs in particular you're going to need are:
This article assumes you have the SGI Audio Tools as part of the Nintendo 64 SDK. The programs in particular you're going to need are:
Line 24: Line 25:


== Authoring a Song with the SGI Audio Tools ==
== Authoring a Song with the SGI Audio Tools ==
=== Compressing Sequence Data ===
==== Converting Your MIDI File(s) ====
MIDI files are generally either '''Type 0''' or '''Type 1'''. The former specifies all of the notes in a single "track" while the latter has multiple tracks, typically for each instrument. The SGI tools require MIDI files to be in Type 0 and provides the `midicvt` tool to convert to it. Programs such as [https://musescore.org/ MuseScore] likely export in Type 1, so it's usually a good idea to convert to Type 0 before continuing.

For each of your original MIDI files, run the following:
<br ><code>midicvt some_midi.mid some_midi_converted.mid</code>

<code>some_midi_converted.mid</code> is the name of the converted file in this example.

==== Compressing Your MIDI File(s) ====
Once your MIDI files have been converted to Type 0, we'll be converting them to a compressed sequence format specialized for embedded playback on the Nintendo 64.

For each of your converted MIDI files, run the following:
<br ><code>midicomp some_midi_converted.mid some_midi_compressed.cmf</code>

You'll now have various `cmf` files for each of your songs.

==== Compiling Your MIDI File(s) ====
Now that we've compressed each MIDI file, its time to compile them into one "song bank". This will be added to your ROM and loaded in at runtime. To do this, we'll be using the <code><sbc></code> tool.

Run the following command with each of your <code>cmf</code> files as parameters.
<br ><code>sbc -Osongs.sbk first_song_compressed.cmf second_song_compressed.cmf third_song_compressed.cmf</code>

The '''ordering is important''' here! Keep note of the order of each parameter, as when you're selecting your songs in your game's source code, you'll be indexing them as they're ordered here (eg: <code>first_song_compressed.cmf</code> will be <code>0</code>, second_song_compressed.cmf </code> will be <code>1</code>, etc.).

Note the lack of space between the <code>-O</code> flag and the output file name. This seems to be intended. 🤷

=== Compressing Sounds ===
=== Compressing Sounds ===
==== Converting samples with SoX ====
==== Converting samples with SoX ====
Line 50: Line 78:
On each of your samples, run the following:
On each of your samples, run the following:
<br /><code>vadpcm_enc -c song_sample.table song_sample.aiff compressed_song_sample.aifc</code>
<br /><code>vadpcm_enc -c song_sample.table song_sample.aiff compressed_song_sample.aifc</code>

The following <code>.aifc</code> file(s) will be compiled in to make a sound bank.


=== Authoring the Bank File ===
=== Authoring the Bank File ===

Revision as of 05:15, 9 August 2020

Introduction

TODO

Prerequisites

This article assumes you're familiar with the following terms/concepts:

  • Audio samples
  • Sample rate
  • MIDI
  • Linear predictive coding
  • AIFF format
  • the PATH environment variable (for program quick access)

If you're a bit unfamiliar, a quick search, tutorial, or Wikipedia skim should suffice.

This article assumes you have the SGI Audio Tools as part of the Nintendo 64 SDK. The programs in particular you're going to need are:

  • tabledesign
  • vadpcm_enc
  • ic
  • midicvt
  • midicomp
  • sbc

This article also assumes that you're using the aforementioned programs in a Windows 95-like environment. An emulator, such as Oracle VirtualBox works fine too.

The n64decomp project has decompiled tabledesign and adpcm here. It's possible to build those two particular programs yourself and run them in the environment of your choice, which might make your life a little easier!

Authoring a Song with the SGI Audio Tools

Compressing Sequence Data

Converting Your MIDI File(s)

MIDI files are generally either Type 0 or Type 1. The former specifies all of the notes in a single "track" while the latter has multiple tracks, typically for each instrument. The SGI tools require MIDI files to be in Type 0 and provides the `midicvt` tool to convert to it. Programs such as MuseScore likely export in Type 1, so it's usually a good idea to convert to Type 0 before continuing.

For each of your original MIDI files, run the following:
midicvt some_midi.mid some_midi_converted.mid

some_midi_converted.mid is the name of the converted file in this example.

Compressing Your MIDI File(s)

Once your MIDI files have been converted to Type 0, we'll be converting them to a compressed sequence format specialized for embedded playback on the Nintendo 64.

For each of your converted MIDI files, run the following:
midicomp some_midi_converted.mid some_midi_compressed.cmf

You'll now have various `cmf` files for each of your songs.

Compiling Your MIDI File(s)

Now that we've compressed each MIDI file, its time to compile them into one "song bank". This will be added to your ROM and loaded in at runtime. To do this, we'll be using the <sbc> tool.

Run the following command with each of your cmf files as parameters.
sbc -Osongs.sbk first_song_compressed.cmf second_song_compressed.cmf third_song_compressed.cmf

The ordering is important here! Keep note of the order of each parameter, as when you're selecting your songs in your game's source code, you'll be indexing them as they're ordered here (eg: first_song_compressed.cmf will be 0, second_song_compressed.cmf will be 1, etc.).

Note the lack of space between the -O flag and the output file name. This seems to be intended. 🤷

Compressing Sounds

Converting samples with SoX

SoX bills itself as the Swiss Army knife of sound processing programs. Its uses include (but aren't limited to) converting audio between formats, providing effects, and even recording. Given that SoX is an open-source tool, it's well worth including into any game developer's setup.

The tabledesign and vadpcm_enc tools require audio samples to be in AIFF or AIFC. If the samples you're using are in a different format, such as WAV, you can use SoX to batch-convert your samples. It's also a good idea to resample each effect to the same sample rate, such as 32000Hz. If you're generating your bank file via a script, you can assume the sample rate in your code to save time.

If we want to convert an arbitrary WAV file to AIFF with a sample rate of 32000 and in mono we can enter:
sox some_file.wav -r 32000 -c 1 converted_file.aiff

This article assumes that the reader is converting their files to AIFF with SoX.

Creating a code book for each file

You'll want to create a code book for each AIFF sample you want to use in your song. To do this, you'll run the tabledesign command on each of your samples and save the output of that program to a file.

For clarity, we'll be suffix-ing each code book with .table but it's not necessary to do.

On each of your samples, run the following:
tabledesign song_sample.aiff > song_sample.table

It's worth noting that by default tabledesign will print to STDOUT. The > operator for writing to a file should work both on Mac/Linux/BSD/etc. and Windows here.

Compressing each sample

Once we've created a code book, we'll want to convert our AIFF samples to Nintendo's compressed AIFC formats. To do that, we'll be using vadpcm_enc.

On each of your samples, run the following:
vadpcm_enc -c song_sample.table song_sample.aiff compressed_song_sample.aifc

The following .aifc file(s) will be compiled in to make a sound bank.

Authoring the Bank File

Creating the Instrument Bank

Playing a song with NuSystem

Linking the Audio Library

Setting up playback

Starting/stoping playback