1 // Combination of Fir_Resampler and Blip_Buffer mixing. Used by Sega FM emulators.
2
3 // Game_Music_Emu 0.6.0
4 #ifndef DUAL_RESAMPLER_H
5 #define DUAL_RESAMPLER_H
6
7 #include "Fir_Resampler.h"
8 #include "Blip_Buffer.h"
9
10 class Dual_Resampler {
11 public:
12 Dual_Resampler();
13 virtual ~Dual_Resampler();
14
15 typedef short dsample_t;
16
17 double setup( double oversample, double rolloff, double gain );
18 blargg_err_t reset( int max_pairs );
19 void resize( int pairs_per_frame );
20 void clear();
21
22 void dual_play( long count, dsample_t* out, Blip_Buffer& );
23
24 protected:
25 virtual int play_frame( blip_time_t, int pcm_count, dsample_t* pcm_out ) = 0;
26 private:
27
28 blargg_vector<dsample_t> sample_buf;
29 int sample_buf_size;
30 int oversamples_per_frame;
31 int buf_pos;
32 int resampler_size;
33
34 Fir_Resampler<12> resampler;
35 void mix_samples( Blip_Buffer&, dsample_t* );
36 void play_frame_( Blip_Buffer&, dsample_t* );
37 };
38
setup(double oversample,double rolloff,double gain)39 inline double Dual_Resampler::setup( double oversample, double rolloff, double gain )
40 {
41 return resampler.time_ratio( oversample, rolloff, gain * 0.5 );
42 }
43
clear()44 inline void Dual_Resampler::clear()
45 {
46 buf_pos = sample_buf_size;
47 resampler.clear();
48 }
49
50 #endif
51