Skip to content

byzin02/PyByteb-Lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

# 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==1.0.0

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!

About

A cool python lib for you play your formulas, pip command: pip install pybyteb==1.0.0

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors