summaryrefslogtreecommitdiff
path: root/apps
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 /apps
parent51a73d81cda6136f901e8d56f4720dc28edf648a (diff)
downloadrockbox-3f61caa0cd7e818416be08778f356efd54e596fb.tar.gz
rockbox-3f61caa0cd7e818416be08778f356efd54e596fb.zip
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>
Diffstat (limited to 'apps')
-rw-r--r--apps/SOURCES1
-rw-r--r--apps/rbcodec_helpers.c102
-rw-r--r--apps/rbcodecplatform.h4
3 files changed, 107 insertions, 0 deletions
diff --git a/apps/SOURCES b/apps/SOURCES
index 45eb0768a3..e20f1c961b 100644
--- a/apps/SOURCES
+++ b/apps/SOURCES
@@ -26,6 +26,7 @@ menus/audiohw_eq_menu.c
26menus/eq_menu.c 26menus/eq_menu.c
27buffering.c 27buffering.c
28voice_thread.c 28voice_thread.c
29rbcodec_helpers.c
29#else /* !SWCODEC */ 30#else /* !SWCODEC */
30mpeg.c 31mpeg.c
31#endif 32#endif
diff --git a/apps/rbcodec_helpers.c b/apps/rbcodec_helpers.c
new file mode 100644
index 0000000000..a7c592c62c
--- /dev/null
+++ b/apps/rbcodec_helpers.c
@@ -0,0 +1,102 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Nicolas Pitre <nico@cam.org>
11 * Copyright (C) 2006-2007 by Stéphane Doyon <s.doyon@videotron.ca>
12 * Copyright (C) 2012 Michael Sevakis
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24#include "platform.h"
25#include "dsp_core.h"
26#include "core_alloc.h"
27#include "tdspeed.h"
28
29static int handles[4] = { 0, 0, 0, 0 };
30
31static int move_callback(int handle, void *current, void *new)
32{
33#if 0
34 /* Should not currently need to block this since DSP loop completes an
35 iteration before yielding and begins again at its input buffer */
36 if (dsp_is_busy(tdspeed_state.dsp))
37 return BUFLIB_CB_CANNOT_MOVE; /* DSP processing in progress */
38#endif
39
40 for (unsigned int i = 0; i < ARRAYLEN(handles); i++)
41 {
42 if (handle != handles[i])
43 continue;
44
45 tdspeed_move(i, current, new);
46 break;
47 }
48
49 return BUFLIB_CB_OK;
50}
51
52static struct buflib_callbacks ops =
53{
54 .move_callback = move_callback,
55 .shrink_callback = NULL,
56};
57
58/* Allocate timestretch buffers */
59bool tdspeed_alloc_buffers(int32_t **buffers, const int *buf_s, int nbuf)
60{
61 static const char *buffer_names[4] = {
62 "tdspeed ovl L",
63 "tdspeed ovl R",
64 "tdspeed out L",
65 "tdspeed out R"
66 };
67
68 for (int i = 0; i < nbuf; i++)
69 {
70 if (handles[i] <= 0)
71 {
72 handles[i] = core_alloc_ex(buffer_names[i], buf_s[i], &ops);
73
74 if (handles[i] <= 0)
75 return false;
76 }
77
78 if (buffers[i] == NULL)
79 {
80 buffers[i] = core_get_data(handles[i]);
81
82 if (buffers[i] == NULL)
83 return false;
84 }
85 }
86
87 return true;
88}
89
90/* Free timestretch buffers */
91void tdspeed_free_buffers(int32_t **buffers, int nbuf)
92{
93 for (int i = 0; i < nbuf; i++)
94 {
95 if (handles[i] > 0)
96 core_free(handles[i]);
97
98 handles[i] = 0;
99 buffers[i] = NULL;
100 }
101}
102
diff --git a/apps/rbcodecplatform.h b/apps/rbcodecplatform.h
index 1dc72ac4e0..d644b7c47a 100644
--- a/apps/rbcodecplatform.h
+++ b/apps/rbcodecplatform.h
@@ -31,5 +31,9 @@
31#include "dsp-util.h" 31#include "dsp-util.h"
32#define HAVE_CLIP_SAMPLE_16 32#define HAVE_CLIP_SAMPLE_16
33#endif 33#endif
34
35bool tdspeed_alloc_buffers(int32_t **buffers, const int *buf_s, int nbuf);
36void tdspeed_free_buffers(int32_t **buffers, int nbuf);
37
34#endif 38#endif
35 39