Commit Graph
59 Commits
Author SHA1 Message Date
Earle F. Philhower, III 9c120a777a Add callbacks for metadata and status reports
All objects can have a metadata and/or status report callback once created.
They will call the source program with the parsed ID3 tag, ICY StreamTitle,
or text and numeric error ID of any interesting event.  It is up to the end
application to figure out what to do with this.  Normally, you'd just print
it to the LCD or Serial port.  But it is possible to detect, say, a buffer
overflow and then switch to a lower bitrate stream for example.
2017-12-06 21:11:23 -08:00
Earle F. Philhower, III 1ab9348a4c Update the instructions for installation
The library will not compile w/o the SPI driver, add it to the README.
Point to my fork until @armSeb's pull request in the original is merged.
2017-12-06 14:20:39 -08:00
armSeb 97c05c9f34 SPIRAM buffer support from @armSeb
* Initial SPIRAM buffering support

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* SPI RAM Buffering fill & read.

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* First "working" version...

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* Improved version of SPIRAM buffering

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>

* Fixed spiram.h path

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>

* Buffer fill optimization

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>

* Modified read block min to avoid too little buffering attempts

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>

* Temps buffer size decrease from 2048 to 1600 Bytes

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>

* Decrease the temp buffer to 256Bytes

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>

* Local buffer variable

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>

* Added loop function to SPIRAMBuffer that refill it automatically

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* Compile issue

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* Add possibility to define Chip Select pin from Sketch

Signed-off-by: Sebastien Decourriere <sebtx452@gmail.com>

* Externalize libspiram

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* Copyright fix

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* Deleted embedded libspiram

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* Added comments, example and keyword

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* README modification

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* Correction

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* Schema example

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>

* README correction

