Commit Graph

449 Commits

Author SHA1 Message Date
Scott Shawcroft 5e789b3850
Don't allocate the pre brightness buffer if brightness is 1.0 still 2020-01-27 15:10:32 -08:00
Scott Shawcroft 39971794dd
Encapsulate buffers inside PixelBuf and refactor it. 2020-01-24 18:23:07 -08:00
Lucian Copeland 70932cab42 Simplify the flash-display conflict fix 2020-01-24 14:33:28 -05:00
Lucian Copeland 2afca4e942 Fix flash-display conflict error 2020-01-24 14:25:36 -05:00
Jeff Epler b4ddee2bb6 Mixer: rename function based on review comment 2020-01-20 14:08:56 -06:00
Jeff Epler 982c63a717 Mixer: use MP_LIKELY macro instead of locally brewed one 2020-01-20 14:08:32 -06:00
Jeff Epler 449dbea456 Mixer: Rework for performance, particularly of the S16 case
This removes downscaling (halving-add) when multiple voices are
being mixed.  To avoid clipping, and get similar behavior to before,
set the "level" of each voice to (1/voice_count).

Slow paths that were applicable to only M0 chips were removed.

As a side effect, the internal volume representation is now 0 ..
0x8000 (inclusive), which additionally makes a level of exactly 0.5
representable.

Testing performed, on PyGamer: For all 4 data cases, for stereo and
mono, for 1 and 2 voices, play pure sign waves represented as
RawSamples and view the result on a scope and through headphones.
Also, scope the amount of time spent in background tasks.

Code size: growth of +272 bytes

Performance (time in background task when mixing 2 stereo 16-bit voices):
76us per down from 135us (once per ~2.9ms long term average)
(Decrease from 4.7% to 2.4% of all CPU time)
2020-01-16 10:48:38 -06:00
Jeff Epler e6869c8983 mixer: factor out mix_one_voice 2020-01-16 10:31:26 -06:00
Scott Shawcroft a10cd8580c
Merge pull request #2445 from jepler/mp3-jeplayer-fixes
Fixes for JEplayer
2020-01-08 12:50:13 -08:00
Jeff Epler dd6010a17e Fix more build problems 2020-01-06 13:35:43 -06:00
Jeff Epler dc729718eb audiomp3: rename to MP3Decoder 2020-01-06 07:51:41 -06:00
Jeff Epler ec22520992 MP3File: Add rms_level property
This lets a music player show it vu-meter style
2020-01-02 15:23:42 -06:00
Roy Hooper f1a9039632 Merge branch 'master' into pixelbuf-subscr-change 2019-12-29 13:56:31 -05:00
Jeff Epler 97bb46c047 MP3File: tweak buffer handling
After adding the ability to change files in an existing MP3File object,
it became apparent that at the beginning of a track some part of an
existing buffer was playing first.

I noticed that in get_buffer, the just-populated buffer wasn't being
returned, but the other one was.  But still after fixing this, I heard
wrong audio at the beginning of a track, so I took the heavy duty approach
and zeroed the buffers out.  That means there's a remaining bug to chase,
which is merely hidden by the memset()s.
2019-12-24 09:43:15 -06:00
Jeff Epler 00628a7ddd MP3File: whitespace 2019-12-23 09:36:50 -06:00
Jeff Epler 02154caf24 MP3File: Add a settable ".file" property
This enables jeplayer to allocate just one MP3File at startup, rather
than have to make repeated large allocations while the application is
running.

The buffers have to be allocated their theoretical maximum, but that
doesn't matter much as all the real-life MP3 files I checked needed
that much allocation anyway.
2019-12-23 09:36:46 -06:00
Jeff Epler a63da7a6c0 displayio: make 'rotation' property settable 2019-12-16 15:23:41 -06:00
Jeff Epler 91a1706160 MP3: look harder for frame info
Apparently sometimes, a proper "frame info" block is not found after
a "sync word".  Keep looking for one as needed, instead of giving up
after one try.

This was one reason that the "bartlebeats" mp3s would not play.
2019-12-13 18:31:12 -06:00
Jeff Epler bf9b7e7ece MP3: skip ID3V2 metadata
This was one reason that the "bartlebeats" mp3s would not play.
2019-12-13 18:31:12 -06:00
Jeff Epler a854a76819 audiocore: The arguments to reset_buffer went missing
In conversion I missed these arguments were being passed, but noticed
it when an implausible value for audio_channel was sent to mp3's
reset_buffer method.

