blob: 37f78a6fe9c139d32ffea607c53b62656626248b [file] [log] [blame]
kwiberg@webrtc.org877083c2014-08-20 07:42:46 +00001/*
2 * Copyright (c) 2014 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#ifndef WEBRTC_COMMON_AUDIO_WAV_HEADER_H_
12#define WEBRTC_COMMON_AUDIO_WAV_HEADER_H_
13
andrew@webrtc.orga3ed7132014-10-31 21:51:03 +000014#include <stddef.h>
kwiberg@webrtc.org877083c2014-08-20 07:42:46 +000015#include <stdint.h>
16
17namespace webrtc {
18
andrew@webrtc.orga3ed7132014-10-31 21:51:03 +000019static const size_t kWavHeaderSize = 44;
kwiberg@webrtc.org877083c2014-08-20 07:42:46 +000020
21enum WavFormat {
22 kWavFormatPcm = 1, // PCM, each sample of size bytes_per_sample
23 kWavFormatALaw = 6, // 8-bit ITU-T G.711 A-law
24 kWavFormatMuLaw = 7, // 8-bit ITU-T G.711 mu-law
25};
26
27// Return true if the given parameters will make a well-formed WAV header.
28bool CheckWavParameters(int num_channels,
29 int sample_rate,
30 WavFormat format,
31 int bytes_per_sample,
32 uint32_t num_samples);
33
34// Write a kWavHeaderSize bytes long WAV header to buf. The payload that
35// follows the header is supposed to have the specified number of interleaved
36// channels and contain the specified total number of samples of the specified
andrew@webrtc.orgf866b2d2014-11-03 18:20:06 +000037// type. CHECKs the input parameters for validity.
38void WriteWavHeader(uint8_t* buf,
kwiberg@webrtc.org877083c2014-08-20 07:42:46 +000039 int num_channels,
40 int sample_rate,
41 WavFormat format,
42 int bytes_per_sample,
43 uint32_t num_samples);
44
andrew@webrtc.orga3ed7132014-10-31 21:51:03 +000045// Read a kWavHeaderSize bytes long WAV header from buf and parse the values
46// into the provided output parameters. Returns false if the header is invalid.
47bool ReadWavHeader(const uint8_t* buf,
48 int* num_channels,
49 int* sample_rate,
50 WavFormat* format,
51 int* bytes_per_sample,
52 uint32_t* num_samples);
53
kwiberg@webrtc.org877083c2014-08-20 07:42:46 +000054} // namespace webrtc
55
56#endif // WEBRTC_COMMON_AUDIO_WAV_HEADER_H_