Because the mp3 player is a long living object and needs to allocate
large contiguous chunks on each frame, it is safer to allocate the
large xr[] and tmp[] arrays at the beginning. Add them to the frame
structure which lives the entire time the mp3 object is alive. No
heap allocations are now used by the mp3 player.
Move the imdct_s[] array to progmem, but do a memcpy_P() to stack
as the macros may cause a 16-bit access after optimization. It's only
36 words long and each data is read, anyway, so this doesn't increase
the CPU work significantly.
As seen in issue #21, the MP3 decoder would barf on a single lost sync
error, even though it was not actually a fatel error.
Rewrote the logic to include another Input() on DNF failure, and only die
when Input() actually fails. Seems to fix the problem in issue #21 and also
did not break the WebRadio.
The web interface has a hardcoded 64 char URL limit, even though the
actual url[] array was increased to 96 chars. Use sizeof(url) in the
handler instead of a hardcoded number to enable use of all space.
Addresses issue #21 , again.
The MD and STATUS callbacks can be passed PROGMEM strings, so be sure to
use proper strcpy_p()s to move them to RAM before printing to avoid crashes.
Found during debug of issue #21 .
DecodeNextFrame had a leftover while(1) in the inner loop without any
additional Input() calls, which could lead to an infinite loop on an
error condition. Remove that unneeded loop. Addresses some of the
stuff found in issue #21
Add handing of ID3V2.2.x (tested) and (I think) V2.3.x, and fix the
unsync handling.
Issue 23 found a problem where ID3V2.2 headers, which are very different
from v2.3 and v2.4, caused crashes. Fixing that showed another bug where
the unsyunc flag was not honored and all data was assumed to be unsync'd
causing improper reads of ID3 tags in some circumstances.
The ICYMDReader was not properly returning the unread "'" characters
and so StreamTitles were being truncated at the first apostrophe. Fix
the unread() and read() member functions to clean up.
EEPROM saving was not calculating the correct checksum because it was
not clearing memory before writing. Fix that so it automatically will
restart the connection on a reset.
There was a fatal corruption caused by improper delete'ing of objects
without clearing their pointers when the initial connection to a stream
failed. Refactor to use the proper StopPlaying() routine.
Extend the URL to 96 characters. We not have enough memory to do so!
@armSeb found that the stream interface caused a big slowdown and
hiccups in his playback, replace the MetadataCallback's *Stream with
a simple *char for faster operation and less overhead.
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.