OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <ctime> | 5 #include <ctime> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/process/launch.h" | 10 #include "base/process/launch.h" |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 command_line.SetProgram(base::FilePath("arecord")); | 206 command_line.SetProgram(base::FilePath("arecord")); |
207 command_line.AppendArg("-d"); | 207 command_line.AppendArg("-d"); |
208 command_line.AppendArg(base::StringPrintf("%d", duration_sec)); | 208 command_line.AppendArg(base::StringPrintf("%d", duration_sec)); |
209 command_line.AppendArg("-f"); | 209 command_line.AppendArg("-f"); |
210 command_line.AppendArg("dat"); | 210 command_line.AppendArg("dat"); |
211 command_line.AppendArg("-c"); | 211 command_line.AppendArg("-c"); |
212 command_line.AppendArg(base::StringPrintf("%d", num_channels)); | 212 command_line.AppendArg(base::StringPrintf("%d", num_channels)); |
213 command_line.AppendArgPath(output_file); | 213 command_line.AppendArgPath(output_file); |
214 #endif | 214 #endif |
215 | 215 |
216 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 216 DVLOG(0) << "Running " << command_line.GetCommandLineString(); |
217 return base::LaunchProcess(command_line, base::LaunchOptions(), | 217 return base::LaunchProcess(command_line, base::LaunchOptions(), |
218 &recording_application_); | 218 &recording_application_); |
219 } | 219 } |
220 | 220 |
221 // Joins the recording program. Returns true on success. | 221 // Joins the recording program. Returns true on success. |
222 bool WaitForRecordingToEnd() { | 222 bool WaitForRecordingToEnd() { |
223 int exit_code = -1; | 223 int exit_code = -1; |
224 base::WaitForExitCode(recording_application_, &exit_code); | 224 base::WaitForExitCode(recording_application_, &exit_code); |
225 return exit_code == 0; | 225 return exit_code == 0; |
226 } | 226 } |
227 private: | 227 private: |
228 base::ProcessHandle recording_application_; | 228 base::ProcessHandle recording_application_; |
229 }; | 229 }; |
230 | 230 |
231 bool ForceMicrophoneVolumeTo100Percent() { | 231 bool ForceMicrophoneVolumeTo100Percent() { |
232 #if defined(OS_WIN) | 232 #if defined(OS_WIN) |
233 // Note: the force binary isn't in tools since it's one of our own. | 233 // Note: the force binary isn't in tools since it's one of our own. |
234 CommandLine command_line(test::GetReferenceFilesDir().Append( | 234 CommandLine command_line(test::GetReferenceFilesDir().Append( |
235 FILE_PATH_LITERAL("force_mic_volume_max.exe"))); | 235 FILE_PATH_LITERAL("force_mic_volume_max.exe"))); |
236 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 236 DVLOG(0) << "Running " << command_line.GetCommandLineString(); |
237 std::string result; | 237 std::string result; |
238 if (!base::GetAppOutput(command_line, &result)) { | 238 if (!base::GetAppOutput(command_line, &result)) { |
239 LOG(ERROR) << "Failed to set source volume: output was " << result; | 239 LOG(ERROR) << "Failed to set source volume: output was " << result; |
240 return false; | 240 return false; |
241 } | 241 } |
242 #elif defined(OS_MACOSX) | 242 #elif defined(OS_MACOSX) |
243 CommandLine command_line(base::FilePath(FILE_PATH_LITERAL("osascript"))); | 243 CommandLine command_line(base::FilePath(FILE_PATH_LITERAL("osascript"))); |
244 command_line.AppendArg("-e"); | 244 command_line.AppendArg("-e"); |
245 command_line.AppendArg("set volume input volume 100"); | 245 command_line.AppendArg("set volume input volume 100"); |
246 command_line.AppendArg("-e"); | 246 command_line.AppendArg("-e"); |
247 command_line.AppendArg("set volume output volume 100"); | 247 command_line.AppendArg("set volume output volume 100"); |
248 | 248 |
249 std::string result; | 249 std::string result; |
250 if (!base::GetAppOutput(command_line, &result)) { | 250 if (!base::GetAppOutput(command_line, &result)) { |
251 LOG(ERROR) << "Failed to set source volume: output was " << result; | 251 LOG(ERROR) << "Failed to set source volume: output was " << result; |
252 return false; | 252 return false; |
253 } | 253 } |
254 #else | 254 #else |
255 // Just force the volume of, say the first 5 devices. A machine will rarely | 255 // Just force the volume of, say the first 5 devices. A machine will rarely |
256 // have more input sources than that. This is way easier than finding the | 256 // have more input sources than that. This is way easier than finding the |
257 // input device we happen to be using. | 257 // input device we happen to be using. |
258 for (int device_index = 0; device_index < 5; ++device_index) { | 258 for (int device_index = 0; device_index < 5; ++device_index) { |
259 std::string result; | 259 std::string result; |
260 const std::string kHundredPercentVolume = "65536"; | 260 const std::string kHundredPercentVolume = "65536"; |
261 CommandLine command_line(base::FilePath(FILE_PATH_LITERAL("pacmd"))); | 261 CommandLine command_line(base::FilePath(FILE_PATH_LITERAL("pacmd"))); |
262 command_line.AppendArg("set-source-volume"); | 262 command_line.AppendArg("set-source-volume"); |
263 command_line.AppendArg(base::StringPrintf("%d", device_index)); | 263 command_line.AppendArg(base::StringPrintf("%d", device_index)); |
264 command_line.AppendArg(kHundredPercentVolume); | 264 command_line.AppendArg(kHundredPercentVolume); |
265 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 265 DVLOG(0) << "Running " << command_line.GetCommandLineString(); |
266 if (!base::GetAppOutput(command_line, &result)) { | 266 if (!base::GetAppOutput(command_line, &result)) { |
267 LOG(ERROR) << "Failed to set source volume: output was " << result; | 267 LOG(ERROR) << "Failed to set source volume: output was " << result; |
268 return false; | 268 return false; |
269 } | 269 } |
270 } | 270 } |
271 #endif | 271 #endif |
272 return true; | 272 return true; |
273 } | 273 } |
274 | 274 |
275 // Removes silence from beginning and end of the |input_audio_file| and writes | 275 // Removes silence from beginning and end of the |input_audio_file| and writes |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 command_line.AppendArg(kAbovePeriods); | 308 command_line.AppendArg(kAbovePeriods); |
309 command_line.AppendArg(kDuration); | 309 command_line.AppendArg(kDuration); |
310 command_line.AppendArg(kTreshold); | 310 command_line.AppendArg(kTreshold); |
311 command_line.AppendArg("reverse"); | 311 command_line.AppendArg("reverse"); |
312 command_line.AppendArg("silence"); | 312 command_line.AppendArg("silence"); |
313 command_line.AppendArg(kAbovePeriods); | 313 command_line.AppendArg(kAbovePeriods); |
314 command_line.AppendArg(kDuration); | 314 command_line.AppendArg(kDuration); |
315 command_line.AppendArg(kTreshold); | 315 command_line.AppendArg(kTreshold); |
316 command_line.AppendArg("reverse"); | 316 command_line.AppendArg("reverse"); |
317 | 317 |
318 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 318 DVLOG(0) << "Running " << command_line.GetCommandLineString(); |
319 std::string result; | 319 std::string result; |
320 bool ok = base::GetAppOutput(command_line, &result); | 320 bool ok = base::GetAppOutput(command_line, &result); |
321 VLOG(0) << "Output was:\n\n" << result; | 321 DVLOG(0) << "Output was:\n\n" << result; |
322 return ok; | 322 return ok; |
323 } | 323 } |
324 | 324 |
325 bool CanParseAsFloat(const std::string& value) { | 325 bool CanParseAsFloat(const std::string& value) { |
326 return atof(value.c_str()) != 0 || value == "0"; | 326 return atof(value.c_str()) != 0 || value == "0"; |
327 } | 327 } |
328 | 328 |
329 // Runs PESQ to compare |reference_file| to a |actual_file|. The |sample_rate| | 329 // Runs PESQ to compare |reference_file| to a |actual_file|. The |sample_rate| |
330 // can be either 16000 or 8000. | 330 // can be either 16000 or 8000. |
331 // | 331 // |
(...skipping 27 matching lines...) Expand all Loading... |
359 LOG(ERROR) << "Missing PESQ binary in " << pesq_path.value() | 359 LOG(ERROR) << "Missing PESQ binary in " << pesq_path.value() |
360 << "; you may have to provide this binary yourself."; | 360 << "; you may have to provide this binary yourself."; |
361 return false; | 361 return false; |
362 } | 362 } |
363 | 363 |
364 CommandLine command_line(pesq_path); | 364 CommandLine command_line(pesq_path); |
365 command_line.AppendArg(base::StringPrintf("+%d", sample_rate)); | 365 command_line.AppendArg(base::StringPrintf("+%d", sample_rate)); |
366 command_line.AppendArgPath(reference_file); | 366 command_line.AppendArgPath(reference_file); |
367 command_line.AppendArgPath(actual_file); | 367 command_line.AppendArgPath(actual_file); |
368 | 368 |
369 VLOG(0) << "Running " << command_line.GetCommandLineString(); | 369 DVLOG(0) << "Running " << command_line.GetCommandLineString(); |
370 std::string result; | 370 std::string result; |
371 if (!base::GetAppOutput(command_line, &result)) { | 371 if (!base::GetAppOutput(command_line, &result)) { |
372 LOG(ERROR) << "Failed to run PESQ."; | 372 LOG(ERROR) << "Failed to run PESQ."; |
373 return false; | 373 return false; |
374 } | 374 } |
375 VLOG(0) << "Output was:\n\n" << result; | 375 DVLOG(0) << "Output was:\n\n" << result; |
376 | 376 |
377 const std::string result_anchor = "Prediction (Raw MOS, MOS-LQO): = "; | 377 const std::string result_anchor = "Prediction (Raw MOS, MOS-LQO): = "; |
378 std::size_t anchor_pos = result.find(result_anchor); | 378 std::size_t anchor_pos = result.find(result_anchor); |
379 if (anchor_pos == std::string::npos) { | 379 if (anchor_pos == std::string::npos) { |
380 LOG(ERROR) << "PESQ was not able to compute a score; we probably recorded " | 380 LOG(ERROR) << "PESQ was not able to compute a score; we probably recorded " |
381 << "only silence. Please check the output/input volume levels."; | 381 << "only silence. Please check the output/input volume levels."; |
382 return false; | 382 return false; |
383 } | 383 } |
384 | 384 |
385 // There are two tab-separated numbers on the format x.xxx, e.g. 5 chars each. | 385 // There are two tab-separated numbers on the format x.xxx, e.g. 5 chars each. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 | 447 |
448 // Note: the sound clip is about 10 seconds: record for 15 seconds to get some | 448 // Note: the sound clip is about 10 seconds: record for 15 seconds to get some |
449 // safety margins on each side. | 449 // safety margins on each side. |
450 AudioRecorder recorder; | 450 AudioRecorder recorder; |
451 static int kRecordingTimeSeconds = 15; | 451 static int kRecordingTimeSeconds = 15; |
452 ASSERT_TRUE(recorder.StartRecording(kRecordingTimeSeconds, recording, true)); | 452 ASSERT_TRUE(recorder.StartRecording(kRecordingTimeSeconds, recording, true)); |
453 | 453 |
454 PlayAudioFile(left_tab); | 454 PlayAudioFile(left_tab); |
455 | 455 |
456 ASSERT_TRUE(recorder.WaitForRecordingToEnd()); | 456 ASSERT_TRUE(recorder.WaitForRecordingToEnd()); |
457 VLOG(0) << "Done recording to " << recording.value() << std::endl; | 457 DVLOG(0) << "Done recording to " << recording.value() << std::endl; |
458 | 458 |
459 HangUp(left_tab); | 459 HangUp(left_tab); |
460 | 460 |
461 base::FilePath trimmed_recording = CreateTemporaryWaveFile(); | 461 base::FilePath trimmed_recording = CreateTemporaryWaveFile(); |
462 | 462 |
463 ASSERT_TRUE(RemoveSilence(recording, trimmed_recording)); | 463 ASSERT_TRUE(RemoveSilence(recording, trimmed_recording)); |
464 VLOG(0) << "Trimmed silence: " << trimmed_recording.value() << std::endl; | 464 DVLOG(0) << "Trimmed silence: " << trimmed_recording.value() << std::endl; |
465 | 465 |
466 std::string raw_mos; | 466 std::string raw_mos; |
467 std::string mos_lqo; | 467 std::string mos_lqo; |
468 base::FilePath reference_file_in_test_dir = | 468 base::FilePath reference_file_in_test_dir = |
469 test::GetReferenceFilesDir().Append(kReferenceFile); | 469 test::GetReferenceFilesDir().Append(kReferenceFile); |
470 ASSERT_TRUE(RunPesq(reference_file_in_test_dir, trimmed_recording, 16000, | 470 ASSERT_TRUE(RunPesq(reference_file_in_test_dir, trimmed_recording, 16000, |
471 &raw_mos, &mos_lqo)); | 471 &raw_mos, &mos_lqo)); |
472 | 472 |
473 perf_test::PrintResult("audio_pesq", "", "raw_mos", raw_mos, "score", true); | 473 perf_test::PrintResult("audio_pesq", "", "raw_mos", raw_mos, "score", true); |
474 perf_test::PrintResult("audio_pesq", "", "mos_lqo", mos_lqo, "score", true); | 474 perf_test::PrintResult("audio_pesq", "", "mos_lqo", mos_lqo, "score", true); |
475 | 475 |
476 EXPECT_TRUE(base::DeleteFile(recording, false)); | 476 EXPECT_TRUE(base::DeleteFile(recording, false)); |
477 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); | 477 EXPECT_TRUE(base::DeleteFile(trimmed_recording, false)); |
478 } | 478 } |
OLD | NEW |