diff --git a/common_audio/wav_file.cc b/common_audio/wav_file.cc index 77b46e72e1..2170b7e4f9 100644 --- a/common_audio/wav_file.cc +++ b/common_audio/wav_file.cc @@ -216,32 +216,3 @@ void WavWriter::Close() { } } // namespace webrtc - -rtc_WavWriter* rtc_WavOpen(const char* filename, - int sample_rate, - size_t num_channels) { - return reinterpret_cast( - new webrtc::WavWriter(filename, sample_rate, num_channels)); -} - -void rtc_WavClose(rtc_WavWriter* wf) { - delete reinterpret_cast(wf); -} - -void rtc_WavWriteSamples(rtc_WavWriter* wf, - const float* samples, - size_t num_samples) { - reinterpret_cast(wf)->WriteSamples(samples, num_samples); -} - -int rtc_WavSampleRate(const rtc_WavWriter* wf) { - return reinterpret_cast(wf)->sample_rate(); -} - -size_t rtc_WavNumChannels(const rtc_WavWriter* wf) { - return reinterpret_cast(wf)->num_channels(); -} - -size_t rtc_WavNumSamples(const rtc_WavWriter* wf) { - return reinterpret_cast(wf)->num_samples(); -} diff --git a/common_audio/wav_file.h b/common_audio/wav_file.h index d7aa2c1c03..1e32bf7855 100644 --- a/common_audio/wav_file.h +++ b/common_audio/wav_file.h @@ -11,8 +11,6 @@ #ifndef COMMON_AUDIO_WAV_FILE_H_ #define COMMON_AUDIO_WAV_FILE_H_ -#ifdef __cplusplus - #include #include #include @@ -103,24 +101,4 @@ class WavReader final : public WavFile { } // namespace webrtc -extern "C" { -#endif // __cplusplus - -// C wrappers for the WavWriter class. -typedef struct rtc_WavWriter rtc_WavWriter; -rtc_WavWriter* rtc_WavOpen(const char* filename, - int sample_rate, - size_t num_channels); -void rtc_WavClose(rtc_WavWriter* wf); -void rtc_WavWriteSamples(rtc_WavWriter* wf, - const float* samples, - size_t num_samples); -int rtc_WavSampleRate(const rtc_WavWriter* wf); -size_t rtc_WavNumChannels(const rtc_WavWriter* wf); -size_t rtc_WavNumSamples(const rtc_WavWriter* wf); - -#ifdef __cplusplus -} // extern "C" -#endif - #endif // COMMON_AUDIO_WAV_FILE_H_ diff --git a/common_audio/wav_file_unittest.cc b/common_audio/wav_file_unittest.cc index fef87c8169..726552a011 100644 --- a/common_audio/wav_file_unittest.cc +++ b/common_audio/wav_file_unittest.cc @@ -103,53 +103,6 @@ TEST(WavWriterTest, MAYBE_CPP) { } } -// Write a tiny WAV file with the C interface and verify the result. -TEST(WavWriterTest, C) { - const std::string outfile = test::OutputPath() + "wavtest2.wav"; - rtc_WavWriter* w = rtc_WavOpen(outfile.c_str(), 11904, 2); - EXPECT_EQ(11904, rtc_WavSampleRate(w)); - EXPECT_EQ(2u, rtc_WavNumChannels(w)); - EXPECT_EQ(0u, rtc_WavNumSamples(w)); - static const size_t kNumSamples = 4; - rtc_WavWriteSamples(w, &kSamples[0], 2); - EXPECT_EQ(2u, rtc_WavNumSamples(w)); - rtc_WavWriteSamples(w, &kSamples[2], kNumSamples - 2); - EXPECT_EQ(kNumSamples, rtc_WavNumSamples(w)); - rtc_WavClose(w); - static const uint8_t kExpectedContents[] = { - // clang-format off - // clang formatting doesn't respect inline comments. - 'R', 'I', 'F', 'F', - 44, 0, 0, 0, // size of whole file - 8: 8 + 44 - 8 - 'W', 'A', 'V', 'E', - 'f', 'm', 't', ' ', - 16, 0, 0, 0, // size of fmt block - 8: 24 - 8 - 1, 0, // format: PCM (1) - 2, 0, // channels: 2 - 0x80, 0x2e, 0, 0, // sample rate: 11904 - 0, 0xba, 0, 0, // byte rate: 2 * 2 * 11904 - 4, 0, // block align: NumChannels * BytesPerSample - 16, 0, // bits per sample: 2 * 8 - 'd', 'a', 't', 'a', - 8, 0, 0, 0, // size of payload: 8 - 0, 0, // first sample: 0.0 - 10, 0, // second sample: 10.0 - 0xff, 0x7f, // third sample: 4e4 (saturated) - 0, 0x80, // fourth sample: -1e9 (saturated) - // clang-format on - }; - static const size_t kContentSize = - kWavHeaderSize + kNumSamples * sizeof(int16_t); - static_assert(sizeof(kExpectedContents) == kContentSize, "content size"); - EXPECT_EQ(kContentSize, test::GetFileSize(outfile)); - FILE* f = fopen(outfile.c_str(), "rb"); - ASSERT_TRUE(f); - uint8_t contents[kContentSize]; - ASSERT_EQ(1u, fread(contents, kContentSize, 1, f)); - EXPECT_EQ(0, fclose(f)); - EXPECT_EQ(0, memcmp(kExpectedContents, contents, kContentSize)); -} - // Write a larger WAV file. You can listen to this file to sanity-check it. TEST(WavWriterTest, LargeFile) { std::string outfile = test::OutputPath() + "wavtest3.wav";