Library Name: lib_mmedia.a
Introduction:
The Multimedia library consists of classes which will handle processing
associated with various media types. This allows programmers to use
media files through a standard interface that just return data
without knowing the details of the file format.
We currently support interfaces to audio data, feature data,
and speech language model formats in this library.
For example, the AudioFile class handles input and output
to audio data files, and support a number of formats including
Sof, raw, NIST SPHERE, and Microsoft wav.
The JSGFParser class supports an interface to language models
defined using the Java Speech Grammar Format.
The Annotation Graph classes provide an interface to a flexible
method for describing metadata related to an audio file.
Example:
This
example
shows how to copy an audio file from one file to another. It uses a
buffer size of 50 samples.
01 // file: $isip/doc/examples/class/mmedia/mmedia_example_00/example.cc
02 // version: $Id: index.html 10248 2005-09-16 19:10:44Z srinivas $
03 //
04
05 // isip include files
06 //
07 #include <AudioFile.h>
08
09 // main program starts here
10 //
11 int main() {
12
13 // declare AudioFile objects for read and write
14 //
15 AudioFile src;
16 src.open(L"./input.raw");
17
18 AudioFile dst;
19 dst.setFileType(AudioFile::SOF_TEXT);
20 String output(L"./output.sof");
21 dst.open(output, File::WRITE_ONLY);
22
23 // loop through 50 samples at a time
24 //
25 for (long i = 0; i < 5; i++) {
26
27 Vector<VectorFloat> data(1);
28
29 // call
30 // getData
31 //
32 src.getData(data(0), 0, i * 50, (long)50);
33
34 // write these 50 samples to the output
35 //
36 dst.writeAudioData(data, 0);
37 }
38 src.close();
39 dst.close();
40
41 output.debug(L"output");
42
43 // exit gracefully
44 //
45 Integral::exit();
46 }
Explanation:
On lines 15 and 16, we open the input audio file. On lines 18-21, we
open the output audio file. We force the output file to be in mode
SOF_TEXT, the human readable form of our standard Sof file.
Inside the loop on line 32, we call the getData method. The first
argument is the output data buffer. The next argument is the channel
to read, in this case we only want to read the first channel. The
third argument is the starting offset, which is calculated by
multiplying the loop counter by the buffer size (50). The final
argument is the number of elements to read.
The next step is to write the data to the output. Note that there
are no position arguments to writeAudioData, the AudioFile class
assumes that every write is to adjacent blocks in the file.
Finally we close the files on lines 38 and 39.
Example:
This
example
shows a simple excise signal program. The user is expected to pass
in a start time, stop time, input file, and output file from the
command line. The output file will contain a copy of the data within
the specified window.
01 // file: $isip/doc/examples/class/mmedia/mmedia_example_00/example.cc
02 // version: $Id: index.html 10248 2005-09-16 19:10:44Z srinivas $
03 //
04
05 // isip include files
06 //
07 #include <AudioFile.h>
08 #include <CommandLine.h>
09
10 // excise_signal: program to excise part of an audio signal from one
11 // file and output it to a new file.
12 //
13 // this is an example excise_signal utility
14 //
15 int main(int argc, const char** argv) {
16
17 // configure the command line parser and an Sdb object.
18 //
19 CommandLine cmdl;
20
21 // 2 parameters: start time and stop time
22 //
23 Float start_time;
24 Float stop_time;
25 String start_param(L"start_time");
26 String stop_param(L"stop_time");
27 cmdl.addOptionParam(start_time, start_param, 0.0);
28 cmdl.addOptionParam(stop_time, stop_param, 0.0);
29
30 // parse the command line
31 //
32 cmdl.parse(argc,argv);
33
34 Filename input;
35 Filename output;
36
37 // read the input and output as the arguments
38 //
39 cmdl.getArgument(input, 0);
40 cmdl.getArgument(output, 1);
41
42 // declare AudioFile objects for read and write
43 //
44 AudioFile src;
45 AudioFile dst;
46
47 // open the input file
48 //
49 src.open(input);
50
51 // we want the output file to have the same format as the input, so
52 // assign the object before opening the new file
53 //
54 dst.assign(src);
55 dst.open(output, File::WRITE_ONLY);
56
57 // read in the data into a buffer and write it to the new file
58 //
59 Vector<VectorFloat> buf(src.getNumChannels());
60 src.getData(buf, start_time, stop_time - start_time);
61 dst.writeAudioData(buf);
62
63 // close the files
64 //
65 src.close();
66 dst.close();
67
68 // exit gracefully
69 //
70 Integral::exit();
71 }
Explanation:
On lines 23-32 we set up the command line to parse our options of
start_time and stop_time. We then obtain the input and output
filenames as arguments in lines 34-40. We now have all user input so
we can move on to processing.
On line 49 we open the input file. Once opened, all internal
parameters of the src object will be set to the input file's
type. On line 54 we configure the output file dst to use the
same format as the input file. Therefore, if the input file is a ulaw
encoded sphere file, the output file will also be a ulaw encoded
sphere file.
On line 59 we allocate our data buffer to hold all the channels in
the input file. On line 60 we call getData to read the audio data
from the input file, notice that we use a direct floating-point time
interface for positioning. We then write the data on line 61 and
close the files on 65 and 66.