summaryrefslogtreecommitdiff
path: root/apps/codecs/shorten.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/shorten.c')
-rw-r--r--apps/codecs/shorten.c92
1 files changed, 40 insertions, 52 deletions
diff --git a/apps/codecs/shorten.c b/apps/codecs/shorten.c
index 290686e968..3edc143773 100644
--- a/apps/codecs/shorten.c
+++ b/apps/codecs/shorten.c
@@ -33,13 +33,13 @@ extern char iend[];
33struct codec_api* rb; 33struct codec_api* rb;
34struct codec_api* ci; 34struct codec_api* ci;
35 35
36#define MAX_DECODED (DEFAULT_BLOCK_SIZE + MAX_NWRAP) 36int32_t decoded0[MAX_DECODE_SIZE] IBSS_ATTR;
37int32_t decoded0[MAX_DECODED] IBSS_ATTR; 37int32_t decoded1[MAX_DECODE_SIZE] IBSS_ATTR;
38int32_t decoded1[MAX_DECODED] IBSS_ATTR;
39 38
40#define MAX_OFFSETS MAX_NMEAN 39int32_t offset0[MAX_OFFSET_SIZE] IBSS_ATTR;
41int32_t offset0[MAX_OFFSETS] IBSS_ATTR; 40int32_t offset1[MAX_OFFSET_SIZE] IBSS_ATTR;
42int32_t offset1[MAX_OFFSETS] IBSS_ATTR; 41
42int8_t ibuf[MAX_BUFFER_SIZE] IBSS_ATTR;
43 43
44/* this is the codec entry point */ 44/* this is the codec entry point */
45enum codec_status codec_start(struct codec_api* api) 45enum codec_status codec_start(struct codec_api* api)
@@ -48,9 +48,8 @@ enum codec_status codec_start(struct codec_api* api)
48 uint32_t samplesdone; 48 uint32_t samplesdone;
49 uint32_t elapsedtime; 49 uint32_t elapsedtime;
50 int8_t *buf; 50 int8_t *buf;
51 int cur_chan, consumed, res; 51 int consumed, res, nsamples;
52 long bytesleft; 52 long bytesleft;
53 int retval;
54 53
55 /* Generic codec initialisation */ 54 /* Generic codec initialisation */
56 rb = api; 55 rb = api;
@@ -72,9 +71,8 @@ enum codec_status codec_start(struct codec_api* api)
72next_track: 71next_track:
73 /* Codec initialization */ 72 /* Codec initialization */
74 if (codec_init(api)) { 73 if (codec_init(api)) {
75 LOGF("Shorten: Error initialising codec\n"); 74 LOGF("Shorten: codec_init error\n");
76 retval = CODEC_ERROR; 75 return CODEC_ERROR;
77 goto exit;
78 } 76 }
79 77
80 while (!*ci->taginfo_ready) 78 while (!*ci->taginfo_ready)
@@ -90,12 +88,11 @@ next_track:
90 } 88 }
91 89
92 /* Read the shorten & wave headers */ 90 /* Read the shorten & wave headers */
93 buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE); 91 buf = ci->request_buffer(&bytesleft, MAX_HEADER_SIZE);
94 res = shorten_init(&sc, (unsigned char *)buf, bytesleft); 92 res = shorten_init(&sc, (unsigned char *)buf, bytesleft);
95 if (res < 0) { 93 if (res < 0) {
96 LOGF("shorten_init error: %d\n", res); 94 LOGF("Shorten: shorten_init error: %d\n", res);
97 retval = CODEC_ERROR; 95 return CODEC_ERROR;
98 goto exit;
99 } 96 }
100 97
101 ci->id3->frequency = sc.sample_rate; 98 ci->id3->frequency = sc.sample_rate;
@@ -117,14 +114,13 @@ next_track:
117 114
118seek_start: 115seek_start:
119 /* The main decoding loop */ 116 /* The main decoding loop */
120 ci->memset(&decoded0, 0, sizeof(int32_t)*MAX_DECODED); 117 ci->memset(&decoded0, 0, sizeof(int32_t)*MAX_DECODE_SIZE);
121 ci->memset(&decoded1, 0, sizeof(int32_t)*MAX_DECODED); 118 ci->memset(&decoded1, 0, sizeof(int32_t)*MAX_DECODE_SIZE);
122 ci->memset(&offset0, 0, sizeof(int32_t)*MAX_OFFSETS); 119 ci->memset(&offset0, 0, sizeof(int32_t)*MAX_OFFSET_SIZE);
123 ci->memset(&offset1, 0, sizeof(int32_t)*MAX_OFFSETS); 120 ci->memset(&offset1, 0, sizeof(int32_t)*MAX_OFFSET_SIZE);
124 121
125 cur_chan = 0;
126 samplesdone = 0; 122 samplesdone = 0;
127 buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE); 123 buf = ci->request_buffer(&bytesleft, MAX_BUFFER_SIZE);
128 while (bytesleft) { 124 while (bytesleft) {
129 ci->yield(); 125 ci->yield();
130 if (ci->stop_codec || ci->reload_codec) { 126 if (ci->stop_codec || ci->reload_codec) {
@@ -143,51 +139,43 @@ seek_start:
143 } 139 }
144 140
145 /* Decode a frame */ 141 /* Decode a frame */
146 ci->yield(); 142 ci->memcpy(ibuf, buf, bytesleft); /* copy buf to iram */
147 if (cur_chan == 0) { 143 res = shorten_decode_frames(&sc, &nsamples, decoded0, decoded1,
148 res = shorten_decode_frame(&sc, decoded0 + sc.nwrap, offset0, 144 offset0, offset1, (unsigned char *)ibuf,
149 (unsigned char *)buf, bytesleft); 145 bytesleft, ci->yield);
146
147 if (res == FN_ERROR) {
148 LOGF("Shorten: shorten_decode_frames error (%d)\n", samplesdone);
149 return CODEC_ERROR;
150 } else { 150 } else {
151 res = shorten_decode_frame(&sc, decoded1 + sc.nwrap, offset1,
152 (unsigned char *)buf, bytesleft);
153 }
154 cur_chan++;
155
156 if (res == 0 && cur_chan == sc.channels) {
157 cur_chan = 0;
158
159 /* Insert decoded samples in pcmbuf */ 151 /* Insert decoded samples in pcmbuf */
160 ci->yield(); 152 if (nsamples) {
161 while (!ci->pcmbuf_insert_split((char*)(decoded0 + sc.nwrap),
162 (char*)(decoded1 + sc.nwrap), sc.blocksize*4)) {
163 ci->yield(); 153 ci->yield();
154 while (!ci->pcmbuf_insert_split((char*)(decoded0 + sc.nwrap),
155 (char*)(decoded1 + sc.nwrap),
156 4*nsamples)) {
157 ci->yield();
158 }
159
160 /* Update the elapsed-time indicator */
161 samplesdone += nsamples;
162 elapsedtime = (samplesdone*10) / (sc.sample_rate/100);
163 ci->set_elapsed(elapsedtime);
164 } 164 }
165 165
166 /* Update the elapsed-time indicator */
167 samplesdone += sc.blocksize;
168 elapsedtime = (samplesdone*10) / (sc.sample_rate/100);
169 ci->set_elapsed(elapsedtime);
170 } else if (res == 1) {
171 /* End of shorten stream...go to next track */ 166 /* End of shorten stream...go to next track */
172 break; 167 if (res == FN_QUIT)
173 } else if (res < 0) { 168 break;
174 LOGF("shorten_decode_frame error: \n", res);
175 retval = CODEC_ERROR;
176 goto exit;
177 } 169 }
178 170
179 consumed = sc.gb.index/8; 171 consumed = sc.gb.index/8;
180 ci->advance_buffer(consumed); 172 ci->advance_buffer(consumed);
173 buf = ci->request_buffer(&bytesleft, MAX_BUFFER_SIZE);
181 sc.bitindex = sc.gb.index - 8*consumed; 174 sc.bitindex = sc.gb.index - 8*consumed;
182 buf = ci->request_buffer(&bytesleft, MAX_FRAMESIZE);
183 } 175 }
184 176
185 LOGF("Shorten: Decoded %d samples\n", samplesdone);
186
187 if (ci->request_next_track()) 177 if (ci->request_next_track())
188 goto next_track; 178 goto next_track;
189 179
190 retval = CODEC_OK; 180 return CODEC_OK;
191exit:
192 return retval;
193} 181}