Note: We no longer publish the latest version of our code here. We primarily use a kumc-bmi github organization. The heron ETL repository, in particular, is not public. Peers in the informatics community should see MultiSiteDev for details on requesting access.

source: webrtc/webrtc/modules/audio_coding/neteq4/tools/input_audio_file.cc @ 0:4bda6873e34c

pub_scrub_3792 tip
Last change on this file since 0:4bda6873e34c was 0:4bda6873e34c, checked in by Michael Prittie <mprittie@…>, 6 years ago

Scrubbed password for publication.

File size: 1.6 KB
Line 
1/*
2 *  Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/modules/audio_coding/neteq4/tools/input_audio_file.h"
12
13namespace webrtc {
14namespace test {
15
16InputAudioFile::InputAudioFile(const std::string file_name) {
17  fp_ = fopen(file_name.c_str(), "rb");
18}
19
20InputAudioFile::~InputAudioFile() { fclose(fp_); }
21
22bool InputAudioFile::Read(size_t samples, int16_t* destination) {
23  if (!fp_) {
24    return false;
25  }
26  size_t samples_read = fread(destination, sizeof(int16_t), samples, fp_);
27  if (samples_read < samples) {
28    // Rewind and read the missing samples.
29    rewind(fp_);
30    size_t missing_samples = samples - samples_read;
31    if (fread(destination, sizeof(int16_t), missing_samples, fp_) <
32        missing_samples) {
33      // Could not read enough even after rewinding the file.
34      return false;
35    }
36  }
37  return true;
38}
39
40void InputAudioFile::DuplicateInterleaved(const int16_t* source, size_t samples,
41                                          size_t channels,
42                                          int16_t* destination) {
43  for (size_t i = 0; i < samples; ++i) {
44    for (size_t j = 0; j < channels; ++j) {
45      destination[i * channels + j] = source[i];
46    }
47  }
48}
49
50}  // namespace test
51}  // namespace webrtc
Note: See TracBrowser for help on using the repository browser.