Skip to content

Commit 92043b4

Browse files
committed
Fixed casting issue related to const pointers to wavetables
1 parent 74b23e7 commit 92043b4

File tree

1 file changed

+52
-52
lines changed

1 file changed

+52
-52
lines changed

DUAL_LFO/DUAL_LFO.ino

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
// One potentiometer to control LFO depth
1010
// A digital input is used to re-trigger/sync the LFO
1111
//
12-
// The LFOs output to pins 11 (LFO1) and 3 (LFO2). Since the output is PWM, it's
12+
// The LFOs output to pins 11 (LFO1) and 3 (LFO2). Since the output is PWM, it's
1313
// important to add low-pass filters to these pins to smooth out the resulting waveform
1414
//
1515
// See accompanying Fritzing documents for circuit information.
1616

1717

1818
// The MIT License (MIT)
19-
//
19+
//
2020
// Copyright (c) 2013-2018 Robert W. Gallup (www.robertgallup.com)
21-
//
21+
//
2222
// Permission is hereby granted, free of charge, to any person obtaining a copy
2323
// of this software and associated documentation files (the "Software"), to deal
2424
// in the Software without restriction, including without limitation the rights
2525
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
2626
// copies of the Software, and to permit persons to whom the Software is
2727
// furnished to do so, subject to the following conditions:
28-
//
28+
//
2929
// The above copyright notice and this permission notice shall be included in
3030
// all copies or substantial portions of the Software.
31-
//
31+
//
3232
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3333
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3434
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -44,7 +44,7 @@
4444

4545
// Used in calculating frequency tuning word
4646
// Create constant to to only calculate 2^32 once
47-
const unsigned long long POW2TO32 = pow(2,32);
47+
const unsigned long long POW2TO32 = pow(2, 32);
4848

4949
// Output Pins (PWM - digital pins)
5050
// WARNING: Don't change these!
@@ -67,7 +67,7 @@ const byte LFO2_OUTPUT_PIN = 3;
6767
#include "wave/sq256.h"
6868

6969
// Wave table pointers
70-
byte *waveTables[] = {sine256, ramp256, saw256, tri256, pulse8, pulse16, pulse64, sq256, noise256};
70+
const byte *waveTables[] = {sine256, ramp256, saw256, tri256, pulse8, pulse16, pulse64, sq256, noise256};
7171
#define NUM_WAVES (sizeof(waveTables) / sizeof(byte *))
7272

7373
// LFO Initial wave table numbers
@@ -107,14 +107,14 @@ byte pinState;
107107

108108
// SYNC variables defined for optional SYNC feature, if defined in Settings.h
109109
#if defined(SYNC)
110-
byte lastSYNC1;
111-
#if !defined(SYNC_COMMON)
112-
byte lastSYNC2;
113-
#endif
110+
byte lastSYNC1;
111+
#if !defined(SYNC_COMMON)
112+
byte lastSYNC2;
113+
#endif
114114
#endif
115115

116116
// Interrupt variables are volatile
117-
volatile byte tickCounter; // Counts interrupt "ticks". Reset every 125
117+
volatile byte tickCounter; // Counts interrupt "ticks". Reset every 125
118118
volatile byte fourMilliCounter; // Counter incremented every 4ms
119119

120120
volatile unsigned long accumulatorA; // Accumulator LFO1
@@ -134,18 +134,18 @@ void setup()
134134
#if defined(SYNC)
135135
// Initialize SYNC pin(s) for optional SYNC feature in Settings.h
136136
pinMode(SYNC1_PIN, INPUT);
137-
lastSYNC1 = (HIGH==SYNC1_TRIGGER)?LOW:HIGH;
138-
#if !defined(SYNC_COMMON)
139-
pinMode(SYNC2_PIN, INPUT);
140-
lastSYNC2 = (HIGH==SYNC2_TRIGGER)?LOW:HIGH;
141-
#endif
137+
lastSYNC1 = (HIGH == SYNC1_TRIGGER) ? LOW : HIGH;
138+
#if !defined(SYNC_COMMON)
139+
pinMode(SYNC2_PIN, INPUT);
140+
lastSYNC2 = (HIGH == SYNC2_TRIGGER) ? LOW : HIGH;
141+
#endif
142142
#endif
143143

144144
#if defined(DISPLAY)
145145
// Initialize display
146146
displaySurface.begin();
147147
#endif
148-
148+
149149
// Initialize PWM Pins
150150
pinMode(LFO1_OUTPUT_PIN, OUTPUT); // pin11= PWM:A
151151
pinMode(LFO2_OUTPUT_PIN, OUTPUT); // pin 3= PWM:B
@@ -158,12 +158,12 @@ void setup()
158158

159159

160160
// Initialize wave tables
161-
LFO1_WaveTable = waveTables[0];
162-
LFO2_WaveTable = waveTables[0];
163-
161+
LFO1_WaveTable = (byte*)waveTables[0];
162+
LFO2_WaveTable = (byte*)waveTables[0];
163+
164164
// Initialize wave switch states
165-
while (LFO1_WaveSwitch.stateDebounced()==0);
166-
while (LFO2_WaveSwitch.stateDebounced()==0);
165+
while (LFO1_WaveSwitch.stateDebounced() == 0);
166+
while (LFO2_WaveSwitch.stateDebounced() == 0);
167167

