annotate src/audio/sdlgenaudiocvt.pl @ 4590:1ad70fb49fcb

Fix so many things that there is little place in this column to list them all but the result is that blending modes just work now for drawing primitives. Fixes involved: 1. Fix handling of alpha channel when SDL_BLENDMODE_NONE is set. 2. Make xrendercolor use floating-point values for color channels and then convert to 16 bit ints. 3. Fix handling of visuals in SDL_x11modes.c so that a 32 bit ARGB visual is used. 4. Fix the background pixel value in SDL_x11window.c so that the window background has an alpha value of 0xFF and not 0.
author Sunny Sachanandani <sunnysachanandani@gmail.com>
date Fri, 09 Jul 2010 21:36:41 +0530
parents bfa8d34ce03a
children 8c9cbb623d55
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
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3020
diff changeset
219 #if DEBUG_CONVERT
1982
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 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3020
diff changeset
394 #if DEBUG_CONVERT
3008
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 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3020
diff changeset
532 #if DEBUG_CONVERT
3008
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
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
540 my $endcomparison = '!=';
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
541
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
542 # 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
543 # overwrite the buffer as we go.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
544 if ($upsample) {
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
545 $endcomparison = '>'; # dst > target
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
546 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
547 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
548 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
549 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
550 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
551 } else {
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
552 $endcomparison = '<'; # dst < target
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
553 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
554 $fctype *dst = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
555 const $fctype *src = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
556 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
557 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
558 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
559
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
560 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
561 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
562 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
563 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
564 $bigger last_sample${idx} = ($bigger) $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
565 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
566 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
567
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
568 print <<EOF;
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
569 while (dst $endcomparison target) {
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
570 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
571
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
572 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
573 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
574 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
575 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
576 const $bigger sample${idx} = ($bigger) $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
577 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
578 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
579
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
580 my $incr = '';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
581 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
582 $incr = ($channels == 1) ? 'src--' : "src -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
583 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
584 my $amount = $channels * $multiple;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
585 $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
586 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
587
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
588
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
589 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
590 $incr;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
591 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
592
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
593 # !!! 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
594 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
595 if ($multiple == 2) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
596 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
597 my $dsti = $i + $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
598 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
599 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
600 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
601 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
602 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
603 my $dsti = $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
604 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
605 dst[$dsti] = ($fctype) sample${i};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
606 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
607 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
608 } elsif ($multiple == 4) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
609 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
610 my $dsti = $i + ($channels * 3);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
611 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
612 dst[$dsti] = ($fctype) sample${i};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
613 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
614 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
615
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
616 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
617 my $dsti = $i + ($channels * 2);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
618 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
619 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
620 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
621 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
622
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
623 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
624 my $dsti = $i + ($channels * 1);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
625 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
626 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
627 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
628 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
629
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
630 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
631 my $dsti = $i + ($channels * 0);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
632 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
633 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
634 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
635 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
636 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
637 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
638 }
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
639 } else { # downsample.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
640 if ($multiple == 2) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
641 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
642 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
643 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
644 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
645 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
646 } elsif ($multiple == 4) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
647 # !!! FIXME: interpolate all 4 samples?
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
648 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
649 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
650 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
651 EOF
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 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
654 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
655 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
656 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
657
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
658 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
659 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
660 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
661 last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
662 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
663 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
664
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
665 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
666 my $amount = $channels * $multiple;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
667 $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
668 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
669 $incr = ($channels == 1) ? 'dst++' : "dst += $channels";
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 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
673 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
674 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
675
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
676 cvt->len_cvt = dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
677 if (cvt->filters[++cvt->filter_index]) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
678 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
679 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
680 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
681
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
682 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
683
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
684 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
685
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
686 sub buildResamplers {
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
687 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
688 foreach (@audiotypes) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
689 my $from = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
690 foreach (@channels) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
691 my $channel = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
692 buildArbitraryResampleFunc($from, $channel, 1);
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
693 buildArbitraryResampleFunc($from, $channel, 0);
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
694 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
695 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
696
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
697 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
698 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
699 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
700 foreach (@channels) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
701 my $channel = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
702 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
703 buildMultipleResampleFunc($from, $channel, 1, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
704 buildMultipleResampleFunc($from, $channel, 0, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
705 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
706 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
707 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
708
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
709 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
710 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
711
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
712 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
713 print "#if !NO_RESAMPLERS\n";
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
714 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
715 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
716 foreach (@channels) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
717 my $channel = $_;
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
718 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
719 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
720 my $sym = $funcs{$hashid};
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
721 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
722 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
723 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
724 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
725
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
726 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
727 foreach (@audiotypes) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
728 my $from = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
729 foreach (@channels) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
730 my $channel = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
731 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
732 for (my $upsample = 0; $upsample <= 1; $upsample++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
733 my $hashid = getResamplerHashId($from, $channel, $upsample, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
734 my $sym = $funcs{$hashid};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
735 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
736 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
737 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
738 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
739 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
740
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
741 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
742 print "#endif /* !NO_RESAMPLERS */\n";
3020
70d876a0b90e NULL-terminate the lists of autogenerated converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 3019
diff changeset
743 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
744 print "};\n\n";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
745 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
746
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
747
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
748 # mainline ...
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
749
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
750 outputHeader();
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
751 buildTypeConverters();
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
752 buildResamplers();
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
753 outputFooter();
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
754
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
755 exit 0;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
756
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
757 # 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
758