Instead of ESP8266WebServer, which is something of a RAM hog and has
extensive use of Strings and allocations, use a simpler one with no
dynamic memory allocations at all, borrowed from PsychoPlug
https://github.com/earlephilhower/psychoplug.
Include the RealNetworks HELIX MP3 decoder as AudioGeneratorMP3a.
Right now runs fine, but requires a full 1152*2 sample buffer and
seems to run slower than real time.
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.
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.
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.
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.
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.
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.
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.
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.
@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.
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.
A simple FIR filter with decimation and specifable taps and rational
decimation allows for frequency conversion or any other kind of filtering
desired.
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.
@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.
@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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.