Changeset 4129:7e48d8df51a3 in roaraudio for libroardsp
- Timestamp:
- 08/09/10 00:50:51 (14 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- libroardsp
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libroardsp/Makefile
r3635 r4129 5 5 6 6 TARGETS=$(SLIB) libroardsp.a 7 OBJS=libroardsp.o convert.o midside.o poly.o filter.o filterchain.o remove.o transcode.o vio_transcode.o rms.o fader.o mixer.o amp.o interleave.o channels.o 7 OBJS=libroardsp.o convert.o midside.o poly.o filter.o filterchain.o remove.o transcode.o vio_transcode.o rms.o fader.o mixer.o amp.o interleave.o channels.o resampler_poly3.o 8 8 OLDROAR=midi.o 9 9 FILTER=filter_lowp.o filter_highp.o filter_amp.o filter_quantify.o filter_add.o filter_clip.o filter_downmix.o filter_dcblock.o filter_swap.o filter_agc.o filter_speex_prep.o -
libroardsp/convert.c
r4125 r4129 3 3 /* 4 4 * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 5 * Copyright (C) Hans-Kristian 'maister' Arntzen - 2010 5 6 * 6 7 * This file is part of libroar a part of RoarAudio, … … 622 623 } 623 624 624 int roar_conv_rate2 (void * out, void * in, int samples, int outsamples, int bits, int channels) {625 int roar_conv_rate2 (void * out, void * in, int outsamples, int samples, int bits, int channels) { 625 626 ROAR_DBG("roar_conv_rate2(out=%p, in=%p, samples=%i, outsamples=%i, bits=%i, channels=%i) = ?", out, in, samples, outsamples, bits, channels); 626 627 switch (bits) { 628 case 8: 629 return roar_conv_poly3_8(out, in, outsamples, samples, channels); 630 break; 627 631 case 16: 628 632 return roar_conv_poly3_16(out, in, outsamples, samples, channels); 633 break; 634 case 32: 635 return roar_conv_poly3_32(out, in, outsamples, samples, channels); 629 636 break; 630 637 } … … 1001 1008 size_t bufsize) { 1002 1009 size_t samples; 1003 size_t needed_buffer;1010 // size_t needed_buffer; 1004 1011 void * cin = in; 1005 1012 struct roar_audio_info cinfo; … … 1106 1113 ROAR_DBG("roar_conv2(*): outsamples=%llu", (long long unsigned int)outsamples); 1107 1114 1108 if ( roar_conv_rate2(out, cin, samples, outsamples, cinfo.bits, cinfo.channels) == -1 )1115 if ( roar_conv_rate2(out, cin, outsamples, samples, cinfo.bits, cinfo.channels) == -1 ) 1109 1116 return -1; 1110 1117 … … 1218 1225 } 1219 1226 1220 /***********************************/1221 // ilen and olen are in samples, not frames.1222 int roar_conv_poly3_16 (int16_t * out, int16_t * in, size_t olen, size_t ilen, int channels) {1223 float ratio = (float)olen / (float)ilen;1224 int16_t *ip;1225 int c, x;1226 float pos_in;1227 float poly[3];1228 float y[3];1229 float x_val;1230 int32_t temp;1231 1232 /* Can't create poly out of less than 3 samples in each channel. */1233 if ( ilen < 3 * channels )1234 return -1;1235 1236 ip = roar_mm_malloc(ilen * sizeof(int16_t));1237 if ( ip == NULL )1238 return -1;1239 1240 memcpy(ip, in, ilen * sizeof(int16_t));1241 1242 olen /= channels;1243 1244 for (x = 0; x < olen; x++) {1245 for (c = 0; c < channels; c++) {1246 pos_in = (float)x / ratio;1247 1248 if ( (int)pos_in == 0 ) {1249 y[0] = ip[0 * channels + c];1250 y[1] = ip[1 * channels + c];1251 y[2] = ip[2 * channels + c];1252 x_val = pos_in;1253 roar_math_mkpoly_3x3(poly, y);1254 } else if ( (int)pos_in + 1 >= ilen/channels ) {1255 /* If we're at the end of the block, we will need to interpolate against a value that is not yet known.1256 * We will assume this value, by linearly extrapolating the two preceding values. From causual testing, this is not audible. */1257 y[0] = ip[((int)pos_in - 1) * channels + c];1258 y[1] = ip[((int)pos_in ) * channels + c];1259 1260 // we create a 2x2 poly here and set the 3rd coefficient to zero to build a 3x3 poly1261 roar_math_mkpoly_2x2(poly, y);1262 poly[2] = 0;1263 x_val = pos_in - (int)pos_in + 1.0;1264 } else {1265 y[0] = ip[((int)pos_in - 1) * channels + c];1266 y[1] = ip[((int)pos_in ) * channels + c];1267 y[2] = ip[((int)pos_in + 1) * channels + c];1268 x_val = pos_in - (int)pos_in + 1.0;1269 roar_math_mkpoly_3x3(poly, y);1270 }1271 1272 1273 temp = (float)(poly[2]*x_val*x_val + poly[1]*x_val + poly[0] + 0.5);1274 /* temp could be out of bounds, so need to check this */1275 if (temp > 0x7FFE ) {1276 out[x * channels + c] = 0x7FFE;1277 } else if (temp < -0x7FFF) {1278 out[x * channels + c] = -0x7FFF;1279 } else {1280 out[x * channels + c] = (int16_t)temp;1281 }1282 }1283 }1284 1285 roar_mm_free(ip);1286 return 0;1287 }1288 1289 1227 //ll
Note: See TracChangeset
for help on using the changeset viewer.