src/audio/sdlgenaudiocvt.pl
changeset 2011 b2b7154ce016
parent 1985 8055185ae4ed
child 2859 99210400e8b9
     1.1 --- a/src/audio/sdlgenaudiocvt.pl	Fri Sep 01 18:04:01 2006 +0000
     1.2 +++ b/src/audio/sdlgenaudiocvt.pl	Fri Sep 01 18:07:41 2006 +0000
     1.3 @@ -54,7 +54,7 @@
     1.4  
     1.5  EOF
     1.6  
     1.7 -    my @vals = ( 127, 255, 32767, 65535, 2147483647 );
     1.8 +    my @vals = ( 127, 32767, 2147483647 );
     1.9      foreach (@vals) {
    1.10          my $val = $_;
    1.11          my $fval = 1.0 / $val;
    1.12 @@ -113,38 +113,28 @@
    1.13  
    1.14  
    1.15  sub maxIntVal {
    1.16 -    my ($signed, $size) = @_;
    1.17 -    if ($signed) {
    1.18 -        if ($size == 8) {
    1.19 -            return 0x7F;
    1.20 -        } elsif ($size == 16) {
    1.21 -            return 0x7FFF;
    1.22 -        } elsif ($size == 32) {
    1.23 -            return 0x7FFFFFFF;
    1.24 -        }
    1.25 -    } else {
    1.26 -        if ($size == 8) {
    1.27 -            return 0xFF;
    1.28 -        } elsif ($size == 16) {
    1.29 -            return 0xFFFF;
    1.30 -        } elsif ($size == 32) {
    1.31 -            return 0xFFFFFFFF;
    1.32 -        }
    1.33 +    my $size = shift;
    1.34 +    if ($size == 8) {
    1.35 +        return 0x7F;
    1.36 +    } elsif ($size == 16) {
    1.37 +        return 0x7FFF;
    1.38 +    } elsif ($size == 32) {
    1.39 +        return 0x7FFFFFFF;
    1.40      }
    1.41  
    1.42      die("bug in script.\n");
    1.43  }
    1.44  
    1.45  sub getFloatToIntMult {
    1.46 -    my ($signed, $size) = @_;
    1.47 -    my $val = maxIntVal($signed, $size) . '.0';
    1.48 +    my $size = shift;
    1.49 +    my $val = maxIntVal($size) . '.0';
    1.50      $val .= 'f' if ($size < 32);
    1.51      return $val;
    1.52  }
    1.53  
    1.54  sub getIntToFloatDivBy {
    1.55 -    my ($signed, $size) = @_;
    1.56 -    return 'DIVBY' . maxIntVal($signed, $size);
    1.57 +    my $size = shift;
    1.58 +    return 'DIVBY' . maxIntVal($size);
    1.59  }
    1.60  
    1.61  sub getSignFlipVal {
    1.62 @@ -215,13 +205,19 @@
    1.63          my $code = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, '*src');
    1.64          if ($ffloat != $tfloat) {
    1.65              if ($ffloat) {
    1.66 -                my $mult = getFloatToIntMult($tsigned, $tsize);
    1.67 +                my $mult = getFloatToIntMult($tsize);
    1.68 +                if (!$tsigned) {   # bump from -1.0f/1.0f to 0.0f/2.0f
    1.69 +                    $code = "($code + 1.0f)";
    1.70 +                }
    1.71                  $code = "(($tctype) ($code * $mult))";
    1.72              } else {
    1.73                  # $divby will be the reciprocal, to avoid pipeline stalls
    1.74                  #  from floating point division...so multiply it.
    1.75 -                my $divby = getIntToFloatDivBy($fsigned, $fsize);
    1.76 +                my $divby = getIntToFloatDivBy($fsize);
    1.77                  $code = "(((float) $code) * $divby)";
    1.78 +                if (!$fsigned) {   # bump from 0.0f/2.0f to -1.0f/1.0f.
    1.79 +                    $code = "($code - 1.0f)";
    1.80 +                }
    1.81              }
    1.82          } else {
    1.83              # All integer conversions here.