annotate src/audio/sdlgenaudiocvt.pl @ 3019:dfd23eb79be9

Allow builds that reduce or eliminate the converters/resamplers. We should probably give options to drop resamplers by channels, too, for developers that know they'll never need more than stereo, etc.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 11 Jan 2009 04:39:09 +0000
parents 786a48f8309c
children 70d876a0b90e
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
99210400e8b9 Updated copyright date
Sam Lantinga <slouken@libsdl.org>
parents: 2011
diff changeset
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
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
65 #ifndef DEBUG_CONVERT
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
66 #define DEBUG_CONVERT 0
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
67 #endif
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
68
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
69
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
70 /* If you can guarantee your data and need space, you can eliminate code... */
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
71
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
72 /* Just build the arbitrary resamplers if you're saving code space. */
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
73 #ifndef LESS_RESAMPLERS
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
74 #define LESS_RESAMPLERS 0
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
75 #endif
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
76
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
77 /* Don't build any resamplers if you're REALLY saving code space. */
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
78 #ifndef NO_RESAMPLERS
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
79 #define NO_RESAMPLERS 0
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
80 #endif
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
81
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
82 /* Don't build any type converters if you're saving code space. */
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
83 #ifndef NO_CONVERTERS
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
84 #define NO_CONVERTERS 0
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
85 #endif
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
86
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
87
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
88 /* *INDENT-OFF* */
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
92 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
93 foreach (@vals) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94 my $val = $_;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 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
96 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
97 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 print("\n");
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
102 sub outputFooter {
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
103 print <<EOF;
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
104 /* $custom_converters converters generated. */
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
105
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
106 /* *INDENT-ON* */
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
107
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
108 /* vi: set ts=4 sw=4 expandtab: */
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
109 EOF
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
110 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 sub splittype {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 my $t = shift;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 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
115 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
116 $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
117 $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
118
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 my $ctype = '';
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 if ($float) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 $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
122 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123 $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
124 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 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
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 getSwapFunc {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 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
131 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
132 my $code = '';
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 if ($float) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 $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
136 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 if ($size > 8) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 $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
139 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140 $code = $val;
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
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 if (($signed) and (!$float)) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 $code = "((Sint${size}) $code)";
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 }
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 return "${code}";
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 sub maxIntVal {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
153 my $size = shift;
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
154 if ($size == 8) {
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
155 return 0x7F;
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
156 } elsif ($size == 16) {
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
157 return 0x7FFF;
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
158 } elsif ($size == 32) {
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
159 return 0x7FFFFFFF;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 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
163 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 sub getFloatToIntMult {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
166 my $size = shift;
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
167 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
168 $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
169 return $val;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 sub getIntToFloatDivBy {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
173 my $size = shift;
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
174 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
175 }
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 sub getSignFlipVal {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178 my $size = shift;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 if ($size == 8) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180 return '0x80';
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 } elsif ($size == 16) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 return '0x8000';
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 } elsif ($size == 32) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 return '0x80000000';
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 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
188 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 sub buildCvtFunc {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 my ($from, $to) = @_;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 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
193 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
194 my $diffs = 0;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 $diffs++ if ($fsize != $tsize);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 $diffs++ if ($fsigned != $tsigned);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 $diffs++ if ($ffloat != $tfloat);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 $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
199
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 return if ($diffs == 0);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
202 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
203 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
204 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
205 $funcs{$hashid} = $sym;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 $custom_converters++;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 # 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
209 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
210
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 print <<EOF;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 static void SDLCALL
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 ${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
214 {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 int i;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 const $srctype *src;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 $tctype *dst;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 #ifdef DEBUG_CONVERT
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 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
221 #endif
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
223 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 if ($fsize < $tsize) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 my $mult = $tsize / $fsize;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 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
228 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
229 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
230 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
231 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 print <<EOF;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 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
235 dst = ($tctype *) cvt->buf;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 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
237 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 # 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
241 # !!! 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
242 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
243 if ($ffloat != $tfloat) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 if ($ffloat) {
2011
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
245 my $mult = getFloatToIntMult($tsize);
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
246 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
247 $code = "($code + 1.0f)";
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
248 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 $code = "(($tctype) ($code * $mult))";
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 # $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
252 # 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
253 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
254 $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
255 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
256 $code = "($code - 1.0f)";
b2b7154ce016 Fixed broken audio conversions between float and unsigned datatypes.
Ryan C. Gordon <icculus@icculus.org>
parents: 1985
diff changeset
257 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 # All integer conversions here.
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 if ($fsigned != $tsigned) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 my $signflipval = getSignFlipVal($fsize);
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 $code = "(($code) ^ $signflipval)";
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 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
267 if ($fsize < $tsize) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 $code = "((($tctype) $code) << $shiftval)";
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 } elsif ($fsize > $tsize) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 $code = "(($tctype) ($code >> $shiftval))";
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 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
275
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 print <<EOF;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 const $tctype val = $code;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 *dst = ${swap};
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 if ($fsize > $tsize) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 my $divby = $fsize / $tsize;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 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
286 } elsif ($fsize < $tsize) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 my $mult = $tsize / $fsize;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 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
289 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 print <<EOF;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 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
293 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
294 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
300 if ($fsigned != $tsigned) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
301 $funcs{$hashid} = 'SDL_ConvertSigned';
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
302 } elsif ($ffloat != $tfloat) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
303 $funcs{$hashid} = 'SDL_ConvertFloat';
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 } elsif ($fsize != $tsize) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 $funcs{$hashid} = 'SDL_ConvertSize';
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306 } elsif ($fendian ne $tendian) {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307 $funcs{$hashid} = 'SDL_ConvertEndian';
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
308 } else {
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309 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
310 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
314
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
315 sub buildTypeConverters {
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
316 print "#if !NO_CONVERTERS\n\n";
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
317 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
318 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
319 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
320 my $to = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
321 buildCvtFunc($from, $to);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
322 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
323 }
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
324 print "#endif /* !NO_CONVERTERS */\n\n\n";
3008
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 print "const SDL_AudioTypeFilters sdl_audio_type_filters[] =\n{\n";
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
327 print "#if !NO_CONVERTERS\n";
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
328 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
329 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
330 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
331 my $to = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
332 if ($from ne $to) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
333 my $hashid = getTypeConvertHashId($from, $to);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
334 my $sym = $funcs{$hashid};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
335 print(" { AUDIO_$from, AUDIO_$to, $sym },\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 }
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
339 print "#endif /* !NO_CONVERTERS */\n";
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
340
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
341 print "};\n\n\n";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
342 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
343
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
344 sub getBiggerCtype {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
345 my ($isfloat, $size) = @_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
346
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
347 if ($isfloat) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
348 if ($size == 32) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
349 return 'double';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
350 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
351 die("bug in script.\n");
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
352 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
353
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
354 if ($size == 8) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
355 return 'Sint16';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
356 } elsif ($size == 16) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
357 return 'Sint32'
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
358 } elsif ($size == 32) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
359 return 'Sint64'
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
362 die("bug in script.\n");
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
363 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
364
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 # 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
367 # Man, this code is skanky.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
368 sub buildArbitraryResampleFunc {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
369 # !!! 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
370 my ($from, $channels, $upsample) = @_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
371 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
372
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
373 my $bigger = getBiggerCtype($ffloat, $fsize);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
374 my $interp = ($ffloat) ? '* 0.5' : '>> 1';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
375
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
376 my $resample = ($upsample) ? 'Upsample' : 'Downsample';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
377 my $hashid = getResamplerHashId($from, $channels, $upsample, 0);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
378 my $sym = "SDL_${resample}_${from}_${channels}c";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
379 $funcs{$hashid} = $sym;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
380 $custom_converters++;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
381
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
382 my $fudge = $fsize * $channels * 2; # !!! FIXME
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
383 my $eps_adjust = ($upsample) ? 'dstsize' : 'srcsize';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
384 my $incr = '';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
385 my $incr2 = '';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
386
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
387
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
388 # !!! FIXME: DEBUG_CONVERT should report frequencies.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
389 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
390 static void SDLCALL
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
391 ${sym}(SDL_AudioCVT * cvt, SDL_AudioFormat format)
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
392 {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
393 #ifdef DEBUG_CONVERT
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
394 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
395 #endif
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
396
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
397 const int srcsize = cvt->len_cvt - $fudge;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
398 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
399 register int eps = 0;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
400 EOF
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
402 # 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
403 # overwrite the buffer as we go.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
404 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
405 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
406 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
407 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
408 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
409 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
410 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
411 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
412 $fctype *dst = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
413 const $fctype *src = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
414 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
415 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
416 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
417
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
418 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
419 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
420 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
421 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
422 $fctype sample${idx} = $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
423 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
424 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
425
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
426 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
427 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
428 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
429 $fctype last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
430 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
431 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
432
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
433 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
434 while (dst != target) {
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
437 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
438 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
439 # !!! 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
440 my $idx = (($channels - $i) - 1);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
441 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
442 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
443 dst[$idx] = $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
444 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
445 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
446
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
447 $incr = ($channels == 1) ? 'dst--' : "dst -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
448 $incr2 = ($channels == 1) ? 'src--' : "src -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
449
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
450 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
451 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
452 eps += srcsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
453 if ((eps << 1) >= dstsize) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
454 $incr2;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
455 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
456 } else { # downsample.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
457 $incr = ($channels == 1) ? 'src++' : "src += $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
458 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
459 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
460 eps += dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
461 if ((eps << 1) >= srcsize) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
462 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
463 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
464 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
465 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
466 dst[$i] = $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
467 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
468 }
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 $incr = ($channels == 1) ? 'dst++' : "dst += $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
471 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
472 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
473 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
474 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
475
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
476 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
477 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
478 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
479 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
480 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
481 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
482 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
483
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
484 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
485 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
486 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
487 last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
488 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
489 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
490
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
491 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
492 eps -= $eps_adjust;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
493 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
494 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
495 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
496
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
497 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
498 cvt->len_cvt = dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
499 if (cvt->filters[++cvt->filter_index]) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
500 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
501 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 }
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 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
505
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
506 }
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 # 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
509 sub buildMultipleResampleFunc {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
510 # !!! 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
511 my ($from, $channels, $upsample, $multiple) = @_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
512 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
513
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
514 my $bigger = getBiggerCtype($ffloat, $fsize);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
515 my $interp = ($ffloat) ? '* 0.5' : '>> 1';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
516 my $interp2 = ($ffloat) ? '* 0.25' : '>> 2';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
517 my $mult3 = ($ffloat) ? '3.0' : '3';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
518 my $lencvtop = ($upsample) ? '*' : '/';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
519
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
520 my $resample = ($upsample) ? 'Upsample' : 'Downsample';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
521 my $hashid = getResamplerHashId($from, $channels, $upsample, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
522 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
523 $funcs{$hashid} = $sym;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
524 $custom_converters++;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
525
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
526 # !!! FIXME: DEBUG_CONVERT should report frequencies.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
527 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
528 static void SDLCALL
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
529 ${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
530 {
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
531 #ifdef DEBUG_CONVERT
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
532 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
533 #endif
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 const int srcsize = cvt->len_cvt;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
536 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
537 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
538
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
539 # 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
540 # overwrite the buffer as we go.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
541 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
542 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
543 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
544 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
545 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
546 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
547 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
548 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
549 $fctype *dst = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
550 const $fctype *src = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
551 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
552 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
553 }
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 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
556 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
557 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
558 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
559 $bigger last_sample${idx} = ($bigger) $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
560 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
561 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
562
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
563 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
564 while (dst != target) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
565 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
566
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
567 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
568 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
569 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
570 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
571 const $bigger sample${idx} = ($bigger) $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
572 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
573 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
574
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
575 my $incr = '';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
576 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
577 $incr = ($channels == 1) ? 'src--' : "src -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
578 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
579 my $amount = $channels * $multiple;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
580 $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
581 }
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 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
585 $incr;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
586 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
587
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
588 # !!! 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
589 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
590 if ($multiple == 2) {
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;
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 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
598 my $dsti = $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
599 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
600 dst[$dsti] = ($fctype) sample${i};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
601 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
602 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
603 } elsif ($multiple == 4) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
604 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
605 my $dsti = $i + ($channels * 3);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
606 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
607 dst[$dsti] = ($fctype) sample${i};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
608 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
609 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
610
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
611 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
612 my $dsti = $i + ($channels * 2);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
613 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
614 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
615 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
616 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
617
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
618 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
619 my $dsti = $i + ($channels * 1);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
620 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
621 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
622 EOF
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 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
626 my $dsti = $i + ($channels * 0);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
627 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
628 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
629 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
630 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
631 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
632 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
633 }
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
634 } else { # downsample.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
635 if ($multiple == 2) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
636 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
637 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
638 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
639 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
640 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
641 } elsif ($multiple == 4) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
642 # !!! FIXME: interpolate all 4 samples?
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
643 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
644 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
645 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
646 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
647 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
648 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
649 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
650 }
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 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
654 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
655 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
656 last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
657 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
658 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
659
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
660 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
661 my $amount = $channels * $multiple;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
662 $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
663 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
664 $incr = ($channels == 1) ? 'dst++' : "dst += $channels";
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 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
668 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
669 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
670
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
671 cvt->len_cvt = dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
672 if (cvt->filters[++cvt->filter_index]) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
673 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
674 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
675 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
676
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
677 EOF
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 sub buildResamplers {
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
682 print "#if !NO_RESAMPLERS\n\n";
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
683 foreach (@audiotypes) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
684 my $from = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
685 foreach (@channels) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
686 my $channel = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
687 buildArbitraryResampleFunc($from, $channel, 1);
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
688 buildArbitraryResampleFunc($from, $channel, 0);
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
689 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
690 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
691
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
692 print "\n#if !LESS_RESAMPLERS\n\n";
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
693 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
694 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
695 foreach (@channels) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
696 my $channel = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
697 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
698 buildMultipleResampleFunc($from, $channel, 1, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
699 buildMultipleResampleFunc($from, $channel, 0, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
700 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
701 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
702 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
703
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
704 print "#endif /* !LESS_RESAMPLERS */\n";
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
705 print "#endif /* !NO_RESAMPLERS */\n\n\n";
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
706
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
707 print "const SDL_AudioRateFilters sdl_audio_rate_filters[] =\n{\n";
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
708 print "#if !NO_RESAMPLERS\n";
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
709 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
710 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
711 foreach (@channels) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
712 my $channel = $_;
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
713 for (my $upsample = 0; $upsample <= 1; $upsample++) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
714 my $hashid = getResamplerHashId($from, $channel, $upsample, 0);
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
715 my $sym = $funcs{$hashid};
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
716 print(" { AUDIO_$from, $channel, $upsample, 0, $sym },\n");
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
717 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
718 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
719 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
720
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
721 print "#if !LESS_RESAMPLERS\n";
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
722 foreach (@audiotypes) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
723 my $from = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
724 foreach (@channels) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
725 my $channel = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
726 for (my $multiple = 2; $multiple <= 4; $multiple += 2) {
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
727 for (my $upsample = 0; $upsample <= 1; $upsample++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
728 my $hashid = getResamplerHashId($from, $channel, $upsample, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
729 my $sym = $funcs{$hashid};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
730 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
731 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
732 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
733 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
734 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
735
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
736 print "#endif /* !LESS_RESAMPLERS */\n";
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
737 print "#endif /* !NO_RESAMPLERS */\n";
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
738 print "};\n\n";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
739 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
740
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
741
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
742 # mainline ...
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
743
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
744 outputHeader();
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
745 buildTypeConverters();
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
746 buildResamplers();
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
747 outputFooter();
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
748
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
749 exit 0;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
750
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
751 # 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
752