Mercurial > spc_convert
view snes_spc/SPC_Filter.cpp @ 3:95cdedd01422
allow user to select number of seconds to convert
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 21 Oct 2011 06:44:35 -0700 |
parents | e38dacceb958 |
children |
line wrap: on
line source
1 // snes_spc 0.9.0. http://www.slack.net/~ant/3 #include "SPC_Filter.h"5 #include <string.h>7 /* Copyright (C) 2007 Shay Green. This module is free software; you8 can redistribute it and/or modify it under the terms of the GNU Lesser9 General Public License as published by the Free Software Foundation; either10 version 2.1 of the License, or (at your option) any later version. This11 module is distributed in the hope that it will be useful, but WITHOUT ANY12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS13 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more14 details. You should have received a copy of the GNU Lesser General Public15 License along with this module; if not, write to the Free Software Foundation,16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */18 #include "blargg_source.h"20 void SPC_Filter::clear() { memset( ch, 0, sizeof ch ); }22 SPC_Filter::SPC_Filter()23 {24 gain = gain_unit;25 bass = bass_norm;26 clear();27 }29 void SPC_Filter::run( short* io, int count )30 {31 require( (count & 1) == 0 ); // must be even33 int const gain = this->gain;34 int const bass = this->bass;35 chan_t* c = &ch [2];36 do37 {38 // cache in registers39 int sum = (--c)->sum;40 int pp1 = c->pp1;41 int p1 = c->p1;43 for ( int i = 0; i < count; i += 2 )44 {45 // Low-pass filter (two point FIR with coeffs 0.25, 0.75)46 int f = io [i] + p1;47 p1 = io [i] * 3;49 // High-pass filter ("leaky integrator")50 int delta = f - pp1;51 pp1 = f;52 int s = sum >> (gain_bits + 2);53 sum += (delta * gain) - (sum >> bass);55 // Clamp to 16 bits56 if ( (short) s != s )57 s = (s >> 31) ^ 0x7FFF;59 io [i] = (short) s;60 }62 c->p1 = p1;63 c->pp1 = pp1;64 c->sum = sum;65 ++io;66 }67 while ( c != ch );68 }