forked from len0rd/rockbox
GSoC/Buflib: Enable compaction in buflib.
This enables the ability to allocate (and free) memory dynamically without fragmentation, through compaction. This means allocations can move and fragmentation be reduced. Most changes are preparing Rockbox for this, which many times means adding a move callback which can temporarily disable movement when the corresponding code is in a critical section. For now, the audio buffer allocation has a central role, because it's the one having allocated most. This buffer is able to shrink itself, for which it needs to stop playback for a very short moment. For this, audio_buffer_available() returns the size of the audio buffer which can possibly be used by other allocations because the audio buffer can shrink. lastfm scrobbling and timestretch can now be toggled at runtime without requiring a reboot. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30381 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
d0b72e2590
commit
baa070cca6
28 changed files with 865 additions and 298 deletions
60
apps/dsp.c
60
apps/dsp.c
|
|
@ -318,30 +318,50 @@ static void tdspeed_setup(struct dsp_config *dspc)
|
|||
resample_buf = big_resample_buf;
|
||||
}
|
||||
|
||||
|
||||
static int move_callback(int handle, void* current, void* new)
|
||||
{
|
||||
/* TODO */
|
||||
(void)handle;(void)current;;
|
||||
big_sample_buf = new;
|
||||
return BUFLIB_CB_OK;
|
||||
}
|
||||
|
||||
static struct buflib_callbacks ops = {
|
||||
.move_callback = move_callback,
|
||||
.shrink_callback = NULL,
|
||||
};
|
||||
|
||||
|
||||
void dsp_timestretch_enable(bool enabled)
|
||||
{
|
||||
/* Hook to set up timestretch buffer on first call to settings_apply() */
|
||||
if (big_sample_buf_count < 0) /* Only do something on first call */
|
||||
static int handle;
|
||||
if (enabled)
|
||||
{
|
||||
if (enabled)
|
||||
{
|
||||
int handle;
|
||||
/* Set up timestretch buffers */
|
||||
big_sample_buf_count = SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO;
|
||||
big_sample_buf = small_resample_buf;
|
||||
handle = core_alloc("resample buf",
|
||||
big_sample_buf_count * RESAMPLE_RATIO * sizeof(int32_t));
|
||||
if (handle > 0)
|
||||
big_resample_buf = core_get_data(handle);
|
||||
else
|
||||
big_sample_buf_count = 0;
|
||||
if (big_sample_buf_count > 0)
|
||||
return; /* already allocated and enabled */
|
||||
/* Set up timestretch buffers */
|
||||
big_sample_buf_count = SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO;
|
||||
big_sample_buf = small_resample_buf;
|
||||
handle = core_alloc_ex("resample buf",
|
||||
big_sample_buf_count * RESAMPLE_RATIO * sizeof(int32_t), &ops);
|
||||
if (handle > 0)
|
||||
{ /* success, now setup tdspeed */
|
||||
big_resample_buf = core_get_data(handle);
|
||||
tdspeed_init();
|
||||
tdspeed_setup(&AUDIO_DSP);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not enabled at startup, "big" buffers will never be available */
|
||||
big_sample_buf_count = 0;
|
||||
}
|
||||
tdspeed_setup(&AUDIO_DSP);
|
||||
}
|
||||
if (!enabled || (handle <= 0)) /* disable */
|
||||
{
|
||||
dsp_set_timestretch(PITCH_SPEED_100);
|
||||
tdspeed_finish();
|
||||
if (handle > 0)
|
||||
core_free(handle);
|
||||
handle = 0;
|
||||
big_sample_buf = NULL;
|
||||
big_sample_buf_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1211,7 +1231,7 @@ int dsp_callback(int msg, intptr_t param)
|
|||
*/
|
||||
int dsp_process(struct dsp_config *dsp, char *dst, const char *src[], int count)
|
||||
{
|
||||
int32_t *tmp[2];
|
||||
static int32_t *tmp[2]; /* tdspeed_doit() needs it static */
|
||||
static long last_yield;
|
||||
long tick;
|
||||
int written = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue