src/audio/sdlgenaudiocvt.pl
changeset 4889 8c9cbb623d55
parent 3602 bfa8d34ce03a
child 5262 b530ef003506
equal deleted inserted replaced
4887:0a77d2fc95ad 4889:8c9cbb623d55
    36 sub outputHeader {
    36 sub outputHeader {
    37     print <<EOF;
    37     print <<EOF;
    38 /* DO NOT EDIT!  This file is generated by sdlgenaudiocvt.pl */
    38 /* DO NOT EDIT!  This file is generated by sdlgenaudiocvt.pl */
    39 /*
    39 /*
    40     SDL - Simple DirectMedia Layer
    40     SDL - Simple DirectMedia Layer
    41     Copyright (C) 1997-2009 Sam Lantinga
    41     Copyright (C) 1997-2010 Sam Lantinga
    42 
    42 
    43     This library is free software; you can redistribute it and/or
    43     This library is free software; you can redistribute it and/or
    44     modify it under the terms of the GNU Lesser General Public
    44     modify it under the terms of the GNU Lesser General Public
    45     License as published by the Free Software Foundation; either
    45     License as published by the Free Software Foundation; either
    46     version 2.1 of the License, or (at your option) any later version.
    46     version 2.1 of the License, or (at your option) any later version.
   398     const int srcsize = cvt->len_cvt - $fudge;
   398     const int srcsize = cvt->len_cvt - $fudge;
   399     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
   399     const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr);
   400     register int eps = 0;
   400     register int eps = 0;
   401 EOF
   401 EOF
   402 
   402 
       
   403     my $endcomparison = '!=';
       
   404 
   403     # Upsampling (growing the buffer) needs to work backwards, since we
   405     # Upsampling (growing the buffer) needs to work backwards, since we
   404     #  overwrite the buffer as we go.
   406     #  overwrite the buffer as we go.
   405     if ($upsample) {
   407     if ($upsample) {
       
   408         $endcomparison = '>';  # dst > target
   406         print <<EOF;
   409         print <<EOF;
   407     $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
   410     $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
   408     const $fctype *src = (($fctype *) (cvt->buf + cvt->len_cvt)) - $channels;
   411     const $fctype *src = (($fctype *) (cvt->buf + cvt->len_cvt)) - $channels;
   409     const $fctype *target = ((const $fctype *) cvt->buf) - $channels;
   412     const $fctype *target = ((const $fctype *) cvt->buf) - $channels;
   410 EOF
   413 EOF
   411     } else {
   414     } else {
       
   415         $endcomparison = '<';  # dst < target
   412         print <<EOF;
   416         print <<EOF;
   413     $fctype *dst = ($fctype *) cvt->buf;
   417     $fctype *dst = ($fctype *) cvt->buf;
   414     const $fctype *src = ($fctype *) cvt->buf;
   418     const $fctype *src = ($fctype *) cvt->buf;
   415     const $fctype *target = (const $fctype *) (cvt->buf + dstsize);
   419     const $fctype *target = (const $fctype *) (cvt->buf + dstsize);
   416 EOF
   420 EOF
   430     $fctype last_sample${idx} = sample${idx};
   434     $fctype last_sample${idx} = sample${idx};
   431 EOF
   435 EOF
   432     }
   436     }
   433 
   437 
   434     print <<EOF;
   438     print <<EOF;
   435     while (dst != target) {
   439     while (dst $endcomparison target) {
   436 EOF
   440 EOF
   437 
   441 
   438     if ($upsample) {
   442     if ($upsample) {
   439         for (my $i = 0; $i < $channels; $i++) {
   443         for (my $i = 0; $i < $channels; $i++) {
   440             # !!! FIXME: don't do this swap every write, just when the samples change.
   444             # !!! FIXME: don't do this swap every write, just when the samples change.