Filters and streams in the MAME Sound System

From MAMEDEV Wiki

The old MAME sound design came about as a result of an evolution from the original MAME code. The problem with evolutionary coding is that at some point it gets gross and unmanageable. This is exactly what happened with the existing sound core. The flow of sound is essentially:

sound core -> stream -> mixer -> OSD

This isn't really so bad, except that streams were something we added later, so a lot of old code is still left directly talking to the mixer. On top of that bit of fun, some basic RC filters were added to the streams engine, and some other filter types were added to the mixer engine.

In the new order of things, as said before, there is no separate mixer engine. In addition, the functionality of a stream has been enhanced. Originally, a stream was a single output channel of audio. Chips that output stereo, for example, would end up allocating a special "joined stream", which was really two streams, but which act kind of like a single stream. Confused yet?

Anyway, the new streams are more flexible. Each stream can have multiple output channels, as well as multiple input channels. Each input channel can be connected to a single output from another stream. And each output channel can be connected to multiple input channels on other streams.

Here are some examples.

Two chips with a single output each, routed to a mono speaker. In this case the mixer is created with two inputs and one output:

  chip #1 ---+
             +---> mixer filter ---> mono speaker
  chip #2 ---+

One mono chip with a single output, routed to both the left and right speakers. In this case we have two speaker outputs, and two mixers, each with one input. The output from the mono chip is split to the input of two filters:

          +---> left mixer filter ---> left speaker
  chip ---+
          +---> right mixer filter ---> right speaker

Now the creation of filters becomes dead easy. The RC filter that is in the stream engine now just becomes another sound component that you need to wire up. Let's say you want an RC filter on the output of one of the chips in the first example. It's just:

chip #1 ---> RC filter---+
                         +---> mixer filter ---> mono speaker
chip #2 -----------------+

And the one other nice thing is that with a few minor tweaks to the discrete sound engine, it can also make use of these input sound streams in order to do much more complex and accurate filtering than was possible with the hacked-in basic filters.