diff options
author | John Glover <j@johnglover.net> | 2012-06-26 19:30:30 +0100 |
---|---|---|
committer | John Glover <j@johnglover.net> | 2012-06-26 19:30:30 +0100 |
commit | 3a865c69d0823b4255bb73e3c79f60092ad944fb (patch) | |
tree | 847ae0ad4b974d3f1808fd3ef3a09445088758fc | |
parent | 4bc35dc4caff7a415e8c24580533602cc80845c1 (diff) | |
download | simpl-3a865c69d0823b4255bb73e3c79f60092ad944fb.tar.gz simpl-3a865c69d0823b4255bb73e3c79f60092ad944fb.tar.bz2 simpl-3a865c69d0823b4255bb73e3c79f60092ad944fb.zip |
[base] Whitespace cleanup.
-rw-r--r-- | src/simpl/base.cpp | 206 | ||||
-rw-r--r-- | src/simpl/base.h | 224 |
2 files changed, 179 insertions, 251 deletions
diff --git a/src/simpl/base.cpp b/src/simpl/base.cpp index 17df215..9b0c28d 100644 --- a/src/simpl/base.cpp +++ b/src/simpl/base.cpp @@ -7,8 +7,7 @@ using namespace simpl; // --------------------------------------------------------------------------- // Peak // --------------------------------------------------------------------------- -Peak::Peak() -{ +Peak::Peak() { amplitude = 0.0; frequency = 0.0; phase = 0.0; @@ -19,34 +18,26 @@ Peak::Peak() frame_number = 0; } -Peak::~Peak() -{ +Peak::~Peak() { } // Returns true iff this peak is unmatched in the given direction, and has positive amplitude -bool Peak::is_free(const string direction) -{ - if(amplitude <= 0.0) - { +bool Peak::is_free(const string direction) { + if(amplitude <= 0.0) { return false; } - if(direction == "forwards") - { - if(next_peak != NULL) - { + if(direction == "forwards") { + if(next_peak != NULL) { return false; } } - else if(direction == "backwards") - { - if(previous_peak != NULL) - { + else if(direction == "backwards") { + if(previous_peak != NULL) { return false; } } - else - { + else { // Throw(InvalidArgument, "Invalid direction"); // TODO: fix this printf("ERROR: InvalidArgument\n"); @@ -59,26 +50,22 @@ bool Peak::is_free(const string direction) // --------------------------------------------------------------------------- // Frame // --------------------------------------------------------------------------- -Frame::Frame() -{ +Frame::Frame() { _size = 512; init(); } -Frame::Frame(int frame_size) -{ +Frame::Frame(int frame_size) { _size = frame_size; init(); } -Frame::~Frame() -{ +Frame::~Frame() { _peaks.clear(); _partials.clear(); } -void Frame::init() -{ +void Frame::init() { _max_peaks = 100; _max_partials = 100; _audio = NULL; @@ -90,91 +77,73 @@ void Frame::init() // Frame - peaks // ------------- -int Frame::num_peaks() -{ +int Frame::num_peaks() { return _peaks.size(); } -int Frame::max_peaks() -{ +int Frame::max_peaks() { return _max_peaks; } -void Frame::max_peaks(int new_max_peaks) -{ +void Frame::max_peaks(int new_max_peaks) { _max_peaks = new_max_peaks; // TODO: potentially losing data here, should prevent or complain - if((int)_peaks.size() > _max_peaks) - { + if((int)_peaks.size() > _max_peaks) { _peaks.resize(_max_peaks); } } -void Frame::add_peak(Peak* peak) -{ +void Frame::add_peak(Peak* peak) { _peaks.push_back(peak); } -void Frame::add_peaks(Peaks* peaks) -{ - for(Peaks::iterator i = peaks->begin(); i != peaks->end(); i++) - { +void Frame::add_peaks(Peaks* peaks) { + for(Peaks::iterator i = peaks->begin(); i != peaks->end(); i++) { add_peak(*i); } } -Peak* Frame::peak(int peak_number) -{ +Peak* Frame::peak(int peak_number) { return _peaks[peak_number]; } -void Frame::clear() -{ +void Frame::clear() { _peaks.clear(); } -Peaks::iterator Frame::peaks_begin() -{ +Peaks::iterator Frame::peaks_begin() { return _peaks.begin(); } -Peaks::iterator Frame::peaks_end() -{ +Peaks::iterator Frame::peaks_end() { return _peaks.end(); } // Frame - partials // ---------------- -int Frame::num_partials() -{ +int Frame::num_partials() { return _partials.size(); } -int Frame::max_partials() -{ +int Frame::max_partials() { return _max_partials; } -void Frame::max_partials(int new_max_partials) -{ +void Frame::max_partials(int new_max_partials) { _max_partials = new_max_partials; // potentially losing data here but the user shouldn't really do this - if((int)_partials.size() > _max_partials) - { + if((int)_partials.size() > _max_partials) { _partials.resize(_max_partials); } } -void Frame::add_partial(Partial partial) -{ - +void Frame::add_partial(Partial partial) { } -Partials::iterator Frame::partials() -{ +Partials::iterator Frame::partials() { return _partials.begin(); } @@ -182,53 +151,43 @@ Partials::iterator Frame::partials() // Frame - audio buffers // --------------------- -int Frame::size() -{ +int Frame::size() { return _size; } -void Frame::size(int new_size) -{ +void Frame::size(int new_size) { _size = new_size; } -void Frame::audio(sample* new_audio) -{ +void Frame::audio(sample* new_audio) { _audio = new_audio; } -sample* Frame::audio() -{ +sample* Frame::audio() { return _audio; } -void Frame::synth(sample* new_synth) -{ +void Frame::synth(sample* new_synth) { _synth = new_synth; } -sample* Frame::synth() -{ +sample* Frame::synth() { return _synth; } -void Frame::residual(sample* new_residual) -{ +void Frame::residual(sample* new_residual) { _residual = new_residual; } -sample* Frame::residual() -{ +sample* Frame::residual() { return _residual; } -void Frame::synth_residual(sample* new_synth_residual) -{ +void Frame::synth_residual(sample* new_synth_residual) { _synth_residual = new_synth_residual; } -sample* Frame::synth_residual() -{ +sample* Frame::synth_residual() { return _synth_residual; } @@ -237,8 +196,7 @@ sample* Frame::synth_residual() // PeakDetection // --------------------------------------------------------------------------- -PeakDetection::PeakDetection() -{ +PeakDetection::PeakDetection() { _sampling_rate = 44100; _frame_size = 2048; _static_frame_size = true; @@ -249,123 +207,100 @@ PeakDetection::PeakDetection() _min_peak_separation = 1.0; // in Hz } -PeakDetection::~PeakDetection() -{ +PeakDetection::~PeakDetection() { clear(); } -void PeakDetection::clear() -{ - for(int i = 0; i < _frames.size(); i++) - { +void PeakDetection::clear() { + for(int i = 0; i < _frames.size(); i++) { delete _frames[i]; } _frames.clear(); } -int PeakDetection::sampling_rate() -{ +int PeakDetection::sampling_rate() { return _sampling_rate; } -void PeakDetection::sampling_rate(int new_sampling_rate) -{ +void PeakDetection::sampling_rate(int new_sampling_rate) { _sampling_rate = new_sampling_rate; } -int PeakDetection::frame_size() -{ +int PeakDetection::frame_size() { return _frame_size; } -void PeakDetection::frame_size(int new_frame_size) -{ + +void PeakDetection::frame_size(int new_frame_size) { _frame_size = new_frame_size; } -bool PeakDetection::static_frame_size() -{ +bool PeakDetection::static_frame_size() { return _static_frame_size; } -void PeakDetection::static_frame_size(bool new_static_frame_size) -{ +void PeakDetection::static_frame_size(bool new_static_frame_size) { _static_frame_size = new_static_frame_size; } -int PeakDetection::next_frame_size() -{ +int PeakDetection::next_frame_size() { return _frame_size; } -int PeakDetection::hop_size() -{ +int PeakDetection::hop_size() { return _hop_size; } -void PeakDetection::hop_size(int new_hop_size) -{ +void PeakDetection::hop_size(int new_hop_size) { _hop_size = new_hop_size; } -int PeakDetection::max_peaks() -{ +int PeakDetection::max_peaks() { return _max_peaks; } -void PeakDetection::max_peaks(int new_max_peaks) -{ +void PeakDetection::max_peaks(int new_max_peaks) { _max_peaks = new_max_peaks; } -std::string PeakDetection::window_type() -{ +std::string PeakDetection::window_type() { return _window_type; } -void PeakDetection::window_type(std::string new_window_type) -{ +void PeakDetection::window_type(std::string new_window_type) { _window_type = new_window_type; } -int PeakDetection::window_size() -{ +int PeakDetection::window_size() { return _window_size; } -void PeakDetection::window_size(int new_window_size) -{ +void PeakDetection::window_size(int new_window_size) { _window_size = new_window_size; } -sample PeakDetection::min_peak_separation() -{ +sample PeakDetection::min_peak_separation() { return _min_peak_separation; } -void PeakDetection::min_peak_separation(sample new_min_peak_separation) -{ +void PeakDetection::min_peak_separation(sample new_min_peak_separation) { _min_peak_separation = new_min_peak_separation; } -int PeakDetection::num_frames() -{ +int PeakDetection::num_frames() { return _frames.size(); } -Frame* PeakDetection::frame(int frame_number) -{ +Frame* PeakDetection::frame(int frame_number) { return _frames[frame_number]; } -Frames PeakDetection::frames() -{ +Frames PeakDetection::frames() { return _frames; } // Find and return all spectral peaks in a given frame of audio -Peaks PeakDetection::find_peaks_in_frame(Frame* frame) -{ +Peaks PeakDetection::find_peaks_in_frame(Frame* frame) { Peaks peaks; return peaks; } @@ -374,16 +309,13 @@ Peaks PeakDetection::find_peaks_in_frame(Frame* frame) // If the signal contains more than 1 frame worth of audio, it will be broken // up into separate frames, each containing a std::vector of peaks. // Frames* PeakDetection::find_peaks(const samples& audio) -Frames PeakDetection::find_peaks(int audio_size, sample* audio) -{ +Frames PeakDetection::find_peaks(int audio_size, sample* audio) { clear(); unsigned int pos = 0; - while(pos < audio_size - _hop_size) - { + while(pos < audio_size - _hop_size) { // get the next frame size - if(!_static_frame_size) - { + if(!_static_frame_size) { _frame_size = next_frame_size(); } diff --git a/src/simpl/base.h b/src/simpl/base.h index 3710a92..b2d0da9 100644 --- a/src/simpl/base.h +++ b/src/simpl/base.h @@ -18,26 +18,24 @@ typedef double sample; // // A spectral Peak // --------------------------------------------------------------------------- -class Peak -{ -public: - sample amplitude; - sample frequency; - sample phase; - Peak* next_peak; - Peak* previous_peak; - int partial_id; - int partial_position; - int frame_number; - - Peak(); - ~Peak(); - - bool is_start_of_partial() - { - return previous_peak == NULL; - }; - bool is_free(const string direction = string("forwards")); +class Peak { + public: + sample amplitude; + sample frequency; + sample phase; + Peak* next_peak; + Peak* previous_peak; + int partial_id; + int partial_position; + int frame_number; + + Peak(); + ~Peak(); + + bool is_start_of_partial() { + return previous_peak == NULL; + }; + bool is_free(const string direction = string("forwards")); }; typedef std::vector<Peak*> Peaks; @@ -62,54 +60,53 @@ typedef std::vector<Partial*> Partials; // - residual samples // - synthesised residual samples // --------------------------------------------------------------------------- -class Frame -{ -private: - int _size; - int _max_peaks; - int _max_partials; - Peaks _peaks; - Partials _partials; - sample* _audio; - sample* _synth; - sample* _residual; - sample* _synth_residual; - void init(); - -public: - Frame(); - Frame(int frame_size); - ~Frame(); - - // peaks - int num_peaks(); - int max_peaks(); - void max_peaks(int new_max_peaks); - void add_peak(Peak* peak); - void add_peaks(Peaks* peaks); - Peak* peak(int peak_number); - void clear(); - Peaks::iterator peaks_begin(); - Peaks::iterator peaks_end(); - - // partials - int num_partials(); - int max_partials(); - void max_partials(int new_max_partials); - void add_partial(Partial partial); - Partials::iterator partials(); - - // audio buffers - int size(); - void size(int new_size); - void audio(sample* new_audio); - sample* audio(); - void synth(sample* new_synth); - sample* synth(); - void residual(sample* new_residual); - sample* residual(); - void synth_residual(sample* new_synth_residual); - sample* synth_residual(); +class Frame { + private: + int _size; + int _max_peaks; + int _max_partials; + Peaks _peaks; + Partials _partials; + sample* _audio; + sample* _synth; + sample* _residual; + sample* _synth_residual; + void init(); + + public: + Frame(); + Frame(int frame_size); + ~Frame(); + + // peaks + int num_peaks(); + int max_peaks(); + void max_peaks(int new_max_peaks); + void add_peak(Peak* peak); + void add_peaks(Peaks* peaks); + Peak* peak(int peak_number); + void clear(); + Peaks::iterator peaks_begin(); + Peaks::iterator peaks_end(); + + // partials + int num_partials(); + int max_partials(); + void max_partials(int new_max_partials); + void add_partial(Partial partial); + Partials::iterator partials(); + + // audio buffers + int size(); + void size(int new_size); + void audio(sample* new_audio); + sample* audio(); + void synth(sample* new_synth); + sample* synth(); + void residual(sample* new_residual); + sample* residual(); + void synth_residual(sample* new_synth_residual); + sample* synth_residual(); }; typedef std::vector<Frame*> Frames; @@ -121,52 +118,51 @@ typedef std::vector<Frame*> Frames; // Detect spectral peaks // --------------------------------------------------------------------------- -class PeakDetection -{ -private: - int _sampling_rate; - int _frame_size; - bool _static_frame_size; - int _hop_size; - int _max_peaks; - std::string _window_type; - int _window_size; - sample _min_peak_separation; - Frames _frames; - -public: - PeakDetection(); - virtual ~PeakDetection(); - void clear(); - - int sampling_rate(); - void sampling_rate(int new_sampling_rate); - int frame_size(); - void frame_size(int new_frame_size); - bool static_frame_size(); - void static_frame_size(bool new_static_frame_size); - virtual int next_frame_size(); - int hop_size(); - void hop_size(int new_hop_size); - int max_peaks(); - void max_peaks(int new_max_peaks); - std::string window_type(); - void window_type(std::string new_window_type); - int window_size(); - void window_size(int new_window_size); - sample min_peak_separation(); - void min_peak_separation(sample new_min_peak_separation); - int num_frames(); - Frame* frame(int frame_number); - Frames frames(); - - // Find and return all spectral peaks in a given frame of audio - virtual Peaks find_peaks_in_frame(Frame* frame); - - // Find and return all spectral peaks in a given audio signal. - // If the signal contains more than 1 frame worth of audio, it will be broken - // up into separate frames, with an array of peaks returned for each frame. - virtual Frames find_peaks(int audio_size, sample* audio); +class PeakDetection { + private: + int _sampling_rate; + int _frame_size; + bool _static_frame_size; + int _hop_size; + int _max_peaks; + std::string _window_type; + int _window_size; + sample _min_peak_separation; + Frames _frames; + + public: + PeakDetection(); + virtual ~PeakDetection(); + void clear(); + + int sampling_rate(); + void sampling_rate(int new_sampling_rate); + int frame_size(); + void frame_size(int new_frame_size); + bool static_frame_size(); + void static_frame_size(bool new_static_frame_size); + virtual int next_frame_size(); + int hop_size(); + void hop_size(int new_hop_size); + int max_peaks(); + void max_peaks(int new_max_peaks); + std::string window_type(); + void window_type(std::string new_window_type); + int window_size(); + void window_size(int new_window_size); + sample min_peak_separation(); + void min_peak_separation(sample new_min_peak_separation); + int num_frames(); + Frame* frame(int frame_number); + Frames frames(); + + // Find and return all spectral peaks in a given frame of audio + virtual Peaks find_peaks_in_frame(Frame* frame); + + // Find and return all spectral peaks in a given audio signal. + // If the signal contains more than 1 frame worth of audio, it will be broken + // up into separate frames, with an array of peaks returned for each frame. + virtual Frames find_peaks(int audio_size, sample* audio); }; } // end of namespace Simpl |