annotate libaf/af_format.c @ 18734:e702b1706df1

cosmetics: Rename some variables and command line parameters. (preparation for upcoming patches)
author diego
date Fri, 16 Jun 2006 21:17:47 +0000
parents a9da2db9eb16
children a965ca17debc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
1 /* This audio output filter changes the format of a data block. Valid
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
2 formats are: AFMT_U8, AFMT_S8, AFMT_S16_LE, AFMT_S16_BE
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
3 AFMT_U16_LE, AFMT_U16_BE, AFMT_S32_LE and AFMT_S32_BE.
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
4 */
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
5
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
6 // Must be defined before any libc headers are included!
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
7 #define _ISOC9X_SOURCE
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
8
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
9 #include <stdio.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
10 #include <stdlib.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
11 #include <string.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
12 #include <unistd.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
13 #include <inttypes.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
14 #include <limits.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
15
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
16 #include "af.h"
16982
a9da2db9eb16 Unify include paths by adding -I.. to CFLAGS.
diego
parents: 16664
diff changeset
17 #include "bswap.h"
a9da2db9eb16 Unify include paths by adding -I.. to CFLAGS.
diego
parents: 16664
diff changeset
18 #include "libvo/fastmemcpy.h"
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
19
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
20 // Integer to float conversion through lrintf()
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
21 #ifdef HAVE_LRINTF
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
22 #include <math.h>
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
23 long int lrintf(float);
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
24 #else
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
25 #define lrintf(x) ((int)(x))
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
26 #endif
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
27
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
28 /* Functions used by play to convert the input audio to the correct
e8832e66babd New features:
anders
parents: 7998
diff changeset
29 format */
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
30
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
31 /* The below includes retrives functions for converting to and from
e8832e66babd New features:
anders
parents: 7998
diff changeset
32 ulaw and alaw */
e8832e66babd New features:
anders
parents: 7998
diff changeset
33 #include "af_format_ulaw.c"
e8832e66babd New features:
anders
parents: 7998
diff changeset
34 #include "af_format_alaw.c"
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
35
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
36 // Switch endianess
e8832e66babd New features:
anders
parents: 7998
diff changeset
37 static void endian(void* in, void* out, int len, int bps);
16664
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
38 // From singed to unsigned and the other way
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
39 static void si2us(void* data, int len, int bps);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
40 // Change the number of bits per sample
e8832e66babd New features:
anders
parents: 7998
diff changeset
41 static void change_bps(void* in, void* out, int len, int inbps, int outbps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
42 // From float to int signed
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
43 static void float2int(float* in, void* out, int len, int bps);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
44 // From signed int to float
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
45 static void int2float(void* in, float* out, int len, int bps);
7719
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
46
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
47 static af_data_t* play(struct af_instance_s* af, af_data_t* data);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
48 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
49 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
50 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
51
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
52 // Helper functions to check sanity for input arguments
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
53
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
54 // Sanity check for bytes per sample
13989
dcb6b4a33aaa declare check_format and check_bps static, they are used nowhere else.
reimar
parents: 12486
diff changeset
55 static int check_bps(int bps)
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
56 {
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
57 if(bps != 4 && bps != 3 && bps != 2 && bps != 1){
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
58 af_msg(AF_MSG_ERROR,"[format] The number of bytes per sample"
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
59 " must be 1, 2, 3 or 4. Current value is %i \n",bps);
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
60 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
61 }
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
62 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
63 }
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
64
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
65 // Check for unsupported formats
13989
dcb6b4a33aaa declare check_format and check_bps static, they are used nowhere else.
reimar
parents: 12486
diff changeset
66 static int check_format(int format)
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
67 {
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
68 char buf[256];
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
69 switch(format & AF_FORMAT_SPECIAL_MASK){
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
70 case(AF_FORMAT_IMA_ADPCM):
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
71 case(AF_FORMAT_MPEG2):
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
72 case(AF_FORMAT_AC3):
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
73 af_msg(AF_MSG_ERROR,"[format] Sample format %s not yet supported \n",
14399
1a882e2a419b af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents: 14335
diff changeset
74 af_fmt2str(format,buf,256));
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
75 return AF_ERROR;
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
76 }
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
77 return AF_OK;
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
78 }
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
79
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
80 // Initialization and runtime control
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
81 static int control(struct af_instance_s* af, int cmd, void* arg)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
82 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
83 switch(cmd){
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
84 case AF_CONTROL_REINIT:{
e8832e66babd New features:
anders
parents: 7998
diff changeset
85 char buf1[256];
e8832e66babd New features:
anders
parents: 7998
diff changeset
86 char buf2[256];
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
87 af_data_t *data = arg;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
88
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
89 // Make sure this filter isn't redundant
14717
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
90 if(af->data->format == data->format &&
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
91 af->data->bps == data->bps)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
92 return AF_DETACH;
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
93
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
94 // Check for errors in configuraton
14717
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
95 if((AF_OK != check_bps(data->bps)) ||
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
96 (AF_OK != check_format(data->format)) ||
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
97 (AF_OK != check_bps(af->data->bps)) ||
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
98 (AF_OK != check_format(af->data->format)))
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
99 return AF_ERROR;
e8832e66babd New features:
anders
parents: 7998
diff changeset
100
14399
1a882e2a419b af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents: 14335
diff changeset
101 af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %s to %s\n",
14717
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
102 af_fmt2str(data->format,buf1,256),
14399
1a882e2a419b af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents: 14335
diff changeset
103 af_fmt2str(af->data->format,buf2,256));
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
104
14717
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
105 af->data->rate = data->rate;
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
106 af->data->nch = data->nch;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
107 af->mul.n = af->data->bps;
14717
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
108 af->mul.d = data->bps;
14433
95bb94a930a3 always cancel down fractions (frac_t) to avoid overflows and playback
reimar
parents: 14399
diff changeset
109 af_frac_cancel(&af->mul);
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
110
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
111 af->play = play; // set default
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
112
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
113 // look whether only endianess differences are there
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
114 if ((af->data->format & ~AF_FORMAT_END_MASK) ==
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
115 (data->format & ~AF_FORMAT_END_MASK))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
116 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
117 af_msg(AF_MSG_VERBOSE,"[format] Accelerated endianess conversion only\n");
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
118 af->play = play_swapendian;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
119 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
120 if ((data->format == AF_FORMAT_FLOAT_NE) &&
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
121 (af->data->format == AF_FORMAT_S16_NE))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
122 {
14399
1a882e2a419b af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents: 14335
diff changeset
123 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n",
14717
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
124 af_fmt2str(data->format,buf1,256),
14399
1a882e2a419b af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents: 14335
diff changeset
125 af_fmt2str(af->data->format,buf2,256));
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
126 af->play = play_float_s16;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
127 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
128 if ((data->format == AF_FORMAT_S16_NE) &&
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
129 (af->data->format == AF_FORMAT_FLOAT_NE))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
130 {
14399
1a882e2a419b af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents: 14335
diff changeset
131 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %s to %s conversion\n",
14717
51a7560a92b7 confusing mixture of typecasts and casted variable, removed typecasts
reimar
parents: 14433
diff changeset
132 af_fmt2str(data->format,buf1,256),
14399
1a882e2a419b af_fmt2str fixes (remove trailing space, call with size of buffer, not size-1)
reimar
parents: 14335
diff changeset
133 af_fmt2str(af->data->format,buf2,256));
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
134 af->play = play_s16_float;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
135 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
136 return AF_OK;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
137 }
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7719
diff changeset
138 case AF_CONTROL_COMMAND_LINE:{
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
139 int format = af_str2fmt_short(arg);
15311
b00b16a1ef05 Error out when invalid format is specified
reimar
parents: 14791
diff changeset
140 if (format == -1) {
b00b16a1ef05 Error out when invalid format is specified
reimar
parents: 14791
diff changeset
141 af_msg(AF_MSG_ERROR, "[format] %s is not a valid format\n", (char *)arg);
b00b16a1ef05 Error out when invalid format is specified
reimar
parents: 14791
diff changeset
142 return AF_ERROR;
b00b16a1ef05 Error out when invalid format is specified
reimar
parents: 14791
diff changeset
143 }
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
144 if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format))
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
145 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
146 return AF_OK;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
147 }
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
148 case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
149 // Check for errors in configuraton
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
150 if(AF_OK != check_format(*(int*)arg))
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
151 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
152
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
153 af->data->format = *(int*)arg;
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
154 af->data->bps = af_fmt2bits(af->data->format)/8;
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
155
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
156 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
157 }
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
158 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
159 return AF_UNKNOWN;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
160 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
161
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
162 // Deallocate memory
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
163 static void uninit(struct af_instance_s* af)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
164 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
165 if(af->data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
166 free(af->data);
12386
be1e7cfddc08 more stupid crap
rfelker
parents: 8994
diff changeset
167 af->setup = 0;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
168 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
169
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
170 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data)
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
171 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
172 af_data_t* l = af->data; // Local data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
173 af_data_t* c = data; // Current working data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
174 int len = c->len/c->bps; // Lenght in samples of current audio block
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
175
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
176 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
177 return NULL;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
178
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
179 endian(c->audio,l->audio,len,c->bps);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
180
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
181 c->audio = l->audio;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
182 c->format = l->format;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
183
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
184 return c;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
185 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
186
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
187 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data)
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
188 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
189 af_data_t* l = af->data; // Local data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
190 af_data_t* c = data; // Current working data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
191 int len = c->len/4; // Lenght in samples of current audio block
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
192
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
193 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
194 return NULL;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
195
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
196 float2int(c->audio, l->audio, len, 2);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
197
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
198 c->audio = l->audio;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
199 c->len = len*2;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
200 c->bps = 2;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
201 c->format = l->format;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
202
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
203 return c;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
204 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
205
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
206 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data)
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
207 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
208 af_data_t* l = af->data; // Local data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
209 af_data_t* c = data; // Current working data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
210 int len = c->len/2; // Lenght in samples of current audio block
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
211
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
212 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
213 return NULL;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
214
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
215 int2float(c->audio, l->audio, len, 2);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
216
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
217 c->audio = l->audio;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
218 c->len = len*4;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
219 c->bps = 4;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
220 c->format = l->format;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
221
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
222 return c;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
223 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
224
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
225 // Filter data through filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
226 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
227 {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
228 af_data_t* l = af->data; // Local data
e8832e66babd New features:
anders
parents: 7998
diff changeset
229 af_data_t* c = data; // Current working data
e8832e66babd New features:
anders
parents: 7998
diff changeset
230 int len = c->len/c->bps; // Lenght in samples of current audio block
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
231
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
232 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
233 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
234
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
235 // Change to cpu native endian format
e8832e66babd New features:
anders
parents: 7998
diff changeset
236 if((c->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE)
e8832e66babd New features:
anders
parents: 7998
diff changeset
237 endian(c->audio,c->audio,len,c->bps);
7719
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
238
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
239 // Conversion table
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
240 if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_MU_LAW) {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
241 from_ulaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
242 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK))
e8832e66babd New features:
anders
parents: 7998
diff changeset
243 to_ulaw(l->audio, l->audio, len, 1, AF_FORMAT_SI);
e8832e66babd New features:
anders
parents: 7998
diff changeset
244 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
16664
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
245 si2us(l->audio,len,l->bps);
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
246 } else if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_A_LAW) {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
247 from_alaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
248 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK))
e8832e66babd New features:
anders
parents: 7998
diff changeset
249 to_alaw(l->audio, l->audio, len, 1, AF_FORMAT_SI);
e8832e66babd New features:
anders
parents: 7998
diff changeset
250 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
16664
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
251 si2us(l->audio,len,l->bps);
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
252 } else if((c->format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F) {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
253 switch(l->format&AF_FORMAT_SPECIAL_MASK){
e8832e66babd New features:
anders
parents: 7998
diff changeset
254 case(AF_FORMAT_MU_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
255 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
256 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
257 case(AF_FORMAT_A_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
258 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
259 break;
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
260 default:
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
261 float2int(c->audio, l->audio, len, l->bps);
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
262 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
16664
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
263 si2us(l->audio,len,l->bps);
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
264 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
265 }
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
266 } else {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
267 // Input must be int
e8832e66babd New features:
anders
parents: 7998
diff changeset
268
e8832e66babd New features:
anders
parents: 7998
diff changeset
269 // Change signed/unsigned
e8832e66babd New features:
anders
parents: 7998
diff changeset
270 if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){
16664
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
271 si2us(c->audio,len,c->bps);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
272 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
273 // Convert to special formats
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
274 switch(l->format&(AF_FORMAT_SPECIAL_MASK|AF_FORMAT_POINT_MASK)){
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
275 case(AF_FORMAT_MU_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
276 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
277 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
278 case(AF_FORMAT_A_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
279 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
280 break;
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
281 case(AF_FORMAT_F):
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
282 int2float(c->audio, l->audio, len, c->bps);
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
283 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
284 default:
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
285 // Change the number of bits
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
286 if(c->bps != l->bps)
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
287 change_bps(c->audio,l->audio,len,c->bps,l->bps);
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
288 else
8185
anders
parents: 8180
diff changeset
289 memcpy(l->audio,c->audio,len*c->bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
290 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
291 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
292 }
7719
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
293
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
294 // Switch from cpu native endian to the correct endianess
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
295 if((l->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE)
e8832e66babd New features:
anders
parents: 7998
diff changeset
296 endian(l->audio,l->audio,len,l->bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
297
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
298 // Set output data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
299 c->audio = l->audio;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
300 c->len = len*l->bps;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
301 c->bps = l->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
302 c->format = l->format;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
303 return c;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
304 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
305
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
306 // Allocate memory and set function pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
307 static int open(af_instance_t* af){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
308 af->control=control;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
309 af->uninit=uninit;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
310 af->play=play;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
311 af->mul.n=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
312 af->mul.d=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
313 af->data=calloc(1,sizeof(af_data_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
314 if(af->data == NULL)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
315 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
316 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
317 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
318
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
319 // Description of this filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
320 af_info_t af_info_format = {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
321 "Sample format conversion",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
322 "format",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
323 "Anders",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
324 "",
7615
c67328dd459a Adding Support for non-reentrant audio filters
anders
parents: 7571
diff changeset
325 AF_FLAGS_REENTRANT,
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
326 open
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
327 };
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
328
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
329 static inline uint32_t load24bit(void* data, int pos) {
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
330 #if WORDS_BIGENDIAN
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
331 return (((uint32_t)((uint8_t*)data)[3*pos])<<24) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
332 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
333 (((uint32_t)((uint8_t*)data)[3*pos+2])<<8);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
334 #else
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
335 return (((uint32_t)((uint8_t*)data)[3*pos])<<8) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
336 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
337 (((uint32_t)((uint8_t*)data)[3*pos+2])<<24);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
338 #endif
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
339 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
340
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
341 static inline void store24bit(void* data, int pos, uint32_t expanded_value) {
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
342 #if WORDS_BIGENDIAN
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
343 ((uint8_t*)data)[3*pos]=expanded_value>>24;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
344 ((uint8_t*)data)[3*pos+1]=expanded_value>>16;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
345 ((uint8_t*)data)[3*pos+2]=expanded_value>>8;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
346 #else
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
347 ((uint8_t*)data)[3*pos]=expanded_value>>8;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
348 ((uint8_t*)data)[3*pos+1]=expanded_value>>16;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
349 ((uint8_t*)data)[3*pos+2]=expanded_value>>24;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
350 #endif
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
351 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
352
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
353 // Function implementations used by play
e8832e66babd New features:
anders
parents: 7998
diff changeset
354 static void endian(void* in, void* out, int len, int bps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
355 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
356 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
357 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
358 case(2):{
e8832e66babd New features:
anders
parents: 7998
diff changeset
359 for(i=0;i<len;i++){
12486
e02a261e4c92 using bswap.h for endianness conversion
reimar
parents: 12481
diff changeset
360 ((uint16_t*)out)[i]=bswap_16(((uint16_t*)in)[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
361 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
362 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
363 }
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
364 case(3):{
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
365 register uint8_t s;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
366 for(i=0;i<len;i++){
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
367 s=((uint8_t*)in)[3*i];
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
368 ((uint8_t*)out)[3*i]=((uint8_t*)in)[3*i+2];
12481
dbbc25ea6403 fix endian conversion for (curently unused) case where in buffer != out buffer
reimar
parents: 12478
diff changeset
369 if (in != out)
dbbc25ea6403 fix endian conversion for (curently unused) case where in buffer != out buffer
reimar
parents: 12478
diff changeset
370 ((uint8_t*)out)[3*i+1]=((uint8_t*)in)[3*i+1];
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
371 ((uint8_t*)out)[3*i+2]=s;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
372 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
373 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
374 }
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
375 case(4):{
e8832e66babd New features:
anders
parents: 7998
diff changeset
376 for(i=0;i<len;i++){
12486
e02a261e4c92 using bswap.h for endianness conversion
reimar
parents: 12481
diff changeset
377 ((uint32_t*)out)[i]=bswap_32(((uint32_t*)in)[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
378 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
379 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
380 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
381 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
382 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
383
16664
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
384 static void si2us(void* data, int len, int bps)
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
385 {
16664
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
386 register long i = -(len * bps);
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
387 register uint8_t *p = &((uint8_t *)data)[len * bps];
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
388 #if AF_FORMAT_NE == AF_FORMAT_LE
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
389 p += bps - 1;
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
390 #endif
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
391 if (len <= 0) return;
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
392 do {
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
393 p[i] ^= 0x80;
9991e406a2a2 much simpler signed/unsigned conversion.
reimar
parents: 15311
diff changeset
394 } while (i += bps);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
395 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
396
e8832e66babd New features:
anders
parents: 7998
diff changeset
397 static void change_bps(void* in, void* out, int len, int inbps, int outbps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
398 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
399 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
400 switch(inbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
401 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
402 switch(outbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
403 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
404 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
405 ((uint16_t*)out)[i]=((uint16_t)((uint8_t*)in)[i])<<8;
e8832e66babd New features:
anders
parents: 7998
diff changeset
406 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
407 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
408 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
409 store24bit(out, i, ((uint32_t)((uint8_t*)in)[i])<<24);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
410 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
411 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
412 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
413 ((uint32_t*)out)[i]=((uint32_t)((uint8_t*)in)[i])<<24;
e8832e66babd New features:
anders
parents: 7998
diff changeset
414 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
415 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
416 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
417 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
418 switch(outbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
419 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
420 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
421 ((uint8_t*)out)[i]=(uint8_t)((((uint16_t*)in)[i])>>8);
e8832e66babd New features:
anders
parents: 7998
diff changeset
422 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
423 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
424 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
425 store24bit(out, i, ((uint32_t)((uint16_t*)in)[i])<<16);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
426 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
427 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
428 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
429 ((uint32_t*)out)[i]=((uint32_t)((uint16_t*)in)[i])<<16;
e8832e66babd New features:
anders
parents: 7998
diff changeset
430 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
431 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
432 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
433 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
434 switch(outbps){
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
435 case(1):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
436 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
437 ((uint8_t*)out)[i]=(uint8_t)(load24bit(in, i)>>24);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
438 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
439 case(2):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
440 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
441 ((uint16_t*)out)[i]=(uint16_t)(load24bit(in, i)>>16);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
442 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
443 case(4):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
444 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
445 ((uint32_t*)out)[i]=(uint32_t)load24bit(in, i);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
446 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
447 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
448 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
449 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
450 switch(outbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
451 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
452 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
453 ((uint8_t*)out)[i]=(uint8_t)((((uint32_t*)in)[i])>>24);
e8832e66babd New features:
anders
parents: 7998
diff changeset
454 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
455 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
456 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
457 ((uint16_t*)out)[i]=(uint16_t)((((uint32_t*)in)[i])>>16);
e8832e66babd New features:
anders
parents: 7998
diff changeset
458 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
459 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
460 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
461 store24bit(out, i, ((uint32_t*)in)[i]);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
462 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
463 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
464 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
465 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
466 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
467
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
468 static void float2int(float* in, void* out, int len, int bps)
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
469 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
470 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
471 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
472 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
473 for(i=0;i<len;i++)
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
474 ((int8_t*)out)[i] = lrintf(127.0 * in[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
475 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
476 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
477 for(i=0;i<len;i++)
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
478 ((int16_t*)out)[i] = lrintf(32767.0 * in[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
479 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
480 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
481 for(i=0;i<len;i++)
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
482 store24bit(out, i, lrintf(2147483647.0 * in[i]));
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
483 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
484 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
485 for(i=0;i<len;i++)
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
486 ((int32_t*)out)[i] = lrintf(2147483647.0 * in[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
487 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
488 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
489 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
490
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
491 static void int2float(void* in, float* out, int len, int bps)
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
492 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
493 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
494 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
495 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
496 for(i=0;i<len;i++)
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
497 out[i]=(1.0/128.0)*((int8_t*)in)[i];
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
498 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
499 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
500 for(i=0;i<len;i++)
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
501 out[i]=(1.0/32768.0)*((int16_t*)in)[i];
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
502 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
503 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
504 for(i=0;i<len;i++)
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
505 out[i]=(1.0/2147483648.0)*((int32_t)load24bit(in, i));
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
506 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
507 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
508 for(i=0;i<len;i++)
14791
df515839c8a9 100l for me, lrintf is better. now fixed so it should be prototyped, and should work even if there is no prototype
rfelker
parents: 14758
diff changeset
509 out[i]=(1.0/2147483648.0)*((int32_t*)in)[i];
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
510 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
511 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
512 }