Nsound  0.9.4
Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Nsound::ReverberationRoom Class Reference

#include <Nsound/ReverberationRoom.h>

Public Member Functions

 ReverberationRoom (const float64 &sample_rate, const float64 &room_feedback, const float64 &wet_percent=0.5, const float64 &dry_percent=1.0, const float64 &low_pass_frequency_Hz=7644.9, const float64 &stereo_spread_seconds=0.0005215)
 Default Constructor. More...
 
 ReverberationRoom (const ReverberationRoom &copy)
 
virtual ~ReverberationRoom ()
 
AudioStream filter (const AudioStream &x)
 
AudioStream filter (const Buffer &x)
 
void filter (float64 &out_left, float64 &out_right, const float64 &in_left, const float64 &in_right)
 
float64 getSampleRate () const
 
ReverberationRoomoperator= (const ReverberationRoom &rhs)
 
void reset ()
 

Protected Attributes

float64 sample_rate_
 
float64 wet_percent_
 
float64 dry_percent_
 
FilterCombLowPassFeedback ** comb_left_
 
FilterCombLowPassFeedback ** comb_right_
 
FilterAllPass ** allpass_left_
 
FilterAllPass ** allpass_right_
 

Static Protected Attributes

static const float64 ROOM_FEEDBACK_SCALE_ = 0.28
 
static const float64 ROOM_FEEDBACK_OFFSET_ = 0.7
 
static const uint32 N_COMB_FILTERS_ = 8
 
static const uint32 N_ALL_PASS_FILTERS_ = 4
 
static const float64 COMB_DELAY_TIME_SECONDS_ [N_COMB_FILTERS_]
 
static const float64 ALL_PASS_DELAY_TIME_SECONDS_ [N_ALL_PASS_FILTERS_]
 

Detailed Description

Definition at line 49 of file ReverberationRoom.h.

Constructor & Destructor Documentation

ReverberationRoom::ReverberationRoom ( const float64 sample_rate,
const float64 room_feedback,
const float64 wet_percent = 0.5,
const float64 dry_percent = 1.0,
const float64 low_pass_frequency_Hz = 7644.9,
const float64 stereo_spread_seconds = 0.0005215 
)

Default Constructor.

sample_rate: the sample rate room_feedback: 0.0 to 1.0, how quickly the room dampens the input wet_percent: 0.0 to 1.0, how much of the filtered input is added to the output dry_percent: 0.0 to 1.0, how much of the original input is added to the output low_pass_frequency_Hz: 0.0 to 1/2 sample rate, attenuate frequencies in the feedback stereo_spread_seconds: >= 0.0, how much delay between the Left and Right channels

Definition at line 91 of file ReverberationRoom.cc.

References ALL_PASS_DELAY_TIME_SECONDS_, allpass_left_, allpass_right_, COMB_DELAY_TIME_SECONDS_, comb_left_, comb_right_, dry_percent_, N_ALL_PASS_FILTERS_, N_COMB_FILTERS_, reset(), ROOM_FEEDBACK_OFFSET_, ROOM_FEEDBACK_SCALE_, sample_rate_, and wet_percent_.

