-
Notifications
You must be signed in to change notification settings - Fork 2
/
SinOsc.cpp
51 lines (42 loc) · 928 Bytes
/
SinOsc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// SinOsc.cpp
// DSPLibrary
//
// Created by Mayank on 9/11/12.
// Copyright (c) 2012 Mayank Sanganeria. All rights reserved.
//
#include "SinOsc.h"
SinOsc::SinOsc()
{
reset();
}
void SinOsc::setSampleRate(double withSampleRate)
{
sampleRate = withSampleRate;
}
void SinOsc::reset()
{
phase = 0.0;
}
void SinOsc::setCenterFrequency(float newFrequency)
{
centerFrequency = newFrequency;
}
void SinOsc::setFrequency(float input)
{ // set the instantaneous frequency based on an input
frequency = centerFrequency * powf(2.0, input * range / 12.0);
}
void SinOsc::setAmplitude(float withAmplitude)
{
amplitude = withAmplitude;
}
void SinOsc::setRange(double withRange)
{
range = withRange;
}
void SinOsc::process (float& output)
{
double phaseIncrement = frequency / sampleRate;
phase = fmod((phase + phaseIncrement), (1.0));
output = sinf(phase * 2.0 * M_PI) * amplitude;
}