It's not clear whether there was any negative impact to this, but it
should be fixed!
2019-12-13 18:31:12 -06:00
Roy Hooper dc8dd6df20 Revert subscr signature change 2019-12-13 14:29:15 -05:00
Roy Hooper 72ad2e9259 Merge branch 'master' into new-pixelbuf-api 2019-12-13 13:45:16 -05:00
Jeff Epler 1cdac3f16a MP3File: Fix stereo playback on samd AudioOut
There were several problems with the way this worked -- the read_count
approach was too complicated and I made a mistake "simplifying" it from
WaveFile.  And when the right channel was returned, it was off by 1 byte,
making it into static.

Instead, directly track which is the "other" channel that has data
available, and by using the right data type make the "+ channel"
arithmetic give the right result.

This requires a double cast (int16_t*)(void*) due to an alignment warning;
the alignment is now ensured manually, but the compiler doesn't make the
necessary inference that the low address bit must be clear.
2019-12-12 08:44:15 -06:00
Jeff Epler 8c841af946 MP3File: Avoid crash in get_buffer when deinitted
When a playing mp3 is deinitted, it's possible to reach get_buffer,
but all the internal pointers are NULL.  This would lead to a hard fault.
Avoid it by returning GET_BUFFER_ERROR instead.
2019-12-11 22:04:10 -06:00
Roy Hooper 0326c98fd5 Merge branch 'master' into new-pixelbuf-api 2019-12-10 20:44:43 -05:00
Roy Hooper 222dd29a14 Fix slice step. 2019-12-10 20:43:00 -05:00
Jeff Epler a08d9e6d8e audiocore: Add MP3File using Adafruit_MP3 library 2019-12-10 14:03:06 -06:00
Scott Shawcroft 19ac8aea8c
Merge pull request #2353 from jepler/audiosample-protocol
Convert audiosamples to use micropython "protocols" (safely)
2019-12-09 14:50:16 -08:00
Jeff Epler d5eca87ca2 audiocore: use mp_obj_t in prototypes 2019-12-06 13:25:40 -06:00
Jeff Epler 60f489d36a audiocore: restore the prototypes of audiosample_xxx functions 2019-12-05 13:08:32 -06:00
Hierophect ab74f45bfb Define polarity and phase in Fourwire 2019-12-05 11:44:21 -05:00
Jeff Epler feb8eb935b audiosample: convert to use a protocol
This eases addition of new sample sources, since the manual virtual
function dispatch functions are just calls via a protocol
2019-12-04 09:31:52 -06:00
Roy Hooper a4bbf35092 Merge branch 'master' into new-pixelbuf-api 2019-12-02 14:06:33 -05:00
Jeff Epler 95d9c49e43 Merge remote-tracking branch 'origin/master' into tick-refactor 2019-11-29 11:27:09 -06:00
Dan Halbert b32a9192df make UART.write be blocking on SAMD; add timeout property 2019-11-27 13:05:29 -05:00
Roy Hooper 56720eae0a remove unnecessary intermediate mp_obj_subscr wrapper 2019-11-26 18:39:08 -05:00
Scott Shawcroft d32dc814d3
Fix ePaper so it works after a GC.
We weren't correctly collecting the start and stop sequences. As
a result, the GC would free the space and allocate other info
there.

Thanks to JacobT on Discord for the bug report!
2019-11-26 12:48:36 -08:00
Roy Hooper 6108fa3766 Merge branch 'master' into new-pixelbuf-api 2019-11-23 12:22:04 -05:00
Jeff Epler 7f744a2369 Supervisor: move most of systick to the supervisor
This code is shared by most parts, except where not all the #ifdefs
inside the tick function were present in all ports.  This mostly would
have broken gamepad tick support on non-samd ports.

The "ms32" and "ms64" variants of the tick functions are introduced
because there is no 64-bit atomic read.  Disabling interrupts avoids
a low probability bug where milliseconds could be off by ~49.5 days
once every ~49.5 days (2^32 ms).

Avoiding disabling interrupts when only the low 32 bits are needed is a minor
optimization.

Testing performed: on metro m4 express, USB still works and
time.monotonic_ns() still counts up
2019-11-18 11:01:23 -06:00
Hierophect de5691acf5 Add never_reset and reset to pin common hal, adjust files 2019-11-15 12:47:00 -05:00
Melissa LeBlanc-Williams 39b38256fd Fixed I2CDisplay reset issue 2019-11-08 12:35:35 -08:00
Scott Shawcroft 47e50e5659
Merge remote-tracking branch 'adafruit/master' into bleio_tweaks 2019-11-01 13:20:58 -07:00
Dan Halbert d0044c74b6 bitbangio.SPI was not setting direction of output pins 2019-10-26 16:06:02 -04:00
Scott Shawcroft ece8352126
Fix build by removing unused vars 2019-10-22 17:24:04 -07:00
Scott Shawcroft ae30a1e5aa
Refine _bleio
This PR refines the _bleio API. It was originally motivated by
the addition of a new CircuitPython service that enables reading
and modifying files on the device. Moving the BLE lifecycle outside
of the VM motivated a number of changes to remove heap allocations
in some APIs.

