Skip to content

Commit 4719232

Browse files
committed
Fixes according to github discussion
1 parent e40e027 commit 4719232

3 files changed

Lines changed: 28 additions & 18 deletions

File tree

LibSource/ComplexFloatArray.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,19 +313,15 @@ void ComplexFloatArray::destroy(ComplexFloatArray array){
313313
delete[] array.data;
314314
}
315315

316-
void ComplexFloatArray::copyFrom(AudioBuffer& buffer) {
317-
FloatArray left = buffer.getSamples(0);
318-
FloatArray right = buffer.getSamples(1);
316+
void ComplexFloatArray::copyFrom(FloatArray real, FloatArray imag) {
319317
for (size_t i = 0; i < getSize(); i++) {
320-
data[i] = ComplexFloat(left[i], right[i]);
318+
data[i] = ComplexFloat(real[i], imag[i]);
321319
}
322320
}
323321

324-
void ComplexFloatArray::copyTo(AudioBuffer& buffer) {
325-
FloatArray left = buffer.getSamples(0);
326-
FloatArray right = buffer.getSamples(1);
322+
void ComplexFloatArray::copyTo(FloatArray real, FloatArray imag) {
327323
for (size_t i = 0; i < getSize(); i++) {
328-
left[i] = data[i].re;
329-
right[i] = data[i].im;
324+
real[i] = data[i].re;
325+
imag[i] = data[i].im;
330326
}
331327
}

LibSource/ComplexFloatArray.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#define __ComplexFloatArray_h__
33

44
#include "FloatArray.h"
5-
#include "AudioBuffer.h"
65
#include "basicmaths.h"
76

87
/**
@@ -133,7 +132,6 @@ struct ComplexFloat {
133132

134133
ComplexFloat& operator+=(float other) {
135134
re += other;
136-
im += other;
137135
return *this;
138136
}
139137

@@ -157,7 +155,6 @@ struct ComplexFloat {
157155

158156
ComplexFloat& operator-=(float other) {
159157
re -= other;
160-
im -= other;
161158
return *this;
162159
}
163160

@@ -501,8 +498,23 @@ class ComplexFloatArray : public SimpleArray<ComplexFloat> {
501498
*/
502499
void setMagnitude(FloatArray magnitude, int offset, size_t count, ComplexFloatArray destination);
503500

504-
void copyFrom(AudioBuffer& buffer);
505-
void copyTo(AudioBuffer& buffer);
501+
using SimpleArray<ComplexFloat>::copyFrom;
502+
using SimpleArray<ComplexFloat>::copyTo;
503+
/**
504+
* Merge two channels of audio containing real and imaginary axis data into this array
505+
*
506+
* @param[in] real Real axis data
507+
* @param[in] imag Imaginary axis data
508+
*/
509+
void copyFrom(FloatArray real, FloatArray imag);
510+
511+
/**
512+
* Split complex data into two channels of audio containing real and imaginary axis data
513+
*
514+
* @param[in] real Real axis data
515+
* @param[in] imag Imaginary axis data
516+
*/
517+
void copyTo(FloatArray real, FloatArray imag);
506518
};
507519

508520
#endif // __ComplexFloatArray_h__

TestPatches/QuadratureSineOscillatorTestPatch.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class QuadratureSineOscillatorTestPatch : public TestPatch {
4343
osc2->setFrequency(480);
4444
AudioBuffer* s1 = AudioBuffer::create(2, 1000);
4545
AudioBuffer* s2 = AudioBuffer::create(2, 1000);
46-
osc1->generate(*s1);
46+
ComplexFloatArray cmp = ComplexFloatArray::create(1000);
47+
osc1->generate(cmp);
48+
cmp.copyTo(s1->getSamples(0), s2->getSamples(1));
4749
for(size_t i=0; i<1000; ++i) {
4850
ComplexFloat sample = osc2->generate();
4951
s2->getSamples(0)[i] = sample.re;
@@ -53,15 +55,15 @@ class QuadratureSineOscillatorTestPatch : public TestPatch {
5355
CHECK_CLOSE(s1->getSamples(0)[i], s2->getSamples(0)[i], 0.00002);
5456
CHECK_CLOSE(s1->getSamples(1)[i], s2->getSamples(1)[i], 0.00002);
5557
}
56-
osc1->generate(*s1);
58+
osc1->generate(cmp);
5759
for(size_t i=0; i<1000; ++i) {
5860
ComplexFloat sample = osc2->generate();
5961
s2->getSamples(0)[i] = sample.re;
6062
s2->getSamples(1)[i] = sample.im;
6163
}
6264
for(size_t i=0; i<1000; ++i) {
63-
CHECK_CLOSE(s1->getSamples(0)[i], s2->getSamples(0)[i], 0.00002);
64-
CHECK_CLOSE(s1->getSamples(1)[i], s2->getSamples(1)[i], 0.00002);
65+
CHECK_CLOSE(cmp[i].re, s2->getSamples(0)[i], 0.00002);
66+
CHECK_CLOSE(cmp[i].im, s2->getSamples(1)[i], 0.00002);
6567
}
6668
AudioBuffer::destroy(s1);
6769
AudioBuffer::destroy(s2);

0 commit comments

Comments
 (0)