Chris@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 Sonic Annotator
|
Chris@0
|
5 A utility for batch feature extraction from audio files.
|
Chris@0
|
6 Mark Levy, Chris Sutton and Chris Cannam, Queen Mary, University of London.
|
Chris@0
|
7 Copyright 2007-2008 QMUL.
|
Chris@0
|
8
|
Chris@0
|
9 This program is free software; you can redistribute it and/or
|
Chris@0
|
10 modify it under the terms of the GNU General Public License as
|
Chris@0
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@0
|
12 License, or (at your option) any later version. See the file
|
Chris@0
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include <iostream>
|
Chris@0
|
17 #include <map>
|
Chris@0
|
18
|
Chris@0
|
19 using namespace std;
|
Chris@0
|
20
|
Chris@0
|
21 #include "DefaultFeatureWriter.h"
|
Chris@0
|
22
|
Chris@144
|
23 string
|
Chris@144
|
24 DefaultFeatureWriter::getDescription() const
|
Chris@144
|
25 {
|
Chris@144
|
26 return "Write features in a generic XML format, with <feature> or <summary> elements containing output name and some or all of timestamp, duration, values, and label.";
|
Chris@144
|
27 }
|
Chris@144
|
28
|
Chris@138
|
29 void DefaultFeatureWriter::write(QString,
|
Chris@138
|
30 const Transform &,
|
Chris@0
|
31 const Vamp::Plugin::OutputDescriptor& output,
|
Chris@0
|
32 const Vamp::Plugin::FeatureList& featureList,
|
Chris@0
|
33 std::string summaryType)
|
Chris@0
|
34 {
|
Chris@0
|
35 // generic XML output
|
Chris@0
|
36
|
Chris@0
|
37 /*
|
Chris@0
|
38
|
Chris@0
|
39 <feature>
|
Chris@0
|
40 <name>output.name</name>
|
Chris@0
|
41 <timestamp>feature.timestamp</timestamp>
|
Chris@0
|
42 <values>output.binName[0]:feature.value[0]...</values>
|
Chris@0
|
43 <label>feature.label</label>
|
Chris@0
|
44 </feature>
|
Chris@0
|
45
|
Chris@0
|
46 */
|
Chris@0
|
47
|
Chris@138
|
48 for (int i = 0; i < (int)featureList.size(); ++i) {
|
Chris@138
|
49
|
Chris@0
|
50 if (summaryType == "") {
|
Chris@0
|
51 cout << "<feature>" << endl;
|
Chris@0
|
52 } else {
|
Chris@0
|
53 cout << "<summary type=\"" << summaryType << "\">" << endl;
|
Chris@0
|
54 }
|
Chris@0
|
55 cout << "\t<name>" << output.name << "</name>" << endl;
|
Chris@0
|
56 if (featureList[i].hasTimestamp) {
|
Chris@0
|
57 cout << "\t<timestamp>" << featureList[i].timestamp << "</timestamp>" << endl;
|
Chris@0
|
58 }
|
Chris@0
|
59 if (featureList[i].hasDuration) {
|
Chris@0
|
60 cout << "\t<duration>" << featureList[i].duration << "</duration>" << endl;
|
Chris@0
|
61 }
|
Chris@0
|
62 if (featureList[i].values.size() > 0)
|
Chris@0
|
63 {
|
Chris@0
|
64 cout << "\t<values>";
|
Chris@138
|
65 for (int j = 0; j < (int)featureList[i].values.size(); ++j) {
|
Chris@0
|
66 if (j > 0)
|
Chris@0
|
67 cout << " ";
|
Chris@0
|
68 if (output.binNames.size() > 0)
|
Chris@0
|
69 cout << output.binNames[j] << ":";
|
Chris@0
|
70 cout << featureList[i].values[j];
|
Chris@0
|
71 }
|
Chris@0
|
72 cout << "</values>" << endl;
|
Chris@0
|
73 }
|
Chris@0
|
74 if (featureList[i].label.length() > 0)
|
Chris@0
|
75 cout << "\t<label>" << featureList[i].label << "</label>" << endl;
|
Chris@0
|
76 if (summaryType == "") {
|
Chris@0
|
77 cout << "</feature>" << endl;
|
Chris@0
|
78 } else {
|
Chris@0
|
79 cout << "</summary>" << endl;
|
Chris@0
|
80 }
|
Chris@0
|
81 }
|
Chris@0
|
82 }
|