| 214 | // stride number of samples. |
| 215 | |
| 216 | void Dither::Apply(enum DitherType ditherType, |
| 217 | constSamplePtr source, sampleFormat sourceFormat, |
| 218 | samplePtr dest, sampleFormat destFormat, |
| 219 | unsigned int len, |
| 220 | unsigned int sourceStride /* = 1 */, |
| 221 | unsigned int destStride /* = 1 */) |
| 222 | { |
| 223 | unsigned int i; |
| 224 | |
| 225 | // This code is not designed for 16-bit or 64-bit machine |
| 226 | wxASSERT(sizeof(int) == 4); |
| 227 | wxASSERT(sizeof(short) == 2); |
| 228 | |
| 229 | // Check parameters |
| 230 | wxASSERT(source); |
| 231 | wxASSERT(dest); |
| 232 | wxASSERT(len >= 0); |
| 233 | wxASSERT(sourceStride > 0); |
| 234 | wxASSERT(destStride > 0); |
| 235 | |
| 236 | if (len == 0) |
| 237 | return; // nothing to do |
| 238 | |
| 239 | if (destFormat == sourceFormat) |
| 240 | { |
| 241 | // No need to dither, because source and destination |
| 242 | // format are the same. Just copy samples. |
| 243 | if (destStride == 1 && sourceStride == 1) |
| 244 | memcpy(dest, source, len * SAMPLE_SIZE(destFormat)); |
| 245 | else |
| 246 | { |
| 247 | if (sourceFormat == floatSample) |
| 248 | { |
| 249 | auto d = (float*)dest; |
| 250 | auto s = (const float*)source; |
| 251 | |
| 252 | for (i = 0; i < len; i++, d += destStride, s += sourceStride) |
| 253 | *d = *s; |
| 254 | } else |
| 255 | if (sourceFormat == int24Sample) |
| 256 | { |
| 257 | auto d = (int*)dest; |
| 258 | auto s = (const int*)source; |
| 259 | |
| 260 | for (i = 0; i < len; i++, d += destStride, s += sourceStride) |
| 261 | *d = *s; |
| 262 | } else |
| 263 | if (sourceFormat == int16Sample) |
| 264 | { |
| 265 | auto d = (short*)dest; |
| 266 | auto s = (const short*)source; |
| 267 | |
| 268 | for (i = 0; i < len; i++, d += destStride, s += sourceStride) |
| 269 | *d = *s; |
| 270 | } else { |
| 271 | wxASSERT(false); // source format unknown |
| 272 | } |
| 273 | } |
no test coverage detected