src/audio/SDL_audiotypecvt.c
changeset 10708 f6cd81aab88e
parent 10608 8661c956c368
child 10711 838b7f845f84
equal deleted inserted replaced
10707:28c1a3f9c88b 10708:f6cd81aab88e
   220 SDL_Upsample_Arbitrary(SDL_AudioCVT *cvt, const int channels)
   220 SDL_Upsample_Arbitrary(SDL_AudioCVT *cvt, const int channels)
   221 {
   221 {
   222     const int srcsize = cvt->len_cvt - (64 * channels);
   222     const int srcsize = cvt->len_cvt - (64 * channels);
   223     const int dstsize = (int) (((double)(cvt->len_cvt/(channels*4))) * cvt->rate_incr) * (channels*4);
   223     const int dstsize = (int) (((double)(cvt->len_cvt/(channels*4))) * cvt->rate_incr) * (channels*4);
   224     register int eps = 0;
   224     register int eps = 0;
   225     float *dst = ((float *) (cvt->buf + dstsize)) - 8;
   225     float *dst = ((float *) (cvt->buf + dstsize)) - channels;
   226     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - 8;
   226     const float *src = ((float *) (cvt->buf + cvt->len_cvt)) - channels;
   227     const float *target = ((const float *) cvt->buf);
   227     const float *target = ((const float *) cvt->buf);
   228     const size_t cpy = sizeof (float) * channels;
   228     const size_t cpy = sizeof (float) * channels;
   229     float last_sample[8];
   229     float last_sample[8];
   230     float sample[8];
   230     float sample[8];
   231     int i;
   231     int i;
   239     SDL_memcpy(sample, src, cpy);
   239     SDL_memcpy(sample, src, cpy);
   240     SDL_memcpy(last_sample, src, cpy);
   240     SDL_memcpy(last_sample, src, cpy);
   241 
   241 
   242     while (dst > target) {
   242     while (dst > target) {
   243         SDL_memcpy(dst, sample, cpy);
   243         SDL_memcpy(dst, sample, cpy);
   244         dst -= 8;
   244         dst -= channels;
   245         eps += srcsize;
   245         eps += srcsize;
   246         if ((eps << 1) >= dstsize) {
   246         if ((eps << 1) >= dstsize) {
   247             src -= 8;
   247             src -= channels;
   248             for (i = 0; i < channels; i++) {
   248             for (i = 0; i < channels; i++) {
   249                 sample[i] = (float) ((((double) src[i]) + ((double) last_sample[i])) * 0.5);
   249                 sample[i] = (float) ((((double) src[i]) + ((double) last_sample[i])) * 0.5);
   250             }
   250             }
   251             SDL_memcpy(last_sample, sample, cpy);
   251             SDL_memcpy(last_sample, sample, cpy);
   252             eps -= dstsize;
   252             eps -= dstsize;