music.PrimaryTables

class music.PrimaryTables(size=2048)[source]

Bases: object

Provides primary tables for waveform lookup.

This class creates sine, triangle, square, and saw wave periods with a given number of samples.

Parameters:
sizeint, optional

The number of samples for each waveform table, by default 2048.

Attributes:
sinendarray

The sine wave table.

trianglendarray

The triangle wave table.

squarendarray

The square wave table.

sawndarray

The sawtooth wave table.

sizeint

The number of samples for each waveform table.

Examples

>>> primary_tables = PrimaryTables()
>>> primary_tables.size
2048
>>> primary_tables.draw_tables()
__init__(size=2048)[source]

Initialize the PrimaryTables class.

Parameters:
sizeint, optional

The number of samples for each waveform table, by default 2048.

Methods

__init__([size])

Initialize the PrimaryTables class.

draw_tables()

Draw the four waveform tables on one pair of axes.

make_tables(size)

Create waveform tables.

make_tables(size)[source]

Create waveform tables.

Parameters:
sizeint

The number of samples for each waveform table.

draw_tables()[source]

Draw the four waveform tables on one pair of axes.

Raises:
ImportError

If matplotlib is not installed. Install it with pip install 'music[plot]'.

Notes

matplotlib is imported here rather than at the top of the module. It is the only thing in the package that needs it, and importing it eagerly cost about 40% of import music’s total time – 1237 ms against 743 ms – and pulled eight further packages into every installation, for a function that only exists to look at the tables.

The examples are marked +SKIP: show() blocks on a window, so a doctest run would hang rather than fail.

Examples

>>> PrimaryTables(size=64).draw_tables()