From 0a453a077a13a89f8386b7008ca7003750caa9a3 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Tue, 15 Aug 2017 19:00:58 -0700 Subject: [PATCH] Warning and static removal Clean up compiler warnings and make static variables in class functions into class variables where they belong. --- src/AudioFileSourceHTTPStream.cpp | 2 +- src/AudioGenerator.h | 3 ++- src/AudioGeneratorMOD.cpp | 42 +++++++++++-------------------- src/AudioGeneratorMOD.h | 15 +++++------ src/AudioGeneratorMP3.cpp | 2 -- src/AudioGeneratorWAV.cpp | 22 ++++++---------- src/AudioOutputI2SNoDAC.cpp | 7 ++---- src/AudioOutputI2SNoDAC.h | 4 +++ src/AudioOutputSerialWAV.cpp | 9 ++++--- 9 files changed, 43 insertions(+), 63 deletions(-) diff --git a/src/AudioFileSourceHTTPStream.cpp b/src/AudioFileSourceHTTPStream.cpp index 2178675..10c6b0c 100644 --- a/src/AudioFileSourceHTTPStream.cpp +++ b/src/AudioFileSourceHTTPStream.cpp @@ -53,7 +53,7 @@ uint32_t AudioFileSourceHTTPStream::read(void *data, uint32_t len) if (!http.connected()) return 0; WiFiClient *stream = http.getStreamPtr(); - while (stream->available() < len) yield(); + while (stream->available() < (int)len) yield(); size_t avail = stream->available(); if (!avail) return 0; diff --git a/src/AudioGenerator.h b/src/AudioGenerator.h index 7499a58..2ca9563 100644 --- a/src/AudioGenerator.h +++ b/src/AudioGenerator.h @@ -28,7 +28,7 @@ class AudioGenerator { public: - AudioGenerator() {}; + AudioGenerator() { lastSample[0] = 0; lastSample[1] = 0; }; virtual ~AudioGenerator() {}; virtual bool begin(AudioFileSource *source, AudioOutput *output) { (void)source; (void)output; return false; }; virtual bool loop() { return false; }; @@ -39,6 +39,7 @@ class AudioGenerator bool running; AudioFileSource *file; AudioOutput *output; + int16_t lastSample[2]; }; diff --git a/src/AudioGeneratorMOD.cpp b/src/AudioGeneratorMOD.cpp index 800f765..cf1fd83 100644 --- a/src/AudioGeneratorMOD.cpp +++ b/src/AudioGeneratorMOD.cpp @@ -45,6 +45,7 @@ AudioGeneratorMOD::AudioGeneratorMOD() sampleRate = 44100; fatBufferSize = 6 * 1024; stereoSeparation = 32; + mixerTick = 0; usePAL = false; UpdateAmiga(); running = false; @@ -74,32 +75,24 @@ bool AudioGeneratorMOD::stop() bool AudioGeneratorMOD::loop() { - static uint16_t i = 0; // Sample counter as we only periodically advance the player control - static uint32_t lastSample = 0; // when we block, store the samples we can't send here - int16_t sample[2]; - if (!running) return false; // Easy-peasy // First, try and push in the stored sample. If we can't, then punt and try later - sample[AudioOutput::LEFTCHANNEL] = lastSample & 0xffff; - sample[AudioOutput::RIGHTCHANNEL] = (lastSample>>16) & 0xffff; - if (!output->ConsumeSample(sample)) return true; // FIFO full, wait... + if (!output->ConsumeSample(lastSample)) return true; // FIFO full, wait... // Now advance enough times to fill the i2s buffer do { - if (i == 0) { + if (mixerTick == 0) { running = RunPlayer(); if (!running) { stop(); return false; } - i = Player.samplesPerTick; + mixerTick = Player.samplesPerTick; } - lastSample = GetSample(); - sample[AudioOutput::LEFTCHANNEL] = lastSample & 0xffff; - sample[AudioOutput::RIGHTCHANNEL] = (lastSample>>16) & 0xffff; - i--; - } while (output->ConsumeSample(sample)); + GetSample( lastSample ); + mixerTick--; + } while (output->ConsumeSample(lastSample)); // We'll be left with one sample still in our buffer because it couldn't fit in the FIFO return true; } @@ -559,9 +552,9 @@ bool AudioGeneratorMOD::ProcessRow() break; } - if (note != NONOTE || Player.lastAmigaPeriod[channel] && + if (note != NONOTE || (Player.lastAmigaPeriod[channel] && effectNumber != VIBRATO && effectNumber != VIBRATOVOLUMESLIDE && - !(effectNumber == 0xE && effectParameterX == NOTEDELAY)) + !(effectNumber == 0xE && effectParameterX == NOTEDELAY))) Mixer.channelFrequency[channel] = Player.amiga / Player.lastAmigaPeriod[channel]; if (note != NONOTE) @@ -733,7 +726,7 @@ bool AudioGeneratorMOD::RunPlayer() return true; } -uint32_t AudioGeneratorMOD::GetSample() +void AudioGeneratorMOD::GetSample(int16_t sample[2]) { int16_t sumL; int16_t sumR; @@ -743,7 +736,7 @@ uint32_t AudioGeneratorMOD::GetSample() int8_t next; int16_t out; - if (!running) return 0; + if (!running) return; sumL = 0; sumR = 0; @@ -784,11 +777,11 @@ uint32_t AudioGeneratorMOD::GetSample() if (!file->seek(samplePointer, SEEK_SET)) { stop(); - return 0; + return; } if (toRead != file->read(FatBuffer.channels[channel], toRead)) { stop(); - return 0; + return; } FatBuffer.samplePointer[channel] = samplePointer; @@ -819,13 +812,8 @@ uint32_t AudioGeneratorMOD::GetSample() sumR /= Mod.numberOfChannels; // Fill the sound buffer with unsigned values - int16_t left = sumL + (1 << (BITDEPTH - 1)); - int16_t right = sumR + (1 << (BITDEPTH - 1)); - - uint32_t sample = (right << 16) & 0xffff0000; - sample |= left & 0xffff; - - return sample; + sample[AudioOutput::LEFTCHANNEL] = sumL + (1 << (BITDEPTH - 1)); + sample[AudioOutput::RIGHTCHANNEL] = sumR + (1 << (BITDEPTH - 1)); } bool AudioGeneratorMOD::LoadMOD() diff --git a/src/AudioGeneratorMOD.h b/src/AudioGeneratorMOD.h index a93a9d5..3260820 100644 --- a/src/AudioGeneratorMOD.h +++ b/src/AudioGeneratorMOD.h @@ -37,10 +37,10 @@ class AudioGeneratorMOD : AudioGenerator bool SetStereoSeparation(int sep) { if (running || (sep<0) || (sep>64)) return false; stereoSeparation = sep; return true; } bool SetPAL(bool use) { if (running) return false; usePAL = use; return true; } - private: + protected: bool LoadMOD(); bool LoadHeader(); - uint32_t GetSample(); + void GetSample(int16_t sample[2]); bool RunPlayer(); void LoadSamples(); bool LoadPattern(uint8_t pattern); @@ -52,10 +52,11 @@ class AudioGeneratorMOD : AudioGenerator protected: - static const int BITDEPTH = 16; + int mixerTick; + enum {BITDEPTH = 16}; int sampleRate; int fatBufferSize; //(6*1024) // File system buffers per-CHANNEL (i.e. total mem required is 4 * FATBUFFERSIZE) - static const int DIVIDER= 10; // Fixed-point mantissa used for integer arithmetic + enum {DIVIDER = 10}; // Fixed-point mantissa used for integer arithmetic int stereoSeparation; //STEREOSEPARATION = 32; // 0 (max) to 64 (mono) bool usePAL; @@ -64,10 +65,7 @@ class AudioGeneratorMOD : AudioGenerator int AMIGA; void UpdateAmiga() { AMIGA = ((usePAL?7159091:7093789) / 2 / sampleRate << DIVIDER); } - static const int ROWS = 64; - static const int SAMPLES = 31; - static const int CHANNELS = 4; - static const int NONOTE = 0xFFFF; + enum {ROWS = 64, SAMPLES = 31, CHANNELS = 4, NONOTE = 0xFFFF, NONOTE8 = 0xff }; typedef struct Sample { uint16_t length; @@ -92,7 +90,6 @@ class AudioGeneratorMOD : AudioGenerator uint8_t effectNumber[ROWS][CHANNELS]; uint8_t effectParameter[ROWS][CHANNELS]; } Pattern; - static const int NONOTE8 = 0xFF; typedef struct player { Pattern currentPattern; diff --git a/src/AudioGeneratorMP3.cpp b/src/AudioGeneratorMP3.cpp index bfabd86..0636940 100644 --- a/src/AudioGeneratorMP3.cpp +++ b/src/AudioGeneratorMP3.cpp @@ -157,8 +157,6 @@ bool AudioGeneratorMP3::GetOneSample(int16_t sample[2]) bool AudioGeneratorMP3::loop() { - static int16_t lastSample[2]= {0,0}; - if (!running) return true; // Nothing to do here! // First, try and push in the stored sample. If we can't, then punt and try later diff --git a/src/AudioGeneratorWAV.cpp b/src/AudioGeneratorWAV.cpp index e08a077..753ea31 100644 --- a/src/AudioGeneratorWAV.cpp +++ b/src/AudioGeneratorWAV.cpp @@ -73,16 +73,10 @@ bool AudioGeneratorWAV::GetBufferedData(int bytes, void *dest) bool AudioGeneratorWAV::loop() { - static int16_t lastLeft = 0; - static int16_t lastRight = 0; - int16_t sample[2]; - if (!running) return true; // Nothing to do here! // First, try and push in the stored sample. If we can't, then punt and try later - sample[AudioOutput::LEFTCHANNEL] = lastLeft; - sample[AudioOutput::RIGHTCHANNEL] = lastRight; - if (!output->ConsumeSample(sample)) return true; // Can't send, but no error detected + if (!output->ConsumeSample(lastSample)) return true; // Can't send, but no error detected // Try and stuff the buffer one sample at a time do @@ -95,19 +89,17 @@ bool AudioGeneratorWAV::loop() } else { r = 0; } - lastLeft = l; - lastRight = r; + lastSample[AudioOutput::LEFTCHANNEL] = l; + lastSample[AudioOutput::RIGHTCHANNEL] = r; } else if (bitsPerSample == 16) { - if (!GetBufferedData(2, &lastLeft)) stop(); + if (!GetBufferedData(2, &lastSample[AudioOutput::LEFTCHANNEL])) stop(); if (channels == 2) { - if (!GetBufferedData(2, &lastRight)) stop(); + if (!GetBufferedData(2, &lastSample[AudioOutput::RIGHTCHANNEL])) stop(); } else { - lastRight = 0; + lastSample[AudioOutput::RIGHTCHANNEL] = 0; } } - sample[AudioOutput::LEFTCHANNEL] = lastLeft; - sample[AudioOutput::RIGHTCHANNEL] = lastRight; - } while (running && output->ConsumeSample(sample)); + } while (running && output->ConsumeSample(lastSample)); return running; } diff --git a/src/AudioOutputI2SNoDAC.cpp b/src/AudioOutputI2SNoDAC.cpp index 8c94f27..9ba34f5 100644 --- a/src/AudioOutputI2SNoDAC.cpp +++ b/src/AudioOutputI2SNoDAC.cpp @@ -30,6 +30,8 @@ AudioOutputI2SNoDAC::AudioOutputI2SNoDAC() i2sOn = true; hertz = 44100; oversample = 32; + lastSamp = 0; + cumErr = 0; } AudioOutputI2SNoDAC::~AudioOutputI2SNoDAC() @@ -75,13 +77,8 @@ bool AudioOutputI2SNoDAC::begin() return true; } -typedef int32_t fixed24p8_t; -#define fixedPosValue 0x007fff00 /* 24.8 of max-signed-int */ void AudioOutputI2SNoDAC::DeltaSigma(int16_t sample[2], uint32_t dsBuff[4]) { - static fixed24p8_t lastSamp = 0; // Last sample value - static fixed24p8_t cumErr = 0; // Running cumulative error since time began - // Not shift 8 because addition takes care of one mult x 2 fixed24p8_t newSamp = ( ((int32_t)sample[0]) + ((int32_t)sample[1]) ) << 7; diff --git a/src/AudioOutputI2SNoDAC.h b/src/AudioOutputI2SNoDAC.h index 0372197..addea60 100644 --- a/src/AudioOutputI2SNoDAC.h +++ b/src/AudioOutputI2SNoDAC.h @@ -41,6 +41,10 @@ class AudioOutputI2SNoDAC : public AudioOutput static bool i2sOn; // One per machine, not per instance... int oversample; void DeltaSigma(int16_t sample[2], uint32_t dsBuff[4]); + typedef int32_t fixed24p8_t; + enum {fixedPosValue=0x007fff00}; /* 24.8 of max-signed-int */ + fixed24p8_t lastSamp; // Last sample value + fixed24p8_t cumErr; // Running cumulative error since time began }; #endif diff --git a/src/AudioOutputSerialWAV.cpp b/src/AudioOutputSerialWAV.cpp index 8a660de..40e9876 100644 --- a/src/AudioOutputSerialWAV.cpp +++ b/src/AudioOutputSerialWAV.cpp @@ -20,12 +20,15 @@ #include "AudioOutputSerialWAV.h" -bool AudioOutputSerialWAV::begin() -{ - static uint8_t wavHeader[] = { // Hardcoded simple WAV header with 0xffffffff lengths all around +static const uint8_t wavHeaderTemplate[] PROGMEM = { // Hardcoded simple WAV header with 0xffffffff lengths all around 0x52, 0x49, 0x46, 0x46, 0xff, 0xff, 0xff, 0xff, 0x57, 0x41, 0x56, 0x45, 0x66, 0x6d, 0x74, 0x20, 0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x22, 0x56, 0x00, 0x00, 0x88, 0x58, 0x01, 0x00, 0x04, 0x00, 0x10, 0x00, 0x64, 0x61, 0x74, 0x61, 0xff, 0xff, 0xff, 0xff }; + +bool AudioOutputSerialWAV::begin() +{ + uint8_t wavHeader[sizeof(wavHeaderTemplate)]; + memcpy_P(wavHeader, wavHeaderTemplate, sizeof(wavHeaderTemplate)); wavHeader[22] = channels & 0xff; wavHeader[23] = 0; wavHeader[24] = hertz & 0xff;