From 3464ba5298016bc3e32d5caafe48fca0c6b123e0 Mon Sep 17 00:00:00 2001 From: Jorj Bauer Date: Sun, 26 Feb 2017 20:34:38 -0500 Subject: [PATCH] reimplement volume control --- globals.cpp | 2 +- sdl/sdl-speaker.cpp | 5 +++++ teensy/bios.cpp | 12 ++++++------ teensy/teensy-speaker.cpp | 7 +++++-- teensy/teensy.ino | 4 ++-- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/globals.cpp b/globals.cpp index 56a38ae..d9e0e24 100644 --- a/globals.cpp +++ b/globals.cpp @@ -8,5 +8,5 @@ PhysicalKeyboard *g_keyboard = NULL; PhysicalSpeaker *g_speaker = NULL; PhysicalPaddles *g_paddles = NULL; PhysicalPrinter *g_printer = NULL; -int16_t g_volume; +int16_t g_volume = 15; uint8_t g_displayType = 3; // FIXME m_perfectcolor diff --git a/sdl/sdl-speaker.cpp b/sdl/sdl-speaker.cpp index 915f7cf..d3888a5 100644 --- a/sdl/sdl-speaker.cpp +++ b/sdl/sdl-speaker.cpp @@ -9,6 +9,9 @@ extern "C" #include "timeutil.h" +#include "globals.h" + + // FIXME: Globals; ick. static pthread_t speakerThreadID; static uint8_t curSpeakerData = 0x00; @@ -141,6 +144,8 @@ void SDLSpeaker::maintainSpeaker(uint32_t c) mixerValue >>= 3; // divide by 8 + // FIXME: g_volume + curSpeakerData = mixerValue & 0xFF; } diff --git a/teensy/bios.cpp b/teensy/bios.cpp index f789e06..09a21f9 100644 --- a/teensy/bios.cpp +++ b/teensy/bios.cpp @@ -125,14 +125,14 @@ bool BIOS::runUntilDone() } break; case ACT_VOLPLUS: - g_volume += 10; - if (g_volume > 255) { - g_volume = 255; + g_volume ++; + if (g_volume > 15) { + g_volume = 15; } volumeDidChange = true; break; case ACT_VOLMINUS: - g_volume -= 10; + g_volume--; if (g_volume < 0) { g_volume = 0; } @@ -213,7 +213,7 @@ bool BIOS::isActionActive(int8_t action) return true; case ACT_VOLPLUS: - return (g_volume < 255); + return (g_volume < 15); case ACT_VOLMINUS: return (g_volume > 0); } @@ -284,7 +284,7 @@ void BIOS::DrawMainMenu(int8_t selection) } // draw the volume bar - uint16_t volCutoff = 300.0 * (float)((float) g_volume / 256.0); + uint16_t volCutoff = 300.0 * (float)((float) g_volume / 15.0); for (uint8_t y=200; y<=210; y++) { ((TeensyDisplay *)g_display)->moveTo(10, y); for (uint16_t x = 0; x< 300; x++) { diff --git a/teensy/teensy-speaker.cpp b/teensy/teensy-speaker.cpp index 87722d5..c736977 100644 --- a/teensy/teensy-speaker.cpp +++ b/teensy/teensy-speaker.cpp @@ -1,7 +1,7 @@ #include #include "teensy-speaker.h" -extern int16_t g_volume; +#include "globals.h" TeensySpeaker::TeensySpeaker(uint8_t pinNum) : PhysicalSpeaker() { @@ -37,7 +37,10 @@ void TeensySpeaker::maintainSpeaker(uint32_t c) }*/ // FIXME: glad it's DAC0 and all, but... how does that relate to the pin passed in the constructor? - analogWriteDAC0(mixerValue); // FIXME: g_volume? + + mixerValue >>= (16-g_volume); + + analogWriteDAC0(mixerValue); } void TeensySpeaker::beginMixing() diff --git a/teensy/teensy.ino b/teensy/teensy.ino index d1c68e0..e67dbe1 100644 --- a/teensy/teensy.ino +++ b/teensy/teensy.ino @@ -371,8 +371,8 @@ void readPrefs() if (p.magic == MAGIC) { // looks valid! Use it. Serial.println("prefs valid! Restoring volume"); - if (p.volume > 4095) { - p.volume = 4095; + if (p.volume > 15) { + p.volume = 15; } if (p.volume < 0) { p.volume = 0;