kwave  18.07.70
Kwave::Osc Class Reference

#include <Osc.h>

Inheritance diagram for Kwave::Osc:
Inheritance graph
Collaboration diagram for Kwave::Osc:
Collaboration graph

Public Slots

void setFrequency (const QVariant &f)
 
void setPhase (const QVariant &p)
 
void setAmplitude (const QVariant &a)
 

Signals

void output (Kwave::SampleArray data)
 
- Signals inherited from Kwave::StreamObject
void attributeChanged (const QVariant value)
 

Public Member Functions

 Osc ()
 
virtual ~Osc () Q_DECL_OVERRIDE
 
virtual void goOn () Q_DECL_OVERRIDE
 
- Public Member Functions inherited from Kwave::SampleSource
 SampleSource (QObject *parent=Q_NULLPTR)
 
virtual ~SampleSource ()
 
virtual bool done () const
 
- Public Member Functions inherited from Kwave::StreamObject
 StreamObject (QObject *parent=Q_NULLPTR)
 
virtual ~StreamObject ()
 
virtual unsigned int tracks () const
 
virtual Kwave::StreamObjectoperator[] (unsigned int track)
 
virtual unsigned int tracksOfPort (const char *port) const
 
virtual Kwave::StreamObjectport (const char *port, unsigned int track)
 
virtual unsigned int blockSize () const
 
void setAttribute (const char *attribute, const QVariant &value)
 

Private Attributes

Kwave::SampleArray m_buffer
 
double m_omega_t
 
double m_f
 
double m_a
 

Additional Inherited Members

- Static Public Member Functions inherited from Kwave::StreamObject
static void setInteractive (bool interactive)
 

Detailed Description

Definition at line 32 of file Osc.h.

Constructor & Destructor Documentation

◆ Osc()

Kwave::Osc::Osc ( )

Constructor

Definition at line 25 of file Osc.cpp.

27  m_buffer(blockSize()), m_omega_t(0.0), m_f(44.1), m_a(1.0)
28 {
29 }
Kwave::SampleArray m_buffer
Definition: Osc.h:73
double m_f
Definition: Osc.h:79
double m_omega_t
Definition: Osc.h:76
virtual unsigned int blockSize() const
double m_a
Definition: Osc.h:82

◆ ~Osc()

Kwave::Osc::~Osc ( )
virtual

Destructor

Definition at line 32 of file Osc.cpp.

33 {
34 }

Member Function Documentation

◆ goOn()

void Kwave::Osc::goOn ( )
virtual

does the calculation

Implements Kwave::SampleSource.

Definition at line 37 of file Osc.cpp.

References double2sample(), m_a, m_buffer, m_f, m_omega_t, output(), and Kwave::SampleArray::size().

Referenced by Kwave::PlayBackPlugin::run().

38 {
39  unsigned int samples = m_buffer.size();
40  const double two_pi = 2.0 * M_PI;
41 
42  Q_ASSERT(!qFuzzyIsNull(m_f));
43  if (qFuzzyIsNull(m_f)) return;
44 
45  double omega = two_pi / m_f;
46  for (unsigned int sample = 0; sample < samples; sample++) {
47  // calculate one sample as sin(w * t)
48  m_buffer[sample] = double2sample(m_a * sin(m_omega_t));
49 
50  // next time, t++
51  m_omega_t += omega;
52 
53  // limit the argument of sin() to [0 ... 4*Pi]
54  while (m_omega_t > two_pi)
55  m_omega_t -= two_pi;
56  }
57 
58  emit output(m_buffer);
59 }
void output(Kwave::SampleArray data)
Kwave::SampleArray m_buffer
Definition: Osc.h:73
double m_f
Definition: Osc.h:79
double m_omega_t
Definition: Osc.h:76
static sample_t double2sample(const double f)
Definition: Sample.h:81
double m_a
Definition: Osc.h:82
unsigned int size() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ output

void Kwave::Osc::output ( Kwave::SampleArray  data)
signal

emits a block with sine wave data

Referenced by goOn().

Here is the caller graph for this function:

◆ setAmplitude

void Kwave::Osc::setAmplitude ( const QVariant &  a)
slot

Sets the amplitude of the sine wave, normed to the range of [0.0 ... 1.0]. The default is 1.0.

Definition at line 74 of file Osc.cpp.

References m_a.

75 {
76  m_a = QVariant(a).toDouble();
77 }
double m_a
Definition: Osc.h:82

◆ setFrequency

void Kwave::Osc::setFrequency ( const QVariant &  f)
slot

Sets the frequency of the sine wave, normed to the sample frequency. You should pass the frequency that you want, divided through the sample frequency. If you never call this, the frequency will be undefined!

Definition at line 62 of file Osc.cpp.

References m_f.

63 {
64  m_f = QVariant(f).toDouble();
65 }
double m_f
Definition: Osc.h:79

◆ setPhase

void Kwave::Osc::setPhase ( const QVariant &  p)
slot

Sets the phase of the sine wave in RAD [0...2*Pi]. The default setting is zero.

Definition at line 68 of file Osc.cpp.

References m_omega_t.

69 {
70  m_omega_t = QVariant(p).toDouble();
71 }
double m_omega_t
Definition: Osc.h:76

Member Data Documentation

◆ m_a

double Kwave::Osc::m_a
private

amplitude [0...1]

Definition at line 82 of file Osc.h.

Referenced by goOn(), and setAmplitude().

◆ m_buffer

Kwave::SampleArray Kwave::Osc::m_buffer
private

buffer for output data

Definition at line 73 of file Osc.h.

Referenced by goOn().

◆ m_f

double Kwave::Osc::m_f
private

frequency [samples/period]

Definition at line 79 of file Osc.h.

Referenced by goOn(), and setFrequency().

◆ m_omega_t

double Kwave::Osc::m_omega_t
private

current time multiplied by 2*Pi*f

Definition at line 76 of file Osc.h.

Referenced by goOn(), and setPhase().


The documentation for this class was generated from the following files: