A small command-line audio effect for 16-bit PCM WAV files, written in C++11 with the standard library. It reads sample data into memory, applies integer quantization and sample-and-hold processing, then writes a WAV file.
| Input | Output |
|---|---|
| Original sample | Processed sample |
- Binary input and output with
std::ifstreamandstd::ofstream. - Integer quantization controlled by
crush_factor. - Sample-and-hold processing controlled by
downsample_factor. - No external audio-processing library.
The processing changes the sample values; it does not change the WAV header's sample rate or bit depth. downsample_factor controls how often a new sample value is taken, so the result can sound similar to lower-rate audio without creating a lower-sample-rate file.
The supplied Makefile uses g++, make, and -std=c++11:
make
./bitcrusher samples/demo_original.wav samples/out.wav 256 4On Windows with MinGW, use mingw32-make and run bitcrusher.exe.
bitcrusher <input.wav> <output.wav> [crush_factor] [downsample_factor]
Both factors are optional. The defaults are 256 and 1, respectively. A larger crush_factor reduces sample precision; a larger downsample_factor holds each selected value for more sample positions.
The reader assumes a conventional 44-byte WAV header followed immediately by 16-bit PCM sample data. It checks the RIFF and WAVE identifiers, but does not fully validate the WAV format or handle arbitrary extra chunks. The sample-and-hold loop processes interleaved sample positions, so stereo channels are not handled independently. Use a copy of the input audio and a simple 16-bit PCM WAV file when trying the tool.
The implementation uses std::vector<int16_t> for audio samples. It does not use memory-mapped files.
MIT. See LICENSE.