duckstation

duckstation, but archived from the revision just before upstream changed it to a proprietary software project, this version is the libre one
git clone https://git.neptards.moe/u3shit/duckstation.git
Log | Files | Refs | README | LICENSE

wav_writer.h (834B)


      1 // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
      2 // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
      3 
      4 #pragma once
      5 #include "common/types.h"
      6 #include <cstdio>
      7 
      8 class WAVWriter
      9 {
     10 public:
     11   WAVWriter();
     12   ~WAVWriter();
     13 
     14   ALWAYS_INLINE u32 GetSampleRate() const { return m_sample_rate; }
     15   ALWAYS_INLINE u32 GetNumChannels() const { return m_num_channels; }
     16   ALWAYS_INLINE u32 GetNumFrames() const { return m_num_frames; }
     17   ALWAYS_INLINE bool IsOpen() const { return (m_file != nullptr); }
     18 
     19   bool Open(const char* filename, u32 sample_rate, u32 num_channels);
     20   void Close();
     21 
     22   void WriteFrames(const s16* samples, u32 num_frames);
     23 
     24 private:
     25   using SampleType = s16;
     26 
     27   bool WriteHeader();
     28 
     29   std::FILE* m_file = nullptr;
     30   u32 m_sample_rate = 0;
     31   u32 m_num_channels = 0;
     32   u32 m_num_frames = 0;
     33 };