ref: 5add94edece948a9ac9fae9e9203744d6758df5c
parent: 04a526de3eeb7a2612b1a54648e07aee6bc16af5
author: robs <robs>
date: Tue May 27 02:37:20 EDT 2008
a few clean-ups
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -3,7 +3,7 @@
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(CMAKE_COMPILER_IS_GNUCC)
- #add_definitions(-Wconversion -Werror)
+ add_definitions(-Wconversion -Werror)
#add_definitions(-Wno-missing-field-initializers)
endif(CMAKE_COMPILER_IS_GNUCC)
@@ -46,8 +46,8 @@
add_library(lib${PROJECT_NAME}
effects formats_i ${optional_srcs}
effects_i ${formats_srcs} soxstdint
- ${effects_srcs} libsox xmalloc
- formats libsox_i
+ ${effects_srcs} libsox util
+ formats libsox_i xmalloc
)
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.c getopt getopt1)
target_link_libraries(${PROJECT_NAME} lib${PROJECT_NAME} lpc10 ${optional_libs})
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -239,7 +239,7 @@
g711.c g711.h g721.c g723_24.c g723_40.c g72x.c g72x.h vox.c vox.h \
raw.c raw.h formats.c formats.h formats_i.c sox_i.h skelform.c \
xmalloc.c xmalloc.h getopt.c getopt1.c getopt.h \
- soxconfig.h util.h libsox.c libsox_i.c
+ soxconfig.h util.c util.h libsox.c libsox_i.c
libsox_la_CFLAGS =
if HAVE_LIBLTDL
--- a/src/example0.c
+++ b/src/example0.c
@@ -53,7 +53,7 @@
chain = sox_create_effects_chain(&in->encoding, &out->encoding);
/* The first effect in the effect chain must be something that can source
- * samples; in this case, we have defined an input handler that inputs
+ * samples; in this case, we use the built-in handler that inputs
* data from an audio file */
e = sox_create_effect(sox_find_effect("input"));
args[0] = (char *)in, assert(e->handler.getopts(e, 1, args) == SOX_SUCCESS);
@@ -73,7 +73,7 @@
assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
/* The last effect in the effect chain must be something that only consumes
- * samples; in this case, we have defined an output handler that outputs
+ * samples; in this case, we use the built-in handler that outputs
* data to an audio file */
e = sox_create_effect(sox_find_effect("output"));
args[0] = (char *)out, assert(e->handler.getopts(e, 1, args) == SOX_SUCCESS);
--- a/src/fifo.h
+++ b/src/fifo.h
@@ -20,6 +20,10 @@
#include <string.h>
+#ifndef FIFO_SIZE_T
+#define FIFO_SIZE_T size_t
+#endif
+
typedef struct {
char * data;
size_t allocation; /* Number of bytes allocated for data. */
@@ -35,7 +39,7 @@
f->end = f->begin = 0;
}
-UNUSED static void * fifo_reserve(fifo_t * f, size_t n)
+UNUSED static void * fifo_reserve(fifo_t * f, FIFO_SIZE_T n)
{
n *= f->item_size;
@@ -60,7 +64,7 @@
}
}
-UNUSED static void * fifo_write(fifo_t * f, size_t n, void const * data)
+UNUSED static void * fifo_write(fifo_t * f, FIFO_SIZE_T n, void const * data)
{
void * s = fifo_reserve(f, n);
if (data)
@@ -68,25 +72,31 @@
return s;
}
-UNUSED static void fifo_trim(fifo_t * f, size_t n)
+UNUSED static void fifo_trim_to(fifo_t * f, FIFO_SIZE_T n)
{
n *= f->item_size;
f->end = f->begin + n;
}
-UNUSED static size_t fifo_occupancy(fifo_t * f)
+UNUSED static void fifo_trim_by(fifo_t * f, FIFO_SIZE_T n)
{
+ n *= f->item_size;
+ f->end -= n;
+}
+
+UNUSED static FIFO_SIZE_T fifo_occupancy(fifo_t * f)
+{
return (f->end - f->begin) / f->item_size;
}
-UNUSED static void * fifo_read(fifo_t * f, size_t n, void * data)
+UNUSED static void * fifo_read(fifo_t * f, FIFO_SIZE_T n, void * data)
{
char * ret = f->data + f->begin;
n *= f->item_size;
- if (n > f->end - f->begin)
+ if (n > (FIFO_SIZE_T)(f->end - f->begin))
return NULL;
if (data)
- memcpy(data, ret, n);
+ memcpy(data, ret, (size_t)n);
f->begin += n;
return ret;
}
@@ -98,7 +108,7 @@
free(f->data);
}
-UNUSED static void fifo_create(fifo_t * f, size_t item_size)
+UNUSED static void fifo_create(fifo_t * f, FIFO_SIZE_T item_size)
{
f->item_size = item_size;
f->allocation = FIFO_MIN;
--- a/src/sox.c
+++ b/src/sox.c
@@ -599,34 +599,6 @@
return clips + mixing_clips + sox_effects_clips(&ofile_effects_chain);
}
-static char const * sigfigs3(sox_size_t number)
-{
- static char string[16][10];
- static unsigned n;
- unsigned a, b, c = 2;
- sprintf(string[n = (n+1) & 15], "%#.3g", (double)number);
- if (sscanf(string[n], "%u.%ue%u", &a, &b, &c) == 3)
- a = 100*a + b;
- switch (c%3) {
- case 0: sprintf(string[n], "%u.%02u%c", a/100,a%100, " kMGTPE"[c/3]); break;
- case 1: sprintf(string[n], "%u.%u%c" , a/10 ,a%10 , " kMGTPE"[c/3]); break;
- case 2: sprintf(string[n], "%u%c" , a , " kMGTPE"[c/3]); break;
- }
- return string[n];
-}
-
-static char const * sigfigs3p(double percentage)
-{
- static char string[16][10];
- static unsigned n;
- sprintf(string[n = (n+1) & 15], "%.1f%%", percentage);
- if (strlen(string[n]) < 5)
- sprintf(string[n], "%.2f%%", percentage);
- else if (strlen(string[n]) > 5)
- sprintf(string[n], "%.0f%%", percentage);
- return string[n];
-}
-
static sox_bool since(struct timeval * then, double secs, sox_bool always_reset)
{
sox_bool ret;
--- a/src/tempo.c
+++ b/src/tempo.c
@@ -157,7 +157,7 @@
tempo_input(t, buff, 128);
tempo_process(t);
}
- fifo_trim(&t->output_fifo, remaining);
+ fifo_trim_to(&t->output_fifo, remaining);
t->samples_in = 0;
}
free(buff);
--- /dev/null
+++ b/src/util.c
@@ -1,0 +1,72 @@
+/* General purpose, i.e. non SoX specific, utility functions.
+ * Copyright (c) 2007-8 robs@users.sourceforge.net
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at
+ * your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "util.h"
+#include <stdio.h>
+
+enum_item const * find_enum_text(char const * text, enum_item const * enum_items)
+{
+ enum_item const * result = NULL; /* Assume not found */
+
+ while (enum_items->text) {
+ if (strncasecmp(text, enum_items->text, strlen(text)) == 0) {
+ if (result != NULL && result->value != enum_items->value)
+ return NULL; /* Found ambiguity */
+ result = enum_items; /* Found match */
+ }
+ ++enum_items;
+ }
+ return result;
+}
+
+enum_item const * find_enum_value(unsigned value, enum_item const * enum_items)
+{
+ for (;enum_items->text; ++enum_items)
+ if (value == enum_items->value)
+ return enum_items;
+ return NULL;
+}
+
+char const * sigfigs3(size_t number)
+{
+ static char string[16][10];
+ static unsigned n;
+ unsigned a, b, c = 2;
+ sprintf(string[n = (n+1) & 15], "%#.3g", (double)number);
+ if (sscanf(string[n], "%u.%ue%u", &a, &b, &c) == 3)
+ a = 100*a + b;
+ switch (c%3) {
+ case 0: sprintf(string[n], "%u.%02u%c", a/100,a%100, " kMGTPE"[c/3]); break;
+ case 1: sprintf(string[n], "%u.%u%c" , a/10 ,a%10 , " kMGTPE"[c/3]); break;
+ case 2: sprintf(string[n], "%u%c" , a , " kMGTPE"[c/3]); break;
+ }
+ return string[n];
+}
+
+char const * sigfigs3p(double percentage)
+{
+ static char string[16][10];
+ static unsigned n;
+ sprintf(string[n = (n+1) & 15], "%.1f%%", percentage);
+ if (strlen(string[n]) < 5)
+ sprintf(string[n], "%.2f%%", percentage);
+ else if (strlen(string[n]) > 5)
+ sprintf(string[n], "%.0f%%", percentage);
+ return string[n];
+}
+
--- a/src/util.h
+++ b/src/util.h
@@ -1,4 +1,4 @@
-/* General purpose, i.e. non SoX specific, utility functions and macros
+/* General purpose, i.e. non SoX specific, utility functions and macros.
*
* (c) 2006-8 Chris Bagwell and SoX contributors
*
@@ -100,25 +100,7 @@
typedef struct {char const *text; unsigned value;} enum_item;
#define ENUM_ITEM(prefix, item) {#item, prefix##item},
-UNUSED static enum_item const * find_enum_text(char const * text, enum_item const * enum_items)
-{
- enum_item const * result = NULL; /* Assume not found */
-
- while (enum_items->text) {
- if (strncasecmp(text, enum_items->text, strlen(text)) == 0) {
- if (result != NULL && result->value != enum_items->value)
- return NULL; /* Found ambiguity */
- result = enum_items; /* Found match */
- }
- ++enum_items;
- }
- return result;
-}
-
-UNUSED static enum_item const * find_enum_value(unsigned value, enum_item const * enum_items)
-{
- for (;enum_items->text; ++enum_items)
- if (value == enum_items->value)
- return enum_items;
- return NULL;
-}
+enum_item const * find_enum_text(char const * text, enum_item const * enum_items);
+enum_item const * find_enum_value(unsigned value, enum_item const * enum_items);
+char const * sigfigs3(size_t number);
+char const * sigfigs3p(double percentage);