Skip to main content

No project description provided

Project description

AudioDAG

CI Quality Gate Status

Construct digital audio signals from individual components, designed for psychophysics stimulus generations. Supports lazy construction or in-memory caching,

Install

pip install audiodag

Usage

Signal components

The audio_dag.signal.component.Component class is designed to handle a function describing ones aspect of a digital signaly. It handles specification of signal properties such as magnitude, duration, and hardware properties such as sampling rate, clipping, and enveloping, etc.

Individual signal component are defined by inheriting from the base component class. The child should define the ._generate_f method and and handle any additional parameters. For example, to create a sine wave:

import numpy as np

from audiodag.signal.components.component import Component

class SineComponent(Component):
    """Class specifically for tonal components."""
    def __init__(self,
                 freq: int = 2000,
                 *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.freq = freq

    def _generate_f(self) -> np.ndarray:
        """Generate vector for components"""
        return np.sin(np.linspace(0, 4 * np.pi * self.freq, self.duration_pts)) * 0.5 * self.mag

sin = SineComponent(freq=12, mag=1, start=100, fs=5000, duration=1000)
sin.plot(show=True)

example_sine

The generation function is called when Component.y is accessed, and can be optionally cached with cache=True, or generated on the fly on each call. The envelope is applied immediately after signal generation (default = constant).

Some predefined tonal and noise signals are defined in audio_dag.signal.components.noise and .tonal.

Compound signal components

Compound components handle combining components (and/or other compound components). The CompoundComponent class automatically creates a generation function that combines the generation functions of the supplied components. Similar to the individual events, this is only evaluated when the top objects .y is called (with optional caching). Meaning a whole DAG (or tree) of components can be combined before allocating any time or memory.

In simple cases, these can be constructed by multiplying components together. For example, to add noise to a sine wave:

Simple - mul

from audiodag.signal.digital.conversion import db_to_lin
from audiodag.signal.components.sine_component import SineComponent
from audiodag.signal.components.noise_component import NoiseComponent

sin = SineComponent(freq=12, mag=1, fs=5000, duration=1000)
noise = NoiseComponent(fs=5000, duration=1000, mag=db_to_lin(ref=1, db_change=-80))

compound_component = sin * noise
compound_component.plot_subplots(show=True)

example_mul

Simple - from list

In more complex cases, for example where unequal weighting or a new envelope is required, components can be specified in a list.

from audiodag.signal.digital.conversion import db_to_lin
from audiodag.signal.components.sine_component import SineComponent
from audiodag.signal.components.noise_component import NoiseComponent
from audiodag.signal.components.component import CompoundComponent
from audiodag.signal.envelopes.templates import CosEnvelope

sin = SineComponent(freq=12, mag=1, start=100, fs=5000, duration=1000)
noise = NoiseComponent(fs=5000, duration=1000, mag=db_to_lin(ref=1, db_change=-80))

compound_component  = CompoundComponent([sin, noise],
                                        envelope=CosEnvelope)
compound_component.plot_subplots(show=True)

example_simple

Complex

from audiodag.signal.digital.conversion import db_to_lin
from audiodag.signal.envelopes.templates import IncreasingEnvelope
from audiodag.signal.components.component import CompoundComponent
from audiodag.signal.components.noise_component import NoiseComponent
from audiodag.signal.components.sine_component import SineComponent

start = 0
sine_4 = SineComponent(start=start, duration=1400, freq=4)

start = 200
duration = 600
sine_2_6 = CompoundComponent([SineComponent(start=start, duration=duration, freq=2),
                              SineComponent(start=start, duration=duration, freq=6)])

start = 600
duration = 1000
sine_2_12 = CompoundComponent([SineComponent(start=start, duration=duration, freq=2),
                               SineComponent(start=start, duration=duration, freq=12)])
sine_8_10 = CompoundComponent([SineComponent(start=start, duration=duration, freq=8),
                               SineComponent(start=start, duration=duration, freq=10),
                               sine_2_12])

noise = NoiseComponent(start=0, duration=1000, envelope=IncreasingEnvelope,
                       mag=db_to_lin(ref=1, db_change=-120))

signal = CompoundComponent([sine_4, sine_2_6, sine_8_10, noise])
signal.plot_subplots(show=True)

example_complex

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

AudioDAG-0.0.19.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

AudioDAG-0.0.19-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

Details for the file AudioDAG-0.0.19.tar.gz.

File metadata

  • Download URL: AudioDAG-0.0.19.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for AudioDAG-0.0.19.tar.gz
Algorithm Hash digest
SHA256 c52056fe7ca2c3101fc86d8d5bf24ef37c01a7dbe0352a4e745eedb1ef4bf01f
MD5 a512fce1908e07661b6a7457fa0aed1e
BLAKE2b-256 20efa8e8eff228201c522ff88a7a356da9e4cc87d9576b8794ae18f7bcdc1835

See more details on using hashes here.

File details

Details for the file AudioDAG-0.0.19-py3-none-any.whl.

File metadata

  • Download URL: AudioDAG-0.0.19-py3-none-any.whl
  • Upload date:
  • Size: 34.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for AudioDAG-0.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 ced36c2e73e98969767626b23da3fefbd5cf0d7b4b8d2dc367ffa5603edf9309
MD5 97354de9d7f8319d7fa5c1f6aacd42f0
BLAKE2b-256 1d73f7155355a1a312bff760abb8f6540b464d5d925cc142595a769a8e7fd48c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page