summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2012-05-06 12:22:09 +0200
committerNils Wallménius <nils@rockbox.org>2012-05-07 10:29:07 +0200
commit3f61caa0cd7e818416be08778f356efd54e596fb (patch)
tree9f0ca1be9d8cd4f0a2dcd8a3a7c20657925de21e
parent51a73d81cda6136f901e8d56f4720dc28edf648a (diff)
downloadrockbox-3f61caa0cd7e818416be08778f356efd54e596fb.zip
rockbox-3f61caa0cd7e818416be08778f356efd54e596fb.tar.gz
rockbox-3f61caa0cd7e818416be08778f356efd54e596fb.tar.bz2
rockbox-3f61caa0cd7e818416be08778f356efd54e596fb.tar.xz
rbcodec: abstract tdspeed buffer allocation
Move code dealing with rockbox specific buflib allocations into a rockbox specific file and implement buffer allocation with malloc/free for warble/stand alone lib. Based on patch by Sean Bartell. Change-Id: I8cb85dad5890fbd34c1bb26abbb89c0b0f6b55cf Reviewed-on: http://gerrit.rockbox.org/144 Tested-by: Nils Wallménius <nils@rockbox.org> Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Reviewed-by: Nils Wallménius <nils@rockbox.org>
-rw-r--r--apps/SOURCES1
-rw-r--r--apps/rbcodec_helpers.c102
-rw-r--r--apps/rbcodecplatform.h4
-rw-r--r--lib/rbcodec/dsp/tdspeed.c148
-rw-r--r--lib/rbcodec/dsp/tdspeed.h1
-rw-r--r--lib/rbcodec/rbcodecplatform-unix.h23
-rw-r--r--lib/rbcodec/test/SOURCES2
-rw-r--r--lib/rbcodec/test/warble.c2
8 files changed, 173 insertions, 110 deletions
diff --git a/apps/SOURCES b/apps/SOURCES
index 45eb076..e20f1c9 100644
--- a/apps/SOURCES
+++ b/apps/SOURCES
@@ -26,6 +26,7 @@ menus/audiohw_eq_menu.c
menus/eq_menu.c
buffering.c
voice_thread.c
+rbcodec_helpers.c
#else /* !SWCODEC */
mpeg.c
#endif
diff --git a/apps/rbcodec_helpers.c b/apps/rbcodec_helpers.c
new file mode 100644
index 0000000..a7c592c
--- /dev/null
+++ b/apps/rbcodec_helpers.c
@@ -0,0 +1,102 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2006 by Nicolas Pitre <nico@cam.org>
+ * Copyright (C) 2006-2007 by Stéphane Doyon <s.doyon@videotron.ca>
+ * Copyright (C) 2012 Michael Sevakis
+ *
+ * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+#include "platform.h"
+#include "dsp_core.h"
+#include "core_alloc.h"
+#include "tdspeed.h"
+
+static int handles[4] = { 0, 0, 0, 0 };
+
+static int move_callback(int handle, void *current, void *new)
+{
+#if 0
+ /* Should not currently need to block this since DSP loop completes an
+ iteration before yielding and begins again at its input buffer */
+ if (dsp_is_busy(tdspeed_state.dsp))
+ return BUFLIB_CB_CANNOT_MOVE; /* DSP processing in progress */
+#endif
+
+ for (unsigned int i = 0; i < ARRAYLEN(handles); i++)
+ {
+ if (handle != handles[i])
+ continue;
+
+ tdspeed_move(i, current, new);
+ break;
+ }
+
+ return BUFLIB_CB_OK;
+}
+
+static struct buflib_callbacks ops =
+{
+ .move_callback = move_callback,
+ .shrink_callback = NULL,
+};
+
+/* Allocate timestretch buffers */
+bool tdspeed_alloc_buffers(int32_t **buffers, const int *buf_s, int nbuf)
+{
+ static const char *buffer_names[4] = {
+ "tdspeed ovl L",
+ "tdspeed ovl R",
+ "tdspeed out L",
+ "tdspeed out R"
+ };
+
+ for (int i = 0; i < nbuf; i++)
+ {
+ if (handles[i] <= 0)
+ {
+ handles[i] = core_alloc_ex(buffer_names[i], buf_s[i], &ops);
+
+ if (handles[i] <= 0)
+ return false;
+ }
+
+ if (buffers[i] == NULL)
+ {
+ buffers[i] = core_get_data(handles[i]);
+
+ if (buffers[i] == NULL)
+ return false;
+ }
+ }
+
+ return true;
+}
+
+/* Free timestretch buffers */
+void tdspeed_free_buffers(int32_t **buffers, int nbuf)
+{
+ for (int i = 0; i < nbuf; i++)
+ {
+ if (handles[i] > 0)
+ core_free(handles[i]);
+
+ handles[i] = 0;
+ buffers[i] = NULL;
+ }
+}
+
diff --git a/apps/rbcodecplatform.h b/apps/rbcodecplatform.h
index 1dc72ac..d644b7c 100644
--- a/apps/rbcodecplatform.h
+++ b/apps/rbcodecplatform.h
@@ -31,5 +31,9 @@
#include "dsp-util.h"
#define HAVE_CLIP_SAMPLE_16
#endif
+
+bool tdspeed_alloc_buffers(int32_t **buffers, const int *buf_s, int nbuf);
+void tdspeed_free_buffers(int32_t **buffers, int nbuf);
+
#endif
diff --git a/lib/rbcodec/dsp/tdspeed.c b/lib/rbcodec/dsp/tdspeed.c
index 82b6b0e..ea1013e 100644
--- a/lib/rbcodec/dsp/tdspeed.c
+++ b/lib/rbcodec/dsp/tdspeed.c
@@ -20,15 +20,17 @@
* KIND, either express or implied.
*
****************************************************************************/
+#include "platform.h"
#include "config.h"
-#include "system.h"
#include "sound.h"
#include "core_alloc.h"
#include "dsp-util.h"
#include "dsp_proc_entry.h"
#include "tdspeed.h"
+#ifndef assert
#define assert(cond)
+#endif
#define TIMESTRETCH_SET_FACTOR (DSP_PROC_SETTING+DSP_PROC_TIMESTRETCH)
@@ -39,6 +41,7 @@
#define MAX_INPUTCOUNT 512 /* Max input count so dst doesn't overflow */
#define FIXED_BUFCOUNT 3072 /* 48KHz factor 3.0 */
#define FIXED_OUTBUFCOUNT 4096
+#define NBUFFERS 4
enum tdspeed_ops
{
@@ -64,8 +67,13 @@ static struct tdspeed_state_s
int32_t *ovl_buff[2]; /* overlap buffer (L+R) */
} tdspeed_state;
-static int handles[4] = { 0, 0, 0, 0 };
-static int32_t *buffers[4] = { NULL, NULL, NULL, NULL };
+static int32_t *buffers[NBUFFERS] = { NULL, NULL, NULL, NULL };
+static const int buffer_sizes[NBUFFERS] = {
+ FIXED_BUFCOUNT * sizeof(int32_t),
+ FIXED_BUFCOUNT * sizeof(int32_t),
+ FIXED_OUTBUFCOUNT * sizeof(int32_t),
+ FIXED_OUTBUFCOUNT * sizeof(int32_t)
+};
#define overlap_buffer (&buffers[0])
#define outbuf (&buffers[2])
@@ -74,107 +82,6 @@ static int32_t *buffers[4] = { NULL, NULL, NULL, NULL };
/* Processed buffer passed out to later stages */
static struct dsp_buffer dsp_outbuf;
-static int move_callback(int handle, void *current, void *new)
-{
-#if 0
- /* Should not currently need to block this since DSP loop completes an
- iteration before yielding and begins again at its input buffer */
- if (dsp_is_busy(tdspeed_state.dsp))
- return BUFLIB_CB_CANNOT_MOVE; /* DSP processing in progress */
-#endif
-
- ptrdiff_t shift = (int32_t *)new - (int32_t *)current;
- int32_t **p32 = dsp_outbuf.p32;
-
- for (unsigned int i = 0; i < ARRAYLEN(handles); i++)
- {
- if (handle != handles[i])
- continue;
-
- switch (i)
- {
- case 0: case 1:
- /* moving overlap (input) buffers */
- tdspeed_state.ovl_buff[i] = new;
- break;
-
- case 2:
- /* moving outbuf left channel and dsp_outbuf.p32[0] */
- if (p32[0] == p32[1])
- p32[1] += shift; /* mono mode */
-
- p32[0] += shift;
- break;
-
- case 3:
- /* moving outbuf right channel and dsp_outbuf.p32[1] */
- p32[1] += shift;
- break;
- }
-
- buffers[i] = new;
- break;
- }
-
- return BUFLIB_CB_OK;
-}
-
-static struct buflib_callbacks ops =
-{
- .move_callback = move_callback,
- .shrink_callback = NULL,
-};
-
-/* Allocate timestretch buffers */
-static bool tdspeed_alloc_buffers(void)
-{
- static const struct
- {
- const char *name;
- size_t size;
- } bufdefs[4] =
- {
- { "tdspeed ovl L", FIXED_BUFCOUNT * sizeof(int32_t) },
- { "tdspeed ovl R", FIXED_BUFCOUNT * sizeof(int32_t) },
- { "tdspeed out L", FIXED_OUTBUFCOUNT * sizeof(int32_t) },
- { "tdspeed out R", FIXED_OUTBUFCOUNT * sizeof(int32_t) },
- };
-
- for (unsigned int i = 0; i < ARRAYLEN(bufdefs); i++)
- {
- if (handles[i] <= 0)
- {
- handles[i] = core_alloc_ex(bufdefs[i].name, bufdefs[i].size, &ops);
-
- if (handles[i] <= 0)
- return false;
- }
-
- if (buffers[i] == NULL)
- {
- buffers[i] = core_get_data(handles[i]);
-
- if (buffers[i] == NULL)
- return false;
- }
- }
-
- return true;
-}
-
-/* Free timestretch buffers */
-static void tdspeed_free_buffers(void)
-{
- for (unsigned int i = 0; i < ARRAYLEN(handles); i++)
- {
- if (handles[i] > 0)
- core_free(handles[i]);
-
- handles[i] = 0;
- buffers[i] = NULL;
- }
-}
-
/* Discard all data */
static void tdspeed_flush(void)
{
@@ -650,7 +557,7 @@ static intptr_t tdspeed_configure(struct dsp_proc_entry *this,
break;
case DSP_PROC_INIT:
- if (!tdspeed_alloc_buffers())
+ if (!tdspeed_alloc_buffers(buffers, buffer_sizes, NBUFFERS))
return -1; /* fail the init */
st->this = this;
@@ -664,7 +571,7 @@ static intptr_t tdspeed_configure(struct dsp_proc_entry *this,
st->this = NULL;
st->factor = PITCH_SPEED_100;
dsp_outbuf.remcount = 0;
- tdspeed_free_buffers();
+ tdspeed_free_buffers(buffers, NBUFFERS);
break;
case TIMESTRETCH_SET_FACTOR:
@@ -680,6 +587,35 @@ static intptr_t tdspeed_configure(struct dsp_proc_entry *this,
(void)value;
}
+void tdspeed_move(int i, void* current, void* new)
+{
+ ptrdiff_t shift = (int32_t *)new - (int32_t *)current;
+ int32_t **p32 = dsp_outbuf.p32;
+
+ switch (i)
+ {
+ case 0: case 1:
+ /* moving overlap (input) buffers */
+ tdspeed_state.ovl_buff[i] = new;
+ break;
+
+ case 2:
+ /* moving outbuf left channel and dsp_outbuf.p32[0] */
+ if (p32[0] == p32[1])
+ p32[1] += shift; /* mono mode */
+
+ p32[0] += shift;
+ break;
+
+ case 3:
+ /* moving outbuf right channel and dsp_outbuf.p32[1] */
+ p32[1] += shift;
+ break;
+ }
+
+ buffers[i] = new;
+}
+
/* Database entry */
DSP_PROC_DB_ENTRY(TIMESTRETCH,
tdspeed_configure);
diff --git a/lib/rbcodec/dsp/tdspeed.h b/lib/rbcodec/dsp/tdspeed.h
index ca8a784..2949c1b 100644
--- a/lib/rbcodec/dsp/tdspeed.h
+++ b/lib/rbcodec/dsp/tdspeed.h
@@ -39,5 +39,6 @@ void dsp_timestretch_enable(bool enable);
void dsp_set_timestretch(int32_t percent);
int32_t dsp_get_timestretch(void);
bool dsp_timestretch_available(void);
+void tdspeed_move(int i, void* current, void* new);
#endif /* _TDSPEED_H */
diff --git a/lib/rbcodec/rbcodecplatform-unix.h b/lib/rbcodec/rbcodecplatform-unix.h
index c9c8a29..5e65be3 100644
--- a/lib/rbcodec/rbcodecplatform-unix.h
+++ b/lib/rbcodec/rbcodecplatform-unix.h
@@ -74,4 +74,27 @@ static inline off_t filesize(int fd) {
#endif
#endif
*/
+
+static inline bool tdspeed_alloc_buffers(int32_t **buffers,
+ const int *buf_s, int nbuf)
+{
+ int i;
+ for (i = 0; i < nbuf; i++)
+ {
+ buffers[i] = malloc(buf_s[i]);
+ if (!buffers[i])
+ return false;
+ }
+ return true;
+}
+
+static inline void tdspeed_free_buffers(int32_t **buffers, int nbuf)
+{
+ int i;
+ for (i = 0; i < nbuf; i++)
+ {
+ free(buffers[i]);
+ }
+}
+
#endif
diff --git a/lib/rbcodec/test/SOURCES b/lib/rbcodec/test/SOURCES
index 4c0d906..a89af23 100644
--- a/lib/rbcodec/test/SOURCES
+++ b/lib/rbcodec/test/SOURCES
@@ -1,6 +1,4 @@
warble.c
-../../../firmware/buflib.c
-../../../firmware/core_alloc.c
../../../firmware/common/strlcpy.c
../../../firmware/common/unicode.c
../../../firmware/common/structec.c
diff --git a/lib/rbcodec/test/warble.c b/lib/rbcodec/test/warble.c
index ea8efcf..d5bc1c5 100644
--- a/lib/rbcodec/test/warble.c
+++ b/lib/rbcodec/test/warble.c
@@ -33,7 +33,6 @@
#include <unistd.h>
#include "buffering.h" /* TYPE_PACKET_AUDIO */
#include "codecs.h"
-#include "core_alloc.h" /* core_allocator_init */
#include "dsp_core.h"
#include "metadata.h"
#include "settings.h"
@@ -851,7 +850,6 @@ int main(int argc, char **argv)
}
}
- core_allocator_init();
if (argc == optind + 2) {
write_init(argv[optind + 1]);
} else if (argc == optind + 1) {