Skip to main content

Create simple "chiptune" style audio waveforms using numpy.

Project description

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.

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

chipnumpy-1.0.0.tar.gz (2.9 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: chipnumpy-1.0.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for chipnumpy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bb2800865e090258d4743a69a7191caac957e940a7cd7699861bb89204972832
MD5 127da5c4809f9b9e850c900d81829e1d
BLAKE2b-256 6f28ceb852d000316fc84bac21db1fd4198058bf75f0a7e79f758c9b8254b616

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