| 1 | /* |
| 2 | * This file is part of DisOrder |
| 3 | * Copyright (C) 2007 Richard Kettlewell |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | /** @file lib/wav.h |
| 19 | * @brief WAV file support |
| 20 | */ |
| 21 | |
| 22 | #ifndef WAV_H |
| 23 | #define WAV_H |
| 24 | |
| 25 | /** @brief WAV file access structure */ |
| 26 | struct wavfile { |
| 27 | /** @brief File descriptor onto file */ |
| 28 | int fd; |
| 29 | |
| 30 | /** @brief File length */ |
| 31 | off_t length; |
| 32 | |
| 33 | /** @brief Offset of data chunk */ |
| 34 | off_t data; |
| 35 | |
| 36 | /** @brief Sample rate (Hz) */ |
| 37 | int rate; |
| 38 | |
| 39 | /** @brief Number of channels (usually 1 or 2) */ |
| 40 | int channels; |
| 41 | |
| 42 | /** @brief Bits per sample */ |
| 43 | int bits; |
| 44 | |
| 45 | /** @brief Size of data chunk in bytes */ |
| 46 | off_t datasize; |
| 47 | }; |
| 48 | |
| 49 | /** @brief Sample data callback from wav_data() |
| 50 | * @param f WAV file being read |
| 51 | * @param data Pointer to sample data |
| 52 | * @param nbytes Number of bytes of data |
| 53 | * @param u As passed to wav_data() |
| 54 | * @return 0 on success or an errno value on error |
| 55 | * |
| 56 | * @p nbytes is always a multiple of the frame size and never 0. |
| 57 | */ |
| 58 | typedef int wav_data_callback(struct wavfile *f, |
| 59 | const char *data, |
| 60 | size_t nbytes, |
| 61 | void *u); |
| 62 | |
| 63 | int wav_init(struct wavfile *f, const char *path); |
| 64 | void wav_destroy(struct wavfile *f); |
| 65 | int wav_data(struct wavfile *f, |
| 66 | wav_data_callback *callback, |
| 67 | void *u); |
| 68 | |
| 69 | #endif /* WAV_H */ |
| 70 | |
| 71 | /* |
| 72 | Local Variables: |
| 73 | c-basic-offset:2 |
| 74 | comment-column:40 |
| 75 | fill-column:79 |
| 76 | indent-tabs-mode:nil |
| 77 | End: |
| 78 | */ |