Skip to main content

A simple and modern Bytebeat library for Python.

Project description

# Libray PyByteb

**PyByteb** is a Python library for creating and playing **Bytebeat** formulas in real time. It provides an easy-to-use API while supporting many classic Bytebeat operators and mathematical functions inspired by JavaScript syntax.

Whether you're experimenting with algorithmic music, generating retro sounds, or just having fun with mathematical expressions, PyByteb aims to make the process simple and enjoyable.

⚠️ **Early Release Notice**

PyByteb is currently in its first public release. While it has been tested extensively and great care has been taken to reduce bugs and unexpected behavior, there may still be edge cases or issues with certain formulas.

If you encounter any problems, feedback and bug reports are greatly appreciated and will help improve future versions.

---

# Features

* ✅ Real-time Bytebeat playback

* ✅ JavaScript-like expression syntax

* ✅ Bitwise operators (\&, |, ^, \~, <<, >>, >>>)

* ✅ Ternary operator (condition ? true : false)

* ✅ Hexadecimal, binary and octal literals

* ✅ Built-in mathematical functions

* ✅ Formula validation before playback

* ✅ Pause, resume and stop controls

* ✅ Optional looping

* ✅ Adjustable sample rate

* ✅ Wait for playback completion with wait()

---

# Installation

pip install pybyteb

Or install the dependencies manually:

pip install numpy sounddevice lark numba

---

# Quick Start

import pybyteb as by



by.play(

&#x20;   "t \* ((t >> 5) | (t >> 8))",

&#x20;   duration=5000

)

---

# Creating a Formula

import pybyteb as by



formula = by.Formula(

&#x20;   "t \* ((t >> 5) | (t >> 8))"

)

You can also specify a custom sample rate:

formula = by.Formula(

&#x20;   "t",

&#x20;   sample\_rate=44100

)

---

# Methods

## play()

Starts playback.

formula.play(duration=3000)

Parameters:

| Argument | Type | Description |

| ---------- | ------ | -------------------------------- |

| duration | int | Playback length in milliseconds |

| loop | bool | Plays continuously until stopped |

Example:

formula.play(duration=5000, loop=False)

Infinite playback:

formula.play(loop=True)

---

## pause()

Temporarily pauses playback.

formula.pause()

---

## resume()

Resumes playback after a pause.

formula.resume()

---

## stop()

Stops playback immediately.

formula.stop()

---

## wait()

Waits until playback finishes.

formula.play(duration=5000)

formula.wait()

You can also specify a timeout:

formula.wait(timeout\_ms=2000)

---

## release()

Releases all internal resources used by the formula.

formula.release()

Calling release() multiple times is safe.

---

# Formula Validation

import pybyteb as by



by.validate("t >> 4")

Returns:


True

With detailed information:

by.validate("t \&\&\&", details=True)

Returns:


(False, "invalid syntax at position 5.")

---

# Supported Operators

### Arithmetic


\+

\-

\*

/

%

### Bitwise


\&

|

^

\~

<<

>>

>>>

### Comparison


<

<=

>

>=

==

!=

===

!==

### Logical


\&\&

||

!

### Ternary


condition ? value1 : value2

Example:

t > 5000 ? 255 : 0

Nested ternaries are also supported.

---

# Number Formats

Decimal:


255

Hexadecimal:


0xFF

Binary:


0b11111111

Octal:


0o377

---

# Supported Math Functions


abs()

min()

max()

pow()



sin()

cos()

tan()



asin()

acos()

atan()

atan2()



sqrt()



floor()

ceil()

round()



log()

exp()

Example:

sin(t \* 0.01) \* 127 + 128

---

# Example Bytebeat Formulas

Classic:

t \* ((t >> 5) | (t >> 8))

Noise:

(t ^ (t >> 7)) \& 255

Bitwise melody:

(t \* 5 \& (t >> 7)) | (t \* 3 \& (t >> 10))

Conditional:

(t \& 2048) ? (t >> 4) : (t << 2)

Waveform:

sin(t \* 0.02) \* 127 + 128

---

# Formula Properties

formula.sample\_rate

Returns the configured sample rate.

formula.state

Possible values:


"idle"

"playing"

"paused"

"stopped"

"released"

Convenience properties:

formula.is\_playing

formula.is\_paused

---

# Context Manager Support

with by.Formula("t >> 4") as f:

&#x20;   f.play(duration=3000)

&#x20;   f.wait()

Resources are released automatically when leaving the block.

---

# Tips

* Use wait() after play() if you want your script to wait until playback finishes.

* Use loop=True for continuous playback.

* Call release() when you're done with a Formula instance.

* Complex formulas may require more CPU resources.

---

# Compatibility

* Python 3.9+

* Windows

* Linux (depending on the available audio backend)

---

# About the Author

**PyByteb** was created by **Byzin (Matheus)**.

I'm a Brazilian developer 🇧🇷, and this is my **first published Python library**. The project started as a personal experiment while learning about Bytebeat generation and low-level programming concepts, and eventually grew into a reusable package.

I hope it can be useful for other developers, musicians, and anyone interested in procedural audio or creative coding.

Contributions, suggestions, and bug reports are always welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybyteb-1.0.0.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybyteb-1.0.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file pybyteb-1.0.0.tar.gz.

File metadata

  • Download URL: pybyteb-1.0.0.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for pybyteb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6100f8c35fa7d00e4edfe0d9665f53d8c304edd40ec7aea92b731c90158aeefa
MD5 500650ee0658b22dac1228af1321b61a
BLAKE2b-256 4f1465be5294994e8cd4b2c2c6d3cc36f9cefc4a3e31fbfb017bb7b0b4571777

See more details on using hashes here.

File details

Details for the file pybyteb-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pybyteb-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for pybyteb-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25d83e939e23746c91a2ab14b853ce24a033b934be1862f313415e85478006fc
MD5 139e6c5455c56d5ed0d0bdec0ab3b2f5
BLAKE2b-256 4445e34d735b58fff21ec70b0b61aad9299f2ee506bc224f57622d107eb30dce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page