66 lines
1.5 KiB
C++
66 lines
1.5 KiB
C++
/*
|
|
* Filename: WavWriter.h
|
|
*
|
|
* Description:
|
|
*
|
|
*
|
|
* Version:
|
|
* Created: Mon Mar 9 18:00:11 2020
|
|
* Revision: None
|
|
* Author: Rachel Fae Fox (foxiepaws),fox@foxiepa.ws
|
|
*
|
|
*/
|
|
#pragma once
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
|
|
// standard wave files have a 32bit size limit.
|
|
#define WAVMAX (0xffffff - 20)
|
|
typedef unsigned int uint;
|
|
|
|
namespace amalgam {
|
|
class WavWriter {
|
|
|
|
uint32_t length = 0;
|
|
uint32_t sr; // sample rate (gstool(samplerate))
|
|
uint16_t bd; // bit depth (gstool(bitdepth))
|
|
uint16_t ch; // channels (gstool(channels))
|
|
uint32_t datasize;
|
|
uint32_t fmtsize = 16;
|
|
uint16_t type = 1;
|
|
uint32_t riffsize;
|
|
uint32_t byterate;
|
|
uint16_t blockalign;
|
|
FILE* file;
|
|
|
|
// helpers
|
|
bool fit() { return (WAVMAX-fmtsize) > (length + byterate); } // see if one more sample will fit
|
|
void writeBytes(char* bytes, uint count);
|
|
|
|
public:
|
|
// gstool
|
|
/* BEGIN GSTOOL GENERATED BLOCK */
|
|
// getters
|
|
uint32_t samplerate() { return sr; }
|
|
uint16_t bitdepth() { return bd; }
|
|
uint16_t channels() { return ch; }
|
|
// setters
|
|
void samplerate(uint32_t v) { sr = v; }
|
|
void bitdepth(uint16_t v) { bd = v; }
|
|
void channels(uint16_t v) { ch = v; }
|
|
/* END GSTOOL GENERATED BLOCK */
|
|
|
|
WavWriter() {}
|
|
~WavWriter();
|
|
WavWriter(char* filename, uint srate, uint chan, uint bps);
|
|
void finalise();
|
|
void writeHeader();
|
|
void write(...);
|
|
};
|
|
}
|
|
|
|
/* Local Variables: */
|
|
/* mode: c++ */
|
|
/* flycheck-clang-language-standard: "c++11" */
|
|
/* End: */
|