X-Git-Url: https://git.distorted.org.uk/~mdw/disorder/blobdiff_plain/717ba9873384d81663a2da9eb7071824c30a739f..0a066775fe988ab36bd72583cf34d14784039fe3:/lib/wav.c
diff --git a/lib/wav.c b/lib/wav.c
index c7d4b93..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
@@ -103,13 +101,11 @@
* orderings of different channels.
*/
-#include
-#include "types.h"
+#include "common.h"
#include
#include
#include
-#include
#include "log.h"
#include "wav.h"
@@ -132,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
@@ -142,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;
@@ -155,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
@@ -172,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);
@@ -201,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
@@ -231,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;