Waveform.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * Waveform.cpp (JackFX) 
00003  ******************************************************************************/
00004 
00005 #include "Waveform.h"
00006 
00007 Waveform::Waveform(Waveform::WaveType t) : 
00008     ISoundSource(), 
00009     m_wavetype(t),
00010     m_phase(0),
00011     m_freq(1),
00012     m_offset(0),
00013     m_amplitude(1)
00014 {
00015 }
00016 
00017 Waveform::~Waveform()
00018 {
00019 }
00020 
00021 void Waveform::Process(jack_nframes_t count)
00022 {
00023     ISoundSource::Process(count);
00024 
00025     float samplelength = 4.0f / jack_get_sample_rate(JackClient::GetSingleton()->GetClient());
00026     for (unsigned int x = 0; x < count; ++x) {
00027         GetPipe().GetSamples()[x] = (
00028                 CalcWave(
00029                         fmod(m_time + m_phase, 1.0f)
00030                     )
00031                 + m_offset)
00032             * m_amplitude;
00033         m_time += samplelength * m_freq;
00034         while (m_time > 1) {
00035             m_time -= 1;
00036         }
00037     }
00038 }
00039 
00040 float Waveform::CalcWave(float t)
00041 {
00042     //cout << "Waveform for time position " << t << endl;
00043     float ret;
00044     switch (m_wavetype) {
00045         case W_SIN:
00046             ret = sin(t * 6.283);
00047             break;
00048         case W_TRI:
00049             ret = abs(0.5 - t);
00050             break;
00051         case W_SAW:
00052             ret = t;
00053             break;
00054         case W_RSAW:
00055             ret = 1 - t;
00056             break;
00057         case W_SQU:
00058             ret = t > 0.5;
00059             break;
00060         default:
00061             ret = 0;
00062     }
00063     return ret;
00064 }
00065 
00066 

Get JackFX at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated for JackFX by  doxygen