WIP - build some code on the PC to run valgrind/etc.

This commit is contained in:
Earle F. Philhower, III committed 2018-01-19 19:39:19 -08:00
1 parent e5d23a4692
commit cffb424c2c
10 files changed
+452 -8

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
/*
AudioFileSourceSTDIO
Input STDIO "file" to be used by AudioGenerator
Only for hot-based testing
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Arduino.h>
#ifndef ARDUINO
#include "AudioFileSourceSTDIO.h"
AudioFileSourceSTDIO::AudioFileSourceSTDIO()
{
f = NULL;
}
AudioFileSourceSTDIO::AudioFileSourceSTDIO(const char *filename)
{
open(filename);
}
bool AudioFileSourceSTDIO::open(const char *filename)
{
f = fopen(filename, "rb");
return f;
}
AudioFileSourceSTDIO::~AudioFileSourceSTDIO()
{
if (f) fclose(f);
f = NULL;
}
uint32_t AudioFileSourceSTDIO::read(void *data, uint32_t len)
{
return fread(reinterpret_cast<uint8_t*>(data), 1, len, f);
}
bool AudioFileSourceSTDIO::seek(int32_t pos, int dir)
{
return fseek(f, pos, dir);
}
bool AudioFileSourceSTDIO::close()
{
fclose(f);
return true;
}
bool AudioFileSourceSTDIO::isOpen()
{
return f?true:false;
}
uint32_t AudioFileSourceSTDIO::getSize()
{
if (!f) return 0;
uint32_t p = ftell(f);
fseek(f, 0, SEEK_END);
uint32_t len = ftell(f);
fseek(f, p, SEEK_SET);
return len;
}
#endif
+53
View File
@@ -0,0 +1,53 @@
/*
AudioFileSourceSTDIO
Input SPIFFS "file" to be used by AudioGenerator
Only for host-based testing, not Arduino
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOFILESOURCESTDIO_H
#define _AUDIOFILESOURCESTDIO_H
#include <Arduino.h>
#ifndef ARDUINO
#include "AudioFileSource.h"
class AudioFileSourceSTDIO : public AudioFileSource
{
public:
AudioFileSourceSTDIO();
AudioFileSourceSTDIO(const char *filename);
virtual ~AudioFileSourceSTDIO() override;
virtual bool open(const char *filename) override;
virtual uint32_t read(void *data, uint32_t len) override;
virtual bool seek(int32_t pos, int dir) override;
virtual bool close() override;
virtual bool isOpen() override;
virtual uint32_t getSize() override;
virtual uint32_t getPos() override { if (!f) return 0; else return (uint32_t)ftell(f); };
private:
FILE *f;
};
#endif // !ARDUINO
#endif
+11 -3
View File
@@ -232,7 +232,7 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
#undef stack
extern "C" {
#ifdef ESP32
//TOTO - add ESP32 checks
//TODO - add ESP32 checks
void stack(const char *s, const char *t, int i)
{
}
@@ -240,7 +240,7 @@ extern "C" {
{
return 8192;
}
#else
#elif defined(ESP8266)
#include <cont.h>
extern cont_t g_cont;
@@ -274,6 +274,14 @@ extern "C" {
int freestack = 4 * (sp - g_cont.stack);
return freestack;
}
#endif
#else
void stack(const char *s, const char *t, int i)
{
}
int stackfree()
{
return 8192;
}
#endif
}
+115
View File
@@ -0,0 +1,115 @@
/*
AudioOutputSTDIO
Writes a WAV file to the STDIO filesystem
Only for host-based testing
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Arduino.h>
#ifndef ARDUINO
#include "AudioOutputSTDIO.h"
#include <unistd.h>
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 };
void AudioOutputSTDIO::SetFilename(const char *name)
{
free(filename);
filename = strdup(name);
}
bool AudioOutputSTDIO::begin()
{
uint8_t wavHeader[sizeof(wavHeaderTemplate)];
memset(wavHeader, 0, sizeof(wavHeader));
if (f) return false; // Already open!
unlink(filename);
f = fopen(filename, "wb+");
if (!f) return false;
// We'll fix the header up when we close the file
fwrite(wavHeader, sizeof(wavHeader), 1, f);
return true;
}
bool AudioOutputSTDIO::ConsumeSample(int16_t sample[2])
{
for (int i=0; i<channels; i++) {
if (bps == 8) {
uint8_t l = sample[i] & 0xff;
fwrite(&l, sizeof(l), 1, f);
} else {
uint8_t l = sample[i] & 0xff;
uint8_t h = (sample[i] >> 8) & 0xff;
fwrite(&l, sizeof(l), 1, f);
fwrite(&h, sizeof(h), 1, f);
}
}
return true;
}
bool AudioOutputSTDIO::stop()
{
uint8_t wavHeader[sizeof(wavHeaderTemplate)];
memcpy_P(wavHeader, wavHeaderTemplate, sizeof(wavHeaderTemplate));
int chunksize = ftell(f) - 8;
wavHeader[4] = chunksize & 0xff;
wavHeader[5] = (chunksize>>8)&0xff;
wavHeader[6] = (chunksize>>16)&0xff;
wavHeader[7] = (chunksize>>24)&0xff;
wavHeader[22] = channels & 0xff;
wavHeader[23] = 0;
wavHeader[24] = hertz & 0xff;
wavHeader[25] = (hertz >> 8) & 0xff;
wavHeader[26] = (hertz >> 16) & 0xff;
wavHeader[27] = (hertz >> 24) & 0xff;
int byteRate = hertz * bps * channels / 8;
wavHeader[28] = byteRate & 0xff;
wavHeader[29] = (byteRate >> 8) & 0xff;
wavHeader[30] = (byteRate >> 16) & 0xff;
wavHeader[31] = (byteRate >> 24) & 0xff;
wavHeader[32] = channels * bps / 8;
wavHeader[33] = 0;
wavHeader[34] = bps;
wavHeader[35] = 0;
int datasize = ftell(f) - sizeof(wavHeader);
wavHeader[40] = datasize & 0xff;
wavHeader[41] = (datasize>>8)&0xff;
wavHeader[42] = (datasize>>16)&0xff;
wavHeader[43] = (datasize>>24)&0xff;
// Write real header out
fseek(f, 0, SEEK_SET);
fwrite(wavHeader, sizeof(wavHeader), 1, f);
fclose(f);
return true;
}
#endif
+47
View File
@@ -0,0 +1,47 @@
/*
AudioOutputSTDIO
Writes a WAV file to the STDIO filesystem
Only for host-based testing
Copyright (C) 2017 Earle F. Philhower, III
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _AUDIOOUTPUTSTDIO_H
#define _AUDIOOUTPUTSTDIO_H
#include <Arduino.h>
#ifndef ARDUINO
#include "AudioOutput.h"
class AudioOutputSTDIO : public AudioOutput
{
public:
AudioOutputSTDIO() { filename = NULL; };
~AudioOutputSTDIO() { free(filename); };
virtual bool begin() override;
virtual bool ConsumeSample(int16_t sample[2]) override;
virtual bool stop() override;
void SetFilename(const char *name);
private:
FILE *f;
char *filename;
};
#endif
#endif
+1 -5
View File
@@ -1257,11 +1257,7 @@ static void tsf_voice_render(tsf* f, struct tsf_voice* v, float* outputBuffer, i
void DumpF32P32(char *name, long long x) {
#ifdef ESP32
printf("%s = %08x.%08x\n", name, (int)((x>>32)&0xffffffff), (int)(x&0xffffffff));
#else
printf("%s = %08x.%08x\n", name, (int32)((x>>32)&0xffffffff), (int32)(x&0xffffffff));
#endif
printf("%s = %08x.%08x\n", name, (int32_t)((x>>32)&0xffffffff), (int32_t)(x&0xffffffff));
}
static void tsf_voice_render_fast(tsf* f, struct tsf_voice* v, short* outputBuffer, int numSamples)
{