48 lines
1.5 KiB
C
48 lines
1.5 KiB
C
// Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
|
|
// See LICENSE.md for license information.
|
|
// SPDX-License-Identifier: MIT
|
|
//
|
|
// gateWav.h - 16-bit PCM WAV files for the gate tools: read with the chunk
|
|
// walk the graders were first written against (Python's wave module's), so
|
|
// a recording cut short or written with wrong sizes yields the same audio,
|
|
// and written with the plain 44-byte header.
|
|
|
|
#ifndef GATE_WAV_H
|
|
#define GATE_WAV_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
#include "toolBuf.h"
|
|
|
|
// A WAV's format and its audio: the data chunk's whole frames, as far as
|
|
// the RIFF chunk and the file go.
|
|
typedef struct GateWavT {
|
|
uint32_t channels;
|
|
uint32_t rate;
|
|
uint8_t *bytes;
|
|
size_t byteCount;
|
|
} GateWavT;
|
|
|
|
// The frames the bytes hold.
|
|
size_t gateWavFrames(const GateWavT *wav);
|
|
|
|
void gateWavFree(GateWavT *wav);
|
|
|
|
// Each frame's samples averaged over its channels: gateWavFrames of them,
|
|
// in a malloc'd array.
|
|
double *gateWavMono(const GateWavT *wav);
|
|
|
|
// Read path as a 16-bit PCM WAV; false, with what is wrong appended to problem
|
|
// ("cannot read PATH: <why>", or "PATH: <what is wrong with it>"), when it
|
|
// cannot be.
|
|
bool gateWavRead(const char *path, GateWavT *wav, ToolBufT *problem);
|
|
|
|
// A frame's 16-bit sample in one channel.
|
|
double gateWavSample(const GateWavT *wav, size_t frame, uint32_t channel);
|
|
|
|
// A 16-bit PCM WAV of len bytes of frames; false if it cannot be written.
|
|
bool gateWavWrite(const char *path, uint32_t channels, uint32_t rate, const uint8_t *data, size_t len);
|
|
|
|
#endif
|