Skip to content

Commit 7c0f246

Browse files
* Add pitch wheel control
- Pitch +/- 2 semitones per General MIDI * Increase voice count from 12 to 16
1 parent 478815a commit 7c0f246

9 files changed

+76
-6
lines changed

Control.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "StdAfx.h"
2+
/*
3+
MINI VIRTUAL ANALOG SYNTHESIZER
4+
Copyright 2014 Kenneth D. Miller III
5+
6+
Controllers
7+
*/
8+
9+
namespace Control
10+
{
11+
// pitch wheel value
12+
int pitch_wheel;
13+
float pitch_scale;
14+
15+
void SetPitchWheel(int value)
16+
{
17+
pitch_wheel = value;
18+
pitch_scale = powf(2.0f, float(pitch_wheel * 2) / float(0x2000 * 12));
19+
}
20+
21+
// reset all controllers
22+
void ResetAll()
23+
{
24+
pitch_wheel = 0;
25+
pitch_scale = 1;
26+
}
27+
}

Control.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#pragma once
2+
/*
3+
MINI VIRTUAL ANALOG SYNTHESIZER
4+
Copyright 2014 Kenneth D. Miller III
5+
6+
Controllers
7+
*/
8+
9+
namespace Control
10+
{
11+
// pitch wheel value
12+
extern int pitch_wheel;
13+
extern float pitch_scale;
14+
15+
// set pitch wheel value
16+
extern void SetPitchWheel(int value);
17+
18+
// reset all controllers
19+
extern void ResetAll();
20+
}

DisplayOscillatorFrequency.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ Oscillator Frequency Display
99
#include "DisplayOscillatorFrequency.h"
1010
#include "Menu.h"
1111
#include "Voice.h"
12+
#include "Control.h"
1213
#include "Console.h"
1314
#include "OscillatorNote.h"
1415

1516
// show oscillator frequency
1617
void UpdateOscillatorFrequencyDisplay(HANDLE hOut, int const v, int const o)
1718
{
18-
// key frequency (taking octave shift into account)
19-
float const key_freq = note_frequency[voice_note[v]];
19+
// key frequency (taking pitch wheel control into account)
20+
float const key_freq = Control::pitch_scale * note_frequency[voice_note[v]];
2021

2122
// get attributes to use
2223
Menu::MenuMode menu = Menu::MenuMode(Menu::MENU_OSC1 + o);

DisplayOscillatorWaveform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Oscillator Waveform Display
1515
#include "Envelope.h"
1616
#include "Wave.h"
1717
#include "Voice.h"
18+
#include "Control.h"
1819

1920
#define WAVEFORM_WIDTH 80
2021
#define WAVEFORM_HEIGHT 20
@@ -89,7 +90,7 @@ void UpdateOscillatorWaveformDisplay(HANDLE hOut, BASS_INFO const &info, int con
8990
float const step_base = cycle / float(WAVEFORM_WIDTH);
9091

9192
// key frequency
92-
float const key_freq = note_frequency[voice_note[v]];
93+
float const key_freq = Control::pitch_scale * note_frequency[voice_note[v]];
9394

9495
// update filter envelope generator
9596
float const flt_env_amplitude = flt_env_state[v].amplitude;

Midi.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
/*
2+
MINI VIRTUAL ANALOG SYNTHESIZER
3+
Copyright 2014 Kenneth D. Miller III
4+
5+
MIDI Support
6+
*/
17
#include "StdAfx.h"
28

39
#include "Debug.h"
410
#include "Midi.h"
511
#include "Voice.h"
12+
#include "Control.h"
613

714
// midi messages
815
// http://www.midi.org/techspecs/midimessages.php
@@ -78,6 +85,7 @@ namespace Midi
7885
break;
7986
case MIDI_RESET_ALL_CONTROLLERS:
8087
DebugPrint("Reset All Controllers\n");
88+
Control::ResetAll();
8189
break;
8290
case MIDI_LOCAL_CONTROL:
8391
DebugPrint("Local Control %s\n", data2 ? "On" : "Off");
@@ -109,6 +117,7 @@ namespace Midi
109117
break;
110118
case MIDI_PITCH_WHEEL_CHANGE:
111119
DebugPrint("Pitch Wheel Change: value=%d\n", (data2 << 7) + data1 - 0x2000);
120+
Control::SetPitchWheel((data2 << 7) + data1 - 0x2000);
112121
break;
113122
case MIDI_SYSTEM:
114123
DebugPrint("System %02x %02x %02x\n", data1, data2);

Midi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
#pragma once
2+
/*
3+
MINI VIRTUAL ANALOG SYNTHESIZER
4+
Copyright 2014 Kenneth D. Miller III
5+
6+
MIDI Support
7+
*/
28

39
namespace Midi
410
{

Voice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Voice Assignment
1212
extern float note_frequency[NOTES];
1313

1414
// number of voices
15-
#define VOICES 12
15+
#define VOICES 16
1616

1717
// current note assignemnts
1818
// (via keyboard or midi input)

synth.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Copyright 2014 Kenneth D. Miller III
1212
#include "Keys.h"
1313
#include "Voice.h"
1414
#include "Midi.h"
15+
#include "Control.h"
1516

1617
#include "PolyBLEP.h"
1718
#include "Oscillator.h"
@@ -104,8 +105,8 @@ DWORD CALLBACK WriteStream(HSTREAM handle, short *buffer, DWORD length, void *us
104105
// get the voice index
105106
int v = index[i];
106107

107-
// key frequency (taking octave shift into account)
108-
float const key_freq = note_frequency[voice_note[v]];
108+
// key frequency (taking pitch wheel control into account)
109+
float const key_freq = Control::pitch_scale * note_frequency[voice_note[v]];
109110

110111
// update filter envelope generator
111112
float const flt_env_amplitude = flt_env_state[v].Update(flt_env_config, step);
@@ -295,6 +296,9 @@ void main(int argc, char **argv)
295296
// enable the first oscillator
296297
osc_config[0].enable = true;
297298

299+
// reset all controllers
300+
Control::ResetAll();
301+
298302
// show all menus
299303
for (int i = 0; i < Menu::MENU_COUNT - (info.dsver < 8); ++i)
300304
Menu::Handler(hOut, 0, 0, Menu::MenuMode(i));

synth.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
</ItemDefinitionGroup>
9494
<ItemGroup>
9595
<ClCompile Include="Console.cpp" />
96+
<ClCompile Include="Control.cpp" />
9697
<ClCompile Include="Debug.cpp" />
9798
<ClCompile Include="DisplayKeyVolumeEnvelope.cpp" />
9899
<ClCompile Include="DisplayLowFrequencyOscillator.cpp" />
@@ -131,6 +132,7 @@
131132
</ItemGroup>
132133
<ItemGroup>
133134
<ClInclude Include="Console.h" />
135+
<ClInclude Include="Control.h" />
134136
<ClInclude Include="Debug.h" />
135137
<ClInclude Include="DisplayKeyVolumeEnvelope.h" />
136138
<ClInclude Include="DisplayLowFrequencyOscillator.h" />

0 commit comments

Comments
 (0)