Commit Graph
21 Commits
Author SHA1 Message Date
Earle F. Philhower, III 8ffebe6496 Enable static allocated buffers, no dynamic malloc
Because we are allocating objects totaling over 80% of the ESP8266 memory
space, we are very sensitive to memory fragmentation.  While we can control
our own allocs, the IP and SDK can allocate any size, at any time, which
can cause us to not be able to find the large contiguous memory areas we need
for the codes.

Work around this by preallocating, before anything else, buffer memory and
never freeing it.  Pass this memory into the codec and it will allocate from
this block and be guaranteed to always succeed.

This may fix the last of the hangs on the webradio/http streaming, which only
seemed to happen after a stop/start cycle.
2018-01-21 13:02:05 -08:00
Earle F. Philhower, III f16cd2b269 Only mad_*_finish after a successful mad_*_start
When the input file(stream) doesn't open, you could end up calling
mp3::stop() which would try and mad_finish structures that were
not yet initialized.  Now carry a flag when these are set, and only
_finish when it's set.
2018-01-20 18:32:21 -08:00
Earle F. Philhower, III 07dee61fbf Merge branch 'hosttests' 2018-01-19 21:25:34 -08:00
Earle F. Philhower, III 0172f17b51 MP3 test in Valgrind
Run a host MP3 test using valgrind, shows no errors.
2018-01-19 21:23:17 -08:00
Earle F. Philhower, III da068e30e6 Ensure BPS=16 is set in MP3 decoder
Valgrind found another uninitialized use.  BitsPerSample was not being
called by the LIBMAD decoder, so it was possible to start out in a bad
state.  Now always set it to 16, the decoder native output size.

Channels are initialized to 2, but this setting is always reset on
a per-frame basis anyway.
2018-01-19 21:09:37 -08:00
Earle F. Philhower, III cffb424c2c WIP - build some code on the PC to run valgrind/etc. 2018-01-19 19:39:19 -08:00
tueddy 03aa2467f0 Porting for ESP-32 (#33)
* support ESP-32
* make compile with ESP-32/arduino platform
* fixed: use libmad on ESP8266 as original
2018-01-18 08:55:03 -08:00
Earle F. Philhower, III 025edf0d81 Clean up DecodeNextFrame path to something sane
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.
2017-12-24 09:20:01 -08:00
Earle F. Philhower, III 6c3064a4b5 Remove infinite loop on error in DecodeNextFrame
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
2017-12-22 21:19:06 -08:00
Earle F. Philhower, III d923ebef36 Move the callback constant strings to PMEM 2017-12-15 12:03:05 -08:00
Earle F. Philhower, III 634d0b8d02 Store AAC/MP3 flag in EEPROM for WebRadio 2017-12-15 10:31:19 -08:00
Earle F. Philhower, III 8d401a4a39 Move strings to PROGMEM, save a few heap bytes 2017-12-14 10:50:55 -08:00
Earle F. Philhower, III cce9ceaffd Try and allocate inner loop mem on stack
Check the available stack space, and if large enough use a stack
variable for the inner loop.  If not, fall back to heap allocation.
2017-12-12 16:57:20 -08:00
Earle F. Philhower, III 1690289714 Rationalize the MP3 generation loop
Remove the inInnerDecode flag in the main generation loop and make the
render path more readable in the MP3 decoder object.
2017-12-08 07:16:01 -08:00
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 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 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 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 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 0a453a077a Warning and static removal
Clean up compiler warnings and make static variables in class functions
into class variables where they belong.
2017-08-15 20:58:16 -07:00
Earle F. Philhower, III 2cf8fcef2a Bring in files from original projects
The library was originally part of several separate projects.  Make the
needed structure and bring those files in, including some READMEs.
2017-08-12 09:01:42 -07:00