ref: eae5898461eaf335dee156fdc68c56d1b015ec2c
parent: 93161739a1130209af623dae66943e1c5c95f183
author: Paul Brossier <piem@piem.org>
date: Fri Jul 13 09:00:12 EDT 2012
src/io: moved sndfileio from examples
--- a/examples/sndfileio.c
+++ /dev/null
@@ -1,254 +1,0 @@
-/*
- Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
-
- This file is part of aubio.
-
- aubio 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 3 of the License, or
- (at your option) any later version.
-
- aubio 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 aubio. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#include "config.h"
-
-#ifdef HAVE_SNDFILE
-
-#include <string.h>
-
-#include <sndfile.h>
-
-#include "aubio_priv.h"
-#include "fvec.h"
-#include "sndfileio.h"
-#include "mathutils.h"
-
-#define MAX_CHANNELS 6
-#define MAX_SIZE 4096
-
-struct _aubio_sndfile_t {
- SNDFILE *handle;
- int samplerate;
- int channels;
- int format;
- float *tmpdata; /** scratch pad for interleaving/deinterleaving. */
- int size; /** store the size to check if realloc needed */
-};
-
-aubio_sndfile_t * new_aubio_sndfile_ro(const char* outputname) {
- aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t);
- SF_INFO sfinfo;
- AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
-
- f->handle = sf_open (outputname, SFM_READ, &sfinfo);
-
- if (f->handle == NULL) {
- AUBIO_ERR("Failed opening %s: %s\n", outputname,
- sf_strerror (NULL)); /* libsndfile err msg */
- return NULL;
- }
-
- if (sfinfo.channels > MAX_CHANNELS) {
- AUBIO_ERR("Not able to process more than %d channels\n", MAX_CHANNELS);
- return NULL;
- }
-
- f->size = MAX_SIZE*sfinfo.channels;
- f->tmpdata = AUBIO_ARRAY(float,f->size);
- /* get input specs */
- f->samplerate = sfinfo.samplerate;
- f->channels = sfinfo.channels;
- f->format = sfinfo.format;
-
- return f;
-}
-
-int aubio_sndfile_open_wo(aubio_sndfile_t * f, const char* inputname) {
- SF_INFO sfinfo;
- AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
-
- /* define file output spec */
- sfinfo.samplerate = f->samplerate;
- sfinfo.channels = f->channels;
- sfinfo.format = f->format;
-
- if (! (f->handle = sf_open (inputname, SFM_WRITE, &sfinfo))) {
- AUBIO_ERR("Not able to open output file %s.\n", inputname);
- AUBIO_ERR("%s\n",sf_strerror (NULL)); /* libsndfile err msg */
- AUBIO_QUIT(AUBIO_FAIL);
- }
-
- if (sfinfo.channels > MAX_CHANNELS) {
- AUBIO_ERR("Not able to process more than %d channels\n", MAX_CHANNELS);
- AUBIO_QUIT(AUBIO_FAIL);
- }
- f->size = MAX_SIZE*sfinfo.channels;
- f->tmpdata = AUBIO_ARRAY(float,f->size);
- return AUBIO_OK;
-}
-
-/* setup file struct from existing one */
-aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * fmodel, const char *outputname) {
- aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t);
- f->samplerate = fmodel->samplerate;
- f->channels = 1; //fmodel->channels;
- f->format = fmodel->format;
- aubio_sndfile_open_wo(f, outputname);
- return f;
-}
-
-
-/* return 0 if properly closed, 1 otherwise */
-int del_aubio_sndfile(aubio_sndfile_t * f) {
- if (sf_close(f->handle)) {
- AUBIO_ERR("Error closing file.");
- puts (sf_strerror (NULL));
- return 1;
- }
- AUBIO_FREE(f->tmpdata);
- AUBIO_FREE(f);
- //AUBIO_DBG("File closed.\n");
- return 0;
-}
-
-/**************************************************************
- *
- * Read write methods
- *
- */
-
-
-/* read frames from file in data
- * return the number of frames actually read */
-int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t ** read) {
- sf_count_t read_frames;
- int i,j, channels = f->channels;
- int nsamples = frames*channels;
- int aread;
- smpl_t *pread;
-
- /* allocate data for de/interleaving reallocated when needed. */
- if (nsamples >= f->size) {
- AUBIO_ERR("Maximum aubio_sndfile_read buffer size exceeded.");
- return -1;
- /*
- AUBIO_FREE(f->tmpdata);
- f->tmpdata = AUBIO_ARRAY(float,nsamples);
- */
- }
- //f->size = nsamples;
-
- /* do actual reading */
- read_frames = sf_read_float (f->handle, f->tmpdata, nsamples);
-
- aread = (int)FLOOR(read_frames/(float)channels);
-
- /* de-interleaving data */
- for (i=0; i<channels; i++) {
- pread = (smpl_t *)fvec_get_data(read[i]);
- for (j=0; j<aread; j++) {
- pread[j] = (smpl_t)f->tmpdata[channels*j+i];
- }
- }
- return aread;
-}
-
-int
-aubio_sndfile_read_mono (aubio_sndfile_t * f, int frames, fvec_t * read)
-{
- sf_count_t read_frames;
- int i, j, channels = f->channels;
- int nsamples = frames * channels;
- int aread;
- smpl_t *pread;
-
- /* allocate data for de/interleaving reallocated when needed. */
- if (nsamples >= f->size) {
- AUBIO_ERR ("Maximum aubio_sndfile_read buffer size exceeded.");
- return -1;
- /*
- AUBIO_FREE(f->tmpdata);
- f->tmpdata = AUBIO_ARRAY(float,nsamples);
- */
- }
- //f->size = nsamples;
-
- /* do actual reading */
- read_frames = sf_read_float (f->handle, f->tmpdata, nsamples);
-
- aread = (int) FLOOR (read_frames / (float) channels);
-
- /* de-interleaving data */
- pread = (smpl_t *) fvec_get_data (read);
- for (i = 0; i < channels; i++) {
- for (j = 0; j < aread; j++) {
- pread[j] += (smpl_t) f->tmpdata[channels * j + i];
- }
- }
- for (j = 0; j < aread; j++) {
- pread[j] /= (smpl_t)channels;
- }
-
- return aread;
-}
-
-/* write 'frames' samples to file from data
- * return the number of frames actually written
- */
-int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t ** write) {
- sf_count_t written_frames = 0;
- int i, j, channels = f->channels;
- int nsamples = channels*frames;
- smpl_t *pwrite;
-
- /* allocate data for de/interleaving reallocated when needed. */
- if (nsamples >= f->size) {
- AUBIO_ERR("Maximum aubio_sndfile_write buffer size exceeded.");
- return -1;
- /*
- AUBIO_FREE(f->tmpdata);
- f->tmpdata = AUBIO_ARRAY(float,nsamples);
- */
- }
- //f->size = nsamples;
-
- /* interleaving data */
- for (i=0; i<channels; i++) {
- pwrite = (smpl_t *)fvec_get_data(write[i]);
- for (j=0; j<frames; j++) {
- f->tmpdata[channels*j+i] = (float)pwrite[j];
- }
- }
- written_frames = sf_write_float (f->handle, f->tmpdata, nsamples);
- return written_frames/channels;
-}
-
-/*******************************************************************
- *
- * Get object info
- *
- */
-
-uint_t aubio_sndfile_channels(aubio_sndfile_t * f) {
- return f->channels;
-}
-
-uint_t aubio_sndfile_samplerate(aubio_sndfile_t * f) {
- return f->samplerate;
-}
-
-void aubio_sndfile_info(aubio_sndfile_t * f) {
- AUBIO_DBG("srate : %d\n", f->samplerate);
- AUBIO_DBG("channels : %d\n", f->channels);
- AUBIO_DBG("format : %d\n", f->format);
-}
-
-#endif /* HAVE_SNDFILE */
--- a/examples/sndfileio.h
+++ /dev/null
@@ -1,79 +1,0 @@
-/*
- Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
-
- This file is part of aubio.
-
- aubio 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 3 of the License, or
- (at your option) any later version.
-
- aubio 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 aubio. If not, see <http://www.gnu.org/licenses/>.
-
-*/
-
-#ifndef SNDFILEIO_H
-#define SNDFILEIO_H
-
-/** @file
- * sndfile functions
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * sndfile object
- */
-typedef struct _aubio_sndfile_t aubio_sndfile_t;
-/**
- * Open a sound file for reading
- */
-aubio_sndfile_t * new_aubio_sndfile_ro (const char * inputfile);
-/**
- * Copy file model from previously opened sound file.
- */
-aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * existingfile, const char * outputname);
-/**
- * Open a sound file for writing
- */
-int aubio_sndfile_open_wo (aubio_sndfile_t * file, const char * outputname);
-/**
- * Read frames data from file into an array of buffers
- */
-int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t ** read);
-/**
- * Read frames data from file into a single buffer
- */
-int aubio_sndfile_read_mono (aubio_sndfile_t * f, int frames, fvec_t * read);
-/**
- * Write data of length frames to file
- */
-int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t ** write);
-/**
- * Close file and delete file object
- */
-int del_aubio_sndfile(aubio_sndfile_t * file);
-/**
- * Return some files facts
- */
-void aubio_sndfile_info(aubio_sndfile_t * file);
-/**
- * Return number of channel in file
- */
-uint_t aubio_sndfile_channels(aubio_sndfile_t * file);
-uint_t aubio_sndfile_samplerate(aubio_sndfile_t * file);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
--- a/examples/wscript_build
+++ b/examples/wscript_build
@@ -1,20 +1,14 @@
# vim:set syntax=python:
# build examples
-sndfileio = ctx.new_task_gen(features = 'c',
- includes = '../src',
- source = ['sndfileio.c'],
- target = 'sndfileio')
-
utilsio = ctx.new_task_gen(name = 'utilsio', features = 'c',
includes = '../src',
- add_objects = 'sndfileio',
source = ['utils.c', 'jackio.c'],
- uselib = ['LASH', 'JACK', 'SNDFILE'],
+ uselib = ['LASH', 'JACK'],
target = 'utilsio')
# loop over all *.c filenames in examples to build them all
-for target_name in ctx.path.ant_glob('*.c', excl = ['utils.c', 'jackio.c', 'sndfileio.c']):
+for target_name in ctx.path.ant_glob('*.c', excl = ['utils.c', 'jackio.c']):
ctx.new_task_gen(features = 'c cprogram',
add_objects = 'utilsio',
includes = '../src',
--- /dev/null
+++ b/src/io/sndfileio.c
@@ -1,0 +1,254 @@
+/*
+ Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+
+ This file is part of aubio.
+
+ aubio 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 3 of the License, or
+ (at your option) any later version.
+
+ aubio 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 aubio. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include "config.h"
+
+#ifdef HAVE_SNDFILE
+
+#include <string.h>
+
+#include <sndfile.h>
+
+#include "aubio_priv.h"
+#include "fvec.h"
+#include "sndfileio.h"
+#include "mathutils.h"
+
+#define MAX_CHANNELS 6
+#define MAX_SIZE 4096
+
+struct _aubio_sndfile_t {
+ SNDFILE *handle;
+ int samplerate;
+ int channels;
+ int format;
+ float *tmpdata; /** scratch pad for interleaving/deinterleaving. */
+ int size; /** store the size to check if realloc needed */
+};
+
+aubio_sndfile_t * new_aubio_sndfile_ro(const char* outputname) {
+ aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t);
+ SF_INFO sfinfo;
+ AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
+
+ f->handle = sf_open (outputname, SFM_READ, &sfinfo);
+
+ if (f->handle == NULL) {
+ AUBIO_ERR("Failed opening %s: %s\n", outputname,
+ sf_strerror (NULL)); /* libsndfile err msg */
+ return NULL;
+ }
+
+ if (sfinfo.channels > MAX_CHANNELS) {
+ AUBIO_ERR("Not able to process more than %d channels\n", MAX_CHANNELS);
+ return NULL;
+ }
+
+ f->size = MAX_SIZE*sfinfo.channels;
+ f->tmpdata = AUBIO_ARRAY(float,f->size);
+ /* get input specs */
+ f->samplerate = sfinfo.samplerate;
+ f->channels = sfinfo.channels;
+ f->format = sfinfo.format;
+
+ return f;
+}
+
+int aubio_sndfile_open_wo(aubio_sndfile_t * f, const char* inputname) {
+ SF_INFO sfinfo;
+ AUBIO_MEMSET(&sfinfo, 0, sizeof (sfinfo));
+
+ /* define file output spec */
+ sfinfo.samplerate = f->samplerate;
+ sfinfo.channels = f->channels;
+ sfinfo.format = f->format;
+
+ if (! (f->handle = sf_open (inputname, SFM_WRITE, &sfinfo))) {
+ AUBIO_ERR("Not able to open output file %s.\n", inputname);
+ AUBIO_ERR("%s\n",sf_strerror (NULL)); /* libsndfile err msg */
+ AUBIO_QUIT(AUBIO_FAIL);
+ }
+
+ if (sfinfo.channels > MAX_CHANNELS) {
+ AUBIO_ERR("Not able to process more than %d channels\n", MAX_CHANNELS);
+ AUBIO_QUIT(AUBIO_FAIL);
+ }
+ f->size = MAX_SIZE*sfinfo.channels;
+ f->tmpdata = AUBIO_ARRAY(float,f->size);
+ return AUBIO_OK;
+}
+
+/* setup file struct from existing one */
+aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * fmodel, const char *outputname) {
+ aubio_sndfile_t * f = AUBIO_NEW(aubio_sndfile_t);
+ f->samplerate = fmodel->samplerate;
+ f->channels = 1; //fmodel->channels;
+ f->format = fmodel->format;
+ aubio_sndfile_open_wo(f, outputname);
+ return f;
+}
+
+
+/* return 0 if properly closed, 1 otherwise */
+int del_aubio_sndfile(aubio_sndfile_t * f) {
+ if (sf_close(f->handle)) {
+ AUBIO_ERR("Error closing file.");
+ puts (sf_strerror (NULL));
+ return 1;
+ }
+ AUBIO_FREE(f->tmpdata);
+ AUBIO_FREE(f);
+ //AUBIO_DBG("File closed.\n");
+ return 0;
+}
+
+/**************************************************************
+ *
+ * Read write methods
+ *
+ */
+
+
+/* read frames from file in data
+ * return the number of frames actually read */
+int aubio_sndfile_read(aubio_sndfile_t * f, int frames, fvec_t ** read) {
+ sf_count_t read_frames;
+ int i,j, channels = f->channels;
+ int nsamples = frames*channels;
+ int aread;
+ smpl_t *pread;
+
+ /* allocate data for de/interleaving reallocated when needed. */
+ if (nsamples >= f->size) {
+ AUBIO_ERR("Maximum aubio_sndfile_read buffer size exceeded.");
+ return -1;
+ /*
+ AUBIO_FREE(f->tmpdata);
+ f->tmpdata = AUBIO_ARRAY(float,nsamples);
+ */
+ }
+ //f->size = nsamples;
+
+ /* do actual reading */
+ read_frames = sf_read_float (f->handle, f->tmpdata, nsamples);
+
+ aread = (int)FLOOR(read_frames/(float)channels);
+
+ /* de-interleaving data */
+ for (i=0; i<channels; i++) {
+ pread = (smpl_t *)fvec_get_data(read[i]);
+ for (j=0; j<aread; j++) {
+ pread[j] = (smpl_t)f->tmpdata[channels*j+i];
+ }
+ }
+ return aread;
+}
+
+int
+aubio_sndfile_read_mono (aubio_sndfile_t * f, int frames, fvec_t * read)
+{
+ sf_count_t read_frames;
+ int i, j, channels = f->channels;
+ int nsamples = frames * channels;
+ int aread;
+ smpl_t *pread;
+
+ /* allocate data for de/interleaving reallocated when needed. */
+ if (nsamples >= f->size) {
+ AUBIO_ERR ("Maximum aubio_sndfile_read buffer size exceeded.");
+ return -1;
+ /*
+ AUBIO_FREE(f->tmpdata);
+ f->tmpdata = AUBIO_ARRAY(float,nsamples);
+ */
+ }
+ //f->size = nsamples;
+
+ /* do actual reading */
+ read_frames = sf_read_float (f->handle, f->tmpdata, nsamples);
+
+ aread = (int) FLOOR (read_frames / (float) channels);
+
+ /* de-interleaving data */
+ pread = (smpl_t *) fvec_get_data (read);
+ for (i = 0; i < channels; i++) {
+ for (j = 0; j < aread; j++) {
+ pread[j] += (smpl_t) f->tmpdata[channels * j + i];
+ }
+ }
+ for (j = 0; j < aread; j++) {
+ pread[j] /= (smpl_t)channels;
+ }
+
+ return aread;
+}
+
+/* write 'frames' samples to file from data
+ * return the number of frames actually written
+ */
+int aubio_sndfile_write(aubio_sndfile_t * f, int frames, fvec_t ** write) {
+ sf_count_t written_frames = 0;
+ int i, j, channels = f->channels;
+ int nsamples = channels*frames;
+ smpl_t *pwrite;
+
+ /* allocate data for de/interleaving reallocated when needed. */
+ if (nsamples >= f->size) {
+ AUBIO_ERR("Maximum aubio_sndfile_write buffer size exceeded.");
+ return -1;
+ /*
+ AUBIO_FREE(f->tmpdata);
+ f->tmpdata = AUBIO_ARRAY(float,nsamples);
+ */
+ }
+ //f->size = nsamples;
+
+ /* interleaving data */
+ for (i=0; i<channels; i++) {
+ pwrite = (smpl_t *)fvec_get_data(write[i]);
+ for (j=0; j<frames; j++) {
+ f->tmpdata[channels*j+i] = (float)pwrite[j];
+ }
+ }
+ written_frames = sf_write_float (f->handle, f->tmpdata, nsamples);
+ return written_frames/channels;
+}
+
+/*******************************************************************
+ *
+ * Get object info
+ *
+ */
+
+uint_t aubio_sndfile_channels(aubio_sndfile_t * f) {
+ return f->channels;
+}
+
+uint_t aubio_sndfile_samplerate(aubio_sndfile_t * f) {
+ return f->samplerate;
+}
+
+void aubio_sndfile_info(aubio_sndfile_t * f) {
+ AUBIO_DBG("srate : %d\n", f->samplerate);
+ AUBIO_DBG("channels : %d\n", f->channels);
+ AUBIO_DBG("format : %d\n", f->format);
+}
+
+#endif /* HAVE_SNDFILE */
--- /dev/null
+++ b/src/io/sndfileio.h
@@ -1,0 +1,79 @@
+/*
+ Copyright (C) 2003-2009 Paul Brossier <piem@aubio.org>
+
+ This file is part of aubio.
+
+ aubio 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 3 of the License, or
+ (at your option) any later version.
+
+ aubio 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 aubio. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef SNDFILEIO_H
+#define SNDFILEIO_H
+
+/** @file
+ * sndfile functions
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * sndfile object
+ */
+typedef struct _aubio_sndfile_t aubio_sndfile_t;
+/**
+ * Open a sound file for reading
+ */
+aubio_sndfile_t * new_aubio_sndfile_ro (const char * inputfile);
+/**
+ * Copy file model from previously opened sound file.
+ */
+aubio_sndfile_t * new_aubio_sndfile_wo(aubio_sndfile_t * existingfile, const char * outputname);
+/**
+ * Open a sound file for writing
+ */
+int aubio_sndfile_open_wo (aubio_sndfile_t * file, const char * outputname);
+/**
+ * Read frames data from file into an array of buffers
+ */
+int aubio_sndfile_read(aubio_sndfile_t * file, int frames, fvec_t ** read);
+/**
+ * Read frames data from file into a single buffer
+ */
+int aubio_sndfile_read_mono (aubio_sndfile_t * f, int frames, fvec_t * read);
+/**
+ * Write data of length frames to file
+ */
+int aubio_sndfile_write(aubio_sndfile_t * file, int frames, fvec_t ** write);
+/**
+ * Close file and delete file object
+ */
+int del_aubio_sndfile(aubio_sndfile_t * file);
+/**
+ * Return some files facts
+ */
+void aubio_sndfile_info(aubio_sndfile_t * file);
+/**
+ * Return number of channel in file
+ */
+uint_t aubio_sndfile_channels(aubio_sndfile_t * file);
+uint_t aubio_sndfile_samplerate(aubio_sndfile_t * file);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
--- a/src/wscript_build
+++ b/src/wscript_build
@@ -1,11 +1,14 @@
# vim:set syntax=python:
-uselib = ['SAMPLERATE']
+source = ctx.path.ant_glob('*.c **/*.c')
+uselib = []
+
if 'HAVE_FFTW3' in conf.get_env():
- source = ctx.path.ant_glob('*.c **/*.c', excl = ['**/ooura_fft8g.c'])
+ source.filter(lambda x: not x.endswith('ooura_fft8g.c'))
uselib += ['FFTW3', 'FFTW3F']
-else:
- source = ctx.path.ant_glob('*.c **/*.c')
+
+if 'HAVE_SAMPLERATE':
+ uselib += ['SAMPLERATE']
# build libaubio
ctx.shlib(