Caught an unhandled exception from libsndfile
This commit is contained in:
parent
ccda509068
commit
1e6a0e635b
|
|
@ -183,9 +183,6 @@ class MainFrame : public wxFrame
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
wxLongLong m_LoopA, m_LoopB;
|
wxLongLong m_LoopA, m_LoopB;
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
|
||||||
wxSystemAppearance m_Theme = wxSystemSettings::GetAppearance();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
bool bAutoplay = false;
|
bool bAutoplay = false;
|
||||||
|
|
@ -262,10 +259,6 @@ class MainFrame : public wxFrame
|
||||||
// Frame resize event handler
|
// Frame resize event handler
|
||||||
void OnResizeFrame(wxSizeEvent& event);
|
void OnResizeFrame(wxSizeEvent& event);
|
||||||
|
|
||||||
// Splitter window sash pos event handler
|
|
||||||
void OnTopSplitterSashPosChanged(wxSplitterEvent& event);
|
|
||||||
void OnBottomSplitterSashPosChanged(wxSplitterEvent& event);
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
// Timer update event handler
|
// Timer update event handler
|
||||||
void UpdateElapsedTime(wxTimerEvent& event);
|
void UpdateElapsedTime(wxTimerEvent& event);
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
#include "Utility/Log.hpp"
|
#include "Utility/Log.hpp"
|
||||||
#include "Utility/Paths.hpp"
|
#include "Utility/Paths.hpp"
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <wx/brush.h>
|
#include <wx/brush.h>
|
||||||
|
|
@ -35,6 +36,7 @@
|
||||||
#include <wx/gdicmn.h>
|
#include <wx/gdicmn.h>
|
||||||
#include <wx/pen.h>
|
#include <wx/pen.h>
|
||||||
|
|
||||||
|
#include <sndfile.h>
|
||||||
#include <sndfile.hh>
|
#include <sndfile.hh>
|
||||||
|
|
||||||
WaveformViewer::WaveformViewer(wxWindow* window, wxDataViewListCtrl& library,
|
WaveformViewer::WaveformViewer(wxWindow* window, wxDataViewListCtrl& library,
|
||||||
|
|
@ -178,77 +180,85 @@ void WaveformViewer::UpdateWaveformBitmap()
|
||||||
|
|
||||||
std::vector<float> waveform;
|
std::vector<float> waveform;
|
||||||
|
|
||||||
// TODO, FIXME: Don't reload file on every window resize
|
try
|
||||||
snd_file.read(&sample.at(0), frames * channels);
|
|
||||||
|
|
||||||
float display_width = this->GetSize().GetWidth();
|
|
||||||
float display_height = this->GetSize().GetHeight();
|
|
||||||
|
|
||||||
SH_LOG_INFO("Calculating Waveform bars RMS..");
|
|
||||||
|
|
||||||
float chunk_size = (float)(frames) / (float)display_width;
|
|
||||||
int number_of_chunks = static_cast<int>(static_cast<float>(frames) / chunk_size);
|
|
||||||
|
|
||||||
// Start with low non-zero value
|
|
||||||
float normalize = 0.00001;
|
|
||||||
|
|
||||||
for (int i = 0; i < number_of_chunks; i++)
|
|
||||||
{
|
{
|
||||||
double sum = 0, mono = 0;
|
// TODO, FIXME: Don't reload file on every window resize
|
||||||
|
snd_file.read(&sample.at(0), frames * channels);
|
||||||
|
|
||||||
int start_point = static_cast<int>(i * chunk_size * channels);
|
float display_width = this->GetSize().GetWidth();
|
||||||
|
float display_height = this->GetSize().GetHeight();
|
||||||
|
|
||||||
// Iterate on the chunk, get the square of sum of monos
|
SH_LOG_INFO("Calculating Waveform bars RMS..");
|
||||||
for (int j = 0; j < chunk_size; j++)
|
|
||||||
|
float chunk_size = (float)(frames) / (float)display_width;
|
||||||
|
int number_of_chunks = static_cast<int>(static_cast<float>(frames) / chunk_size);
|
||||||
|
|
||||||
|
// Start with low non-zero value
|
||||||
|
float normalize = 0.00001;
|
||||||
|
|
||||||
|
for (int i = 0; i < number_of_chunks; i++)
|
||||||
{
|
{
|
||||||
if (channels == 2)
|
double sum = 0, mono = 0;
|
||||||
mono = 0.5f * (sample[start_point + (2 * j)] + sample[start_point + (2 * j) + 1]);
|
|
||||||
else
|
|
||||||
mono = sample[start_point + j];
|
|
||||||
|
|
||||||
sum += mono * mono; // Square
|
int start_point = static_cast<int>(i * chunk_size * channels);
|
||||||
|
|
||||||
|
// Iterate on the chunk, get the square of sum of monos
|
||||||
|
for (int j = 0; j < chunk_size; j++)
|
||||||
|
{
|
||||||
|
if (channels == 2)
|
||||||
|
mono = 0.5f * (sample[start_point + (2 * j)] + sample[start_point + (2 * j) + 1]);
|
||||||
|
else
|
||||||
|
mono = sample[start_point + j];
|
||||||
|
|
||||||
|
sum += mono * mono; // Square
|
||||||
|
}
|
||||||
|
|
||||||
|
sum /= chunk_size; // Mean
|
||||||
|
sum = pow(sum, 0.5); // Root
|
||||||
|
|
||||||
|
// We might bleed a bit on the end and get some near infs, dunno
|
||||||
|
// what is causing astronomically big numbers from sample[]
|
||||||
|
if ((sum < 200.0) && (sum > normalize))
|
||||||
|
normalize = sum;
|
||||||
|
|
||||||
|
waveform.push_back(sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
sum /= chunk_size; // Mean
|
// Actually normalize
|
||||||
sum = pow(sum, 0.5); // Root
|
for (int i = 0; i < waveform.size(); i++)
|
||||||
|
waveform[i] /= normalize;
|
||||||
|
|
||||||
// We might bleed a bit on the end and get some near infs, dunno
|
// Draw code
|
||||||
// what is causing astronomically big numbers from sample[]
|
wxMemoryDC mdc(m_WaveformBitmap);
|
||||||
if ((sum < 200.0) && (sum > normalize))
|
|
||||||
normalize = sum;
|
|
||||||
|
|
||||||
waveform.push_back(sum);
|
mdc.SetBackground(wxBrush(wxColour(0, 0, 0, 150), wxBRUSHSTYLE_SOLID));
|
||||||
|
mdc.Clear();
|
||||||
|
|
||||||
|
m_WaveformColour = serializer.DeserializeWaveformColour();
|
||||||
|
|
||||||
|
mdc.SetPen(wxPen(wxColour(m_WaveformColour), 2, wxPENSTYLE_SOLID));
|
||||||
|
|
||||||
|
SH_LOG_DEBUG("Drawing bitmap..");
|
||||||
|
|
||||||
|
for (int i = 0; i < waveform.size() - 1; i++)
|
||||||
|
{
|
||||||
|
float half_display_height = static_cast<float>(display_height) / 2.0f;
|
||||||
|
|
||||||
|
// X is percentage of i relative to waveform.size() multiplied by
|
||||||
|
// the width, Y is the half height times the value up or down
|
||||||
|
float X = display_width * ((float)i / waveform.size());
|
||||||
|
float Y = waveform[i] * half_display_height;
|
||||||
|
|
||||||
|
mdc.DrawLine(X, half_display_height + Y, X, half_display_height - Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
SH_LOG_DEBUG("Done drawing bitmap..");
|
||||||
}
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
// Actually normalize
|
|
||||||
for (int i = 0; i < waveform.size(); i++)
|
|
||||||
waveform[i] /= normalize;
|
|
||||||
|
|
||||||
// Draw code
|
|
||||||
wxMemoryDC mdc(m_WaveformBitmap);
|
|
||||||
|
|
||||||
mdc.SetBackground(wxBrush(wxColour(0, 0, 0, 150), wxBRUSHSTYLE_SOLID));
|
|
||||||
mdc.Clear();
|
|
||||||
|
|
||||||
m_WaveformColour = serializer.DeserializeWaveformColour();
|
|
||||||
|
|
||||||
mdc.SetPen(wxPen(wxColour(m_WaveformColour), 2, wxPENSTYLE_SOLID));
|
|
||||||
|
|
||||||
SH_LOG_DEBUG("Drawing bitmap..");
|
|
||||||
|
|
||||||
for (int i = 0; i < waveform.size() - 1; i++)
|
|
||||||
{
|
{
|
||||||
float half_display_height = static_cast<float>(display_height) / 2.0f;
|
SH_LOG_ERROR("Error! SNDFILE {}", e.what());
|
||||||
|
SH_LOG_ERROR("Error! SNDFILE {}", sf_strerror(snd_file.rawHandle()));
|
||||||
// X is percentage of i relative to waveform.size() multiplied by
|
|
||||||
// the width, Y is the half height times the value up or down
|
|
||||||
float X = display_width * ((float)i / waveform.size());
|
|
||||||
float Y = waveform[i] * half_display_height;
|
|
||||||
|
|
||||||
mdc.DrawLine(X, half_display_height + Y, X, half_display_height - Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SH_LOG_DEBUG("Done drawing bitmap..");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaveformViewer::OnControlKeyDown(wxKeyEvent &event)
|
void WaveformViewer::OnControlKeyDown(wxKeyEvent &event)
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,11 @@
|
||||||
#include "Utility/Tags.hpp"
|
#include "Utility/Tags.hpp"
|
||||||
#include "SampleHiveConfig.hpp"
|
#include "SampleHiveConfig.hpp"
|
||||||
|
|
||||||
|
// #include <iomanip>
|
||||||
|
|
||||||
#include <taglib/tag.h>
|
#include <taglib/tag.h>
|
||||||
#include <taglib/fileref.h>
|
#include <taglib/fileref.h>
|
||||||
|
// #include <taglib/tpropertymap.h>
|
||||||
|
|
||||||
#ifndef USE_SYSTEM_INCLUDE_PATH
|
#ifndef USE_SYSTEM_INCLUDE_PATH
|
||||||
#include <taglib/toolkit/tstring.h>
|
#include <taglib/toolkit/tstring.h>
|
||||||
|
|
@ -44,14 +47,15 @@ Tags::~Tags()
|
||||||
AudioInfo Tags::GetAudioInfo()
|
AudioInfo Tags::GetAudioInfo()
|
||||||
{
|
{
|
||||||
wxString artist, album, genre, title, comment;
|
wxString artist, album, genre, title, comment;
|
||||||
int channels = 0, length = 0, sample_rate = 0, bitrate = 0;
|
int channels = 0, length_ms = 0, length_s = 0, sample_rate = 0, bitrate = 0;
|
||||||
|
|
||||||
TagLib::FileRef f (static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
|
TagLib::FileRef f(static_cast<const char*>(m_Filepath.c_str()), true, TagLib::AudioProperties::ReadStyle::Average);
|
||||||
|
|
||||||
if (!f.isNull() && f.tag() && f.audioProperties())
|
if (!f.isNull() && f.tag() && f.audioProperties())
|
||||||
{
|
{
|
||||||
TagLib::Tag* tag = f.tag();
|
TagLib::Tag* tag = f.tag();
|
||||||
TagLib::AudioProperties* properties = f.audioProperties();
|
TagLib::AudioProperties* properties = f.audioProperties();
|
||||||
|
// TagLib::PropertyMap property_map = f.file()->properties();
|
||||||
|
|
||||||
TagLib::String Title = tag->title();
|
TagLib::String Title = tag->title();
|
||||||
TagLib::String Artist = tag->artist();
|
TagLib::String Artist = tag->artist();
|
||||||
|
|
@ -64,8 +68,8 @@ AudioInfo Tags::GetAudioInfo()
|
||||||
|
|
||||||
bitrate = properties->bitrate();
|
bitrate = properties->bitrate();
|
||||||
channels = properties->channels();
|
channels = properties->channels();
|
||||||
length = properties->lengthInMilliseconds();
|
length_ms = properties->lengthInMilliseconds();
|
||||||
int length_sec = properties->lengthInSeconds();
|
length_s = properties->lengthInSeconds();
|
||||||
sample_rate = properties->sampleRate();
|
sample_rate = properties->sampleRate();
|
||||||
|
|
||||||
title = wxString::FromUTF8(Title.toCString(true));
|
title = wxString::FromUTF8(Title.toCString(true));
|
||||||
|
|
@ -75,13 +79,33 @@ AudioInfo Tags::GetAudioInfo()
|
||||||
comment = wxString::FromUTF8(Comment.toCString(true));
|
comment = wxString::FromUTF8(Comment.toCString(true));
|
||||||
|
|
||||||
bValid = true;
|
bValid = true;
|
||||||
|
|
||||||
|
// unsigned int longest = 0;
|
||||||
|
|
||||||
|
// for(TagLib::PropertyMap::ConstIterator i = property_map.begin(); i != property_map.end(); ++i)
|
||||||
|
// {
|
||||||
|
// if (i->first.size() > longest)
|
||||||
|
// {
|
||||||
|
// longest = i->first.size();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// std::cout << "-- TAG (properties) --" << std::endl;
|
||||||
|
|
||||||
|
// for(TagLib::PropertyMap::ConstIterator i = property_map.begin(); i != property_map.end(); ++i)
|
||||||
|
// {
|
||||||
|
// for(TagLib::StringList::ConstIterator j = i->second.begin(); j != i->second.end(); ++j)
|
||||||
|
// {
|
||||||
|
// std::cout << std::left << std::setw(longest) << i->first << " - " << '"' << *j << '"' << std::endl;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
bValid = false;
|
bValid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { title, artist, album, genre, comment, channels, length, sample_rate, bitrate };
|
return { title, artist, album, genre, comment, channels, length_ms, sample_rate, bitrate };
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tags::SetTitle(std::string title)
|
void Tags::SetTitle(std::string title)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue