summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-09-11 13:21:49 +0200
committerJohn Glover <j@johnglover.net>2012-09-11 13:21:49 +0200
commita2cc58647900f3888838a9016f5d9d37c8160569 (patch)
tree0948df9baf6e83877da27be15092ac95a313df85 /src
parent1afaa87774ef8f3b8d29f085f1771c9593f887ec (diff)
downloadsimpl-a2cc58647900f3888838a9016f5d9d37c8160569.tar.gz
simpl-a2cc58647900f3888838a9016f5d9d37c8160569.tar.bz2
simpl-a2cc58647900f3888838a9016f5d9d37c8160569.zip
[base, peak_detection] Allow blocks of samples
smaller than the frame size to be copied to Frame objects. Remove unused code from Peak objects relating to old Partials objects. Manage memory for sample arrays in Frame objects if operating in non-real-time.
Diffstat (limited to 'src')
-rw-r--r--src/simpl/base.cpp92
-rw-r--r--src/simpl/base.h16
-rw-r--r--src/simpl/peak_detection.cpp11
3 files changed, 78 insertions, 41 deletions
diff --git a/src/simpl/base.cpp b/src/simpl/base.cpp
index 1751dd5..01e18b2 100644
--- a/src/simpl/base.cpp
+++ b/src/simpl/base.cpp
@@ -12,39 +12,11 @@ Peak::Peak() {
frequency = 0.0;
phase = 0.0;
bandwidth = 0.0;
- next_peak = NULL;
- previous_peak = NULL;
- partial_id = 0;
- partial_position = 0;
- frame_number = 0;
}
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) {
- return false;
- }
-
- if(direction == "forwards") {
- if(next_peak != NULL) {
- return false;
- }
- }
- else if(direction == "backwards") {
- if(previous_peak != NULL) {
- return false;
- }
- }
- else {
- return false;
- }
-
- return true;
-}
-
// ---------------------------------------------------------------------------
// Partial
@@ -275,6 +247,22 @@ void Frame::audio(sample* new_audio) {
}
}
+void Frame::audio(sample* new_audio, int size) {
+ // this should only be called if the Frame is managing the memory
+ // for the sample arrays
+ if(!_alloc_memory) {
+ throw Exception(std::string("Memory not managed by Frame."));
+ }
+
+ // copy size should also be less than or equal to the current frame size
+ if(size > _size) {
+ throw Exception(std::string("Specified copy size is too large, "
+ "it must be less than the Frame size."));
+ }
+
+ memcpy(_audio, new_audio, sizeof(sample) * size);
+}
+
sample* Frame::audio() {
return _audio;
}
@@ -288,6 +276,22 @@ void Frame::synth(sample* new_synth) {
}
}
+void Frame::synth(sample* new_synth, int size) {
+ // this should only be called if the Frame is managing the memory
+ // for the sample arrays
+ if(!_alloc_memory) {
+ throw Exception(std::string("Memory not managed by Frame."));
+ }
+
+ // copy size should also be less than or equal to the current frame synth size
+ if(size > _synth_size) {
+ throw Exception(std::string("Specified copy size is too large, "
+ "it must be less than the Frame synth size."));
+ }
+
+ memcpy(_synth, new_synth, sizeof(sample) * size);
+}
+
sample* Frame::synth() {
return _synth;
}
@@ -301,6 +305,22 @@ void Frame::residual(sample* new_residual) {
}
}
+void Frame::residual(sample* new_residual, int size) {
+ // this should only be called if the Frame is managing the memory
+ // for the sample arrays
+ if(!_alloc_memory) {
+ throw Exception(std::string("Memory not managed by Frame."));
+ }
+
+ // copy size should also be less than or equal to the current frame size
+ if(size > _size) {
+ throw Exception(std::string("Specified copy size is too large, "
+ "it must be less than the Frame size."));
+ }
+
+ memcpy(_residual, new_residual, sizeof(sample) * size);
+}
+
sample* Frame::residual() {
return _residual;
}
@@ -314,6 +334,22 @@ void Frame::synth_residual(sample* new_synth_residual) {
}
}
+void Frame::synth_residual(sample* new_synth_residual, int size) {
+ // this should only be called if the Frame is managing the memory
+ // for the sample arrays
+ if(!_alloc_memory) {
+ throw Exception(std::string("Memory not managed by Frame."));
+ }
+
+ // copy size should also be less than or equal to the current frame synth size
+ if(size > _synth_size) {
+ throw Exception(std::string("Specified copy size is too large, "
+ "it must be less than the Frame synth size."));
+ }
+
+ memcpy(_synth_residual, new_synth_residual, sizeof(sample) * size);
+}
+
sample* Frame::synth_residual() {
return _synth_residual;
}
diff --git a/src/simpl/base.h b/src/simpl/base.h
index 8d7138c..9e04ef7 100644
--- a/src/simpl/base.h
+++ b/src/simpl/base.h
@@ -4,7 +4,7 @@
#include <vector>
#include <string>
-using namespace std;
+#include "exceptions.h"
namespace simpl
{
@@ -23,19 +23,9 @@ class Peak {
sample frequency;
sample phase;
sample bandwidth;
- 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;
@@ -128,12 +118,16 @@ class Frame {
int synth_size();
void synth_size(int new_size);
void audio(sample* new_audio);
+ void audio(sample* new_audio, int size);
sample* audio();
void synth(sample* new_synth);
+ void synth(sample* new_synth, int size);
sample* synth();
void residual(sample* new_residual);
+ void residual(sample* new_residual, int size);
sample* residual();
void synth_residual(sample* new_synth_residual);
+ void synth_residual(sample* new_synth_residual, int size);
sample* synth_residual();
};
diff --git a/src/simpl/peak_detection.cpp b/src/simpl/peak_detection.cpp
index ff66278..0f28da3 100644
--- a/src/simpl/peak_detection.cpp
+++ b/src/simpl/peak_detection.cpp
@@ -143,8 +143,15 @@ Frames PeakDetection::find_peaks(int audio_size, sample* audio) {
}
// get the next frame
- Frame* f = new Frame(_frame_size);
- f->audio(&(audio[pos]));
+ Frame* f = new Frame(_frame_size, true);
+
+ if((int)pos <= (audio_size - _frame_size)) {
+ f->audio(&(audio[pos]), _frame_size);
+ }
+ else {
+ f->audio(&(audio[pos]), audio_size - pos);
+ }
+
f->max_peaks(_max_peaks);
// find peaks