Beispiel #1
0
class Sound(Resampled):
    """
    A simple pipeline that computes a perceptually weighted modified discrete
    cosine transform, and "persists" feature data in an in-memory store.
    """

    windowed = zounds.ArrayWithUnitsFeature(
        zounds.SlidingWindow,
        needs=Resampled.resampled,
        wscheme=zounds.HalfLapped(),
        wfunc=zounds.OggVorbisWindowingFunc(),
        store=True)

    mdct = zounds.ArrayWithUnitsFeature(zounds.MDCT, needs=windowed)

    weighted = zounds.ArrayWithUnitsFeature(lambda x: x * zounds.AWeighting(),
                                            needs=mdct)
Beispiel #2
0
import featureflow as ff
import zounds
import numpy as np

windowing = zounds.HalfLapped()


# Segment audio files #########################################################

class Settings(ff.PersistenceSettings):
    id_provider = ff.UserSpecifiedIdProvider(key='_id')
    key_builder = ff.StringDelimitedKeyBuilder(seperator='|')
    database = ff.LmdbDatabase(path='onsetdata', key_builder=key_builder)
    event_log = ff.EventLog(
        path='onsetdataevents', channel=ff.InMemoryChannel())


STFT = zounds.stft(
    resample_to=zounds.SR11025(),
    wscheme=windowing)


class WithOnsets(STFT, Settings):
    bark = zounds.ArrayWithUnitsFeature(
        zounds.BarkBands,
        needs=STFT.fft,
        store=True)

    transience = zounds.ArrayWithUnitsFeature(
        zounds.MeasureOfTransience,
        needs=STFT.fft,
BaseModel = zounds.resampled(resample_to=samplerate, store_resampled=True)

scale_bands = 96
spectrogram_duration = 64

anchor_slice = slice(spectrogram_duration, spectrogram_duration * 2)

scale = zounds.GeometricScale(start_center_hz=50,
                              stop_center_hz=samplerate.nyquist,
                              bandwidth_ratio=0.115,
                              n_bands=scale_bands)
scale.ensure_overlap_ratio()

spectrogram_duration = 64

windowing_scheme = zounds.HalfLapped()
spectrogram_sample_rate = zounds.SampleRate(
    frequency=windowing_scheme.frequency * (spectrogram_duration // 2),
    duration=windowing_scheme.frequency * spectrogram_duration)


def spectrogram(x):
    x = apply_scale(np.abs(x.real),
                    scale,
                    window=zounds.OggVorbisWindowingFunc())
    x = zounds.log_modulus(x * 100)
    return x * zounds.AWeighting()


@zounds.simple_lmdb_settings('spectrogram_embedding',
                             map_size=1e11,
Beispiel #4
0
 def _complex_stft(cls, samples, window_sr=None):
     window_sr = window_sr or zounds.HalfLapped()
     return zounds.spectral.stft(samples, window_sr)