annotate libaf/af_format.c @ 14322:e0f63bf677c0

synced to 1.74 (typo fix)
author gabrov
date Mon, 03 Jan 2005 10:19:48 +0000
parents 5a2473f37499
children 8380694ba14f
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
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
6 #include <stdio.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
7 #include <stdlib.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
8 #include <string.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
9 #include <unistd.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
10 #include <inttypes.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
11 #include <limits.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
12
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
13 #include "af.h"
12486
e02a261e4c92 using bswap.h for endianness conversion
reimar
parents: 12481
diff changeset
14 #include "../bswap.h"
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
15 #include "../libvo/fastmemcpy.h"
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
16
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
17 // Integer to float conversion through lrintf()
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
18 #ifdef HAVE_LRINTF
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
19 #define __USE_ISOC99 1
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
20 #include <math.h>
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
21 #else
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
22 #define lrintf(x) ((int)(x))
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
23 #endif
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
24
e8832e66babd New features:
anders
parents: 7998
diff changeset
25 /* Functions used by play to convert the input audio to the correct
e8832e66babd New features:
anders
parents: 7998
diff changeset
26 format */
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
27
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
28 /* The below includes retrives functions for converting to and from
e8832e66babd New features:
anders
parents: 7998
diff changeset
29 ulaw and alaw */
e8832e66babd New features:
anders
parents: 7998
diff changeset
30 #include "af_format_ulaw.c"
e8832e66babd New features:
anders
parents: 7998
diff changeset
31 #include "af_format_alaw.c"
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
32
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
33 // Switch endianess
e8832e66babd New features:
anders
parents: 7998
diff changeset
34 static void endian(void* in, void* out, int len, int bps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
35 // From singed to unsigned
e8832e66babd New features:
anders
parents: 7998
diff changeset
36 static void si2us(void* in, void* out, int len, int bps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
37 // From unsinged to signed
e8832e66babd New features:
anders
parents: 7998
diff changeset
38 static void us2si(void* in, void* out, int len, int bps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
39 // Change the number of bits per sample
e8832e66babd New features:
anders
parents: 7998
diff changeset
40 static void change_bps(void* in, void* out, int len, int inbps, int outbps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
41 // From float to int signed
e8832e66babd New features:
anders
parents: 7998
diff changeset
42 static void float2int(void* in, void* out, int len, int bps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
43 // From signed int to float
e8832e66babd New features:
anders
parents: 7998
diff changeset
44 static void int2float(void* in, void* 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
45
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
46 static af_data_t* play(struct af_instance_s* af, af_data_t* data);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
47 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
48 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
49 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
50
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
51 // Convert from string to format
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
52 int af_str2fmt(char* str)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
53 {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
54 int format=0;
e8832e66babd New features:
anders
parents: 7998
diff changeset
55 // Scan for endianess
e8832e66babd New features:
anders
parents: 7998
diff changeset
56 if(strstr(str,"be") || strstr(str,"BE"))
e8832e66babd New features:
anders
parents: 7998
diff changeset
57 format |= AF_FORMAT_BE;
e8832e66babd New features:
anders
parents: 7998
diff changeset
58 else if(strstr(str,"le") || strstr(str,"LE"))
e8832e66babd New features:
anders
parents: 7998
diff changeset
59 format |= AF_FORMAT_LE;
e8832e66babd New features:
anders
parents: 7998
diff changeset
60 else
e8832e66babd New features:
anders
parents: 7998
diff changeset
61 format |= AF_FORMAT_NE;
e8832e66babd New features:
anders
parents: 7998
diff changeset
62
e8832e66babd New features:
anders
parents: 7998
diff changeset
63 // Scan for special formats
e8832e66babd New features:
anders
parents: 7998
diff changeset
64 if(strstr(str,"mulaw") || strstr(str,"MULAW")){
e8832e66babd New features:
anders
parents: 7998
diff changeset
65 format |= AF_FORMAT_MU_LAW; return format;
e8832e66babd New features:
anders
parents: 7998
diff changeset
66 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
67 if(strstr(str,"alaw") || strstr(str,"ALAW")){
e8832e66babd New features:
anders
parents: 7998
diff changeset
68 format |= AF_FORMAT_A_LAW; return format;
e8832e66babd New features:
anders
parents: 7998
diff changeset
69 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
70 if(strstr(str,"ac3") || strstr(str,"AC3")){
e8832e66babd New features:
anders
parents: 7998
diff changeset
71 format |= AF_FORMAT_AC3; return format;
e8832e66babd New features:
anders
parents: 7998
diff changeset
72 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
73 if(strstr(str,"mpeg2") || strstr(str,"MPEG2")){
e8832e66babd New features:
anders
parents: 7998
diff changeset
74 format |= AF_FORMAT_MPEG2; return format;
e8832e66babd New features:
anders
parents: 7998
diff changeset
75 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
76 if(strstr(str,"imaadpcm") || strstr(str,"IMAADPCM")){
e8832e66babd New features:
anders
parents: 7998
diff changeset
77 format |= AF_FORMAT_IMA_ADPCM; return format;
e8832e66babd New features:
anders
parents: 7998
diff changeset
78 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
79
e8832e66babd New features:
anders
parents: 7998
diff changeset
80 // Scan for int/float
e8832e66babd New features:
anders
parents: 7998
diff changeset
81 if(strstr(str,"float") || strstr(str,"FLOAT")){
e8832e66babd New features:
anders
parents: 7998
diff changeset
82 format |= AF_FORMAT_F; return format;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
83 }
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
84 else
e8832e66babd New features:
anders
parents: 7998
diff changeset
85 format |= AF_FORMAT_I;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
86
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
87 // Scan for signed/unsigned
e8832e66babd New features:
anders
parents: 7998
diff changeset
88 if(strstr(str,"unsigned") || strstr(str,"UNSIGNED"))
e8832e66babd New features:
anders
parents: 7998
diff changeset
89 format |= AF_FORMAT_US;
e8832e66babd New features:
anders
parents: 7998
diff changeset
90 else
e8832e66babd New features:
anders
parents: 7998
diff changeset
91 format |= AF_FORMAT_SI;
e8832e66babd New features:
anders
parents: 7998
diff changeset
92
e8832e66babd New features:
anders
parents: 7998
diff changeset
93 return format;
e8832e66babd New features:
anders
parents: 7998
diff changeset
94 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
95
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
96 inline int af_fmt2bits(int format)
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
97 {
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
98 return (format & AF_FORMAT_BITS_MASK)+8;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
99 // return (((format & AF_FORMAT_BITS_MASK)>>3)+1) * 8;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
100 #if 0
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
101 switch(format & AF_FORMAT_BITS_MASK)
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
102 {
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
103 case AF_FORMAT_8BIT: return 8;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
104 case AF_FORMAT_16BIT: return 16;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
105 case AF_FORMAT_24BIT: return 24;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
106 case AF_FORMAT_32BIT: return 32;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
107 case AF_FORMAT_48BIT: return 48;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
108 }
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
109 #endif
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
110 return -1;
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
111 }
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
112
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
113 /* Convert format to str input str is a buffer for the
e8832e66babd New features:
anders
parents: 7998
diff changeset
114 converted string, size is the size of the buffer */
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
115 char* af_fmt2str(int format, char* str, int size)
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
116 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
117 int i=0;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
118
14256
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
119 if (size < 1)
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
120 return NULL;
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
121 size--; // reserve one for terminating 0
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
122
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
123 // Endianess
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
124 if(AF_FORMAT_LE == (format & AF_FORMAT_END_MASK))
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
125 i+=snprintf(str,size-i,"little-endian ");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
126 else
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
127 i+=snprintf(str,size-i,"big-endian ");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
128
e8832e66babd New features:
anders
parents: 7998
diff changeset
129 if(format & AF_FORMAT_SPECIAL_MASK){
e8832e66babd New features:
anders
parents: 7998
diff changeset
130 switch(format & AF_FORMAT_SPECIAL_MASK){
e8832e66babd New features:
anders
parents: 7998
diff changeset
131 case(AF_FORMAT_MU_LAW):
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
132 i+=snprintf(&str[i],size-i,"mu-law "); break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
133 case(AF_FORMAT_A_LAW):
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
134 i+=snprintf(&str[i],size-i,"A-law "); break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
135 case(AF_FORMAT_MPEG2):
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
136 i+=snprintf(&str[i],size-i,"MPEG-2 "); break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
137 case(AF_FORMAT_AC3):
e8832e66babd New features:
anders
parents: 7998
diff changeset
138 i+=snprintf(&str[i],size-i,"AC3 "); break;
14263
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
139 case(AF_FORMAT_IMA_ADPCM):
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
140 i+=snprintf(&str[i],size-i,"IMA-ADPCM "); break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
141 default:
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
142 printf("Unknown special\n");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
143 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
144 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
145 else{
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
146 // Bits
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
147 i+=snprintf(&str[i],size-i,"%d-bit ", af_fmt2bits(format));
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
148
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
149 // Point
e8832e66babd New features:
anders
parents: 7998
diff changeset
150 if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK))
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
151 i+=snprintf(&str[i],size-i,"float ");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
152 else{
e8832e66babd New features:
anders
parents: 7998
diff changeset
153 // Sign
e8832e66babd New features:
anders
parents: 7998
diff changeset
154 if(AF_FORMAT_US == (format & AF_FORMAT_SIGN_MASK))
e8832e66babd New features:
anders
parents: 7998
diff changeset
155 i+=snprintf(&str[i],size-i,"unsigned ");
e8832e66babd New features:
anders
parents: 7998
diff changeset
156 else
e8832e66babd New features:
anders
parents: 7998
diff changeset
157 i+=snprintf(&str[i],size-i,"signed ");
e8832e66babd New features:
anders
parents: 7998
diff changeset
158
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
159 i+=snprintf(&str[i],size-i,"int ");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
160 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
161 }
14256
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
162 str[i] = 0; // make sure it is 0 terminated.
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
163 return str;
7568
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
14263
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
166 char *af_fmt2str_short(int format)
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
167 {
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
168 switch(format)
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
169 {
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
170 // special
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
171 case AF_FORMAT_MU_LAW: return "mulaw";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
172 case AF_FORMAT_A_LAW: return "alaw";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
173 case AF_FORMAT_MPEG2: return "mpeg2";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
174 case AF_FORMAT_AC3: return "ac3";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
175 case AF_FORMAT_IMA_ADPCM: return "imaadpcm";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
176 // ordinary
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
177 case AF_FORMAT_U8: return "u8";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
178 case AF_FORMAT_S8: return "s8";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
179 case AF_FORMAT_U16_LE: return "u16le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
180 case AF_FORMAT_U16_BE: return "u16be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
181 case AF_FORMAT_S16_LE: return "s16le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
182 case AF_FORMAT_S16_BE: return "s16be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
183 case AF_FORMAT_U24_LE: return "u24le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
184 case AF_FORMAT_U24_BE: return "u24be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
185 case AF_FORMAT_S24_LE: return "s24le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
186 case AF_FORMAT_S24_BE: return "s24be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
187 case AF_FORMAT_U32_LE: return "u32le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
188 case AF_FORMAT_U32_BE: return "u32be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
189 case AF_FORMAT_S32_LE: return "s32le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
190 case AF_FORMAT_S32_BE: return "s32be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
191 case AF_FORMAT_FLOAT_LE: return "floatle";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
192 case AF_FORMAT_FLOAT_BE: return "floatbe";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
193 }
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
194 return "??";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
195 }
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
196
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
197 // Helper functions to check sanity for input arguments
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
198
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
199 // 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
200 static int check_bps(int bps)
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
201 {
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
202 if(bps != 4 && bps != 3 && bps != 2 && bps != 1){
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
203 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
204 " must be 1, 2, 3 or 4. Current value is %i \n",bps);
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
205 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
206 }
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
207 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
208 }
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
209
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
210 // Check for unsupported formats
13989
dcb6b4a33aaa declare check_format and check_bps static, they are used nowhere else.
reimar
parents: 12486
diff changeset
211 static int check_format(int format)
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
212 {
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
213 char buf[256];
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
214 switch(format & AF_FORMAT_SPECIAL_MASK){
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
215 case(AF_FORMAT_MPEG2):
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
216 case(AF_FORMAT_AC3):
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
217 af_msg(AF_MSG_ERROR,"[format] Sample format %s not yet supported \n",
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
218 af_fmt2str(format,buf,255));
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
219 return AF_ERROR;
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
220 }
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
221 return AF_OK;
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
222 }
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
223
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
224 // Initialization and runtime control
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
225 static int control(struct af_instance_s* af, int cmd, void* arg)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
226 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
227 switch(cmd){
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
228 case AF_CONTROL_REINIT:{
e8832e66babd New features:
anders
parents: 7998
diff changeset
229 char buf1[256];
e8832e66babd New features:
anders
parents: 7998
diff changeset
230 char buf2[256];
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
231 af_data_t *data = arg;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
232
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
233 // Make sure this filter isn't redundant
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
234 if(af->data->format == ((af_data_t*)arg)->format &&
e8832e66babd New features:
anders
parents: 7998
diff changeset
235 af->data->bps == ((af_data_t*)arg)->bps)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
236 return AF_DETACH;
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
237
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
238 // Check for errors in configuraton
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
239 if((AF_OK != check_bps(((af_data_t*)arg)->bps)) ||
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
240 (AF_OK != check_format(((af_data_t*)arg)->format)) ||
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
241 (AF_OK != check_bps(af->data->bps)) ||
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
242 (AF_OK != check_format(af->data->format)))
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
243 return AF_ERROR;
e8832e66babd New features:
anders
parents: 7998
diff changeset
244
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
245 af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %sto %s \n",
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
246 af_fmt2str(((af_data_t*)arg)->format,buf1,255),
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
247 af_fmt2str(af->data->format,buf2,255));
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
248
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
249 af->data->rate = ((af_data_t*)arg)->rate;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
250 af->data->nch = ((af_data_t*)arg)->nch;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
251 af->mul.n = af->data->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
252 af->mul.d = ((af_data_t*)arg)->bps;
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
253
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
254 af->play = play; // set default
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
255
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
256 // look whether only endianess differences are there
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
257 if ((af->data->format & ~AF_FORMAT_END_MASK) ==
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
258 (data->format & ~AF_FORMAT_END_MASK))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
259 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
260 af_msg(AF_MSG_VERBOSE,"[format] Accelerated endianess conversion only\n");
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
261 af->play = play_swapendian;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
262 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
263 if ((data->format == AF_FORMAT_FLOAT_NE) &&
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
264 (af->data->format == AF_FORMAT_S16_NE))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
265 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
266 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %sto %sconversion\n",
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
267 af_fmt2str(((af_data_t*)arg)->format,buf1,255),
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
268 af_fmt2str(af->data->format,buf2,255));
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
269 af->play = play_float_s16;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
270 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
271 if ((data->format == AF_FORMAT_S16_NE) &&
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
272 (af->data->format == AF_FORMAT_FLOAT_NE))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
273 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
274 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %sto %sconversion\n",
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
275 af_fmt2str(((af_data_t*)arg)->format,buf1,255),
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
276 af_fmt2str(af->data->format,buf2,255));
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
277 af->play = play_s16_float;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
278 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
279 return AF_OK;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
280 }
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7719
diff changeset
281 case AF_CONTROL_COMMAND_LINE:{
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
282 int bps = 2;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
283 int format = AF_FORMAT_NE;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
284 char str[256];
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
285 str[0] = '\0';
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
286 sscanf((char*)arg,"%i:%s",&bps,str);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
287 // Convert string to format
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
288 format = af_str2fmt(str);
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
289
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
290 // Automatic correction of errors
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
291 switch(format & AF_FORMAT_SPECIAL_MASK){
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
292 case(AF_FORMAT_A_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
293 case(AF_FORMAT_MU_LAW):
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
294 bps=1; break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
295 case(AF_FORMAT_AC3):
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
296 bps=4; break; // I think
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
297 }
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
298 if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK))
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
299 bps=4;
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
300
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
301 // set appropriate AF_FORMAT_BITS
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
302 format |= (bps-1)<<3; // hack
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
303
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
304 if((AF_OK != af->control(af,AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET,&bps)) ||
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
305 (AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)))
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
306 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
307 return AF_OK;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
308 }
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
309 case AF_CONTROL_FORMAT_BPS | AF_CONTROL_SET:
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
310 // Reinit must be called after this function has been called
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
311
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
312 // Check for errors in configuraton
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
313 if(AF_OK != check_bps(*(int*)arg))
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
314 return AF_ERROR;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
315
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
316 af->data->bps = *(int*)arg;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
317 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
318 case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
319 // Reinit must be called after this function has been called
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
320
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
321 // Check for errors in configuraton
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
322 if(AF_OK != check_format(*(int*)arg))
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
323 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
324
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
325 af->data->format = *(int*)arg;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
326 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
327 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
328 return AF_UNKNOWN;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
329 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
330
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
331 // Deallocate memory
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
332 static void uninit(struct af_instance_s* af)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
333 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
334 if(af->data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
335 free(af->data);
12386
be1e7cfddc08 more stupid crap
rfelker
parents: 8994
diff changeset
336 af->setup = 0;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
337 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
338
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
339 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data)
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
340 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
341 af_data_t* l = af->data; // Local data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
342 af_data_t* c = data; // Current working data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
343 int len = c->len/c->bps; // Lenght in samples of current audio block
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
344
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
345 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
346 return NULL;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
347
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
348 endian(c->audio,l->audio,len,c->bps);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
349
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
350 c->audio = l->audio;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
351 c->format = l->format;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
352
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
353 return c;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
354 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
355
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
356 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data)
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
357 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
358 af_data_t* l = af->data; // Local data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
359 af_data_t* c = data; // Current working data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
360 int len = c->len/4; // Lenght in samples of current audio block
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
361
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
362 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
363 return NULL;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
364
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
365 float2int(c->audio, l->audio, len, 2);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
366
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
367 c->audio = l->audio;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
368 c->len = len*2;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
369 c->bps = 2;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
370 c->format = l->format;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
371
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
372 return c;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
373 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
374
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
375 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data)
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
376 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
377 af_data_t* l = af->data; // Local data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
378 af_data_t* c = data; // Current working data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
379 int len = c->len/2; // Lenght in samples of current audio block
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
380
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
381 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
382 return NULL;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
383
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
384 int2float(c->audio, l->audio, len, 2);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
385
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
386 c->audio = l->audio;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
387 c->len = len*4;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
388 c->bps = 4;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
389 c->format = l->format;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
390
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
391 return c;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
392 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
393
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
394 // Filter data through filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
395 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
396 {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
397 af_data_t* l = af->data; // Local data
e8832e66babd New features:
anders
parents: 7998
diff changeset
398 af_data_t* c = data; // Current working data
e8832e66babd New features:
anders
parents: 7998
diff changeset
399 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
400
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
401 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
402 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
403
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
404 // Change to cpu native endian format
e8832e66babd New features:
anders
parents: 7998
diff changeset
405 if((c->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE)
e8832e66babd New features:
anders
parents: 7998
diff changeset
406 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
407
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
408 // Conversion table
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
409 if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_MU_LAW) {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
410 from_ulaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
411 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK))
e8832e66babd New features:
anders
parents: 7998
diff changeset
412 to_ulaw(l->audio, l->audio, len, 1, AF_FORMAT_SI);
e8832e66babd New features:
anders
parents: 7998
diff changeset
413 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
e8832e66babd New features:
anders
parents: 7998
diff changeset
414 si2us(l->audio,l->audio,len,l->bps);
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
415 } else if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_A_LAW) {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
416 from_alaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
417 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK))
e8832e66babd New features:
anders
parents: 7998
diff changeset
418 to_alaw(l->audio, l->audio, len, 1, AF_FORMAT_SI);
e8832e66babd New features:
anders
parents: 7998
diff changeset
419 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
e8832e66babd New features:
anders
parents: 7998
diff changeset
420 si2us(l->audio,l->audio,len,l->bps);
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
421 } else if((c->format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F) {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
422 switch(l->format&AF_FORMAT_SPECIAL_MASK){
e8832e66babd New features:
anders
parents: 7998
diff changeset
423 case(AF_FORMAT_MU_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
424 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
425 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
426 case(AF_FORMAT_A_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
427 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
428 break;
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
429 default:
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
430 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
431 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
432 si2us(l->audio,l->audio,len,l->bps);
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
433 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
434 }
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
435 } else {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
436 // Input must be int
e8832e66babd New features:
anders
parents: 7998
diff changeset
437
e8832e66babd New features:
anders
parents: 7998
diff changeset
438 // Change signed/unsigned
e8832e66babd New features:
anders
parents: 7998
diff changeset
439 if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){
e8832e66babd New features:
anders
parents: 7998
diff changeset
440 if((c->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
e8832e66babd New features:
anders
parents: 7998
diff changeset
441 us2si(c->audio,c->audio,len,c->bps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
442 else
e8832e66babd New features:
anders
parents: 7998
diff changeset
443 si2us(c->audio,c->audio,len,c->bps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
444 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
445 // Convert to special formats
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
446 switch(l->format&(AF_FORMAT_SPECIAL_MASK|AF_FORMAT_POINT_MASK)){
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
447 case(AF_FORMAT_MU_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
448 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
449 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
450 case(AF_FORMAT_A_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
451 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
452 break;
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
453 case(AF_FORMAT_F):
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
454 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
455 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
456 default:
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
457 // Change the number of bits
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
458 if(c->bps != l->bps)
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
459 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
460 else
8185
anders
parents: 8180
diff changeset
461 memcpy(l->audio,c->audio,len*c->bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
462 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
463 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
464 }
7719
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
465
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
466 // Switch from cpu native endian to the correct endianess
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
467 if((l->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE)
e8832e66babd New features:
anders
parents: 7998
diff changeset
468 endian(l->audio,l->audio,len,l->bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
469
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
470 // Set output data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
471 c->audio = l->audio;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
472 c->len = len*l->bps;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
473 c->bps = l->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
474 c->format = l->format;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
475 return c;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
476 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
477
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
478 // Allocate memory and set function pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
479 static int open(af_instance_t* af){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
480 af->control=control;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
481 af->uninit=uninit;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
482 af->play=play;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
483 af->mul.n=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
484 af->mul.d=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
485 af->data=calloc(1,sizeof(af_data_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
486 if(af->data == NULL)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
487 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
488 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
489 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
490
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
491 // Description of this filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
492 af_info_t af_info_format = {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
493 "Sample format conversion",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
494 "format",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
495 "Anders",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
496 "",
7615
c67328dd459a Adding Support for non-reentrant audio filters
anders
parents: 7571
diff changeset
497 AF_FLAGS_REENTRANT,
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
498 open
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
499 };
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
500
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
501 static inline uint32_t load24bit(void* data, int pos) {
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
502 #if WORDS_BIGENDIAN
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
503 return (((uint32_t)((uint8_t*)data)[3*pos])<<24) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
504 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
505 (((uint32_t)((uint8_t*)data)[3*pos+2])<<8);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
506 #else
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
507 return (((uint32_t)((uint8_t*)data)[3*pos])<<8) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
508 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
509 (((uint32_t)((uint8_t*)data)[3*pos+2])<<24);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
510 #endif
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
511 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
512
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
513 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
514 #if WORDS_BIGENDIAN
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
515 ((uint8_t*)data)[3*pos]=expanded_value>>24;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
516 ((uint8_t*)data)[3*pos+1]=expanded_value>>16;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
517 ((uint8_t*)data)[3*pos+2]=expanded_value>>8;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
518 #else
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
519 ((uint8_t*)data)[3*pos]=expanded_value>>8;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
520 ((uint8_t*)data)[3*pos+1]=expanded_value>>16;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
521 ((uint8_t*)data)[3*pos+2]=expanded_value>>24;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
522 #endif
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
523 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
524
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
525 // Function implementations used by play
e8832e66babd New features:
anders
parents: 7998
diff changeset
526 static void endian(void* in, void* out, int len, int bps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
527 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
528 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
529 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
530 case(2):{
e8832e66babd New features:
anders
parents: 7998
diff changeset
531 for(i=0;i<len;i++){
12486
e02a261e4c92 using bswap.h for endianness conversion
reimar
parents: 12481
diff changeset
532 ((uint16_t*)out)[i]=bswap_16(((uint16_t*)in)[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
533 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
534 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
535 }
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
536 case(3):{
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
537 register uint8_t s;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
538 for(i=0;i<len;i++){
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
539 s=((uint8_t*)in)[3*i];
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
540 ((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
541 if (in != out)
dbbc25ea6403 fix endian conversion for (curently unused) case where in buffer != out buffer
reimar
parents: 12478
diff changeset
542 ((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
543 ((uint8_t*)out)[3*i+2]=s;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
544 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
545 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
546 }
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
547 case(4):{
e8832e66babd New features:
anders
parents: 7998
diff changeset
548 for(i=0;i<len;i++){
12486
e02a261e4c92 using bswap.h for endianness conversion
reimar
parents: 12481
diff changeset
549 ((uint32_t*)out)[i]=bswap_32(((uint32_t*)in)[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
550 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
551 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
552 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
553 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
554 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
555
e8832e66babd New features:
anders
parents: 7998
diff changeset
556 static void si2us(void* in, void* out, int len, int bps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
557 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
558 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
559 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
560 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
561 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
562 ((uint8_t*)out)[i]=(uint8_t)(SCHAR_MAX+((int)((int8_t*)in)[i]));
e8832e66babd New features:
anders
parents: 7998
diff changeset
563 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
564 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
565 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
566 ((uint16_t*)out)[i]=(uint16_t)(SHRT_MAX+((int)((int16_t*)in)[i]));
e8832e66babd New features:
anders
parents: 7998
diff changeset
567 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
568 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
569 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
570 store24bit(out, i, (uint32_t)(INT_MAX+(int32_t)load24bit(in, i)));
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
571 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
572 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
573 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
574 ((uint32_t*)out)[i]=(uint32_t)(INT_MAX+((int32_t*)in)[i]);
e8832e66babd New features:
anders
parents: 7998
diff changeset
575 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
576 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
577 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
578
e8832e66babd New features:
anders
parents: 7998
diff changeset
579 static void us2si(void* in, void* out, int len, int bps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
580 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
581 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
582 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
583 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
584 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
585 ((int8_t*)out)[i]=(int8_t)(SCHAR_MIN+((int)((uint8_t*)in)[i]));
e8832e66babd New features:
anders
parents: 7998
diff changeset
586 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
587 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
588 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
589 ((int16_t*)out)[i]=(int16_t)(SHRT_MIN+((int)((uint16_t*)in)[i]));
e8832e66babd New features:
anders
parents: 7998
diff changeset
590 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
591 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
592 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
593 store24bit(out, i, (int32_t)(INT_MIN+(uint32_t)load24bit(in, i)));
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
594 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
595 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
596 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
597 ((int32_t*)out)[i]=(int32_t)(INT_MIN+((uint32_t*)in)[i]);
e8832e66babd New features:
anders
parents: 7998
diff changeset
598 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
599 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
600 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
601
e8832e66babd New features:
anders
parents: 7998
diff changeset
602 static void change_bps(void* in, void* out, int len, int inbps, int outbps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
603 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
604 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
605 switch(inbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
606 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
607 switch(outbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
608 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
609 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
610 ((uint16_t*)out)[i]=((uint16_t)((uint8_t*)in)[i])<<8;
e8832e66babd New features:
anders
parents: 7998
diff changeset
611 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
612 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
613 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
614 store24bit(out, i, ((uint32_t)((uint8_t*)in)[i])<<24);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
615 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
616 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
617 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
618 ((uint32_t*)out)[i]=((uint32_t)((uint8_t*)in)[i])<<24;
e8832e66babd New features:
anders
parents: 7998
diff changeset
619 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
620 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
621 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
622 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
623 switch(outbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
624 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
625 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
626 ((uint8_t*)out)[i]=(uint8_t)((((uint16_t*)in)[i])>>8);
e8832e66babd New features:
anders
parents: 7998
diff changeset
627 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
628 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
629 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
630 store24bit(out, i, ((uint32_t)((uint16_t*)in)[i])<<16);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
631 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
632 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
633 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
634 ((uint32_t*)out)[i]=((uint32_t)((uint16_t*)in)[i])<<16;
e8832e66babd New features:
anders
parents: 7998
diff changeset
635 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
636 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
637 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
638 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
639 switch(outbps){
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
640 case(1):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
641 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
642 ((uint8_t*)out)[i]=(uint8_t)(load24bit(in, i)>>24);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
643 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
644 case(2):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
645 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
646 ((uint16_t*)out)[i]=(uint16_t)(load24bit(in, i)>>16);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
647 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
648 case(4):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
649 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
650 ((uint32_t*)out)[i]=(uint32_t)load24bit(in, i);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
651 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
652 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
653 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
654 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
655 switch(outbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
656 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
657 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
658 ((uint8_t*)out)[i]=(uint8_t)((((uint32_t*)in)[i])>>24);
e8832e66babd New features:
anders
parents: 7998
diff changeset
659 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
660 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
661 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
662 ((uint16_t*)out)[i]=(uint16_t)((((uint32_t*)in)[i])>>16);
e8832e66babd New features:
anders
parents: 7998
diff changeset
663 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
664 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
665 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
666 store24bit(out, i, ((uint32_t*)in)[i]);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
667 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
668 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
669 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
670 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
671 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
672
e8832e66babd New features:
anders
parents: 7998
diff changeset
673 static void float2int(void* in, void* out, int len, int bps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
674 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
675 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
676 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
677 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
678 for(i=0;i<len;i++)
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
679 ((int8_t*)out)[i]=(int8_t)lrintf(SCHAR_MAX*((float*)in)[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
680 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
681 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
682 for(i=0;i<len;i++)
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
683 ((int16_t*)out)[i]=(int16_t)lrintf(SHRT_MAX*((float*)in)[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
684 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
685 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
686 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
687 store24bit(out, i, (int32_t)lrintf(INT_MAX*((float*)in)[i]));
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
688 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
689 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
690 for(i=0;i<len;i++)
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
691 ((int32_t*)out)[i]=(int32_t)lrintf(INT_MAX*((float*)in)[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
692 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
693 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
694 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
695
e8832e66babd New features:
anders
parents: 7998
diff changeset
696 static void int2float(void* in, void* out, int len, int bps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
697 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
698 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
699 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
700 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
701 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
702 ((float*)out)[i]=(1.0/SCHAR_MAX)*((float)((int8_t*)in)[i]);
e8832e66babd New features:
anders
parents: 7998
diff changeset
703 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
704 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
705 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
706 ((float*)out)[i]=(1.0/SHRT_MAX)*((float)((int16_t*)in)[i]);
e8832e66babd New features:
anders
parents: 7998
diff changeset
707 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
708 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
709 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
710 ((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t)load24bit(in, i)));
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
711 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
712 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
713 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
714 ((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t*)in)[i]);
e8832e66babd New features:
anders
parents: 7998
diff changeset
715 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
716 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
717 }