<commit_before># -*- coding: utf-8 -*-
#
# Copyright (c) 2017 <NAME> <<EMAIL>>

# This file is part of TimeSide.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Author: <NAME> <<EMAIL>>

from timeside.core import implements, interfacedoc
from timeside.core.api import IAnalyzer
from timeside.core.tools.parameters import HasTraits
from timeside.core.tools.parameters import store_parameters

import vamp
import vampyhost
from .vampyhost_wrapper import VampAnalyzer

import numpy as np


class VampSpectralCentroid(VampAnalyzer):
    """Calculate the centroid frequency of the spectrum of the input signal"""

    implements(IAnalyzer)

    class _Param(HasTraits):
        pass

    _schema = {'$schema': 'http://json-schema.org/schema#',
               'properties': {},
               'type': 'object'}

    @store_parameters
    def __init__(self):
        super(VampSpectralCentroid, self).__init__()
        # Define Vamp plugin key and output
        self.plugin_key = 'vamp-libxtract:spectral_centroid'
        self.plugin_output = 'spectral_centroid'

    @interfacedoc
    def setup(self, channels=None, samplerate=None,
              blocksize=None, totalframes=None):
        super(VampSpectralCentroid, self).setup(
            channels, samplerate, blocksize, totalframes)

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

    @staticmethod
    @interfacedoc
    def name():
        return "Spectral centroid (vamp)"

    @staticmethod
    @interfacedoc
    def version():
        return "1.0.0"

    @staticmethod
    @interfacedoc
    def unit():
        return ""

    def post_process(self):
        super(VampSpectralCentroid, self).post_process()  # get remaining results

        result = self.new_result(data_mode='value', time_mode='framewise')
        result.data_object.value = self.vamp_results['vector'][1]
        result.data_object.y_value = self.vamp_results['vector'][0]
        self.add_result(result)
<commit_msg>[analyzers] set VampSpectralCentroid blocksize to 1024 (see #279)<commit_after># -*- coding: utf-8 -*-
#
# Copyright (c) 2017 <NAME> <<EMAIL>>

# This file is part of TimeSide.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# Author: <NAME> <<EMAIL>>

from timeside.core import implements, interfacedoc
from timeside.core.api import IAnalyzer
from timeside.core.tools.parameters import HasTraits
from timeside.core.tools.parameters import store_parameters

import vamp
import vampyhost
from .vampyhost_wrapper import VampAnalyzer

import numpy as np


class VampSpectralCentroid(VampAnalyzer):
    """Calculate the centroid frequency of the spectrum of the input signal"""

    implements(IAnalyzer)

    class _Param(HasTraits):
        pass

    _schema = {'$schema': 'http://json-schema.org/schema#',
               'properties': {},
               'type': 'object'}

    @store_parameters
    def __init__(self):
        super(VampSpectralCentroid, self).__init__()
        self.input_blocksize = 1024
        self.input_stepsize = self.input_blocksize
        # Define Vamp plugin key and output
        self.plugin_key = 'vamp-libxtract:spectral_centroid'
        self.plugin_output = 'spectral_centroid'

    @interfacedoc
    def setup(self, channels=None, samplerate=None,
              blocksize=None, totalframes=None):
        super(VampSpectralCentroid, self).setup(
            channels, samplerate, blocksize, totalframes)

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

    @staticmethod
    @interfacedoc
    def name():
        return "Spectral centroid (vamp)"

    @staticmethod
    @interfacedoc
    def version():
        return "1.0.0"

    @staticmethod
    @interfacedoc
    def unit():
        return ""

    def post_process(self):
        super(VampSpectralCentroid, self).post_process()  # get remaining results

        result = self.new_result(data_mode='value', time_mode='framewise')
        result.data_object.value = self.vamp_results['vector'][1]
        result.data_object.y_value = self.vamp_results['vector'][0]
        self.add_result(result)

{'fraction_non_alphanumeric': 0.09044848939763558, 'fraction_numerical': 0.006192531431788328, 'mean_word_length': 3.343928280358598, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '373150', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1504, 'n_words': 489}