mirror of
https://github.com/alexkay/spek.git
synced 2025-04-21 19:07:37 +03:00
Fix a bug in the spectral density clipping
This commit is contained in:
parent
ce6496cbb4
commit
c6dc7afcea
@ -22,12 +22,11 @@
|
||||
|
||||
#include "spek-fft.h"
|
||||
|
||||
struct spek_fft_plan * spek_fft_plan_new(int n, int threshold)
|
||||
struct spek_fft_plan * spek_fft_plan_new(int n)
|
||||
{
|
||||
struct spek_fft_plan *p = malloc(sizeof(struct spek_fft_plan));
|
||||
p->input = av_mallocz(sizeof(float) * n);
|
||||
p->output = av_mallocz(sizeof(float) * (n / 2 + 1));
|
||||
p->threshold = threshold;
|
||||
int bits = 0;
|
||||
while (n) {
|
||||
n >>= 1;
|
||||
@ -51,8 +50,7 @@ void spek_fft_execute(struct spek_fft_plan *p)
|
||||
p->input[i * 2] * p->input[i * 2] +
|
||||
p->input[i * 2 + 1] * p->input[i * 2 + 1];
|
||||
val /= n * n;
|
||||
val = 10.0 * log10f (val);
|
||||
p->output[i] = val < p->threshold ? p->threshold : val;
|
||||
p->output[i] = 10.0 * log10f (val);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,6 @@ struct spek_fft_plan
|
||||
// Internal data.
|
||||
struct RDFTContext *cx;
|
||||
int n;
|
||||
int threshold;
|
||||
|
||||
// Exposed properties.
|
||||
float *input;
|
||||
@ -34,7 +33,7 @@ struct spek_fft_plan
|
||||
};
|
||||
|
||||
// Allocate buffers and create a new FFT plan.
|
||||
struct spek_fft_plan * spek_fft_plan_new(int n, int threshold);
|
||||
struct spek_fft_plan * spek_fft_plan_new(int n);
|
||||
|
||||
// Execute the FFT on plan->input.
|
||||
void spek_fft_execute(struct spek_fft_plan *p);
|
||||
|
@ -45,7 +45,6 @@ struct spek_pipeline
|
||||
const struct spek_audio_properties *properties;
|
||||
int bands;
|
||||
int samples;
|
||||
int threshold;
|
||||
spek_pipeline_cb cb;
|
||||
void *cb_data;
|
||||
|
||||
@ -80,14 +79,13 @@ static void reader_sync(struct spek_pipeline *p, int pos);
|
||||
static float average_input(const struct spek_pipeline *p, void *buffer);
|
||||
|
||||
struct spek_pipeline * spek_pipeline_open(
|
||||
const char *path, int bands, int samples, int threshold, spek_pipeline_cb cb, void *cb_data)
|
||||
const char *path, int bands, int samples, spek_pipeline_cb cb, void *cb_data)
|
||||
{
|
||||
struct spek_pipeline *p = malloc(sizeof(struct spek_pipeline));
|
||||
p->cx = spek_audio_open(path);
|
||||
p->properties = spek_audio_get_properties(p->cx);
|
||||
p->bands = bands;
|
||||
p->samples = samples;
|
||||
p->threshold = threshold;
|
||||
p->cb = cb;
|
||||
p->cb_data = cb_data;
|
||||
|
||||
@ -109,7 +107,7 @@ struct spek_pipeline * spek_pipeline_open(
|
||||
for (int i = 0; i < p->nfft; ++i) {
|
||||
p->coss[i] = cosf(cf * i);
|
||||
}
|
||||
p->fft = spek_fft_plan_new(p->nfft, threshold);
|
||||
p->fft = spek_fft_plan_new(p->nfft);
|
||||
p->input_size = p->nfft * (NFFT * 2 + 1);
|
||||
p->input = malloc(p->input_size * sizeof(float));
|
||||
p->output = malloc(bands * sizeof(float));
|
||||
|
@ -25,7 +25,7 @@ struct spek_audio_properties;
|
||||
typedef void (*spek_pipeline_cb)(int sample, float *values, void *cb_data);
|
||||
|
||||
struct spek_pipeline * spek_pipeline_open(
|
||||
const char *path, int bands, int samples, int threshold, spek_pipeline_cb cb, void *cb_data);
|
||||
const char *path, int bands, int samples, spek_pipeline_cb cb, void *cb_data);
|
||||
|
||||
const struct spek_audio_properties * spek_pipeline_properties(struct spek_pipeline *pipeline);
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <wx/dcbuffer.h>
|
||||
|
||||
extern "C" {
|
||||
@ -143,7 +145,6 @@ void SpekSpectrogram::on_size(wxSizeEvent& evt)
|
||||
|
||||
void SpekSpectrogram::on_have_sample(SpekHaveSampleEvent& event)
|
||||
{
|
||||
static double log10_threshold = log10(-THRESHOLD);
|
||||
int bands = event.get_bands();
|
||||
int sample = event.get_sample();
|
||||
const float *values = event.get_values();
|
||||
@ -154,9 +155,10 @@ void SpekSpectrogram::on_have_sample(SpekHaveSampleEvent& event)
|
||||
}
|
||||
|
||||
// TODO: check image size, quit if wrong.
|
||||
double range = log(1.0 - THRESHOLD);
|
||||
for (int y = 0; y < bands; y++) {
|
||||
double level = log10(1.0 - THRESHOLD + values[y]) / log10_threshold;
|
||||
if (level > 1.0) level = 1.0;
|
||||
double value = MAX(THRESHOLD, values[y]);
|
||||
double level = log(1.0 - THRESHOLD + value) / range;
|
||||
uint32_t color = spek_palette_spectrum(level);
|
||||
this->image.SetRGB(
|
||||
sample,
|
||||
@ -353,7 +355,6 @@ void SpekSpectrogram::start()
|
||||
this->path.utf8_str(),
|
||||
BANDS,
|
||||
samples,
|
||||
THRESHOLD,
|
||||
pipeline_cb,
|
||||
this
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user