annotate libaf/af_format.c @ 14345:c49569461eec

alphabetical order
author diego
date Mon, 03 Jan 2005 23:31:07 +0000
parents 8380694ba14f
children 1a882e2a419b
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
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
113 inline int af_bits2fmt(int bits)
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
114 {
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
115 return (bits/8 - 1) << 3;
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
116 }
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
117
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
118 /* Convert format to str input str is a buffer for the
e8832e66babd New features:
anders
parents: 7998
diff changeset
119 converted string, size is the size of the buffer */
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
120 char* af_fmt2str(int format, char* str, int size)
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
121 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
122 int i=0;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
123
14256
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
124 if (size < 1)
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
125 return NULL;
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
126 size--; // reserve one for terminating 0
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
127
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
128 // Endianess
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
129 if(AF_FORMAT_LE == (format & AF_FORMAT_END_MASK))
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
130 i+=snprintf(str,size-i,"little-endian ");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
131 else
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
132 i+=snprintf(str,size-i,"big-endian ");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
133
e8832e66babd New features:
anders
parents: 7998
diff changeset
134 if(format & AF_FORMAT_SPECIAL_MASK){
e8832e66babd New features:
anders
parents: 7998
diff changeset
135 switch(format & AF_FORMAT_SPECIAL_MASK){
e8832e66babd New features:
anders
parents: 7998
diff changeset
136 case(AF_FORMAT_MU_LAW):
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
137 i+=snprintf(&str[i],size-i,"mu-law "); break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
138 case(AF_FORMAT_A_LAW):
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
139 i+=snprintf(&str[i],size-i,"A-law "); break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
140 case(AF_FORMAT_MPEG2):
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
141 i+=snprintf(&str[i],size-i,"MPEG-2 "); break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
142 case(AF_FORMAT_AC3):
e8832e66babd New features:
anders
parents: 7998
diff changeset
143 i+=snprintf(&str[i],size-i,"AC3 "); break;
14263
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
144 case(AF_FORMAT_IMA_ADPCM):
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
145 i+=snprintf(&str[i],size-i,"IMA-ADPCM "); break;
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
146 default:
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
147 printf("Unknown special\n");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
148 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
149 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
150 else{
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
151 // Bits
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
152 i+=snprintf(&str[i],size-i,"%d-bit ", af_fmt2bits(format));
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
153
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
154 // Point
e8832e66babd New features:
anders
parents: 7998
diff changeset
155 if(AF_FORMAT_F == (format & AF_FORMAT_POINT_MASK))
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
156 i+=snprintf(&str[i],size-i,"float ");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
157 else{
e8832e66babd New features:
anders
parents: 7998
diff changeset
158 // Sign
e8832e66babd New features:
anders
parents: 7998
diff changeset
159 if(AF_FORMAT_US == (format & AF_FORMAT_SIGN_MASK))
e8832e66babd New features:
anders
parents: 7998
diff changeset
160 i+=snprintf(&str[i],size-i,"unsigned ");
e8832e66babd New features:
anders
parents: 7998
diff changeset
161 else
e8832e66babd New features:
anders
parents: 7998
diff changeset
162 i+=snprintf(&str[i],size-i,"signed ");
e8832e66babd New features:
anders
parents: 7998
diff changeset
163
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
164 i+=snprintf(&str[i],size-i,"int ");
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
165 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
166 }
14256
27002dcf0a70 ensure af_fmt2str always return a 0 terminated string
reimar
parents: 14245
diff changeset
167 str[i] = 0; // make sure it is 0 terminated.
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
168 return str;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
169 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
170
14263
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
171 char *af_fmt2str_short(int format)
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
172 {
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
173 switch(format)
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
174 {
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
175 // special
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
176 case AF_FORMAT_MU_LAW: return "mulaw";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
177 case AF_FORMAT_A_LAW: return "alaw";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
178 case AF_FORMAT_MPEG2: return "mpeg2";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
179 case AF_FORMAT_AC3: return "ac3";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
180 case AF_FORMAT_IMA_ADPCM: return "imaadpcm";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
181 // ordinary
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
182 case AF_FORMAT_U8: return "u8";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
183 case AF_FORMAT_S8: return "s8";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
184 case AF_FORMAT_U16_LE: return "u16le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
185 case AF_FORMAT_U16_BE: return "u16be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
186 case AF_FORMAT_S16_LE: return "s16le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
187 case AF_FORMAT_S16_BE: return "s16be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
188 case AF_FORMAT_U24_LE: return "u24le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
189 case AF_FORMAT_U24_BE: return "u24be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
190 case AF_FORMAT_S24_LE: return "s24le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
191 case AF_FORMAT_S24_BE: return "s24be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
192 case AF_FORMAT_U32_LE: return "u32le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
193 case AF_FORMAT_U32_BE: return "u32be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
194 case AF_FORMAT_S32_LE: return "s32le";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
195 case AF_FORMAT_S32_BE: return "s32be";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
196 case AF_FORMAT_FLOAT_LE: return "floatle";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
197 case AF_FORMAT_FLOAT_BE: return "floatbe";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
198 }
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
199 return "??";
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
200 }
bc80d39d19e8 af_fmt2str_short
alex
parents: 14261
diff changeset
201
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
202 int af_str2fmt_short(char* str)
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
203 {
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
204 int i;
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
205 static struct {
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
206 const char *name;
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
207 const int format;
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
208 } table[] = {
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
209 { "mulaw", AF_FORMAT_MU_LAW },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
210 { "alaw", AF_FORMAT_A_LAW },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
211 { "mpeg2", AF_FORMAT_MPEG2 },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
212 { "ac3", AF_FORMAT_AC3 },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
213 { "imaadpcm", AF_FORMAT_IMA_ADPCM },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
214
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
215 { "u8", AF_FORMAT_U8 },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
216 { "s8", AF_FORMAT_S8 },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
217 { "u16le", AF_FORMAT_U16_LE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
218 { "u16be", AF_FORMAT_U16_BE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
219 { "u16ne", AF_FORMAT_U16_NE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
220 { "s16le", AF_FORMAT_S16_LE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
221 { "s16be", AF_FORMAT_S16_BE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
222 { "s16ne", AF_FORMAT_S16_NE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
223 { "u24le", AF_FORMAT_U24_LE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
224 { "u24be", AF_FORMAT_U24_BE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
225 { "u24ne", AF_FORMAT_U24_NE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
226 { "s24le", AF_FORMAT_S24_LE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
227 { "s24be", AF_FORMAT_S24_BE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
228 { "s24ne", AF_FORMAT_S24_NE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
229 { "u32le", AF_FORMAT_U32_LE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
230 { "u32be", AF_FORMAT_U32_BE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
231 { "u32ne", AF_FORMAT_U32_NE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
232 { "s32le", AF_FORMAT_S32_LE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
233 { "s32be", AF_FORMAT_S32_BE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
234 { "s32ne", AF_FORMAT_S32_NE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
235 { "floatle", AF_FORMAT_FLOAT_LE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
236 { "floatbe", AF_FORMAT_FLOAT_BE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
237 { "floatne", AF_FORMAT_FLOAT_NE },
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
238
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
239 { NULL, 0 }
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
240 };
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
241
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
242 for (i = 0; table[i].name; i++)
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
243 if (!strcasecmp(str, table[i].name))
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
244 return table[i].format;
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
245
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
246 return -1;
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
247 }
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
248
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
249 // Helper functions to check sanity for input arguments
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
250
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
251 // 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
252 static int check_bps(int bps)
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
253 {
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
254 if(bps != 4 && bps != 3 && bps != 2 && bps != 1){
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
255 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
256 " must be 1, 2, 3 or 4. Current value is %i \n",bps);
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
257 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
258 }
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
259 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
260 }
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
261
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
262 // Check for unsupported formats
13989
dcb6b4a33aaa declare check_format and check_bps static, they are used nowhere else.
reimar
parents: 12486
diff changeset
263 static int check_format(int format)
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
264 {
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
265 char buf[256];
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
266 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
267 case(AF_FORMAT_IMA_ADPCM):
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
268 case(AF_FORMAT_MPEG2):
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
269 case(AF_FORMAT_AC3):
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
270 af_msg(AF_MSG_ERROR,"[format] Sample format %s not yet supported \n",
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
271 af_fmt2str(format,buf,255));
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
272 return AF_ERROR;
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
273 }
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
274 return AF_OK;
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
275 }
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
276
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
277 // Initialization and runtime control
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
278 static int control(struct af_instance_s* af, int cmd, void* arg)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
279 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
280 switch(cmd){
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
281 case AF_CONTROL_REINIT:{
e8832e66babd New features:
anders
parents: 7998
diff changeset
282 char buf1[256];
e8832e66babd New features:
anders
parents: 7998
diff changeset
283 char buf2[256];
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
284 af_data_t *data = arg;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
285
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
286 // Make sure this filter isn't redundant
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
287 if(af->data->format == ((af_data_t*)arg)->format &&
e8832e66babd New features:
anders
parents: 7998
diff changeset
288 af->data->bps == ((af_data_t*)arg)->bps)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
289 return AF_DETACH;
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
290
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
291 // Check for errors in configuraton
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
292 if((AF_OK != check_bps(((af_data_t*)arg)->bps)) ||
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
293 (AF_OK != check_format(((af_data_t*)arg)->format)) ||
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
294 (AF_OK != check_bps(af->data->bps)) ||
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
295 (AF_OK != check_format(af->data->format)))
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
296 return AF_ERROR;
e8832e66babd New features:
anders
parents: 7998
diff changeset
297
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
298 af_msg(AF_MSG_VERBOSE,"[format] Changing sample format from %sto %s \n",
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
299 af_fmt2str(((af_data_t*)arg)->format,buf1,255),
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13989
diff changeset
300 af_fmt2str(af->data->format,buf2,255));
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
301
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
302 af->data->rate = ((af_data_t*)arg)->rate;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
303 af->data->nch = ((af_data_t*)arg)->nch;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
304 af->mul.n = af->data->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
305 af->mul.d = ((af_data_t*)arg)->bps;
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
306
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
307 af->play = play; // set default
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
308
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
309 // look whether only endianess differences are there
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
310 if ((af->data->format & ~AF_FORMAT_END_MASK) ==
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
311 (data->format & ~AF_FORMAT_END_MASK))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
312 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
313 af_msg(AF_MSG_VERBOSE,"[format] Accelerated endianess conversion only\n");
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
314 af->play = play_swapendian;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
315 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
316 if ((data->format == AF_FORMAT_FLOAT_NE) &&
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
317 (af->data->format == AF_FORMAT_S16_NE))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
318 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
319 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %sto %sconversion\n",
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
320 af_fmt2str(((af_data_t*)arg)->format,buf1,255),
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
321 af_fmt2str(af->data->format,buf2,255));
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
322 af->play = play_float_s16;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
323 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
324 if ((data->format == AF_FORMAT_S16_NE) &&
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
325 (af->data->format == AF_FORMAT_FLOAT_NE))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
326 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
327 af_msg(AF_MSG_VERBOSE,"[format] Accelerated %sto %sconversion\n",
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
328 af_fmt2str(((af_data_t*)arg)->format,buf1,255),
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
329 af_fmt2str(af->data->format,buf2,255));
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
330 af->play = play_s16_float;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
331 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
332 return AF_OK;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
333 }
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7719
diff changeset
334 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
335 int format = af_str2fmt_short(arg);
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
336 if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format))
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
337 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
338 return AF_OK;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
339 }
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
340 case AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET:{
8607
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
341 // Check for errors in configuraton
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
342 if(AF_OK != check_format(*(int*)arg))
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
343 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
344
d6f40a06867b Changes includes:
anders
parents: 8185
diff changeset
345 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
346 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
347
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
348 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
349 }
14335
8380694ba14f af_bits2fmt and af_str2fmt_short, also removed the extra FORMAT_BPS control in format.c
alex
parents: 14272
diff changeset
350 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
351 return AF_UNKNOWN;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
352 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
353
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
354 // Deallocate memory
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
355 static void uninit(struct af_instance_s* af)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
356 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
357 if(af->data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
358 free(af->data);
12386
be1e7cfddc08 more stupid crap
rfelker
parents: 8994
diff changeset
359 af->setup = 0;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
360 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
361
14272
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
362 static af_data_t* play_swapendian(struct af_instance_s* af, af_data_t* data)
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
363 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
364 af_data_t* l = af->data; // Local data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
365 af_data_t* c = data; // Current working data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
366 int len = c->len/c->bps; // Lenght in samples of current audio block
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
367
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
368 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
369 return NULL;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
370
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
371 endian(c->audio,l->audio,len,c->bps);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
372
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
373 c->audio = l->audio;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
374 c->format = l->format;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
375
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
376 return c;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
377 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
378
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
379 static af_data_t* play_float_s16(struct af_instance_s* af, af_data_t* data)
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
380 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
381 af_data_t* l = af->data; // Local data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
382 af_data_t* c = data; // Current working data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
383 int len = c->len/4; // Lenght in samples of current audio block
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
384
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
385 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
386 return NULL;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
387
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
388 float2int(c->audio, l->audio, len, 2);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
389
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
390 c->audio = l->audio;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
391 c->len = len*2;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
392 c->bps = 2;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
393 c->format = l->format;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
394
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
395 return c;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
396 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
397
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
398 static af_data_t* play_s16_float(struct af_instance_s* af, af_data_t* data)
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
399 {
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
400 af_data_t* l = af->data; // Local data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
401 af_data_t* c = data; // Current working data
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
402 int len = c->len/2; // Lenght in samples of current audio block
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
403
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
404 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
405 return NULL;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
406
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
407 int2float(c->audio, l->audio, len, 2);
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
408
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
409 c->audio = l->audio;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
410 c->len = len*4;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
411 c->bps = 4;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
412 c->format = l->format;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
413
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
414 return c;
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
415 }
5a2473f37499 accelerated conversions
alex
parents: 14263
diff changeset
416
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
417 // Filter data through filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
418 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
419 {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
420 af_data_t* l = af->data; // Local data
e8832e66babd New features:
anders
parents: 7998
diff changeset
421 af_data_t* c = data; // Current working data
e8832e66babd New features:
anders
parents: 7998
diff changeset
422 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
423
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
424 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
425 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
426
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
427 // Change to cpu native endian format
e8832e66babd New features:
anders
parents: 7998
diff changeset
428 if((c->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE)
e8832e66babd New features:
anders
parents: 7998
diff changeset
429 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
430
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
431 // Conversion table
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
432 if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_MU_LAW) {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
433 from_ulaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
434 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK))
e8832e66babd New features:
anders
parents: 7998
diff changeset
435 to_ulaw(l->audio, l->audio, len, 1, AF_FORMAT_SI);
e8832e66babd New features:
anders
parents: 7998
diff changeset
436 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
e8832e66babd New features:
anders
parents: 7998
diff changeset
437 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
438 } else if((c->format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_A_LAW) {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
439 from_alaw(c->audio, l->audio, len, l->bps, l->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
440 if(AF_FORMAT_A_LAW == (l->format&AF_FORMAT_SPECIAL_MASK))
e8832e66babd New features:
anders
parents: 7998
diff changeset
441 to_alaw(l->audio, l->audio, len, 1, AF_FORMAT_SI);
e8832e66babd New features:
anders
parents: 7998
diff changeset
442 if((l->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
e8832e66babd New features:
anders
parents: 7998
diff changeset
443 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
444 } else if((c->format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F) {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
445 switch(l->format&AF_FORMAT_SPECIAL_MASK){
e8832e66babd New features:
anders
parents: 7998
diff changeset
446 case(AF_FORMAT_MU_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
447 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
448 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
449 case(AF_FORMAT_A_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
450 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
451 break;
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
452 default:
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
453 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
454 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
455 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
456 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
457 }
14261
710b223604fa 100l use right mask type when checking for input format
rtognimp
parents: 14256
diff changeset
458 } else {
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
459 // Input must be int
e8832e66babd New features:
anders
parents: 7998
diff changeset
460
e8832e66babd New features:
anders
parents: 7998
diff changeset
461 // Change signed/unsigned
e8832e66babd New features:
anders
parents: 7998
diff changeset
462 if((c->format&AF_FORMAT_SIGN_MASK) != (l->format&AF_FORMAT_SIGN_MASK)){
e8832e66babd New features:
anders
parents: 7998
diff changeset
463 if((c->format&AF_FORMAT_SIGN_MASK) == AF_FORMAT_US)
e8832e66babd New features:
anders
parents: 7998
diff changeset
464 us2si(c->audio,c->audio,len,c->bps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
465 else
e8832e66babd New features:
anders
parents: 7998
diff changeset
466 si2us(c->audio,c->audio,len,c->bps);
e8832e66babd New features:
anders
parents: 7998
diff changeset
467 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
468 // Convert to special formats
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
469 switch(l->format&(AF_FORMAT_SPECIAL_MASK|AF_FORMAT_POINT_MASK)){
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
470 case(AF_FORMAT_MU_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
471 to_ulaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
472 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
473 case(AF_FORMAT_A_LAW):
e8832e66babd New features:
anders
parents: 7998
diff changeset
474 to_alaw(c->audio, l->audio, len, c->bps, c->format&AF_FORMAT_POINT_MASK);
e8832e66babd New features:
anders
parents: 7998
diff changeset
475 break;
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
476 case(AF_FORMAT_F):
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
477 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
478 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
479 default:
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
480 // Change the number of bits
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
481 if(c->bps != l->bps)
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
482 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
483 else
8185
anders
parents: 8180
diff changeset
484 memcpy(l->audio,c->audio,len*c->bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
485 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
486 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
487 }
7719
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
488
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
489 // Switch from cpu native endian to the correct endianess
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
490 if((l->format&AF_FORMAT_END_MASK)!=AF_FORMAT_NE)
e8832e66babd New features:
anders
parents: 7998
diff changeset
491 endian(l->audio,l->audio,len,l->bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
492
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
493 // Set output data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
494 c->audio = l->audio;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
495 c->len = len*l->bps;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
496 c->bps = l->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
497 c->format = l->format;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
498 return c;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
499 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
500
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
501 // Allocate memory and set function pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
502 static int open(af_instance_t* af){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
503 af->control=control;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
504 af->uninit=uninit;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
505 af->play=play;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
506 af->mul.n=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
507 af->mul.d=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
508 af->data=calloc(1,sizeof(af_data_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
509 if(af->data == NULL)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
510 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
511 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
512 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
513
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
514 // Description of this filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
515 af_info_t af_info_format = {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
516 "Sample format conversion",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
517 "format",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
518 "Anders",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
519 "",
7615
c67328dd459a Adding Support for non-reentrant audio filters
anders
parents: 7571
diff changeset
520 AF_FLAGS_REENTRANT,
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
521 open
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
522 };
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
523
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
524 static inline uint32_t load24bit(void* data, int pos) {
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
525 #if WORDS_BIGENDIAN
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
526 return (((uint32_t)((uint8_t*)data)[3*pos])<<24) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
527 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
528 (((uint32_t)((uint8_t*)data)[3*pos+2])<<8);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
529 #else
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
530 return (((uint32_t)((uint8_t*)data)[3*pos])<<8) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
531 (((uint32_t)((uint8_t*)data)[3*pos+1])<<16) |
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
532 (((uint32_t)((uint8_t*)data)[3*pos+2])<<24);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
533 #endif
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
534 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
535
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
536 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
537 #if WORDS_BIGENDIAN
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
538 ((uint8_t*)data)[3*pos]=expanded_value>>24;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
539 ((uint8_t*)data)[3*pos+1]=expanded_value>>16;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
540 ((uint8_t*)data)[3*pos+2]=expanded_value>>8;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
541 #else
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
542 ((uint8_t*)data)[3*pos]=expanded_value>>8;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
543 ((uint8_t*)data)[3*pos+1]=expanded_value>>16;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
544 ((uint8_t*)data)[3*pos+2]=expanded_value>>24;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
545 #endif
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
546 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
547
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
548 // Function implementations used by play
e8832e66babd New features:
anders
parents: 7998
diff changeset
549 static void endian(void* in, void* out, int len, int bps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
550 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
551 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
552 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
553 case(2):{
e8832e66babd New features:
anders
parents: 7998
diff changeset
554 for(i=0;i<len;i++){
12486
e02a261e4c92 using bswap.h for endianness conversion
reimar
parents: 12481
diff changeset
555 ((uint16_t*)out)[i]=bswap_16(((uint16_t*)in)[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
556 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
557 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
558 }
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
559 case(3):{
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
560 register uint8_t s;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
561 for(i=0;i<len;i++){
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
562 s=((uint8_t*)in)[3*i];
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
563 ((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
564 if (in != out)
dbbc25ea6403 fix endian conversion for (curently unused) case where in buffer != out buffer
reimar
parents: 12478
diff changeset
565 ((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
566 ((uint8_t*)out)[3*i+2]=s;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
567 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
568 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
569 }
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
570 case(4):{
e8832e66babd New features:
anders
parents: 7998
diff changeset
571 for(i=0;i<len;i++){
12486
e02a261e4c92 using bswap.h for endianness conversion
reimar
parents: 12481
diff changeset
572 ((uint32_t*)out)[i]=bswap_32(((uint32_t*)in)[i]);
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
573 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
574 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
575 }
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 si2us(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 ((uint8_t*)out)[i]=(uint8_t)(SCHAR_MAX+((int)((int8_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 ((uint16_t*)out)[i]=(uint16_t)(SHRT_MAX+((int)((int16_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, (uint32_t)(INT_MAX+(int32_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 ((uint32_t*)out)[i]=(uint32_t)(INT_MAX+((int32_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 us2si(void* in, void* out, int len, int bps)
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(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
606 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
607 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
608 ((int8_t*)out)[i]=(int8_t)(SCHAR_MIN+((int)((uint8_t*)in)[i]));
e8832e66babd New features:
anders
parents: 7998
diff changeset
609 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
610 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
611 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
612 ((int16_t*)out)[i]=(int16_t)(SHRT_MIN+((int)((uint16_t*)in)[i]));
e8832e66babd New features:
anders
parents: 7998
diff changeset
613 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
614 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
615 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
616 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
617 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
618 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
619 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
620 ((int32_t*)out)[i]=(int32_t)(INT_MIN+((uint32_t*)in)[i]);
e8832e66babd New features:
anders
parents: 7998
diff changeset
621 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
622 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
623 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
624
e8832e66babd New features:
anders
parents: 7998
diff changeset
625 static void change_bps(void* in, void* out, int len, int inbps, int outbps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
626 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
627 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
628 switch(inbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
629 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
630 switch(outbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
631 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
632 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
633 ((uint16_t*)out)[i]=((uint16_t)((uint8_t*)in)[i])<<8;
e8832e66babd New features:
anders
parents: 7998
diff changeset
634 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
635 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
636 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
637 store24bit(out, i, ((uint32_t)((uint8_t*)in)[i])<<24);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
638 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
639 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
640 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
641 ((uint32_t*)out)[i]=((uint32_t)((uint8_t*)in)[i])<<24;
e8832e66babd New features:
anders
parents: 7998
diff changeset
642 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
643 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
644 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
645 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
646 switch(outbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
647 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
648 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
649 ((uint8_t*)out)[i]=(uint8_t)((((uint16_t*)in)[i])>>8);
e8832e66babd New features:
anders
parents: 7998
diff changeset
650 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
651 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
652 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
653 store24bit(out, i, ((uint32_t)((uint16_t*)in)[i])<<16);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
654 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
655 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
656 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
657 ((uint32_t*)out)[i]=((uint32_t)((uint16_t*)in)[i])<<16;
e8832e66babd New features:
anders
parents: 7998
diff changeset
658 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
659 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
660 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
661 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
662 switch(outbps){
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
663 case(1):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
664 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
665 ((uint8_t*)out)[i]=(uint8_t)(load24bit(in, i)>>24);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
666 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
667 case(2):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
668 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
669 ((uint16_t*)out)[i]=(uint16_t)(load24bit(in, i)>>16);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
670 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
671 case(4):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
672 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
673 ((uint32_t*)out)[i]=(uint32_t)load24bit(in, i);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
674 break;
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
675 }
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
676 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
677 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
678 switch(outbps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
679 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
680 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
681 ((uint8_t*)out)[i]=(uint8_t)((((uint32_t*)in)[i])>>24);
e8832e66babd New features:
anders
parents: 7998
diff changeset
682 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
683 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
684 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
685 ((uint16_t*)out)[i]=(uint16_t)((((uint32_t*)in)[i])>>16);
e8832e66babd New features:
anders
parents: 7998
diff changeset
686 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
687 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
688 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
689 store24bit(out, i, ((uint32_t*)in)[i]);
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
690 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
691 }
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 float2int(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++)
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
702 ((int8_t*)out)[i]=(int8_t)lrintf(SCHAR_MAX*((float*)in)[i]);
8167
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++)
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
706 ((int16_t*)out)[i]=(int16_t)lrintf(SHRT_MAX*((float*)in)[i]);
8167
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 store24bit(out, i, (int32_t)lrintf(INT_MAX*((float*)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++)
8180
4ba9aed295f2 Fixing segfault bug and addnig support for lrintf() in format conversion
anders
parents: 8167
diff changeset
714 ((int32_t*)out)[i]=(int32_t)lrintf(INT_MAX*((float*)in)[i]);
8167
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 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
718
e8832e66babd New features:
anders
parents: 7998
diff changeset
719 static void int2float(void* in, void* out, int len, int bps)
e8832e66babd New features:
anders
parents: 7998
diff changeset
720 {
e8832e66babd New features:
anders
parents: 7998
diff changeset
721 register int i;
e8832e66babd New features:
anders
parents: 7998
diff changeset
722 switch(bps){
e8832e66babd New features:
anders
parents: 7998
diff changeset
723 case(1):
e8832e66babd New features:
anders
parents: 7998
diff changeset
724 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
725 ((float*)out)[i]=(1.0/SCHAR_MAX)*((float)((int8_t*)in)[i]);
e8832e66babd New features:
anders
parents: 7998
diff changeset
726 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
727 case(2):
e8832e66babd New features:
anders
parents: 7998
diff changeset
728 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
729 ((float*)out)[i]=(1.0/SHRT_MAX)*((float)((int16_t*)in)[i]);
e8832e66babd New features:
anders
parents: 7998
diff changeset
730 break;
12478
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
731 case(3):
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
732 for(i=0;i<len;i++)
7f8eb5f6814a support for 24 bit pcm/wav files
reimar
parents: 12386
diff changeset
733 ((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
734 break;
8167
e8832e66babd New features:
anders
parents: 7998
diff changeset
735 case(4):
e8832e66babd New features:
anders
parents: 7998
diff changeset
736 for(i=0;i<len;i++)
e8832e66babd New features:
anders
parents: 7998
diff changeset
737 ((float*)out)[i]=(1.0/INT_MAX)*((float)((int32_t*)in)[i]);
e8832e66babd New features:
anders
parents: 7998
diff changeset
738 break;
e8832e66babd New features:
anders
parents: 7998
diff changeset
739 }
e8832e66babd New features:
anders
parents: 7998
diff changeset
740 }