Mercurial > hg > xmms-sid
changeset 278:69ec4290030c
Added filtering code into CVS.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 25 Dec 2004 08:50:03 +0000 |
parents | c27763d388d9 |
children | 1481531b4ce2 |
files | src/xmms-sid.h src/xs_filter.c |
diffstat | 2 files changed, 75 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/xmms-sid.h Sat Dec 25 08:49:02 2004 +0000 +++ b/src/xmms-sid.h Sat Dec 25 08:50:03 2004 +0000 @@ -191,6 +191,7 @@ void xs_about(void); +gint xs_rateconv_filter(void *, void *, gint, gint, gint); t_xs_tuneinfo *xs_tuneinfo_new(gchar *, gint, gint, gchar *, gchar *, gchar *, gint, gint, gint, gint); void xs_tuneinfo_free(t_xs_tuneinfo *);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/xs_filter.c Sat Dec 25 08:50:03 2004 +0000 @@ -0,0 +1,74 @@ +/* + XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) + + Audio rate-conversion filter + + Written by Matti "ccr" Hamalainen <ccr@tnsp.org> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include "xmms-sid.h" + +/* Let's do some preprocessor magic :) */ +#define XS_FVAR(T, P, K) g ## K ## int ## P *sp_ ## T ## P , *dp_ ## T ## P + +#define XS_FILTER1(T, P, K) \ + dataSize /= sizeof(g ## K ## int ## P); tmpo_ ## T = 0; \ + sp_ ## T ## P = (g ## K ## int ## P *) srcBuf; \ + dp_ ## T ## P = (g ## K ## int ## P *) destBuf; \ + while (dataSize-- > oversampleFactor) { \ + for (tmp_ ## T = 0, i = 0; i < oversampleFactor; i++) \ + tmp_ ## T += sp_ ## T ## P [i]; \ + *(dp_ ## T ## P ++) = tmp_ ## T / (oversampleFactor); \ + sp_ ## T ## P ++; \ + } + +gint xs_rateconv_filter(void *destBuf, void *srcBuf, gint audioFormat, gint oversampleFactor, gint dataSize) +{ + guint32 tmp_u, tmpo_u; + gint32 tmp_s, tmpo_s; + XS_FVAR(u, 8, u); + XS_FVAR(s, 8,); + XS_FVAR(u, 16, u); + XS_FVAR(s, 16,); + gint i; + + if (dataSize <= 0) + return dataSize; + + switch (audioFormat) { + case FMT_U8: + case FMT_S8: + XS_FILTER1(s, 8,); + break; + + + case FMT_U16_BE: + case FMT_U16_LE: + case FMT_U16_NE: + + case FMT_S16_BE: + case FMT_S16_LE: + case FMT_S16_NE: + XS_FILTER1(s, 16,); + break; + + default: + return -1; + } + + return 0; +} +