| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/environment.h" | 9 #include "base/environment.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 binary_file_ = file_util::OpenFile(file_path, "wb"); | 58 binary_file_ = file_util::OpenFile(file_path, "wb"); |
| 59 DLOG_IF(ERROR, !binary_file_) << "Failed to open binary PCM data file."; | 59 DLOG_IF(ERROR, !binary_file_) << "Failed to open binary PCM data file."; |
| 60 LOG(INFO) << ">> Output file: " << file_path.value() | 60 LOG(INFO) << ">> Output file: " << file_path.value() |
| 61 << " has been created."; | 61 << " has been created."; |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual ~WriteToFileAudioSink() { | 64 virtual ~WriteToFileAudioSink() { |
| 65 size_t bytes_written = 0; | 65 size_t bytes_written = 0; |
| 66 while (bytes_written < bytes_to_write_) { | 66 while (bytes_written < bytes_to_write_) { |
| 67 const uint8* chunk; | 67 const uint8* chunk; |
| 68 size_t chunk_size; | 68 int chunk_size; |
| 69 | 69 |
| 70 // Stop writing if no more data is available. | 70 // Stop writing if no more data is available. |
| 71 if (!buffer_.GetCurrentChunk(&chunk, &chunk_size)) | 71 if (!buffer_.GetCurrentChunk(&chunk, &chunk_size)) |
| 72 break; | 72 break; |
| 73 | 73 |
| 74 // Write recorded data chunk to the file and prepare for next chunk. | 74 // Write recorded data chunk to the file and prepare for next chunk. |
| 75 fwrite(chunk, 1, chunk_size, binary_file_); | 75 fwrite(chunk, 1, chunk_size, binary_file_); |
| 76 buffer_.Seek(chunk_size); | 76 buffer_.Seek(chunk_size); |
| 77 bytes_written += chunk_size; | 77 bytes_written += chunk_size; |
| 78 } | 78 } |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 | 383 |
| 384 LOG(INFO) << ">> Sample rate: " << aisw.sample_rate() << " [Hz]"; | 384 LOG(INFO) << ">> Sample rate: " << aisw.sample_rate() << " [Hz]"; |
| 385 WriteToFileAudioSink file_sink(file_name); | 385 WriteToFileAudioSink file_sink(file_name); |
| 386 LOG(INFO) << ">> Speak into the default microphone while recording."; | 386 LOG(INFO) << ">> Speak into the default microphone while recording."; |
| 387 ais->Start(&file_sink); | 387 ais->Start(&file_sink); |
| 388 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); | 388 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); |
| 389 ais->Stop(); | 389 ais->Stop(); |
| 390 LOG(INFO) << ">> Recording has stopped."; | 390 LOG(INFO) << ">> Recording has stopped."; |
| 391 ais->Close(); | 391 ais->Close(); |
| 392 } | 392 } |
| OLD | NEW |