73 lines
2.2 KiB
C
Raw Normal View History

/*
* 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.
*/
#ifndef WEBRTC_COMMON_AUDIO_WAV_WRITER_H_
#define WEBRTC_COMMON_AUDIO_WAV_WRITER_H_
#ifdef __cplusplus
#include <stdint.h>
#include <cstddef>
#include <string>
namespace webrtc {
// Simple C++ class for writing 16-bit PCM WAV files. All error handling is
Add CHECK and friends from Chromium. Replace FATAL_ERROR_IF with the more familiar (to Chromium developers) CHECK and DCHECK. The full Chromium implementation is fairly elaborate but I copied enough to get us most of the benefits. I believe the main missing component is a more advanced stack dump. For this bit I relied on the V8 implementation. There are a few minor modifications from the Chromium original: - The FatalMessage class is specialized for logging fatal error messages and aborting. Chromium uses the general LogMessage class, which we could consider moving towards in the future. - NOTIMPLEMENTED() and NOTREACHED() have been removed, partly because I don't want to rely on our logging.h until base/ and system_wrappers/ are consolidated. - FATAL() replaces LOG(FATAL). Minor modifications from V8's stack dump: - If parsing of a stack trace symbol fails, just print the unparsed symbol. (I noticed this happened on Mac.) - Use __GLIBCXX__ and __UCLIBC__. This is from examining the backtrace use in Chromium. UNREACHABLE() has been removed because its behavior is different than Chromium's NOTREACHED(), which is bound to cause confusion. The few uses were replaced with FATAL(), matching the previous behavior. Add a NO_RETURN macro, allowing us to remove unreachable return statements following a CHECK/FATAL. TESTED=the addition of dummy CHECK, DCHECK, CHECK_EQ and FATAL did the did the right things. Stack traces work on Mac, but I don't get symbols on Linux. R=henrik.lundin@webrtc.org, kwiberg@webrtc.org, tommi@webrtc.org Review URL: https://webrtc-codereview.appspot.com/22449004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7003 4adac7df-926f-26a2-2b94-8c16560cd09d
2014-08-28 16:28:26 +00:00
// by calls to CHECK(), making it unsuitable for anything but debug code.
class WavFile {
public:
// Open a new WAV file for writing.
WavFile(const std::string& filename, int sample_rate, int num_channels);
// Close the WAV file, after writing its header.
~WavFile();
// Write additional samples to the file. Each sample is in the range
// [-32768,32767], and there must be the previously specified number of
// interleaved channels.
void WriteSamples(const float* samples, size_t num_samples);
void WriteSamples(const int16_t* samples, size_t num_samples);
int sample_rate() const { return sample_rate_; }
int num_channels() const { return num_channels_; }
uint32_t num_samples() const { return num_samples_; }
private:
void Close();
const int sample_rate_;
const int num_channels_;
uint32_t num_samples_; // total number of samples written to file
FILE* file_handle_; // output file, owned by this class
};
} // namespace webrtc
extern "C" {
#endif // __cplusplus
// C wrappers for the WavFile class.
typedef struct rtc_WavFile rtc_WavFile;
rtc_WavFile* rtc_WavOpen(const char* filename,
int sample_rate,
int num_channels);
void rtc_WavClose(rtc_WavFile* wf);
void rtc_WavWriteSamples(rtc_WavFile* wf,
const float* samples,
size_t num_samples);
int rtc_WavSampleRate(const rtc_WavFile* wf);
int rtc_WavNumChannels(const rtc_WavFile* wf);
uint32_t rtc_WavNumSamples(const rtc_WavFile* wf);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // WEBRTC_COMMON_AUDIO_WAV_WRITER_H_