saveMatrixAsMtx#
- csoundengine.csoundlib.saveMatrixAsMtx(outfile, data, metadata=None, encoding='float32', title='', sr=44100)[source]#
Save data in wav format using the mtx extension
This is not a real output. It is used to transfer the data in binary form to be read by another program. To distinguish this from a normal wav file an extension .mtx is recommended. Data is saved always flat, and a header with the shape of data is included before the data.
Header Format:
headerlength, numRows, numColumns, ...
The description of each metadata value is included as wav metadata at the comment key with the format:
"headerSize: xx, numRows: xx, numColumns: xx, columns: 'headerSize numRows numColumns ...'"
This metadata can be retrieved in csound via:
itabnum ftgen 0, 0, 0, -1, "sndfile.mtx", 0, 0, 1 Scomment = filereadmeta("sndfile.mtx", "comment") imeta = dict_loadstr(Scomment) ScolumnNames = dict_get(imeta, "columns") idatastart = tab_i(0, itabnum) inumrows = dict_get(imeta, "numRows") ; inumrows can also be retrieved by reading the table at index 1 ; inumrows = tab_i(1, itabnum) inumcols = tab_i(2, itabnum) ; The data at (krow, kcol) can be read via kvalue = tab(idatastart + krow*inumcols + kcol, itabnum) ; Alternatively an array can be created as a view: kArr[] memview itabnum, idatastart reshapearray kArr, inumrows, inumcols kvalue = kArr[krow][kcol]
- Parameters:
outfile (str) – The path where the data is written to
data (numpy array) – a numpy array of shape (numcols, numsamples). A 2D matrix representing a series of streams sampled at a regular period (dt)
metadata (
dict
[str
,str
|float
] |None
) – Any float values here are included in the header, and the description of this data is included as metadata in the wav fileencoding – the data can be encoded in float32 or float64
title – if given will be included in the output metadata
sr (
int
) – sample rate. I
- Return type:
None