csound-xtract is a set of plugin opcodes which use libXtract to perform feature extraction and associated tasks from within Csound.
Development is still ongoing and subject to various research matters, thus is provided in an experimental/alpha state and may contain bugs. Parts of the code are due overhauls and refactoring, but the intention is for the opcodes and general operation to remain the same as presented here.
- Cmake >= 3.8
- Csound with development headers >= 6.14.0
- LibXtract
Tested on Linux and Windows 7 with MSYS as of March 2021.
Create a build directory at the top of the source tree, execute cmake .., make and optionally make install as root. If the latter is not used/possible then the resulting libcsxtract library can be used with the --opcode-lib flag in Csound.
eg:
mkdir build && cd build
cmake ..
make && sudo make install
Cmake should find Csound and libXtract using the modules in the cmake/Modules directory and installation should be as simple as above.
Some examples are provided in the examples directory.
Declare a feature extraction profile for use in extraction opcodes. The exact techniques for extraction of individual features can be found by examining the libXtract documentation and source code.
Analyse sound contained in a f-table and store in a handle, for later use in comparison/matching opcodes. Done during init time.
Analyse a live sound.
Compare two extraction streams using a basic distance function between each frame of the analyses. The profiles used for the streams must be the same.
-
kdistance : the calculated distance, 0 should represent no difference between the analyses.
-
ixtract1 : analysis stream as created by xtractor
- ixtract2 : analysis stream as created by xtractor
- ktrigger : comparison is conducted when 1
- idistancefunc : 0 for Euclidean distance, 1 for Manhattan distance
Obtain the analysis data from an xtractor handle. The array length will depend on the number of features specified in the profile used (MFCC uses 13 indexes, all others use 1). The indexes are presented in the same order as declared in xtprofile. For example, a profile using MFCC and centroid would mean indexes 0 to 12 would be MFCCs, and 13 would be centroid. Similarly a profile using only centroid and flatness would imply index 0 would be centroid, and 1 would be flatness.
Obtain the analysis data from an xtractor handle as with xtdump, but accumulate the analyses and output the mean when ktrigger is 1.
Obtain the nearest match in a corpus created with xtcorpus by comparing a live input stream created by xtractor.
-
kposition : position of nearest corpus region, in sample points
-
icorpus : corpus handle as created by xtcorpus
- ixtract : analysis stream as created by xtractor
- ktrigger : perform the comparison when 1
- idistancefunc : 0 for Euclidean distance, 1 for Manhattan distance