Submit initial patch from FS#12176. Adds support for several new game music formats...
[kugel-rb.git] / apps / codecs / libgme / resampler.h
blobf5e8c5511947abd79f252b4787b5935b993ae501
1 // Combination of Downsampler and Blip_Buffer mixing. Used by Sega FM emulators.
3 // Game_Music_Emu 0.5.5
4 #ifndef RESAMPLER_H
5 #define RESAMPLER_H
7 #include "blargg_config.h"
8 #include "multi_buffer.h"
10 typedef short dsample_t;
12 enum { stereo = 2 };
13 enum { max_buf_size = 3960 };
14 enum { max_resampler_size = 5942 };
15 enum { write_offset = 8 * stereo };
16 enum { gain_bits = 14 };
18 struct Resampler {
19 int (*callback)( void*, blip_time_t, int, dsample_t* );
20 void* callback_data;
22 dsample_t sample_buf [max_buf_size];
23 int sample_buf_size;
24 int oversamples_per_frame;
25 int buf_pos;
26 int resampler_size;
27 int gain_;
29 // Internal resampler
30 dsample_t buf [max_resampler_size];
31 int buffer_size;
33 int write_pos;
34 double rate_;
36 int pos;
37 int step;
40 static inline void Resampler_init( struct Resampler* this )
42 this->pos = 0;
43 this->write_pos = 0;
44 this->rate_ = 0;
47 blargg_err_t Resampler_reset( struct Resampler* this, int max_pairs );
48 void Resampler_resize( struct Resampler* this, int pairs_per_frame );
50 void Resampler_play( struct Resampler* this, long count, dsample_t* out, struct Stereo_Buffer* ) ICODE_ATTR;
52 static inline void Resampler_set_callback(struct Resampler* this, int (*func)( void*, blip_time_t, int, dsample_t* ), void* user_data )
54 this->callback = func;
55 this->callback_data = user_data;
58 blargg_err_t Resampler_setup( struct Resampler* this, double oversample, double rolloff, double gain );
60 static inline void Resampler_clear( struct Resampler* this )
62 this->buf_pos = this->sample_buf_size;
64 this->pos = 0;
65 this->write_pos = 0;
68 #endif