1 /****************************************************************************** 2 * 3 * Copyright 2022 Google LLC 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #ifndef __WAVE_H 20 #define __WAVE_H 21 22 #include <stdio.h> 23 #include <stdint.h> 24 25 26 /** 27 * Read WAVE file header 28 * fp Opened file, moved after header on return 29 * bitdepth Return bitdepth 30 * samplesize Return size of samples, in bytes 31 * samplerate Return samplerate, in Hz 32 * nchannels Return number of channels 33 * nframes Return count of frames 34 * return 0: Ok -1: Bad or unsupported WAVE File 35 */ 36 int wave_read_header(FILE *fp, int *bitdepth, int *samplesize, 37 int *samplerate, int *nchannels, int *nframes); 38 39 /** 40 * Read PCM samples from wave file 41 * fp Opened file 42 * samplesize Size of samples, in bytes 43 * nch, count Number of channels and count of frames to read 44 * buffer Output buffer of `nchannels * count` interleaved samples 45 * return Number of frames read 46 */ 47 int wave_read_pcm(FILE *fp, int samplesize, 48 int nch, int count, void *_buffer); 49 50 /** 51 * Write WAVE file header 52 * fp Opened file, moved after header on return 53 * bitdepth Bitdepth 54 * samplesize Size of samples 55 * samplerate Samplerate, in Hz 56 * nchannels Number of channels 57 * nframes Count of frames 58 */ 59 void wave_write_header(FILE *fp, int bitdepth, int samplesize, 60 int samplerate, int nchannels, int nframes); 61 62 /** 63 * Write PCM samples to wave file 64 * fp Opened file 65 * samplesize Size of samples, in bytes 66 * pcm, nch PCM frames, as 'nch' interleaved samples 67 * off, count Offset and count of frames 68 */ 69 void wave_write_pcm(FILE *fp, int samplesize, 70 const void *pcm, int nch, int off, int count); 71 72 73 #endif /* __WAVE_H */ 74