annotate src/audio/sdlgenaudiocvt.pl @ 5022:02e2c3d18bb8

Fixed building with the latest iOS SDK (4.2)
author Sam Lantinga <slouken@libsdl.org>
date Tue, 18 Jan 2011 15:00:56 -0800
parents 8c9cbb623d55
children b530ef003506
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
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3602
diff changeset
41 Copyright (C) 1997-2010 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
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3602
diff changeset
403 my $endcomparison = '!=';
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3602
diff changeset
404
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
405 # 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
406 # overwrite the buffer as we go.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
407 if ($upsample) {
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3602
diff changeset
408 $endcomparison = '>'; # dst > target
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
409 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
410 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
411 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
412 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
413 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
414 } else {
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3602
diff changeset
415 $endcomparison = '<'; # dst < target
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
416 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
417 $fctype *dst = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
418 const $fctype *src = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
419 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
420 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
421 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
422
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
423 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
424 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
425 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
426 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
427 $fctype sample${idx} = $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
428 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
429 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
430
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
431 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
432 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
433 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
434 $fctype last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
435 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
436 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
437
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
438 print <<EOF;
4889
8c9cbb623d55 Fixed crashing loading 48KHz audio, contributed by Terry Welsh
Sam Lantinga <slouken@libsdl.org>
parents: 3602
diff changeset
439 while (dst $endcomparison target) {
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
440 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
441
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
442 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
443 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
444 # !!! 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
445 my $idx = (($channels - $i) - 1);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
446 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
447 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
448 dst[$idx] = $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
449 EOF
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
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
452 $incr = ($channels == 1) ? 'dst--' : "dst -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
453 $incr2 = ($channels == 1) ? 'src--' : "src -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
454
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
455 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
456 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
457 eps += srcsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
458 if ((eps << 1) >= dstsize) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
459 $incr2;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
460 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
461 } else { # downsample.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
462 $incr = ($channels == 1) ? 'src++' : "src += $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
463 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
464 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
465 eps += dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
466 if ((eps << 1) >= srcsize) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
467 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
468 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
469 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
470 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
471 dst[$i] = $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
472 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
473 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
474
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
475 $incr = ($channels == 1) ? 'dst++' : "dst += $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
476 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
477 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
478 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
479 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
480
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
481 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
482 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
483 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
484 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
485 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
486 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
487 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
488
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
489 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
490 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
491 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
492 last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
493 EOF
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 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
497 eps -= $eps_adjust;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
498 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
499 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
500 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
501
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
502 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
503 cvt->len_cvt = dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
504 if (cvt->filters[++cvt->filter_index]) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
505 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
506 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
508
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
509 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
510
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
511 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
512
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
513 # 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
514 sub buildMultipleResampleFunc {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
515 # !!! 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
516 my ($from, $channels, $upsample, $multiple) = @_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
517 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
518
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
519 my $bigger = getBiggerCtype($ffloat, $fsize);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
520 my $interp = ($ffloat) ? '* 0.5' : '>> 1';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
521 my $interp2 = ($ffloat) ? '* 0.25' : '>> 2';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
522 my $mult3 = ($ffloat) ? '3.0' : '3';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
523 my $lencvtop = ($upsample) ? '*' : '/';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
524
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
525 my $resample = ($upsample) ? 'Upsample' : 'Downsample';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
526 my $hashid = getResamplerHashId($from, $channels, $upsample, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
527 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
528 $funcs{$hashid} = $sym;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
529 $custom_converters++;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
530
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
531 # !!! FIXME: DEBUG_CONVERT should report frequencies.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
532 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
533 static void SDLCALL
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
534 ${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
535 {
3032
77c3e67f0740 Fixed Visual C++ build
Sam Lantinga <slouken@libsdl.org>
parents: 3020
diff changeset
536 #if DEBUG_CONVERT
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
537 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
538 #endif
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
539
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
540 const int srcsize = cvt->len_cvt;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
541 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
542 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
543
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
544 my $endcomparison = '!=';
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
545
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
546 # 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
547 # overwrite the buffer as we go.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
548 if ($upsample) {
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
549 $endcomparison = '>'; # dst > target
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
550 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
551 $fctype *dst = (($fctype *) (cvt->buf + dstsize)) - $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
552 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
553 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
554 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
555 } else {
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
556 $endcomparison = '<'; # dst < target
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
557 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
558 $fctype *dst = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
559 const $fctype *src = ($fctype *) cvt->buf;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
560 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
561 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
562 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
563
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
564 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
565 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
566 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
567 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
568 $bigger last_sample${idx} = ($bigger) $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
569 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
570 }
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 print <<EOF;
3602
bfa8d34ce03a Fixed buffer overflows in resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3032
diff changeset
573 while (dst $endcomparison target) {
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
574 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
575
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
576 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
577 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
578 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
579 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
580 const $bigger sample${idx} = ($bigger) $val;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
581 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
582 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
583
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
584 my $incr = '';
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
585 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
586 $incr = ($channels == 1) ? 'src--' : "src -= $channels";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
587 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
588 my $amount = $channels * $multiple;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
589 $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
590 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
591
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
592
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
593 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
594 $incr;
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
595 EOF
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
596
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
597 # !!! 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
598 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
599 if ($multiple == 2) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
600 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
601 my $dsti = $i + $channels;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
602 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
603 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
604 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
605 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
606 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
607 my $dsti = $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
608 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
609 dst[$dsti] = ($fctype) sample${i};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
610 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
611 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
612 } elsif ($multiple == 4) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
613 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
614 my $dsti = $i + ($channels * 3);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
615 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
616 dst[$dsti] = ($fctype) sample${i};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
617 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
618 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
619
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
620 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
621 my $dsti = $i + ($channels * 2);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
622 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
623 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
624 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
625 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
626
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
627 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
628 my $dsti = $i + ($channels * 1);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
629 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
630 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
631 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
632 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
633
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
634 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
635 my $dsti = $i + ($channels * 0);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
636 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
637 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
638 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
639 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
640 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
641 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
642 }
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
643 } else { # downsample.
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
644 if ($multiple == 2) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
645 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
646 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
647 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
648 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
649 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
650 } elsif ($multiple == 4) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
651 # !!! FIXME: interpolate all 4 samples?
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
652 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
653 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
654 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
655 EOF
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 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
658 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
659 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
660 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
661
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
662 for (my $i = 0; $i < $channels; $i++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
663 my $idx = ($upsample) ? (($channels - $i) - 1) : $i;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
664 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
665 last_sample${idx} = sample${idx};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
666 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
667 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
668
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
669 if ($upsample) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
670 my $amount = $channels * $multiple;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
671 $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
672 } else {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
673 $incr = ($channels == 1) ? 'dst++' : "dst += $channels";
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 print <<EOF;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
677 $incr;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
678 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
679
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
680 cvt->len_cvt = dstsize;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
681 if (cvt->filters[++cvt->filter_index]) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
682 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
683 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
684 }
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
685
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
686 EOF
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
687
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
688 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
689
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
690 sub buildResamplers {
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
691 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
692 foreach (@audiotypes) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
693 my $from = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
694 foreach (@channels) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
695 my $channel = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
696 buildArbitraryResampleFunc($from, $channel, 1);
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
697 buildArbitraryResampleFunc($from, $channel, 0);
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
698 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
699 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
700
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
701 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
702 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
703 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
704 foreach (@channels) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
705 my $channel = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
706 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
707 buildMultipleResampleFunc($from, $channel, 1, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
708 buildMultipleResampleFunc($from, $channel, 0, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
709 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
710 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
711 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
712
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
713 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
714 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
715
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
716 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
717 print "#if !NO_RESAMPLERS\n";
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
718 foreach (@audiotypes) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
719 my $from = $_;
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
720 foreach (@channels) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
721 my $channel = $_;
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
722 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
723 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
724 my $sym = $funcs{$hashid};
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
725 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
726 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
727 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
728 }
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
729
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
730 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
731 foreach (@audiotypes) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
732 my $from = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
733 foreach (@channels) {
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
734 my $channel = $_;
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
735 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
736 for (my $upsample = 0; $upsample <= 1; $upsample++) {
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
737 my $hashid = getResamplerHashId($from, $channel, $upsample, $multiple);
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
738 my $sym = $funcs{$hashid};
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
739 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
740 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
741 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
742 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
743 }
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
744
3019
dfd23eb79be9 Allow builds that reduce or eliminate the converters/resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 3008
diff changeset
745 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
746 print "#endif /* !NO_RESAMPLERS */\n";
3020
70d876a0b90e NULL-terminate the lists of autogenerated converters.
Ryan C. Gordon <icculus@icculus.org>
parents: 3019
diff changeset
747 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
748 print "};\n\n";
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
749 }
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
750
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
751
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
752 # mainline ...
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
753
3008
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
754 outputHeader();
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
755 buildTypeConverters();
786a48f8309c First shot at autogenerated audio resamplers.
Ryan C. Gordon <icculus@icculus.org>
parents: 2956
diff changeset
756 buildResamplers();
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
757 outputFooter();
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
758
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
759 exit 0;
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
760
1985
8055185ae4ed Added source color and alpha modulation support.
Sam Lantinga <slouken@libsdl.org>
parents: 1982
diff changeset
761 # 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
762