X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/05b75f8d50b83e943af3be4071449304d82dbdcd..eff6238fcaa690773dc292816fa47b8767efa00c:/lib/wav.c diff --git a/lib/wav.c b/lib/wav.c index d0f3acf..fe7ffbb 100644 --- a/lib/wav.c +++ b/lib/wav.c @@ -2,20 +2,18 @@ * This file is part of DisOrder * Copyright (C) 2007 Richard Kettlewell * - * This program is free software; you can redistribute it and/or modify + * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA + * along with this program. If not, see . */ /** @file lib/wav.c * @brief WAV file support @@ -130,9 +128,8 @@ int wav_init(struct wavfile *f, const char *path) { off_t where; memset(f, 0, sizeof *f); - f->fd = -1; f->data = -1; - if((f->fd = open(path, O_RDONLY)) < 0) goto error_errno; + if(hreader_init(path, f->input)) goto error_errno; /* Read the file header * * offset size meaning @@ -140,7 +137,7 @@ int wav_init(struct wavfile *f, const char *path) { * 04 4 length of rest of file * 08 4 'WAVE' * */ - if((n = pread(f->fd, header, 12, 0)) < 0) goto error_errno; + if((n = hreader_pread(f->input, header, 12, 0)) < 0) goto error_errno; else if(n < 12) goto einval; if(strncmp(header, "RIFF", 4) || strncmp(header + 8, "WAVE", 4)) goto einval; @@ -153,7 +150,7 @@ int wav_init(struct wavfile *f, const char *path) { * 00 4 chunk ID * 04 4 length of rest of chunk */ - if((n = pread(f->fd, header, 8, where)) < 0) goto error_errno; + if((n = hreader_pread(f->input, header, 8, where)) < 0) goto error_errno; else if(n < 8) goto einval; if(!strncmp(header,"fmt ", 4)) { /* This is the format chunk @@ -170,7 +167,8 @@ int wav_init(struct wavfile *f, const char *path) { * 18 ? extra undocumented rubbish */ if(get32(header + 4) < 16) goto einval; - if((n = pread(f->fd, header + 8, 16, where + 8)) < 0) goto error_errno; + if((n = hreader_pread(f->input, header + 8, 16, where + 8)) < 0) + goto error_errno; else if(n < 16) goto einval; f->channels = get16(header + 0x0A); f->rate = get32(header + 0x0C); @@ -199,13 +197,7 @@ error: /** @brief Close a WAV file */ void wav_destroy(struct wavfile *f) { - if(f) { - const int save_errno = errno; - - if(f->fd >= 0) - close(f->fd); - errno = save_errno; - } + hreader_close(f->input); } /** @brief Visit all the data in a WAV file @@ -229,7 +221,7 @@ int wav_data(struct wavfile *f, size_t want = (off_t)sizeof buffer > left ? (size_t)left : sizeof buffer; want -= want % bytes_per_frame; - if((n = pread(f->fd, buffer, want, where)) < 0) return errno; + if((n = hreader_pread(f->input, buffer, want, where)) < 0) return errno; if((size_t)n < want) return EINVAL; if((err = callback(f, buffer, n, u))) return err; where += n;