Skip to content
Browse files

Directly filter in FilterNode.cpp

  • Loading branch information...
1 parent 8d0136c commit 689bfe4e2a46d2e55a88362a8744533362f43100 Caleb Kemere committed Feb 14, 2012
View
3 Builds/Linux/build/savedState.xml
@@ -3,6 +3,7 @@
<PROCESSORGRAPH>
<SIGNALCHAIN>
<PROCESSOR name="Sources/Intan Demo Board" insertionPoint="0"/>
- <PROCESSOR name="Sinks/LFP Viewer" insertionPoint="1"/>
+ <PROCESSOR name="Filters/Bandpass Filter" insertionPoint="1"/>
+ <PROCESSOR name="Sinks/LFP Viewer" insertionPoint="2"/>
</SIGNALCHAIN>
</PROCESSORGRAPH>
View
2 Builds/Linux/build/windowState.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<MAINWINDOW>
- <BOUNDS x="1729" y="52" w="1161" h="968" fullscreen="0"/>
+ <BOUNDS x="66" y="24" w="1854" h="1056" fullscreen="0"/>
</MAINWINDOW>
View
119 Source/Processors/FilterNode.cpp
@@ -123,6 +123,9 @@ void FilterNode::setNumInputs(int inputs)
16, // number of channels (must be const)
Dsp::DirectFormII> // realization
(1024); // number of samples over which to fade
+
+ w1 = new float[16*3];
+ w2 = new float[16*3];
} else if (nChans == 32) {
@@ -134,15 +137,32 @@ void FilterNode::setNumInputs(int inputs)
(1024); // number of samples over which to fade
// parameter changes
+ w1 = new float[32*3];
+ w2 = new float[32*3];
+
} else {
// send a message saying this is not implemented
}
//std::cout << "Filter created with " << getNumInputs() << " channels." << std::endl;
-
setFilterParameters();
+
+ // [b,a] = butter(2,600/15000,'high')
+ a1_1 = -1.787432517956485;
+ a1_2 = 0.807949591420913;
+ b1_0 = 0.898845527344350;
+ b1_1 = -1.797691054688699;
+ b1_2 = 0.898845527344350;
+
+ // [b,a] = butter(2,6000/15000)
+ a2_1 = -0.073623846384979;
+ a2_2 = 0.172531250527518;
+ b2_0 = 0.274726851035635;
+ b2_1 = 0.549453702071270;
+ b2_2 = 0.274726851035635;
+
setPlayConfigDetails(getNumInputs(), getNumOutputs(), 44100.0, 128);
@@ -208,8 +228,101 @@ void FilterNode::process(AudioSampleBuffer &buffer,
//int nSamps = getNumSamples(midiMessages);
//std::cout << nSamples << std::endl;
- filter->process (nSamples, buffer.getArrayOfChannels());
- //std::cout << "Filter node:" << *buffer.getSampleData(0,0);
+ const int nChan = buffer.getNumChannels();
+
+ static int flag = 100;
+
+ if (flag == 100) {
+ std::cout << "Filternode: nChan " << nChan << " nSamples " << nSamples << std::endl;
+ flag = 0;
+ }
+ else
+ flag++;
+
+ static int offset = 0;
+ static int offset1 = 1;
+ static int offset2 = 2;
+
+ float **data = buffer.getArrayOfChannels();
+
+ //filter->process (nSamples, buffer.getArrayOfChannels());
+
+#ifdef USE_INTRINSICS
+ __m128d A1_1, A1_2, B1_0, B1_1, B1_2;
+ __m128d W1_0, W1_1, W1_2;
+ __m128d Y, W2_0, W2_1, W2_2;
+ __m128d A2_1, A2_2, B2_0, B2_1, B2_2;
+ __m128d mul1, mul2, mul3, mul4, mul5;
+
+ A1_1 = _mm_loadl_ps(&a1_1);
+ A1_2 = _mm_loadl_ps(&a1_2);
+ B1_0 = _mm_loadl_ps(&b1_0);
+ B1_1 = _mm_loadl_ps(&b1_1);
+ B1_2 = _mm_loadl_ps(&b1_2);
+
+ A2_1 = _mm_loadl_ps(&a2_1);
+ A2_2 = _mm_loadl_ps(&a2_2);
+ B2_0 = _mm_loadl_ps(&b2_0);
+ B2_1 = _mm_loadl_ps(&b2_1);
+ B2_2 = _mm_loadl_ps(&b2_2);
+#endif
+ for (int i=0; i < nSamples; i++) {
+#ifdef USE_INTRINSICS
+ for (int c=0; c<nChan; c = c + 4) {
+ W1_1 = _mm_loadu_ps(&(w[c + offset1*nChan]));
+ W1_2 = _mm_loadu_ps(&(w[c + offset2*nChan]));
+
+ // CRAP - the order of data in memory is wrong (each channel is sequential)
+ W1_0 = _mm_loadu_ps(&(w[c + offset1*nChan]));
+
+ w1[c + offset*nChan] = data[c][i] - \
+ a1_1 * w1[c + offset1*nChan] - \
+ a1_2 * w1[c + offset2*nChan];
+
+ w2[c + offset*nChan] = b1_0 * w1[c + offset*nChan] + \
+ b1_1 * w1[c + offset1*nChan] + \
+ b1_2 * w1[c + offset2*nChan];
+
+ w2[c + offset*nChan] = w2[c+offset*nChan] - \
+ a2_1 * w2[c + offset1*nChan] - \
+ a2_2 * w2[c + offset2*nChan];
+
+ data[c][i] = b2_0 * w2[c + offset*nChan] + \
+ b2_1 * w2[c + offset1*nChan] + \
+ b2_2 * w2[c + offset2*nChan];
+ }
+#else
+ for (int c=0; c<nChan; c++) {
+ w1[c + offset*nChan] = data[c][i] - \
+ a1_1 * w1[c + offset1*nChan] - \
+ a1_2 * w1[c + offset2*nChan];
+
+ w2[c + offset*nChan] = b1_0 * w1[c + offset*nChan] + \
+ b1_1 * w1[c + offset1*nChan] + \
+ b1_2 * w1[c + offset2*nChan];
+
+ w2[c + offset*nChan] = w2[c+offset*nChan] - \
+ a2_1 * w2[c + offset1*nChan] - \
+ a2_2 * w2[c + offset2*nChan];
+
+ data[c][i] = b2_0 * w2[c + offset*nChan] + \
+ b2_1 * w2[c + offset1*nChan] + \
+ b2_2 * w2[c + offset2*nChan];
+ }
+#endif
+ if (offset == 0) {
+ offset = 2; offset1 = 0; offset2 = 1;
+ }
+ else if (offset == 1) {
+ offset = 0; offset1 = 1; offset2 = 2;
+ }
+ else {
+ offset = 1; offset1 = 2; offset2 = 0;
+ }
+
+ }
+
+ //std::cout << "Filter node:" << *buffer.getSampleData(0,0);
}
View
6 Source/Processors/FilterNode.h
@@ -44,6 +44,12 @@ class FilterNode : public GenericProcessor
private:
double lowCut, highCut;
+
+ float *w1;
+ float a1_1, a1_2, b1_0, b1_1, b1_2;
+ float *w2;
+ float a2_1, a2_2, b2_0, b2_1, b2_2;
+
Dsp::Filter* filter;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FilterNode);

0 comments on commit 689bfe4

Please sign in to comment.
Something went wrong with that request. Please try again.