@@ -38,8 +38,14 @@ IIRFilterNode::IIRFilterNode(
3838 isInitialized_ = true ;
3939 channelCountMode_ = ChannelCountMode::MAX;
4040
41- x_.resize (IIRFilterNode::bufferLength, 0 .0f );
42- y_.resize (IIRFilterNode::bufferLength, 0 .0f );
41+ int maxChannels = 32 ; // TODO: magic number, jaki jest faktyczy Channels?
42+ xBuffers_.resize (maxChannels);
43+ yBuffers_.resize (maxChannels);
44+
45+ for (int c = 0 ; c < maxChannels; ++c) {
46+ xBuffers_[c].resize (bufferLength, 0 .0f );
47+ yBuffers_[c].resize (bufferLength, 0 .0f );
48+ }
4349
4450 size_t feedforwardLength = feedforward_.size ();
4551 size_t feedbackLength = feedback_.size ();
@@ -108,6 +114,8 @@ void IIRFilterNode::getFrequencyResponse(
108114// y[n] = sum(b[k] * x[n - k], k = 0, M) - sum(a[k] * y[n - k], k = 1, N)
109115// where b[k] are the feedforward coefficients and a[k] are the feedback coefficients of the filter
110116
117+ // TODO: tail
118+
111119std::shared_ptr<AudioBus> IIRFilterNode::processNode (
112120 const std::shared_ptr<AudioBus> &processingBus,
113121 int framesToProcess) {
@@ -117,34 +125,36 @@ std::shared_ptr<AudioBus> IIRFilterNode::processNode(
117125 size_t feedbackLength = feedback_.size ();
118126 int minLength = std::min (feedbackLength, feedforwardLength);
119127
128+ int mask = bufferLength - 1 ;
129+
120130 for (int c = 0 ; c < numChannels; ++c) {
121131 // for (int c = 0; c < 1; ++c) {
122132 auto channelData = processingBus->getChannel (c)->getData ();
123133 // auto channelData2 = processingBus->getChannel(1)->getData();
134+ auto &x = xBuffers_[c];
135+ auto &y = yBuffers_[c];
124136
125137 for (int n = 0 ; n < framesToProcess; ++n) {
126138 float yn = feedforward_[0 ] * channelData[n];
127139
128140 for (int k = 1 ; k < minLength; ++k) {
129- int m = (m_bufferIndex - k) & (bufferLength - 1 ) ;
130- yn += feedforward_[k] * x_ [m];
131- yn -= feedback_[k] * y_ [m];
141+ int m = (n - k) & mask ;
142+ yn += feedforward_[k] * x [m];
143+ yn -= feedback_[k] * y [m];
132144 }
133145
134146 for (int k = minLength; k < feedforwardLength; ++k) {
135- yn += feedforward_[k] * x_[(m_bufferIndex - k) & (bufferLength - 1 ) ];
147+ yn += feedforward_[k] * x[(n - k) & mask ];
136148 }
137149 for (int k = minLength; k < feedbackLength; ++k) {
138- yn -= feedback_[k] * y_[(m_bufferIndex - k) & (bufferLength - 1 ) ];
150+ yn -= feedback_[k] * y[(n - k) & mask ];
139151 }
140152
141153 channelData[n] = yn;
142154 // channelData2[n] = yn;
143155
144- x_[m_bufferIndex] = channelData[n];
145- y_[m_bufferIndex] = yn;
146-
147- m_bufferIndex = (m_bufferIndex + 1 ) & (bufferLength - 1 );
156+ x[n & mask] = channelData[n];
157+ y[n & mask] = yn;
148158 }
149159 }
150160 return processingBus;
0 commit comments