It also motivated unifying connection initiation to the Adapter class
rather than the Central and Peripheral classes which have been removed.
Adapter now handles the GAP portion of BLE including advertising, which
has moved but is largely unchanged, and scanning, which has been enhanced
to return an iterator of filtered results.

Once a connection is created (either by us (aka Central) or a remote
device (aka Peripheral)) it is represented by a new Connection class.
This class knows the current connection state and can discover and
instantiate remote Services along with their Characteristics and
Descriptors.

Relates to #586
2019-10-21 18:57:03 -07:00
Roy Hooper 2970680e6a fix show and fix step > 1 2019-10-20 19:54:25 -04:00
Roy Hooper 1051001495 Merge branch 'master' into new-pixelbuf-api 2019-10-03 19:06:55 -04:00
jepler 523025ce8c Merge remote-tracking branch 'origin/master' into audio-stuttering-background 2019-09-12 20:45:59 -05:00
Scott Shawcroft 89fed709ad
Merge pull request #2127 from jepler/nrf-i2s
nrf: Add i2s audio output
2019-09-10 11:00:26 -07:00
Dan Halbert 2b560015c9
Merge pull request #2129 from jepler/audiomixer-debugging
audiomixer: Supply constants in a way "-Og" optimization expects
2019-09-09 22:43:49 -04:00
jepler 676f7aa808 os_listdir: This can be long-running, run background tasks
While finding sources of clicks and buzzes in nrf i2sout, I identified
this site as one which could be long running.  Reproducer code was to
play a 22.05kHz sample and repeatedly print `os.listdir('')`
2019-09-09 20:14:02 -05:00
Scott Shawcroft 6ad860a963
Merge pull request #2101 from matthewnewberg/display_io_dither
Add random dithering to ColorConverter
2019-09-09 10:11:07 -07:00
jepler 82427612d1 WaveFile: Return GET_BUFFER_ERROR if wrong amount read
Closes: #2128
2019-09-08 21:59:07 -05:00
jepler 8768896d6b audiomixer: Supply constants in a way "-Og" optimization expects
These arguments are constrained to be compile-time constants, a fact
that gcc complains about under "-Og" optimization, but not in normal
builds.  Declare them as enumerated types
2019-09-08 21:18:15 -05:00
Matthew Newberg 4604a69498 Move dither parameter to ColorConverter constructor and parameter 2019-09-05 21:55:45 -04:00
Dan Halbert f3af2a6fb7 Merge remote-tracking branch 'adafruit/master' into choose-usb-devices-xac 2019-09-04 21:56:13 -04:00
Matthew Newberg 3ab6a23434 Removed unused return value in displayio_colorconverter_convert 2019-09-04 20:42:24 -04:00
Dan Halbert fca440fb66
Merge pull request #2113 from tannewt/displayio_hidden
Add .hidden to TileGrid and Group
2019-09-04 15:48:00 -04:00
Scott Shawcroft 321b57a5d2
Merge pull request #2080 from sommersoft/mixer_voice
Add audiocore.MixerVoice
2019-09-04 12:46:59 -07:00
Scott Shawcroft 70407e4d87
Bitpack bools in TileGrid and Group 2019-09-04 10:27:21 -07:00
Radomir Dopieralski 5f6228b6f0 Fix transactions in _stage after displayio changes
Also, move the rendering setup code to shared-module from
shared-bindings.

In CP 5.0, displayio_display_core_set_region_to_update now starts
its own transaction, so it has to be moved outside of the transaction
started by the render call.
2019-09-04 16:41:58 +02:00
Dan Halbert 95a5a57f94 Merge remote-tracking branch 'adafruit/master' into choose-usb-devices-xac 2019-09-04 00:12:09 -04:00
sommersoft edfcee29ff remove leftover debug print 2019-09-03 22:25:27 -05:00
Dan Halbert d3cb1030c8 trivial change; try to force check run 2019-09-03 23:15:50 -04:00
Dan Halbert 94ba027544 simpler generation of HID device tables 2019-09-03 21:16:14 -04:00
Scott Shawcroft 949f8761b8
Add .hidden to TileGrid and Group
This allows for one to preserve ordering within a Group while
hiding something temporarily.