98  :
99  sample_rate_(sample_rate),
100  wet_percent_(wet_percent),
101  dry_percent_(dry_percent),
102  comb_left_(NULL),
103  comb_right_(NULL),
104  allpass_left_(NULL),
105  allpass_right_(NULL)
106 {
107  // Bounds checks:
108  if(wet_percent_ < 0.0)
109  {
110  wet_percent_ = 0.0;
111  }
112 
113  if(wet_percent_ > 1.0)
114  {
115  wet_percent_ = 1.0;
116  }
117 
118  if(dry_percent_ < 0.0)
119  {
120  dry_percent_ = 0.0;
121  }
122 
123  if(dry_percent_ > 1.0)
124  {
125  dry_percent_ = 1.0;
126  }
127 
128  float64 lpf = low_pass_frequency_Hz;
129 
130  if(lpf < 0.0)
131  {
132  lpf = 0.0;
133  }
134 
135  float64 stereo_spread = stereo_spread_seconds;
136 
137  if(stereo_spread < 0.0)
138  {
139  stereo_spread = 0.0;
140  }
141 
142  // Convert the room size to a delay time.
143  float64 comb_feedback = ROOM_FEEDBACK_SCALE_ * room_feedback
145 
146  // Allocate filter pointers
149 
150  for(uint32 i = 0; i < N_COMB_FILTERS_; ++i)
151  {
153  sample_rate_,
155  comb_feedback,
156  lpf);
157 
159  sample_rate_,
160  COMB_DELAY_TIME_SECONDS_[i] + stereo_spread,
161  comb_feedback,
162  lpf);
163  }
164 
165  // Allocate filter pointers
168 
169  for(uint32 i = 0; i < N_ALL_PASS_FILTERS_; ++i)
170  {
171  allpass_left_[i] = new FilterAllPass(
172  sample_rate_,
174  0.5);
175 
176  allpass_right_[i] = new FilterAllPass(
177  sample_rate_,
178  ALL_PASS_DELAY_TIME_SECONDS_[i] + stereo_spread,
179  0.5);
180  }
181 
183 
184  // Init random number generator.
185  std::srand(static_cast<unsigned int>(std::time(0)));
186 }
unsigned int uint32
Definition: Nsound.h:153
FilterCombLowPassFeedback ** comb_left_
static const float64 ALL_PASS_DELAY_TIME_SECONDS_[N_ALL_PASS_FILTERS_]
FilterCombLowPassFeedback ** comb_right_
static const float64 ROOM_FEEDBACK_OFFSET_
double float64
Definition: Nsound.h:146
static const float64 ROOM_FEEDBACK_SCALE_
static const float64 COMB_DELAY_TIME_SECONDS_[N_COMB_FILTERS_]
static const uint32 N_COMB_FILTERS_
A class for filtering audio in the frequecy domain.
FilterAllPass ** allpass_left_
static const uint32 N_ALL_PASS_FILTERS_
FilterAllPass ** allpass_right_
ReverberationRoom::ReverberationRoom ( const ReverberationRoom copy)

Definition at line 190 of file ReverberationRoom.cc.

191  :
195  comb_left_(NULL),
196  comb_right_(NULL),
197  allpass_left_(NULL),
198  allpass_right_(NULL)
199 {
200  *this = copy;
201 }
FilterCombLowPassFeedback ** comb_left_
FilterCombLowPassFeedback ** comb_right_
FilterAllPass ** allpass_left_
FilterAllPass ** allpass_right_
ReverberationRoom::~ReverberationRoom ( )
virtual

Definition at line 205 of file ReverberationRoom.cc.

References allpass_left_, allpass_right_, comb_left_, comb_right_, N_ALL_PASS_FILTERS_, and N_COMB_FILTERS_.

206 {
207  for(uint32 i = 0; i < N_COMB_FILTERS_; ++i)
208  {
209  delete comb_left_[i];
210  delete comb_right_[i];
211  }
212  delete [] comb_left_;
213  delete [] comb_right_;
214 
215  for(uint32 i = 0; i < N_ALL_PASS_FILTERS_; ++i)
216  {
217  delete allpass_left_[i];
218  delete allpass_right_[i];
219  }
220  delete [] allpass_left_;
221  delete [] allpass_right_;
222 }
unsigned int uint32
Definition: Nsound.h:153
FilterCombLowPassFeedback ** comb_left_
FilterCombLowPassFeedback ** comb_right_
static const uint32 N_COMB_FILTERS_
FilterAllPass ** allpass_left_
static const uint32 N_ALL_PASS_FILTERS_
FilterAllPass ** allpass_right_

Member Function Documentation

AudioStream ReverberationRoom::filter ( const AudioStream x)

Definition at line 226 of file ReverberationRoom.cc.

References Nsound::AudioStream::getLength(), Nsound::AudioStream::getNChannels(), reset(), and sample_rate_.

Referenced by filter(), main(), and my_main().

227 {
228  if(x.getNChannels() == 1)
229  {
230  return filter(x[0]);
231  }
232  else if(x.getNChannels() < 2)
233  {
234  return x;
235  }
236 
237  reset();
238 
240 
241  uint32 n_samples = x.getLength();
242 
243  float64 left;
244  float64 right;
245 
246  for(uint32 n = 0; n < n_samples; ++n)
247  {
248  filter(left, right, x[0][n], x[1][n]);
249 
250  y[0] << left;
251  y[1] << right;
252  }
253 
254  return y;
255 }
unsigned int uint32
Definition: Nsound.h:153
uint32 getLength() const
Returns the number of samples of audio data in the stream.
Definition: AudioStream.cc:197
double float64
Definition: Nsound.h:146
AudioStream filter(const AudioStream &x)
uint32 getNChannels(void) const
Returns the number of audio channels in the stream.
Definition: AudioStream.h:212
AudioStream ReverberationRoom::filter ( const Buffer x)

