annotate src/libsndfile-1.0.27/examples/generate.c @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 1df64224f5ac
children
rev   line source
Chris@40 1 /*
Chris@40 2 ** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
Chris@40 3 **
Chris@40 4 ** All rights reserved.
Chris@40 5 **
Chris@40 6 ** Redistribution and use in source and binary forms, with or without
Chris@40 7 ** modification, are permitted provided that the following conditions are
Chris@40 8 ** met:
Chris@40 9 **
Chris@40 10 ** * Redistributions of source code must retain the above copyright
Chris@40 11 ** notice, this list of conditions and the following disclaimer.
Chris@40 12 ** * Redistributions in binary form must reproduce the above copyright
Chris@40 13 ** notice, this list of conditions and the following disclaimer in
Chris@40 14 ** the documentation and/or other materials provided with the
Chris@40 15 ** distribution.
Chris@40 16 ** * Neither the author nor the names of any contributors may be used
Chris@40 17 ** to endorse or promote products derived from this software without
Chris@40 18 ** specific prior written permission.
Chris@40 19 **
Chris@40 20 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Chris@40 21 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
Chris@40 22 ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
Chris@40 23 ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
Chris@40 24 ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
Chris@40 25 ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
Chris@40 26 ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
Chris@40 27 ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
Chris@40 28 ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
Chris@40 29 ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
Chris@40 30 ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Chris@40 31 */
Chris@40 32
Chris@40 33 #include "sfconfig.h"
Chris@40 34
Chris@40 35 #include <stdio.h>
Chris@40 36 #include <stdlib.h>
Chris@40 37 #include <string.h>
Chris@40 38 #include <math.h>
Chris@40 39
Chris@40 40 #include <sndfile.h>
Chris@40 41
Chris@40 42 #define BUFFER_LEN 4096
Chris@40 43
Chris@40 44 static void encode_file (const char *infilename, const char *outfilename, int filetype) ;
Chris@40 45
Chris@40 46 int
Chris@40 47 main (int argc, char **argv)
Chris@40 48 {
Chris@40 49 if (argc != 2)
Chris@40 50 { puts ("\nEncode a single input file into a number of different output ") ;
Chris@40 51 puts ("encodings. These output encodings can then be moved to another ") ;
Chris@40 52 puts ("OS for testing.\n") ;
Chris@40 53 puts (" Usage : generate <filename>\n") ;
Chris@40 54 exit (1) ;
Chris@40 55 } ;
Chris@40 56
Chris@40 57 /* A couple of standard WAV files. Make sure Win32 plays these. */
Chris@40 58 encode_file (argv [1], "pcmu8.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_U8) ;
Chris@40 59 encode_file (argv [1], "pcm16.wav" , SF_FORMAT_WAV | SF_FORMAT_PCM_16) ;
Chris@40 60 encode_file (argv [1], "imaadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM) ;
Chris@40 61 encode_file (argv [1], "msadpcm.wav", SF_FORMAT_WAV | SF_FORMAT_IMA_ADPCM) ;
Chris@40 62 encode_file (argv [1], "gsm610.wav" , SF_FORMAT_WAV | SF_FORMAT_GSM610) ;
Chris@40 63
Chris@40 64 /* Soundforge W64. */
Chris@40 65 encode_file (argv [1], "pcmu8.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_U8) ;
Chris@40 66 encode_file (argv [1], "pcm16.w64" , SF_FORMAT_W64 | SF_FORMAT_PCM_16) ;
Chris@40 67 encode_file (argv [1], "imaadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_MS_ADPCM) ;
Chris@40 68 encode_file (argv [1], "msadpcm.w64", SF_FORMAT_W64 | SF_FORMAT_IMA_ADPCM) ;
Chris@40 69 encode_file (argv [1], "gsm610.w64" , SF_FORMAT_W64 | SF_FORMAT_GSM610) ;
Chris@40 70
Chris@40 71 return 0 ;
Chris@40 72 } /* main */
Chris@40 73
Chris@40 74 /*============================================================================================
Chris@40 75 ** Helper functions and macros.
Chris@40 76 */
Chris@40 77
Chris@40 78 #define PUT_DOTS(k) \
Chris@40 79 { while (k--) \
Chris@40 80 putchar ('.') ; \
Chris@40 81 putchar (' ') ; \
Chris@40 82 }
Chris@40 83
Chris@40 84 /*========================================================================================
Chris@40 85 */
Chris@40 86
Chris@40 87 static void
Chris@40 88 encode_file (const char *infilename, const char *outfilename, int filetype)
Chris@40 89 { static float buffer [BUFFER_LEN] ;
Chris@40 90
Chris@40 91 SNDFILE *infile, *outfile ;
Chris@40 92 SF_INFO sfinfo ;
Chris@40 93 int k, readcount ;
Chris@40 94
Chris@40 95 printf (" %s -> %s ", infilename, outfilename) ;
Chris@40 96 fflush (stdout) ;
Chris@40 97
Chris@40 98 k = 16 - strlen (outfilename) ;
Chris@40 99 PUT_DOTS (k) ;
Chris@40 100
Chris@40 101 memset (&sfinfo, 0, sizeof (sfinfo)) ;
Chris@40 102
Chris@40 103 if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
Chris@40 104 { printf ("Error : could not open file : %s\n", infilename) ;
Chris@40 105 puts (sf_strerror (NULL)) ;
Chris@40 106 exit (1) ;
Chris@40 107 }
Chris@40 108
Chris@40 109 sfinfo.format = filetype ;
Chris@40 110
Chris@40 111 if (! sf_format_check (&sfinfo))
Chris@40 112 { sf_close (infile) ;
Chris@40 113 printf ("Invalid encoding\n") ;
Chris@40 114 return ;
Chris@40 115 } ;
Chris@40 116
Chris@40 117 if (! (outfile = sf_open (outfilename, SFM_WRITE, &sfinfo)))
Chris@40 118 { printf ("Error : could not open file : %s\n", outfilename) ;
Chris@40 119 puts (sf_strerror (NULL)) ;
Chris@40 120 exit (1) ;
Chris@40 121 } ;
Chris@40 122
Chris@40 123 while ((readcount = sf_read_float (infile, buffer, BUFFER_LEN)) > 0)
Chris@40 124 sf_write_float (outfile, buffer, readcount) ;
Chris@40 125
Chris@40 126 sf_close (infile) ;
Chris@40 127 sf_close (outfile) ;
Chris@40 128
Chris@40 129 printf ("ok\n") ;
Chris@40 130
Chris@40 131 return ;
Chris@40 132 } /* encode_file */
Chris@40 133