diff options
author | Erik de Castro Lopo <erikd@mega-nerd.com> | 2008-08-16 16:16:39 +1000 |
---|---|---|
committer | Erik de Castro Lopo <erikd@mega-nerd.com> | 2008-08-16 16:16:39 +1000 |
commit | 686e6c6386ebd117b111d4021c8b91030ed3be57 (patch) | |
tree | bd794591290776e27a7a0d3c442e2d9a2861a315 /examples | |
parent | 7ec8cfadf22dc2857e8c91fa8b5b732097d83760 (diff) |
examples/ : Break some functionality out of sndfile-convert.c so it can be used in examples/sndfile-bwf-set.c.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/Makefile.am | 4 | ||||
-rw-r--r-- | examples/copy_data.c | 89 | ||||
-rw-r--r-- | examples/copy_data.h | 37 | ||||
-rw-r--r-- | examples/sndfile-convert.c | 54 |
4 files changed, 131 insertions, 53 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am index f9ddf01..636a4c8 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -25,13 +25,13 @@ sndfile_jackplay_SOURCES = sndfile-jackplay.c sndfile_jackplay_CFLAGS = $(JACK_CFLAGS) sndfile_jackplay_LDADD = $(SNDFILEDIR)/libsndfile.la $(JACK_LIBS) -sndfile_convert_SOURCES = sndfile-convert.c +sndfile_convert_SOURCES = sndfile-convert.c copy_data.c copy_data.h sndfile_convert_LDADD = $(SNDFILEDIR)/libsndfile.la sndfile_cmp_SOURCES = sndfile-cmp.c sndfile_cmp_LDADD = $(SNDFILEDIR)/libsndfile.la -sndfile_bwf_set_SOURCES = sndfile-bwf-set.c +sndfile_bwf_set_SOURCES = sndfile-bwf-set.c copy_data.c copy_data.h sndfile_bwf_set_LDADD = $(SNDFILEDIR)/libsndfile.la make_sine_SOURCES = make_sine.c diff --git a/examples/copy_data.c b/examples/copy_data.c new file mode 100644 index 0000000..72a4736 --- /dev/null +++ b/examples/copy_data.c @@ -0,0 +1,89 @@ +/* +** Copyright (C) 1999-2008 Erik de Castro Lopo <erikd@mega-nerd.com> +** +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the author nor the names of any contributors may be used +** to endorse or promote products derived from this software without +** specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +#include <sndfile.h> + +#include "copy_data.h" + +#define BUFFER_LEN 4096 + +void +sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels) +{ static double data [BUFFER_LEN], max ; + int frames, readcount, k ; + + frames = BUFFER_LEN / channels ; + readcount = frames ; + + sf_command (infile, SFC_CALC_SIGNAL_MAX, &max, sizeof (max)) ; + + if (max < 1.0) + { while (readcount > 0) + { readcount = sf_readf_double (infile, data, frames) ; + sf_writef_double (outfile, data, readcount) ; + } ; + } + else + { sf_command (infile, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ; + + while (readcount > 0) + { readcount = sf_readf_double (infile, data, frames) ; + for (k = 0 ; k < readcount * channels ; k++) + data [k] /= max ; + sf_writef_double (outfile, data, readcount) ; + } ; + } ; + + return ; +} /* sfe_copy_data_fp */ + +void +sfe_copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels) +{ static int data [BUFFER_LEN] ; + int frames, readcount ; + + frames = BUFFER_LEN / channels ; + readcount = frames ; + + while (readcount > 0) + { readcount = sf_readf_int (infile, data, frames) ; + sf_writef_int (outfile, data, readcount) ; + } ; + + return ; +} /* sfe_copy_data_int */ + diff --git a/examples/copy_data.h b/examples/copy_data.h new file mode 100644 index 0000000..69c748d --- /dev/null +++ b/examples/copy_data.h @@ -0,0 +1,37 @@ +/* +** Copyright (C) 1999-2008 Erik de Castro Lopo <erikd@mega-nerd.com> +** +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the author nor the names of any contributors may be used +** to endorse or promote products derived from this software without +** specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR +** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <sndfile.h> + +void sfe_copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels) ; + +void sfe_copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels) ; diff --git a/examples/sndfile-convert.c b/examples/sndfile-convert.c index 318508d..4bdb1c4 100644 --- a/examples/sndfile-convert.c +++ b/examples/sndfile-convert.c @@ -37,7 +37,7 @@ #include <sndfile.h> -#define BUFFER_LEN 1024 +#include "copy_data.h" typedef struct @@ -52,8 +52,6 @@ typedef struct } OUTPUT_FORMAT_MAP ; static void copy_metadata (SNDFILE *outfile, SNDFILE *infile) ; -static void copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels) ; -static void copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels) ; static OUTPUT_FORMAT_MAP format_map [] = { @@ -333,9 +331,9 @@ main (int argc, char * argv []) if ((outfileminor == SF_FORMAT_DOUBLE) || (outfileminor == SF_FORMAT_FLOAT) || (infileminor == SF_FORMAT_DOUBLE) || (infileminor == SF_FORMAT_FLOAT) || (infileminor == SF_FORMAT_VORBIS) || (outfileminor == SF_FORMAT_VORBIS)) - copy_data_fp (outfile, infile, sfinfo.channels) ; + sfe_copy_data_fp (outfile, infile, sfinfo.channels) ; else - copy_data_int (outfile, infile, sfinfo.channels) ; + sfe_copy_data_int (outfile, infile, sfinfo.channels) ; sf_close (infile) ; sf_close (outfile) ; @@ -367,49 +365,3 @@ copy_metadata (SNDFILE *outfile, SNDFILE *infile) } /* copy_metadata */ -static void -copy_data_fp (SNDFILE *outfile, SNDFILE *infile, int channels) -{ static double data [BUFFER_LEN], max ; - int frames, readcount, k ; - - frames = BUFFER_LEN / channels ; - readcount = frames ; - - sf_command (infile, SFC_CALC_SIGNAL_MAX, &max, sizeof (max)) ; - - if (max < 1.0) - { while (readcount > 0) - { readcount = sf_readf_double (infile, data, frames) ; - sf_writef_double (outfile, data, readcount) ; - } ; - } - else - { sf_command (infile, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE) ; - - while (readcount > 0) - { readcount = sf_readf_double (infile, data, frames) ; - for (k = 0 ; k < readcount * channels ; k++) - data [k] /= max ; - sf_writef_double (outfile, data, readcount) ; - } ; - } ; - - return ; -} /* copy_data_fp */ - -static void -copy_data_int (SNDFILE *outfile, SNDFILE *infile, int channels) -{ static int data [BUFFER_LEN] ; - int frames, readcount ; - - frames = BUFFER_LEN / channels ; - readcount = frames ; - - while (readcount > 0) - { readcount = sf_readf_int (infile, data, frames) ; - sf_writef_int (outfile, data, readcount) ; - } ; - - return ; -} /* copy_data_int */ - |