Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
299833dbf9 | ||
|
|
90258c566a | ||
|
|
0ec3bc3b31 | ||
|
|
2fb8d887b1 | ||
|
|
93a540da9b | ||
|
|
1c51669729 | ||
|
|
96d036087b |
No files matched your search
@@ -0,0 +1,108 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#else
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#endif
|
||||||
|
#include "AudioFileSourceICYStream.h"
|
||||||
|
#include "AudioFileSourceBuffer.h"
|
||||||
|
#include "AudioGeneratorMP3.h"
|
||||||
|
#include "AudioOutputNull.h"
|
||||||
|
|
||||||
|
// To run, set your ESP8266 build to 160MHz, update the SSID info, and upload.
|
||||||
|
|
||||||
|
// Enter your WiFi setup here:
|
||||||
|
#ifndef STASSID
|
||||||
|
#define STASSID ""
|
||||||
|
#define STAPSK ""
|
||||||
|
#endif
|
||||||
|
|
||||||
|
const char* ssid = STASSID;
|
||||||
|
const char* password = STAPSK;
|
||||||
|
|
||||||
|
// Randomly picked URL
|
||||||
|
const char *URL="http://icecast.radiofrance.fr/franceinter-lofi.mp3";
|
||||||
|
//const char *URL="http://kvbstreams.dyndns.org:8000/wkvi-am";
|
||||||
|
|
||||||
|
AudioGeneratorMP3 *mp3;
|
||||||
|
AudioFileSourceICYStream *file;
|
||||||
|
AudioFileSourceBuffer *buff;
|
||||||
|
AudioOutputNull *out;
|
||||||
|
|
||||||
|
// Called when a metadata event occurs (i.e. an ID3 tag, an ICY block, etc.
|
||||||
|
void MDCallback(void *cbData, const char *type, bool isUnicode, const char *string)
|
||||||
|
{
|
||||||
|
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||||
|
(void) isUnicode; // Punt this ball for now
|
||||||
|
// Note that the type and string may be in PROGMEM, so copy them to RAM for printf
|
||||||
|
char s1[32], s2[64];
|
||||||
|
strncpy_P(s1, type, sizeof(s1));
|
||||||
|
s1[sizeof(s1)-1]=0;
|
||||||
|
strncpy_P(s2, string, sizeof(s2));
|
||||||
|
s2[sizeof(s2)-1]=0;
|
||||||
|
Serial.printf("METADATA(%s) '%s' = '%s'\n", ptr, s1, s2);
|
||||||
|
Serial.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when there's a warning or error (like a buffer underflow or decode hiccup)
|
||||||
|
void StatusCallback(void *cbData, int code, const char *string)
|
||||||
|
{
|
||||||
|
const char *ptr = reinterpret_cast<const char *>(cbData);
|
||||||
|
// Note that the string may be in PROGMEM, so copy it to RAM for printf
|
||||||
|
char s1[64];
|
||||||
|
strncpy_P(s1, string, sizeof(s1));
|
||||||
|
s1[sizeof(s1)-1]=0;
|
||||||
|
Serial.printf("STATUS(%s) '%d' = '%s'\n", ptr, code, s1);
|
||||||
|
Serial.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
delay(1000);
|
||||||
|
Serial.println("Connecting to WiFi");
|
||||||
|
|
||||||
|
WiFi.disconnect();
|
||||||
|
WiFi.softAPdisconnect(true);
|
||||||
|
WiFi.mode(WIFI_STA);
|
||||||
|
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
// Try forever
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
Serial.println("...Connecting to WiFi");
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
Serial.println("Connected");
|
||||||
|
|
||||||
|
audioLogger = &Serial;
|
||||||
|
file = new AudioFileSourceICYStream(URL);
|
||||||
|
file->RegisterMetadataCB(MDCallback, (void*)"ICY");
|
||||||
|
buff = new AudioFileSourceBuffer(file, 4096);
|
||||||
|
buff->RegisterStatusCB(StatusCallback, (void*)"buffer");
|
||||||
|
out = new AudioOutputNull();
|
||||||
|
mp3 = new AudioGeneratorMP3();
|
||||||
|
mp3->RegisterStatusCB(StatusCallback, (void*)"mp3");
|
||||||
|
mp3->begin(buff, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
static int lastms = 0;
|
||||||
|
|
||||||
|
if (mp3->isRunning()) {
|
||||||
|
if (millis()-lastms > 1000) {
|
||||||
|
lastms = millis();
|
||||||
|
Serial.printf("Running for %d ms...\n", lastms);
|
||||||
|
Serial.flush();
|
||||||
|
}
|
||||||
|
if (!mp3->loop()) mp3->stop();
|
||||||
|
} else {
|
||||||
|
Serial.printf("MP3 done\n");
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Executable
+50
@@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
ino=${PWD##*/}
|
||||||
|
|
||||||
|
if [ ! -d "${ESP8266ARDUINO}/tests/host" ]; then
|
||||||
|
echo "\${ESP8266ARDUINO} should point to ESP8266 Arduino core directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
THISLIB=$(pwd)/../..
|
||||||
|
MAD=$(ls ${THISLIB}/src/libmad/*.c)
|
||||||
|
|
||||||
|
cd ${ESP8266ARDUINO}/tests/host
|
||||||
|
|
||||||
|
if [ "$1" = "clean" ]; then
|
||||||
|
make clean
|
||||||
|
cd ${THISLIB}
|
||||||
|
rm -f src/*.o src/libmad/*.o
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$1" = "-h" ]; then
|
||||||
|
echo "usage:"
|
||||||
|
echo " $0"
|
||||||
|
echo " $0 clean"
|
||||||
|
echo " FORCE32=0 $0 (run with valgrind)"
|
||||||
|
echo " FORCE32=1 $0 (run in 32 bits)"
|
||||||
|
echo "variable ESP8266ARDUINO must point to esp8266 Arduino core directory"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -z "${FORCE32}" ] && FORCE32=0
|
||||||
|
|
||||||
|
if [ "${FORCE32}" = 0 ]; then
|
||||||
|
run=valgrind
|
||||||
|
else
|
||||||
|
run=
|
||||||
|
fi
|
||||||
|
|
||||||
|
eval make FORCE32=${FORCE32} V=1 -j \
|
||||||
|
USERCSOURCES=\"${MAD}\" \
|
||||||
|
USERCXXSOURCES=\"${THISLIB}/src/AudioFileSourceBuffer.cpp ${THISLIB}/src/AudioLogger.cpp ${THISLIB}/src/AudioGeneratorMP3.cpp ${THISLIB}/src/AudioFileSourceICYStream.cpp ${THISLIB}/src/AudioFileSourceHTTPStream.cpp\" \
|
||||||
|
USERCFLAGS=\"-I${THISLIB}/src/\" \
|
||||||
|
${THISLIB}/examples/${ino}/${ino}
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
$run ./bin/${ino}/${ino} "$@"
|
||||||
|
stty sane
|
||||||
|
|
||||||
+5
-2
@@ -14,10 +14,13 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/earlephilhower/ESP8266Audio"
|
"url": "https://github.com/earlephilhower/ESP8266Audio"
|
||||||
},
|
},
|
||||||
"version": "1.5.1",
|
"version": "1.6",
|
||||||
"homepage": "https://github.com/earlephilhower/ESP8266Audio",
|
"homepage": "https://github.com/earlephilhower/ESP8266Audio",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"SPI": "1.0"
|
"SPI": "1.0",
|
||||||
|
"SPIFFS": "1.0",
|
||||||
|
"HTTPClient": "1.0",
|
||||||
|
"WiFiClientSecure": "1.0"
|
||||||
},
|
},
|
||||||
"frameworks": "Arduino",
|
"frameworks": "Arduino",
|
||||||
"examples": [
|
"examples": [
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name=ESP8266Audio
|
name=ESP8266Audio
|
||||||
version=1.5.1
|
version=1.6
|
||||||
author=Earle F. Philhower, III
|
author=Earle F. Philhower, III
|
||||||
maintainer=Earle F. Philhower, III
|
maintainer=Earle F. Philhower, III
|
||||||
sentence=Audio file and I2S sound playing routines.
|
sentence=Audio file and I2S sound playing routines.
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ bool AudioFileSourceHTTPStream::open(const char *url)
|
|||||||
http.begin(client, url);
|
http.begin(client, url);
|
||||||
http.setReuse(true);
|
http.setReuse(true);
|
||||||
#ifndef ESP32
|
#ifndef ESP32
|
||||||
http.setFollowRedirects(true);
|
http.setFollowRedirects(HTTPC_FORCE_FOLLOW_REDIRECTS);
|
||||||
#endif
|
#endif
|
||||||
int code = http.GET();
|
int code = http.GET();
|
||||||
if (code != HTTP_CODE_OK) {
|
if (code != HTTP_CODE_OK) {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ class AudioGenerator
|
|||||||
virtual bool loop() { return false; };
|
virtual bool loop() { return false; };
|
||||||
virtual bool stop() { return false; };
|
virtual bool stop() { return false; };
|
||||||
virtual bool isRunning() { return false;};
|
virtual bool isRunning() { return false;};
|
||||||
|
virtual void desync () { };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool RegisterMetadataCB(AudioStatus::metadataCBFn fn, void *data) { return cb.RegisterMetadataCB(fn, data); }
|
virtual bool RegisterMetadataCB(AudioStatus::metadataCBFn fn, void *data) { return cb.RegisterMetadataCB(fn, data); }
|
||||||
|
|||||||
+68
-12
@@ -29,11 +29,23 @@ AudioGeneratorMP3::AudioGeneratorMP3()
|
|||||||
buff = NULL;
|
buff = NULL;
|
||||||
nsCountMax = 1152/32;
|
nsCountMax = 1152/32;
|
||||||
madInitted = false;
|
madInitted = false;
|
||||||
preallocateSpace = NULL;
|
|
||||||
preallocateSize = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioGeneratorMP3::AudioGeneratorMP3(void *space, int size)
|
AudioGeneratorMP3::AudioGeneratorMP3(void *space, int size): preallocateSpace(space), preallocateSize(size)
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
file = NULL;
|
||||||
|
output = NULL;
|
||||||
|
buff = NULL;
|
||||||
|
nsCountMax = 1152/32;
|
||||||
|
madInitted = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioGeneratorMP3::AudioGeneratorMP3(void *buff, int buffSize, void *stream, int streamSize, void *frame, int frameSize, void *synth, int synthSize):
|
||||||
|
preallocateSpace(buff), preallocateSize(buffSize),
|
||||||
|
preallocateStreamSpace(stream), preallocateStreamSize(streamSize),
|
||||||
|
preallocateFrameSpace(frame), preallocateFrameSize(frameSize),
|
||||||
|
preallocateSynthSpace(synth), preallocateSynthSize(synthSize)
|
||||||
{
|
{
|
||||||
running = false;
|
running = false;
|
||||||
file = NULL;
|
file = NULL;
|
||||||
@@ -41,8 +53,6 @@ AudioGeneratorMP3::AudioGeneratorMP3(void *space, int size)
|
|||||||
buff = NULL;
|
buff = NULL;
|
||||||
nsCountMax = 1152/32;
|
nsCountMax = 1152/32;
|
||||||
madInitted = false;
|
madInitted = false;
|
||||||
preallocateSpace = space;
|
|
||||||
preallocateSize = size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudioGeneratorMP3::~AudioGeneratorMP3()
|
AudioGeneratorMP3::~AudioGeneratorMP3()
|
||||||
@@ -109,7 +119,12 @@ enum mad_flow AudioGeneratorMP3::Input()
|
|||||||
|
|
||||||
if (stream->next_frame) {
|
if (stream->next_frame) {
|
||||||
unused = lastBuffLen - (stream->next_frame - buff);
|
unused = lastBuffLen - (stream->next_frame - buff);
|
||||||
memmove(buff, stream->next_frame, unused);
|
if (unused < 0) {
|
||||||
|
desync();
|
||||||
|
unused = 0;
|
||||||
|
} else {
|
||||||
|
memmove(buff, stream->next_frame, unused);
|
||||||
|
}
|
||||||
stream->next_frame = NULL;
|
stream->next_frame = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,6 +140,10 @@ enum mad_flow AudioGeneratorMP3::Input()
|
|||||||
// Can't read any from the file, and we don't have anything left. It's done....
|
// Can't read any from the file, and we don't have anything left. It's done....
|
||||||
return MAD_FLOW_STOP;
|
return MAD_FLOW_STOP;
|
||||||
}
|
}
|
||||||
|
if (len < 0) {
|
||||||
|
desync();
|
||||||
|
unused = 0;
|
||||||
|
}
|
||||||
|
|
||||||
lastBuffLen = len + unused;
|
lastBuffLen = len + unused;
|
||||||
mad_stream_buffer(stream, buff, lastBuffLen);
|
mad_stream_buffer(stream, buff, lastBuffLen);
|
||||||
@@ -132,6 +151,16 @@ enum mad_flow AudioGeneratorMP3::Input()
|
|||||||
return MAD_FLOW_CONTINUE;
|
return MAD_FLOW_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudioGeneratorMP3::desync ()
|
||||||
|
{
|
||||||
|
audioLogger->printf_P(PSTR("MP3:desync\n"));
|
||||||
|
if (stream) {
|
||||||
|
stream->next_frame = nullptr;
|
||||||
|
stream->this_frame = nullptr;
|
||||||
|
stream->sync = 0;
|
||||||
|
}
|
||||||
|
lastBuffLen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool AudioGeneratorMP3::DecodeNextFrame()
|
bool AudioGeneratorMP3::DecodeNextFrame()
|
||||||
{
|
{
|
||||||
@@ -196,6 +225,17 @@ retry:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!DecodeNextFrame()) {
|
if (!DecodeNextFrame()) {
|
||||||
|
if (stream->error == MAD_ERROR_BUFLEN) {
|
||||||
|
// randomly seeking can lead to endless
|
||||||
|
// and unrecoverable "MAD_ERROR_BUFLEN" loop
|
||||||
|
audioLogger->printf_P(PSTR("MP3:ERROR_BUFLEN %d\n"), unrecoverable);
|
||||||
|
if (++unrecoverable >= 3) {
|
||||||
|
unrecoverable = 0;
|
||||||
|
return (running = false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
unrecoverable = 0;
|
||||||
|
}
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
samplePtr = 9999;
|
samplePtr = 9999;
|
||||||
@@ -243,16 +283,32 @@ bool AudioGeneratorMP3::begin(AudioFileSource *source, AudioOutput *output)
|
|||||||
lastBuffLen = 0;
|
lastBuffLen = 0;
|
||||||
|
|
||||||
// Allocate all large memory chunks
|
// Allocate all large memory chunks
|
||||||
if (preallocateSpace) {
|
if (preallocateStreamSize + preallocateFrameSize + preallocateSynthSize) {
|
||||||
|
if (preallocateSize >= preAllocBuffSize() &&
|
||||||
|
preallocateStreamSize >= preAllocStreamSize() &&
|
||||||
|
preallocateFrameSize >= preAllocFrameSize() &&
|
||||||
|
preallocateSynthSize >= preAllocSynthSize()) {
|
||||||
|
buff = reinterpret_cast<unsigned char *>(preallocateSpace);
|
||||||
|
stream = reinterpret_cast<struct mad_stream *>(preallocateStreamSpace);
|
||||||
|
frame = reinterpret_cast<struct mad_frame *>(preallocateFrameSpace);
|
||||||
|
synth = reinterpret_cast<struct mad_synth *>(preallocateSynthSpace);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
audioLogger->printf_P("OOM error in MP3: Want %d/%d/%d/%d bytes, have %d/%d/%d/%d bytes preallocated.\n",
|
||||||
|
preAllocBuffSize(), preAllocStreamSize(), preAllocFrameSize(), preAllocSynthSize(),
|
||||||
|
preallocateSize, preallocateStreamSize, preallocateFrameSize, preallocateSynthSize);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (preallocateSpace) {
|
||||||
uint8_t *p = reinterpret_cast<uint8_t *>(preallocateSpace);
|
uint8_t *p = reinterpret_cast<uint8_t *>(preallocateSpace);
|
||||||
buff = reinterpret_cast<unsigned char *>(p);
|
buff = reinterpret_cast<unsigned char *>(p);
|
||||||
p += (buffLen+7) & ~7;
|
p += preAllocBuffSize();
|
||||||
stream = reinterpret_cast<struct mad_stream *>(p);
|
stream = reinterpret_cast<struct mad_stream *>(p);
|
||||||
p += (sizeof(struct mad_stream)+7) & ~7;
|
p += preAllocStreamSize();
|
||||||
frame = reinterpret_cast<struct mad_frame *>(p);
|
frame = reinterpret_cast<struct mad_frame *>(p);
|
||||||
p += (sizeof(struct mad_frame)+7) & ~7;
|
p += preAllocFrameSize();
|
||||||
synth = reinterpret_cast<struct mad_synth *>(p);
|
synth = reinterpret_cast<struct mad_synth *>(p);
|
||||||
p += (sizeof(struct mad_synth)+7) & ~7;
|
p += preAllocSynthSize();
|
||||||
int neededBytes = p - reinterpret_cast<uint8_t *>(preallocateSpace);
|
int neededBytes = p - reinterpret_cast<uint8_t *>(preallocateSpace);
|
||||||
if (neededBytes > preallocateSize) {
|
if (neededBytes > preallocateSize) {
|
||||||
audioLogger->printf_P("OOM error in MP3: Want %d bytes, have %d bytes preallocated.\n", neededBytes, preallocateSize);
|
audioLogger->printf_P("OOM error in MP3: Want %d bytes, have %d bytes preallocated.\n", neededBytes, preallocateSize);
|
||||||
@@ -302,7 +358,7 @@ extern "C" {
|
|||||||
{
|
{
|
||||||
return 8192;
|
return 8192;
|
||||||
}
|
}
|
||||||
#elif defined(ESP8266)
|
#elif defined(ESP8266) && !defined(CORE_MOCK)
|
||||||
#include <cont.h>
|
#include <cont.h>
|
||||||
extern cont_t g_cont;
|
extern cont_t g_cont;
|
||||||
|
|
||||||
|
|||||||
+21
-5
@@ -30,17 +30,31 @@ class AudioGeneratorMP3 : public AudioGenerator
|
|||||||
public:
|
public:
|
||||||
AudioGeneratorMP3();
|
AudioGeneratorMP3();
|
||||||
AudioGeneratorMP3(void *preallocateSpace, int preallocateSize);
|
AudioGeneratorMP3(void *preallocateSpace, int preallocateSize);
|
||||||
|
AudioGeneratorMP3(void *buff, int buffSize, void *stream, int streamSize, void *frame, int frameSize, void *synth, int synthSize);
|
||||||
virtual ~AudioGeneratorMP3() override;
|
virtual ~AudioGeneratorMP3() override;
|
||||||
virtual bool begin(AudioFileSource *source, AudioOutput *output) override;
|
virtual bool begin(AudioFileSource *source, AudioOutput *output) override;
|
||||||
virtual bool loop() override;
|
virtual bool loop() override;
|
||||||
virtual bool stop() override;
|
virtual bool stop() override;
|
||||||
virtual bool isRunning() override;
|
virtual bool isRunning() override;
|
||||||
|
virtual void desync () override;
|
||||||
protected:
|
|
||||||
void *preallocateSpace;
|
|
||||||
int preallocateSize;
|
|
||||||
|
|
||||||
const int buffLen = 0x600; // Slightly larger than largest MP3 frame
|
static constexpr int preAllocSize () { return preAllocBuffSize() + preAllocStreamSize() + preAllocFrameSize() + preAllocSynthSize(); }
|
||||||
|
static constexpr int preAllocBuffSize () { return ((buffLen + 7) & ~7); }
|
||||||
|
static constexpr int preAllocStreamSize () { return ((sizeof(struct mad_stream) + 7) & ~7); }
|
||||||
|
static constexpr int preAllocFrameSize () { return (sizeof(struct mad_frame) + 7) & ~7; }
|
||||||
|
static constexpr int preAllocSynthSize () { return (sizeof(struct mad_synth) + 7) & ~7; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void *preallocateSpace = nullptr;
|
||||||
|
int preallocateSize = 0;
|
||||||
|
void *preallocateStreamSpace = nullptr;
|
||||||
|
int preallocateStreamSize = 0;
|
||||||
|
void *preallocateFrameSpace = nullptr;
|
||||||
|
int preallocateFrameSize = 0;
|
||||||
|
void *preallocateSynthSpace = nullptr;
|
||||||
|
int preallocateSynthSize = 0;
|
||||||
|
|
||||||
|
static constexpr int buffLen = 0x600; // Slightly larger than largest MP3 frame
|
||||||
unsigned char *buff;
|
unsigned char *buff;
|
||||||
int lastReadPos;
|
int lastReadPos;
|
||||||
int lastBuffLen;
|
int lastBuffLen;
|
||||||
@@ -62,6 +76,8 @@ class AudioGeneratorMP3 : public AudioGenerator
|
|||||||
bool DecodeNextFrame();
|
bool DecodeNextFrame();
|
||||||
bool GetOneSample(int16_t sample[2]);
|
bool GetOneSample(int16_t sample[2]);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int unrecoverable = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -121,6 +121,8 @@ struct FLAC__BitReader {
|
|||||||
void *client_data;
|
void *client_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||||
static inline void crc16_update_word_(FLAC__BitReader *br, brword word)
|
static inline void crc16_update_word_(FLAC__BitReader *br, brword word)
|
||||||
{
|
{
|
||||||
unsigned crc = br->read_crc16;
|
unsigned crc = br->read_crc16;
|
||||||
@@ -149,6 +151,7 @@ static inline void crc16_update_word_(FLAC__BitReader *br, brword word)
|
|||||||
#endif
|
#endif
|
||||||
br->crc16_align = 0;
|
br->crc16_align = 0;
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
static FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
|
static FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
|
||||||
{
|
{
|
||||||
@@ -338,6 +341,8 @@ void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
|
|||||||
br->crc16_align = br->consumed_bits;
|
br->crc16_align = br->consumed_bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||||
FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
|
FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
|
||||||
{
|
{
|
||||||
FLAC__ASSERT(0 != br);
|
FLAC__ASSERT(0 != br);
|
||||||
@@ -353,6 +358,7 @@ FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
|
|||||||
}
|
}
|
||||||
return br->read_crc16;
|
return br->read_crc16;
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
inline FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
|
inline FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
|
||||||
{
|
{
|
||||||
|
|||||||
+3
-1
@@ -136,7 +136,8 @@ FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
|
|||||||
|
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||||
unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
|
unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
|
||||||
{
|
{
|
||||||
unsigned crc = 0;
|
unsigned crc = 0;
|
||||||
@@ -146,3 +147,4 @@ unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
|
|||||||
|
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
@@ -2021,6 +2021,8 @@ FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||||
FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
|
FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
|
||||||
{
|
{
|
||||||
uint32_t channel;
|
uint32_t channel;
|
||||||
@@ -2167,6 +2169,7 @@ FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FL
|
|||||||
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
|
decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
|
FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -486,16 +486,17 @@ struct tsf_stream_memory { const char* buffer; unsigned int total, pos; };
|
|||||||
static int tsf_stream_memory_read(struct tsf_stream_memory* m, void* ptr, unsigned int size) { if (size > m->total - m->pos) size = m->total - m->pos; TSF_MEMCPY(ptr, m->buffer+m->pos, size); m->pos += size; return size; }
|
static int tsf_stream_memory_read(struct tsf_stream_memory* m, void* ptr, unsigned int size) { if (size > m->total - m->pos) size = m->total - m->pos; TSF_MEMCPY(ptr, m->buffer+m->pos, size); m->pos += size; return size; }
|
||||||
static int tsf_stream_memory_tell(struct tsf_stream_memory* m) { return m->pos; }
|
static int tsf_stream_memory_tell(struct tsf_stream_memory* m) { return m->pos; }
|
||||||
static int tsf_stream_memory_size(struct tsf_stream_memory* m) { return m->total; }
|
static int tsf_stream_memory_size(struct tsf_stream_memory* m) { return m->total; }
|
||||||
static int tsf_stream_memory_skip(struct tsf_stream_memory* m, unsigned int count) { if (m->pos + count > m->total) return 0; m->pos += count; return 1; }
|
static int tsf_stream_memory_skip(struct tsf_stream_memory* m, unsigned int count) { if (m->pos + count > m->total) count = m->total - m->pos; m->pos += count; return 1; }
|
||||||
static int tsf_stream_memory_seek(struct tsf_stream_memory* m, unsigned int pos) { if (pos > m->total) return 0; else m->pos = pos; return 1; }
|
static int tsf_stream_memory_seek(struct tsf_stream_memory* m, unsigned int pos) { if (pos > m->total) return 0; else m->pos = pos; return 1; }
|
||||||
static int tsf_stream_memory_close(struct tsf_stream_memory* m) { (void)m; return 1; }
|
static int tsf_stream_memory_close(struct tsf_stream_memory* m) { TSF_FREE(m); return 1; }
|
||||||
TSFDEF tsf* tsf_load_memory(const void* buffer, int size)
|
TSFDEF tsf* tsf_load_memory(const void* buffer, int size)
|
||||||
{
|
{
|
||||||
struct tsf_stream stream = { TSF_NULL, (int(*)(void*,void*,unsigned int))&tsf_stream_memory_read, (int(*)(void*))&tsf_stream_memory_tell, (int(*)(void*,unsigned int))&tsf_stream_memory_skip, (int(*)(void*,unsigned int))&tsf_stream_memory_seek, (int(*)(void*))&tsf_stream_memory_close, (int(*)(void*))&tsf_stream_memory_size };
|
struct tsf_stream stream = { TSF_NULL, (int(*)(void*,void*,unsigned int))&tsf_stream_memory_read, (int(*)(void*))&tsf_stream_memory_tell, (int(*)(void*,unsigned int))&tsf_stream_memory_skip, (int(*)(void*,unsigned int))&tsf_stream_memory_seek, (int(*)(void*))&tsf_stream_memory_close, (int(*)(void*))&tsf_stream_memory_size };
|
||||||
struct tsf_stream_memory f = { 0, 0, 0 };
|
struct tsf_stream_memory* f = (struct tsf_stream_memory*)TSF_MALLOC(sizeof(struct tsf_stream_memory));
|
||||||
f.buffer = (const char*)buffer;
|
f->pos = 0;
|
||||||
f.total = size;
|
f->buffer = (const char*)buffer;
|
||||||
stream.data = &f;
|
f->total = size;
|
||||||
|
stream.data = f;
|
||||||
return tsf_load(&stream);
|
return tsf_load(&stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-2
@@ -73,12 +73,17 @@ libopus=../../src/libopus/opus_decoder.c ../../src/libopus/opus_projection_decod
|
|||||||
|
|
||||||
opusfile=../../src/opusfile/opusfile.c ../../src/opusfile/stream.c ../../src/opusfile/internal.c ../../src/opusfile/info.c
|
opusfile=../../src/opusfile/opusfile.c ../../src/opusfile/stream.c ../../src/opusfile/internal.c ../../src/opusfile/info.c
|
||||||
|
|
||||||
|
libflac=../../src/libflac/md5.c ../../src/libflac/window.c ../../src/libflac/memory.c ../../src/libflac/cpu.c \
|
||||||
|
../../src/libflac/fixed.c ../../src/libflac/format.c ../../src/libflac/lpc.c ../../src/libflac/crc.c \
|
||||||
|
../../src/libflac/bitreader.c ../../src/libflac/bitmath.c ../../src/libflac/stream_decoder.c ../../src/libflac/float.c
|
||||||
|
|
||||||
|
|
||||||
CCOPTS=-g -Wunused-parameter -Wall -m32 -include Arduino.h
|
CCOPTS=-g -Wunused-parameter -Wall -m32 -include Arduino.h
|
||||||
CPPOPTS=-g -Wunused-parameter -Wall -std=c++11 -m32 -include Arduino.h
|
CPPOPTS=-g -Wunused-parameter -Wall -std=c++11 -m32 -include Arduino.h
|
||||||
|
|
||||||
.phony: all
|
.phony: all
|
||||||
|
|
||||||
all: mp3 aac wav midi opus
|
all: mp3 aac wav midi opus flac
|
||||||
|
|
||||||
mp3: FORCE
|
mp3: FORCE
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
@@ -94,6 +99,13 @@ aac: FORCE
|
|||||||
rm -f *.o
|
rm -f *.o
|
||||||
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./aac
|
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./aac
|
||||||
|
|
||||||
|
flac: FORCE
|
||||||
|
rm -f *.o
|
||||||
|
gcc $(CCOPTS) -DUSE_DEFAULT_STDLIB -c $(libflac) -I ../../src/ -I ../../src/libflac -I.
|
||||||
|
g++ $(CPPOPTS) -o flac flac.cpp Serial.cpp *.o ../../src/AudioFileSourceSTDIO.cpp ../../src/AudioOutputSTDIO.cpp ../../src/AudioFileSourceID3.cpp ../../src/AudioGeneratorFLAC.cpp ../../src/AudioLogger.cpp -I ../../src/ -I.
|
||||||
|
rm -f *.o
|
||||||
|
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./flac
|
||||||
|
|
||||||
wav: FORCE
|
wav: FORCE
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
g++ $(CPPOPTS) -o wav wav.cpp Serial.cpp ../../src/AudioFileSourceSTDIO.cpp ../../src/AudioOutputSTDIO.cpp ../../src/AudioGeneratorWAV.cpp ../../src/AudioLogger.cpp -I ../../src/ -I.
|
g++ $(CPPOPTS) -o wav wav.cpp Serial.cpp ../../src/AudioFileSourceSTDIO.cpp ../../src/AudioOutputSTDIO.cpp ../../src/AudioGeneratorWAV.cpp ../../src/AudioLogger.cpp -I ../../src/ -I.
|
||||||
@@ -116,6 +128,6 @@ opus: FORCE
|
|||||||
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./opus
|
echo valgrind --leak-check=full --track-origins=yes -v --error-limit=no --show-leak-kinds=all ./opus
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f mp3 aac wav midi opus *.o
|
rm -f mp3 aac wav midi opus flac *.o
|
||||||
|
|
||||||
FORCE:
|
FORCE:
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include "AudioFileSourceSTDIO.h"
|
||||||
|
#include "AudioOutputSTDIO.h"
|
||||||
|
#include "AudioGeneratorFLAC.h"
|
||||||
|
|
||||||
|
#define AAC "gs-16b-2c-44100hz.flac"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
(void) argc;
|
||||||
|
(void) argv;
|
||||||
|
AudioFileSourceSTDIO *in = new AudioFileSourceSTDIO(AAC);
|
||||||
|
AudioOutputSTDIO *out = new AudioOutputSTDIO();
|
||||||
|
out->SetFilename("out.flac.wav");
|
||||||
|
AudioGeneratorFLAC *flac = new AudioGeneratorFLAC();
|
||||||
|
|
||||||
|
flac->begin(in, out);
|
||||||
|
while (flac->loop()) { /*noop*/ }
|
||||||
|
flac->stop();
|
||||||
|
|
||||||
|
delete flac;
|
||||||
|
delete out;
|
||||||
|
delete in;
|
||||||
|
}
|
||||||
Binary file not shown.
Reference in new issue
Block a user