annotate libaf/af_format.c @ 8027:b9da278e4c92

verbose can be negative
author arpi
date Fri, 01 Nov 2002 17:46:45 +0000
parents d48a06d07afb
children e8832e66babd
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 "../config.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
14 #include "../mp_msg.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
15
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
16 #include "../libao2/afmt.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
17
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
18 #include "af.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
19
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
20 // Number of bits
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
21 #define B08 (0<<0)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
22 #define B16 (1<<0)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
23 #define B32 (2<<0)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
24 #define NBITS_MASK (3<<0)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
25
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
26 // Endianess
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
27 #define BE (0<<2) // Big Endian
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
28 #define LE (1<<2) // Little Endian
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
29 #define END_MASK (1<<2)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
30
7719
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
31 #if WORDS_BIGENDIAN // native endian of cpu
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
32 #define NE BE
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
33 #else
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
34 #define NE LE
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
35 #endif
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
36
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
37 // Signed
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
38 #define US (0<<3) // Un Signed
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
39 #define SI (1<<3) // SIgned
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
40 #define SIGN_MASK (1<<3)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
41
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
42 int decode(int format)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
43 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
44 // Check input format
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
45 switch(format){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
46 case(AFMT_U8):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
47 return LE|B08|US;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
48 case(AFMT_S8):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
49 return LE|B08|SI; break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
50 case(AFMT_S16_LE):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
51 return LE|B16|SI; break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
52 case(AFMT_S16_BE):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
53 return BE|B16|SI; break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
54 case(AFMT_U16_LE):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
55 return LE|B16|US; break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
56 case(AFMT_U16_BE):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
57 return BE|B16|US; break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
58 case(AFMT_S32_LE):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
59 return LE|B32|SI; break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
60 case(AFMT_S32_BE):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
61 return BE|B32|SI; break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
62 case(AFMT_IMA_ADPCM):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
63 case(AFMT_MU_LAW):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
64 case(AFMT_A_LAW):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
65 case(AFMT_MPEG):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
66 case(AFMT_AC3):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
67 mp_msg(MSGT_AFILTER,MSGL_ERR,"[af_format] Input audio format not yet supported \n");
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
68 return 0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
69 default:
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
70 //This can not happen ....
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
71 mp_msg(MSGT_AFILTER,MSGL_ERR,"Unrecognized input audio format\n");
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
72 return 0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
73 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
74
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
75 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
76
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
77 // Initialization and runtime control
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
78 static int control(struct af_instance_s* af, int cmd, void* arg)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
79 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
80 switch(cmd){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
81 case AF_CONTROL_REINIT:
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
82 // Make sure this filter isn't redundant
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
83 if(af->data->format == ((af_data_t*)arg)->format && af->data->bps == ((af_data_t*)arg)->bps)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
84 return AF_DETACH;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
85
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
86 af->data->rate = ((af_data_t*)arg)->rate;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
87 af->data->nch = ((af_data_t*)arg)->nch;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
88 af->mul.n = af->data->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
89 af->mul.d = ((af_data_t*)arg)->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
90 return AF_OK;
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7719
diff changeset
91 case AF_CONTROL_COMMAND_LINE:{
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7719
diff changeset
92 af_data_t d;
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7719
diff changeset
93 sscanf((char*)arg,"%i:%i",&(d.format),&(d.bps));
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7719
diff changeset
94 return af->control(af,AF_CONTROL_FORMAT,&d);
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7719
diff changeset
95 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
96 case AF_CONTROL_FORMAT:
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
97 // Reinit must be called after this function has been called
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
98
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
99 // Sanity check for sample format
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
100 if(0 == ((int)af->setup=decode(((af_data_t*)arg)->format)))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
101 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
102 af->data->format = ((af_data_t*)arg)->format;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
103
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
104 // Sanity check for bytes per sample
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
105 if(((af_data_t*)arg)->bps != 4 && ((af_data_t*)arg)->bps != 2 && ((af_data_t*)arg)->bps != 1){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
106 mp_msg(MSGT_AFILTER,MSGL_ERR,"[format] The number of output bytes per sample must be 1, 2 or 4. Current value is%i \n",((af_data_t*)arg)->bps);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
107 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
108 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
109 af->data->bps=((af_data_t*)arg)->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
110
7571
8819fdf88b5d Adding support for multiple audio streams and removing annoying message from resample and format
anders
parents: 7568
diff changeset
111 mp_msg(MSGT_AFILTER,MSGL_V,"[format] Changing number sample format to 0x%08X and/or bytes per sample to %i \n",af->data->format,af->data->bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
112 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
113 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
114 return AF_UNKNOWN;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
115 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
116
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
117 // Deallocate memory
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
118 static void uninit(struct af_instance_s* af)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
119 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
120 if(af->data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
121 free(af->data);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
122 (int)af->setup = 0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
123 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
124
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
125 // Filter data through filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
126 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
127 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
128 af_data_t* l = af->data; // Local data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
129 void* la = NULL; // Local audio
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
130 int lf = (int)af->setup; // Local format
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
131 af_data_t* c = data; // Current working data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
132 void* ca = c->audio; // Current audio
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
133 int cf = decode(c->format); // Current format
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
134 register int i = 0; // Counter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
135 int len = c->len>>(cf&NBITS_MASK); // Loop end
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
136
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
137 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
138 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
139
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
140 la = l->audio;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
141
7719
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
142 // Change to cpu native endian
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
143 if((cf&END_MASK)!=NE){
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
144 switch(cf&NBITS_MASK){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
145 case(B16):{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
146 register uint16_t s;
7711
194bcc364c3f Correcting counters and flags
anders
parents: 7615
diff changeset
147 for(i=0;i<len;i++){
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
148 s=((uint16_t*)ca)[i];
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
149 ((uint16_t*)ca)[i]=(uint16_t)(((s&0x00FF)<<8) | (s&0xFF00)>>8);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
150 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
151 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
152 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
153 case(B32):{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
154 register uint32_t s;
7711
194bcc364c3f Correcting counters and flags
anders
parents: 7615
diff changeset
155 for(i=0;i<len;i++){
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
156 s=((uint32_t*)ca)[i];
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
157 ((uint32_t*)ca)[i]=(uint32_t)(((s&0x000000FF)<<24) | ((s&0x0000FF00)<<8) |
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
158 ((s&0x00FF0000)>>8) | ((s&0xFF000000)>>24));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
159 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
160 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
161 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
162 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
163 }
7719
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
164
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
165 // Change signed/unsigned
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
166 if((cf&SIGN_MASK) != (lf&SIGN_MASK)){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
167 switch((cf&NBITS_MASK)){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
168 case(B08):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
169 switch(cf&SIGN_MASK){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
170 case(US):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
171 for(i=0;i<len;i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
172 ((int8_t*)ca)[i]=(int8_t)(SCHAR_MIN+((int)((uint8_t*)ca)[i]));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
173 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
174 case(SI):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
175 for(i=0;i<len;i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
176 ((uint8_t*)ca)[i]=(uint8_t)(SCHAR_MAX+((int)((int8_t*)ca)[i]));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
177 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
178 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
179 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
180 case(B16):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
181 switch(cf&SIGN_MASK){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
182 case(US):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
183 for(i=0;i<len;i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
184 ((int16_t*)ca)[i]=(int16_t)(SHRT_MIN+((int)((uint16_t*)ca)[i]));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
185 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
186 case(SI):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
187 for(i=0;i<len;i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
188 ((uint16_t*)ca)[i]=(uint16_t)(SHRT_MAX+((int)((int16_t*)ca)[i]));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
189 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
190 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
191 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
192 case(B32):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
193 switch(cf&SIGN_MASK){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
194 case(US):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
195 for(i=0;i<len;i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
196 ((int32_t*)ca)[i]=(int32_t)(INT_MIN+((uint32_t*)ca)[i]);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
197 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
198 case(SI):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
199 for(i=0;i<len;i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
200 ((uint32_t*)ca)[i]=(uint32_t)(INT_MAX+((int32_t*)ca)[i]);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
201 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
202 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
203 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
204 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
205 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
206 // Change the number of bits
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
207 if((cf&NBITS_MASK) == (lf&NBITS_MASK)){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
208 memcpy(la,ca,c->len);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
209 } else {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
210 switch(cf&NBITS_MASK){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
211 case(B08):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
212 switch(lf&NBITS_MASK){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
213 case(B16):
7711
194bcc364c3f Correcting counters and flags
anders
parents: 7615
diff changeset
214 for(i=0;i<len;i++)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
215 ((uint16_t*)la)[i]=((uint16_t)((uint8_t*)ca)[i])<<8;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
216 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
217 case(B32):
7711
194bcc364c3f Correcting counters and flags
anders
parents: 7615
diff changeset
218 for(i=0;i<len;i++)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
219 ((uint32_t*)la)[i]=((uint32_t)((uint8_t*)ca)[i])<<24;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
220 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
221 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
222 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
223 case(B16):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
224 switch(lf&NBITS_MASK){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
225 case(B08):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
226 for(i=0;i<len;i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
227 ((uint8_t*)la)[i]=(uint8_t)((((uint16_t*)ca)[i])>>8);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
228 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
229 case(B32):
7711
194bcc364c3f Correcting counters and flags
anders
parents: 7615
diff changeset
230 for(i=0;i<len;i++)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
231 ((uint32_t*)la)[i]=((uint32_t)((uint16_t*)ca)[i])<<16;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
232 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
233 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
234 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
235 case(B32):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
236 switch(lf&NBITS_MASK){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
237 case(B08):
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
238 for(i=0;i<len;i++)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
239 ((uint8_t*)la)[i]=(uint8_t)((((uint32_t*)ca)[i])>>24);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
240 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
241 case(B16):
7711
194bcc364c3f Correcting counters and flags
anders
parents: 7615
diff changeset
242 for(i=0;i<len;i++)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
243 ((uint16_t*)la)[i]=(uint16_t)((((uint32_t*)ca)[i])>>16);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
244 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
245 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
246 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
247 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
248 }
7719
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
249
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
250 // Switch from cpu native endian to the correct endianess
41e8d0916c60 Fix for audio filters on big endian cpus. It's working now on Solaris SPARC &
jkeil
parents: 7711
diff changeset
251 if((lf&END_MASK)!=NE){
7711
194bcc364c3f Correcting counters and flags
anders
parents: 7615
diff changeset
252 switch(lf&NBITS_MASK){
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
253 case(B16):{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
254 register uint16_t s;
7711
194bcc364c3f Correcting counters and flags
anders
parents: 7615
diff changeset
255 for(i=0;i<len;i++){
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
256 s=((uint16_t*)la)[i];
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
257 ((uint16_t*)la)[i]=(uint16_t)(((s&0x00FF)<<8) | (s&0xFF00)>>8);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
258 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
259 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
260 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
261 case(B32):{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
262 register uint32_t s;
7711
194bcc364c3f Correcting counters and flags
anders
parents: 7615
diff changeset
263 for(i=0;i<len;i++){
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
264 s=((uint32_t*)la)[i];
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
265 ((uint32_t*)la)[i]=(uint32_t)(((s&0x000000FF)<<24) | ((s&0x0000FF00)<<8) |
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
266 ((s&0x00FF0000)>>8) | ((s&0xFF000000)>>24));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
267 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
268 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
269 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
270 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
271 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
272
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
273 // Set output data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
274
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
275 // Make sure no samples are lost
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
276 c->len = (c->len*l->bps)/c->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
277 c->audio = l->audio;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
278 c->bps = l->bps;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
279 c->format = l->format;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
280 return c;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
281 }
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 // Allocate memory and set function pointers
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
284 static int open(af_instance_t* af){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
285 af->control=control;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
286 af->uninit=uninit;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
287 af->play=play;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
288 af->mul.n=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
289 af->mul.d=1;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
290 af->data=calloc(1,sizeof(af_data_t));
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
291 if(af->data == NULL)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
292 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
293 (int)af->setup = 0;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
294 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
295 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
296
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
297 // Description of this filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
298 af_info_t af_info_format = {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
299 "Sample format conversion",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
300 "format",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
301 "Anders",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
302 "",
7615
c67328dd459a Adding Support for non-reentrant audio filters
anders
parents: 7571
diff changeset
303 AF_FLAGS_REENTRANT,
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
304 open
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
305 };