Skip to content
Snippets Groups Projects
Commit 4e43b764 authored by jsiegle's avatar jsiegle
Browse files

Change visualizer refresh rate

parent 4ba483e2
No related branches found
No related tags found
No related merge requests found
......@@ -279,8 +279,6 @@ void LfpDisplayNode::process(AudioSampleBuffer &buffer, MidiBuffer &events, int&
initializeEventChannel();
checkForEvents(events); // update timestamp, see if we got any TTL events
int samplesLeft = displayBuffer->getNumSamples() - displayBufferIndex;
......@@ -324,52 +322,7 @@ void LfpDisplayNode::process(AudioSampleBuffer &buffer, MidiBuffer &events, int&
displayBufferIndex = extraSamples;
}
//std::cout << *displayBuffer->getSampleData(displayBuffer->getNumChannels()-1,
// displayBufferIndex-1) << std::endl;
///// failed attempt to use abstractFifo:
// int start1, size1, start2, size2;
// abstractFifo.prepareToWrite(nSamples, start1, size1, start2, size2);
// if (size1 > 0)
// {
// for (int chan = 0; chan < buffer.getNumChannels(); chan++)
// {
// displayBuffer->copyFrom(chan, // destChannel
// start1, // destStartSample
// buffer, // source
// chan, // source channel
// 0, // source start sample
// size1); // numSamples
// }
// displayBufferIndex += size1;
// }
// if (size2 > 0)
// {
// for (int chan = 0; chan < buffer.getNumChannels(); chan++)
// {
// displayBuffer->copyFrom(chan, // destChannel
// start2, // destStartSample
// buffer, // source
// chan, // source channel
// size1, // source start sample
// size2); // numSamples
// }
// displayBufferIndex = size2;
// }
// std::cout << displayBufferIndex << std::endl;
// abstractFifo.finishedWrite(size1 + size2);
}
......@@ -26,7 +26,7 @@
#include <math.h>
LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* processor_) :
timebase(1.0f), displayGain(2.f), timeOffset(0.0f), processor(processor_),
timebase(1.0f), displayGain(1.0f), timeOffset(0.0f), processor(processor_),
screenBufferIndex(0), displayBufferIndex(0)
{
......@@ -38,6 +38,8 @@ LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* processor_) :
displayBufferSize = displayBuffer->getNumSamples();
std::cout << "Setting displayBufferSize on LfpDisplayCanvas to " << displayBufferSize << std::endl;
screenBuffer = new AudioSampleBuffer(MAX_N_CHAN, MAX_N_SAMP);
viewport = new Viewport();
lfpDisplay = new LfpDisplay(this, viewport);
timescale = new LfpTimescale(this);
......@@ -56,6 +58,8 @@ LfpDisplayCanvas::LfpDisplayCanvas(LfpDisplayNode* processor_) :
LfpDisplayCanvas::~LfpDisplayCanvas()
{
deleteAndZero(screenBuffer);
}
void LfpDisplayCanvas::resized()
......@@ -78,14 +82,14 @@ void LfpDisplayCanvas::beginAnimation()
screenBufferIndex = 0;
startCallbacks();
startTimer(500);
}
void LfpDisplayCanvas::endAnimation()
{
std::cout << "Ending animation." << std::endl;
stopCallbacks();
stopTimer();
}
void LfpDisplayCanvas::update()
......@@ -103,8 +107,6 @@ void LfpDisplayCanvas::update()
repaint();
lfpDisplay->repaint();
}
......@@ -133,25 +135,30 @@ void LfpDisplayCanvas::refreshScreenBuffer()
screenBufferIndex = 0;
int w = lfpDisplay->getWidth();
//std::cout << "Refreshing buffer size to " << w << "pixels." << std::endl;
screenBuffer->clear();
for (int i = 0; i < w; i++)
{
float x = float(i);
// int w = lfpDisplay->getWidth();
// //std::cout << "Refreshing buffer size to " << w << "pixels." << std::endl;
for (int n = 0; n < nChans; n++)
{
waves[n][i*2] = x;
waves[n][i*2+1] = 0.5f; // line in center of display
}
}
// for (int i = 0; i < w; i++)
// {
// float x = float(i);
// for (int n = 0; n < nChans; n++)
// {
// waves[n][i*2] = x;
// waves[n][i*2+1] = 0.5f; // line in center of display
// }
// }
}
void LfpDisplayCanvas::updateScreenBuffer()
{
// copy new samples from the displayBuffer into the screenBuffer (waves)
lastScreenBufferIndex = screenBufferIndex;
int maxSamples = lfpDisplay->getWidth();
int index = processor->getDisplayBufferIndex();
......@@ -179,16 +186,31 @@ void LfpDisplayCanvas::updateScreenBuffer()
float alpha = (float) subSampleOffset;
float invAlpha = 1.0f - alpha;
screenBuffer->clear(screenBufferIndex, 1);
for (int channel = 0; channel < nChans; channel++) {
gain = -1.0f / (processor->channels[channel]->bitVolts * float(0x7fff));
waves[channel][screenBufferIndex*2+1] =
*(displayBuffer->getSampleData(channel, displayBufferIndex))*invAlpha*gain*displayGain;
gain = 1.0f / (processor->channels[channel]->bitVolts * float(0x7fff));
screenBuffer->addFrom(channel, // destChannel
screenBufferIndex, // destStartSample
displayBuffer->getSampleData(channel, displayBufferIndex), // source
1, // numSamples
invAlpha*gain*displayGain); // gain
waves[channel][screenBufferIndex*2+1] +=
*(displayBuffer->getSampleData(channel, nextPos))*alpha*gain*displayGain;
screenBuffer->addFrom(channel, // destChannel
screenBufferIndex, // destStartSample
displayBuffer->getSampleData(channel, nextPos), // source
1, // numSamples
alpha*gain*displayGain); // gain
waves[channel][screenBufferIndex*2+1] += 0.5f; // to center in viewport
//waves[channel][screenBufferIndex*2+1] =
// *(displayBuffer->getSampleData(channel, displayBufferIndex))*invAlpha*gain*displayGain;
//waves[channel][screenBufferIndex*2+1] +=
// *(displayBuffer->getSampleData(channel, nextPos))*alpha*gain*displayGain;
//waves[channel][screenBufferIndex*2+1] += 0.5f; // to center in viewport
}
......@@ -220,12 +242,12 @@ void LfpDisplayCanvas::updateScreenBuffer()
float LfpDisplayCanvas::getXCoord(int chan, int samp)
{
return waves[chan][samp*2];
return samp;
}
float LfpDisplayCanvas::getYCoord(int chan, int samp)
{
return waves[chan][samp*2+1];
return *screenBuffer->getSampleData(chan, samp);
}
void LfpDisplayCanvas::paint(Graphics& g)
......@@ -235,16 +257,13 @@ void LfpDisplayCanvas::paint(Graphics& g)
updateScreenBuffer();
g.fillAll(Colours::grey);
g.setColour(Colours::yellow);
g.setColour(Colours::grey);
g.drawLine(screenBufferIndex, 0, screenBufferIndex, getHeight());
lfpDisplay->repaint();
g.fillRect(0, 0, getWidth(), getHeight());
g.setColour(Colours::yellow);
//g.drawLine(0,0, getWidth(), getHeight());
//g.drawLine(0,getHeight(),getWidth(), 0);
g.drawLine(screenBufferIndex, 0, screenBufferIndex, getHeight());
}
......@@ -335,20 +354,23 @@ void LfpDisplay::paint(Graphics& g)
int bottomBorder = viewport->getViewHeight() + topBorder;
// ensure that only visible channels are redrawn
for (int i = 0; i < numChans; i++)
{
// for (int i = 0; i < numChans; i++)
// {
int componentTop = getChildComponent(i)->getY();
int componentBottom = getChildComponent(i)->getHeight() + componentTop;
// int componentTop = getChildComponent(i)->getY();
// int componentBottom = getChildComponent(i)->getHeight() + componentTop;
if ( (topBorder <= componentBottom && bottomBorder >= componentTop) )
{
getChildComponent(i)->repaint();
// if ( (topBorder <= componentBottom && bottomBorder >= componentTop) )
// {
// getChildComponent(i)->repaint(canvas->lastScreenBufferIndex,
// 0,
// canvas->screenBufferIndex,
// getChildComponent(i)->getHeight());
//std::cout << i << std::endl;
}
// //std::cout << i << std::endl;
// }
}
// }
}
......@@ -396,13 +418,15 @@ void LfpChannelDisplay::paint(Graphics& g)
g.drawLine(0, getHeight()/2, getWidth(), getHeight()/2);
for (int i = 0; i < getWidth()-1; i++)
int stepSize = 1;
for (int i = 0; i < getWidth()-1; i += stepSize)
{
g.drawLine(i,
canvas->getYCoord(chan, i)*getHeight(),
i+1,
canvas->getYCoord(chan, i+1)*getHeight());
(canvas->getYCoord(chan, i)+0.5f)*getHeight(),
i+stepSize,
(canvas->getYCoord(chan, i+stepSize)+0.5f)*getHeight());
}
}
......
......@@ -65,6 +65,9 @@ public:
float getXCoord(int chan, int samp);
float getYCoord(int chan, int samp);
int screenBufferIndex;
int lastScreenBufferIndex;
private:
float sampleRate;
......@@ -74,10 +77,11 @@ private:
static const int MAX_N_CHAN = 256; // maximum number of channels
static const int MAX_N_SAMP = 5000; // maximum display size in pixels
float waves[MAX_N_CHAN][MAX_N_SAMP*2]; // we need an x and y point for each sample
//float waves[MAX_N_CHAN][MAX_N_SAMP*2]; // we need an x and y point for each sample
LfpDisplayNode* processor;
AudioSampleBuffer* displayBuffer;
AudioSampleBuffer* screenBuffer;
MidiBuffer* eventBuffer;
ScopedPointer<LfpTimescale> timescale;
......@@ -86,7 +90,7 @@ private:
void refreshScreenBuffer();
void updateScreenBuffer();
int screenBufferIndex;
int displayBufferIndex;
int displayBufferSize;
......
......@@ -398,8 +398,6 @@ void SpikeDisplay::plotSpike(const SpikeObject& spike)
}
// ----------------------------------------------------------------
SpikePlot::SpikePlot(SpikeDisplayCanvas* sdc, int elecNum, int numChans) :
......
......@@ -61,7 +61,7 @@ public:
virtual void setParameter(int, int, int, float) = 0;
/** Starts the timer callbacks. */
void startCallbacks() { startTimer(1/refreshRate); }
void startCallbacks() { startTimer(100); }
/** Stops the timer callbacks. */
void stopCallbacks() { stopTimer(); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment