Metadata-Version: 2.4
Name: pybyteb
Version: 1.0.0
Summary: A simple and modern Bytebeat library for Python.
Author: Byzin (Matheus)
License: MIT
Project-URL: Homepage, https://github.com/bayzin02/PyByteb-Lib-
Project-URL: Repository, https://github.com/bayzin02/PyByteb-Lib-
Project-URL: Issues, https://github.com/bayzin02/PyByteb-Lib-/issues
Keywords: bytebeat,audio,music,sound,procedural,algorithmic,dsp,python
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Multimedia :: Sound/Audio
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: sounddevice>=0.5.0
Requires-Dist: lark>=1.2.2
Requires-Dist: numba>=0.60.0
Dynamic: license-file

\# 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



```bash

pip install pybyteb

```



Or install the dependencies manually:



```bash

pip install numpy sounddevice lark numba

```



\---



\# Quick Start



```python

import pybyteb as by



by.play(

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

&#x20;   duration=5000

)

```



\---



\# Creating a Formula



```python

import pybyteb as by



formula = by.Formula(

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

)

```



You can also specify a custom sample rate:



```python

formula = by.Formula(

&#x20;   "t",

&#x20;   sample\_rate=44100

)

```



\---



\# Methods



\## play()



Starts playback.



```python

formula.play(duration=3000)

```



Parameters:



| Argument   | Type   | Description                      |

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

| `duration` | `int`  | Playback length in milliseconds  |

| `loop`     | `bool` | Plays continuously until stopped |



Example:



```python

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

```



Infinite playback:



```python

formula.play(loop=True)

```



\---



\## pause()



Temporarily pauses playback.



```python

formula.pause()

```



\---



\## resume()



Resumes playback after a pause.



```python

formula.resume()

```



\---



\## stop()



Stops playback immediately.



```python

formula.stop()

```



\---



\## wait()



Waits until playback finishes.



```python

formula.play(duration=5000)

formula.wait()

```



You can also specify a timeout:



```python

formula.wait(timeout\_ms=2000)

```



\---



\## release()



Releases all internal resources used by the formula.



```python

formula.release()

```



Calling `release()` multiple times is safe.



\---



\# Formula Validation



```python

import pybyteb as by



by.validate("t >> 4")

```



Returns:



```

True

```



With detailed information:



```python

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

```



Returns:



```

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

```



\---



\# Supported Operators



\### Arithmetic



```

\+

\-

\*

/

%

```



\### Bitwise



```

\&

|

^

\~

<<

>>

>>>

```



\### Comparison



```

<

<=

>

>=

==

!=

===

!==

```



\### Logical



```

\&\&

||

!

```



\### Ternary



```

condition ? value1 : value2

```



Example:



```text

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:



```text

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

```



\---



\# Example Bytebeat Formulas



Classic:



```text

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

```



Noise:



```text

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

```



Bitwise melody:



```text

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

```



Conditional:



```text

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

```



Waveform:



```text

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

```



\---



\# Formula Properties



```python

formula.sample\_rate

```



Returns the configured sample rate.



```python

formula.state

```



Possible values:



```

"idle"

"playing"

"paused"

"stopped"

"released"

```



Convenience properties:



```python

formula.is\_playing

formula.is\_paused

```



\---



\# Context Manager Support



```python

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!



