Open Ephys GUI
 All Classes Functions Variables Pages
ResamplingNode.h
1 /*
2  ------------------------------------------------------------------
3 
4  This file is part of the Open Ephys GUI
5  Copyright (C) 2012 Open Ephys
6 
7  ------------------------------------------------------------------
8 
9  This program is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifndef __RESAMPLINGNODE_H_79663B0__
25 #define __RESAMPLINGNODE_H_79663B0__
26 
27 
28 #include "../../JuceLibraryCode/JuceHeader.h"
29 #include "../Dsp/Dsp.h"
30 #include "GenericProcessor.h"
31 
32 /**
33 
34  --UNDER CONSTRUCTION--
35 
36  Changes the sample rate of continuous data.
37 
38  Code is based on Juce's ResamplingAudioSource class.
39 
40  @see GenericProcessor
41 
42 */
43 
45 
46 {
47 public:
48 
49  // real member functions:
50  ResamplingNode(bool destBufferIsTempBuffer);
51  ~ResamplingNode();
52 
53  AudioSampleBuffer* getBufferAddress() { return destBuffer; }
54  void updateFilter();
55 
56  void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
57  void releaseResources();
58  void process(AudioSampleBuffer &buffer, MidiBuffer &midiMessages, int& nSamples);
59  void setParameter (int parameterIndex, float newValue);
60 
61  AudioSampleBuffer* getContinuousBuffer() {return destBuffer;}
62 
63 
64 private:
65 
66  // sample rate, timebase, and ratio info:
67  double sourceBufferSampleRate, destBufferSampleRate;
68  double ratio, lastRatio;
69  double destBufferTimebaseSecs;
70  int destBufferWidth;
71 
72  // major objects:
73  Dsp::Filter* filter;
74  AudioSampleBuffer* destBuffer;
75  AudioSampleBuffer* tempBuffer;
76 
77  // is the destBuffer a temp buffer or not?
78  bool destBufferIsTempBuffer;
79  bool isTransmitting;
80 
81  // indexing objects that persist between rounds:
82  int destBufferPos;
83 
84  // for testing purposes only:
85  void writeContinuousBuffer(float*, int, int);
86 
87  FILE* file;
88  int64 timestamp;
89  Time timer;
90 
91  int16* continuousDataBuffer;
92 
93  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ResamplingNode);
94 
95 };
96 
97 
98 
99 
100 #endif // __RESAMPLINGNODE_H_79663B0__