History

changes for GOMP

robs committed 17 years ago

Commit 902c6301 parent 52b037b49 files · +183 −36Browse files

Unified · Split

49 files
  1. CMakeLists.txt +6 −0
  2. configure.ac +3 −3
  3. src/8svx.c +1 −0
  4. src/CMakeLists.txt +1 −3
  5. src/adpcms.c +1 −0
  6. src/alsa.c +4 −0
  7. src/amr.h +1 −0
  8. src/ao.c +1 −0
  9. src/bend.c +1 −0
  10. src/coreaudio.c +2 −0
  11. src/dat.c +1 −0
  12. src/effects.c +3 −1
  13. src/effects_i.c +39 −16
  14. src/example0.c +1 −1
  15. src/example1.c +1 −1
  16. src/example2.c +1 −0
  17. src/ffmpeg.c +1 −0
  18. src/flac.c +1 −0
  19. src/gsm.c +1 −0
  20. src/hcom.c +1 −0
  21. src/ladspa.c +1 −0
  22. src/libsox.c +11 −0
  23. src/loudness.c +1 −0
  24. src/lpc10.c +2 −0
  25. src/mp3.c +1 −2
  26. src/noiseprof.c +1 −0
  27. src/noisered.c +2 −0
  28. src/normalise.c +1 −0
  29. src/overdrive.c +1 −0
  30. src/rabbit.c +1 −0
  31. src/rate.c +1 −0
  32. src/raw.c +2 −0
  33. src/reverb.c +1 −0
  34. src/silence.c +1 −0
  35. src/skelform.c +1 −0
  36. src/smp.c +1 −0
  37. src/sox.c +24 −4
  38. src/sox.h +6 −4
  39. src/sox_i.h +4 −1
  40. src/sox_sample_test.h +1 −0
  41. src/soxconfig.h.cmake +1 −0
  42. src/soxomp.h +38 −0
  43. src/spectrogram.c +1 −0
  44. src/splice.c +1 −0
  45. src/stat.c +1 −0
  46. src/tempo.c +1 −0
  47. src/voc.c +2 −0
  48. src/wav.c +1 −0
  49. src/wavpack.c +2 −0