168168
// Initialize timer
169169
Setup_timer2();
@@ -173,8 +173,8 @@ void setup()
173173

174174
void loop()
175175
{
176-
177-
// SYNC code included if SYNC option defined in Settings.h
176+
177+
// SYNC code included if SYNC option defined in Settings.h
178178
#if defined(SYNC)
179179

180180
// SYNC 1 + SYNC_COMMON
@@ -183,39 +183,39 @@ void loop()
183183
lastSYNC1 = pinState;
184184
if (pinState == SYNC1_TRIGGER) {
185185
accumulatorA = 0;
186-
#if defined(SYNC_COMMON)
187-
accumulatorB = 0;
188-
#endif
186+
#if defined(SYNC_COMMON)
187+
accumulatorB = 0;
188+
#endif
189189
}
190190
}
191-
191+
192192
// Separate SYNC inputs processed if SYNC1 and SYNC2 pins are different
193-
#if !defined(SYNC_COMMON)
194-
// SYNC 2 (SYNC pins are separate)
195-
pinState = digitalRead(SYNC2_PIN);
196-
if (pinState != lastSYNC2) {
197-
lastSYNC2 = pinState;
198-
if (pinState == SYNC2_TRIGGER) accumulatorB = 0;
199-
}
200-
#endif
201-
193+
#if !defined(SYNC_COMMON)
194+
// SYNC 2 (SYNC pins are separate)
195+
pinState = digitalRead(SYNC2_PIN);
196+
if (pinState != lastSYNC2) {
197+
lastSYNC2 = pinState;
198+
if (pinState == SYNC2_TRIGGER) accumulatorB = 0;
199+
}
200+
#endif
201+
202202
#endif
203-
203+
204204
// Check controls every 1/10 second
205205
if (fourMilliCounter > 25) {
206-
fourMilliCounter=0;
206+
fourMilliCounter = 0;
207207

208-
// If DISPLAY defined in Settings.h
208+
// If DISPLAY defined in Settings.h
209209
#if defined(DISPLAY)
210-
displaySurface.update();
210+
displaySurface.update();
211211
#endif
212212

213213
// LFO 1 wave table switch
214214
pinState = LFO1_WaveSwitch.stateDebounced();
215215
if (LFO1_WaveSwitch.changed()) {
216216
if (pinState == 1) {
217217
LFO1_WaveTableNum = (LFO1_WaveTableNum + 1) % NUM_WAVES;
218-
LFO1_WaveTable = waveTables[LFO1_WaveTableNum];
218+
LFO1_WaveTable = (byte*)waveTables[LFO1_WaveTableNum];
219219
}
220220
}
221221

@@ -224,16 +224,16 @@ void loop()
224224
if (LFO2_WaveSwitch.changed()) {
225225
if (pinState == 1) {
226226
LFO2_WaveTableNum = (LFO2_WaveTableNum + 1) % NUM_WAVES;
227-
LFO2_WaveTable = waveTables[LFO2_WaveTableNum];
227+
LFO2_WaveTable = (byte*)waveTables[LFO2_WaveTableNum];
228228
}
229229
}
230230

231231
// LFO 1 frequency/depth controls
232-
LFO1_TuningWord = POW2TO32 * (((((double)LFO1_FreqKnob.value()*LFO1_FREQ_RANGE)/1024L) + LFO1_FREQ_MIN) / clock);
232+
LFO1_TuningWord = POW2TO32 * (((((double)LFO1_FreqKnob.value() * LFO1_FREQ_RANGE) / 1024L) + LFO1_FREQ_MIN) / clock);
233233
LFO1_Depth = LFO1_DepthKnob.value();
234234

235235
// LFO 2 frequency/depth controls
236-
LFO2_TuningWord = POW2TO32 * (((((double)LFO2_FreqKnob.value()*LFO2_FREQ_RANGE)/1024L) + LFO2_FREQ_MIN) / clock);
236+
LFO2_TuningWord = POW2TO32 * (((((double)LFO2_FreqKnob.value() * LFO2_FREQ_RANGE) / 1024L) + LFO2_FREQ_MIN) / clock);
237237
LFO2_Depth = LFO2_DepthKnob.value();
238238
}
239239

@@ -261,8 +261,8 @@ void Setup_timer2() {
261261
cbi (TCCR2B, WGM22);
262262

263263
// Enable interrupt
264-
sbi (TIMSK2,TOIE2);
265-
264+
sbi (TIMSK2, TOIE2);
265+
266266
}
267267

268268
////////////////////////////////////////////////////////////////
@@ -275,10 +275,10 @@ ISR(TIMER2_OVF_vect) {
275275
byte offset;
276276

277277
// Count every four milliseconds
278-
if(tickCounter++ == 125) {
278+
if (tickCounter++ == 125) {
279279
fourMilliCounter++;
280-
tickCounter=0;
281-
}
280+
tickCounter = 0;
281+
}
282282

283283
// Sample wave table for LFO1
284284
accumulatorA += LFO1_TuningWord;
@@ -289,5 +289,5 @@ ISR(TIMER2_OVF_vect) {
289289
accumulatorB += LFO2_TuningWord;
290290
offset = accumulatorB >> 24; // high order byte
291291
OCR2B = (pgm_read_byte_near(LFO2_WaveTable + offset) * LFO2_Depth) / 1024L;
292-
292+
293293
}

0 commit comments

Comments
 (0)