summaryrefslogtreecommitdiff
path: root/apps/rbcodec_helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/rbcodec_helpers.c')
-rw-r--r--apps/rbcodec_helpers.c102
1 files changed, 102 insertions, 0 deletions
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