-
Notifications
You must be signed in to change notification settings - Fork 306
Added a time resolution slider #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -382,20 +382,27 @@ void PlotView::setFFTAndZoom(int size, int zoom) | |
|
|
||
| void PlotView::setPowerMin(int power) | ||
| { | ||
| powerMin = power; | ||
| // HVI_REVIEW: Not needed? powerMin = power; | ||
| if (spectrogramPlot != nullptr) | ||
| spectrogramPlot->setPowerMin(power); | ||
| updateView(); | ||
| } | ||
|
|
||
| void PlotView::setPowerMax(int power) | ||
| { | ||
| powerMax = power; | ||
| // HVI_REVIEW: Not needed? powerMax = power; | ||
| if (spectrogramPlot != nullptr) | ||
| spectrogramPlot->setPowerMax(power); | ||
| updateView(); | ||
| } | ||
|
|
||
| void PlotView::setTimeResolution(int resolution) | ||
| { | ||
| if (spectrogramPlot != nullptr) | ||
| spectrogramPlot->setTimeResolution(resolution); | ||
| // updateView(true); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be commented out, it should just be deleted |
||
| } | ||
|
|
||
| void PlotView::paintEvent(QPaintEvent *event) | ||
| { | ||
| if (mainSampleSource == nullptr) return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,10 @@ SpectrogramControls::SpectrogramControls(const QString & title, QWidget * parent | |
| powerMinSlider->setRange(-140, 10); | ||
| layout->addRow(new QLabel(tr("Power min:")), powerMinSlider); | ||
|
|
||
| timeResolutionSlider = new QSlider(Qt::Horizontal, widget); | ||
| timeResolutionSlider->setRange(0, 99); | ||
| layout->addRow(new QLabel(tr("Time resolution:")), timeResolutionSlider); | ||
|
|
||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit, but I'd prefer this to be just under the zoom slider - it makes sense to group FFT size/zoom/resolution together. |
||
| scalesCheckBox = new QCheckBox(widget); | ||
| scalesCheckBox->setCheckState(Qt::Checked); | ||
| layout->addRow(new QLabel(tr("Scales:")), scalesCheckBox); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,12 +33,13 @@ | |
|
|
||
| SpectrogramPlot::SpectrogramPlot(std::shared_ptr<SampleSource<std::complex<float>>> src) : Plot(src), inputSource(src), fftSize(512), tuner(fftSize, this) | ||
| { | ||
| setFFTSize(fftSize); | ||
| zoomLevel = 1; | ||
| powerMax = 0.0f; | ||
| powerMin = -50.0f; | ||
| timeResolution = 0.0; | ||
| sampleRate = 0; | ||
| frequencyScaleEnabled = false; | ||
| setFFTSize(fftSize); | ||
|
|
||
| for (int i = 0; i < 256; i++) { | ||
| float p = (float)i / 256; | ||
|
|
@@ -271,15 +272,46 @@ std::shared_ptr<AbstractSampleSource> SpectrogramPlot::output() | |
| return tunerTransform; | ||
| } | ||
|
|
||
| static float bessel(float x, int kmax = 5) | ||
| { | ||
| int k; | ||
| float kfactorial = 1.0; | ||
| float half_x_to_k_pow = 1.0; | ||
| float term; | ||
| float result = 1.0; | ||
| for(k = 1; k < kmax; k++) { | ||
| half_x_to_k_pow *= x/2.0; | ||
| kfactorial *= k; | ||
| term = half_x_to_k_pow / kfactorial; | ||
| result += term * term; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| void SpectrogramPlot::setFFTSize(int size) | ||
| { | ||
| float sizeScale = float(size) / float(fftSize); | ||
| float beta = 20; | ||
| float denominator = bessel(beta); | ||
|
|
||
| fftSize = size; | ||
| fft.reset(new FFT(fftSize)); | ||
|
|
||
| window.reset(new float[fftSize]); | ||
| for (int i = 0; i < fftSize; i++) { | ||
| window[i] = 0.5f * (1.0f - cos(Tau * i / (fftSize - 1))); | ||
| int zeroCount = (fftSize * timeResolution) / 100; | ||
| if ((zeroCount >= 0) && (zeroCount <= fftSize)) { | ||
| int windowSize = fftSize - zeroCount; | ||
| for (int i = 0; i < windowSize; i++) { | ||
| float term = float(2*i - windowSize + 1) / windowSize; | ||
| window[i] = bessel(beta * sqrt(1.0 - term * term)) / denominator; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently I notice that the spectrogram shifts to the right as you increase the time resolution slider. To stop that happening, I think that the non-zero values should be centered in the window, rather than left-aligned. |
||
| } | ||
| for (int i = windowSize; i < fftSize; i++) { | ||
| window[i] = 0; | ||
| } | ||
| } else { | ||
| for(int i = 0; i < fftSize; i++) { | ||
| window[i] = 0; | ||
| } | ||
| } | ||
|
|
||
| setHeight(fftSize); | ||
|
|
@@ -301,6 +333,14 @@ void SpectrogramPlot::setPowerMin(int power) | |
| { | ||
| powerMin = power; | ||
| pixmapCache.clear(); | ||
| // HVI_REVIEW: Why no tunerMoved like in setPowerMax()? | ||
| } | ||
|
|
||
| void SpectrogramPlot::setTimeResolution(int resolution) | ||
| { | ||
| timeResolution = resolution; | ||
| setFFTSize(fftSize); | ||
| invalidateEvent(); | ||
| } | ||
|
|
||
| void SpectrogramPlot::setZoomLevel(int zoom) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does look like these are unused and should be removed. I'd prefer that as a separate commit that just deletes the lines, rather than commenting them out