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

Dependents:   SoundWaveGeneratorTest SoundWaveGeneratorTest

SoundWaveGenerator.cpp

Committer:
osmeest
Date:
2011-01-24
Revision:
0:ed89ef772e92

File content as of revision 0:ed89ef772e92:

#include "snd_wave_generator/SoundWaveGenerator.h"

namespace snd_wave_generator {

void SoundWaveGenerator::play(Wave *wave)
{
    wave->prepare(this->sampleRate);

    this->wave = wave;
    
    this->pos = 0;
    this->ticker.attach(this, &SoundWaveGenerator::tickerHandler, 1.0 / this->sampleRate);
}

void SoundWaveGenerator::stop()
{
    this->ticker.detach();
    this->output.write(0.0);
    this->wave = NULL;
}
    
void SoundWaveGenerator::tickerHandler()
{
    float v = this->wave ? this->wave->read(this->pos++) : 0.0;
    this->output.write(v);
}

} // snd_wave_generator