Fixes #1688
2019-09-03 16:15:27 -07:00
Scott Shawcroft b53f169824
Fix I2CDisplay bus_free to not grab lock
Fixes #2098
2019-09-03 14:46:47 -07:00
Dan Halbert 42f5edbd33 WIP 2019-09-03 14:44:46 -04:00
Dave Astels b318896b85 Capture rotation 2019-09-03 12:35:41 -04:00
sommersoft b1c3d47413 Merge branch 'master' of https://github.com/adafruit/circuitpython into mixer_voice 2019-09-01 21:16:12 -05:00
sommersoft 362c1664ae use more accurate ARMv7 prepocessor flags; TODOs for asm instructions 2019-09-01 17:36:29 -05:00
Matthew Newberg d87bfaf480 Add random dithering to ColorConverter 2019-08-31 22:07:09 -04:00
sommersoft 3c7c3c98d7 include CMSIS instrinsic addition functions for M4; cleanup C math funcs 2019-08-31 17:36:54 -05:00
sommersoft 8120f5cdad Merge branch 'master' of https://github.com/adafruit/circuitpython into mixer_voice 2019-08-29 22:14:53 -05:00
Dan Halbert 7a64af9280 rename bleio module to _bleio 2019-08-29 18:44:27 -04:00
Scott Shawcroft bea77c651a
Minor renames 2019-08-26 16:37:59 -07:00
sommersoft 696117b048 disable audiomixer on boards it doesn't fit on 2019-08-25 14:53:34 -05:00
sommersoft 7f64af38cb fix 'audiomixer_mixer_reset_buffer' 2019-08-25 09:33:23 -05:00
sommersoft df5568d993 move Mixer & MixerVoice from 'audiocore' to 'audiomixer' 2019-08-24 23:36:18 -05:00
sommersoft b54fd961cb Merge branch 'master' of https://github.com/adafruit/circuitpython into mixer_voice 2019-08-24 17:14:05 -05:00
sommersoft 965f2bf799 fix MixerVoice.get_level; now returns a float between 0-1. 2019-08-24 09:24:54 -05:00
sommersoft 2c55b40a53 use a MixerVoice constructor 2019-08-24 07:56:12 -05:00
Scott Shawcroft 7324b70a7c
Rework based on Dan's review 2019-08-23 15:27:21 -07:00
Scott Shawcroft 72e7ffa324
More cleanup 2019-08-22 16:16:09 -07:00
Scott Shawcroft 8d836fa248
Regular display fixes including refresh tweaks 2019-08-22 14:25:46 -07:00
Scott Shawcroft f2a1972ba8
Add refresh_time to use if busy_pin is not given 2019-08-22 14:23:33 -07:00
Scott Shawcroft 3a98de1236
Add reset() to display busses to detect whether it works 2019-08-22 14:23:33 -07:00
Scott Shawcroft 24b30965c4
Refresh ePaper displays once code.py is done running 2019-08-22 14:23:32 -07:00
Scott Shawcroft 36a23e0fe3
Rework refresh API and factor common display stuff out
NOT TESTED! Just compiles

Fixes #1691
2019-08-22 14:23:27 -07:00
Scott Shawcroft c247e7df9c
Begin refresh rework. 2019-08-22 14:08:33 -07:00
Scott Shawcroft 70680d5b22
EPaper displays work mostly. 2019-08-22 14:08:33 -07:00
Dan Halbert 7cc15e56c8 make translate 2019-08-22 15:20:23 -04:00
Dave Astels d547d59cba Merge remote-tracking branch 'adafruit/master' into displayio_fill_area 2019-08-21 15:02:51 -04:00
Dan Halbert e00696de7f merge from upstream and make translate 2019-08-20 13:06:23 -04:00
Dan Halbert cccbbd956d Detect lack of pulldown; check for pin in use 2019-08-19 23:40:34 -04:00
sommersoft 1b2996a75e Merge branch 'master' of https://github.com/adafruit/circuitpython into mixer_voice 2019-08-19 21:23:27 -05:00
sommersoft 17190ae63e abandon incomplete mixer asm math functions 2019-08-19 21:20:52 -05:00
Dan Halbert e3dc5e3a66 Merge remote-tracking branch 'adafruit/master' into run-background-tasks
Restore dependencies indicated by indentation in circuitpy_mpconfig.h.
2019-08-19 12:41:20 -04:00
Dan Halbert 6b54e6749e
Merge pull request #2032 from pewpew-game/audiocore-buffer
Allow to specify pre-allocated buffer in audicore.WaveFile
2019-08-19 11:54:19 -04:00
Dan Halbert e2a4c76a37 make nrf touchio be generic: now available for SAMD51 too 2019-08-18 08:44:10 -04:00