libambix
the AMBIsonics eXchange library
|
When opening a file for read, the ambix_info_t struct should be set to 0. On successful open, all fields are filled by the library. If the open fails, the state of the ambix_info_t fields is undefined.
The only exception to this is, if you want to force the ambix file to be read as either "BASIC" or "EXTENDED", e.g. because you don't want to care about adaptor matrices or because you do. In this case you must set the fileformat field the requested format.
You can read any ambix file as "BASIC" by setting the 'fileformat' member of the ambix_info_t struct to AMBIX_BASIC prior to opening the file. This will automatically do any conversion needed, by pre-multiplying the raw ambisonics data with an embedded adaptor matrix.
Real "BASIC" files lack extra audio channels. However, when opening a file that is not a "BASIC" ambix file (e.g. an "EXTENDED" ambix file) as a "BASIC" one, by forcing the 'fileformat' member to 'AMBIX_BASIC', extra channels might be readable.
You can read an ambix file as "EXTENDED" by setting the 'fileformat' member of the ambix_info_t struct to AMBIX_EXTENDED prior to opening the file. You will then have to retrieve the adaptor matrix from the file, in order to be able to reconstruct the full ambisonics set. You can also analyze the matrix to make educated guesses about the original channel layout.
If you do not specify the format prior to opening, you can query the format of the file from the ambix_info_t struct.
To write data to an ambix file, you have to open it with the AMBIX_WRITE flag. You also need to specify some global properties of the output data, namely the samplerate and the sampleformat, as well as the number of ambisonics channels and the number of extra channels that are physically stored on the disk.
You can write "BASIC" ambix files by setting the 'fileformat' member of the ambix_info_t struct to AMBIX_BASIC prior to opening the file.
You will need to provide a full set of ambisonics channels when writing data to the file, and must not set an adaptor matrix (see also Writing EXTENDED ambix files using the BASIC interface). A full set of ambisonics must always satisfy the formula \(channels=(order_{ambi}+1)^2\).
You cannot write extra audio channels into a "BASIC" ambix file.
You can write "EXTENDED" ambix files by setting the 'fileformat' member of the ambix_info_t struct to AMBIX_EXTENDED prior to opening the file.
You MUST set an adaptormatrix (to convert the reduced set to a full ambisonics set) using ambix_set_adaptormatrix(). It gets written to disk prior to writing any samples to the file (or closing the ambix file). It is an error to call ambix_set_adaptormatrix() after starting to write samples.
Finally, you can create "EXTENDED" ambix files from a full set of ambisonics channels and an adaptor matrix. This can be useful if you have a setup that works with full ambisonics sets (e.g. a DAW project) and you want to create a size-optimized ambix file that only stores a reduced set.
This can be achieved by setting the 'fileformat' member of the ambix_info_t struct to AMBIX_BASIC (because you will provide the full ambisonics set as if the file were opened in "BASIC" mode) and the 'ambichannels' member to the (reduced) number of ambisonics channel as will be written to the disk, and then setting an adaptor matrix ambix_set_adaptormatrix(), that will convert the reduced set back to the full set. libambix will internally reduce the full ambisonics set (as passed to ambix_writef()) using the (pseudo) inverse of the adaptor-matrix.
The adaptor matrix gets written to disk prior to writing any samples to the file (or closing the ambix file). It is an error to call ambix_set_adaptormatrix() after starting to write samples.