1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
26 #include "core_alloc.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)
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 */
41 for (unsigned int i
= 0; i
< ARRAYLEN(handles
); i
++)
43 if (handle
!= handles
[i
])
46 tdspeed_move(i
, current
, new);
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] = {
69 for (int i
= 0; i
< nbuf
; i
++)
73 handles
[i
] = core_alloc_ex(buffer_names
[i
], buf_s
[i
], &ops
);
79 if (buffers
[i
] == NULL
)
81 buffers
[i
] = core_get_data(handles
[i
]);
83 if (buffers
[i
] == NULL
)
91 /* Free timestretch buffers */
92 void tdspeed_free_buffers(int32_t **buffers
, int nbuf
)
94 for (int i
= 0; i
< nbuf
; i
++)
97 core_free(handles
[i
]);
103 #endif /* HAVE_PITCHCONTROL */