mirror of
https://github.com/alexkay/spek.git
synced 2025-05-31 23:59:19 +03:00
Close the file after processing, fixes #26
This commit is contained in:
parent
a380a77bdd
commit
b8e472fcfb
@ -227,6 +227,9 @@ static void * reader_func(void *pp)
|
||||
// Force the worker to quit.
|
||||
reader_sync(p, -1);
|
||||
pthread_join(p->worker_thread, NULL);
|
||||
|
||||
// Notify the client.
|
||||
p->cb(-1, NULL, p->cb_data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -32,9 +32,14 @@ SpekHaveSampleEvent::SpekHaveSampleEvent(const SpekHaveSampleEvent& other)
|
||||
SetEventType(SPEK_HAVE_SAMPLE);
|
||||
this->bands = other.bands;
|
||||
this->sample = other.sample;
|
||||
this->values = (float *)malloc(this->bands * sizeof(float));
|
||||
memcpy(this->values, other.values, this->bands * sizeof(float));
|
||||
this->free_values = true;
|
||||
if (other.values) {
|
||||
this->values = (float *)malloc(this->bands * sizeof(float));
|
||||
memcpy(this->values, other.values, this->bands * sizeof(float));
|
||||
this->free_values = true;
|
||||
} else {
|
||||
this->values = NULL;
|
||||
this->free_values = false;
|
||||
}
|
||||
}
|
||||
|
||||
SpekHaveSampleEvent::~SpekHaveSampleEvent()
|
||||
|
@ -58,7 +58,8 @@ static wxString trim(wxDC& dc, const wxString& s, int length, bool trim_end);
|
||||
SpekSpectrogram::SpekSpectrogram(wxFrame *parent) :
|
||||
wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE),
|
||||
pipeline(NULL),
|
||||
properties(NULL),
|
||||
duration(0.0),
|
||||
sample_rate(0),
|
||||
palette(RULER, BANDS),
|
||||
image(1, 1),
|
||||
prev_width(-1)
|
||||
@ -99,6 +100,7 @@ void SpekSpectrogram::save(const wxString& path)
|
||||
|
||||
void SpekSpectrogram::on_idle(wxIdleEvent& evt)
|
||||
{
|
||||
// TODO: remove?
|
||||
Update();
|
||||
}
|
||||
|
||||
@ -126,6 +128,11 @@ void SpekSpectrogram::on_have_sample(SpekHaveSampleEvent& event)
|
||||
int sample = event.get_sample();
|
||||
const float *values = event.get_values();
|
||||
|
||||
if (sample == -1) {
|
||||
this->stop();
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: check image size, quit if wrong.
|
||||
for (int y = 0; y < bands; y++) {
|
||||
double level = log10(1.0 - THRESHOLD + values[y]) / log10_threshold;
|
||||
@ -235,7 +242,6 @@ void SpekSpectrogram::render(wxDC& dc)
|
||||
dc.SetFont(small_font);
|
||||
|
||||
// Time ruler.
|
||||
double duration = this->properties->duration;
|
||||
int time_factors[] = {1, 2, 5, 10, 20, 30, 1*60, 2*60, 5*60, 10*60, 20*60, 30*60, 0};
|
||||
SpekRuler time_ruler(
|
||||
LPAD,
|
||||
@ -244,16 +250,16 @@ void SpekSpectrogram::render(wxDC& dc)
|
||||
// TODO: i18n
|
||||
wxT("00:00"),
|
||||
time_factors,
|
||||
(int)duration,
|
||||
(int)this->duration,
|
||||
1.5,
|
||||
(w - LPAD - RPAD) / duration,
|
||||
(w - LPAD - RPAD) / this->duration,
|
||||
0.0,
|
||||
time_formatter
|
||||
);
|
||||
time_ruler.draw(dc);
|
||||
|
||||
// Frequency ruler.
|
||||
int freq = this->properties->sample_rate / 2;
|
||||
int freq = this->sample_rate / 2;
|
||||
int freq_factors[] = {1000, 2000, 5000, 10000, 20000, 0};
|
||||
SpekRuler freq_ruler(
|
||||
LPAD,
|
||||
@ -328,8 +334,10 @@ void SpekSpectrogram::start()
|
||||
this
|
||||
);
|
||||
spek_pipeline_start(this->pipeline);
|
||||
this->properties = spek_pipeline_properties(this->pipeline);
|
||||
this->desc = spek_audio_desc(this->properties);
|
||||
const spek_audio_properties *properties = spek_pipeline_properties(this->pipeline);
|
||||
this->desc = spek_audio_desc(properties);
|
||||
this->duration = properties->duration;
|
||||
this->sample_rate = properties->sample_rate;
|
||||
} else {
|
||||
this->image.Create(1, 1);
|
||||
}
|
||||
@ -342,7 +350,6 @@ void SpekSpectrogram::stop()
|
||||
if (this->pipeline) {
|
||||
spek_pipeline_close(this->pipeline);
|
||||
this->pipeline = NULL;
|
||||
this->properties = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,9 +44,10 @@ private:
|
||||
void stop();
|
||||
|
||||
spek_pipeline *pipeline;
|
||||
const spek_audio_properties *properties;
|
||||
wxString path;
|
||||
wxString desc;
|
||||
double duration;
|
||||
int sample_rate;
|
||||
wxImage palette;
|
||||
wxImage image;
|
||||
int prev_width;
|
||||
|
Loading…
x
Reference in New Issue
Block a user