blargg_err_t Effects_Buffer::set_channel_count( int count, int const* types ) { RETURN_ERR( Multi_Buffer::set_channel_count( count, types ) ); delete_bufs(); mixer.samples_read = 0; RETURN_ERR( chans.resize( count + extra_chans ) ); RETURN_ERR( new_bufs( min( bufs_max, count + extra_chans ) ) ); for ( int i = bufs_size; --i >= 0; ) RETURN_ERR( bufs [i].set_sample_rate( sample_rate(), length() ) ); for ( int i = chans.size(); --i >= 0; ) { chan_t& ch = chans [i]; ch.cfg.vol = 1.0f; ch.cfg.pan = 0.0f; ch.cfg.surround = false; ch.cfg.echo = false; } // side channels with echo chans [2].cfg.echo = true; chans [3].cfg.echo = true; clock_rate( clock_rate_ ); bass_freq( bass_freq_ ); apply_config(); clear(); return 0; }
Blip_Buffer::blargg_err_t Blip_Buffer::set_sample_rate( long new_rate, int msec ) { if ( buffer_size_ == silent_buf_size ) { assert( 0 ); return "Internal (tried to resize Silent_Blip_Buffer)"; } // start with maximum length that resampled time can represent long new_size = (ULONG_MAX >> BLIP_BUFFER_ACCURACY) - blip_buffer_extra_ - 64; if ( msec != blip_max_length ) { long s = (new_rate * (msec + 1) + 999) / 1000; if ( s < new_size ) new_size = s; else assert( 0 ); // fails if requested buffer length exceeds limit } if ( buffer_size_ != new_size ) { void* p = realloc( buffer_, (new_size + blip_buffer_extra_) * sizeof *buffer_ ); if ( !p ) return "Out of memory"; buffer_ = (buf_t_*) p; } buffer_size_ = new_size; assert( buffer_size_ != silent_buf_size ); // size should never happen to match this // update things based on the sample rate sample_rate_ = new_rate; length_ = new_size * 1000 / new_rate - 1; if ( msec ) assert( length_ == msec ); // ensure length is same as that passed in // update these since they depend on sample rate if ( clock_rate_ ) clock_rate( clock_rate_ ); bass_freq( bass_freq_ ); clear(); return 0; // success }
Blip_Buffer::blargg_err_t Blip_Buffer::set_sample_rate( long new_rate, int msec ) { // start with maximum length that resampled time can represent long new_size = (ULONG_MAX >> BLIP_BUFFER_ACCURACY) - buffer_extra - 64; if ( msec != blip_max_length ) { long s = (new_rate * (msec + 1) + 999) / 1000; if ( s < new_size ) new_size = s; else assert( 0 ); // fails if requested buffer length exceeds limit } if ( buffer_size_ != new_size ) { void* p = realloc( buffer_, (new_size + buffer_extra) * sizeof *buffer_ ); if ( !p ) return "Out of memory"; buffer_ = (buf_t_*) p; } buffer_size_ = new_size; // update things based on the sample rate sample_rate_ = new_rate; length_ = int(new_size * 1000 / new_rate - 1); if ( msec ) assert( length_ == msec ); // ensure length is same as that passed in if ( clock_rate_ ) clock_rate( clock_rate_ ); bass_freq( bass_freq_ ); clear(); return 0; // success }