summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Glover <j@johnglover.net>2012-07-06 14:51:07 +0100
committerJohn Glover <j@johnglover.net>2012-07-06 14:51:07 +0100
commit0af5fcc2bfa03f81a13815d070d93bea95b8745c (patch)
tree5608e5000676a687806a171b51d7435561b282f5 /src
parentc0a6f9d7dfeddbb49c1b9388ffdcc989b06fdfe9 (diff)
downloadsimpl-0af5fcc2bfa03f81a13815d070d93bea95b8745c.tar.gz
simpl-0af5fcc2bfa03f81a13815d070d93bea95b8745c.tar.bz2
simpl-0af5fcc2bfa03f81a13815d070d93bea95b8745c.zip
[base] Enable Frame object to allocate memory for their audio arrays if requested.
Diffstat (limited to 'src')
-rw-r--r--src/simpl/base.cpp64
-rw-r--r--src/simpl/base.h5
2 files changed, 63 insertions, 6 deletions
diff --git a/src/simpl/base.cpp b/src/simpl/base.cpp
index 3b35251..e3da251 100644
--- a/src/simpl/base.cpp
+++ b/src/simpl/base.cpp
@@ -81,17 +81,27 @@ Peak* Partial::peak(int peak_number) {
// ---------------------------------------------------------------------------
Frame::Frame() {
_size = 512;
+ _alloc_memory = false;
init();
}
-Frame::Frame(int frame_size) {
+Frame::Frame(int frame_size, bool alloc_memory) {
_size = frame_size;
+ _alloc_memory = alloc_memory;
init();
+
+ if(_alloc_memory) {
+ create_arrays();
+ }
}
Frame::~Frame() {
_peaks.clear();
_partials.clear();
+
+ if(_alloc_memory) {
+ destroy_arrays();
+ }
}
void Frame::init() {
@@ -107,6 +117,25 @@ void Frame::init() {
_synth_residual = NULL;
}
+void Frame::create_arrays() {
+ _audio = new sample[_size];
+ _synth = new sample[_size];
+ _residual = new sample[_size];
+ _synth_residual = new sample[_size];
+
+ memset(_audio, 0.0, sizeof(sample) * _size);
+ memset(_synth, 0.0, sizeof(sample) * _size);
+ memset(_residual, 0.0, sizeof(sample) * _size);
+ memset(_synth_residual, 0.0, sizeof(sample) * _size);
+}
+
+void Frame::destroy_arrays() {
+ delete [] _audio;
+ delete [] _synth;
+ delete [] _residual;
+ delete [] _synth_residual;
+}
+
// Frame - peaks
// -------------
@@ -199,10 +228,20 @@ int Frame::size() {
void Frame::size(int new_size) {
_size = new_size;
+
+ if(_alloc_memory) {
+ destroy_arrays();
+ create_arrays();
+ }
}
void Frame::audio(sample* new_audio) {
- _audio = new_audio;
+ if(_alloc_memory) {
+ memcpy(_audio, new_audio, sizeof(sample) * _size);
+ }
+ else {
+ _audio = new_audio;
+ }
}
sample* Frame::audio() {
@@ -210,7 +249,12 @@ sample* Frame::audio() {
}
void Frame::synth(sample* new_synth) {
- _synth = new_synth;
+ if(_alloc_memory) {
+ memcpy(_synth, new_synth, sizeof(sample) * _size);
+ }
+ else {
+ _synth = new_synth;
+ }
}
sample* Frame::synth() {
@@ -218,7 +262,12 @@ sample* Frame::synth() {
}
void Frame::residual(sample* new_residual) {
- _residual = new_residual;
+ if(_alloc_memory) {
+ memcpy(_residual, new_residual, sizeof(sample) * _size);
+ }
+ else {
+ _residual = new_residual;
+ }
}
sample* Frame::residual() {
@@ -226,7 +275,12 @@ sample* Frame::residual() {
}
void Frame::synth_residual(sample* new_synth_residual) {
- _synth_residual = new_synth_residual;
+ if(_alloc_memory) {
+ memcpy(_synth_residual, new_synth_residual, sizeof(sample) * _size);
+ }
+ else {
+ _synth_residual = new_synth_residual;
+ }
}
sample* Frame::synth_residual() {
diff --git a/src/simpl/base.h b/src/simpl/base.h
index b82ded1..7c19f77 100644
--- a/src/simpl/base.h
+++ b/src/simpl/base.h
@@ -90,10 +90,13 @@ class Frame {
sample* _residual;
sample* _synth_residual;
void init();
+ bool _alloc_memory;
+ void create_arrays();
+ void destroy_arrays();
public:
Frame();
- Frame(int frame_size);
+ Frame(int frame_size, bool alloc_memory=false);
~Frame();
// peaks