audiodev.bytequeue

A byte FIFO for PCM waiting between a writer and a device, kept in small chunks.

The host and browser backends buffer PCM between write() and the device. A bytearray grown at the back and cut at the front needs one contiguous block the size of everything pending each time it grows, about a megabyte at 44.1 kHz stereo, and on a MicroPython heap shared with a UI there is sometimes no such block: MemoryError in the middle of playback.

ByteQueue holds the same bytes in fixed-size chunks, so the largest block it ever asks for is one chunk, and it only holds as many chunks as there are bytes pending (plus a few spares it reuses). limit caps what it accepts.

It is not thread-safe: one writer and one reader on the same thread, or a caller-held lock.