*/
-#include "config.h"
+#include "aubio_priv.h"
#ifdef HAVE_WAVREAD
-#include "aubio_priv.h"
#include "fvec.h"
#include "fmat.h"
#include "source_wavread.h"
goto beach;
}
- if (s->path) AUBIO_FREE(s->path);
s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
// BitsPerSample
bytes_read += fread(buf, 1, 2, s->fid);
bitspersample = read_little_endian(buf, 2);
+
+ if ( channels == 0 ) {
+ AUBIO_ERR("source_wavread: Failed opening %s (number of channels can not be 0)\n", s->path);
+ goto beach;
+ }
+
+ if ( (sint_t)sr <= 0 ) {
+ AUBIO_ERR("source_wavread: Failed opening %s (samplerate can not be <= 0)\n", s->path);
+ goto beach;
+ }
+
+ if ( byterate == 0 ) {
+ AUBIO_ERR("source_wavread: Failed opening %s (byterate can not be 0)\n", s->path);
+ goto beach;
+ }
+
+ if ( bitspersample == 0 ) {
+ AUBIO_ERR("source_wavread: Failed opening %s (bitspersample can not be 0)\n", s->path);
+ goto beach;
+ }
#if 0
if ( bitspersample != 16 ) {
AUBIO_ERR("source_wavread: can not process %dbit file %s\n",
uint_t i, j;
uint_t end = 0;
uint_t total_wrote = 0;
+ if (s->fid == NULL) {
+ AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
+ s->path);
+ return;
+ }
while (total_wrote < s->hop_size) {
end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
for (i = 0; i < end; i++) {
uint_t i,j;
uint_t end = 0;
uint_t total_wrote = 0;
+ if (s->fid == NULL) {
+ AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
+ s->path);
+ return;
+ }
while (total_wrote < s->hop_size) {
end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
for (j = 0; j < read_data->height; j++) {
uint_t aubio_source_wavread_seek (aubio_source_wavread_t * s, uint_t pos) {
uint_t ret = 0;
+ if (s->fid == NULL) {
+ AUBIO_ERR("source_wavread: could not seek %s (file not opened?)\n", s->path, pos);
+ return AUBIO_FAIL;
+ }
if ((sint_t)pos < 0) {
+ AUBIO_ERR("source_wavread: could not seek %s at %d (seeking position should be >= 0)\n", s->path, pos);
return AUBIO_FAIL;
}
ret = fseek(s->fid, s->seek_start + pos * s->blockalign, SEEK_SET);
}
uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) {
- if (!s->fid) {
- return AUBIO_FAIL;
+ if (s->fid == NULL) {
+ return AUBIO_OK;
}
if (fclose(s->fid)) {
AUBIO_ERR("source_wavread: could not close %s (%s)\n", s->path, strerror(errno));
}
void del_aubio_source_wavread(aubio_source_wavread_t * s) {
- if (!s) return;
+ AUBIO_ASSERT(s);
aubio_source_wavread_close(s);
if (s->short_output) AUBIO_FREE(s->short_output);
if (s->output) del_fmat(s->output);