<commit_before># -*- coding: utf-8 -*-

from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
from timeside.api import *
import numpy


class Gain(Processor):
    implements(IEffect)

    @interfacedoc
    def __init__(self, gain=1.0):
        self.gain = gain

    @staticmethod
    @interfacedoc
    def id():
        return "test_gain"

    @staticmethod
    @interfacedoc
    def name():
        return "Gain test effect"

    def process(self, frames, eod=False):
        return numpy.multiply(frames, self.gain), eod


class FixedInputProcessor(Processor):
    """Processor which does absolutely nothing except illustrating the use
    of the FixedInputSizeAdapter. It also tests things a bit."""

    implements(IProcessor)

    BUFFER_SIZE = 1024

    @staticmethod
    @interfacedoc
    def id():
        return "test_fixed"

    @interfacedoc
    def setup(self, channels, samplerate, nframes):
        super(FixedInputProcessor, self).setup(channels, samplerate, nframes)
        self.adapter = FixedSizeInputAdapter(self.BUFFER_SIZE, channels, pad=True)

    @interfacedoc
    def process(self, frames, eod=False):
        for buffer, end in self.adapter.process(frames, eod):
            # Test that the adapter is actually doing the job:
            if len(buffer) != self.BUFFER_SIZE:
                raise Exception("Bad buffer size from adapter")

        return frames, eod





<commit_msg>tests/api/examples.py: remove old FixedInputProcessor<commit_after># -*- coding: utf-8 -*-

from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter
from timeside.api import *
import numpy


class Gain(Processor):
    implements(IEffect)

    @interfacedoc
    def __init__(self, gain=1.0):
        self.gain = gain

    @staticmethod
    @interfacedoc
    def id():
        return "test_gain"

    @staticmethod
    @interfacedoc
    def name():
        return "Gain test effect"

    def process(self, frames, eod=False):
        return numpy.multiply(frames, self.gain), eod

{'fraction_non_alphanumeric': 0.09335288367546432, 'fraction_numerical': 0.004887585532746823, 'mean_word_length': 3.0058708414872797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6776534', 'n_tokens_mistral': 613, 'n_tokens_neox': 580, 'n_words': 170}