Linux: Depend on liberation-fonts package for RPMs.
[chromium-blink-merge.git] / media / base / audio_buffer_unittest.cc
blobb48220df528d2837e70a3e5663712e4b2e9cd4d8
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
3 // found in the LICENSE file.
5 #include "media/base/audio_buffer.h"
6 #include "media/base/audio_bus.h"
7 #include "media/base/test_helpers.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace media {
12 static const int kSampleRate = 48000;
14 static void VerifyBusWithOffset(AudioBus* bus,
15 int offset,
16 int frames,
17 float start,
18 float start_offset,
19 float increment) {
20 for (int ch = 0; ch < bus->channels(); ++ch) {
21 const float v = start_offset + start + ch * bus->frames() * increment;
22 for (int i = offset; i < offset + frames; ++i) {
23 ASSERT_FLOAT_EQ(v + i * increment, bus->channel(ch)[i]) << "i=" << i
24 << ", ch=" << ch;
29 static void VerifyBus(AudioBus* bus, int frames, float start, float increment) {
30 VerifyBusWithOffset(bus, 0, frames, start, 0, increment);
33 static void TrimRangeTest(SampleFormat sample_format) {
34 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
35 const int channels = ChannelLayoutToChannelCount(channel_layout);
36 const int frames = kSampleRate / 10;
37 const base::TimeDelta timestamp = base::TimeDelta();
38 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
39 scoped_refptr<AudioBuffer> buffer = MakeAudioBuffer<float>(sample_format,
40 channel_layout,
41 channels,
42 kSampleRate,
45 frames,
46 timestamp);
47 EXPECT_EQ(frames, buffer->frame_count());
48 EXPECT_EQ(timestamp, buffer->timestamp());
49 EXPECT_EQ(duration, buffer->duration());
51 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
53 // Verify all frames before trimming.
54 buffer->ReadFrames(frames, 0, 0, bus.get());
55 VerifyBus(bus.get(), frames, 0, 1);
57 // Trim 10ms of frames from the middle of the buffer.
58 int trim_start = frames / 2;
59 const int trim_length = kSampleRate / 100;
60 const base::TimeDelta trim_duration = base::TimeDelta::FromMilliseconds(10);
61 buffer->TrimRange(trim_start, trim_start + trim_length);
62 EXPECT_EQ(frames - trim_length, buffer->frame_count());
63 EXPECT_EQ(timestamp, buffer->timestamp());
64 EXPECT_EQ(duration - trim_duration, buffer->duration());
65 bus->Zero();
66 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
67 VerifyBus(bus.get(), trim_start, 0, 1);
68 VerifyBusWithOffset(bus.get(),
69 trim_start,
70 buffer->frame_count() - trim_start,
72 trim_length,
73 1);
75 // Trim 10ms of frames from the start, which just adjusts the buffer's
76 // internal start offset.
77 buffer->TrimStart(trim_length);
78 trim_start -= trim_length;
79 EXPECT_EQ(frames - 2 * trim_length, buffer->frame_count());
80 EXPECT_EQ(timestamp + trim_duration, buffer->timestamp());
81 EXPECT_EQ(duration - 2 * trim_duration, buffer->duration());
82 bus->Zero();
83 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
84 VerifyBus(bus.get(), trim_start, trim_length, 1);
85 VerifyBusWithOffset(bus.get(),
86 trim_start,
87 buffer->frame_count() - trim_start,
88 trim_length,
89 trim_length,
90 1);
92 // Trim 10ms of frames from the end, which just adjusts the buffer's frame
93 // count.
94 buffer->TrimEnd(trim_length);
95 EXPECT_EQ(frames - 3 * trim_length, buffer->frame_count());
96 EXPECT_EQ(timestamp + trim_duration, buffer->timestamp());
97 EXPECT_EQ(duration - 3 * trim_duration, buffer->duration());
98 bus->Zero();
99 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
100 VerifyBus(bus.get(), trim_start, trim_length, 1);
101 VerifyBusWithOffset(bus.get(),
102 trim_start,
103 buffer->frame_count() - trim_start,
104 trim_length,
105 trim_length,
108 // Trim another 10ms from the inner portion of the buffer.
109 buffer->TrimRange(trim_start, trim_start + trim_length);
110 EXPECT_EQ(frames - 4 * trim_length, buffer->frame_count());
111 EXPECT_EQ(timestamp + trim_duration, buffer->timestamp());
112 EXPECT_EQ(duration - 4 * trim_duration, buffer->duration());
113 bus->Zero();
114 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
115 VerifyBus(bus.get(), trim_start, trim_length, 1);
116 VerifyBusWithOffset(bus.get(),
117 trim_start,
118 buffer->frame_count() - trim_start,
119 trim_length,
120 trim_length * 2,
123 // Trim off the end using TrimRange() to ensure end index is exclusive.
124 buffer->TrimRange(buffer->frame_count() - trim_length, buffer->frame_count());
125 EXPECT_EQ(frames - 5 * trim_length, buffer->frame_count());
126 EXPECT_EQ(timestamp + trim_duration, buffer->timestamp());
127 EXPECT_EQ(duration - 5 * trim_duration, buffer->duration());
128 bus->Zero();
129 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
130 VerifyBus(bus.get(), trim_start, trim_length, 1);
131 VerifyBusWithOffset(bus.get(),
132 trim_start,
133 buffer->frame_count() - trim_start,
134 trim_length,
135 trim_length * 2,
138 // Trim off the start using TrimRange() to ensure start index is inclusive.
139 buffer->TrimRange(0, trim_length);
140 trim_start -= trim_length;
141 EXPECT_EQ(frames - 6 * trim_length, buffer->frame_count());
142 EXPECT_EQ(timestamp + trim_duration, buffer->timestamp());
143 EXPECT_EQ(duration - 6 * trim_duration, buffer->duration());
144 bus->Zero();
145 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
146 VerifyBus(bus.get(), trim_start, 2 * trim_length, 1);
147 VerifyBusWithOffset(bus.get(),
148 trim_start,
149 buffer->frame_count() - trim_start,
150 trim_length * 2,
151 trim_length * 2,
155 TEST(AudioBufferTest, CopyFrom) {
156 const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_MONO;
157 scoped_refptr<AudioBuffer> original_buffer =
158 MakeAudioBuffer<uint8>(kSampleFormatU8,
159 kChannelLayout,
160 ChannelLayoutToChannelCount(kChannelLayout),
161 kSampleRate,
164 kSampleRate / 100,
165 base::TimeDelta());
166 scoped_refptr<AudioBuffer> new_buffer =
167 AudioBuffer::CopyFrom(kSampleFormatU8,
168 original_buffer->channel_layout(),
169 original_buffer->channel_count(),
170 original_buffer->sample_rate(),
171 original_buffer->frame_count(),
172 &original_buffer->channel_data()[0],
173 original_buffer->timestamp());
174 EXPECT_EQ(original_buffer->frame_count(), new_buffer->frame_count());
175 EXPECT_EQ(original_buffer->timestamp(), new_buffer->timestamp());
176 EXPECT_EQ(original_buffer->duration(), new_buffer->duration());
177 EXPECT_EQ(original_buffer->sample_rate(), new_buffer->sample_rate());
178 EXPECT_EQ(original_buffer->channel_count(), new_buffer->channel_count());
179 EXPECT_EQ(original_buffer->channel_layout(), new_buffer->channel_layout());
180 EXPECT_FALSE(original_buffer->end_of_stream());
183 TEST(AudioBufferTest, CreateEOSBuffer) {
184 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateEOSBuffer();
185 EXPECT_TRUE(buffer->end_of_stream());
188 TEST(AudioBufferTest, FrameSize) {
189 const uint8 kTestData[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
190 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
191 27, 28, 29, 30, 31 };
192 const base::TimeDelta kTimestamp = base::TimeDelta::FromMicroseconds(1337);
194 const uint8* const data[] = { kTestData };
195 scoped_refptr<AudioBuffer> buffer =
196 AudioBuffer::CopyFrom(kSampleFormatU8,
197 CHANNEL_LAYOUT_STEREO,
199 kSampleRate,
201 data,
202 kTimestamp);
203 EXPECT_EQ(16, buffer->frame_count()); // 2 channels of 8-bit data
205 buffer = AudioBuffer::CopyFrom(kSampleFormatF32, CHANNEL_LAYOUT_4_0, 4,
206 kSampleRate, 2, data, kTimestamp);
207 EXPECT_EQ(2, buffer->frame_count()); // now 4 channels of 32-bit data
210 TEST(AudioBufferTest, ReadU8) {
211 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
212 const int channels = ChannelLayoutToChannelCount(channel_layout);
213 const int frames = 10;
214 const base::TimeDelta start_time;
215 scoped_refptr<AudioBuffer> buffer = MakeAudioBuffer<uint8>(kSampleFormatU8,
216 channel_layout,
217 channels,
218 kSampleRate,
219 128,
221 frames,
222 start_time);
223 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
224 buffer->ReadFrames(frames, 0, 0, bus.get());
225 VerifyBus(bus.get(), frames, 0, 1.0f / 127.0f);
227 // Now read the same data one frame at a time.
228 bus->Zero();
229 for (int i = 0; i < frames; ++i)
230 buffer->ReadFrames(1, i, i, bus.get());
231 VerifyBus(bus.get(), frames, 0, 1.0f / 127.0f);
234 TEST(AudioBufferTest, ReadS16) {
235 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
236 const int channels = ChannelLayoutToChannelCount(channel_layout);
237 const int frames = 10;
238 const base::TimeDelta start_time;
239 scoped_refptr<AudioBuffer> buffer = MakeAudioBuffer<int16>(kSampleFormatS16,
240 channel_layout,
241 channels,
242 kSampleRate,
245 frames,
246 start_time);
247 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
248 buffer->ReadFrames(frames, 0, 0, bus.get());
249 VerifyBus(bus.get(), frames, 1.0f / kint16max, 1.0f / kint16max);
251 // Now read the same data one frame at a time.
252 bus->Zero();
253 for (int i = 0; i < frames; ++i)
254 buffer->ReadFrames(1, i, i, bus.get());
255 VerifyBus(bus.get(), frames, 1.0f / kint16max, 1.0f / kint16max);
258 TEST(AudioBufferTest, ReadS32) {
259 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
260 const int channels = ChannelLayoutToChannelCount(channel_layout);
261 const int frames = 20;
262 const base::TimeDelta start_time;
263 scoped_refptr<AudioBuffer> buffer = MakeAudioBuffer<int32>(kSampleFormatS32,
264 channel_layout,
265 channels,
266 kSampleRate,
269 frames,
270 start_time);
271 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
272 buffer->ReadFrames(frames, 0, 0, bus.get());
273 VerifyBus(bus.get(), frames, 1.0f / kint32max, 1.0f / kint32max);
275 // Read second 10 frames.
276 bus->Zero();
277 buffer->ReadFrames(10, 10, 0, bus.get());
278 VerifyBus(bus.get(), 10, 11.0f / kint32max, 1.0f / kint32max);
281 TEST(AudioBufferTest, ReadF32) {
282 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
283 const int channels = ChannelLayoutToChannelCount(channel_layout);
284 const int frames = 20;
285 const base::TimeDelta start_time;
286 scoped_refptr<AudioBuffer> buffer = MakeAudioBuffer<float>(kSampleFormatF32,
287 channel_layout,
288 channels,
289 kSampleRate,
290 1.0f,
291 1.0f,
292 frames,
293 start_time);
294 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
295 buffer->ReadFrames(10, 0, 0, bus.get());
296 VerifyBus(bus.get(), 10, 1, 1);
298 // Read second 10 frames.
299 bus->Zero();
300 buffer->ReadFrames(10, 10, 0, bus.get());
301 VerifyBus(bus.get(), 10, 11, 1);
304 TEST(AudioBufferTest, ReadS16Planar) {
305 const ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
306 const int channels = ChannelLayoutToChannelCount(channel_layout);
307 const int frames = 20;
308 const base::TimeDelta start_time;
309 scoped_refptr<AudioBuffer> buffer =
310 MakeAudioBuffer<int16>(kSampleFormatPlanarS16,
311 channel_layout,
312 channels,
313 kSampleRate,
316 frames,
317 start_time);
318 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
319 buffer->ReadFrames(10, 0, 0, bus.get());
320 VerifyBus(bus.get(), 10, 1.0f / kint16max, 1.0f / kint16max);
322 // Read all the frames backwards, one by one. ch[0] should be 20, 19, ...
323 bus->Zero();
324 for (int i = frames - 1; i >= 0; --i)
325 buffer->ReadFrames(1, i, i, bus.get());
326 VerifyBus(bus.get(), frames, 1.0f / kint16max, 1.0f / kint16max);
328 // Read 0 frames with different offsets. Existing data in AudioBus should be
329 // unchanged.
330 buffer->ReadFrames(0, 0, 0, bus.get());
331 VerifyBus(bus.get(), frames, 1.0f / kint16max, 1.0f / kint16max);
332 buffer->ReadFrames(0, 0, 10, bus.get());
333 VerifyBus(bus.get(), frames, 1.0f / kint16max, 1.0f / kint16max);
334 buffer->ReadFrames(0, 10, 0, bus.get());
335 VerifyBus(bus.get(), frames, 1.0f / kint16max, 1.0f / kint16max);
338 TEST(AudioBufferTest, ReadF32Planar) {
339 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
340 const int channels = ChannelLayoutToChannelCount(channel_layout);
341 const int frames = 100;
342 const base::TimeDelta start_time;
343 scoped_refptr<AudioBuffer> buffer =
344 MakeAudioBuffer<float>(kSampleFormatPlanarF32,
345 channel_layout,
346 channels,
347 kSampleRate,
348 1.0f,
349 1.0f,
350 frames,
351 start_time);
353 // Read all 100 frames from the buffer. F32 is planar, so ch[0] should be 1,
354 // 2, 3, 4, ..., ch[1] should be 101, 102, 103, ..., and so on for all 4
355 // channels.
356 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, 100);
357 buffer->ReadFrames(frames, 0, 0, bus.get());
358 VerifyBus(bus.get(), frames, 1, 1);
360 // Now read 20 frames from the middle of the buffer.
361 bus->Zero();
362 buffer->ReadFrames(20, 50, 0, bus.get());
363 VerifyBus(bus.get(), 20, 51, 1);
366 TEST(AudioBufferTest, EmptyBuffer) {
367 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
368 const int channels = ChannelLayoutToChannelCount(channel_layout);
369 const int frames = kSampleRate / 100;
370 const base::TimeDelta start_time;
371 scoped_refptr<AudioBuffer> buffer = AudioBuffer::CreateEmptyBuffer(
372 channel_layout, channels, kSampleRate, frames, start_time);
373 EXPECT_EQ(frames, buffer->frame_count());
374 EXPECT_EQ(start_time, buffer->timestamp());
375 EXPECT_EQ(base::TimeDelta::FromMilliseconds(10), buffer->duration());
376 EXPECT_FALSE(buffer->end_of_stream());
378 // Read all 100 frames from the buffer. All data should be 0.
379 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
380 buffer->ReadFrames(frames, 0, 0, bus.get());
381 VerifyBus(bus.get(), frames, 0, 0);
384 TEST(AudioBufferTest, Trim) {
385 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
386 const int channels = ChannelLayoutToChannelCount(channel_layout);
387 const int frames = kSampleRate / 10;
388 const base::TimeDelta start_time;
389 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(100);
390 scoped_refptr<AudioBuffer> buffer =
391 MakeAudioBuffer<float>(kSampleFormatPlanarF32,
392 channel_layout,
393 channels,
394 kSampleRate,
395 0.0f,
396 1.0f,
397 frames,
398 start_time);
399 EXPECT_EQ(frames, buffer->frame_count());
400 EXPECT_EQ(start_time, buffer->timestamp());
401 EXPECT_EQ(duration, buffer->duration());
403 const int ten_ms_of_frames = kSampleRate / 100;
404 const base::TimeDelta ten_ms = base::TimeDelta::FromMilliseconds(10);
406 scoped_ptr<AudioBus> bus = AudioBus::Create(channels, frames);
407 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
408 VerifyBus(bus.get(), buffer->frame_count(), 0.0f, 1.0f);
410 // Trim off 10ms of frames from the start.
411 buffer->TrimStart(ten_ms_of_frames);
412 EXPECT_EQ(start_time + ten_ms, buffer->timestamp());
413 EXPECT_EQ(frames - ten_ms_of_frames, buffer->frame_count());
414 EXPECT_EQ(duration - ten_ms, buffer->duration());
415 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
416 VerifyBus(bus.get(), buffer->frame_count(), ten_ms_of_frames, 1.0f);
418 // Trim off 10ms of frames from the end.
419 buffer->TrimEnd(ten_ms_of_frames);
420 EXPECT_EQ(start_time + ten_ms, buffer->timestamp());
421 EXPECT_EQ(frames - 2 * ten_ms_of_frames, buffer->frame_count());
422 EXPECT_EQ(duration - 2 * ten_ms, buffer->duration());
423 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
424 VerifyBus(bus.get(), buffer->frame_count(), ten_ms_of_frames, 1.0f);
426 // Trim off 40ms more from the start.
427 buffer->TrimStart(4 * ten_ms_of_frames);
428 EXPECT_EQ(start_time + 5 * ten_ms, buffer->timestamp());
429 EXPECT_EQ(frames - 6 * ten_ms_of_frames, buffer->frame_count());
430 EXPECT_EQ(duration - 6 * ten_ms, buffer->duration());
431 buffer->ReadFrames(buffer->frame_count(), 0, 0, bus.get());
432 VerifyBus(bus.get(), buffer->frame_count(), 5 * ten_ms_of_frames, 1.0f);
434 // Trim off the final 40ms from the end.
435 buffer->TrimEnd(4 * ten_ms_of_frames);
436 EXPECT_EQ(0, buffer->frame_count());
437 EXPECT_EQ(start_time + 5 * ten_ms, buffer->timestamp());
438 EXPECT_EQ(base::TimeDelta(), buffer->duration());
441 TEST(AudioBufferTest, TrimRangePlanar) {
442 TrimRangeTest(kSampleFormatPlanarF32);
445 TEST(AudioBufferTest, TrimRangeInterleaved) {
446 TrimRangeTest(kSampleFormatF32);
449 static scoped_refptr<AudioBuffer> MakeReadFramesInterleavedTestBuffer(
450 SampleFormat sample_format,
451 int sample_rate,
452 ChannelLayout channel_layout,
453 int channel_count,
454 int frames) {
455 switch (sample_format) {
456 case kSampleFormatS16:
457 case kSampleFormatPlanarS16:
458 return MakeAudioBuffer<int16>(sample_format,
459 channel_layout,
460 channel_count,
461 sample_rate,
464 frames,
465 base::TimeDelta::FromSeconds(0));
466 case kSampleFormatS32:
467 return MakeAudioBuffer<int32>(kSampleFormatS32,
468 channel_layout,
469 channel_count,
470 sample_rate,
472 65536,
473 frames,
474 base::TimeDelta::FromSeconds(0));
475 case kSampleFormatF32:
476 case kSampleFormatPlanarF32:
477 return MakeAudioBuffer<float>(
478 sample_format,
479 channel_layout,
480 channel_count,
481 sample_rate,
482 0.0f,
483 65536.0f / std::numeric_limits<int32>::max(),
484 frames,
485 base::TimeDelta::FromSeconds(0));
486 case kSampleFormatPlanarS32:
487 return MakeAudioBuffer<int32>(
488 sample_format,
489 channel_layout,
490 channel_count,
491 sample_rate,
492 0.0f,
493 65536.0f / std::numeric_limits<int32>::max(),
494 frames,
495 base::TimeDelta::FromSeconds(0));
496 case kSampleFormatU8:
497 case kUnknownSampleFormat:
498 EXPECT_FALSE(true);
499 break;
501 return AudioBuffer::CreateEOSBuffer();
504 static void ReadFramesInterleavedS32Test(SampleFormat sample_format) {
505 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
506 const int channels = ChannelLayoutToChannelCount(channel_layout);
507 const int frames = kSampleRate / 100;
508 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(10);
509 scoped_refptr<AudioBuffer> buffer = MakeReadFramesInterleavedTestBuffer(
510 sample_format, kSampleRate, channel_layout, channels, frames);
511 EXPECT_EQ(frames, buffer->frame_count());
512 EXPECT_EQ(duration, buffer->duration());
514 int32* dest = new int32[frames * channels];
515 buffer->ReadFramesInterleavedS32(frames, dest);
517 int count = 0;
518 for (int i = 0; i < frames; ++i) {
519 for (int ch = 0; ch < channels; ++ch) {
520 EXPECT_EQ(dest[count++], (frames * ch + i) << 16);
523 delete[] dest;
526 TEST(AudioBufferTest, ReadFramesInterleavedS32FromS16) {
527 ReadFramesInterleavedS32Test(kSampleFormatS16);
530 TEST(AudioBufferTest, ReadFramesInterleavedS32FromS32) {
531 ReadFramesInterleavedS32Test(kSampleFormatS32);
534 TEST(AudioBufferTest, ReadFramesInterleavedS32FromF32) {
535 ReadFramesInterleavedS32Test(kSampleFormatF32);
538 TEST(AudioBufferTest, ReadFramesInterleavedS32FromPlanarS16) {
539 ReadFramesInterleavedS32Test(kSampleFormatPlanarS16);
542 TEST(AudioBufferTest, ReadFramesInterleavedS32FromPlanarF32) {
543 ReadFramesInterleavedS32Test(kSampleFormatPlanarF32);
546 static void ReadFramesInterleavedS16Test(SampleFormat sample_format) {
547 const ChannelLayout channel_layout = CHANNEL_LAYOUT_4_0;
548 const int channels = ChannelLayoutToChannelCount(channel_layout);
549 const int frames = kSampleRate / 100;
550 const base::TimeDelta duration = base::TimeDelta::FromMilliseconds(10);
551 scoped_refptr<AudioBuffer> buffer = MakeReadFramesInterleavedTestBuffer(
552 sample_format, kSampleRate, channel_layout, channels, frames);
553 EXPECT_EQ(frames, buffer->frame_count());
554 EXPECT_EQ(duration, buffer->duration());
556 int16* dest = new int16[frames * channels];
557 buffer->ReadFramesInterleavedS16(frames, dest);
559 int count = 0;
560 for (int i = 0; i < frames; ++i) {
561 for (int ch = 0; ch < channels; ++ch) {
562 EXPECT_EQ(dest[count++], (frames * ch + i));
565 delete[] dest;
568 TEST(AudioBufferTest, ReadFramesInterleavedS16FromS16) {
569 ReadFramesInterleavedS16Test(kSampleFormatS16);
572 TEST(AudioBufferTest, ReadFramesInterleavedS16FromS32) {
573 ReadFramesInterleavedS16Test(kSampleFormatS32);
576 TEST(AudioBufferTest, ReadFramesInterleavedS16FromF32) {
577 ReadFramesInterleavedS16Test(kSampleFormatF32);
580 TEST(AudioBufferTest, ReadFramesInterleavedS16FromPlanarS16) {
581 ReadFramesInterleavedS16Test(kSampleFormatPlanarS16);
584 TEST(AudioBufferTest, ReadFramesInterleavedS16FromPlanarF32) {
585 ReadFramesInterleavedS16Test(kSampleFormatPlanarF32);
588 } // namespace media