annotate libaf/af_format.c @ 14424:b3ab8fa3c3f5

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