usb: add support for hardware handled SET ADDR/CONFIG
[maemo-rb.git] / apps / rbcodec_helpers.c
blobb412bb3aa47275e4cc444290191b5881cec3df4c
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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
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.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 #include "platform.h"
25 #include "dsp_core.h"
26 #include "core_alloc.h"
27 #include "tdspeed.h"
29 #ifdef HAVE_PITCHCONTROL
30 static int handles[4] = { 0, 0, 0, 0 };
32 static int move_callback(int handle, void *current, void *new)
34 #if 0
35 /* Should not currently need to block this since DSP loop completes an
36 iteration before yielding and begins again at its input buffer */
37 if (dsp_is_busy(tdspeed_state.dsp))
38 return BUFLIB_CB_CANNOT_MOVE; /* DSP processing in progress */
39 #endif
41 for (unsigned int i = 0; i < ARRAYLEN(handles); i++)
43 if (handle != handles[i])
44 continue;
46 tdspeed_move(i, current, new);
47 break;
50 return BUFLIB_CB_OK;
53 static struct buflib_callbacks ops =
55 .move_callback = move_callback,
56 .shrink_callback = NULL,
59 /* Allocate timestretch buffers */
60 bool tdspeed_alloc_buffers(int32_t **buffers, const int *buf_s, int nbuf)
62 static const char *buffer_names[4] = {
63 "tdspeed ovl L",
64 "tdspeed ovl R",
65 "tdspeed out L",
66 "tdspeed out R"
69 for (int i = 0; i < nbuf; i++)
71 if (handles[i] <= 0)
73 handles[i] = core_alloc_ex(buffer_names[i], buf_s[i], &ops);
75 if (handles[i] <= 0)
76 return false;
79 if (buffers[i] == NULL)
81 buffers[i] = core_get_data(handles[i]);
83 if (buffers[i] == NULL)
84 return false;
88 return true;
91 /* Free timestretch buffers */
92 void tdspeed_free_buffers(int32_t **buffers, int nbuf)
94 for (int i = 0; i < nbuf; i++)
96 if (handles[i] > 0)
97 core_free(handles[i]);
99 handles[i] = 0;
100 buffers[i] = NULL;
103 #endif /* HAVE_PITCHCONTROL */