src/audio/SDL_audiocvt.c
changeset 12803 70d338e248c8
parent 12503 806492103856
child 12807 a39d8cdf50f4
equal deleted inserted replaced
12802:f9a9d6c76b21 12803:70d338e248c8
   716     /*float *dst = (float *) cvt->buf;
   716     /*float *dst = (float *) cvt->buf;
   717     const int dstlen = (cvt->len * cvt->len_mult);*/
   717     const int dstlen = (cvt->len * cvt->len_mult);*/
   718     /* !!! FIXME: remove this if we can get the resampler to work in-place again. */
   718     /* !!! FIXME: remove this if we can get the resampler to work in-place again. */
   719     float *dst = (float *) (cvt->buf + srclen);
   719     float *dst = (float *) (cvt->buf + srclen);
   720     const int dstlen = (cvt->len * cvt->len_mult) - srclen;
   720     const int dstlen = (cvt->len * cvt->len_mult) - srclen;
   721     const int paddingsamples = (ResamplerPadding(inrate, outrate) * chans);
   721     const int requestedpadding = ResamplerPadding(inrate, outrate);
       
   722     int paddingsamples;
   722     float *padding;
   723     float *padding;
   723 
   724 
       
   725     if (requestedpadding < INT32_MAX / chans) {
       
   726         paddingsamples = requestedpadding * chans;
       
   727     } else {
       
   728         paddingsamples = 0;
       
   729     }
   724     SDL_assert(format == AUDIO_F32SYS);
   730     SDL_assert(format == AUDIO_F32SYS);
   725 
   731 
   726     /* we keep no streaming state here, so pad with silence on both ends. */
   732     /* we keep no streaming state here, so pad with silence on both ends. */
   727     padding = (float *) SDL_calloc(paddingsamples ? paddingsamples : 1, sizeof (float));
   733     padding = (float *) SDL_calloc(paddingsamples ? paddingsamples : 1, sizeof (float));
   728     if (!padding) {
   734     if (!padding) {
   887         return SDL_SetError("Invalid destination format");
   893         return SDL_SetError("Invalid destination format");
   888     } else if (!SDL_SupportedChannelCount(src_channels)) {
   894     } else if (!SDL_SupportedChannelCount(src_channels)) {
   889         return SDL_SetError("Invalid source channels");
   895         return SDL_SetError("Invalid source channels");
   890     } else if (!SDL_SupportedChannelCount(dst_channels)) {
   896     } else if (!SDL_SupportedChannelCount(dst_channels)) {
   891         return SDL_SetError("Invalid destination channels");
   897         return SDL_SetError("Invalid destination channels");
   892     } else if (src_rate == 0) {
   898     } else if (src_rate <= 0) {
   893         return SDL_SetError("Source rate is zero");
   899         return SDL_SetError("Source rate is equal to or less than zero");
   894     } else if (dst_rate == 0) {
   900     } else if (dst_rate <= 0) {
   895         return SDL_SetError("Destination rate is zero");
   901         return SDL_SetError("Destination rate is equal to or less than zero");
       
   902     } else if (src_rate >= INT32_MAX / RESAMPLER_SAMPLES_PER_ZERO_CROSSING) {
       
   903         return SDL_SetError("Source rate is too high");
       
   904     } else if (dst_rate >= INT32_MAX / RESAMPLER_SAMPLES_PER_ZERO_CROSSING) {
       
   905         return SDL_SetError("Destination rate is too high");
   896     }
   906     }
   897 
   907 
   898 #if DEBUG_CONVERT
   908 #if DEBUG_CONVERT
   899     printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n",
   909     printf("Build format %04x->%04x, channels %u->%u, rate %d->%d\n",
   900            src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate);
   910            src_fmt, dst_fmt, src_channels, dst_channels, src_rate, dst_rate);