Skip to content
Snippets Groups Projects
Commit ae38b575 authored by Stuart Layton's avatar Stuart Layton
Browse files

Signal Generator now generates fake action potentials!!! The phase dial can be...

Signal Generator now generates fake action potentials!!! The phase dial can be used to scale up and down noise on the spikes
parent c6faf745
No related branches found
No related tags found
No related merge requests found
......@@ -241,7 +241,7 @@
77F2E2E7A2419CB172C0B1EA /* MainWindow.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = MainWindow.cpp; path = ../../Source/MainWindow.cpp; sourceTree = SOURCE_ROOT; };
7977CAB4A151C41F4140FE1A /* Merger.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Merger.h; path = ../../Source/Processors/Utilities/Merger.h; sourceTree = SOURCE_ROOT; };
79892A4E41809A09A4711AC3 /* BebasNeue.otf */ = {isa = PBXFileReference; lastKnownFileType = file.otf; name = BebasNeue.otf; path = ../../Resources/Fonts/BebasNeue.otf; sourceTree = SOURCE_ROOT; };
7A9A31FC1AE8FB238FAE995E /* SpikeDisplayCanvas.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = SpikeDisplayCanvas.cpp; path = ../../Source/Processors/Visualization/SpikeDisplayCanvas.cpp; sourceTree = SOURCE_ROOT; };
7A9A31FC1AE8FB238FAE995E /* SpikeDisplayCanvas.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = SpikeDisplayCanvas.cpp; path = ../../Source/Processors/Visualization/SpikeDisplayCanvas.cpp; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
7B825983F25D8984E02F6FFB /* Parameter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = Parameter.h; path = ../../Source/Processors/Parameter.h; sourceTree = SOURCE_ROOT; };
7BD1C1A7C30ED736F4816C31 /* SourceNode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SourceNode.h; path = ../../Source/Processors/SourceNode.h; sourceTree = SOURCE_ROOT; };
7BD204C890F9A2F301B15128 /* NetworkThread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = NetworkThread.h; path = ../../Source/Processors/DataThreads/NetworkThread.h; sourceTree = SOURCE_ROOT; };
......
......@@ -37,7 +37,7 @@ SignalGeneratorEditor::SignalGeneratorEditor (GenericProcessor* parentNode)
int buttonWidth = 31;
int buttonHeight = 19;
for (int i = 0; i < 5; i++)
for (int i = 0; i < 6; i++)
{
WaveformSelector* ws = new WaveformSelector(i);
ws->setBounds(15 + (buttonWidth)*i, 30, buttonWidth, buttonHeight);
......@@ -52,7 +52,7 @@ SignalGeneratorEditor::SignalGeneratorEditor (GenericProcessor* parentNode)
amplitudeSlider->addListener(this);
amplitudeSlider->setSliderStyle(Slider::Rotary);
amplitudeSlider->setTextBoxStyle(Slider::TextBoxBelow, false, 40, 20);
amplitudeSlider->setValue(5);
amplitudeSlider->setValue(2.5);
addAndMakeVisible(amplitudeSlider);
frequencySlider = new Slider ("Frequency Slider");
......@@ -252,6 +252,16 @@ WaveformSelector::WaveformSelector(int type) : Button("Waveform")
neutralOver = ImageCache::getFromMemory (BinaryData::RadioButtons05_png,
BinaryData::RadioButtons05_pngSize);
}
else if (type == 5) {
selected = ImageCache::getFromMemory (BinaryData::RadioButtons_selected05_png,
BinaryData::RadioButtons_selected05_pngSize);
selectedOver= ImageCache::getFromMemory (BinaryData::RadioButtons_selected_over05_png,
BinaryData::RadioButtons_selected_over05_pngSize);
neutral = ImageCache::getFromMemory (BinaryData::RadioButtons_neutral05_png,
BinaryData::RadioButtons_neutral05_pngSize);
neutralOver = ImageCache::getFromMemory (BinaryData::RadioButtons05_png,
BinaryData::RadioButtons05_pngSize);
}
}
......
......@@ -54,7 +54,7 @@ SpikeDetectorEditor::SpikeDetectorEditor (GenericProcessor* parentNode)
electrodeTypes->setJustificationType (Justification::centredLeft);
electrodeTypes->addListener(this);
electrodeTypes->setBounds(65,40,110,20);
electrodeTypes->setSelectedId(3);
electrodeTypes->setSelectedId(2);
addAndMakeVisible(electrodeTypes);
electrodeList = new ComboBox("Electrode List");
......
......@@ -153,7 +153,8 @@ bool SignalGenerator::disable() {
return true;
}
void SignalGenerator::process(AudioSampleBuffer &buffer,
void SignalGenerator::process(AudioSampleBuffer &buffer,
MidiBuffer &midiMessages,
int& nSamps)
{
......@@ -184,6 +185,9 @@ void SignalGenerator::process(AudioSampleBuffer &buffer,
case NOISE:
sample = amplitude[j] * (float(rand()) / float(RAND_MAX)-0.5f);
break;
case SPIKE:
sample = generateSpikeSample(amplitude[j], currentPhase[j], phase[j]);
break;
default:
sample = 0;
}
......@@ -199,8 +203,6 @@ void SignalGenerator::process(AudioSampleBuffer &buffer,
}
// for (int chan = 0; chan < buffer.getNumChannels(); chan++)
// {
......@@ -266,3 +268,36 @@ void SignalGenerator::process(AudioSampleBuffer &buffer,
// }
}
float SignalGenerator::generateSpikeSample(double amp, double phase, double noise){
const int N_SAMP = 80;
double waveform[80] =
{ 1.0000, 1.0002, 1.0003, 1.0006, 1.0009, 1.0016, 1.0026, 1.0041, 1.0065, 1.0101, 1.0152, 1.0225, 1.0324, 1.0455, 1.0623, 1.0831, 1.1079,
1.1363, 1.1675, 1.2001, 1.2324, 1.2623, 1.2876, 1.3061, 1.3161, 1.3163, 1.3062, 1.2863, 1.2575, 1.2216, 1.1808, 1.1375, 1.0941, 1.0527,
1.0151, 0.9827, 0.9562, 0.9360, 0.9220, 0.9137, 0.9105, 0.9117, 0.9162, 0.9231, 0.9317, 0.9410, 0.9505, 0.9595, 0.9678, 0.9750, 0.9811,
0.9861, 0.9900, 0.9931, 0.9953, 0.9969, 0.9980, 0.9987, 0.9992, 0.9995, 0.9997, 0.9999, 0.9999, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000};
// We don't want to shift the waveform but scale it, and we don't want to scale
// the baseline, just the peak of the waveform
double scale[80] =
{ 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0001, 1.0004, 1.0009, 1.0020, 1.0044, 1.0091, 1.0175, 1.0317, 1.0540, 1.0863, 1.1295, 1.1827, 1.2420, 1.3011, 1.3521, 1.3867, 1.3990, 1.3867, 1.3521, 1.3011, 1.2420, 1.1827, 1.1295, 1.0863, 1.0540, 1.0317, 1.0175, 1.0091, 1.0044, 1.0020, 1.0009, 1.0004, 1.0001, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000};
int shift = -4500;//1000 + 32768;
int sampIdx = 0;
int gain = 3000;
double r = ((rand() % 201) - 100) / 1000.0; // Generate random number between -.1 and .1
noise = r * noise / (double_Pi * 2); // Shrink the range of r based upon the value of noise
sampIdx = (int) (phase / (2 * double_Pi) * (N_SAMP-1)); // bind between 0 and N_SAMP-1, too tired to figure out the proper math
//sampIdx = sampIdx + 8;
float sample = shift + gain * ( ( waveform[sampIdx] + noise ) * pow( scale[sampIdx], amp / 250.0 ) ) ;
return sample;
}
......@@ -69,14 +69,16 @@ private:
double defaultFrequency;
double defaultAmplitude;
float generateSpikeSample(double amp, double phase, double noise);
float sampleRateRatio;
//void updateWaveform(int chan);
enum wvfrm
{
TRIANGLE, SINE, SQUARE, SAW, NOISE
TRIANGLE, SINE, SQUARE, SAW, NOISE, SPIKE
};
Array<int> waveformType;
......
......@@ -28,7 +28,7 @@ SpikeDisplayCanvas::SpikeDisplayCanvas(SpikeDisplayNode* n) : processor(n),
totalScrollPix(0)
{
nCols = 2;
nCols = 1;
update();
......@@ -301,7 +301,7 @@ void SpikeDisplayCanvas::processSpikeEvents()
for (int i = 0; i < newSpike.nChannels * newSpike.nSamples; i++)
{
simSpike.data[i] = newSpike.data[i] + 5000;// * 3 - 10000;
simSpike.data[i] = newSpike.data[i%80] + 5000;// * 3 - 10000;
}
simSpike.nSamples = 40;
......
......@@ -29,7 +29,7 @@
// Simple method for serializing a SpikeObject into a string of bytes
int packSpike(SpikeObject *s, uint8_t* buffer, int bufferSize){
int reqBytes = 1 + 4 + 2 + 2 + 2 + 2 * s->nChannels * s->nSamples + 2 * s->nChannels * 2;
//int reqBytes = 1 + 4 + 2 + 2 + 2 + 2 * s->nChannels * s->nSamples + 2 * s->nChannels * 2;
int idx = 0;
......@@ -101,12 +101,13 @@ bool unpackSpike(SpikeObject *s, uint8_t* buffer, int bufferSize){
idx += s->nChannels * 2;
memcpy( &(s->threshold), buffer+idx, s->nChannels *2);
//idx += s->nChannels * 2;
idx += s->nChannels * 2;
// if (idx >= bufferSize)
// std::cout<<"Buffer Overrun! More data extracted than was given!"<<std::endl;
return true;
//if (idx >= bufferSize)
// std::cout<<"Buffer Overrun! More data extracted than was given!"<<std::endl;
}
......
......@@ -150,7 +150,7 @@ void SpikePlot::updateAxesPositions(){
}
for (int i=0; i<nWaveAx; i++)
wAxes[i].setPosition(minX + (i % nWaveCols) * axesWidth, minY + (i/nWaveCols) * axesHeight, axesWidth, axesHeight);
wAxes[i].setPosition(minX + (i % nWaveCols) * axesWidth/nWaveCols, minY + (i/nWaveCols) * axesHeight, axesWidth/nWaveCols, axesHeight);
for (int i=0; i<nProjAx; i++)
pAxes[i].setPosition(minX + (1 + i%nProjCols) * axesWidth, minY + (i/nProjCols) * axesHeight, axesWidth, axesHeight);
......@@ -180,8 +180,8 @@ void SpikePlot::setPosition(int x, int y, double w, double h){
void SpikePlot::initLimits(){
for (int i=0; i<nChannels; i++)
{
limits[i][0] = 3045;//-1*pow(2,11);
limits[i][1] = 9503;//pow(2,14)*1.6;
limits[i][0] = 2209;//-1*pow(2,11);
limits[i][1] = 11059;//pow(2,14)*1.6;
}
}
......
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