Signed-off-by: sebastien <armseb@MacBook-de-sebastien.local>
2017-12-06 13:30:51 -08:00
Earle F. Philhower, III 471034707d Add ICY Metadata callback to the example 2017-12-04 12:53:58 -08:00
Earle F. Philhower, III 3226d6ec0a Add metadta callback for Icy streams
Allow a UI to get a notification when a StreamTitle or other metadata
comes into the stream. Callback function would normally just update a
flag and let the next global event loop handle updating the display.
2017-12-04 12:45:16 -08:00
Earle F. Philhower, III 8c6bb549f1 Fix crash on ::loop in MIDI generator
Forgot to save the passed in *AudioFileSource, since it was not needed
in the MIDI playback engine (it's encapsulated in a buffered object).  Now
with ::loop in every object, it's needed and we were calling a garbage
object causing a random crash.
2017-12-04 10:51:20 -08:00
Earle F. Philhower, III 75268b5e3b Add inline ID3 decoder w/callback interface
ID3 tags can now automatically give your app a callback with different tag
types without any additional work on your application.  See the PlayMP3 example
for a very simple example of AudioFileSourceID3's use.
2017-12-02 13:01:46 -08:00
Earle F. Philhower, III fece88a9be Add loop method to all input and outputs
Adds a virtual loop() method to the file input and audio output objects.
By default does nothing, but it can be used to prefill buffers/etc. in the
case of a buffered input, or to update a volume meter on an output, etc.

The AudioGenerators all now call it as part of their own loop()s, so there
is no user intervention required to make it work.

Thanks to @armSeb for the idea with his SPI RAM code.
2017-11-24 10:35:20 -08:00
Earle F. Philhower, III df4588197f Add note about SBR not being supported due to RAM 2017-11-23 20:01:38 -08:00
Earle F. Philhower, III 373b4ef6ff Move a few small tables into PROGMEM
No reason not to save a few bytes of RAM by moving some char[] to PROGMEM.
2017-11-23 19:31:39 -08:00
Earle F. Philhower, III 1875683ce1 Add SBR code back in, but disable for now.
The SBR code compiles, but it requires an additional 50,788 bytes of system
RAM to run so it's not going to work on the ESP8266.  Add the code in just in
case someone wants to move it to another architecture w/more RAM available.
2017-11-23 19:04:30 -08:00
Earle F. Philhower, III 432f892d70 Add retry logic to HTTP Streams
On a 0-byte read or a disconnect, optionally automatically reconnect
up to a user specified number of tries with a delay between each attempt.
2017-11-22 07:20:42 -08:00
Earle F. Philhower, III 2737dec473 Fix block corruption when hitting an ICY block
Wasn't incrementing the returned data pointer when we had to split the
requested read into pre- and post-ICY blocks.  This resulted in errors
in the decoded stream.
2017-11-21 20:09:37 -08:00
Earle F. Philhower, III 4b2bbe7ad5 Preliminary ICY HTTP stream support
Add a subclass of the HTTPStream that can extract the ICY metadata.
Needs to implement a callback function or parse it internally and expose
a class variable to let the UI see the current stream information.
2017-11-21 11:55:23 -08:00
Earle F. Philhower, III 64032d8f43 Force refill of buffer when emptied completely
@armSeb founf another case in issue #9 where the buffer would never
refill if the input stream was very slightly below the output stream
velocity.  In that case, when we hit a 0-water mark, force a complete
refill of the buffer on the next pass.
2017-11-21 08:36:17 -08:00
Earle F. Philhower, III fad8af052f Reduce default MP3 buffer to max frame size + fluff
MP3 maximum frame size of 1441 bytes, and now that there is a real
buffering class available it makes no sense to include additional space
in ths decoder.  Reduce to the minimum to save memory in default case.
2017-11-21 08:11:05 -08:00
Earle F. Philhower, III 09b8079ef7 Add FIR and decimation filter for frequency xvert
A simple FIR filter with decimation and specifable taps and rational
decimation allows for frequency conversion or any other kind of filtering
desired.
2017-11-21 07:45:02 -08:00
Earle F. Philhower, III 9c3f579c96 Add buffering to MP3 streaming
The buffer class seems to work very well to avoid hiccups while
streaming from the web, so add it by default to the example to
make it easier for users to cut-n-paste and make it work.
2017-11-20 12:15:32 -08:00
Earle F. Philhower, III 8b080899af Fix buffer example snippet to actually work
@gerardwr found that the cut-n-pasted original example code could never
actually work, in issue 9.  Rewrite so instead of a full working sample
(which would be 40+ lines due to WiFi setup) only the relevant changes are
shown.
2017-11-20 07:11:17 -08:00
Earle F. Philhower, III 860c6678ab Fix noise during amplification
@armSeb, in issue 7, noticed noise being introduced when amplifying the
output.  By moving the amplification to right before submitting the sample
to I2S it went away.  Update with his suggested fix.
2017-11-20 07:04:11 -08:00
Earle F. Philhower, III 8a19c9c093 Fix buffering losing bytes
Correct issue @armSeb found and fixed where some bytes on the fallthrough
case were not being recorded as stored, leading to mp3 playback errors.
Fixes one half of issue 7.
2017-11-20 06:59:57 -08:00
Earle F. Philhower, III 3f7cf95a15 Save 88 bytes by moving a table to PROGMEM 2017-11-18 19:15:46 -08:00
Earle F. Philhower, III d723b36aca Free 188 bytes of RAM by moving bitrevtab to PMEM 2017-11-18 19:12:24 -08:00
Earle F. Philhower, III fdffe0226e Fix typos and add links to other projects 2017-11-18 19:04:33 -08:00
Earle F. Philhower, III f4702a0719 Remove GCC -Wall warnings
Clear up warnings generated with -Wall used to compile.  No functional change.
2017-11-18 18:53:58 -08:00
Earle F. Philhower, III 5e5a15359c Remove the FastROMFS bits for now
Having the FastROMFS file source caused the importation of the entire
FastROMFS library, which most folks will not have installed.  Remove it
for now.
2017-11-18 08:45:48 -08:00
Earle F. Philhower, III 551a8ac0bb Add AAC playback using Helix from RealNetworks
AACs can now be played back on the ESP8266 thanks to the RealNetworks
Helix project's AAC decoder.  SBR is *not* supported, as there is not
enough RAM in the system to support it.
2017-11-18 08:42:09 -08:00
Earle F. Philhower, III 14010d340e Add SetGain to I2S outputs to scale output volume
A new SetGain(float 0.0 ... 4.0) method can scale the output volume of
an I2S DAC or SW DAC by scaling the samples. Proper clipping is performed.
Adds a 16x16 multiply and a couple shifts/branches to every sample output.
2017-11-17 08:48:19 -08:00
Earle F. Philhower, III 65c1373300 Less naive double-buffer reading
Use memcpy instead of complicated byte-by-byte operations to read data
out of the buffer.  Should allow for somewhat faster reads.
2017-11-15 13:17:43 -08:00
Earle F. Philhower, III 07531b905e Turn on O3 optimization on the buffer filter 2017-11-15 07:14:27 -08:00
Earle F. Philhower, III 545127558f Handle OOM in note_on without SEGV
When note_on tries to reallocate the voices[] array, realloc can return
NULL.  In this case, instead of faulting, restore the original pointer
(which is untouched per realloc() semantics) and ignore the note_on
command.
2017-11-14 15:11:59 -08:00
Earle F. Philhower, III f7b6f90ffe Fix unitialized MONO flag
MONO was not set and could result (randomly at start of runtime) in
mixing the two channels instead of sending them across unmolested.
Now initialize it to FALSE and normal behaviour.
2017-11-14 13:32:55 -08:00
Earle F. Philhower, III c669a329c4 Add double-buffer input file source
AudioFileSourceBuffer allows system RAM to be used to buffer an
input file (normally just a HTTP Stream) to help avoid hiccups.
This could also be subclassed to use an external SRAM, at some
soint.
2017-11-14 07:08:45 -08:00
Earle F. Philhower, III f61fcb80f8 Call StopMIDI on ::stop() invocation to free mem 2017-10-30 20:58:54 -07:00
Earle F. Philhower, III 4b52ce7397 Fix meta_len MIDI entry parsing
meta_length is a varlen, not a single byte.  Use get_varlen() to handle
>127 byte entries automatically.
2017-10-30 20:08:23 -07:00
Earle F. Philhower, III e11da8c325 MIDI + Soundfont wavetable synthesis capability
AudioGeneratorMIDI plays a .MID file using any Soundfont2 wavetable
synthesis file.  This is a highly hacked combination of TinySoundFont
and MIDITONES, and requires the FastROMFS to run at real-time in most
cases.
2017-10-29 17:43:00 -07:00
Earle F. Philhower, III bf4f3d3257 Add double buffer and FastROMFS classes
AudioFileSourceFastROMFS connects with the new FastROMFS to enable
higher speed read from SPI flash for files.  Requires
https://github.com/earlephilhower/ESP8266FastROMFS to be installed.

AudioOutputBuffer implements a 2nd-level memory buffer for output
dat to hopefully allow playback w/o hiccups, but needs to be vetted.
Without being able to call it from an interrupt, not sure it can actually
improve output performance.
2017-10-27 21:14:14 -07:00
Earle F. Philhower, III c5da8c3062 Add timeout and HTTP size to streamer EOF checks
HTTPStreamer assumed the server would drop the connection when no more
data was available to be transferred from the source file.
For individual files, though, the web server will send the expected length
in the headers and leave the connection open (i.e. to recycle the connection
and accelerate web browsing).  In this case, the streamer would effectively
hang waiting for more data than was being transmitted.

Now check the read data against the expected data, and also add a 0.5s
timeout no matter what to the reading.

Tested on streaming and served files, seems to work fine.
2017-10-22 10:04:19 -07:00
Earle F. Philhower, III 2dac08ef4e Fix mono MP3 decoding causing choppy output
Fixes issue #5 about choppy audio on low bitrate, mono MP3s.

The number of 32-sample elements to generate per MP3 data frame was
set to 36 as that was what I saw on all my source files.  However, on
mono files only half the number of samples are to be generated and
you'd end up with the synthesizer bands running out of energy and
have periods of 0-samples between proper data.

Now simply check each decoded frame for the proper NSMAX value and
only generate that many.  Tested on force.mp3 in the issue referenced.
2017-10-21 21:15:59 -07:00
Earle F. Philhower, III 047fef2678 Add SPIFFS file output option
AudioOutputSPIFFSWAV writes a valid WAV file to the SPIFFS filesystem.
Be sure to do a SPIFFS.start() or .format before calling any output.
Set the filename using the additional ->SetFilename() call.
2017-10-05 19:04:40 -07:00
Earle F. Philhower, III 199e00d73a Update the library descriptions properly. 2017-10-02 11:09:20 -07:00
Earle F. Philhower, III 7b89388008 Minor note about WEMOS SD card shield 2017-09-29 06:58:03 -07:00
Earle F. Philhower, III ddb47b29c1 Explicitly call out path to config.h
Under Windows it seems that the Arduino compilation can't find
<config.h> from inside a subdirectory.  So just point explicitly to
"../config.h" for includes in subdirs.
2017-09-28 12:01:41 -07:00
Earle F. Philhower, III cf0d5f298e Add classes to syntax hilighter 2017-09-06 12:12:22 -07:00
Earle F. Philhower, III 92120b317a Add shifting for 24- and 32-bit audio output
Right-shift appropriate # of bits for the higher bit depths.
2017-08-18 13:44:23 -07:00
Earle F. Philhower, III d0411c8b6e Add -O3 optimization to all C files
Arduino normally builds with -Os (optimize for size). For audio decode
we'd rather go fast, so add pragma inside files.
2017-08-18 13:10:53 -07:00
Earle F. Philhower, III d436a4ba7b Clean up headers and remove unneeded source files
Remove STDIO/FILE references from code and headers.  Remove any header
files not needed to support stread_decoder playback.
2017-08-18 13:07:23 -07:00
Earle F. Philhower, III c8af3b5d7b Fix header paths to not need symlinks
The FLAC makefile has additional -I include paths which let them use
files in other directories without path specifiers.  Arduino doesn't
support this, so while my development system was using symlinks, this
would not work well under Windows.  Instead, simply add proper path
specifiers to includes in other directories.
2017-08-18 11:50:42 -07:00
Earle F. Philhower, III 443979673f Add SD card file input class 2017-08-18 08:18:22 -07:00
Earle F. Philhower, III 685dcbf18d Add FLAC support to the framework via libflac-1.3.2
Ported libFLAC v1.3.2 to the ESP8266.  Moved CRC constants to PROGMEM
and the error strings.  Still to be done would be decreasing the output
buffer to an int16_t and moving a larce number of "const int" to enums
since "const int" eats 4 bytes per variable.
2017-08-17 18:25:04 -07:00