diff --git a/src/audio/FreqPlayer.cpp b/src/audio/FreqPlayer.cpp new file mode 100644 index 0000000..42692f8 --- /dev/null +++ b/src/audio/FreqPlayer.cpp @@ -0,0 +1,61 @@ +/* Copyright 2016 (C) Louis-Joseph Fournier + * louisjoseph.fournier@gmail.com + * + * This file is part of SailTuner. + * + * SailTuner is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SailTuner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include + +#include "FreqPlayer.hpp" + +template typename FreqPlayer::FreqPlayer(int _rate): + rate(_rate), + freq(440), + volume(0.2), + n_frame(0), + waveform(W_SINUS) +{ +} + +template typename void FreqPlayer::Reset() +{ + n_frame = 0; +} + +template typename void FreqPlayer::SetFreq(double freq) +{ + this->freq = freq; +} + +template typename void FreqPlayer::SetVolume(double volume) +{ + this->volume = volume; +} + +int16_t FreqPlayer::max() { return INT16_MAX; } +double FreqPlayer::max() { return 1; } + +template typename double FreqPlayer::radius() +{ + return (double) (n_sample++) * freq / rate * M_PI * 2; +} + +template typename sample_t FreqPlayer::AudioFrame() +{ +// return (n_sample++) +} + +// instanciation for int16 +template class LinearFilter; diff --git a/src/audio/FreqPlayer.hpp b/src/audio/FreqPlayer.hpp new file mode 100644 index 0000000..1dc247e --- /dev/null +++ b/src/audio/FreqPlayer.hpp @@ -0,0 +1,63 @@ +/* Copyright 2016 (C) Louis-Joseph Fournier + * louisjoseph.fournier@gmail.com + * + * This file is part of SailTuner. + * + * SailTuner is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * SailTuner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#ifndef _FREQ_PLAYER_HPP +#define _FREQ_PLAYER_HPP + +/** + * FreqPlayer + * + * Play a note at given frequency + * Waveform style can be: sinus + */ +template class FreqPlayer { + public: + /// waveform style + enum WAVEFORM { W_SINUS }; + + private: + /// current frequency + double freq; + /// current volume (linear) + double volume; + /// audio rate + int rate; + /// current frame nb + int n_frame; + /// wave form + WAVEFORM waveform; + + /// return the max sample_t + sample_t max(); + /// return the current radius + double radius(); + + public: + FreqPlayer(int rate); + ~FreqPlayer() {} + + /// reset current sound + void Reset(); + /// get next audio frame + sample_t AudioFrame(); + /// set current frequency + void SetFreq(double freq); + /// set current volume + void SetVolume(double volume); +}; + +#endif