annotate src/audio/sdlgenaudiocvt.pl @ 3020:70d876a0b90e

NULL-terminate the lists of autogenerated converters.
author Ryan C. Gordon <icculus@icculus.org>
date Sun, 11 Jan 2009 04:46:14 +0000
parents dfd23eb79be9
children 77c3e67f0740
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
3020
70d876a0b90e NULL-terminate the lists of autogenerated converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 3019
diff changeset
341 print(" { 0, 0, NULL }\n");
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
342 print "};\n\n\n";
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
345 sub getBiggerCtype {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
346 my ($isfloat, $size) = @_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
347
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
348 if ($isfloat) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
349 if ($size == 32) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
350 return 'double';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
351 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
352 die("bug in script.\n");
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
355 if ($size == 8) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
356 return 'Sint16';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
357 } elsif ($size == 16) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
358 return 'Sint32'
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
359 } elsif ($size == 32) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
360 return 'Sint64'
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
363 die("bug in script.\n");
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
367 # 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
368 # Man, this code is skanky.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
369 sub buildArbitraryResampleFunc {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
370 # !!! 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
371 my ($from, $channels, $upsample) = @_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
372 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
373
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
374 my $bigger = getBiggerCtype($ffloat, $fsize);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
375 my $interp = ($ffloat) ? '* 0.5' : '>> 1';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
376
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
377 my $resample = ($upsample) ? 'Upsample' : 'Downsample';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
378 my $hashid = getResamplerHashId($from, $channels, $upsample, 0);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
379 my $sym = "SDL_${resample}_${from}_${channels}c";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
380 $funcs{$hashid} = $sym;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
381 $custom_converters++;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
382
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
383 my $fudge = $fsize * $channels * 2; # !!! FIXME
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
384 my $eps_adjust = ($upsample) ? 'dstsize' : 'srcsize';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
385 my $incr = '';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
386 my $incr2 = '';
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
389 # !!! FIXME: DEBUG_CONVERT should report frequencies.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
390 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
391 static void SDLCALL
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
392 ${sym}(SDL_AudioCVT * cvt, SDL_AudioFormat format)
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
393 {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
394 #ifdef DEBUG_CONVERT
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
395 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
396 #endif
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
397
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
398 const int srcsize = cvt->len_cvt - $fudge;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
399 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
400 register int eps = 0;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
401 EOF
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
403 # 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
404 # overwrite the buffer as we go.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
405 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
406 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
407 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
408 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
409 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
410 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
411 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
412 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
413 $fctype *dst = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
414 const $fctype *src = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
415 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
416 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
419 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
420 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
421 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
422 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
423 $fctype sample${idx} = $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
424 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
427 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
428 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
429 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
430 $fctype last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
431 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
434 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
435 while (dst != target) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
436 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
437
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
438 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
439 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
440 # !!! 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
441 my $idx = (($channels - $i) - 1);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
442 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
443 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
444 dst[$idx] = $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
445 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
448 $incr = ($channels == 1) ? 'dst--' : "dst -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
449 $incr2 = ($channels == 1) ? 'src--' : "src -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
450
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
451 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
452 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
453 eps += srcsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
454 if ((eps << 1) >= dstsize) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
455 $incr2;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
456 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
457 } else { # downsample.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
458 $incr = ($channels == 1) ? 'src++' : "src += $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
459 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
460 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
461 eps += dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
462 if ((eps << 1) >= srcsize) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
463 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
464 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
465 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
466 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
467 dst[$i] = $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
468 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
469 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
470
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
471 $incr = ($channels == 1) ? 'dst++' : "dst += $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
472 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
473 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
474 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
477 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
478 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
479 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
480 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
481 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
482 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
485 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
486 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
487 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
488 last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
489 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
492 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
493 eps -= $eps_adjust;
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 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
496 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
497
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
498 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
499 cvt->len_cvt = dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
500 if (cvt->filters[++cvt->filter_index]) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
501 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
502 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
505 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
509 # 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
510 sub buildMultipleResampleFunc {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
511 # !!! 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
512 my ($from, $channels, $upsample, $multiple) = @_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
513 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
514
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
515 my $bigger = getBiggerCtype($ffloat, $fsize);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
516 my $interp = ($ffloat) ? '* 0.5' : '>> 1';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
517 my $interp2 = ($ffloat) ? '* 0.25' : '>> 2';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
518 my $mult3 = ($ffloat) ? '3.0' : '3';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
519 my $lencvtop = ($upsample) ? '*' : '/';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
520
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
521 my $resample = ($upsample) ? 'Upsample' : 'Downsample';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
522 my $hashid = getResamplerHashId($from, $channels, $upsample, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
523 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
524 $funcs{$hashid} = $sym;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
525 $custom_converters++;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
526
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
527 # !!! FIXME: DEBUG_CONVERT should report frequencies.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
528 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
529 static void SDLCALL
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
530 ${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
531 {
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
532 #ifdef DEBUG_CONVERT
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
533 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
534 #endif
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
535
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
536 const int srcsize = cvt->len_cvt;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
537 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
538 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
539
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
540 # 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
541 # overwrite the buffer as we go.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
542 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
543 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
544 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
545 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
546 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
547 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
548 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
549 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
550 $fctype *dst = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
551 const $fctype *src = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
552 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
553 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
554 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
555
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
556 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
557 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
558 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
559 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
560 $bigger last_sample${idx} = ($bigger) $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
561 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
564 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
565 while (dst != target) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
566 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
567
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
568 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
569 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
570 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
571 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
572 const $bigger sample${idx} = ($bigger) $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
573 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
576 my $incr = '';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
577 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
578 $incr = ($channels == 1) ? 'src--' : "src -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
579 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
580 my $amount = $channels * $multiple;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
581 $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
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
585 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
586 $incr;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
587 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
588
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
589 # !!! 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
590 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
591 if ($multiple == 2) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
592 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
593 my $dsti = $i + $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
594 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
595 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
596 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
597 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
598 for (my $i = $channels-1; $i >= 0; $i--) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
599 my $dsti = $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
600 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
601 dst[$dsti] = ($fctype) sample${i};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
602 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
603 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
604 } elsif ($multiple == 4) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
605 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
606 my $dsti = $i + ($channels * 3);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
607 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
608 dst[$dsti] = ($fctype) sample${i};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
609 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
612 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
613 my $dsti = $i + ($channels * 2);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
614 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
615 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
616 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
619 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
620 my $dsti = $i + ($channels * 1);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
621 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
622 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
623 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
624 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
625
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
626 for (my $i = $channels-1; $i >= 0; $i--) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
627 my $dsti = $i + ($channels * 0);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
628 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
629 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
630 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
631 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
632 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
633 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
634 }
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
635 } else { # downsample.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
636 if ($multiple == 2) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
637 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
638 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
639 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
640 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
641 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
642 } elsif ($multiple == 4) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
643 # !!! FIXME: interpolate all 4 samples?
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
644 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
645 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
646 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
647 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
648 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
649 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
650 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
651 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
652 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
653
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
654 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
655 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
656 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
657 last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
658 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
661 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
662 my $amount = $channels * $multiple;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
663 $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
664 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
665 $incr = ($channels == 1) ? 'dst++' : "dst += $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
666 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
667
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
668 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
669 $incr;
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
672 cvt->len_cvt = dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
673 if (cvt->filters[++cvt->filter_index]) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
674 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
675 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
676 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
677
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
678 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
679
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
680 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
681
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
682 sub buildResamplers {
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
683 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
684 foreach (@audiotypes) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
685 my $from = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
686 foreach (@channels) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
687 my $channel = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
688 buildArbitraryResampleFunc($from, $channel, 1);
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
689 buildArbitraryResampleFunc($from, $channel, 0);
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
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
693 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
694 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
695 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
696 foreach (@channels) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
697 my $channel = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
698 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
699 buildMultipleResampleFunc($from, $channel, 1, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
700 buildMultipleResampleFunc($from, $channel, 0, $multiple);
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 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
704
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
705 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
706 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
707
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
708 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
709 print "#if !NO_RESAMPLERS\n";
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
710 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
711 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
712 foreach (@channels) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
713 my $channel = $_;
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
714 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
715 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
716 my $sym = $funcs{$hashid};
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
717 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
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
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
722 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
723 foreach (@audiotypes) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
724 my $from = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
725 foreach (@channels) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
726 my $channel = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
727 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
728 for (my $upsample = 0; $upsample <= 1; $upsample++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
729 my $hashid = getResamplerHashId($from, $channel, $upsample, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
730 my $sym = $funcs{$hashid};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
731 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
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 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
736
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
737 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
738 print "#endif /* !NO_RESAMPLERS */\n";
3020
70d876a0b90e NULL-terminate the lists of autogenerated converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 3019
diff changeset
739 print(" { 0, 0, 0, 0, NULL }\n");
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
740 print "};\n\n";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
741 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
742
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 # mainline ...
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
745
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
746 outputHeader();
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
747 buildTypeConverters();
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
748 buildResamplers();
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
749 outputFooter();
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
750
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
751 exit 0;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
752
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
753 # 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
754