forked from len0rd/rockbox
Implement move callback for timestretch sample allocation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30813 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
8e18dc85cf
commit
d228d4d130
1 changed files with 51 additions and 23 deletions
74
apps/dsp.c
74
apps/dsp.c
|
@ -19,6 +19,7 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -210,6 +211,7 @@ static int treble; /* A/V */
|
||||||
/* Settings applicable to audio codec only */
|
/* Settings applicable to audio codec only */
|
||||||
#ifdef HAVE_PITCHSCREEN
|
#ifdef HAVE_PITCHSCREEN
|
||||||
static int32_t pitch_ratio = PITCH_SPEED_100;
|
static int32_t pitch_ratio = PITCH_SPEED_100;
|
||||||
|
static int big_sample_locks;
|
||||||
#endif
|
#endif
|
||||||
static int channels_mode;
|
static int channels_mode;
|
||||||
long dsp_sw_gain;
|
long dsp_sw_gain;
|
||||||
|
@ -280,16 +282,34 @@ void sound_set_pitch(int32_t percent)
|
||||||
AUDIO_DSP.codec_frequency);
|
AUDIO_DSP.codec_frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tdspeed_set_pointers( bool time_stretch_active )
|
||||||
|
{
|
||||||
|
if( time_stretch_active )
|
||||||
|
{
|
||||||
|
sample_buf_count = BIG_SAMPLE_BUF_COUNT;
|
||||||
|
resample_buf_count = BIG_RESAMPLE_BUF_COUNT;
|
||||||
|
sample_buf[0] = big_sample_buf[0];
|
||||||
|
sample_buf[1] = big_sample_buf[1];
|
||||||
|
resample_buf[0] = big_resample_buf[0];
|
||||||
|
resample_buf[1] = big_resample_buf[1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sample_buf_count = SMALL_SAMPLE_BUF_COUNT;
|
||||||
|
resample_buf_count = SMALL_RESAMPLE_BUF_COUNT;
|
||||||
|
sample_buf[0] = small_sample_buf[0];
|
||||||
|
sample_buf[1] = small_sample_buf[1];
|
||||||
|
resample_buf[0] = small_resample_buf[0];
|
||||||
|
resample_buf[1] = small_resample_buf[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void tdspeed_setup(struct dsp_config *dspc)
|
static void tdspeed_setup(struct dsp_config *dspc)
|
||||||
{
|
{
|
||||||
/* Assume timestretch will not be used */
|
/* Assume timestretch will not be used */
|
||||||
dspc->tdspeed_active = false;
|
dspc->tdspeed_active = false;
|
||||||
sample_buf[0] = small_sample_buf[0];
|
|
||||||
sample_buf[1] = small_sample_buf[1];
|
tdspeed_set_pointers( false );
|
||||||
resample_buf[0] = small_resample_buf[0];
|
|
||||||
resample_buf[1] = small_resample_buf[1];
|
|
||||||
sample_buf_count = SMALL_SAMPLE_BUF_COUNT;
|
|
||||||
resample_buf_count = SMALL_RESAMPLE_BUF_COUNT;
|
|
||||||
|
|
||||||
if (!dsp_timestretch_available())
|
if (!dsp_timestretch_available())
|
||||||
return; /* Timestretch not enabled or buffer not allocated */
|
return; /* Timestretch not enabled or buffer not allocated */
|
||||||
|
@ -305,23 +325,33 @@ static void tdspeed_setup(struct dsp_config *dspc)
|
||||||
|
|
||||||
/* Timestretch is to be used */
|
/* Timestretch is to be used */
|
||||||
dspc->tdspeed_active = true;
|
dspc->tdspeed_active = true;
|
||||||
sample_buf[0] = big_sample_buf[0];
|
|
||||||
sample_buf[1] = big_sample_buf[1];
|
tdspeed_set_pointers( true );
|
||||||
resample_buf[0] = big_resample_buf[0];
|
|
||||||
resample_buf[1] = big_resample_buf[1];
|
|
||||||
sample_buf_count = BIG_SAMPLE_BUF_COUNT;
|
|
||||||
resample_buf_count = BIG_RESAMPLE_BUF_COUNT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int move_callback(int handle, void* current, void* new)
|
static int move_callback(int handle, void* current, void* new)
|
||||||
{
|
{
|
||||||
/* TODO */
|
(void)handle;(void)current;
|
||||||
(void)handle;(void)current;;
|
|
||||||
|
if ( big_sample_locks > 0 )
|
||||||
|
return BUFLIB_CB_CANNOT_MOVE;
|
||||||
|
|
||||||
big_sample_buf = new;
|
big_sample_buf = new;
|
||||||
|
|
||||||
|
/* no allocation without timestretch enabled */
|
||||||
|
tdspeed_set_pointers( true );
|
||||||
return BUFLIB_CB_OK;
|
return BUFLIB_CB_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lock_sample_buf( bool lock )
|
||||||
|
{
|
||||||
|
if ( lock )
|
||||||
|
big_sample_locks++;
|
||||||
|
else
|
||||||
|
big_sample_locks--;
|
||||||
|
}
|
||||||
|
|
||||||
static struct buflib_callbacks ops = {
|
static struct buflib_callbacks ops = {
|
||||||
.move_callback = move_callback,
|
.move_callback = move_callback,
|
||||||
.shrink_callback = NULL,
|
.shrink_callback = NULL,
|
||||||
|
@ -331,8 +361,7 @@ static struct buflib_callbacks ops = {
|
||||||
void dsp_timestretch_enable(bool enabled)
|
void dsp_timestretch_enable(bool enabled)
|
||||||
{
|
{
|
||||||
/* Hook to set up timestretch buffer on first call to settings_apply() */
|
/* Hook to set up timestretch buffer on first call to settings_apply() */
|
||||||
static int handle;
|
static int handle = -1;
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
if (big_sample_buf)
|
if (big_sample_buf)
|
||||||
|
@ -340,12 +369,11 @@ void dsp_timestretch_enable(bool enabled)
|
||||||
|
|
||||||
/* Set up timestretch buffers */
|
/* Set up timestretch buffers */
|
||||||
big_sample_buf = &small_resample_buf[0];
|
big_sample_buf = &small_resample_buf[0];
|
||||||
|
|
||||||
handle = core_alloc_ex("resample buf",
|
handle = core_alloc_ex("resample buf",
|
||||||
2 * BIG_RESAMPLE_BUF_COUNT * sizeof(int32_t),
|
2 * BIG_RESAMPLE_BUF_COUNT * sizeof(int32_t),
|
||||||
&ops);
|
&ops);
|
||||||
|
big_sample_locks = 0;
|
||||||
enabled = handle > 0;
|
enabled = handle >= 0;
|
||||||
|
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
|
@ -362,10 +390,10 @@ void dsp_timestretch_enable(bool enabled)
|
||||||
dsp_set_timestretch(PITCH_SPEED_100);
|
dsp_set_timestretch(PITCH_SPEED_100);
|
||||||
tdspeed_finish();
|
tdspeed_finish();
|
||||||
|
|
||||||
if (handle > 0)
|
if (handle >= 0)
|
||||||
core_free(handle);
|
core_free(handle);
|
||||||
|
|
||||||
handle = 0;
|
handle = -1;
|
||||||
big_sample_buf = NULL;
|
big_sample_buf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -784,12 +812,12 @@ static inline int resample(struct dsp_config *dsp, int count, int32_t *src[])
|
||||||
resample_buf[0],
|
resample_buf[0],
|
||||||
resample_buf[1]
|
resample_buf[1]
|
||||||
};
|
};
|
||||||
|
lock_sample_buf( true );
|
||||||
count = dsp->resample(count, &dsp->data, (const int32_t **)src, dst);
|
count = dsp->resample(count, &dsp->data, (const int32_t **)src, dst);
|
||||||
|
|
||||||
src[0] = dst[0];
|
src[0] = dst[0];
|
||||||
src[1] = dst[dsp->data.num_channels - 1];
|
src[1] = dst[dsp->data.num_channels - 1];
|
||||||
|
lock_sample_buf( false );
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue