#include <Waveform.h>
Public Types | |
Public Member Functions | |
void | SetAmplitude (float p) |
void | SetFrequency (float p) |
void | SetOffset (float p) |
void | SetPhase (float p) |
Waveform (WaveType t) | |
~Waveform () | |
Protected Member Functions | |
float | CalcWave (float t) |
void | Process (jack_nframes_t count) |
Private Attributes | |
float | m_amplitude |
float | m_freq |
float | m_last_time |
float | m_offset |
float | m_phase |
float | m_time |
WaveType | m_wavetype |
Definition at line 14 of file Waveform.h.
enum Waveform::WaveType |
Waveform::Waveform | ( | Waveform::WaveType | t | ) |
Definition at line 7 of file Waveform.cpp.
00007 : 00008 ISoundSource(), 00009 m_wavetype(t), 00010 m_phase(0), 00011 m_freq(1), 00012 m_offset(0), 00013 m_amplitude(1) 00014 { 00015 }
Waveform::~Waveform | ( | ) |
float Waveform::CalcWave | ( | float | t | ) | [protected] |
Definition at line 40 of file Waveform.cpp.
References m_wavetype, W_RSAW, W_SAW, W_SIN, W_SQU, and W_TRI.
Referenced by Process().
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 }
void Waveform::Process | ( | jack_nframes_t | count | ) | [protected, virtual] |
Reimplemented from ISoundSource.
Definition at line 21 of file Waveform.cpp.
References CalcWave(), ISoundElement::GetPipe(), SoundFrame::GetSamples(), JackClient::GetSingleton(), m_amplitude, m_freq, m_offset, m_phase, and m_time.
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 }
void Waveform::SetAmplitude | ( | float | p | ) | [inline] |
Definition at line 35 of file Waveform.h.
References m_amplitude.
Referenced by BOOST_PYTHON_MODULE().
00035 { m_amplitude = p; }
void Waveform::SetFrequency | ( | float | p | ) | [inline] |
Definition at line 34 of file Waveform.h.
References m_freq.
Referenced by BOOST_PYTHON_MODULE().
00034 { m_freq = p; }
void Waveform::SetOffset | ( | float | p | ) | [inline] |
Definition at line 36 of file Waveform.h.
References m_offset.
Referenced by BOOST_PYTHON_MODULE().
00036 { m_offset = p; }
void Waveform::SetPhase | ( | float | p | ) | [inline] |
Definition at line 37 of file Waveform.h.
References m_phase.
Referenced by BOOST_PYTHON_MODULE().
00037 { m_phase = p; }
float Waveform::m_amplitude [private] |
float Waveform::m_freq [private] |
float Waveform::m_last_time [private] |
Definition at line 49 of file Waveform.h.
float Waveform::m_offset [private] |
float Waveform::m_phase [private] |
float Waveform::m_time [private] |
WaveType Waveform::m_wavetype [private] |