libsidplayfp  1.8.7
Filter6581.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2004,2010 Dag Lem <resid@nimrod.no>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef FILTER6581_H
24 #define FILTER6581_H
25 
26 #include "siddefs-fp.h"
27 
28 #include <memory>
29 
30 #include "Filter.h"
31 #include "FilterModelConfig.h"
32 
33 namespace reSIDfp
34 {
35 
36 class Integrator;
37 
320 class Filter6581 : public Filter
321 {
322 private:
324  unsigned short* currentGain;
325 
327  unsigned short* currentMixer;
328 
330  unsigned short* currentSummer;
331 
333  unsigned short* currentResonance;
334 
335  const unsigned short* f0_dac;
336 
337  unsigned short** mixer;
338  unsigned short** summer;
339  unsigned short** gain;
340 
342  int Vhp;
343 
345  int Vbp;
346 
348  int Vlp;
349 
351  int ve;
352 
353  const int voiceScaleS14;
354  const int voiceDC;
355 
357  std::auto_ptr<Integrator> hpIntegrator;
358 
360  std::auto_ptr<Integrator> bpIntegrator;
361 
362 public:
363  Filter6581() :
364  currentGain(0),
365  currentMixer(0),
366  currentSummer(0),
367  currentResonance(0),
368  f0_dac(FilterModelConfig::getInstance()->getDAC(0.5)),
369  mixer(FilterModelConfig::getInstance()->getMixer()),
370  summer(FilterModelConfig::getInstance()->getSummer()),
371  gain(FilterModelConfig::getInstance()->getGain()),
372  Vhp(0),
373  Vbp(0),
374  Vlp(0),
375  ve(0),
376  voiceScaleS14(FilterModelConfig::getInstance()->getVoiceScaleS14()),
377  voiceDC(FilterModelConfig::getInstance()->getVoiceDC()),
378  hpIntegrator(FilterModelConfig::getInstance()->buildIntegrator()),
379  bpIntegrator(FilterModelConfig::getInstance()->buildIntegrator())
380  {
381  input(0);
382  }
383 
384  ~Filter6581();
385 
386  int clock(int voice1, int voice2, int voice3);
387 
388  void input(int sample) { ve = (sample * voiceScaleS14 * 3 >> 10) + mixer[0][0]; }
389 
393  void updatedCenterFrequency();
394 
400  void updatedResonance() { currentResonance = gain[~res & 0xf]; }
401 
402  void updatedMixing();
403 
404 public:
410  void setFilterCurve(double curvePosition);
411 };
412 
413 } // namespace reSIDfp
414 
415 #if RESID_INLINING || defined(FILTER6581_CPP)
416 
417 #include "Integrator.h"
418 
419 namespace reSIDfp
420 {
421 
422 RESID_INLINE
423 int Filter6581::clock(int voice1, int voice2, int voice3)
424 {
425  voice1 = (voice1 * voiceScaleS14 >> 18) + voiceDC;
426  voice2 = (voice2 * voiceScaleS14 >> 18) + voiceDC;
427  voice3 = (voice3 * voiceScaleS14 >> 18) + voiceDC;
428 
429  int Vi = 0;
430  int Vo = 0;
431 
432  (filt1 ? Vi : Vo) += voice1;
433 
434  (filt2 ? Vi : Vo) += voice2;
435 
436  // NB! Voice 3 is not silenced by voice3off if it is routed
437  // through the filter.
438  if (filt3)
439  {
440  Vi += voice3;
441  }
442  else if (!voice3off)
443  {
444  Vo += voice3;
445  }
446 
447  (filtE ? Vi : Vo) += ve;
448 
449  const int oldVhp = Vhp;
450  Vhp = currentSummer[currentResonance[Vbp] + Vlp + Vi];
451  Vlp = bpIntegrator->solve(Vbp);
452  Vbp = hpIntegrator->solve(oldVhp);
453 
454  if (lp)
455  {
456  Vo += Vlp;
457  }
458 
459  if (bp)
460  {
461  Vo += Vbp;
462  }
463 
464  if (hp)
465  {
466  Vo += Vhp;
467  }
468 
469  return currentGain[currentMixer[Vo]] - (1 << 15);
470 }
471 
472 } // namespace reSIDfp
473 
474 #endif
475 
476 #endif
void updatedMixing()
Definition: Filter6581.cpp:42
bool hp
Highpass, bandpass, and lowpass filter modes.
Definition: Filter.h:51
bool filt1
Routing to filter or outside filter.
Definition: Filter.h:45
Definition: Dac.cpp:25
int clock(int voice1, int voice2, int voice3)
Definition: Filter6581.h:423
bool voice3off
Switch voice 3 off.
Definition: Filter.h:48
void setFilterCurve(double curvePosition)
Definition: Filter6581.cpp:84
void updatedCenterFrequency()
Definition: Filter6581.cpp:35
unsigned char res
Filter resonance.
Definition: Filter.h:39
Definition: Filter6581.h:320
void updatedResonance()
Definition: Filter6581.h:400
Definition: Filter.h:32