Mercurial > sdl-ios-xcode
annotate src/audio/sdlgenaudiocvt.pl @ 3008:786a48f8309c
First shot at autogenerated audio resamplers.
Don't check in a new SDL_audiotypecvt.c yet, though.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 09 Jan 2009 15:41:45 +0000 |
parents | 1210d5a28e16 |
children | dfd23eb79be9 |
rev | line source |
---|---|
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 #!/usr/bin/perl -w |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
2 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 use warnings; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
4 use strict; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
6 my @audiotypes = qw( |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 U8 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 S8 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
9 U16LSB |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
10 S16LSB |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
11 U16MSB |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
12 S16MSB |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
13 S32LSB |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
14 S32MSB |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
15 F32LSB |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
16 F32MSB |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
17 ); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
18 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
19 my @channels = ( 1, 2, 4, 6, 8 ); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 my %funcs; |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
21 my $custom_converters = 0; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
22 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
23 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
24 sub getTypeConvertHashId { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
25 my ($from, $to) = @_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
26 return "TYPECONVERTER $from/$to"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
27 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
28 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
29 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
30 sub getResamplerHashId { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
31 my ($from, $channels, $upsample, $multiple) = @_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
32 return "RESAMPLER $from/$channels/$upsample/$multiple"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
33 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
34 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
35 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
36 sub outputHeader { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
37 print <<EOF; |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
38 /* DO NOT EDIT! This file is generated by sdlgenaudiocvt.pl */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 /* |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
40 SDL - Simple DirectMedia Layer |
2859 | 41 Copyright (C) 1997-2009 Sam Lantinga |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
42 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
43 This library is free software; you can redistribute it and/or |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
44 modify it under the terms of the GNU Lesser General Public |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
45 License as published by the Free Software Foundation; either |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
46 version 2.1 of the License, or (at your option) any later version. |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
47 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
48 This library is distributed in the hope that it will be useful, |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
49 but WITHOUT ANY WARRANTY; without even the implied warranty of |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
50 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
51 Lesser General Public License for more details. |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
52 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
53 You should have received a copy of the GNU Lesser General Public |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
54 License along with this library; if not, write to the Free Software |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
55 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
56 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
57 Sam Lantinga |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
58 slouken\@libsdl.org |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
59 */ |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
60 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
61 #include "SDL_config.h" |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
62 #include "SDL_audio.h" |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
63 #include "SDL_audio_c.h" |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
64 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
65 /* *INDENT-OFF* */ |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
66 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
67 EOF |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
68 |
2011
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
69 my @vals = ( 127, 32767, 2147483647 ); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
70 foreach (@vals) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
71 my $val = $_; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
72 my $fval = 1.0 / $val; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
73 print("#define DIVBY${val} ${fval}f\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
74 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
75 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
76 print("\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
77 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
78 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
79 sub outputFooter { |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
80 print <<EOF; |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
81 /* $custom_converters converters generated. */ |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
82 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
83 /* *INDENT-ON* */ |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
84 |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
85 /* vi: set ts=4 sw=4 expandtab: */ |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
86 EOF |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
87 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
88 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
89 sub splittype { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
90 my $t = shift; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
91 my ($signed, $size, $endian) = $t =~ /([USF])(\d+)([LM]SB|)/; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
92 my $float = ($signed eq 'F') ? 1 : 0; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
93 $signed = (($float) or ($signed eq 'S')) ? 1 : 0; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
94 $endian = 'NONE' if ($endian eq ''); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
95 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
96 my $ctype = ''; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
97 if ($float) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
98 $ctype = (($size == 32) ? 'float' : 'double'); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
99 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 $ctype = (($signed) ? 'S' : 'U') . "int${size}"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
101 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
102 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
103 return ($signed, $float, $size, $endian, $ctype); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
104 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
105 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
106 sub getSwapFunc { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
107 my ($size, $signed, $float, $endian, $val) = @_; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
108 my $BEorLE = (($endian eq 'MSB') ? 'BE' : 'LE'); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
109 my $code = ''; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
110 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
111 if ($float) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
112 $code = "SDL_SwapFloat${BEorLE}($val)"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
113 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
114 if ($size > 8) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
115 $code = "SDL_Swap${BEorLE}${size}($val)"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
116 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
117 $code = $val; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
118 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
119 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
120 if (($signed) and (!$float)) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
121 $code = "((Sint${size}) $code)"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
122 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
123 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
124 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
125 return "${code}"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
126 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
127 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
128 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
129 sub maxIntVal { |
2011
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
130 my $size = shift; |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
131 if ($size == 8) { |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
132 return 0x7F; |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
133 } elsif ($size == 16) { |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
134 return 0x7FFF; |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
135 } elsif ($size == 32) { |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
136 return 0x7FFFFFFF; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
137 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
138 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
139 die("bug in script.\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
140 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
141 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
142 sub getFloatToIntMult { |
2011
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
143 my $size = shift; |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
144 my $val = maxIntVal($size) . '.0'; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
145 $val .= 'f' if ($size < 32); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
146 return $val; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
147 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
148 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
149 sub getIntToFloatDivBy { |
2011
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
150 my $size = shift; |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
151 return 'DIVBY' . maxIntVal($size); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
152 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
153 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
154 sub getSignFlipVal { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
155 my $size = shift; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
156 if ($size == 8) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
157 return '0x80'; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
158 } elsif ($size == 16) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 return '0x8000'; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
160 } elsif ($size == 32) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
161 return '0x80000000'; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
162 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
163 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
164 die("bug in script.\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
165 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
166 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
167 sub buildCvtFunc { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
168 my ($from, $to) = @_; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
169 my ($fsigned, $ffloat, $fsize, $fendian, $fctype) = splittype($from); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 my ($tsigned, $tfloat, $tsize, $tendian, $tctype) = splittype($to); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
171 my $diffs = 0; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
172 $diffs++ if ($fsize != $tsize); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
173 $diffs++ if ($fsigned != $tsigned); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
174 $diffs++ if ($ffloat != $tfloat); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
175 $diffs++ if ($fendian ne $tendian); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
176 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
177 return if ($diffs == 0); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
178 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
179 my $hashid = getTypeConvertHashId($from, $to); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
180 if (1) { # !!! FIXME: if ($diffs > 1) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
181 my $sym = "SDL_Convert_${from}_to_${to}"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
182 $funcs{$hashid} = $sym; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
183 $custom_converters++; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
184 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
185 # Always unsigned for ints, for possible byteswaps. |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
186 my $srctype = (($ffloat) ? 'float' : "Uint${fsize}"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
187 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
188 print <<EOF; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
189 static void SDLCALL |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
190 ${sym}(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
191 { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
192 int i; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
193 const $srctype *src; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
194 $tctype *dst; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
195 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
196 #ifdef DEBUG_CONVERT |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
197 fprintf(stderr, "Converting AUDIO_${from} to AUDIO_${to}.\\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
198 #endif |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
199 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
200 EOF |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
201 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
202 if ($fsize < $tsize) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
203 my $mult = $tsize / $fsize; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
204 print <<EOF; |
2956
1210d5a28e16
Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents:
2955
diff
changeset
|
205 src = ((const $srctype *) (cvt->buf + cvt->len_cvt)) - 1; |
1210d5a28e16
Fixed off-by-one in audio converters, when growing a data type's size.
Ryan C. Gordon <icculus@icculus.org>
parents:
2955
diff
changeset
|
206 dst = (($tctype *) (cvt->buf + cvt->len_cvt * $mult)) - 1; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
207 for (i = cvt->len_cvt / sizeof ($srctype); i; --i, --src, --dst) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
208 EOF |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
209 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
210 print <<EOF; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
211 src = (const $srctype *) cvt->buf; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
212 dst = ($tctype *) cvt->buf; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
213 for (i = cvt->len_cvt / sizeof ($srctype); i; --i, ++src, ++dst) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
214 EOF |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
215 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
216 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
217 # Have to convert to/from float/int. |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
218 # !!! FIXME: cast through double for int32<->float? |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
219 my $code = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, '*src'); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
220 if ($ffloat != $tfloat) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
221 if ($ffloat) { |
2011
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
222 my $mult = getFloatToIntMult($tsize); |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
223 if (!$tsigned) { # bump from -1.0f/1.0f to 0.0f/2.0f |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
224 $code = "($code + 1.0f)"; |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
225 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
226 $code = "(($tctype) ($code * $mult))"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
227 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
228 # $divby will be the reciprocal, to avoid pipeline stalls |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
229 # from floating point division...so multiply it. |
2011
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
230 my $divby = getIntToFloatDivBy($fsize); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
231 $code = "(((float) $code) * $divby)"; |
2011
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
232 if (!$fsigned) { # bump from 0.0f/2.0f to -1.0f/1.0f. |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
233 $code = "($code - 1.0f)"; |
b2b7154ce016
Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents:
1985
diff
changeset
|
234 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
235 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
236 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
237 # All integer conversions here. |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
238 if ($fsigned != $tsigned) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
239 my $signflipval = getSignFlipVal($fsize); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
240 $code = "(($code) ^ $signflipval)"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
241 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
242 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
243 my $shiftval = abs($fsize - $tsize); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
244 if ($fsize < $tsize) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
245 $code = "((($tctype) $code) << $shiftval)"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
246 } elsif ($fsize > $tsize) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
247 $code = "(($tctype) ($code >> $shiftval))"; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
248 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
249 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
250 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
251 my $swap = getSwapFunc($tsize, $tsigned, $tfloat, $tendian, 'val'); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
252 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
253 print <<EOF; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
254 const $tctype val = $code; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
255 *dst = ${swap}; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
256 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
257 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
258 EOF |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
259 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
260 if ($fsize > $tsize) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
261 my $divby = $fsize / $tsize; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
262 print(" cvt->len_cvt /= $divby;\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
263 } elsif ($fsize < $tsize) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
264 my $mult = $tsize / $fsize; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
265 print(" cvt->len_cvt *= $mult;\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
266 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
267 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
268 print <<EOF; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
269 if (cvt->filters[++cvt->filter_index]) { |
2955
2692999d5271
Avoid unnecessary assignment in generated audio type converters.
Ryan C. Gordon <icculus@icculus.org>
parents:
2859
diff
changeset
|
270 cvt->filters[cvt->filter_index] (cvt, AUDIO_$to); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
271 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
272 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
273 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
274 EOF |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
275 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
276 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
277 if ($fsigned != $tsigned) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
278 $funcs{$hashid} = 'SDL_ConvertSigned'; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
279 } elsif ($ffloat != $tfloat) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
280 $funcs{$hashid} = 'SDL_ConvertFloat'; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
281 } elsif ($fsize != $tsize) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
282 $funcs{$hashid} = 'SDL_ConvertSize'; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
283 } elsif ($fendian ne $tendian) { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
284 $funcs{$hashid} = 'SDL_ConvertEndian'; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
285 } else { |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
286 die("error in script.\n"); |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
287 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
288 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
289 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
290 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
291 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
292 sub buildTypeConverters { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
293 foreach (@audiotypes) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
294 my $from = $_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
295 foreach (@audiotypes) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
296 my $to = $_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
297 buildCvtFunc($from, $to); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
298 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
299 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
300 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
301 print "const SDL_AudioTypeFilters sdl_audio_type_filters[] =\n{\n"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
302 foreach (@audiotypes) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
303 my $from = $_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
304 foreach (@audiotypes) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
305 my $to = $_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
306 if ($from ne $to) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
307 my $hashid = getTypeConvertHashId($from, $to); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
308 my $sym = $funcs{$hashid}; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
309 print(" { AUDIO_$from, AUDIO_$to, $sym },\n"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
310 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
311 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
312 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
313 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
314 print "};\n\n\n"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
315 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
316 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
317 sub getBiggerCtype { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
318 my ($isfloat, $size) = @_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
319 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
320 if ($isfloat) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
321 if ($size == 32) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
322 return 'double'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
323 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
324 die("bug in script.\n"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
325 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
326 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
327 if ($size == 8) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
328 return 'Sint16'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
329 } elsif ($size == 16) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
330 return 'Sint32' |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
331 } elsif ($size == 32) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
332 return 'Sint64' |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
333 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
334 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
335 die("bug in script.\n"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
336 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
337 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
338 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
339 # These handle arbitrary resamples...44100Hz to 48000Hz, for example. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
340 # Man, this code is skanky. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
341 sub buildArbitraryResampleFunc { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
342 # !!! FIXME: we do a lot of unnecessary and ugly casting in here, due to getSwapFunc(). |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
343 my ($from, $channels, $upsample) = @_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
344 my ($fsigned, $ffloat, $fsize, $fendian, $fctype) = splittype($from); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
345 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
346 my $bigger = getBiggerCtype($ffloat, $fsize); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
347 my $interp = ($ffloat) ? '* 0.5' : '>> 1'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
348 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
349 my $resample = ($upsample) ? 'Upsample' : 'Downsample'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
350 my $hashid = getResamplerHashId($from, $channels, $upsample, 0); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
351 my $sym = "SDL_${resample}_${from}_${channels}c"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
352 $funcs{$hashid} = $sym; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
353 $custom_converters++; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
354 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
355 my $fudge = $fsize * $channels * 2; # !!! FIXME |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
356 my $eps_adjust = ($upsample) ? 'dstsize' : 'srcsize'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
357 my $incr = ''; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
358 my $incr2 = ''; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
359 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
360 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
361 # !!! FIXME: DEBUG_CONVERT should report frequencies. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
362 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
363 static void SDLCALL |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
364 ${sym}(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
365 { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
366 #ifdef DEBUG_CONVERT |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
367 fprintf(stderr, "$resample arbitrary (x%f) AUDIO_${from}, ${channels} channels.\\n", cvt->rate_incr); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
368 #endif |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
369 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
370 const int srcsize = cvt->len_cvt - $fudge; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
371 const int dstsize = (int) (((double)cvt->len_cvt) * cvt->rate_incr); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
372 register int eps = 0; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
373 EOF |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
374 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
375 # Upsampling (growing the buffer) needs to work backwards, since we |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
376 # overwrite the buffer as we go. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
377 if ($upsample) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
378 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
379 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
380 const $fctype *src = (($fctype *) (cvt->buf + cvt->len_cvt)) - $channels; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
381 const $fctype *target = ((const $fctype *) cvt->buf) - $channels; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
382 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
383 } else { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
384 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
385 $fctype *dst = ($fctype *) cvt->buf; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
386 const $fctype *src = ($fctype *) cvt->buf; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
387 const $fctype *target = (const $fctype *) (cvt->buf + dstsize); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
388 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
389 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
390 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
391 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
392 my $idx = ($upsample) ? (($channels - $i) - 1) : $i; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
393 my $val = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, "src[$idx]"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
394 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
395 $fctype sample${idx} = $val; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
396 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
397 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
398 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
399 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
400 my $idx = ($upsample) ? (($channels - $i) - 1) : $i; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
401 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
402 $fctype last_sample${idx} = sample${idx}; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
403 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
404 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
405 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
406 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
407 while (dst != target) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
408 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
409 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
410 if ($upsample) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
411 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
412 # !!! FIXME: don't do this swap every write, just when the samples change. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
413 my $idx = (($channels - $i) - 1); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
414 my $val = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, "sample${idx}"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
415 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
416 dst[$idx] = $val; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
417 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
418 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
419 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
420 $incr = ($channels == 1) ? 'dst--' : "dst -= $channels"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
421 $incr2 = ($channels == 1) ? 'src--' : "src -= $channels"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
422 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
423 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
424 $incr; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
425 eps += srcsize; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
426 if ((eps << 1) >= dstsize) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
427 $incr2; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
428 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
429 } else { # downsample. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
430 $incr = ($channels == 1) ? 'src++' : "src += $channels"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
431 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
432 $incr; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
433 eps += dstsize; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
434 if ((eps << 1) >= srcsize) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
435 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
436 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
437 my $val = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, "sample${i}"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
438 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
439 dst[$i] = $val; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
440 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
441 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
442 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
443 $incr = ($channels == 1) ? 'dst++' : "dst += $channels"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
444 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
445 $incr; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
446 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
447 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
448 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
449 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
450 my $idx = ($upsample) ? (($channels - $i) - 1) : $i; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
451 my $swapped = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, "src[$idx]"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
452 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
453 sample${idx} = ($fctype) (((($bigger) $swapped) + (($bigger) last_sample${idx})) $interp); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
454 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
455 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
456 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
457 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
458 my $idx = ($upsample) ? (($channels - $i) - 1) : $i; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
459 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
460 last_sample${idx} = sample${idx}; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
461 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
462 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
463 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
464 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
465 eps -= $eps_adjust; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
466 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
467 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
468 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
469 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
470 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
471 cvt->len_cvt = dstsize; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
472 if (cvt->filters[++cvt->filter_index]) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
473 cvt->filters[cvt->filter_index] (cvt, format); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
474 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
475 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
476 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
477 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
478 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
479 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
480 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
481 # These handle clean resamples...doubling and quadrupling the sample rate, etc. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
482 sub buildMultipleResampleFunc { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
483 # !!! FIXME: we do a lot of unnecessary and ugly casting in here, due to getSwapFunc(). |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
484 my ($from, $channels, $upsample, $multiple) = @_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
485 my ($fsigned, $ffloat, $fsize, $fendian, $fctype) = splittype($from); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
486 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
487 my $bigger = getBiggerCtype($ffloat, $fsize); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
488 my $interp = ($ffloat) ? '* 0.5' : '>> 1'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
489 my $interp2 = ($ffloat) ? '* 0.25' : '>> 2'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
490 my $mult3 = ($ffloat) ? '3.0' : '3'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
491 my $lencvtop = ($upsample) ? '*' : '/'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
492 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
493 my $resample = ($upsample) ? 'Upsample' : 'Downsample'; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
494 my $hashid = getResamplerHashId($from, $channels, $upsample, $multiple); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
495 my $sym = "SDL_${resample}_${from}_${channels}c_x${multiple}"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
496 $funcs{$hashid} = $sym; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
497 $custom_converters++; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
498 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
499 # !!! FIXME: DEBUG_CONVERT should report frequencies. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
500 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
501 static void SDLCALL |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
502 ${sym}(SDL_AudioCVT * cvt, SDL_AudioFormat format) |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
503 { |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
504 #ifdef DEBUG_CONVERT |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
505 fprintf(stderr, "$resample (x${multiple}) AUDIO_${from}, ${channels} channels.\\n"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
506 #endif |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
507 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
508 const int srcsize = cvt->len_cvt; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
509 const int dstsize = cvt->len_cvt $lencvtop $multiple; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
510 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
511 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
512 # Upsampling (growing the buffer) needs to work backwards, since we |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
513 # overwrite the buffer as we go. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
514 if ($upsample) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
515 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
516 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
517 const $fctype *src = (($fctype *) (cvt->buf + cvt->len_cvt)) - $channels; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
518 const $fctype *target = ((const $fctype *) cvt->buf) - $channels; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
519 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
520 } else { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
521 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
522 $fctype *dst = ($fctype *) cvt->buf; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
523 const $fctype *src = ($fctype *) cvt->buf; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
524 const $fctype *target = (const $fctype *) (cvt->buf + dstsize); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
525 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
526 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
527 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
528 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
529 my $idx = ($upsample) ? (($channels - $i) - 1) : $i; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
530 my $val = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, "src[$idx]"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
531 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
532 $bigger last_sample${idx} = ($bigger) $val; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
533 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
534 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
535 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
536 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
537 while (dst != target) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
538 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
539 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
540 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
541 my $idx = ($upsample) ? (($channels - $i) - 1) : $i; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
542 my $val = getSwapFunc($fsize, $fsigned, $ffloat, $fendian, "src[$idx]"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
543 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
544 const $bigger sample${idx} = ($bigger) $val; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
545 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
546 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
547 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
548 my $incr = ''; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
549 if ($upsample) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
550 $incr = ($channels == 1) ? 'src--' : "src -= $channels"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
551 } else { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
552 my $amount = $channels * $multiple; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
553 $incr = "src += $amount"; # can't ever be 1, so no "++" version. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
554 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
555 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
556 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
557 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
558 $incr; |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
559 EOF |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
560 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
561 # !!! FIXME: This really begs for some Altivec or SSE, etc. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
562 if ($upsample) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
563 if ($multiple == 2) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
564 for (my $i = $channels-1; $i >= 0; $i--) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
565 my $dsti = $i + $channels; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
566 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
567 dst[$dsti] = ($fctype) ((sample${i} + last_sample${i}) $interp); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
568 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
569 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
570 for (my $i = $channels-1; $i >= 0; $i--) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
571 my $dsti = $i; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
572 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
573 dst[$dsti] = ($fctype) sample${i}; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
574 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
575 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
576 } elsif ($multiple == 4) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
577 for (my $i = $channels-1; $i >= 0; $i--) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
578 my $dsti = $i + ($channels * 3); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
579 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
580 dst[$dsti] = ($fctype) sample${i}; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
581 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
582 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
583 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
584 for (my $i = $channels-1; $i >= 0; $i--) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
585 my $dsti = $i + ($channels * 2); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
586 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
587 dst[$dsti] = ($fctype) ((($mult3 * sample${i}) + last_sample${i}) $interp2); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
588 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
589 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
590 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
591 for (my $i = $channels-1; $i >= 0; $i--) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
592 my $dsti = $i + ($channels * 1); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
593 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
594 dst[$dsti] = ($fctype) ((sample${i} + last_sample${i}) $interp); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
595 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
596 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
597 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
598 for (my $i = $channels-1; $i >= 0; $i--) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
599 my $dsti = $i + ($channels * 0); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
600 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
601 dst[$dsti] = ($fctype) ((sample${i} + ($mult3 * last_sample${i})) $interp2); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
602 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
603 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
604 } else { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
605 die('bug in program.'); # we only handle x2 and x4. |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
606 } |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
607 } else { # downsample. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
608 if ($multiple == 2) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
609 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
610 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
611 dst[$i] = ($fctype) ((sample${i} + last_sample${i}) $interp); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
612 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
613 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
614 } elsif ($multiple == 4) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
615 # !!! FIXME: interpolate all 4 samples? |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
616 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
617 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
618 dst[$i] = ($fctype) ((sample${i} + last_sample${i}) $interp); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
619 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
620 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
621 } else { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
622 die('bug in program.'); # we only handle x2 and x4. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
623 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
624 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
625 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
626 for (my $i = 0; $i < $channels; $i++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
627 my $idx = ($upsample) ? (($channels - $i) - 1) : $i; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
628 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
629 last_sample${idx} = sample${idx}; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
630 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
631 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
632 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
633 if ($upsample) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
634 my $amount = $channels * $multiple; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
635 $incr = "dst -= $amount"; # can't ever be 1, so no "--" version. |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
636 } else { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
637 $incr = ($channels == 1) ? 'dst++' : "dst += $channels"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
638 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
639 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
640 print <<EOF; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
641 $incr; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
642 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
643 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
644 cvt->len_cvt = dstsize; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
645 if (cvt->filters[++cvt->filter_index]) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
646 cvt->filters[cvt->filter_index] (cvt, format); |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
647 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
648 } |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
649 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
650 EOF |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
651 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
652 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
653 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
654 sub buildResamplers { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
655 foreach (@audiotypes) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
656 my $from = $_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
657 foreach (@channels) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
658 my $channel = $_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
659 for (my $multiple = 2; $multiple <= 4; $multiple += 2) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
660 buildMultipleResampleFunc($from, $channel, 1, $multiple); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
661 buildMultipleResampleFunc($from, $channel, 0, $multiple); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
662 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
663 buildArbitraryResampleFunc($from, $channel, 1); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
664 buildArbitraryResampleFunc($from, $channel, 0); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
665 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
666 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
667 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
668 print "const SDL_AudioRateFilters sdl_audio_rate_filters[] =\n{\n"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
669 foreach (@audiotypes) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
670 my $from = $_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
671 foreach (@channels) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
672 my $channel = $_; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
673 for (my $multiple = 0; $multiple <= 4; $multiple += 2) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
674 for (my $upsample = 0; $upsample <= 1; $upsample++) { |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
675 my $hashid = getResamplerHashId($from, $channel, $upsample, $multiple); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
676 my $sym = $funcs{$hashid}; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
677 print(" { AUDIO_$from, $channel, $upsample, $multiple, $sym },\n"); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
678 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
679 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
680 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
681 } |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
682 |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
683 print "};\n\n"; |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
684 } |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
685 |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
686 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
687 # mainline ... |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
688 |
3008
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
689 outputHeader(); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
690 buildTypeConverters(); |
786a48f8309c
First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents:
2956
diff
changeset
|
691 buildResamplers(); |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
692 outputFooter(); |
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
693 |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
694 exit 0; |
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
695 |
1985
8055185ae4ed
Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents:
1982
diff
changeset
|
696 # end of sdlgenaudiocvt.pl ... |
1982
3b4ce57c6215
First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
697 |