Path: blob/a-new-beginning/Cherry/Core/include/audio/Effects_Buffer.h
2 views
// Multi-channel effects buffer with echo and individual panning for each channel12// Game_Music_Emu $vers3#ifndef EFFECTS_BUFFER_H4#define EFFECTS_BUFFER_H56#include "Multi_Buffer.h"78// See Simple_Effects_Buffer (below) for a simpler interface910class Effects_Buffer : public Multi_Buffer {11public:12// To reduce memory usage, fewer buffers can be used (with a best-fit13// approach if there are too few), and maximum echo delay can be reduced14Effects_Buffer( int max_bufs = 32, long echo_size = 24 * 1024L );1516struct pan_vol_t17{18float vol; // 0.0 = silent, 0.5 = half volume, 1.0 = normal19float pan; // -1.0 = left, 0.0 = center, +1.0 = right20};2122// Global configuration23struct config_t24{25bool enabled; // false = disable all effects2627// Current sound is echoed at adjustable left/right delay,28// with reduced treble and volume (feedback).29float treble; // 1.0 = full treble, 0.1 = very little, 0.0 = silent30int delay [2]; // left, right delays (msec)31float feedback; // 0.0 = no echo, 0.5 = each echo half previous, 1.0 = cacophony32pan_vol_t side_chans [2]; // left and right side channel volume and pan33};34config_t& config() { return config_; }3536// Limits of delay (msec)37int min_delay() const;38int max_delay() const;3940// Per-channel configuration. Two or more channels with matching parameters are41// optimized to internally use the same buffer.42struct chan_config_t : pan_vol_t43{44// (inherited from pan_vol_t)45//float vol; // these only affect center channel46//float pan;47bool surround; // if true, negates left volume to put sound in back48bool echo; // false = channel doesn't have any echo49};50chan_config_t& chan_config( int i ) { return chans [i + extra_chans].cfg; }5152// Apply any changes made to config() and chan_config()53virtual void apply_config();5455public:56~Effects_Buffer();57blargg_err_t set_sample_rate( long samples_per_sec, int msec = blip_default_length );58blargg_err_t set_channel_count( int, int const* = 0 );59void clock_rate( long );60void bass_freq( int );61void clear();62channel_t channel( int );63void end_frame( blip_time_t );64long read_samples( blip_sample_t*, long );65long samples_avail() const { return (bufs [0].samples_avail() - mixer.samples_read) * 2; }66enum { stereo = 2 };67typedef blargg_long fixed_t;68protected:69enum { extra_chans = stereo * stereo };70private:71config_t config_;72long clock_rate_;73int bass_freq_;7475blargg_long echo_size;7677struct chan_t78{79fixed_t vol [stereo];80chan_config_t cfg;81channel_t channel;82};83blargg_vector<chan_t> chans;8485struct buf_t : Tracked_Blip_Buffer86{87fixed_t vol [stereo];88bool echo;8990void* operator new ( size_t, void* p ) { return p; }91void operator delete ( void* ) { }9293~buf_t() { }94};95buf_t* bufs;96int bufs_size;97int bufs_max; // bufs_size <= bufs_max, to limit memory usage98Stereo_Mixer mixer;99100struct {101long delay [stereo];102fixed_t treble;103fixed_t feedback;104fixed_t low_pass [stereo];105} s;106107blargg_vector<fixed_t> echo;108blargg_long echo_pos;109110bool no_effects;111bool no_echo;112113void assign_buffers();114void clear_echo();115void mix_effects( blip_sample_t* out, int pair_count );116blargg_err_t new_bufs( int size );117void delete_bufs();118};119120// Simpler interface and lower memory usage121class Simple_Effects_Buffer : public Effects_Buffer {122public:123struct config_t124{125bool enabled; // false = disable all effects126float echo; // 0.0 = none, 1.0 = lots127float stereo; // 0.0 = channels in center, 1.0 = channels on left/right128bool surround; // true = put some channels in back129};130config_t& config() { return config_; }131132// Apply any changes made to config()133void apply_config();134135public:136Simple_Effects_Buffer();137private:138config_t config_;139void chan_config(); // hide140};141142#endif143144145