UlascanErsoy / Team-7---Multimodal-Accessibility

TOPH: Data driven sonification framework
1 stars 2 forks source link

Build the Skeleton of Toph #15

Closed UlascanErsoy closed 3 weeks ago

UlascanErsoy commented 1 month ago

Implemented some simple primitives;

class AudioStage:
    """AudioStage is a wrapper for pyaudio,
    implements a context manager in addition to other utility
    functions to play nice with primitives provided by TOPH
    """

    # TODO: IDK maybe put somewhere
    CHUNK_SIZE = 1024

    def __init__(
        self, frame_rate: int = 44100, sample_width: int = 2, n_channels: int = 2
    ):

AudioStage is a context manager that makes sure every toph object created within follows the same settings.

I also created some simple generators;

class SineWave(Playable):
    """The simplest sine generator"""

    def __init__(self, f: int, secs: float):

and

class SpatialPanner(Effect):
    """The simplest spatial panner (l/r)"""

    def __init__(self, dir: float = 0):
class Chain(Playable):
    """Chain playables together"""

    def __init__(self, *args):
        """Takes a list of playables chains
        them back to back
        """

We are essentially building the d3.js for audio (and in python). Using these building blocks we can build sonifications;

    with AudioStage() as stage:
        panner = SpatialPanner(dir = - 0.1)
        chain =  Chain(
                    SineWave(f = 110, secs=1.5).apply_effect(panner),
                    Silence(secs=2.5),
                    SineWave(f = 220, secs=1.5),
                    Silence(secs=0.5),
                    SineWave(f = 440, secs=1.5),
                    )
        stage.play(chain)

As of (a8cbe0d).

For 3d Panning