Skip to main content

Chipnumpy

Chipnumpy is a module for creating simple chiptune style audio waveforms using numpy.

Chipnumpy was inspired by chippy. It has a similar API and generates the same types of waveforms. Unlike chippy, chipnumpy uses numpy, which makes it significantly faster.

To install:

pip3 install chipnumpy

For example implementation, see examples/c_scale.py (requires pygame to play the audio).

Synthesizer API

The constructor

Start to generate audio by creating a Synthesizer:

from chipnumpy.synthesizer import Synthesizer

s = Synthesizer()

You can optionally set the random seed: s = Synthesizer(seed=0). This is used when generating noise waveforms; it can be useful if you want to recreate noise waveforms with the same seed.

Generate a sine waveform

from chipnumpy.synthesizer import Synthesizer

s = Synthesizer()
data = s.sine(note=293.66, amplitude=0.5, length=1.1)

note is either a frequency in Hz, or a string representing a note + octave:

from chipnumpy.synthesizer import Synthesizer

s = Synthesizer()
data = s.sine(note="C5", amplitude=0.5, length=1.1)

amplitude controls the volume and is clamped to be between 0 and 1.

length is the duration of the waveform in seconds.

The returned data is an int16 byte array.

Generate other waveforms

To generate a triangle waveform: data = s.triangle("C5", 0.5, 1.1)

To generate a sawtooth waveform: data = s.sawtooth("C5", 0.5, 1.1)

To generate a pulse waveform: data = s.pulse("C5", 0.5, 1.1) You can optionally set the duty cycle parameter, which controls the length of the pulse (must be between 1 and 100): s.pulse("C5", 0.5, 1.1, duty_cycle=50).

To generate a sawtooth waveform: data = s.sawtooth("C5", 0.5, 1.1)

To generate a noise waveform with the same syntax: data = s.noise("C5", 0.5, 1.1) This uses random values; see above for how to seed the random number generator.

Generate and write wav data

To convert data to wav data (i.e. to add a wav header): wav = s.to_wav(data)

To convert data to wav data and write to disk: s.write(data, path) where data is an int16 byte array and path is either a string or a Path.

Metadata

Release files for chipnumpy 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chipnumpy 1.0.0
File Size Uploaded
chipnumpy-1.0.0.tar.gz 2.9 kB Details

Release files / chipnumpy-1.0.0.tar.gz

Download URL chipnumpy-1.0.0.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bb2800865e090258d4743a69a7191caac957e940a7cd7699861bb89204972832
BLAKE2b-256 checksum
How to use checksums
6f28ceb852d000316fc84bac21db1fd4198058bf75f0a7e79f758c9b8254b616
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.26.0 setuptools/58.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page