Definition at line 259 of file ReverberationRoom.cc.

References filter(), Nsound::Buffer::getLength(), reset(), and sample_rate_.

260 {
261  reset();
263 
264  uint32 n_samples = x.getLength();
265 
266  float64 left;
267  float64 right;
268 
269  for(uint32 n = 0; n < n_samples; ++n)
270  {
271  filter(left, right, x[n], x[n]);
272 
273  y[0] << left;
274  y[1] << right;
275  }
276 
277  return y;
278 }
unsigned int uint32
Definition: Nsound.h:153
double float64
Definition: Nsound.h:146
AudioStream filter(const AudioStream &x)
uint32 getLength() const
Returns the number of samples in the Buffer.
Definition: Buffer.h:587
void ReverberationRoom::filter ( float64 out_left,
float64 out_right,
const float64 in_left,
const float64 in_right 
)

Definition at line 282 of file ReverberationRoom.cc.

References allpass_left_, allpass_right_, comb_left_, comb_right_, dry_percent_, Nsound::FilterAllPass::filter(), Nsound::FilterCombLowPassFeedback::filter(), getRandom(), N_ALL_PASS_FILTERS_, N_COMB_FILTERS_, and wet_percent_.

287 {
288  out_left = 0.0 + getRandom() * 1e-23;
289  out_right = 0.0 + getRandom() * 1e-23;
290 
291  // Sum the comb filters in parallel
292  for(uint32 i = 0; i < N_COMB_FILTERS_; ++i)
293  {
294  out_left += comb_left_[i]->filter(in_left * 0.15);
295  out_right += comb_right_[i]->filter(in_right * 0.15);
296  }
297 
298  // Serilalize the all pass fitlers
299  for(uint32 i = 0; i < N_ALL_PASS_FILTERS_; ++i)
300  {
301  out_left = allpass_left_[i]->filter(out_left);
302  out_right = allpass_right_[i]->filter(out_left);
303  }
304 
305  out_left = wet_percent_ * out_left + dry_percent_ * in_left;
306  out_right = wet_percent_ * out_right + dry_percent_ * in_right;
307 }
unsigned int uint32
Definition: Nsound.h:153
FilterCombLowPassFeedback ** comb_left_
FilterCombLowPassFeedback ** comb_right_
float64 getRandom()
AudioStream filter(const AudioStream &x)
static const uint32 N_COMB_FILTERS_
AudioStream filter(const AudioStream &x)
FilterAllPass ** allpass_left_
static const uint32 N_ALL_PASS_FILTERS_
FilterAllPass ** allpass_right_
float64 Nsound::ReverberationRoom::getSampleRate ( ) const
inline

Definition at line 88 of file ReverberationRoom.h.

References sample_rate_.

88 { return sample_rate_; };
ReverberationRoom & ReverberationRoom::operator= ( const ReverberationRoom rhs)

Definition at line 312 of file ReverberationRoom.cc.

References allpass_left_, allpass_right_, comb_left_, comb_right_, dry_percent_, N_ALL_PASS_FILTERS_, N_COMB_FILTERS_, sample_rate_, and wet_percent_.

313 {
314  if(this == & rhs)
315  {
316  return *this;
317  }
318 
322 
323  for(uint32 i = 0; i < N_COMB_FILTERS_; ++i)
324  {
325  *comb_left_[i] = *(rhs.comb_left_[i]);
326  *comb_right_[i] = *(rhs.comb_right_[i]);
327  }
328 
329  for(uint32 i = 0; i < N_ALL_PASS_FILTERS_; ++i)
330  {
331  *allpass_left_[i] = *(rhs.allpass_left_[i]);
332  *allpass_right_[i] = *(rhs.allpass_right_[i]);
333  }
334 
335  return *this;
336 }
unsigned int uint32
Definition: Nsound.h:153
FilterCombLowPassFeedback ** comb_left_
FilterCombLowPassFeedback ** comb_right_
static const uint32 N_COMB_FILTERS_
FilterAllPass ** allpass_left_
static const uint32 N_ALL_PASS_FILTERS_
FilterAllPass ** allpass_right_
void ReverberationRoom::reset ( )

Definition at line 340 of file ReverberationRoom.cc.

References allpass_left_, allpass_right_, comb_left_, comb_right_, N_ALL_PASS_FILTERS_, N_COMB_FILTERS_, Nsound::FilterCombLowPassFeedback::reset(), and Nsound::FilterAllPass::reset().

Referenced by filter(), and ReverberationRoom().

341 {
342  for(uint32 i = 0; i < N_COMB_FILTERS_; ++i)
343  {
344  comb_left_[i]->reset();
345  comb_right_[i]->reset();
346  }
347 
348  for(uint32 i = 0; i < N_ALL_PASS_FILTERS_; ++i)
349  {
350  allpass_left_[i]->reset();
351  allpass_right_[i]->reset();
352  }
353 }
unsigned int uint32
Definition: Nsound.h:153
FilterCombLowPassFeedback ** comb_left_
FilterCombLowPassFeedback ** comb_right_
static const uint32 N_COMB_FILTERS_
FilterAllPass ** allpass_left_
static const uint32 N_ALL_PASS_FILTERS_
FilterAllPass ** allpass_right_

Member Data Documentation

float64 Nsound::ReverberationRoom::sample_rate_
protected

Definition at line 98 of file ReverberationRoom.h.

Referenced by filter(), getSampleRate(), operator=(), and ReverberationRoom().

float64 Nsound::ReverberationRoom::wet_percent_
protected

Definition at line 100 of file ReverberationRoom.h.

Referenced by filter(), operator=(), and ReverberationRoom().

float64 Nsound::ReverberationRoom::dry_percent_
protected

Definition at line 101 of file ReverberationRoom.h.

Referenced by filter(), operator=(), and ReverberationRoom().

FilterCombLowPassFeedback** Nsound::ReverberationRoom::comb_left_
protected

Definition at line 103 of file ReverberationRoom.h.

Referenced by filter(), operator=(), reset(), ReverberationRoom(), and ~ReverberationRoom().

FilterCombLowPassFeedback** Nsound::ReverberationRoom::comb_right_
protected

Definition at line 104 of file ReverberationRoom.h.

Referenced by filter(), operator=(), reset(), ReverberationRoom(), and ~ReverberationRoom().

FilterAllPass** Nsound::ReverberationRoom::allpass_left_
protected

Definition at line 106 of file ReverberationRoom.h.

Referenced by filter(), operator=(), reset(), ReverberationRoom(), and ~ReverberationRoom().

FilterAllPass** Nsound::ReverberationRoom::allpass_right_
protected

Definition at line 107 of file ReverberationRoom.h.

Referenced by filter(), operator=(), reset(), ReverberationRoom(), and ~ReverberationRoom().

const float64 ReverberationRoom::ROOM_FEEDBACK_SCALE_ = 0.28
staticprotected

Definition at line 109 of file ReverberationRoom.h.

Referenced by ReverberationRoom().

const float64 ReverberationRoom::ROOM_FEEDBACK_OFFSET_ = 0.7
staticprotected

Definition at line 110 of file ReverberationRoom.h.

Referenced by ReverberationRoom().

const uint32 Nsound::ReverberationRoom::N_COMB_FILTERS_ = 8
staticprotected

Definition at line 112 of file ReverberationRoom.h.

Referenced by filter(), operator=(), reset(), ReverberationRoom(), and ~ReverberationRoom().

const uint32 Nsound::ReverberationRoom::N_ALL_PASS_FILTERS_ = 4
staticprotected

Definition at line 113 of file ReverberationRoom.h.

Referenced by filter(), operator=(), reset(), ReverberationRoom(), and ~ReverberationRoom().

const float64 ReverberationRoom::COMB_DELAY_TIME_SECONDS_
staticprotected
Initial value:
=
{
1116.0 / 44100.0,
1188.0 / 44100.0,
1277.0 / 44100.0,
1356.0 / 44100.0,
1422.0 / 44100.0,
1491.0 / 44100.0,
1557.0 / 44100.0,
1617.0 / 44100.0
}

Definition at line 115 of file ReverberationRoom.h.

Referenced by ReverberationRoom().

const float64 ReverberationRoom::ALL_PASS_DELAY_TIME_SECONDS_
staticprotected
Initial value:
=
{
556.0 / 44100.0,
441.0 / 44100.0,
341.0 / 44100.0,
225.0 / 44100.0
}

Definition at line 117 of file ReverberationRoom.h.

Referenced by ReverberationRoom().


The documentation for this class was generated from the following files: