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

Side by Side Diff: media/tools/wav_ola_test.cc

Issue 149573: Refactor WritableBuffer interface for more useful ptr management. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « media/filters/ffmpeg_video_decoder_unittest.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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // Dummy class to feed data to OLA algorithm. Necessary to create callback. 42 // Dummy class to feed data to OLA algorithm. Necessary to create callback.
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> b(new DataBuffer()); 52 scoped_refptr<DataBuffer> buffer(new DataBuffer(window_size_));
53 uint8* buf = b->GetWritableData(window_size_); 53 uint8* buf = buffer->GetWritableData();
54 if (fread(buf, 1, window_size_, input_) > 0) { 54 if (fread(buf, 1, window_size_, input_) > 0) {
55 ola_->EnqueueBuffer(b.get()); 55 ola_->EnqueueBuffer(buffer.get());
56 } 56 }
57 } 57 }
58 58
59 private: 59 private:
60 FILE* input_; 60 FILE* input_;
61 AudioRendererAlgorithmOLA* ola_; 61 AudioRendererAlgorithmOLA* ola_;
62 size_t window_size_; 62 size_t window_size_;
63 63
64 DISALLOW_COPY_AND_ASSIGN(Dummy); 64 DISALLOW_COPY_AND_ASSIGN(Dummy);
65 }; 65 };
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 << "\n" 129 << "\n"
130 << "Scaling audio by " << playback_rate << "x..." << std::endl; 130 << "Scaling audio by " << playback_rate << "x..." << std::endl;
131 131
132 // Write the header back out again. 132 // Write the header back out again.
133 if (fwrite(&wav, sizeof(wav), 1, output.get()) < 1) { 133 if (fwrite(&wav, sizeof(wav), 1, output.get()) < 1) {
134 LOG(ERROR) << "could not write WAV header"; 134 LOG(ERROR) << "could not write WAV header";
135 return 1; 135 return 1;
136 } 136 }
137 137
138 // Create buffer to be filled by |ola|. 138 // Create buffer to be filled by |ola|.
139 scoped_refptr<DataBuffer> buffer(new DataBuffer()); 139 scoped_refptr<DataBuffer> buffer(new DataBuffer(window_size));
140 uint8* buf = buffer->GetWritableData(window_size); 140 const uint8* buf = buffer->GetData();
141 141
142 // Keep track of bytes written to disk and bytes copied to |b|. 142 // Keep track of bytes written to disk and bytes copied to |b|.
143 size_t bytes_written = 0; 143 size_t bytes_written = 0;
144 size_t bytes; 144 size_t bytes;
145 while ((bytes = ola.FillBuffer(buffer.get())) > 0) { 145 while ((bytes = ola.FillBuffer(buffer.get())) > 0) {
146 if (fwrite(buf, 1, bytes, output.get()) != bytes) { 146 if (fwrite(buf, 1, bytes, output.get()) != bytes) {
147 LOG(ERROR) << "could not write data after " << bytes_written; 147 LOG(ERROR) << "could not write data after " << bytes_written;
148 } else { 148 } else {
149 bytes_written += bytes; 149 bytes_written += bytes;
150 } 150 }
151 } 151 }
152 152
153 // Seek back to the beginning of our output file and update the header. 153 // Seek back to the beginning of our output file and update the header.
154 wav.chunk_size = 36 + bytes_written; 154 wav.chunk_size = 36 + bytes_written;
155 wav.subchunk1_size = 16; 155 wav.subchunk1_size = 16;
156 wav.subchunk2_size = bytes_written; 156 wav.subchunk2_size = bytes_written;
157 fseek(output.get(), 0, SEEK_SET); 157 fseek(output.get(), 0, SEEK_SET);
158 if (fwrite(&wav, sizeof(wav), 1, output.get()) < 1) { 158 if (fwrite(&wav, sizeof(wav), 1, output.get()) < 1) {
159 LOG(ERROR) << "could not write wav header."; 159 LOG(ERROR) << "could not write wav header.";
160 return 1; 160 return 1;
161 } 161 }
162 162
163 return 0; 163 return 0;
164 } 164 }
OLDNEW
« no previous file with comments | « media/filters/ffmpeg_video_decoder_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698