ref: bb3de85b4548137544fc06a3e10a2b30c9e017cd
parent: 2fcc4d9eec388ee6583fbda2235b690b718159f0
author: Ulrich Klauer <ulrich@chirlu.de>
date: Sun Jan 29 20:43:07 EST 2012
Use size_t to count effects, flows, chains, files Use only size_t for index variables etc. when effects, flows, effects chains, or files are counted. Previously, there was inconsistent use of size_t, int, or unsigned int.
--- a/src/effects.c
+++ b/src/effects.c
@@ -130,7 +130,7 @@
int sox_add_effect(sox_effects_chain_t * chain, sox_effect_t * effp, sox_signalinfo_t * in, sox_signalinfo_t const * out)
{
int ret, (*start)(sox_effect_t * effp) = effp->handler.start;
- unsigned f;
+ size_t f;
sox_effect_t eff0; /* Copy of effect for flow 0 before calling start */
effp->global_info = &chain->global_info;
@@ -186,7 +186,7 @@
if (chain->length == chain->table_size) {
chain->table_size += EFF_TABLE_STEP;
lsx_debug_more("sox_add_effect: extending effects table, "
- "new size = %lu", (unsigned long)chain->table_size);
+ "new size = %" PRIuPTR, chain->table_size);
lsx_revalloc(chain->effects, chain->table_size);
}
@@ -213,8 +213,8 @@
{
sox_effect_t * effp1 = &chain->effects[n - 1][0];
sox_effect_t * effp = &chain->effects[n][0];
- int effstatus = SOX_SUCCESS, f = 0;
- size_t i;
+ int effstatus = SOX_SUCCESS;
+ size_t i, f = 0;
const sox_sample_t *ibuf;
size_t idone = effp1->oend - effp1->obeg;
size_t obeg = sox_globals.bufsiz - effp->oend;
@@ -237,7 +237,7 @@
ibuf = &effp1->obuf[effp1->obeg];
for (i = 0; i < idone; i += effp->flows)
- for (f = 0; f < (int)effp->flows; ++f)
+ for (f = 0; f < effp->flows; ++f)
chain->ibufc[f][i / effp->flows] = *ibuf++;
#ifdef HAVE_OPENMP
@@ -244,7 +244,7 @@
if (sox_globals.use_threads && effp->flows > 1)
{
#pragma omp parallel for
- for (f = 0; f < (int)effp->flows; ++f) {
+ for (f = 0; f < effp->flows; ++f) {
size_t idonec = idone / effp->flows;
size_t odonec = obeg / effp->flows;
int eff_status_c = effp->handler.flow(&chain->effects[n][f],
@@ -261,7 +261,7 @@
else /* sox_globals.use_threads */
#endif
{
- for (f = 0; f < (int)effp->flows; ++f) {
+ for (f = 0; f < effp->flows; ++f) {
size_t idonec = idone / effp->flows;
size_t odonec = obeg / effp->flows;
int eff_status_c = effp->handler.flow(&chain->effects[n][f],
@@ -279,7 +279,7 @@
}
for (i = 0; i < odone_last; ++i)
- for (f = 0; f < (int)effp->flows; ++f)
+ for (f = 0; f < effp->flows; ++f)
*obuf++ = chain->obufc[f][i];
idone = effp->flows * idone_last;
@@ -399,8 +399,10 @@
++e;
else if (e == source_e)
draining = sox_true;
- else if ((int)--e < (int)source_e)
+ else if (e < source_e)
e = source_e;
+ else
+ --e;
if (callback && callback(source_e == chain->length, client_data) != SOX_SUCCESS) {
flow_status = SOX_EOF; /* Client has requested to stop the flow. */
@@ -420,7 +422,7 @@
sox_uint64_t sox_effects_clips(sox_effects_chain_t * chain)
{
- unsigned i, f;
+ size_t i, f;
uint64_t clips = 0;
for (i = 1; i < chain->length - 1; ++i)
for (f = 0; f < chain->effects[i][0].flows; ++f)
@@ -430,7 +432,7 @@
sox_uint64_t sox_stop_effect(sox_effect_t *effp)
{
- unsigned f;
+ size_t f;
uint64_t clips = 0;
for (f = 0; f < effp->flows; ++f) {
@@ -445,7 +447,7 @@
if (chain->length == chain->table_size) {
chain->table_size += EFF_TABLE_STEP;
lsx_debug_more("sox_push_effect_last: extending effects table, "
- "new size = %lu", (unsigned long)chain->table_size);
+ "new size = %" PRIuPTR, chain->table_size);
lsx_revalloc(chain->effects, chain->table_size);
}
@@ -473,7 +475,7 @@
void sox_delete_effect(sox_effect_t *effp)
{
uint64_t clips;
- unsigned f;
+ size_t f;
if ((clips = sox_stop_effect(effp)) != 0)
lsx_warn("%s clipped %" PRIu64 " samples; decrease volume?",
--- a/src/sox.c
+++ b/src/sox.c
@@ -178,9 +178,9 @@
/* Size of memory structures related to effects arguments (user_effargs[i],
* user_effargs[i][j].argv) to be extended in steps of EFFARGS_STEP */
#define EFFARGS_STEP 8
-static unsigned *nuser_effects = NULL; /* array: number of effects in each chain */
-static int current_eff_chain = 0;
-static int eff_chain_count = 0;
+static size_t *nuser_effects = NULL; /* array: number of effects in each chain */
+static size_t current_eff_chain = 0;
+static size_t eff_chain_count = 0;
static sox_bool very_first_effchain = sox_true;
/* Indicates that not only the first effects chain is in effect (hrm), but
also that it has never been restarted. Only then we may use the
@@ -745,7 +745,7 @@
*/
static void free_eff_chain(void)
{
- unsigned j;
+ size_t j;
int k;
for (j = 0; j < nuser_effects[eff_chain_count]; j++)
{
@@ -792,8 +792,7 @@
static void parse_effects(int argc, char ** argv)
{
while (optstate.ind < argc) {
- unsigned eff_offset;
- size_t j;
+ size_t eff_offset, j;
int newline_mode = 0;
eff_offset = nuser_effects[eff_chain_count];
@@ -1012,7 +1011,7 @@
*/
static void create_user_effects(void)
{
- unsigned i;
+ size_t i;
sox_effect_t *effp;
size_t num_effects = nuser_effects[current_eff_chain];
@@ -1056,7 +1055,7 @@
{
sox_signalinfo_t signal = combiner_signal;
int guard = is_guarded - 1;
- unsigned i;
+ size_t i;
sox_effect_t * effp;
char * rate_arg = is_player ? (play_rate_arg ? play_rate_arg : "-l") : NULL;
@@ -1189,7 +1188,7 @@
static uint64_t total_clips(void)
{
- unsigned i;
+ size_t i;
uint64_t clips = 0;
for (i = 0; i < file_count; ++i)
clips += files[i]->ft->clips + files[i]->volume_clips;
@@ -1596,7 +1595,7 @@
* -n isn't as convenient.
*/
for (i = 0; i < input_count; i++) {
- unsigned j;
+ size_t j;
for (j =0; j < nuser_effects[current_eff_chain] &&
!files[i]->ft->signal.channels; ++j)
files[i]->ft->signal.channels = user_efftab[j]->in_signal.channels;
@@ -2013,7 +2012,7 @@
static void usage_effect(char const * name)
{
- int i;
+ size_t i;
display_SoX_version(stdout);
putchar('\n');
@@ -2875,7 +2874,7 @@
signal(SIGINT, SIG_IGN); /* So child pipes aren't killed by track skip */
for (i = 0; i < input_count; i++) {
- int j = input_count - 1 - i; /* Open in reverse order 'cos of rec (below) */
+ size_t j = input_count - 1 - i; /* Open in reverse order 'cos of rec (below) */
file_t * f = files[j];
/* When mixing audio, default to input side volume adjustments that will
--- a/src/sox.h
+++ b/src/sox.h
@@ -1620,12 +1620,12 @@
*/
typedef struct sox_effects_chain_t {
sox_effect_t **effects; /**< Table of effects to be applied to a stream */
- unsigned length; /**< Number of effects to be applied */
+ size_t length; /**< Number of effects to be applied */
sox_effects_globals_t global_info; /**< Copy of global effects settings */
sox_encodinginfo_t const * in_enc; /**< Input encoding */
sox_encodinginfo_t const * out_enc; /**< Output encoding */
/* The following items are private to the libSoX effects chain functions. */
- unsigned table_size; /**< Size of effects table (including unused entries) */
+ size_t table_size; /**< Size of effects table (including unused entries) */
sox_sample_t **ibufc; /**< Channel interleave buffer */
sox_sample_t **obufc; /**< Channel interleave buffer */
} sox_effects_chain_t;