spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit b8e472fcfb687ac6a4f0fdf5bcba777f37b41f6b
parent a380a77bdd942e9c94d22e95244855695c876210
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Thu,  6 Sep 2012 10:21:47 -0700

Close the file after processing, fixes #26

Diffstat:
Mlib/spek-pipeline.c | 3+++
Msrc/spek-events.cc | 11++++++++---
Msrc/spek-spectrogram.cc | 23+++++++++++++++--------
Msrc/spek-spectrogram.hh | 3++-
4 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/lib/spek-pipeline.c b/lib/spek-pipeline.c @@ -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; } diff --git a/src/spek-events.cc b/src/spek-events.cc @@ -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() diff --git a/src/spek-spectrogram.cc b/src/spek-spectrogram.cc @@ -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; } } diff --git a/src/spek-spectrogram.hh b/src/spek-spectrogram.hh @@ -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;