CMakeLists.txt+6−0
@@ -69,6 +69,12 @@ optional(EXTERNAL_GSM gsm/gsm.h gsm gsm_create "") · 68 unmodified lines
6969 optional(HAVE_ALSA alsa/asoundlib.h asound snd_pcm_open alsa)
7070 optional(HAVE_AMRNB amrnb/sp_dec.h amrnb Decoder_Interface_init amr-nb)
7171 optional(HAVE_AMRWB amrwb/dec.h amrwb D_IF_init amr-wb)
72+if(CMAKE_COMPILER_IS_GNUCC)
73+ optional(HAVE_OPENMP omp.h gomp omp_get_thread_num "")
74+ if(HAVE_OPENMP)
75+ add_definitions(-fopenmp)
76+ endif(HAVE_OPENMP)
77+endif(CMAKE_COMPILER_IS_GNUCC)
7278 optional(HAVE_ID3TAG id3tag.h id3tag id3_file_open "")
7379 optional(HAVE_LIBAO ao/ao.h ao ao_play ao)
7480 optional(HAVE_FLAC FLAC/all.h FLAC FLAC__stream_encoder_new flac)
configure.ac+3−3
@@ -183,7 +183,7 @@ AC_SUBST(LIBTOOLFLAGS) · 182 unmodified lines
183183 dnl Check for GOMP
184184 AC_MSG_CHECKING([whether to use GOMP])
185185 AC_ARG_ENABLE(gomp,
186− AC_HELP_STRING([--enable-gomp], [Use GOMP.]),,enable_gomp=no)
186+ AC_HELP_STRING([--disable-gomp], [Don't use GOMP.]),,enable_gomp=yes)
187187 AC_MSG_RESULT($enable_gomp)
188188 if test "$enable_gomp" = "yes"; then
189189 AC_CHECK_HEADERS(omp.h,
@@ -191,10 +191,10 @@ if test "$enable_gomp" = "yes"; then · 1 unmodified line
191191 enable_gomp=no)
192192 fi
193193 if test "$enable_gomp" = yes; then
194− AC_DEFINE(HAVE_GOMP, 1, [Define to 1 if you have GOMP.])
194+ AC_DEFINE(HAVE_OPENMP, 1, [Define to 1 if you have GOMP.])
195195 CFLAGS="$CFLAGS -fopenmp"
196196 fi
197−AM_CONDITIONAL(HAVE_GOMP, test x$enable_gomp = xyes)
197+AM_CONDITIONAL(HAVE_OPENMP, test x$enable_gomp = xyes)
198198 AC_SUBST(GOMP_LIBS)
199199
200200 audio_driver_found=no
src/8svx.c+1−0
@@ -254,6 +254,7 @@ static int startwrite(sox_format_t * ft) · 253 unmodified lines
254254 static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t len)
255255 {
256256 priv_t * p = (priv_t * ) ft->priv;
257+ SOX_SAMPLE_LOCALS;
257258
258259 unsigned char datum;
259260 size_t done = 0, i;
src/CMakeLists.txt+1−3
@@ -13,9 +13,7 @@ if(CMAKE_COMPILER_IS_GNUCC) · 12 unmodified lines
1313 else(${ver} LESS 403)
1414 add_definitions(-Wtraditional-conversion)
1515 endif(${ver} LESS 403)
16− add_definitions(-Werror)
17− add_definitions(-fopenmp)
18− set(optional_libs ${optional_libs} gomp)
16+ #add_definitions(-Werror)
1917 endif(CMAKE_COMPILER_IS_GNUCC)
2018
2119 if (NOT EXTERNAL_GSM)
src/adpcms.c+1−0
@@ -251,6 +251,7 @@ size_t lsx_adpcm_write(sox_format_t * ft, adpcm_io_t * state, const sox_sample_t · 250 unmodified lines
251251 short word;
252252
253253 while (count < length) {
254+ SOX_SAMPLE_LOCALS;
254255 word = SOX_SAMPLE_TO_SIGNED_16BIT(*buffer++, ft->clips);
255256
256257 byte <<= 4;
src/alsa.c+4−0
@@ -536,12 +536,14 @@ static int startwrite(sox_format_t * ft) · 535 unmodified lines
536536
537537 static void sox_ub_write_buf(char* buf1, sox_sample_t const * buf2, size_t len, sox_bool swap UNUSED, size_t * clips)
538538 {
539+ SOX_SAMPLE_LOCALS;
539540 while (len--)
540541 *(uint8_t *)buf1++ = SOX_SAMPLE_TO_UNSIGNED_8BIT(*buf2++, *clips);
541542 }
542543
543544 static void sox_sb_write_buf(char *buf1, sox_sample_t const * buf2, size_t len, sox_bool swap UNUSED, size_t * clips)
544545 {
546+ SOX_SAMPLE_LOCALS;
545547 while (len--)
546548 *(int8_t *)buf1++ = SOX_SAMPLE_TO_SIGNED_8BIT(*buf2++, *clips);
547549 }
@@ -550,6 +552,7 @@ static void sox_uw_write_buf(char *buf1, sox_sample_t const * buf2, size_t len, · 2 unmodified lines
550552 {
551553 while (len--)
552554 {
555+ SOX_SAMPLE_LOCALS;
553556 uint16_t datum = SOX_SAMPLE_TO_UNSIGNED_16BIT(*buf2++, *clips);
554557 if (swap)
555558 datum = lsx_swapw(datum);
@@ -562,6 +565,7 @@ static void sox_sw_write_buf(char *buf1, sox_sample_t const * buf2, size_t len, · 6 unmodified lines
562565 {
563566 while (len--)
564567 {
568+ SOX_SAMPLE_LOCALS;
565569 int16_t datum = SOX_SAMPLE_TO_SIGNED_16BIT(*buf2++, *clips);
566570 if (swap)
567571 datum = lsx_swapw(datum);
src/amr.h+1−0
@@ -117,6 +117,7 @@ static size_t write_samples(sox_format_t * ft, const sox_sample_t * buf, size_t · 116 unmodified lines
117117 size_t done;
118118
119119 for (done = 0; done < len; ++done) {
120+ SOX_SAMPLE_LOCALS;
120121 p->pcm[p->pcm_index++] = SOX_SAMPLE_TO_SIGNED_16BIT(*buf++, ft->clips);
121122 if (p->pcm_index == AMR_FRAME) {
122123 p->pcm_index = 0;
src/ao.c+1−0
@@ -79,6 +79,7 @@ static void sox_sw_write_buf(char *buf1, sox_sample_t const * buf2, size_t len, · 78 unmodified lines
7979 {
8080 while (len--)
8181 {
82+ SOX_SAMPLE_LOCALS;
8283 uint16_t datum = SOX_SAMPLE_TO_SIGNED_16BIT(*buf2++, *clips);
8384 if (swap)
8485 datum = lsx_swapw(datum);
src/bend.c+1−0
@@ -150,6 +150,7 @@ static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, · 149 unmodified lines
150150
151151 /* main processing loop */
152152 for (i = 0; i < len; i++) {
153+ SOX_SAMPLE_LOCALS;
153154 ++p->in_pos;
154155
155156 /* As long as we have not yet collected enough data just read in */
src/coreaudio.c+2−0
@@ -213,6 +213,7 @@ static size_t read_samples(sox_format_t *ft, sox_sample_t *buf, size_t nsamp) · 212 unmodified lines
213213 size_t samp_left;
214214 OSStatus status;
215215 float *p;
216+ SOX_SAMPLE_LOCALS;
216217
217218 if (!ac->device_started)
218219 {
@@ -263,6 +264,7 @@ static size_t write_samples(sox_format_t *ft, const sox_sample_t *buf, size_t ns · 44 unmodified lines
263264 size_t samp_left;
264265 OSStatus status;
265266 float *p;
267+ SOX_SAMPLE_LOCALS;
266268
267269 if (!ac->device_started)
268270 {
src/dat.c+1−0
@@ -135,6 +135,7 @@ static size_t sox_datwrite(sox_format_t * ft, const sox_sample_t *buf, size_t ns · 134 unmodified lines
135135 sprintf(s," %15.8g ",dat->timevalue);
136136 lsx_writes(ft, s);
137137 for (i=0; i<ft->signal.channels; i++) {
138+ SOX_SAMPLE_LOCALS;
138139 sampval = SOX_SAMPLE_TO_FLOAT_64BIT(*buf++, ft->clips);
139140 sprintf(s," %15.8g", sampval);
140141 lsx_writes(ft, s);
src/effects.c+3−1
@@ -218,13 +218,15 @@ static int flow_effect(sox_effects_chain_t * chain, size_t n) · 217 unmodified lines
218218 for (f = 0; f < (int)effp->flows; ++f)
219219 chain->ibufc[f][i / effp->flows] = *ibuf++;
220220
221+#ifdef HAVE_OPENMP
221222 #pragma omp parallel for
223+#endif
222224 for (f = 0; f < (int)effp->flows; ++f) {
223225 size_t idonec = idone / effp->flows;
224226 size_t odonec = obeg / effp->flows;
225227 int eff_status_c = effp->handler.flow(&chain->effects[n][f],
226228 chain->ibufc[f], chain->obufc[f], &idonec, &odonec);
227−#ifndef HAVE_GOMP
229+#ifndef HAVE_OPENMP
228230 if (f && (idonec != idone_last || odonec != odone_last)) {
229231 lsx_fail("flowed asymmetrically!");
230232 effstatus = SOX_EOF;
src/effects_i.c+39−16
@@ -397,26 +397,36 @@ int lsx_set_dft_length(int num_taps) /* Set to 4 x nearest power of 2 */ · 396 unmodified lines
397397 }
398398
399399 #include "fft4g.h"
400−int * lsx_fft_br;
400+int * lsx_fft_br;
401401 double * lsx_fft_sc;
402+static int fft_len;
403+#ifdef HAVE_OPENMP
404+static omp_lock_t fft_cache_lock;
405+#endif
406+
407+static void init_fft_cache(void)
408+{
409+ omp_init_lock(&fft_cache_lock);
410+}
411+
412+static void clear_fft_cache(void)
413+{
414+ omp_destroy_lock(&fft_cache_lock);
415+ free(lsx_fft_br);
416+ free(lsx_fft_sc);
417+ lsx_fft_sc = NULL;
418+ lsx_fft_br = NULL;
419+ fft_len = 0;
420+}
402421
403422 static void update_fft_cache(int len)
404423 {
405− static int n;
406−
407− if (!len) {
408− free(lsx_fft_br);
409− free(lsx_fft_sc);
410− lsx_fft_sc = NULL;
411− lsx_fft_br = NULL;
412− n = 0;
413− return;
414− }
415− if (len > n) {
416− int old_n = n;
417− n = len;
418− lsx_fft_br = lsx_realloc(lsx_fft_br, dft_br_len(n) * sizeof(*lsx_fft_br));
419− lsx_fft_sc = lsx_realloc(lsx_fft_sc, dft_sc_len(n) * sizeof(*lsx_fft_sc));
424+ omp_set_lock(&fft_cache_lock);
425+ if (len > fft_len) {
426+ int old_n = fft_len;
427+ fft_len = len;
428+ lsx_fft_br = lsx_realloc(lsx_fft_br, dft_br_len(fft_len) * sizeof(*lsx_fft_br));
429+ lsx_fft_sc = lsx_realloc(lsx_fft_sc, dft_sc_len(fft_len) * sizeof(*lsx_fft_sc));
420430 if (!old_n)
421431 lsx_fft_br[0] = 0;
422432 }
@@ -432,6 +442,7 @@ void lsx_safe_rdft(int len, int type, double * d) · 9 unmodified lines
432442 assert(is_power_of_2(len));
433443 update_fft_cache(len);
434444 lsx_rdft(len, type, d, lsx_fft_br, lsx_fft_sc);
445+ omp_unset_lock(&fft_cache_lock);
435446 }
436447
437448 void lsx_safe_cdft(int len, int type, double * d)
@@ -439,6 +450,7 @@ void lsx_safe_cdft(int len, int type, double * d) · 1 unmodified line
439450 assert(is_power_of_2(len));
440451 update_fft_cache(len);
441452 lsx_cdft(len, type, d, lsx_fft_br, lsx_fft_sc);
453+ omp_unset_lock(&fft_cache_lock);
442454 }
443455
444456 void lsx_power_spectrum(int n, double const * in, double * out)
@@ -536,3 +548,14 @@ void lsx_apply_kaiser(double h[], const int num_points, double beta) · 91 unmodified lines
536548 }
537549 }
538550
551+int lsx_effects_init(void)
552+{
553+ init_fft_cache();
554+ return SOX_SUCCESS;
555+}
556+
557+int lsx_effects_quit(void)
558+{
559+ clear_fft_cache();
560+ return SOX_SUCCESS;
561+}
src/example0.c+1−1
@@ -38,7 +38,7 @@ int main(int argc, char * argv[]) · 37 unmodified lines
3838 assert(argc == 3);
3939
4040 /* All libSoX applications must start by initialising the SoX library */
41− assert(sox_format_init() == SOX_SUCCESS);
41+ assert(sox_init() == SOX_SUCCESS);
4242
4343 /* Open the input file (with default parameters) */
4444 assert(in = sox_open_read(argv[1], NULL, NULL, NULL));
src/example1.c+1−1
@@ -110,7 +110,7 @@ int main(int argc, char * argv[]) · 109 unmodified lines
110110 assert(argc == 3);
111111
112112 /* All libSoX applications must start by initialising the SoX library */
113− assert(sox_format_init() == SOX_SUCCESS);
113+ assert(sox_init() == SOX_SUCCESS);
114114
115115 /* Open the input file (with default parameters) */
116116 assert(in = sox_open_read(argv[1], NULL, NULL, NULL));
src/example2.c+1−0
@@ -87,6 +87,7 @@ int main(int argc, char * argv[]) · 86 unmodified lines
8787 int l, r;
8888
8989 for (i = 0; i < block_size; ++i) {
90+ SOX_SAMPLE_LOCALS;
9091 /* convert the sample from SoX's internal format to a `double' for
9192 * processing in this application: */
9293 double sample = SOX_SAMPLE_TO_FLOAT_64BIT(buf[i], clips);
src/ffmpeg.c+1−0
@@ -406,6 +406,7 @@ static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t l · 405 unmodified lines
406406 do {
407407 /* If output frame is not full, copy data into it */
408408 if (ffmpeg->samples_index < ffmpeg->audio_input_frame_size) {
409+ SOX_SAMPLE_LOCALS;
409410 for (; nread < len && ffmpeg->samples_index < ffmpeg->audio_input_frame_size; nread++)
410411 ffmpeg->samples[ffmpeg->samples_index++] = SOX_SAMPLE_TO_SIGNED_16BIT(buf[nread], ft->clips);
411412 }
src/flac.c+1−0
@@ -436,6 +436,7 @@ static size_t write_samples(sox_format_t * const ft, sox_sample_t const * const · 435 unmodified lines
436436 unsigned i;
437437
438438 for (i = 0; i < len; ++i) {
439+ SOX_SAMPLE_LOCALS;
439440 long pcm = SOX_SAMPLE_TO_SIGNED_32BIT(sampleBuffer[i], ft->clips);
440441 p->decoded_samples[i] = pcm >> (32 - p->bits_per_sample);
441442 switch (p->bits_per_sample) {
src/gsm.c+1−0
@@ -195,6 +195,7 @@ static size_t sox_gsmwrite(sox_format_t * ft, const sox_sample_t *buf, size_t sa · 194 unmodified lines
195195
196196 while (done < samp)
197197 {
198+ SOX_SAMPLE_LOCALS;
198199 while ((p->samplePtr < p->sampleTop) && (done < samp))
199200 *(p->samplePtr)++ =
200201 SOX_SAMPLE_TO_SIGNED_16BIT(buf[done++], ft->clips);
src/hcom.c+1−0
@@ -277,6 +277,7 @@ static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t l · 276 unmodified lines
277277 }
278278
279279 for (i = 0; i < len; i++) {
280+ SOX_SAMPLE_LOCALS;
280281 datum = *buf++;
281282 p->data[p->pos++] = SOX_SAMPLE_TO_UNSIGNED_8BIT(datum, ft->clips);
282283 }
src/ladspa.c+1−0
@@ -230,6 +230,7 @@ static int sox_ladspa_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sa · 229 unmodified lines
230230
231231 if (len) {
232232 LADSPA_Data *buf = lsx_malloc(sizeof(LADSPA_Data) * len);
233+ SOX_SAMPLE_LOCALS;
233234
234235 /* Insert input if effect takes it */
235236 if (l_st->input_port != ULONG_MAX) {
src/libsox.c+11−0
@@ -85,3 +85,14 @@ SOX_MESSAGE_FUNCTION(lsx_debug_most , 6) · 84 unmodified lines
8585
8686 #undef SOX_MESSAGE_FUNCTION
8787
88+int sox_init(void)
89+{
90+ sox_format_init();
91+ return lsx_effects_init();
92+}
93+
94+int sox_quit(void)
95+{
96+ sox_format_quit();
97+ return lsx_effects_quit();
98+}
src/loudness.c+1−0
@@ -161,6 +161,7 @@ static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, · 160 unmodified lines
161161 priv_t * p = (priv_t *)effp->priv;
162162 size_t i, odone = min(*osamp, (size_t)fifo_occupancy(&p->output_fifo));
163163 double const * s = fifo_read(&p->output_fifo, (int)odone, NULL);
164+ SOX_SAMPLE_LOCALS;
164165
165166 for (i = 0; i < odone; ++i)
166167 *obuf++ = SOX_FLOAT_64BIT_TO_SAMPLE(*s++, effp->clips);
src/lpc10.c+2−0
@@ -153,6 +153,7 @@ static size_t read_samples(sox_format_t * ft, sox_sample_t *buf, size_t len) · 152 unmodified lines
153153 size_t nread = 0;
154154
155155 while (nread < len) {
156+ SOX_SAMPLE_LOCALS;
156157 /* Read more data if buffer is empty */
157158 if (lpc->samples == LPC10_SAMPLES_PER_FRAME) {
158159 INT32 bits[LPC10_BITS_IN_COMPRESSED_FRAME];
@@ -178,6 +179,7 @@ static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t l · 19 unmodified lines
178179
179180 while (len > 0) {
180181 while (len > 0 && lpc->samples < LPC10_SAMPLES_PER_FRAME) {
182+ SOX_SAMPLE_LOCALS;
181183 lpc->speech[lpc->samples++] = SOX_SAMPLE_TO_FLOAT_32BIT(buf[nwritten++], ft->clips);
182184 len--;
183185 }
src/mp3.c+1−2
@@ -406,6 +406,7 @@ static size_t sox_mp3write(sox_format_t * ft, const sox_sample_t *buf, size_t sa · 405 unmodified lines
406406 int i,j;
407407 ptrdiff_t done = 0;
408408 size_t written;
409+ SOX_SAMPLE_LOCALS;
409410
410411 /* NOTE: This logic assumes that "short int" is 16-bits
411412 * on all platforms. It happens to be for all that I know
@@ -442,9 +443,7 @@ static size_t sox_mp3write(sox_format_t * ft, const sox_sample_t *buf, size_t sa · 30 unmodified lines
442443 {
443444 j=0;
444445 for (i=0; i<nsamples; i++)
445− {
446446 buffer_l[i]=SOX_SAMPLE_TO_SIGNED_16BIT(buf[j++], ft->clips);
447− }
448447 }
449448
450449 mp3buffer_size = 1.25 * nsamples + 7200;
src/noiseprof.c+1−0
@@ -124,6 +124,7 @@ static int sox_noiseprof_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox · 123 unmodified lines
124124
125125 /* Collect data for every channel. */
126126 for (i = 0; i < chans; i ++) {
127+ SOX_SAMPLE_LOCALS;
127128 chandata_t * chan = &(p->chandata[i]);
128129 for (j = 0; j < n; j ++)
129130 chan->window[j + p->bufdata] =
src/noisered.c+2−0
@@ -230,6 +230,7 @@ static int process_window(sox_effect_t * effp, priv_t * data, unsigned chan_num, · 229 unmodified lines
230230 int use = min(len, WINDOWSIZE)-min(len,(WINDOWSIZE/2));
231231 chandata_t *chan = &(data->chandata[chan_num]);
232232 int first = (chan->lastwindow == NULL);
233+ SOX_SAMPLE_LOCALS;
233234
234235 if ((nextwindow = lsx_calloc(WINDOWSIZE, sizeof(float))) == NULL)
235236 return SOX_EOF;
@@ -283,6 +284,7 @@ static int sox_noisered_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_ · 47 unmodified lines
283284
284285 /* Reduce noise on every channel. */
285286 for (i = 0; i < tracks; i ++) {
287+ SOX_SAMPLE_LOCALS;
286288 chandata_t* chan = &(data->chandata[i]);
287289 size_t j;
288290
src/normalise.c+1−0
@@ -63,6 +63,7 @@ static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, · 62 unmodified lines
6363 return SOX_EOF;
6464 }
6565 if (p->balance) for (len = *isamp; len; --len, ++ibuf) {
66+ SOX_SAMPLE_LOCALS;
6667 size_t dummy = 0;
6768 double d = SOX_SAMPLE_TO_FLOAT_64BIT(*ibuf, dummy);
6869 p->rms += sqr(d);
src/overdrive.c+1−0
@@ -50,6 +50,7 @@ static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, · 49 unmodified lines
5050 priv_t * p = (priv_t *)effp->priv;
5151 size_t dummy = 0, len = *isamp = *osamp = min(*isamp, *osamp);
5252 while (len--) {
53+ SOX_SAMPLE_LOCALS;
5354 double d = SOX_SAMPLE_TO_FLOAT_64BIT(*ibuf++, dummy), d0 = d;
5455 d *= p->gain;
5556 d += p->colour;
src/rabbit.c+1−0
@@ -114,6 +114,7 @@ static int flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_sample_t *obu · 113 unmodified lines
114114 size_t isamples0 = d->input_frames * channels;
115115 size_t isamples = isamples0 + *isamp;
116116 size_t osamples = isamples * (d->src_ratio + 0.01) + 8;
117+ SOX_SAMPLE_LOCALS;
117118
118119 if (osamples > *osamp) {
119120 osamples = *osamp;
src/rate.c+1−0
@@ -623,6 +623,7 @@ static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, · 622 unmodified lines
623623 {
624624 priv_t * p = (priv_t *)effp->priv;
625625 size_t i, odone = *osamp;
626+ SOX_SAMPLE_LOCALS;
626627
627628 sample_t const * s = rate_output(&p->rate, NULL, &odone);
628629 for (i = 0; i < odone; ++i) *obuf++ = TO_SOX(*s++, effp->clips);
src/raw.c+2−0
@@ -69,6 +69,7 @@ int lsx_rawstart(sox_format_t * ft, sox_bool default_rate, · 68 unmodified lines
6969 sox_format_t * ft, sox_sample_t *buf, size_t len) \
7070 { \
7171 size_t n, nread; \
72+ SOX_SAMPLE_LOCALS; \
7273 ctype *data = lsx_malloc(sizeof(ctype) * len); \
7374 nread = lsx_read_ ## type ## _buf(ft, (uctype *)data, len); \
7475 for (n = 0; n < nread; n++) \
@@ -94,6 +95,7 @@ READ_SAMPLES_FUNC(df, sizeof(double), su, double, double, SOX_FLOAT_64BIT_TO_SAM · 19 unmodified lines
9495 static size_t sox_write_ ## sign ## type ## _samples( \
9596 sox_format_t * ft, sox_sample_t const * buf, size_t len) \
9697 { \
98+ SOX_SAMPLE_LOCALS; \
9799 size_t n, nwritten; \
98100 ctype *data = lsx_malloc(sizeof(ctype) * len); \
99101 for (n = 0; n < len; n++) \
src/reverb.c+1−0
@@ -219,6 +219,7 @@ static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, · 218 unmodified lines
219219 {
220220 priv_t * p = (priv_t *)effp->priv;
221221 size_t c, i, w, len = min(*isamp / p->ichannels, *osamp / p->ochannels);
222+ SOX_SAMPLE_LOCALS;
222223
223224 *isamp = len * p->ichannels, *osamp = len * p->ochannels;
224225 for (c = 0; c < p->ichannels; ++c)
src/silence.c+1−0
@@ -280,6 +280,7 @@ static int aboveThreshold(sox_effect_t * effp, sox_sample_t value, double thresh · 279 unmodified lines
280280 /* Only consider the original bits when looking for silence */
281281 switch(effp->in_signal.precision)
282282 {
283+ SOX_SAMPLE_LOCALS;
283284 case 8:
284285 value = SOX_SAMPLE_TO_SIGNED_8BIT(value, dummy_clipped_count);
285286 ratio = (double)abs(value) / (double)SOX_INT8_MAX;
src/skelform.c+1−0
@@ -159,6 +159,7 @@ static size_t write_samples(sox_format_t * ft, const sox_sample_t *buf, size_t l · 158 unmodified lines
159159 switch (ft->encoding.bits_per_sample) {
160160 case 8:
161161 switch (ft->encoding.encoding) {
162+ SOX_SAMPLE_LOCALS;
162163 case SOX_ENCODING_UNSIGNED:
163164 while (done < len && lsx_writeb(ft, SOX_SAMPLE_TO_UNSIGNED_8BIT(*buf++, ft->clips)) == SOX_SUCCESS)
164165 ++done;
src/smp.c+1−0
@@ -368,6 +368,7 @@ static size_t sox_smpwrite(sox_format_t * ft, const sox_sample_t *buf, size_t le · 367 unmodified lines
368368 size_t done = 0;
369369
370370 while(done < len) {
371+ SOX_SAMPLE_LOCALS;
371372 datum = (int) SOX_SAMPLE_TO_SIGNED_16BIT(*buf++, ft->clips);
372373 lsx_writew(ft, (uint16_t)datum);
373374 smp->NoOfSamps++;
src/sox.c+24−4
@@ -20,7 +20,7 @@ · 19 unmodified lines
2020 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2121 */
2222
23−#include "soxconfig.h"
23+#include "soxomp.h" /* Make this 1st in list (for soxconfig) */
2424 #include "sox.h"
2525 #include "util.h"
2626
@@ -169,6 +169,10 @@ static sox_bool user_restart_eff = sox_false; · 142 unmodified lines
169169 static int success = 0;
170170 static sox_sample_t omax[2], omin[2];
171171
172+/* Multi-processing */
173+
174+static sox_bool single_threaded = sox_false;
175+
172176
173177 /* Cleanup atexit() function, hence always called. */
174178 static void cleanup(void)
@@ -1516,12 +1520,18 @@ static void display_SoX_version(FILE * file) · 1341 unmodified lines
15161520 #elif defined __SUNPRO_C
15171521 fprintf(file, "sun c: %x\n", __SUNPRO_C);
15181522 #endif
1519− fprintf(file, "arch: %lu%lu%lu%lu %lu%lu %lu%lu %c\n",
1523+ fprintf(file, "arch: %lu%lu%lu%lu %lu%lu %lu%lu %c %s\n",
15201524 (unsigned long)sizeof(char), (unsigned long)sizeof(short),
15211525 (unsigned long)sizeof(long), (unsigned long)sizeof(off_t),
15221526 (unsigned long)sizeof(float), (unsigned long)sizeof(double),
15231527 (unsigned long)sizeof(int *), (unsigned long)sizeof(int (*)(void)),
1524− "LB"[MACHINE_IS_BIGENDIAN]);
1528+ "LB"[MACHINE_IS_BIGENDIAN],
1529+#ifdef HAVE_OPENMP
1530+ "OMP"
1531+#else
1532+ ""
1533+#endif
1534+ );
15251535 }
15261536 }
15271537
@@ -1818,6 +1828,7 @@ static struct option long_options[] = · 290 unmodified lines
18181828 {"output" , required_argument, NULL, 0},
18191829 {"effects-file" , required_argument, NULL, 0},
18201830 {"temp" , required_argument, NULL, 0},
1831+ {"single-threaded" , no_argument, NULL, 0},
18211832
18221833 {"bits" , required_argument, NULL, 'b'},
18231834 {"channels" , required_argument, NULL, 'c'},
@@ -2006,6 +2017,10 @@ static char parse_gopts_and_fopts(file_t * f, int argc, char **argv) · 182 unmodified lines
20062017 sox_globals.tmp_path = strdup(optarg);
20072018 break;
20082019
2020+ case 17:
2021+ single_threaded = sox_true;
2022+ break;
2023+
20092024 }
20102025 break;
20112026
@@ -2443,7 +2458,7 @@ int main(int argc, char **argv) · 431 unmodified lines
24432458 else if (strends(myname, "soxi"))
24442459 sox_mode = sox_soxi;
24452460
2446− if (sox_format_init() != SOX_SUCCESS)
2461+ if (sox_init() != SOX_SUCCESS)
24472462 exit(1);
24482463
24492464 if (sox_mode == sox_soxi)
@@ -2471,6 +2486,11 @@ int main(int argc, char **argv) · 21 unmodified lines
24712486 }
24722487 #endif
24732488
2489+#ifdef HAVE_OPENMP
2490+ if (single_threaded)
2491+ omp_set_num_threads(1);
2492+#endif
2493+
24742494 if (sox_globals.verbosity > 2)
24752495 display_SoX_version(stderr);
24762496
src/sox.h+6−4
@@ -97,9 +97,8 @@ typedef int32_t sox_sample_t; · 96 unmodified lines
9797 * the upper-most bit then treating them as signed integers.
9898 */
9999
100−/* Temporary variables to prevent multiple evaluation of macro arguments: */
101−static sox_sample_t sox_macro_temp_sample UNUSED;
102−static double sox_macro_temp_double UNUSED;
100+#define SOX_SAMPLE_LOCALS sox_sample_t sox_macro_temp_sample UNUSED; \
101+ double sox_macro_temp_double UNUSED
103102
104103 #define SOX_SAMPLE_NEG SOX_INT_MIN(32)
105104 #define SOX_SAMPLE_TO_UNSIGNED(bits,d,clips) \
@@ -395,6 +394,10 @@ struct sox_format { · 289 unmodified lines
395394 #define SOX_FILE_BIG_END (SOX_FILE_ENDIAN | SOX_FILE_ENDBIG)
396395
397396 int sox_format_init(void);
397+void sox_format_quit(void);
398+
399+int sox_init(void);
400+int sox_quit(void);
398401
399402 typedef const sox_format_handler_t *(*sox_format_fn_t)(void);
400403
@@ -429,7 +432,6 @@ int sox_close(sox_format_t * ft); · 28 unmodified lines
429432 int sox_seek(sox_format_t * ft, uint64_t offset, int whence);
430433
431434 sox_format_handler_t const * sox_find_format(char const * name, sox_bool no_dev);
432−void sox_format_quit(void);
433435
434436 /*
435437 * Structures for effects.
src/sox_i.h+4−1
@@ -13,7 +13,7 @@ · 12 unmodified lines
1313 #ifndef SOX_I_H
1414 #define SOX_I_H
1515
16−#include "soxconfig.h"
16+#include "soxomp.h" /* Make this 1st in list (for soxconfig) */
1717 #include "sox.h"
1818 #include "util.h"
1919
@@ -266,4 +266,7 @@ char * lsx_usage_lines(char * * usage, char const * const * lines, size_t n); · 246 unmodified lines
266266
267267 int lsx_effect_set_imin(sox_effect_t * effp, size_t imin);
268268
269+int lsx_effects_init(void);
270+int lsx_effects_quit(void);
271+
269272 #endif
src/sox_sample_test.h+1−0
@@ -163,6 +163,7 @@ int main() · 162 unmodified lines
163163 size_t clips = 0;
164164
165165 double d;
166+ SOX_SAMPLE_LOCALS;
166167
167168 TEST_UINT(8)
168169 TEST_UINT(16)
src/soxconfig.h.cmake+1−0
@@ -23,6 +23,7 @@ · 22 unmodified lines
2323 #cmakedefine HAVE_MKSTEMP 1
2424 #cmakedefine HAVE_OGG_SPEEX 1
2525 #cmakedefine HAVE_OGG_VORBIS 1
26+#cmakedefine HAVE_OPENMP 1
2627 #cmakedefine HAVE_POPEN 1
2728 #cmakedefine HAVE_PNG 1
2829 #cmakedefine HAVE_SAMPLERATE_H 1
src/soxomp.h+38−0
@@ -0,0 +1,38 @@
1+#include "soxconfig.h"
2+
3+#ifdef HAVE_OPENMP
4+ #include <omp.h>
5+#else
6+
7+typedef int omp_lock_t;
8+typedef int omp_nest_lock_t;
9+
10+#define omp_set_num_threads(int) (void)0
11+#define omp_get_num_threads() 1
12+#define omp_get_max_threads() 1
13+#define omp_get_thread_num() 0
14+#define omp_get_num_procs() 1
15+#define omp_in_parallel() 1
16+
17+#define omp_set_dynamic(int) (void)0
18+#define omp_get_dynamic() 0
19+
20+#define omp_set_nested(int) (void)0
21+#define omp_get_nested() 0
22+
23+#define omp_init_lock(omp_lock_t) (void)0
24+#define omp_destroy_lock(omp_lock_t) (void)0
25+#define omp_set_lock(omp_lock_t) (void)0
26+#define omp_unset_lock(omp_lock_t) (void)0
27+#define omp_test_lock(omp_lock_t) 0
28+
29+#define omp_init_nest_lock(omp_nest_lock_t) (void)0
30+#define omp_destroy_nest_lock(omp_nest_lock_t) (void)0
31+#define omp_set_nest_lock(omp_nest_lock_t) (void)0
32+#define omp_unset_nest_lock(omp_nest_lock_t) (void)0
33+#define omp_test_nest_lock(omp_nest_lock_t) 0
34+
35+#define omp_get_wtime() 0
36+#define omp_get_wtick() 0
37+
38+#endif
src/spectrogram.c+1−0
@@ -193,6 +193,7 @@ static int flow(sox_effect_t * effp, · 192 unmodified lines
193193 *isamp = *osamp = len;
194194
195195 while (sox_true) {
196+ SOX_SAMPLE_LOCALS;
196197 if (p->read == p->step_size) {
197198 memmove(p->buf, p->buf + p->step_size,
198199 (p->dft_size - p->step_size) * sizeof(*p->buf));
src/splice.c+1−0
@@ -152,6 +152,7 @@ static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, · 151 unmodified lines
152152 {
153153 priv_t * p = (priv_t *)effp->priv;
154154 size_t c, idone = 0, odone = 0;
155+ SOX_SAMPLE_LOCALS;
155156 *isamp /= effp->in_signal.channels;
156157 *osamp /= effp->in_signal.channels;
157158
src/stat.c+1−0
@@ -140,6 +140,7 @@ static int sox_stat_flow(sox_effect_t * effp, const sox_sample_t *ibuf, sox_samp · 139 unmodified lines
140140
141141 if (stat->fft) {
142142 for (x = 0; x < len; x++) {
143+ SOX_SAMPLE_LOCALS;
143144 stat->re_in[stat->fft_offset++] = SOX_SAMPLE_TO_FLOAT_32BIT(ibuf[x], effp->clips);
144145
145146 if (stat->fft_offset >= stat->fft_size) {
src/tempo.c+1−0
@@ -264,6 +264,7 @@ static int flow(sox_effect_t * effp, const sox_sample_t * ibuf, · 263 unmodified lines
264264 priv_t * p = (priv_t *)effp->priv;
265265 size_t i, odone = *osamp /= effp->in_signal.channels;
266266 float const * s = tempo_output(p->tempo, NULL, &odone);
267+ SOX_SAMPLE_LOCALS;
267268
268269 for (i = 0; i < odone * effp->in_signal.channels; ++i)
269270 *obuf++ = SOX_FLOAT_32BIT_TO_SAMPLE(*s++, effp->clips);
src/voc.c+2−0
@@ -347,6 +347,7 @@ static size_t read_samples(sox_format_t * ft, sox_sample_t * buf, · 346 unmodified lines
347347 /* Read the data in the file */
348348 if (v->size <= 4) {
349349 if (!v->adpcm.setup.sign) {
350+ SOX_SAMPLE_LOCALS;
350351 if (lsx_readb(ft, &uc) == SOX_EOF) {
351352 lsx_warn("VOC input: short file");
352353 v->block_remaining = 0;
@@ -489,6 +490,7 @@ static size_t write_samples(sox_format_t * ft, const sox_sample_t * buf, · 136 unmodified lines
489490 }
490491 v->samples += len;
491492 while (done < len) {
493+ SOX_SAMPLE_LOCALS;
492494 if (ft->encoding.bits_per_sample == 8) {
493495 uc = SOX_SAMPLE_TO_UNSIGNED_8BIT(*buf++, ft->clips);
494496 lsx_writeb(ft, uc);
src/wav.c+1−0
@@ -331,6 +331,7 @@ static size_t wavgsmwrite(sox_format_t * ft, const sox_sample_t *buf, size_t len · 330 unmodified lines
331331 ft->sox_errno = SOX_SUCCESS;
332332
333333 while (done < len) {
334+ SOX_SAMPLE_LOCALS;
334335 while ((wav->gsmindex < 160*2) && (done < len))
335336 wav->gsmsample[(wav->gsmindex)++] =
336337 SOX_SAMPLE_TO_SIGNED_16BIT(buf[done++], ft->clips);
src/wavpack.c+2−0
@@ -71,6 +71,7 @@ static size_t read_samples(sox_format_t * ft, sox_sample_t * buf, size_t len) · 70 unmodified lines
7171 priv_t * p = (priv_t *)ft->priv;
7272 size_t i, actual = WavpackUnpackSamples(p->codec, buf, (uint32_t) len / ft->signal.channels) * ft->signal.channels;
7373 for (i = 0; i < actual; ++i) switch (ft->encoding.bits_per_sample) {
74+ SOX_SAMPLE_LOCALS;
7475 case 8: buf[i] = SOX_SIGNED_8BIT_TO_SAMPLE(buf[i],); break;
7576 case 16: buf[i] = SOX_SIGNED_16BIT_TO_SAMPLE(buf[i],); break;
7677 case 24: buf[i] = SOX_SIGNED_24BIT_TO_SAMPLE(buf[i],); break;
@@ -119,6 +120,7 @@ static size_t write_samples(sox_format_t * ft, const sox_sample_t * buf, size_t · 42 unmodified lines
119120 int result;
120121
121122 for (i = 0; i < len; ++i) switch (ft->encoding.bits_per_sample) {
123+ SOX_SAMPLE_LOCALS;
122124 case 8: obuf[i] = SOX_SAMPLE_TO_SIGNED_8BIT(buf[i], ft->clips); break;
123125 case 16: obuf[i] = SOX_SAMPLE_TO_SIGNED_16BIT(buf[i], ft->clips); break;
124126 case 24: obuf[i] = SOX_SAMPLE_TO_SIGNED_24BIT(buf[i], ft->clips) << 8;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t