summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/dsp.c74
1 files changed, 51 insertions, 23 deletions
diff --git a/apps/dsp.c b/apps/dsp.c
index ec45db0c74..2113d251a1 100644
--- a/apps/dsp.c
+++ b/apps/dsp.c
@@ -19,6 +19,7 @@
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "config.h" 21#include "config.h"
22
22#include <stdbool.h> 23#include <stdbool.h>
23#include <inttypes.h> 24#include <inttypes.h>
24#include <string.h> 25#include <string.h>
@@ -210,6 +211,7 @@ static int treble; /* A/V */
210/* Settings applicable to audio codec only */ 211/* Settings applicable to audio codec only */
211#ifdef HAVE_PITCHSCREEN 212#ifdef HAVE_PITCHSCREEN
212static int32_t pitch_ratio = PITCH_SPEED_100; 213static int32_t pitch_ratio = PITCH_SPEED_100;
214static int big_sample_locks;
213#endif 215#endif
214static int channels_mode; 216static int channels_mode;
215 long dsp_sw_gain; 217 long dsp_sw_gain;
@@ -280,16 +282,34 @@ void sound_set_pitch(int32_t percent)
280 AUDIO_DSP.codec_frequency); 282 AUDIO_DSP.codec_frequency);
281} 283}
282 284
285static void tdspeed_set_pointers( bool time_stretch_active )
286{
287 if( time_stretch_active )
288 {
289 sample_buf_count = BIG_SAMPLE_BUF_COUNT;
290 resample_buf_count = BIG_RESAMPLE_BUF_COUNT;
291 sample_buf[0] = big_sample_buf[0];
292 sample_buf[1] = big_sample_buf[1];
293 resample_buf[0] = big_resample_buf[0];
294 resample_buf[1] = big_resample_buf[1];
295 }
296 else
297 {
298 sample_buf_count = SMALL_SAMPLE_BUF_COUNT;
299 resample_buf_count = SMALL_RESAMPLE_BUF_COUNT;
300 sample_buf[0] = small_sample_buf[0];
301 sample_buf[1] = small_sample_buf[1];
302 resample_buf[0] = small_resample_buf[0];
303 resample_buf[1] = small_resample_buf[1];
304 }
305}
306
283static void tdspeed_setup(struct dsp_config *dspc) 307static void tdspeed_setup(struct dsp_config *dspc)
284{ 308{
285 /* Assume timestretch will not be used */ 309 /* Assume timestretch will not be used */
286 dspc->tdspeed_active = false; 310 dspc->tdspeed_active = false;
287 sample_buf[0] = small_sample_buf[0]; 311
288 sample_buf[1] = small_sample_buf[1]; 312 tdspeed_set_pointers( false );
289 resample_buf[0] = small_resample_buf[0];
290 resample_buf[1] = small_resample_buf[1];
291 sample_buf_count = SMALL_SAMPLE_BUF_COUNT;
292 resample_buf_count = SMALL_RESAMPLE_BUF_COUNT;
293 313
294 if (!dsp_timestretch_available()) 314 if (!dsp_timestretch_available())
295 return; /* Timestretch not enabled or buffer not allocated */ 315 return; /* Timestretch not enabled or buffer not allocated */
@@ -305,23 +325,33 @@ static void tdspeed_setup(struct dsp_config *dspc)
305 325
306 /* Timestretch is to be used */ 326 /* Timestretch is to be used */
307 dspc->tdspeed_active = true; 327 dspc->tdspeed_active = true;
308 sample_buf[0] = big_sample_buf[0]; 328
309 sample_buf[1] = big_sample_buf[1]; 329 tdspeed_set_pointers( true );
310 resample_buf[0] = big_resample_buf[0];
311 resample_buf[1] = big_resample_buf[1];
312 sample_buf_count = BIG_SAMPLE_BUF_COUNT;
313 resample_buf_count = BIG_RESAMPLE_BUF_COUNT;
314} 330}
315 331
316 332
317static int move_callback(int handle, void* current, void* new) 333static int move_callback(int handle, void* current, void* new)
318{ 334{
319 /* TODO */ 335 (void)handle;(void)current;
320 (void)handle;(void)current;; 336
337 if ( big_sample_locks > 0 )
338 return BUFLIB_CB_CANNOT_MOVE;
339
321 big_sample_buf = new; 340 big_sample_buf = new;
341
342 /* no allocation without timestretch enabled */
343 tdspeed_set_pointers( true );
322 return BUFLIB_CB_OK; 344 return BUFLIB_CB_OK;
323} 345}
324 346
347void lock_sample_buf( bool lock )
348{
349 if ( lock )
350 big_sample_locks++;
351 else
352 big_sample_locks--;
353}
354
325static struct buflib_callbacks ops = { 355static struct buflib_callbacks ops = {
326 .move_callback = move_callback, 356 .move_callback = move_callback,
327 .shrink_callback = NULL, 357 .shrink_callback = NULL,
@@ -331,8 +361,7 @@ static struct buflib_callbacks ops = {
331void dsp_timestretch_enable(bool enabled) 361void dsp_timestretch_enable(bool enabled)
332{ 362{
333 /* Hook to set up timestretch buffer on first call to settings_apply() */ 363 /* Hook to set up timestretch buffer on first call to settings_apply() */
334 static int handle; 364 static int handle = -1;
335
336 if (enabled) 365 if (enabled)
337 { 366 {
338 if (big_sample_buf) 367 if (big_sample_buf)
@@ -340,12 +369,11 @@ void dsp_timestretch_enable(bool enabled)
340 369
341 /* Set up timestretch buffers */ 370 /* Set up timestretch buffers */
342 big_sample_buf = &small_resample_buf[0]; 371 big_sample_buf = &small_resample_buf[0];
343
344 handle = core_alloc_ex("resample buf", 372 handle = core_alloc_ex("resample buf",
345 2 * BIG_RESAMPLE_BUF_COUNT * sizeof(int32_t), 373 2 * BIG_RESAMPLE_BUF_COUNT * sizeof(int32_t),
346 &ops); 374 &ops);
347 375 big_sample_locks = 0;
348 enabled = handle > 0; 376 enabled = handle >= 0;
349 377
350 if (enabled) 378 if (enabled)
351 { 379 {
@@ -362,10 +390,10 @@ void dsp_timestretch_enable(bool enabled)
362 dsp_set_timestretch(PITCH_SPEED_100); 390 dsp_set_timestretch(PITCH_SPEED_100);
363 tdspeed_finish(); 391 tdspeed_finish();
364 392
365 if (handle > 0) 393 if (handle >= 0)
366 core_free(handle); 394 core_free(handle);
367 395
368 handle = 0; 396 handle = -1;
369 big_sample_buf = NULL; 397 big_sample_buf = NULL;
370 } 398 }
371} 399}
@@ -784,12 +812,12 @@ static inline int resample(struct dsp_config *dsp, int count, int32_t *src[])
784 resample_buf[0], 812 resample_buf[0],
785 resample_buf[1] 813 resample_buf[1]
786 }; 814 };
787 815 lock_sample_buf( true );
788 count = dsp->resample(count, &dsp->data, (const int32_t **)src, dst); 816 count = dsp->resample(count, &dsp->data, (const int32_t **)src, dst);
789 817
790 src[0] = dst[0]; 818 src[0] = dst[0];
791 src[1] = dst[dsp->data.num_channels - 1]; 819 src[1] = dst[dsp->data.num_channels - 1];
792 820 lock_sample_buf( false );
793 return count; 821 return count;
794} 822}
795 823