webrtc学习:wav文件读写

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/glw0223/article/details/88096872

webrtc对wav文件的读写,只是写了简单的代码,不过参考文档不错。

http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html

代码示例如下:

wav_header.cc里

/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

// Based on the WAV file format documentation at
// https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ and
// http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html

#include "common_audio/wav_header.h"

#include <cstring>
#include <limits>
#include <string>

#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/sanitizer.h"
#include "rtc_base/system/arch.h"

namespace webrtc {
namespace {

struct ChunkHeader {
  uint32_t ID;
  uint32_t Size;
};
static_assert(sizeof(ChunkHeader) == 8, "ChunkHeader size");

struct RiffHeader {
  ChunkHeader header;
  uint32_t Format;
};

// We can't nest this definition in WavHeader, because VS2013 gives an error
// on sizeof(WavHeader::fmt): "error C2070: 'unknown': illegal sizeof operand".
struct FmtSubchunk {
  ChunkHeader header;
  uint16_t AudioFormat;
  uint16_t NumChannels;
  uint32_t SampleRate;
  uint32_t ByteRate;
  uint16_t BlockAlign;
  uint16_t BitsPerSample;
};
static_assert(sizeof(FmtSubchunk) == 24, "FmtSubchunk size");
const uint32_t kFmtSubchunkSize = sizeof(FmtSubchunk) - sizeof(ChunkHeader);

// Simple wav header. It does not include chunks that are not essential to read
// audio samples.
struct WavHeader {
  WavHeader(const WavHeader&) = default;
  WavHeader& operator=(const WavHeader&) = default;
  RiffHeader riff;
  FmtSubchunk fmt;
  struct {
    ChunkHeader header;
  } data;
};

还有其他的文件,如下

git log

commit 9a27c2fc7a2eb068eb06fad2e991039e2fceb960 (master)
Author: Artem Titarenko <[email protected]>
Date:   Thu Jan 31 10:20:00 2019 +0100

    Make internal.*.webrtc iOS bots dimensions depend on bot_id and pool only

    Bug: webrtc:10047
    Change-Id: I48bcc15721859062c73c7e5fbae7a2fd65713adc
    Reviewed-on: https://webrtc-review.googlesource.com/c/120615
    Reviewed-by: Oleh Prypin <[email protected]>
    Commit-Queue: Artem Titarenko <[email protected]>
    Cr-Commit-Position: refs/heads/master@{#26485}

猜你喜欢

转载自blog.csdn.net/glw0223/article/details/88096872