Skip to content

Commit 989d731

Browse files
Voice WIP
1 parent 7c2f1b8 commit 989d731

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

M4_Eyes/pdmvoice.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ bool voiceSetup(bool modEnable) {
110110

111111
// Allocate buffer for voice modulation, if enabled
112112
if(modEnable) {
113-
// 250 comes from min period in voicePitch()
114-
modBuf = (uint8_t *)malloc((int)(48000000.0 / 250.0 / MOD_MIN + 0.5));
113+
// Second 16.0 comes from min period in voicePitch()
114+
modBuf = (uint8_t *)malloc((int)(48000000.0 /16.0 / 16.0 / MOD_MIN + 0.5));
115115
// If malloc fails, program will continue without modulation
116116
}
117117

@@ -161,7 +161,7 @@ bool voiceSetup(bool modEnable) {
161161
// adjustment (after appying constraints) will be returned.
162162
float voicePitch(float p) {
163163
float desiredPlaybackRate = sampleRate * p;
164-
int32_t period = (int32_t)(48000000.0 / 16.0 / desiredPlaybackRate + 0.5);
164+
int32_t period = (int32_t)(48000000.0 / 16.0 / desiredPlaybackRate);
165165
if(period > 160) period = 160; // Hard limit is 65536, 160 is a practical limit
166166
else if(period < 16) period = 16; // Leave some cycles for IRQ handler
167167
float actualPlaybackRate = 48000000.0 / 16.0 / (float)period;
@@ -190,6 +190,7 @@ void voiceMod(uint32_t freq, uint8_t waveform) {
190190
if(modBuf) { // Ignore if no modulation buffer allocated
191191
if(freq < MOD_MIN) freq = MOD_MIN;
192192
/*
193+
TO DO: FIX THIS NOW THAT USING ARCADA ZEROTIMER:
193194
uint16_t period = TIMER->COUNT16.CC[0].reg + 1; // Audio out timer ticks
194195
float playbackRate = 48000000.0 / 16.0 / (float)period; // Audio out samples/sec
195196
modLen = (int)(playbackRate / freq + 0.5);

0 commit comments

Comments
 (0)