summaryrefslogtreecommitdiff
path: root/apps/tdspeed.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tdspeed.c')
-rw-r--r--apps/tdspeed.c75
1 files changed, 62 insertions, 13 deletions
diff --git a/apps/tdspeed.c b/apps/tdspeed.c
index 476995a271..69699e5bb4 100644
--- a/apps/tdspeed.c
+++ b/apps/tdspeed.c
@@ -38,6 +38,46 @@
38 38
39#define FIXED_BUFSIZE 3072 /* 48KHz factor 3.0 */ 39#define FIXED_BUFSIZE 3072 /* 48KHz factor 3.0 */
40 40
41static int32_t** dsp_src;
42static int handles[4];
43static int32_t *overlap_buffer[2] = { NULL, NULL };
44static int32_t *outbuf[2] = { NULL, NULL };
45
46static int move_callback(int handle, void* current, void* new)
47{
48 /* TODO */
49 (void)handle;
50 if (dsp_src)
51 {
52 int ch = (current == outbuf[0]) ? 0 : 1;
53 dsp_src[ch] = outbuf[ch] = new;
54 }
55 return BUFLIB_CB_OK;
56}
57
58static struct buflib_callbacks ops = {
59 .move_callback = move_callback,
60 .shrink_callback = NULL,
61};
62
63static int ovl_move_callback(int handle, void* current, void* new)
64{
65 /* TODO */
66 (void)handle;
67 if (dsp_src)
68 {
69 int ch = (current == overlap_buffer[0]) ? 0 : 1;
70 overlap_buffer[ch] = new;
71 }
72 return BUFLIB_CB_OK;
73}
74
75static struct buflib_callbacks ovl_ops = {
76 .move_callback = ovl_move_callback,
77 .shrink_callback = NULL,
78};
79
80
41static struct tdspeed_state_s 81static struct tdspeed_state_s
42{ 82{
43 bool stereo; 83 bool stereo;
@@ -51,39 +91,47 @@ static struct tdspeed_state_s
51 int32_t *ovl_buff[2]; /* overlap buffer */ 91 int32_t *ovl_buff[2]; /* overlap buffer */
52} tdspeed_state; 92} tdspeed_state;
53 93
54static int32_t *overlap_buffer[2] = { NULL, NULL };
55static int32_t *outbuf[2] = { NULL, NULL };
56
57void tdspeed_init(void) 94void tdspeed_init(void)
58{ 95{
59 int handle;
60
61 if (!global_settings.timestretch_enabled) 96 if (!global_settings.timestretch_enabled)
62 return; 97 return;
63 98
64 /* Allocate buffers */ 99 /* Allocate buffers */
65 if (overlap_buffer[0] == NULL) 100 if (overlap_buffer[0] == NULL)
66 { 101 {
67 handle = core_alloc("tdspeed ovl left", FIXED_BUFSIZE * sizeof(int32_t)); 102 handles[0] = core_alloc_ex("tdspeed ovl left", FIXED_BUFSIZE * sizeof(int32_t), &ovl_ops);
68 overlap_buffer[0] = core_get_data(handle); 103 overlap_buffer[0] = core_get_data(handles[0]);
69 } 104 }
70 if (overlap_buffer[1] == NULL) 105 if (overlap_buffer[1] == NULL)
71 { 106 {
72 handle = core_alloc("tdspeed ovl right", FIXED_BUFSIZE * sizeof(int32_t)); 107 handles[1] = core_alloc_ex("tdspeed ovl right", FIXED_BUFSIZE * sizeof(int32_t), &ovl_ops);
73 overlap_buffer[1] = core_get_data(handle); 108 overlap_buffer[1] = core_get_data(handles[1]);
74 } 109 }
75 if (outbuf[0] == NULL) 110 if (outbuf[0] == NULL)
76 { 111 {
77 handle = core_alloc("tdspeed left", TDSPEED_OUTBUFSIZE * sizeof(int32_t)); 112 handles[2] = core_alloc_ex("tdspeed left", TDSPEED_OUTBUFSIZE * sizeof(int32_t), &ops);
78 outbuf[0] = core_get_data(handle); 113 outbuf[0] = core_get_data(handles[2]);
79 } 114 }
80 if (outbuf[1] == NULL) 115 if (outbuf[1] == NULL)
81 { 116 {
82 handle = core_alloc("tdspeed right", TDSPEED_OUTBUFSIZE * sizeof(int32_t)); 117 handles[3] = core_alloc_ex("tdspeed right", TDSPEED_OUTBUFSIZE * sizeof(int32_t), &ops);
83 outbuf[1] = core_get_data(handle); 118 outbuf[1] = core_get_data(handles[3]);
84 } 119 }
85} 120}
86 121
122void tdspeed_finish(void)
123{
124 for(unsigned i = 0; i < ARRAYLEN(handles); i++)
125 {
126 if (handles[i] > 0)
127 {
128 core_free(handles[i]);
129 handles[i] = 0;
130 }
131 }
132 overlap_buffer[0] = overlap_buffer[1] = NULL;
133 outbuf[0] = outbuf[1] = NULL;
134}
87 135
88bool tdspeed_config(int samplerate, bool stereo, int32_t factor) 136bool tdspeed_config(int samplerate, bool stereo, int32_t factor)
89{ 137{
@@ -390,6 +438,7 @@ long tdspeed_est_input_size(long size)
390 438
391int tdspeed_doit(int32_t *src[], int count) 439int tdspeed_doit(int32_t *src[], int count)
392{ 440{
441 dsp_src = src;
393 count = tdspeed_apply( (int32_t *[2]) { outbuf[0], outbuf[1] }, 442 count = tdspeed_apply( (int32_t *[2]) { outbuf[0], outbuf[1] },
394 src, count, 0, TDSPEED_OUTBUFSIZE); 443 src, count, 0, TDSPEED_OUTBUFSIZE);
395 444