@@ -131,25 +131,28 @@ void audioio_mixer_reset_buffer(audioio_mixer_obj_t* self,
131
131
}
132
132
}
133
133
134
+ #pragma GCC push_options
135
+ #pragma GCC optimize ("O0")
134
136
uint32_t add8signed (uint32_t a , uint32_t b ) {
135
137
#if (defined (__ARM_FEATURE_DSP ) && (__ARM_FEATURE_DSP == 1 ))
136
138
return __QADD8 (a , b );
137
139
#else
138
140
uint32_t result = 0 ;
139
141
for (int8_t i = 0 ; i < 4 ; i ++ ) {
140
- int8_t ai = a >> (sizeof (int8_t ) * i );
141
- int8_t bi = b >> (sizeof (int8_t ) * i );
142
+ int8_t ai = a >> (sizeof (int8_t ) * 8 * i );
143
+ int8_t bi = b >> (sizeof (int8_t ) * 8 * i );
142
144
int32_t intermediate = (int32_t ) ai + bi ;
143
145
if (intermediate > CHAR_MAX ) {
144
146
intermediate = CHAR_MAX ;
145
147
} else if (intermediate < CHAR_MIN ) {
146
- intermediate = CHAR_MIN ;
148
+ // intermediate = CHAR_MIN;
147
149
}
148
- result |= ((int8_t ) intermediate ) >> (sizeof (int8_t ) * i );
150
+ result |= ((( uint32_t ) intermediate ) & 0xff ) << (sizeof (int8_t ) * 8 * i );
149
151
}
150
152
return result ;
151
153
#endif
152
154
}
155
+ #pragma GCC pop_options
153
156
154
157
uint32_t add8unsigned (uint32_t a , uint32_t b ) {
155
158
#if (defined (__ARM_FEATURE_DSP ) && (__ARM_FEATURE_DSP == 1 ))
@@ -161,13 +164,13 @@ uint32_t add8unsigned(uint32_t a, uint32_t b) {
161
164
#else
162
165
uint32_t result = 0 ;
163
166
for (int8_t i = 0 ; i < 4 ; i ++ ) {
164
- uint8_t ai = a >> (sizeof (uint8_t ) * i ) ;
165
- uint8_t bi = b >> (sizeof (uint8_t ) * i ) ;
167
+ int8_t ai = ( a >> (sizeof (uint8_t ) * 8 * i )) - 128 ;
168
+ int8_t bi = ( b >> (sizeof (uint8_t ) * 8 * i )) - 128 ;
166
169
int32_t intermediate = (int32_t ) ai + bi ;
167
170
if (intermediate > UCHAR_MAX ) {
168
171
intermediate = UCHAR_MAX ;
169
172
}
170
- result |= ((uint8_t ) intermediate ) >> (sizeof (uint8_t ) * i );
173
+ result |= ((uint8_t ) intermediate + 128 ) << (sizeof (uint8_t ) * 8 * i );
171
174
}
172
175
return result ;
173
176
#endif
@@ -179,15 +182,15 @@ uint32_t add16signed(uint32_t a, uint32_t b) {
179
182
#else
180
183
uint32_t result = 0 ;
181
184
for (int8_t i = 0 ; i < 2 ; i ++ ) {
182
- int16_t ai = a >> (sizeof (int16_t ) * i );
183
- int16_t bi = b >> (sizeof (int16_t ) * i );
185
+ int16_t ai = a >> (sizeof (int16_t ) * 8 * i );
186
+ int16_t bi = b >> (sizeof (int16_t ) * 8 * i );
184
187
int32_t intermediate = (int32_t ) ai + bi ;
185
188
if (intermediate > SHRT_MAX ) {
186
189
intermediate = SHRT_MAX ;
187
190
} else if (intermediate < SHRT_MIN ) {
188
191
intermediate = SHRT_MIN ;
189
192
}
190
- result |= ((int16_t ) intermediate ) >> (sizeof (int16_t ) * i );
193
+ result |= ((( uint32_t ) intermediate ) & 0xffff ) << (sizeof (int16_t ) * 8 * i );
191
194
}
192
195
return result ;
193
196
#endif
@@ -203,13 +206,13 @@ uint32_t add16unsigned(uint32_t a, uint32_t b) {
203
206
#else
204
207
uint32_t result = 0 ;
205
208
for (int8_t i = 0 ; i < 2 ; i ++ ) {
206
- uint16_t ai = a >> (sizeof (uint16_t ) * i ) ;
207
- uint16_t bi = b >> (sizeof (uint16_t ) * i ) ;
208
- uint32_t intermediate = (uint32_t ) ai + bi ;
209
+ int16_t ai = ( a >> (sizeof (uint16_t ) * 8 * i )) - 0x8000 ;
210
+ int16_t bi = ( b >> (sizeof (uint16_t ) * 8 * i )) - 0x8000 ;
211
+ int32_t intermediate = (int32_t ) ai + bi ;
209
212
if (intermediate > USHRT_MAX ) {
210
213
intermediate = USHRT_MAX ;
211
214
}
212
- result |= ((uint16_t ) intermediate ) >> (sizeof (int16_t ) * i );
215
+ result |= ((uint16_t ) intermediate + 0x8000 ) << (sizeof (int16_t ) * 8 * i );
213
216
}
214
217
return result ;
215
218
#endif
0 commit comments