diff options
author | Sakari Bergen <sakari.bergen@beatwaves.net> | 2010-03-15 19:11:48 +0000 |
---|---|---|
committer | Sakari Bergen <sakari.bergen@beatwaves.net> | 2010-03-15 19:11:48 +0000 |
commit | 830911f6f9451d83a58043b3f9084d3caa164b7b (patch) | |
tree | f4ca4e3d86b51d66e7cecfb6b370cc4eb553e2d7 /libs/audiographer/src | |
parent | 44f4b84551d36ef4103d09452768f5ba53e0002c (diff) |
Fix export, which has been broken since the boost::signals2 changes. Also update Audiographer, bacause of its incomplete sndfile handling. Audiographer is equal to revision 74
git-svn-id: svn://localhost/ardour2/branches/3.0@6760 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/audiographer/src')
-rw-r--r-- | libs/audiographer/src/debug_utils.cc | 26 | ||||
-rw-r--r-- | libs/audiographer/src/gdither/gdither.cc | 474 | ||||
-rw-r--r-- | libs/audiographer/src/gdither/gdither.h | 92 | ||||
-rw-r--r-- | libs/audiographer/src/gdither/gdither_types.h | 48 | ||||
-rw-r--r-- | libs/audiographer/src/gdither/gdither_types_internal.h | 74 | ||||
-rw-r--r-- | libs/audiographer/src/gdither/noise.h | 38 | ||||
-rw-r--r-- | libs/audiographer/src/general/sample_format_converter.cc (renamed from libs/audiographer/src/sample_format_converter.cc) | 55 | ||||
-rw-r--r-- | libs/audiographer/src/general/sr_converter.cc (renamed from libs/audiographer/src/sr_converter.cc) | 14 | ||||
-rw-r--r-- | libs/audiographer/src/sndfile_base.cc | 56 | ||||
-rw-r--r-- | libs/audiographer/src/sndfile_reader.cc | 68 | ||||
-rw-r--r-- | libs/audiographer/src/sndfile_writer.cc | 74 | ||||
-rw-r--r-- | libs/audiographer/src/utils.cc | 14 |
12 files changed, 62 insertions, 971 deletions
diff --git a/libs/audiographer/src/debug_utils.cc b/libs/audiographer/src/debug_utils.cc new file mode 100644 index 0000000000..352c549f06 --- /dev/null +++ b/libs/audiographer/src/debug_utils.cc @@ -0,0 +1,26 @@ +#include "audiographer/debug_utils.h" + +#include "audiographer/process_context.h" + +#include <sstream> + +namespace AudioGrapher { + +std::string +DebugUtils::process_context_flag_name (FlagField::Flag flag) +{ + std::ostringstream ret; + + switch (flag) { + case ProcessContext<>::EndOfInput: + ret << "EndOfInput"; + break; + default: + ret << flag; + break; + } + + return ret.str(); +} + +} // namespace
\ No newline at end of file diff --git a/libs/audiographer/src/gdither/gdither.cc b/libs/audiographer/src/gdither/gdither.cc deleted file mode 100644 index 966da47b06..0000000000 --- a/libs/audiographer/src/gdither/gdither.cc +++ /dev/null @@ -1,474 +0,0 @@ -/* - * Copyright (C) 2002 Steve Harris <steve@plugin.org.uk> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include "gdither_types_internal.h" -#include "gdither.h" -#include "noise.h" - -/* this monstrosity is necessary to get access to lrintf() and random(). - whoever is writing the glibc headers <cmath> and <cstdlib> should be - hauled off to a programmer re-education camp. for the rest of - their natural lives. or longer. <paul@linuxaudiosystems.com> -*/ - -#define _ISOC9X_SOURCE 1 -#define _ISOC99_SOURCE 1 -#ifdef __cplusplus -#include <cmath> -#else -#include <math.h> -#endif - -#undef __USE_SVID -#define __USE_SVID 1 -#ifdef __cplusplus -#include <cstdlib> -#else -#include <stdlib.h> -#endif - -#include <sys/types.h> - -/* Lipshitz's minimally audible FIR, only really works for 46kHz-ish signals */ -static const float shaped_bs[] = { 2.033f, -2.165f, 1.959f, -1.590f, 0.6149f }; - -/* Some useful constants */ -#define MAX_U8 255 -#define MIN_U8 0 -#define SCALE_U8 128.0f - -#define MAX_S16 32767 -#define MIN_S16 -32768 -#define SCALE_S16 32768.0f - -#define MAX_S24 8388607 -#define MIN_S24 -8388608 -#define SCALE_S24 8388608.0f - -GDither gdither_new(GDitherType type, uint32_t channels, - - GDitherSize bit_depth, int dither_depth) -{ - GDither s; - - s = (GDither)calloc(1, sizeof(struct GDither_s)); - s->type = type; - s->channels = channels; - s->bit_depth = (int)bit_depth; - - if (dither_depth <= 0 || dither_depth > (int)bit_depth) { - dither_depth = (int)bit_depth; - } - s->dither_depth = dither_depth; - - s->scale = (float)(1LL << (dither_depth - 1)); - if (bit_depth == GDitherFloat || bit_depth == GDitherDouble) { - s->post_scale_fp = 1.0f / s->scale; - s->post_scale = 0; - } else { - s->post_scale_fp = 0.0f; - s->post_scale = 1 << ((int)bit_depth - dither_depth); - } - - switch (bit_depth) { - case GDither8bit: - /* Unsigned 8 bit */ - s->bias = 1.0f; - s->clamp_u = 255; - s->clamp_l = 0; - break; - case GDither16bit: - /* Signed 16 bit */ - s->bias = 0.0f; - s->clamp_u = 32767; - s->clamp_l = -32768; - break; - case GDither32bit: - /* Signed 24 bit, in upper 24 bits of 32 bit word */ - s->bias = 0.0f; - s->clamp_u = 8388607; - s->clamp_l = -8388608; - break; - case GDitherFloat: - /* normalised float */ - s->bias = 0.0f; - s->clamp_u = lrintf(s->scale); - s->clamp_l = lrintf(-s->scale); - break; - case GDitherDouble: - /* normalised float */ - s->bias = 0.0f; - s->clamp_u = lrintf(s->scale); - s->clamp_l = lrintf(-s->scale); - break; - case 23: - /* special performance test case */ - s->scale = SCALE_S24; - s->post_scale = 256; - s->bias = 0.0f; - s->clamp_u = 8388607; - s->clamp_l = -8388608; - break; - default: - /* Not a bit depth we can handle */ - free(s); - - return NULL; - break; - } - - switch (type) { - case GDitherNone: - case GDitherRect: - /* No state */ - break; - - case GDitherTri: - /* The last whitenoise sample */ - s->tri_state = (float *) calloc(channels, sizeof(float)); - break; - - case GDitherShaped: - /* The error from the last few samples encoded */ - s->shaped_state = (GDitherShapedState*) - calloc(channels, sizeof(GDitherShapedState)); - break; - } - - return s; -} - -void gdither_free(GDither s) -{ - if (s) { - free(s->tri_state); - free(s->shaped_state); - free(s); - } -} - -inline static void gdither_innner_loop(const GDitherType dt, - const uint32_t stride, const float bias, const float scale, - - const uint32_t post_scale, const int bit_depth, - const uint32_t channel, const uint32_t length, float *ts, - - GDitherShapedState *ss, float const *x, void *y, const int clamp_u, - - const int clamp_l) -{ - uint32_t pos, i; - uint8_t *o8 = (uint8_t*) y; - int16_t *o16 = (int16_t*) y; - int32_t *o32 = (int32_t*) y; - float tmp, r, ideal; - int64_t clamped; - - i = channel; - for (pos = 0; pos < length; pos++, i += stride) { - tmp = x[i] * scale + bias; - - switch (dt) { - case GDitherNone: - break; - case GDitherRect: - tmp -= GDITHER_NOISE; - break; - case GDitherTri: - r = GDITHER_NOISE - 0.5f; - tmp -= r - ts[channel]; - ts[channel] = r; - break; - case GDitherShaped: - /* Save raw value for error calculations */ - ideal = tmp; - - /* Run FIR and add white noise */ - ss->buffer[ss->phase] = GDITHER_NOISE * 0.5f; - tmp += ss->buffer[ss->phase] * shaped_bs[0] - + ss->buffer[(ss->phase - 1) & GDITHER_SH_BUF_MASK] - * shaped_bs[1] - + ss->buffer[(ss->phase - 2) & GDITHER_SH_BUF_MASK] - * shaped_bs[2] - + ss->buffer[(ss->phase - 3) & GDITHER_SH_BUF_MASK] - * shaped_bs[3] - + ss->buffer[(ss->phase - 4) & GDITHER_SH_BUF_MASK] - * shaped_bs[4]; - - /* Roll buffer and store last error */ - ss->phase = (ss->phase + 1) & GDITHER_SH_BUF_MASK; - ss->buffer[ss->phase] = (float)lrintf(tmp) - ideal; - break; - } - - clamped = lrintf(tmp); - if (clamped > clamp_u) { - clamped = clamp_u; - } else if (clamped < clamp_l) { - clamped = clamp_l; - } - - switch (bit_depth) { - case GDither8bit: - o8[i] = (u_int8_t) (clamped * post_scale); - break; - case GDither16bit: - o16[i] = (int16_t) (clamped * post_scale); - break; - case GDither32bit: - o32[i] = (int32_t) (clamped * post_scale); - break; - } - } -} - -/* floating pint version of the inner loop function */ -inline static void gdither_innner_loop_fp(const GDitherType dt, - const uint32_t stride, const float bias, const float scale, - - const float post_scale, const int bit_depth, - const uint32_t channel, const uint32_t length, float *ts, - - GDitherShapedState *ss, float const *x, void *y, const int clamp_u, - - const int clamp_l) -{ - uint32_t pos, i; - float *oflt = (float*) y; - double *odbl = (double*) y; - float tmp, r, ideal; - double clamped; - - i = channel; - for (pos = 0; pos < length; pos++, i += stride) { - tmp = x[i] * scale + bias; - - switch (dt) { - case GDitherNone: - break; - case GDitherRect: - tmp -= GDITHER_NOISE; - break; - case GDitherTri: - r = GDITHER_NOISE - 0.5f; - tmp -= r - ts[channel]; - ts[channel] = r; - break; - case GDitherShaped: - /* Save raw value for error calculations */ - ideal = tmp; - - /* Run FIR and add white noise */ - ss->buffer[ss->phase] = GDITHER_NOISE * 0.5f; - tmp += ss->buffer[ss->phase] * shaped_bs[0] - + ss->buffer[(ss->phase - 1) & GDITHER_SH_BUF_MASK] - * shaped_bs[1] - + ss->buffer[(ss->phase - 2) & GDITHER_SH_BUF_MASK] - * shaped_bs[2] - + ss->buffer[(ss->phase - 3) & GDITHER_SH_BUF_MASK] - * shaped_bs[3] - + ss->buffer[(ss->phase - 4) & GDITHER_SH_BUF_MASK] - * shaped_bs[4]; - - /* Roll buffer and store last error */ - ss->phase = (ss->phase + 1) & GDITHER_SH_BUF_MASK; - ss->buffer[ss->phase] = (float)lrintf(tmp) - ideal; - break; - } - - clamped = rintf(tmp); - if (clamped > clamp_u) { - clamped = clamp_u; - } else if (clamped < clamp_l) { - clamped = clamp_l; - } - - switch (bit_depth) { - case GDitherFloat: - oflt[i] = (float) (clamped * post_scale); - break; - case GDitherDouble: - odbl[i] = (double) (clamped * post_scale); - break; - } - } -} - -#define GDITHER_CONV_BLOCK 512 - -void gdither_run(GDither s, uint32_t channel, uint32_t length, - double const *x, void *y) -{ - float conv[GDITHER_CONV_BLOCK]; - uint32_t i, pos; - char *ycast = (char *)y; - - int step; - - switch (s->bit_depth) { - case GDither8bit: - step = 1; - break; - case GDither16bit: - step = 2; - break; - case GDither32bit: - case GDitherFloat: - step = 4; - break; - case GDitherDouble: - step = 8; - break; - default: - step = 0; - break; - } - - pos = 0; - while (pos < length) { - for (i=0; (i + pos) < length && i < GDITHER_CONV_BLOCK; i++) { - conv[i] = x[pos + i]; - } - gdither_runf(s, channel, i, conv, ycast + s->channels * step); - pos += i; - } -} - -void gdither_runf(GDither s, uint32_t channel, uint32_t length, - float const *x, void *y) -{ - uint32_t pos, i; - float tmp; - int64_t clamped; - GDitherShapedState *ss = NULL; - - if (!s || channel >= s->channels) { - return; - } - - if (s->shaped_state) { - ss = s->shaped_state + channel; - } - - if (s->type == GDitherNone && s->bit_depth == 23) { - int32_t *o32 = (int32_t*) y; - - for (pos = 0; pos < length; pos++) { - i = channel + (pos * s->channels); - tmp = x[i] * 8388608.0f; - - clamped = lrintf(tmp); - if (clamped > 8388607) { - clamped = 8388607; - } else if (clamped < -8388608) { - clamped = -8388608; - } - - o32[i] = (int32_t) (clamped * 256); - } - - return; - } - - /* some common case handling code - looks a bit wierd, but it allows - * the compiler to optimise out the branches in the inner loop */ - if (s->bit_depth == 8 && s->dither_depth == 8) { - switch (s->type) { - case GDitherNone: - gdither_innner_loop(GDitherNone, s->channels, 128.0f, SCALE_U8, - 1, 8, channel, length, NULL, NULL, x, y, - MAX_U8, MIN_U8); - break; - case GDitherRect: - gdither_innner_loop(GDitherRect, s->channels, 128.0f, SCALE_U8, - 1, 8, channel, length, NULL, NULL, x, y, - MAX_U8, MIN_U8); - break; - case GDitherTri: - gdither_innner_loop(GDitherTri, s->channels, 128.0f, SCALE_U8, - 1, 8, channel, length, s->tri_state, - NULL, x, y, MAX_U8, MIN_U8); - break; - case GDitherShaped: - gdither_innner_loop(GDitherShaped, s->channels, 128.0f, SCALE_U8, - 1, 8, channel, length, NULL, - ss, x, y, MAX_U8, MIN_U8); - break; - } - } else if (s->bit_depth == 16 && s->dither_depth == 16) { - switch (s->type) { - case GDitherNone: - gdither_innner_loop(GDitherNone, s->channels, 0.0f, SCALE_S16, - 1, 16, channel, length, NULL, NULL, x, y, - MAX_S16, MIN_S16); - break; - case GDitherRect: - gdither_innner_loop(GDitherRect, s->channels, 0.0f, SCALE_S16, - 1, 16, channel, length, NULL, NULL, x, y, - MAX_S16, MIN_S16); - break; - case GDitherTri: - gdither_innner_loop(GDitherTri, s->channels, 0.0f, SCALE_S16, - 1, 16, channel, length, s->tri_state, - NULL, x, y, MAX_S16, MIN_S16); - break; - case GDitherShaped: - gdither_innner_loop(GDitherShaped, s->channels, 0.0f, - SCALE_S16, 1, 16, channel, length, NULL, - ss, x, y, MAX_S16, MIN_S16); - break; - } - } else if (s->bit_depth == 32 && s->dither_depth == 24) { - switch (s->type) { - case GDitherNone: - gdither_innner_loop(GDitherNone, s->channels, 0.0f, SCALE_S24, - 256, 32, channel, length, NULL, NULL, x, - y, MAX_S24, MIN_S24); - break; - case GDitherRect: - gdither_innner_loop(GDitherRect, s->channels, 0.0f, SCALE_S24, - 256, 32, channel, length, NULL, NULL, x, - y, MAX_S24, MIN_S24); - break; - case GDitherTri: - gdither_innner_loop(GDitherTri, s->channels, 0.0f, SCALE_S24, - 256, 32, channel, length, s->tri_state, - NULL, x, y, MAX_S24, MIN_S24); - break; - case GDitherShaped: - gdither_innner_loop(GDitherShaped, s->channels, 0.0f, SCALE_S24, - 256, 32, channel, length, - NULL, ss, x, y, MAX_S24, MIN_S24); - break; - } - } else if (s->bit_depth == GDitherFloat || s->bit_depth == GDitherDouble) { - gdither_innner_loop_fp(s->type, s->channels, s->bias, s->scale, - s->post_scale_fp, s->bit_depth, channel, length, - s->tri_state, ss, x, y, s->clamp_u, s->clamp_l); - } else { - /* no special case handling, just process it from the struct */ - - gdither_innner_loop(s->type, s->channels, s->bias, s->scale, - s->post_scale, s->bit_depth, channel, - length, s->tri_state, ss, x, y, s->clamp_u, - s->clamp_l); - } -} - -/* vi:set ts=8 sts=4 sw=4: */ diff --git a/libs/audiographer/src/gdither/gdither.h b/libs/audiographer/src/gdither/gdither.h deleted file mode 100644 index d2b2657f32..0000000000 --- a/libs/audiographer/src/gdither/gdither.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2002 Steve Harris <steve@plugin.org.uk> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#ifndef GDITHER_H -#define GDITHER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "gdither_types.h" - -/* Create and initialise a state structure, takes a dither type, a number of - * channels and a bit depth as input - * - * The Dither type is one of - * - * GDitherNone - straight nearest neighbour rounding. Theres no pressing - * reason to do this at 8 or 16 bit, but you might want to at 24, for some - * reason. At the lest it will save you writing int->float conversion code, - * which is arder than it sounds. - * - * GDitherRect - mathematically most accurate, lowest noise floor, but not - * that good for audio. It is the fastest though. - * - * GDitherTri - a happy medium between Rectangular and Shaped, reasonable - * noise floor, not too obvious, quite fast. - * - * GDitherShaped - should have the least audible impact, but has the highest - * noise floor, fairly CPU intensive. Not advisible if your going to apply - * any frequency manipulation afterwards. - * - * channels, sets the number of channels in the output data, output data will - * be written interleaved into the area given to gdither_run(). Set to 1 - * if you are not working with interleaved buffers. - * - * bit depth, sets the bit width of the output sample data, it can be one of: - * - * GDither8bit - 8 bit unsiged - * GDither16bit - 16 bit signed - * GDither32bit - 24+bits in upper bits of a 32 bit word - * GDitherFloat - IEEE floating point (32bits) - * GDitherDouble - Double precision IEEE floating point (64bits) - * - * dither_depth, set the number of bits before the signal will be truncated to, - * eg. 16 will produce an output stream with 16bits-worth of signal. Setting to - * zero or greater than the width of the output format will dither to the - * maximum precision allowed by the output format. - */ -GDither gdither_new(GDitherType type, uint32_t channels, - - GDitherSize bit_depth, int dither_depth); - -/* Frees memory used by gdither_new. - */ -void gdither_free(GDither s); - -/* Applies dithering to the supplied signal. - * - * channel is the channel number you are processing (0 - channles-1), length is - * the length of the input, in samples, x is the input samples (float), y is - * where the output samples will be written, it should have the approaprate - * type for the chosen bit depth - */ -void gdither_runf(GDither s, uint32_t channel, uint32_t length, - float const *x, void *y); - -/* see gdither_runf, vut input argument is double format */ -void gdither_run(GDither s, uint32_t channel, uint32_t length, - double const *x, void *y); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libs/audiographer/src/gdither/gdither_types.h b/libs/audiographer/src/gdither/gdither_types.h deleted file mode 100644 index bcc0097d7f..0000000000 --- a/libs/audiographer/src/gdither/gdither_types.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2002 Steve Harris <steve@plugin.org.uk> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#ifndef GDITHER_TYPES_H -#define GDITHER_TYPES_H - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - GDitherNone = 0, - GDitherRect, - GDitherTri, - GDitherShaped -} GDitherType; - -typedef enum { - GDither8bit = 8, - GDither16bit = 16, - GDither32bit = 32, - GDitherFloat = 25, - GDitherDouble = 54 -} GDitherSize; - -typedef void *GDither; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libs/audiographer/src/gdither/gdither_types_internal.h b/libs/audiographer/src/gdither/gdither_types_internal.h deleted file mode 100644 index 6cb0c48af9..0000000000 --- a/libs/audiographer/src/gdither/gdither_types_internal.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2002 Steve Harris <steve@plugin.org.uk> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#ifndef GDITHER_TYPES_H -#define GDITHER_TYPES_H - -#include <stdint.h> - -#ifdef __cplusplus -extern "C" { -#endif - -#define GDITHER_SH_BUF_SIZE 8 -#define GDITHER_SH_BUF_MASK 7 - -/* this must agree with whats in gdither_types.h */ -typedef enum { - GDitherNone = 0, - GDitherRect, - GDitherTri, - GDitherShaped -} GDitherType; - -typedef enum { - GDither8bit = 8, - GDither16bit = 16, - GDither32bit = 32, - GDitherFloat = 25, - GDitherDouble = 54 -} GDitherSize; - -typedef struct { - uint32_t phase; - float buffer[GDITHER_SH_BUF_SIZE]; -} GDitherShapedState; - -typedef struct GDither_s { - GDitherType type; - uint32_t channels; - uint32_t bit_depth; - uint32_t dither_depth; - float scale; - uint32_t post_scale; - float post_scale_fp; - float bias; - - int clamp_u; - - int clamp_l; - float *tri_state; - GDitherShapedState *shaped_state; -} *GDither; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libs/audiographer/src/gdither/noise.h b/libs/audiographer/src/gdither/noise.h deleted file mode 100644 index 96a582ef9b..0000000000 --- a/libs/audiographer/src/gdither/noise.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright (C) 2000-2007 Paul Davis - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef NOISE_H -#define NOISE_H - -/* Can be overrriden with any code that produces whitenoise between 0.0f and - * 1.0f, eg (random() / (float)RAND_MAX) should be a good source of noise, but - * its expensive */ -#ifndef GDITHER_NOISE -#define GDITHER_NOISE gdither_noise() -#endif - -inline static float gdither_noise() -{ - static uint32_t rnd = 23232323; - rnd = (rnd * 196314165) + 907633515; - - return rnd * 2.3283064365387e-10f; -} - -#endif diff --git a/libs/audiographer/src/sample_format_converter.cc b/libs/audiographer/src/general/sample_format_converter.cc index 5b2d3d6e8c..5f63fe9f2f 100644 --- a/libs/audiographer/src/sample_format_converter.cc +++ b/libs/audiographer/src/general/sample_format_converter.cc @@ -1,17 +1,16 @@ -#include "audiographer/sample_format_converter.h" +#include "audiographer/general/sample_format_converter.h" -#include "gdither/gdither.h" #include "audiographer/exception.h" +#include "audiographer/type_utils.h" +#include "private/gdither/gdither.h" #include <boost/format.hpp> -#include <cstring> - namespace AudioGrapher { template <typename TOut> -SampleFormatConverter<TOut>::SampleFormatConverter (uint32_t channels) : +SampleFormatConverter<TOut>::SampleFormatConverter (ChannelCount channels) : channels (channels), dither (0), data_out_size (0), @@ -24,7 +23,9 @@ template <> void SampleFormatConverter<float>::init (nframes_t max_frames, int type, int data_width) { - if (data_width != 32) { throw Exception (*this, "Unsupported data width"); } + if (throw_level (ThrowObject) && data_width != 32) { + throw Exception (*this, "Unsupported data width"); + } init_common (max_frames); dither = gdither_new (GDitherNone, channels, GDitherFloat, data_width); } @@ -33,7 +34,9 @@ template <> void SampleFormatConverter<int32_t>::init (nframes_t max_frames, int type, int data_width) { - if(data_width < 24) { throw Exception (*this, "Use SampleFormatConverter<int16_t> for data widths < 24"); } + if(throw_level (ThrowObject) && data_width < 24) { + throw Exception (*this, "Trying to use SampleFormatConverter<int32_t> for data widths < 24"); + } init_common (max_frames); @@ -41,7 +44,7 @@ SampleFormatConverter<int32_t>::init (nframes_t max_frames, int type, int data_w dither = gdither_new ((GDitherType) type, channels, GDither32bit, data_width); } else if (data_width == 32) { dither = gdither_new (GDitherNone, channels, GDitherFloat, data_width); - } else { + } else if (throw_level (ThrowObject)) { throw Exception (*this, "Unsupported data width"); } } @@ -50,7 +53,9 @@ template <> void SampleFormatConverter<int16_t>::init (nframes_t max_frames, int type, int data_width) { - if (data_width != 16) { throw Exception (*this, "Unsupported data width"); } + if (throw_level (ThrowObject) && data_width != 16) { + throw Exception (*this, "Unsupported data width"); + } init_common (max_frames); dither = gdither_new ((GDitherType) type, channels, GDither16bit, data_width); } @@ -59,7 +64,9 @@ template <> void SampleFormatConverter<uint8_t>::init (nframes_t max_frames, int type, int data_width) { - if (data_width != 8) { throw Exception (*this, "Unsupported data width"); } + if (throw_level (ThrowObject) && data_width != 8) { + throw Exception (*this, "Unsupported data width"); + } init_common (max_frames); dither = gdither_new ((GDitherType) type, channels, GDither8bit, data_width); } @@ -106,14 +113,13 @@ void SampleFormatConverter<TOut>::process (ProcessContext<float> const & c_in) { float const * const data = c_in.data(); - nframes_t const frames = c_in.frames(); - check_frame_count (frames); + check_frame_and_channel_count (c_in.frames (), c_in.channels ()); /* Do conversion */ - for (uint32_t chn = 0; chn < channels; ++chn) { - gdither_runf (dither, chn, frames / channels, data, data_out); + for (uint32_t chn = 0; chn < c_in.channels(); ++chn) { + gdither_runf (dither, chn, c_in.frames_per_channel (), data, data_out); } /* Write forward */ @@ -157,9 +163,8 @@ void SampleFormatConverter<float>::process (ProcessContext<float> const & c_in) { // Make copy of data and pass it to non-const version - nframes_t frames = c_in.frames(); - check_frame_count (frames); - memcpy (data_out, c_in.data(), frames * sizeof(float)); + check_frame_and_channel_count (c_in.frames(), c_in.channels()); + TypeUtils<float>::copy (c_in.data(), data_out, c_in.frames()); ProcessContext<float> c (c_in, data_out); process (c); @@ -167,17 +172,17 @@ SampleFormatConverter<float>::process (ProcessContext<float> const & c_in) template<typename TOut> void -SampleFormatConverter<TOut>::check_frame_count(nframes_t frames) +SampleFormatConverter<TOut>::check_frame_and_channel_count(nframes_t frames, ChannelCount channels_) { - if (frames % channels != 0) { - throw Exception (*this, boost::str (boost::format ( - "Number of frames given to process() was not a multiple of channels: %1% frames with %2% channels") - % frames % channels)); + if (throw_level (ThrowStrict) && channels_ != channels) { + throw Exception (*this, boost::str (boost::format + ("Wrong channel count given to process(), %1% instead of %2%") + % channels_ % channels)); } - if (frames > data_out_size) { - throw Exception (*this, boost::str (boost::format ( - "Too many frames given to process(), %1% instad of %2%") + if (throw_level (ThrowProcess) && frames > data_out_size) { + throw Exception (*this, boost::str (boost::format + ("Too many frames given to process(), %1% instad of %2%") % frames % data_out_size)); } } diff --git a/libs/audiographer/src/sr_converter.cc b/libs/audiographer/src/general/sr_converter.cc index c62fd719e8..1fe51742a0 100644 --- a/libs/audiographer/src/sr_converter.cc +++ b/libs/audiographer/src/general/sr_converter.cc @@ -1,4 +1,5 @@ -#include "audiographer/sr_converter.h" +#include "audiographer/general/sr_converter.h" + #include "audiographer/exception.h" #include "audiographer/type_utils.h" @@ -21,6 +22,7 @@ SampleRateConverter::SampleRateConverter (uint32_t channels) , data_out_size (0) , src_state (0) { + add_supported_flag (ProcessContext<>::EndOfInput); } void @@ -78,6 +80,8 @@ SampleRateConverter::allocate_buffers (nframes_t max_frames) void SampleRateConverter::process (ProcessContext<float> const & c) { + check_flags (*this, c); + if (!active) { output (c); return; @@ -86,17 +90,11 @@ SampleRateConverter::process (ProcessContext<float> const & c) nframes_t frames = c.frames(); float * in = const_cast<float *> (c.data()); // TODO check if this is safe! - if (throw_level (ThrowStrict) && frames > max_frames_in) { + if (throw_level (ThrowProcess) && frames > max_frames_in) { throw Exception (*this, str (format ( "process() called with too many frames, %1% instead of %2%") % frames % max_frames_in)); } - - if (throw_level (ThrowStrict) && frames % channels != 0) { - throw Exception (*this, boost::str (boost::format ( - "Number of frames given to process() was not a multiple of channels: %1% frames with %2% channels") - % frames % channels)); - } int err; bool first_time = true; diff --git a/libs/audiographer/src/sndfile_base.cc b/libs/audiographer/src/sndfile_base.cc deleted file mode 100644 index 8d12f9341b..0000000000 --- a/libs/audiographer/src/sndfile_base.cc +++ /dev/null @@ -1,56 +0,0 @@ -#include "audiographer/sndfile_base.h" -#include "audiographer/exception.h" - -#include <boost/format.hpp> - -namespace AudioGrapher -{ - -using std::string; -using boost::str; -using boost::format; - -/* SndfileWriterBase */ - -SndfileBase::SndfileBase (ChannelCount channels, nframes_t samplerate, int format, string const & path) - : path (path) -{ - char errbuf[256]; - - sf_info.channels = channels; - sf_info.samplerate = samplerate; - sf_info.format = format; - - if (!sf_format_check (&sf_info)) { - throw Exception (*this, "Invalid format in constructor"); - } - - if (path.length() == 0) { - throw Exception (*this, "No output file specified"); - } - - /* TODO add checks that the directory path exists, and also - check if we are overwriting an existing file... - */ - - // Open file - if (path.compare ("temp")) { - if ((sndfile = sf_open (path.c_str(), SFM_WRITE, &sf_info)) == 0) { - sf_error_str (0, errbuf, sizeof (errbuf) - 1); - throw Exception (*this, str (boost::format ("Cannot open output file \"%1%\" (%2%)") % path % errbuf)); - } - } else { - FILE * file; - if (!(file = tmpfile ())) { - throw Exception (*this, "Cannot open tempfile"); - } - sndfile = sf_open_fd (fileno(file), SFM_RDWR, &sf_info, true); - } -} - -SndfileBase::~SndfileBase () -{ - sf_close (sndfile); -} - -} // namespace diff --git a/libs/audiographer/src/sndfile_reader.cc b/libs/audiographer/src/sndfile_reader.cc deleted file mode 100644 index 8297844721..0000000000 --- a/libs/audiographer/src/sndfile_reader.cc +++ /dev/null @@ -1,68 +0,0 @@ -#include "audiographer/sndfile_reader.h" - -#include <boost/format.hpp> - -#include "audiographer/exception.h" - -namespace AudioGrapher -{ - -template<typename T> -SndfileReader<T>::SndfileReader (ChannelCount channels, nframes_t samplerate, int format, std::string path) - : SndfileBase (channels, samplerate, format, path) -{ - init (); -} - -template<typename T> -nframes_t -SndfileReader<T>::seek (nframes_t frames, SeekType whence) -{ - return sf_seek (sndfile, frames, whence); -} - -template<typename T> -nframes_t -SndfileReader<T>::read (ProcessContext<T> & context) -{ - if (context.channels() != sf_info.channels) { - throw Exception (*this, boost::str (boost::format ( - "ProcessContext given to read() has a wrong amount of channels: %1% instead of %2%") - % context.channels() % sf_info.channels)); - } - - nframes_t frames_read = (*read_func) (sndfile, context.data(), context.frames()); - if (frames_read < context.frames()) { - context.frames() = frames_read; - context.set_flag (ProcessContext<T>::EndOfInput); - } - output (context); - return frames_read; -} - -template<> -void -SndfileReader<short>::init() -{ - read_func = &sf_read_short; -} - -template<> -void -SndfileReader<int>::init() -{ - read_func = &sf_read_int; -} - -template<> -void -SndfileReader<float>::init() -{ - read_func = &sf_read_float; -} - -template class SndfileReader<short>; -template class SndfileReader<int>; -template class SndfileReader<float>; - -} // namespace
\ No newline at end of file diff --git a/libs/audiographer/src/sndfile_writer.cc b/libs/audiographer/src/sndfile_writer.cc deleted file mode 100644 index f8c9ea63b5..0000000000 --- a/libs/audiographer/src/sndfile_writer.cc +++ /dev/null @@ -1,74 +0,0 @@ -#include "audiographer/sndfile_writer.h" -#include "audiographer/exception.h" - -#include <cstring> - -#include <boost/format.hpp> - -namespace AudioGrapher -{ - -using std::string; -using boost::str; -using boost::format; - -template <typename T> -SndfileWriter<T>::SndfileWriter (ChannelCount channels, nframes_t samplerate, int format, string const & path) : - SndfileBase (channels, samplerate, format, path) -{ - // init write function - init (); -} - -template <> -void -SndfileWriter<float>::init () -{ - write_func = &sf_write_float; -} - -template <> -void -SndfileWriter<int>::init () -{ - write_func = &sf_write_int; -} - -template <> -void -SndfileWriter<short>::init () -{ - write_func = &sf_write_short; -} - -template <typename T> -void -SndfileWriter<T>::process (ProcessContext<T> const & c) -{ - if (c.channels() != sf_info.channels) { - throw Exception (*this, str (boost::format( - "Wrong number of channels given to process(), %1% instead of %2%") - % c.channels() % sf_info.channels)); - } - - char errbuf[256]; - nframes_t written = (*write_func) (sndfile, c.data(), c.frames()); - if (written != c.frames()) { - sf_error_str (sndfile, errbuf, sizeof (errbuf) - 1); - throw Exception (*this, str ( format("Could not write data to output file (%1%)") % errbuf)); - } - - if (c.has_flag(ProcessContext<T>::EndOfInput)) { - sf_write_sync (sndfile); - FileWritten (path); - if (debug_level (DebugProcess)) { - debug_stream() << str ( format("Finished writing file %1%") % path) << std::endl; - } - } -} - -template class SndfileWriter<short>; -template class SndfileWriter<int>; -template class SndfileWriter<float>; - -} // namespace diff --git a/libs/audiographer/src/utils.cc b/libs/audiographer/src/utils.cc deleted file mode 100644 index 018fad3113..0000000000 --- a/libs/audiographer/src/utils.cc +++ /dev/null @@ -1,14 +0,0 @@ -#include "audiographer/utils.h" - -using namespace AudioGrapher; - -char const * Utils::zeros = 0; -unsigned long Utils::num_zeros = 0; - -void -Utils::free_resources() -{ - num_zeros = 0; - delete [] zeros; - zeros = 0; -}
\ No newline at end of file |