chipnumpy


Namechipnumpy JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://github.com/subalterngames/chipnumpy
SummaryCreate simple "chiptune" style audio waveforms using numpy.
upload_time2023-01-13 20:57:00
maintainer
docs_urlNone
authorEsther Alter
requires_python
licenseMIT
keywords audio chiptune synthesizer waveform
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Chipnumpy

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

Chipnumpy was inspired by [chippy](https://github.com/benmoran56/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:

```bash
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:

```python
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

```python
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:

```python
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`.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/subalterngames/chipnumpy",
    "name": "chipnumpy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "audio chiptune synthesizer waveform",
    "author": "Esther Alter",
    "author_email": "subalterngames@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6f/28/ceb852d000316fc84bac21db1fd4198058bf75f0a7e79f758c9b8254b616/chipnumpy-1.0.0.tar.gz",
    "platform": null,
    "description": "# Chipnumpy\r\n\r\n**Chipnumpy is a module for creating simple chiptune style audio waveforms using numpy.** \r\n\r\nChipnumpy was inspired by [chippy](https://github.com/benmoran56/chippy). It has a similar API and generates the same types of waveforms. Unlike chippy, chipnumpy uses numpy, which makes it significantly faster.\r\n\r\nTo install:\r\n\r\n```bash\r\npip3 install chipnumpy\r\n```\r\n\r\nFor example implementation, see `examples/c_scale.py` (requires pygame to play the audio).\r\n\r\n# Synthesizer API\r\n\r\n## The constructor\r\n\r\nStart to generate audio by creating a Synthesizer:\r\n\r\n```python\r\nfrom chipnumpy.synthesizer import Synthesizer\r\n\r\ns = Synthesizer()\r\n```\r\n\r\nYou 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.\r\n\r\n## Generate a sine waveform\r\n\r\n```python\r\nfrom chipnumpy.synthesizer import Synthesizer\r\n\r\ns = Synthesizer()\r\ndata = s.sine(note=293.66, amplitude=0.5, length=1.1)\r\n```\r\n\r\n`note` is either a frequency in Hz, or a string representing a note + octave:\r\n\r\n```python\r\nfrom chipnumpy.synthesizer import Synthesizer\r\n\r\ns = Synthesizer()\r\ndata = s.sine(note=\"C5\", amplitude=0.5, length=1.1)\r\n```\r\n\r\n`amplitude` controls the volume and is clamped to be between 0 and 1.\r\n\r\n`length` is the duration of the waveform in seconds.\r\n\r\nThe returned `data` is an int16 byte array.\r\n\r\n## Generate other waveforms\r\n\r\nTo generate a **triangle waveform**: `data = s.triangle(\"C5\", 0.5, 1.1)`\r\n\r\nTo generate a **sawtooth waveform**: `data = s.sawtooth(\"C5\", 0.5, 1.1)`\r\n\r\nTo 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)`.\r\n\r\nTo generate a **sawtooth waveform**: `data = s.sawtooth(\"C5\", 0.5, 1.1)`\r\n\r\nTo 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.\r\n\r\n## Generate and write wav data\r\n\r\nTo convert data to wav data (i.e. to add a wav header): `wav = s.to_wav(data)`\r\n\r\nTo 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`.\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Create simple \"chiptune\" style audio waveforms using numpy.",
    "version": "1.0.0",
    "split_keywords": [
        "audio",
        "chiptune",
        "synthesizer",
        "waveform"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6f28ceb852d000316fc84bac21db1fd4198058bf75f0a7e79f758c9b8254b616",
                "md5": "127da5c4809f9b9e850c900d81829e1d",
                "sha256": "bb2800865e090258d4743a69a7191caac957e940a7cd7699861bb89204972832"
            },
            "downloads": -1,
            "filename": "chipnumpy-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "127da5c4809f9b9e850c900d81829e1d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 2876,
            "upload_time": "2023-01-13T20:57:00",
            "upload_time_iso_8601": "2023-01-13T20:57:00.411052Z",
            "url": "https://files.pythonhosted.org/packages/6f/28/ceb852d000316fc84bac21db1fd4198058bf75f0a7e79f758c9b8254b616/chipnumpy-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-13 20:57:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "subalterngames",
    "github_project": "chipnumpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "chipnumpy"
}
        
Elapsed time: 0.08836s