00001
00002
00003
00004
00005
00006 #include "gapeaudioplot.h"
00007 #include "gapezoomableslider.h"
00008 #include <qcheckbox.h>
00009 #include <qlcdnumber.h>
00010 #include <qsize.h>
00011 #include <qfont.h>
00012 #include <qlayout.h>
00013 #include <qcheckbox.h>
00014 #include <string.h>
00015 #include <assert.h>
00016 #include <math.h>
00017 #include <stdlib.h>
00018
00019
00020
00021
00022
00023
00024 GapeAudioPlot::GapeAudioPlot( QWidget *parent, const char* title, const char* xlabel, const char* ylabel,
00025 int nSamples, double independentScalar, int rFrequency)
00026 : GapeController(parent),
00027 plotDisplay(new QwtPlot(this))
00028 {
00029 numSamples = nSamples;
00030 plotDisplayCounter = 0;
00031 refreshFrequency = rFrequency;
00032
00033
00034 for( int i = 0; i < AUDIOPLOT_MAX_NUM_SAMPLES; ++i )
00035 {
00036 sampleIndices[i] = i * independentScalar;
00037 samples[i] = 0.0;
00038 }
00039
00040
00041 curveHandle = plotDisplay->insertCurve( "samples" );
00042 plotDisplay->setCurveRawData( curveHandle, sampleIndices,
00043 samples, numSamples );
00044
00045
00046 setBackgroundColor( AUDIOPLOT_DEFAULT_BG_COLOR );
00047 setCurveColor( AUDIOPLOT_DEFAULT_CURVE_COLOR );
00048
00049
00050 plotDisplay->setPlotBorder( 5 );
00051
00052
00053 plotDisplay->setAutoReplot( false );
00054
00055
00056
00057 plotDisplay->setAxisScale( QwtPlot::xBottom, 0, sampleIndices[numSamples-1] );
00058
00059
00060 long mY = plotDisplay->insertLineMarker( "", QwtPlot::yLeft );
00061 plotDisplay->setMarkerYPos( mY, 0.0 );
00062
00063
00064 plotDisplay->setTitle( title );
00065 plotDisplay->setTitleFont( QFont("Times", 11, QFont::Bold) );
00066
00067
00068 plotDisplay->setAxisTitle( QwtPlot::xBottom, xlabel );
00069 plotDisplay->setAxisTitleFont( QwtPlot::xBottom, QFont("Times", 10) );
00070 plotDisplay->setAxisTitle( QwtPlot::yLeft, ylabel );
00071 plotDisplay->setAxisTitleFont( QwtPlot::yLeft, QFont("Times", 10) );
00072
00073
00074 setMinimumSize( 500,200 );
00075
00076 }
00077
00078
00079 void GapeAudioPlot::receiveTick(const GapeFloat* values, int numValues) {
00080
00081 if (numValues > AUDIOPLOT_MAX_NUM_SAMPLES) {
00082 numValues = AUDIOPLOT_MAX_NUM_SAMPLES;
00083 GapeConsts::reportError("Too many samples in GapeAudioPlot receiveTick(), gapeaudioplot.cpp line 83\n");
00084 }
00085
00086 if (numValues <= 0 || values == NULL) return;
00087
00088 if (sizeof(GapeFloat) != sizeof (double)) {
00089 GapeConsts::reportError("not using doubles, audioplot can't graph, gapeaudioplot.cpp line 89\n");
00090 }
00091
00092 if(++plotDisplayCounter == refreshFrequency) {
00093 plotDisplayCounter = 0;
00094
00095 if (numValues != numSamples) {
00096 numSamples = numValues;
00097 plotDisplay->setCurveRawData( curveHandle, sampleIndices,
00098 samples, numSamples );
00099 plotDisplay->setAxisScale( QwtPlot::xBottom, 0,
00100 sampleIndices[numSamples-1] );
00101 }
00102
00103 memcpy(samples, values, numSamples * sizeof(GapeFloat));
00104
00105 requestUpdate();
00106 }
00107
00108 }
00109
00110
00111 GapeTimeDomainPlot::GapeTimeDomainPlot( QWidget *parent, const char* title, const char* hlabel, const char* vlabel,
00112 int nSamples, double independentScalar, int rFrequency)
00113 : GapeAudioPlot (parent,title,hlabel,vlabel,nSamples,independentScalar,rFrequency) {
00114
00115 autoScaleBox = new QCheckBox("Auto-scale amplitude?",this);
00116 muteBox = new QCheckBox("Freeze",this);
00117 numSamplesSlider = new GapeZoomableSlider( AUDIOPLOT_MIN_NUM_SAMPLES, AUDIOPLOT_MAX_NUM_SAMPLES, 1,
00118 AUDIOPLOT_DEFAULT_NUM_SAMPLES, QSlider::Horizontal, this );
00119 numSamplesLCD = new QLCDNumber(4,this);
00120 numSamplesLCD->display(AUDIOPLOT_DEFAULT_NUM_SAMPLES);
00121
00122 layout = new QGridLayout(this,2,4);
00123 layout->addMultiCellWidget(plotDisplay,0,0,0,3);
00124 layout->addWidget(autoScaleBox,1,0);
00125 layout->addWidget(numSamplesSlider,1,1);
00126 layout->addWidget(numSamplesLCD,1,2);
00127 layout->addWidget(muteBox,1,3);
00128
00129 connect(numSamplesSlider, SIGNAL (valueChanged(int)), numSamplesLCD, SLOT(display(int)));
00130 connect(numSamplesSlider, SIGNAL (valueChanged(int)), this, SIGNAL(emitNumSamples(int)));
00131 connect(autoScaleBox, SIGNAL (toggled(bool)), this, SLOT(setRangeAutoscale(bool)));
00132 connect(muteBox, SIGNAL (toggled(bool)), this, SLOT(setMute(bool)));
00133 autoScaleBox->setChecked(true);
00134 muteBox->setChecked(false);
00135 }
00136
00137
00138 GapeFreqDomainPlot::GapeFreqDomainPlot( QWidget *parent, const char* title, const char* hlabel,
00139 const char* vlabel, int rFrequency)
00140 : GapeAudioPlot (parent, title, hlabel, vlabel, ((GAPE_NFFT_LENGTH + 1) / 2), GapeConsts::sampleRate / 2.0 / ((GAPE_NFFT_LENGTH + 1) / 2.0), rFrequency) {
00141
00142
00143
00144
00145
00146
00147 autoScaleBox = new QCheckBox("Auto-scale amplitude?",this);
00148 logSpecBox = new QCheckBox("Show log magnitiude of spectrum?",this);
00149 muteBox = new QCheckBox("Freeze",this);
00150
00151 layout = new QGridLayout(this,2,3);
00152 layout->addMultiCellWidget(plotDisplay,0,0,0,2);
00153 layout->addWidget(autoScaleBox,1,0);
00154 layout->addWidget(logSpecBox,1,1);
00155 layout->addWidget(muteBox,1,2);
00156
00157
00158
00159
00160
00161
00162 connect(autoScaleBox, SIGNAL (toggled(bool)), this, SLOT(setRangeAutoscale(bool)));
00163 connect(logSpecBox, SIGNAL (toggled(bool)), this, SLOT(takeLogOfSpectrum(bool)));
00164 connect(muteBox, SIGNAL (toggled(bool)), this, SLOT(setMute(bool)));
00165 autoScaleBox->setChecked(true);
00166 logSpecBox->setChecked(false);
00167 muteBox->setChecked(false);
00168 }