summaryrefslogtreecommitdiff
path: root/apps/dsp.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-08-30 14:01:45 +0000
committerThomas Martitz <kugel@rockbox.org>2011-08-30 14:01:45 +0000
commitbaa070cca6d459a7c5aed81f29e4cc4f6c7410b3 (patch)
tree5123360aea420b96e4a97a8e88cf51b4277152d9 /apps/dsp.c
parentd0b72e25903574acb1cf9184a6052cdd646dbc37 (diff)
downloadrockbox-baa070cca6d459a7c5aed81f29e4cc4f6c7410b3.zip
rockbox-baa070cca6d459a7c5aed81f29e4cc4f6c7410b3.tar.gz
rockbox-baa070cca6d459a7c5aed81f29e4cc4f6c7410b3.tar.bz2
rockbox-baa070cca6d459a7c5aed81f29e4cc4f6c7410b3.tar.xz
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
Diffstat (limited to 'apps/dsp.c')
-rw-r--r--apps/dsp.c60
1 files changed, 40 insertions, 20 deletions
diff --git a/apps/dsp.c b/apps/dsp.c
index a728dd7..167c043 100644
--- a/apps/dsp.c
+++ b/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;