From 3f61caa0cd7e818416be08778f356efd54e596fb Mon Sep 17 00:00:00 2001 From: Nils Wallménius Date: Sun, 6 May 2012 12:22:09 +0200 Subject: rbcodec: abstract tdspeed buffer allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Michael Sevakis Reviewed-by: Nils Wallménius --- apps/SOURCES | 1 + apps/rbcodec_helpers.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ apps/rbcodecplatform.h | 4 ++ 3 files changed, 107 insertions(+) create mode 100644 apps/rbcodec_helpers.c (limited to 'apps') 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 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 0000000000..a7c592c62c --- /dev/null +++ b/apps/rbcodec_helpers.c @@ -0,0 +1,102 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2006 by Nicolas Pitre + * Copyright (C) 2006-2007 by Stéphane Doyon + * 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 1dc72ac4e0..d644b7c47a 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 -- cgit v1.2.3