diff options
-rw-r--r-- | apps/plugins/wv2wav.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/apps/plugins/wv2wav.c b/apps/plugins/wv2wav.c index 73f71cd962..1a3cd83720 100644 --- a/apps/plugins/wv2wav.c +++ b/apps/plugins/wv2wav.c | |||
@@ -32,7 +32,7 @@ static file_info_struct file_info; | |||
32 | static long temp_buffer [BUFFER_SIZE]; | 32 | static long temp_buffer [BUFFER_SIZE]; |
33 | 33 | ||
34 | /* Reformat samples from longs in processor's native endian mode to | 34 | /* Reformat samples from longs in processor's native endian mode to |
35 | little-endian data with (possibly) less than 4 bytes / sample. */ | 35 | little-endian data with 2 bytes / sample. */ |
36 | uchar* format_samples (int bps, uchar *dst, long *src, ulong samcnt) | 36 | uchar* format_samples (int bps, uchar *dst, long *src, ulong samcnt) |
37 | { | 37 | { |
38 | long temp; | 38 | long temp; |
@@ -41,7 +41,10 @@ uchar* format_samples (int bps, uchar *dst, long *src, ulong samcnt) | |||
41 | { | 41 | { |
42 | case 1: | 42 | case 1: |
43 | while (samcnt--) | 43 | while (samcnt--) |
44 | *dst++ = *src++ + 128; | 44 | { |
45 | *dst++ = (uchar)(temp = (*src++ << 8)); | ||
46 | *dst++ = (uchar)(temp >> 8); | ||
47 | } | ||
45 | 48 | ||
46 | break; | 49 | break; |
47 | 50 | ||
@@ -57,9 +60,8 @@ uchar* format_samples (int bps, uchar *dst, long *src, ulong samcnt) | |||
57 | case 3: | 60 | case 3: |
58 | while (samcnt--) | 61 | while (samcnt--) |
59 | { | 62 | { |
60 | *dst++ = (uchar)(temp = *src++); | 63 | *dst++ = (uchar)(temp = (*src++ >> 8)); |
61 | *dst++ = (uchar)(temp >> 8); | 64 | *dst++ = (uchar)(temp >> 8); |
62 | *dst++ = (uchar)(temp >> 16); | ||
63 | } | 65 | } |
64 | 66 | ||
65 | break; | 67 | break; |
@@ -67,10 +69,8 @@ uchar* format_samples (int bps, uchar *dst, long *src, ulong samcnt) | |||
67 | case 4: | 69 | case 4: |
68 | while (samcnt--) | 70 | while (samcnt--) |
69 | { | 71 | { |
70 | *dst++ = (uchar)(temp = *src++); | 72 | *dst++ = (uchar)(temp = (*src++ >> 16)); |
71 | *dst++ = (uchar)(temp >> 8); | 73 | *dst++ = (uchar)(temp >> 8); |
72 | *dst++ = (uchar)(temp >> 16); | ||
73 | *dst++ = (uchar)(temp >> 24); | ||
74 | } | 74 | } |
75 | 75 | ||
76 | break; | 76 | break; |
@@ -83,7 +83,6 @@ uchar* format_samples (int bps, uchar *dst, long *src, ulong samcnt) | |||
83 | void wvpack_decode_data(file_info_struct* file_info, int samples_to_decode, WavpackContext **wpc) | 83 | void wvpack_decode_data(file_info_struct* file_info, int samples_to_decode, WavpackContext **wpc) |
84 | { | 84 | { |
85 | int bps = WavpackGetBytesPerSample(*wpc); | 85 | int bps = WavpackGetBytesPerSample(*wpc); |
86 | |||
87 | /* nothing to decode */ | 86 | /* nothing to decode */ |
88 | if (!samples_to_decode) | 87 | if (!samples_to_decode) |
89 | { | 88 | { |
@@ -98,9 +97,20 @@ void wvpack_decode_data(file_info_struct* file_info, int samples_to_decode, Wavp | |||
98 | /* update some infos */ | 97 | /* update some infos */ |
99 | file_info->current_sample += samples_unpacked; | 98 | file_info->current_sample += samples_unpacked; |
100 | 99 | ||
101 | format_samples (bps, (uchar *) temp_buffer, temp_buffer, samples_unpacked *= file_info->channels); | 100 | /* for now, convert mono to stereo here, in place */ |
102 | 101 | if (WavpackGetReducedChannels (*wpc) == 1) { | |
103 | rb->write(file_info->outfile, temp_buffer, samples_unpacked * bps); | 102 | long *dst = temp_buffer + (samples_unpacked * 2); |
103 | long *src = temp_buffer + samples_unpacked; | ||
104 | long count = samples_unpacked; | ||
105 | |||
106 | while (count--) { | ||
107 | *--dst = *--src; | ||
108 | *--dst = *src; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | format_samples (bps, (uchar *) temp_buffer, temp_buffer, samples_unpacked * file_info->channels); | ||
113 | rb->write(file_info->outfile, temp_buffer, samples_unpacked * 4); | ||
104 | } | 114 | } |
105 | } | 115 | } |
106 | 116 | ||
@@ -118,7 +128,7 @@ long Read(void* buffer, long size) | |||
118 | } | 128 | } |
119 | else | 129 | else |
120 | { | 130 | { |
121 | memcpy(buffer, &filebuf[file_info.curpos], (file_info.filesize-1-file_info.curpos)); | 131 | memcpy(buffer, &filebuf[file_info.curpos], file_info.filesize-file_info.curpos); |
122 | file_info.curpos = file_info.filesize; | 132 | file_info.curpos = file_info.filesize; |
123 | } | 133 | } |
124 | 134 | ||
@@ -151,10 +161,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* file) | |||
151 | return PLUGIN_ERROR; | 161 | return PLUGIN_ERROR; |
152 | } | 162 | } |
153 | 163 | ||
154 | /* grap/set some infos */ | 164 | /* grap/set some infos (forcing some to temp values) */ |
155 | file_info.channels = WavpackGetReducedChannels(wpc); | 165 | file_info.channels = 2; |
156 | file_info.total_samples = WavpackGetNumSamples(wpc); | 166 | file_info.total_samples = WavpackGetNumSamples(wpc); |
157 | file_info.bitspersample = WavpackGetBitsPerSample(wpc); | 167 | file_info.bitspersample = 16; |
158 | file_info.samplerate = WavpackGetSampleRate(wpc); | 168 | file_info.samplerate = WavpackGetSampleRate(wpc); |
159 | file_info.current_sample = 0; | 169 | file_info.current_sample = 0; |
160 | 170 | ||
@@ -175,8 +185,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* file) | |||
175 | } | 185 | } |
176 | } | 186 | } |
177 | 187 | ||
188 | close_wav(&file_info); | ||
189 | |||
178 | /* do some last checks */ | 190 | /* do some last checks */ |
179 | if ((WavpackGetNumSamples (wpc) != (ulong) -1) && (file_info.total_samples != WavpackGetNumSamples (wpc))) | 191 | if ((WavpackGetNumSamples (wpc) != (ulong) -1) && (file_info.current_sample != WavpackGetNumSamples (wpc))) |
180 | { | 192 | { |
181 | rb->splash(HZ*2, true, "incorrect number of samples!"); | 193 | rb->splash(HZ*2, true, "incorrect number of samples!"); |
182 | return PLUGIN_ERROR; | 194 | return PLUGIN_ERROR; |
@@ -187,7 +199,6 @@ enum plugin_status plugin_start(struct plugin_api* api, void* file) | |||
187 | return PLUGIN_ERROR; | 199 | return PLUGIN_ERROR; |
188 | } | 200 | } |
189 | 201 | ||
190 | close_wav(&file_info); | ||
191 | rb->splash(HZ*2, true, "FINISHED!"); | 202 | rb->splash(HZ*2, true, "FINISHED!"); |
192 | 203 | ||
193 | return PLUGIN_OK; | 204 | return PLUGIN_OK; |