SDIF Matlab
From sdif
The SDIF extensions for Matlab come as mex files for Linux, Mac, and Windows XP.
Note that there are two different implementations:
- the old and simple one based on libSDIF (using only two functions loadsdif and writesdif)
- the new proper one based on EaSDIF (using functions like Fopensdif, Freadsdif, Fwritesdif, Fclosesdif)
SDIF Matlab FAQ: user-driven documentation
SDIF Matlab Examples
These examples are for the old and simple interface.
See the help files and the scripts that come with the package.
SDIF Matlab Writing with private type definitions and NVTs
function ~[] = testwritesdif(FILENAME, marker_s)
if ~nargin
FILENAME = 'test_marker_bpm.sdif';
for l=1:20
marker_s(l).time = l/pi;
end
end
% define and write your own types
definition1 = ~['1MTD XBEA { blu, blo }'];
definition2 = ~['1FTD 1MRK { XBEA identifiant; }'];
a = sprintf('%s\n%s\n', definition1, definition2)
writesdif(FILENAME, './~SdifTypes.STYP', a);
% write an NVT
writesdif(0, -1, '1NVT', '1NVT', {'coucou', 'blabla'});
% write some data
for l=1:length(marker_s)
writesdif(marker_s(l).time, 1, '1MRK', 'XBEA', ~[200 0]);
end
writesdif('close');
More about writing 1NVTs in Matlab
if you make any sdif file using the Matlab mex functions,
it will contain the following 1NVT accessed through the
loadsdif function.
>> head=loadsdif('blarg.sdif')
head =
numberOfParameters 2
Writtenby matlabSdifWriter
Version 1
you could write you own NVT frame like
Table{1,1} = 'date written';
Table{1,2} = datestr(now);
Table{2,1} = 'author';
Table{2,2} = 'Noid Blarg';
writesdif('blarg.sdif');
writesdif(0,0,'1NVT','1NVT',Table);
head= loadsdif('blarg.sdif')
head =
numberOfParameters 2
Writtenby matlabSdifWriter
Version 1
author Noid Blarg
date written 11-Apr-2006 21:13:13
notice the author is first and the date is second. This is because the NVTs are internally organized in a hash table. What you get depends on the
hash map. The hash function is just summing the int values of the
characters. So the only solution to your problem would be to write more than a
single NVT because each NVT is hashed independently. Thats why you get the
first 3 lines
numberOfParameters 2 Writtenby matlabSdifWriter Version 1
always at the same position and always on top of the list. They come from an
independent NVT.
Trying to write multiple NVTs in the same go like
Table1{1,1} = 'date written';
Table1{1,2} = datestr(now);
Table2{1,1} = 'author';
Table2{1,2} = 'Noid Blarg';
writesdif( 0 ,-1 , '1NVT' ,'1NVT',Table1,'1NVT',Table2);
will still be in the same hash table, so the order is psuedo random again.
To get them out in order, you can repeatedly write NVTs as long as you did not write other
frames into the sdif file like
writesdif( 0000 ,32 , '1NVT' ,'1NVT',Table1);
writesdif( -122 ,-1111 , '1NVT' ,'1NVT',Table2);
head= loadsdif('blarg.sdif')
head =
numberOfParameters 2
Writtenby matlabSdifWriter
Version 1
date written 11-Apr-2006 21:13:13
author Noid Blarg
Lastly, the StreamID and time must be there, but they can be any float, since they are not evaluated.
The frame type and matrix type must be '1NVT'.
Partial Tracking example in Matlab
extractraxtosdif.m is a script that uses Dan Ellis' partial tracking mfile extractrax.m to analyze a wav file
and write a 1TRC sdif file from it. I have only gotten it to make good tracks from his clar.wav sample provided, so my
guess is that extractrax.m needs considererable tweaking to work with other sounds.
Back to SDIF Wiki.
