Classes to produce a computed sound wave on the analog output.

Dependents:   SoundWaveGeneratorTest SoundWaveGeneratorTest

Files at this revision

API Documentation at this revision

Comitter:
osmeest
Date:
Tue Feb 08 21:39:55 2011 +0000
Parent:
0:ed89ef772e92
Commit message:
Fix the Sine & Triangle wave computations which were very bad !

Changed in this revision

SineWave.cpp Show annotated file Show diff for this revision Revisions of this file
TriangleWave.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ed89ef772e92 -r 6864fd480178 SineWave.cpp
--- a/SineWave.cpp	Mon Jan 24 22:44:39 2011 +0000
+++ b/SineWave.cpp	Tue Feb 08 21:39:55 2011 +0000
@@ -9,9 +9,9 @@
     this->buffer.resize(cycleLength);
 
     std::size_t middle = cycleLength / 2;
-    std::size_t quarter = middle / 4;
+    std::size_t quarter = middle / 2;
     
-    float delta = 3.14 / (2.0 * float(sampleRate) / float(this->frequency));
+    float delta = 6.28 / (float(sampleRate) / float(this->frequency));
     for(std::size_t i = 0; i < quarter; ++i) {
         float dt = delta * i;
         float dv = std::sin(dt) / 2.0;
@@ -23,9 +23,11 @@
         this->buffer.write(cycleLength - i, negValue);
     }
     
+    this->buffer.write(quarter, 1.0);
     if (middle - quarter != quarter) {
-        this->buffer.write(quarter, 1.0);
+        this->buffer.write(middle - quarter, 1.0);
     }
+    this->buffer.write(cycleLength - quarter, 0.0);
     if (middle + quarter != cycleLength - quarter) {
         this->buffer.write(middle + quarter, 0.0);
     }
diff -r ed89ef772e92 -r 6864fd480178 TriangleWave.cpp
--- a/TriangleWave.cpp	Mon Jan 24 22:44:39 2011 +0000
+++ b/TriangleWave.cpp	Tue Feb 08 21:39:55 2011 +0000
@@ -8,9 +8,9 @@
     this->buffer.resize(cycleLength);
 
     std::size_t middle = cycleLength / 2;
-    std::size_t quarter = middle / 4;
+    std::size_t quarter = middle / 2;
     
-    float delta = 0.5 / (float(sampleRate) / float(this->frequency));
+    float delta = 2.0 / (float(sampleRate) / float(this->frequency));
     for(std::size_t i = 0; i < quarter; ++i) {
         float dt = delta * i;
         float posValue = 0.5 + dt;
@@ -21,9 +21,11 @@
         this->buffer.write(cycleLength - i, negValue);
     }
     
+    this->buffer.write(quarter, 1.0);
     if (middle - quarter != quarter) {
-        this->buffer.write(quarter, 1.0);
+        this->buffer.write(middle - quarter, 1.0);
     }
+    this->buffer.write(cycleLength - quarter, 0.0);
     if (middle + quarter != cycleLength - quarter) {
         this->buffer.write(middle + quarter, 0.0);
     }