kwiberg@webrtc.org | 877083c | 2014-08-20 07:42:46 +0000 | [diff] [blame] | 1 | /* |
| 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.org | a3ed713 | 2014-10-31 21:51:03 +0000 | [diff] [blame] | 14 | #include <stddef.h> |
kwiberg@webrtc.org | 877083c | 2014-08-20 07:42:46 +0000 | [diff] [blame] | 15 | #include <stdint.h> |
| 16 | |
| 17 | namespace webrtc { |
| 18 | |
andrew@webrtc.org | a3ed713 | 2014-10-31 21:51:03 +0000 | [diff] [blame] | 19 | static const size_t kWavHeaderSize = 44; |
kwiberg@webrtc.org | 877083c | 2014-08-20 07:42:46 +0000 | [diff] [blame] | 20 | |
| 21 | enum 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. |
| 28 | bool 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.org | f866b2d | 2014-11-03 18:20:06 +0000 | [diff] [blame] | 37 | // type. CHECKs the input parameters for validity. |
| 38 | void WriteWavHeader(uint8_t* buf, |
kwiberg@webrtc.org | 877083c | 2014-08-20 07:42:46 +0000 | [diff] [blame] | 39 | int num_channels, |
| 40 | int sample_rate, |
| 41 | WavFormat format, |
| 42 | int bytes_per_sample, |
| 43 | uint32_t num_samples); |
| 44 | |
andrew@webrtc.org | a3ed713 | 2014-10-31 21:51:03 +0000 | [diff] [blame] | 45 | // 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. |
| 47 | bool 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.org | 877083c | 2014-08-20 07:42:46 +0000 | [diff] [blame] | 54 | } // namespace webrtc |
| 55 | |
| 56 | #endif // WEBRTC_COMMON_AUDIO_WAV_HEADER_H_ |