summaryrefslogtreecommitdiff
path: root/apps/codecs/wavpack.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/codecs/wavpack.c')
-rw-r--r--apps/codecs/wavpack.c76
1 files changed, 6 insertions, 70 deletions
diff --git a/apps/codecs/wavpack.c b/apps/codecs/wavpack.c
index 19c7581e29..ee21347b73 100644
--- a/apps/codecs/wavpack.c
+++ b/apps/codecs/wavpack.c
@@ -24,9 +24,6 @@ CODEC_HEADER
24 24
25static struct codec_api *ci; 25static struct codec_api *ci;
26 26
27#define FORCE_DSP_USE /* fixes some WavPack bugs; adds about 12% to boost ratio
28 (when DSP would not have been used) */
29
30#define BUFFER_SIZE 4096 27#define BUFFER_SIZE 4096
31 28
32static long temp_buffer [BUFFER_SIZE] IBSS_ATTR; 29static long temp_buffer [BUFFER_SIZE] IBSS_ATTR;
@@ -66,8 +63,7 @@ enum codec_status codec_start(struct codec_api* api)
66 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128)); 63 ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, (int *)(1024*128));
67 64
68 ci->configure(DSP_DITHER, (bool *)false); 65 ci->configure(DSP_DITHER, (bool *)false);
69 ci->configure(DSP_SET_STEREO_MODE, (int *)STEREO_INTERLEAVED); 66 ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(27)); // should be 28...
70 ci->configure(DSP_SET_SAMPLE_DEPTH, (int *)(16));
71 67
72 next_track: 68 next_track:
73 69
@@ -79,20 +75,9 @@ enum codec_status codec_start(struct codec_api* api)
79 while (!*ci->taginfo_ready && !ci->stop_codec) 75 while (!*ci->taginfo_ready && !ci->stop_codec)
80 ci->sleep(1); 76 ci->sleep(1);
81 77
82#ifdef FORCE_DSP_USE
83 ci->configure(CODEC_DSP_ENABLE, (bool *)true); 78 ci->configure(CODEC_DSP_ENABLE, (bool *)true);
84 ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency)); 79 ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
85 codec_set_replaygain(ci->id3); 80 codec_set_replaygain(ci->id3);
86#else
87 if (ci->id3->frequency != NATIVE_FREQUENCY ||
88 ci->global_settings->replaygain) {
89 ci->configure(CODEC_DSP_ENABLE, (bool *)true);
90 ci->configure(DSP_SET_FREQUENCY, (long *)(ci->id3->frequency));
91 codec_set_replaygain(ci->id3);
92 }
93 else
94 ci->configure(CODEC_DSP_ENABLE, (bool *)false);
95#endif
96 81
97 /* Create a decoder instance */ 82 /* Create a decoder instance */
98 wpc = WavpackOpenFileInput (read_callback, error); 83 wpc = WavpackOpenFileInput (read_callback, error);
@@ -104,6 +89,7 @@ enum codec_status codec_start(struct codec_api* api)
104 89
105 bps = WavpackGetBytesPerSample (wpc); 90 bps = WavpackGetBytesPerSample (wpc);
106 nchans = WavpackGetReducedChannels (wpc); 91 nchans = WavpackGetReducedChannels (wpc);
92 ci->configure(DSP_SET_STEREO_MODE, nchans == 2 ? (int *)STEREO_INTERLEAVED : (int *)STEREO_MONO);
107 sr_100 = ci->id3->frequency / 100; 93 sr_100 = ci->id3->frequency / 100;
108 94
109 ci->set_elapsed (0); 95 ci->set_elapsed (0);
@@ -141,71 +127,21 @@ enum codec_status codec_start(struct codec_api* api)
141 ci->yield (); 127 ci->yield ();
142 } 128 }
143 129
144 nsamples = WavpackUnpackSamples (wpc, temp_buffer, BUFFER_SIZE / 2); 130 nsamples = WavpackUnpackSamples (wpc, temp_buffer, BUFFER_SIZE / nchans);
145 131
146 if (!nsamples || ci->stop_codec || ci->reload_codec) 132 if (!nsamples || ci->stop_codec || ci->reload_codec)
147 break; 133 break;
148 134
149 /* convert mono to stereo here, in place */ 135 ci->yield ();
150
151 if (nchans == 1) {
152 long *dst = temp_buffer + (nsamples * 2);
153 long *src = temp_buffer + nsamples;
154 long count = nsamples;
155
156 while (count--) {
157 *--dst = *--src;
158 *--dst = *src;
159 if (!(count & 0x7f))
160 ci->yield ();
161 }
162 }
163
164 if (bps == 1) {
165 short *dst = (short *) temp_buffer;
166 long *src = temp_buffer;
167 long count = nsamples;
168
169 while (count--) {
170 *dst++ = *src++ << 8;
171 *dst++ = *src++ << 8;
172 if (!(count & 0x7f))
173 ci->yield ();
174 }
175 }
176 else if (bps == 2) {
177 short *dst = (short *) temp_buffer;
178 long *src = temp_buffer;
179 long count = nsamples;
180
181 while (count--) {
182 *dst++ = *src++;
183 *dst++ = *src++;
184 if (!(count & 0x7f))
185 ci->yield ();
186 }
187 }
188 else {
189 short *dst = (short *) temp_buffer;
190 int shift = (bps - 2) * 8;
191 long *src = temp_buffer;
192 long count = nsamples;
193
194 while (count--) {
195 *dst++ = *src++ >> shift;
196 *dst++ = *src++ >> shift;
197 if (!(count & 0x7f))
198 ci->yield ();
199 }
200 }
201 136
202 if (ci->stop_codec || ci->reload_codec) 137 if (ci->stop_codec || ci->reload_codec)
203 break; 138 break;
204 139
205 while (!ci->pcmbuf_insert ((char *) temp_buffer, nsamples * 4)) 140 while (!ci->pcmbuf_insert ((char *) temp_buffer, nsamples * nchans * 4))
206 ci->sleep (1); 141 ci->sleep (1);
207 142
208 ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10); 143 ci->set_elapsed (WavpackGetSampleIndex (wpc) / sr_100 * 10);
144 ci->yield ();
209 } 145 }
210 146
211 if (ci->request_next_track()) 147 if (ci->request_next_track())