# TTMatrix Design¶

TTMatrix is intended to provide matrix operations for the Jamoma Foundation. As such, it must address the needs of a diverse mix of application areas including DSP research and supporting algorithms and mathematics, image and video processing, and representing collections of vectors of PCM audio.

Acknowledging that there are conflicting conventions in differing fields, we will aim to take the most general and generic conventions when possible and practical. For example, in computer graphics it is the convention to address a location on the screen using an x,y coordinate pair, where x indicates the column number (position across the horizontal axis) and y indicates the row number (position on the vertical axis). In mathematics generally, and linear algebra specifically, it is instead the convention to identify a matrix location in the matrix M as M(i,j) where i is the row number and j is the column number -- the reverse of the convention used in computer graphics. We will favor the latter convention in Jamoma, though there may be some opportunities where we can support both (at least at the C++ level).

Similarly, a matrix in computer graphics is often referred to as having dimensions of width-by-height, and we will favor rows-by-columns.

## Indexing¶

In addition to the aforementioned index ordering, we also will follow the mathematical convention of counting indices beginning with 1. Internally the C code will naturally be zero-based, but we will translate this through accessor methods. One reason for this convention is to make it easier to translate code from mathematical or dsp research, and code from Octave/Matlab, in Jamoma classes operating on matrices and vectors.

## Audio Signals and Buffers¶

We will change the current non-interleaved sample ordering to an interleaved ordering. If we visualize an audio signal or audio buffer as a dimensional block of memory with N channels and M samples for each channel, then the audio signal or buffer is effectively an MxN matrix. The channels are each represented as columns of the matrix and the sample data for each channel is then a column-vector indexed by row. Up through Jamoma 0.5.x it was the reverse.

The following table visualizes the channels and samples for a stereo audio signal with a vector size of 64. The values in the table are the indices into memory used internally.

 channel 1 channel 2 sample 1 0 1 sample 2 2 3 sample 3 4 5 ... ... ... sample 64 126 127

Having all of the sample data interleaved in this way will make true multichannel processes more efficient (the samples for adjacent channels will be adjacent in memory). It also benefits us when doing spectral audio processing, which typically begins with a real signal and results in a complex signal. Using this interleaved format we can view the signal a complex vector, or as 2 simple vectors (one real and one imaginary) -- the layout of memory holds true for either interpretation.