| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // This application is a test for AudioRendererAlgorithmOLA. It reads in a | 5 // This application is a test for AudioRendererAlgorithmOLA. It reads in a |
| 6 // specified wav file (so far only 8, 16 and 32 bit are supported) and uses | 6 // specified wav file (so far only 8, 16 and 32 bit are supported) and uses |
| 7 // ARAO to scale the playback by a specified rate. Then it outputs the result | 7 // ARAO to scale the playback by a specified rate. Then it outputs the result |
| 8 // to the specified location. Command line calls should be as follows: | 8 // to the specified location. Command line calls should be as follows: |
| 9 // | 9 // |
| 10 // wav_ola_test RATE INFILE OUTFILE | 10 // wav_ola_test RATE INFILE OUTFILE |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 class Dummy { | 43 class Dummy { |
| 44 public: | 44 public: |
| 45 Dummy(FILE* in, AudioRendererAlgorithmOLA* ola, size_t window_size) | 45 Dummy(FILE* in, AudioRendererAlgorithmOLA* ola, size_t window_size) |
| 46 : input_(in), | 46 : input_(in), |
| 47 ola_(ola), | 47 ola_(ola), |
| 48 window_size_(window_size) { | 48 window_size_(window_size) { |
| 49 } | 49 } |
| 50 | 50 |
| 51 void ReadDataForAlg() { | 51 void ReadDataForAlg() { |
| 52 scoped_refptr<DataBuffer> buffer(new DataBuffer(window_size_)); | 52 scoped_refptr<DataBuffer> buffer(new DataBuffer(window_size_)); |
| 53 buffer->SetDataSize(window_size_); |
| 53 uint8* buf = buffer->GetWritableData(); | 54 uint8* buf = buffer->GetWritableData(); |
| 54 if (fread(buf, 1, window_size_, input_) > 0) { | 55 if (fread(buf, 1, window_size_, input_) > 0) { |
| 55 ola_->EnqueueBuffer(buffer.get()); | 56 ola_->EnqueueBuffer(buffer.get()); |
| 56 } | 57 } |
| 57 } | 58 } |
| 58 | 59 |
| 59 private: | 60 private: |
| 60 FILE* input_; | 61 FILE* input_; |
| 61 AudioRendererAlgorithmOLA* ola_; | 62 AudioRendererAlgorithmOLA* ola_; |
| 62 size_t window_size_; | 63 size_t window_size_; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 << "\n" | 130 << "\n" |
| 130 << "Scaling audio by " << playback_rate << "x..." << std::endl; | 131 << "Scaling audio by " << playback_rate << "x..." << std::endl; |
| 131 | 132 |
| 132 // Write the header back out again. | 133 // Write the header back out again. |
| 133 if (fwrite(&wav, sizeof(wav), 1, output.get()) < 1) { | 134 if (fwrite(&wav, sizeof(wav), 1, output.get()) < 1) { |
| 134 LOG(ERROR) << "could not write WAV header"; | 135 LOG(ERROR) << "could not write WAV header"; |
| 135 return 1; | 136 return 1; |
| 136 } | 137 } |
| 137 | 138 |
| 138 // Create buffer to be filled by |ola|. | 139 // Create buffer to be filled by |ola|. |
| 139 scoped_refptr<DataBuffer> buffer(new DataBuffer(window_size)); | 140 scoped_array<uint8> buf(new uint8[window_size]); |
| 140 const uint8* buf = buffer->GetData(); | 141 |
| 142 CHECK(buf.get()); |
| 141 | 143 |
| 142 // Keep track of bytes written to disk and bytes copied to |b|. | 144 // Keep track of bytes written to disk and bytes copied to |b|. |
| 143 size_t bytes_written = 0; | 145 size_t bytes_written = 0; |
| 144 size_t bytes; | 146 size_t bytes; |
| 145 while ((bytes = ola.FillBuffer(buffer.get())) > 0) { | 147 while ((bytes = ola.FillBuffer(buf.get(), window_size)) > 0) { |
| 146 if (fwrite(buf, 1, bytes, output.get()) != bytes) { | 148 if (fwrite(buf.get(), 1, bytes, output.get()) != bytes) { |
| 147 LOG(ERROR) << "could not write data after " << bytes_written; | 149 LOG(ERROR) << "could not write data after " << bytes_written; |
| 148 } else { | 150 } else { |
| 149 bytes_written += bytes; | 151 bytes_written += bytes; |
| 150 } | 152 } |
| 151 } | 153 } |
| 152 | 154 |
| 153 // Seek back to the beginning of our output file and update the header. | 155 // Seek back to the beginning of our output file and update the header. |
| 154 wav.chunk_size = 36 + bytes_written; | 156 wav.chunk_size = 36 + bytes_written; |
| 155 wav.subchunk1_size = 16; | 157 wav.subchunk1_size = 16; |
| 156 wav.subchunk2_size = bytes_written; | 158 wav.subchunk2_size = bytes_written; |
| 157 fseek(output.get(), 0, SEEK_SET); | 159 fseek(output.get(), 0, SEEK_SET); |
| 158 if (fwrite(&wav, sizeof(wav), 1, output.get()) < 1) { | 160 if (fwrite(&wav, sizeof(wav), 1, output.get()) < 1) { |
| 159 LOG(ERROR) << "could not write wav header."; | 161 LOG(ERROR) << "could not write wav header."; |
| 160 return 1; | 162 return 1; |
| 161 } | 163 } |
| 162 | 164 |
| 163 return 0; | 165 return 0; |
| 164 } | 166 } |
| OLD | NEW |