#include "st.h"#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <ctype.h>#include <errno.h>#include "machine.h"#include "sox.h"#include "sciprint.h"Include dependency graph for sox.c:

Go to the source code of this file.
Defines | |
| #define | Abs(x) ( ( (x) >= 0) ? (x) : -( x) ) |
| #define | Min(x, y) ( ( (x) < (y)) ? (x) : (y) ) |
Functions | |
| static void checkformat | __PARAMS ((ft_t ft)) |
| static void cleanup | __PARAMS ((void)) |
| static int filetype | __PARAMS ((int fd)) |
| int C2F() | loadwave (char *filename, double *res, integer *size_res, integer flag, WavInfo *Wi, integer *ierr) |
| int C2F() | savewave (char *filename, double *res, integer *rate, integer *size_res, integer *nchannels, integer *ierr) |
| void | init (void) |
| int | filetype (int fd) |
| void | cleanup (void) |
| static void | checkformat (ft_t ft) |
Variables | |
| soundstream | informat |
| ft_t | ft |
| static void cleanup __PARAMS | ( | (void) | ) | [static] |
| static void checkformat | ( | ft_t | ft | ) | [static] |
Definition at line 269 of file sox.c.
References signalinfo::channels, soundstream::filename, FLOATSCI, ft, soundstream::ierr, soundstream::info, signalinfo::rate, sciprint(), signalinfo::size, and signalinfo::style.
Referenced by loadwave().
00270 { 00271 if (ft->info.rate == 0) 00272 { 00273 sciprint("Sampling rate for %s file was not given\r\n", ft->filename); 00274 ft->ierr=1; 00275 return; 00276 } 00277 if ((ft->info.rate < 100) || (ft->info.rate > 50000)) 00278 { 00279 sciprint("Sampling rate %lu for %s file is bogus\r\n", 00280 ft->info.rate, ft->filename); 00281 ft->ierr=1; 00282 return; 00283 } 00284 00285 if (ft->info.size == -1) 00286 { 00287 sciprint("Data size was not given for %s file\r\n", ft->filename); 00288 ft->ierr=1; 00289 return; 00290 } 00291 if (ft->info.style == -1 && ft->info.size != FLOATSCI) 00292 { 00293 sciprint("Data style was not given for %s file\r\n", ft->filename); 00294 ft->ierr=1; 00295 return; 00296 } 00297 /* it's so common, might as well default */ 00298 if (ft->info.channels == -1) 00299 ft->info.channels = 1; 00300 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void cleanup | ( | void | ) |
Definition at line 253 of file sox.c.
References stat.
Referenced by loadwave(), and savewave().
Here is the caller graph for this function:

| void init | ( | void | ) |
Definition at line 232 of file sox.c.
References signalinfo::channels, soundstream::comment, soundstream::filename, soundstream::filetype, soundstream::fp, soundstream::info, informat, NULL, signalinfo::rate, signalinfo::size, signalinfo::style, and soundstream::swap.
00233 { 00234 /* init files */ 00235 informat.info.rate = 0; 00236 informat.info.size = -1; 00237 informat.info.style = -1; 00238 informat.info.channels = -1; 00239 informat.comment = NULL; 00240 informat.swap = 0; 00241 informat.filetype = "wav"; 00242 informat.fp = stdin; 00243 informat.filename = "input"; 00244 }
| int C2F() loadwave | ( | char * | filename, | |
| double * | res, | |||
| integer * | size_res, | |||
| integer | flag, | |||
| WavInfo * | Wi, | |||
| integer * | ierr | |||
| ) |
Definition at line 46 of file sox.c.
References buf, signalinfo::channels, checkformat(), soundstream::comment, errno, soundstream::filename, filetype(), soundstream::fp, ft, i, soundstream::ierr, ierr, soundstream::info, informat, init, NULL, signalinfo::rate, READBINARY, res1(), sciprint(), soundstream::seekable, signalinfo::size, sizes, strerror(), signalinfo::style, styles, wavread(), and wavstartread().
Referenced by C2F().
00047 { 00048 long i,size_max; 00049 #if defined(__alpha)|defined(__ia64__) 00050 int buf[BUFSIZ]; 00051 #else 00052 long buf[BUFSIZ]; 00053 #endif 00054 int olen; 00055 double *res1; 00056 *ierr=0; 00057 init(); 00058 /* Get input format options */ 00059 ft = &informat; 00060 ft->ierr=*ierr; 00061 /* Get input file */ 00062 if ((ft->fp = fopen(filename, READBINARY)) == NULL) 00063 { 00064 sciprint("Can't open input file '%s': %s\r\n", 00065 filename, strerror(errno)); 00066 *ierr=1; 00067 return 0; 00068 } 00069 ft->filename = filename; 00070 #if defined(_MSC_VER) 00071 informat.seekable = 1; 00072 #else 00073 informat.seekable = (filetype(fileno(informat.fp)) == S_IFREG); 00074 #endif 00075 informat.comment = informat.filename; 00076 00077 /* Read and write starters can change their formats. */ 00078 wavstartread(&informat,Wi,flag); 00079 if ( ft->ierr > 0 ) 00080 { 00081 sciprint("Error while reading \r\n"); 00082 *ierr=1; 00083 return 0; 00084 } 00085 checkformat(&informat); 00086 if ( ft->ierr > 0 ) 00087 { 00088 sciprint("Error while reading \r\n"); 00089 *ierr=1; 00090 return 0; 00091 } 00092 if ( flag == 1) 00093 { 00094 sciprint("Input file: using sample rate %lu\r\n", 00095 informat.info.rate); 00096 sciprint("\tsize %s, style %s, %d %s\r\n", 00097 sizes[informat.info.size], 00098 styles[informat.info.style], informat.info.channels, 00099 (informat.info.channels > 1) ? "channels" : "channel"); 00100 } 00101 /* read chunk */ 00102 size_max = *size_res ; 00103 *size_res = 0; 00104 olen = 1; 00105 res1=res; 00106 while ( olen > 0 ) 00107 { 00108 olen = wavread(&informat,buf, (long) BUFSIZ); 00109 if ( ft->ierr > 0 ) 00110 { 00111 sciprint("Error while reading \r\n"); 00112 *ierr=1; 00113 return 0; 00114 } 00115 *size_res += olen ; 00116 if (flag == 1 && *size_res > size_max ) 00117 { 00118 sciprint(" Sorry wav file too big \r\n"); 00119 return 0; 00120 } 00122 if (flag == 1) 00123 for ( i = 0 ; i < olen ; i++ ) 00124 { 00125 *res1++ = buf[i]; 00126 } 00127 } 00128 00129 fclose(informat.fp); 00130 00131 if ( flag == 1 ) 00132 { 00133 for ( i = 0 ; i < *size_res ; i++ ) 00134 { 00135 if ( informat.info.size /8 == 1 ) 00136 res[i] = (res[i]-128)/128; 00137 else 00138 res[i] = ((res[i])/32768)/65536; 00139 } 00140 } 00141 *ierr= ft->ierr; 00142 return 0 ; 00143 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int C2F() savewave | ( | char * | filename, | |
| double * | res, | |||
| integer * | rate, | |||
| integer * | size_res, | |||
| integer * | nchannels, | |||
| integer * | ierr | |||
| ) |
Definition at line 148 of file sox.c.
References buf, signalinfo::channels, cleanup(), soundstream::comment, count, errno, soundstream::filename, filetype(), soundstream::fp, ft, i, soundstream::ierr, ierr, soundstream::info, informat, init, len, long, m, NULL, num, signalinfo::rate, sciprint(), soundstream::seekable, SIGN2, signalinfo::size, strerror(), signalinfo::style, wavstartwrite(), wavstopwrite(), wavwrite(), WORDSCI, WRITEBINARY, and x.
Referenced by C2F().
00149 { 00150 long buf[BUFSIZ]; 00151 long i,size_max; 00152 int count; 00153 double m,*loc; 00154 *ierr=0; 00155 init(); 00156 /* Get input format options */ 00157 ft = &informat; 00158 ft->ierr=*ierr; 00159 /* Get input file */ 00160 if ((ft->fp = fopen(filename, WRITEBINARY)) == NULL) 00161 { 00162 sciprint("Can't open output file '%s': %s\r\n", 00163 filename, strerror(errno)); 00164 *ierr=1; 00165 return 0; 00166 } 00167 00168 ft->filename = filename; 00169 #if defined(_MSC_VER) 00170 informat.seekable = 1; 00171 #else 00172 informat.seekable = (filetype(fileno(informat.fp)) == S_IFREG); 00173 #endif 00174 informat.comment = informat.filename; 00175 00176 /* changing the formats. */ 00177 informat.info.size = WORDSCI; 00178 informat.info.rate = *rate ; 00179 informat.info.style = SIGN2; 00180 informat.info.channels = *nchannels; 00181 00182 m=1.0; 00183 /* 00184 m=res[0]; 00185 for ( i = 0 ; i < *size_res ; i++) 00186 { 00187 if ( Abs(res[i]) > m ) m = Abs(res[i]); 00188 } 00189 */ 00190 wavstartwrite(&informat); 00191 if ( ft->ierr > 0 ) 00192 { 00193 *ierr= ft->ierr; 00194 cleanup(); 00195 return 0; 00196 } 00197 /* read chunk */ 00198 size_max = *size_res ; 00199 *size_res = 0; 00200 count = 0 ; 00201 loc= res; 00202 while ( count < size_max ) 00203 { 00204 double x; 00205 long int len, num; 00206 len = count + BUFSIZ; 00207 len = ( len > size_max ) ? size_max : len; 00208 for ( i = count ; i < len ; i++ ) 00209 { 00210 /* x= v/m*2**(31-1); */ 00211 x= (*loc++)/m*2147483647; 00212 buf[i-count ] = (long) x; 00214 } 00215 num = len - count ; 00216 wavwrite(&informat,buf, num ); 00217 if ( ft->ierr > 0 ) 00218 { 00219 *ierr= ft->ierr; 00220 cleanup(); 00221 return 0; 00222 } 00223 count = len; 00224 } 00225 wavstopwrite(&informat); 00226 fclose(informat.fp); 00227 res[0] = ((double)(size_max))/((double) (*rate)); 00228 *ierr= ft->ierr; 00229 return 0; 00230 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 30 of file sox.c.
Referenced by checkformat(), fill_type(), loadwave(), mget2(), mgeti(), mput2(), mputi(), rawread(), rawwrite(), rblong(), rbshort(), rdouble(), rfloat(), rllong(), rlong(), rlshort(), rshort(), savewave(), wavread(), wavstartread(), wavstartwrite(), wavstopwrite(), wavwrite(), wavwritehdr(), wblong(), wbshort(), wdouble(), wfloat(), wllong(), wlong(), wlshort(), and wshort().
| struct soundstream informat |
1.5.1