Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: webrtc/modules/audio_coding/neteq/test/audio_classifier_test.cc

Issue 2615983002: Remove AudioClassifier (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/audio_coding/neteq/audio_classifier.h"
12
13 #include <math.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17
18 #include <iostream>
19 #include <memory>
20 #include <string>
21
22 int main(int argc, char* argv[]) {
23 if (argc != 5) {
24 std::cout << "Usage: " << argv[0] <<
25 " channels output_type <input file name> <output file name> "
26 << std::endl << std::endl;
27 std::cout << "Where channels can be 1 (mono) or 2 (interleaved stereo),";
28 std::cout << " outputs can be 1 (classification (boolean)) or 2";
29 std::cout << " (classification and music probability (float)),"
30 << std::endl;
31 std::cout << "and the sampling frequency is assumed to be 48 kHz."
32 << std::endl;
33 return -1;
34 }
35
36 const int kFrameSizeSamples = 960;
37 int channels = atoi(argv[1]);
38 if (channels < 1 || channels > 2) {
39 std::cout << "Disallowed number of channels " << channels << std::endl;
40 return -1;
41 }
42
43 int outputs = atoi(argv[2]);
44 if (outputs < 1 || outputs > 2) {
45 std::cout << "Disallowed number of outputs " << outputs << std::endl;
46 return -1;
47 }
48
49 const int data_size = channels * kFrameSizeSamples;
50 std::unique_ptr<int16_t[]> in(new int16_t[data_size]);
51
52 std::string input_filename = argv[3];
53 std::string output_filename = argv[4];
54
55 std::cout << "Input file: " << input_filename << std::endl;
56 std::cout << "Output file: " << output_filename << std::endl;
57
58 FILE* in_file = fopen(input_filename.c_str(), "rb");
59 if (!in_file) {
60 std::cout << "Cannot open input file " << input_filename << std::endl;
61 return -1;
62 }
63
64 FILE* out_file = fopen(output_filename.c_str(), "wb");
65 if (!out_file) {
66 std::cout << "Cannot open output file " << output_filename << std::endl;
67 return -1;
68 }
69
70 webrtc::AudioClassifier classifier;
71 int frame_counter = 0;
72 int music_counter = 0;
73 while (fread(in.get(), sizeof(*in.get()),
74 data_size, in_file) == (size_t) data_size) {
75 bool is_music = classifier.Analysis(in.get(), data_size, channels);
76 if (!fwrite(&is_music, sizeof(is_music), 1, out_file)) {
77 std::cout << "Error writing." << std::endl;
78 return -1;
79 }
80 if (is_music) {
81 music_counter++;
82 }
83 std::cout << "frame " << frame_counter << " decision " << is_music;
84 if (outputs == 2) {
85 float music_prob = classifier.music_probability();
86 if (!fwrite(&music_prob, sizeof(music_prob), 1, out_file)) {
87 std::cout << "Error writing." << std::endl;
88 return -1;
89 }
90 std::cout << " music prob " << music_prob;
91 }
92 std::cout << std::endl;
93 frame_counter++;
94 }
95 std::cout << frame_counter << " frames processed." << std::endl;
96 if (frame_counter > 0) {
97 float music_percentage = music_counter / static_cast<float>(frame_counter);
98 std::cout << music_percentage << " percent music." << std::endl;
99 }
100
101 fclose(in_file);
102 fclose(out_file);
103 return 0;
104 }
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/neteq.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698