source: python/lib/aubio/__init__.py @ 7cfad8e

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since 7cfad8e was 7cfad8e, checked in by Paul Brossier <piem@piem.org>, 5 years ago

[py] add basic module docstring

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#! /usr/bin/env python
2# -*- coding: utf8 -*-
3
4"""
5aubio
6=====
7
8Provides a number of classes and functions for music and audio signal
9analysis.
10
11How to use the documentation
12----------------------------
13
14Documentation of the python module is available as docstrings provided
15within the code, and a reference guide available online from `the
16aubio homepage <https://aubio.org/documentation>`_.
17
18The docstrings examples are written assuming `aubio` and `numpy` have been
19imported with:
20
21>>> import aubio
22>>> import numpy as np
23"""
24
25import numpy
26from ._aubio import __version__ as version
27from ._aubio import float_type
28from ._aubio import *
29from .midiconv import *
30from .slicing import *
31
32class fvec(numpy.ndarray):
33    """fvec(input_arg=1024, **kwargs)
34    A vector holding float samples.
35
36    If `input_arg` is an `int`, a 1-dimensional vector of length `input_arg`
37    will be created and filled with zeros. Otherwise, if `input_arg` is an
38    `array_like` object, it will be converted to a 1-dimensional vector of
39    type :data:`float_type`.
40
41    Parameters
42    ----------
43    input_arg : `int` or `array_like`
44        Can be a positive integer, or any object that can be converted to
45        a numpy array with :func:`numpy.array`.
46    **kwargs
47        Additional keyword arguments passed to :func:`numpy.zeros`, if
48        `input_arg` is an integer, or to :func:`numpy.array`. Should not
49        include `dtype`, which is already specified as
50        :data:`aubio.float_type`.
51
52    Returns
53    -------
54    numpy.ndarray
55        Array of shape `(length,)`.
56
57    Examples
58    --------
59    >>> aubio.fvec(10)
60    array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32)
61    >>> aubio.fvec([0,1,2])
62    array([0., 1., 2.], dtype=float32)
63    >>> a = np.arange(10); type(a), type(aubio.fvec(a))
64    (<class 'numpy.ndarray'>, <class 'numpy.ndarray'>)
65    >>> a.dtype, aubio.fvec(a).dtype
66    (dtype('int64'), dtype('float32'))
67
68    Notes
69    -----
70
71    In the Python world, `fvec` is simply a subclass of
72    :class:`numpy.ndarray`. In practice, any 1-dimensional `numpy.ndarray` of
73    `dtype` :data:`float_type` may be passed to methods accepting
74    `fvec` as parameter. For instance, `sink()` or `pvoc()`.
75
76    See Also
77    --------
78    cvec : a container holding spectral data
79    numpy.ndarray : parent class of :class:`fvec`
80    numpy.zeros : create a numpy array filled with zeros
81    numpy.array : create a numpy array from an existing object
82    """
83    def __new__(cls, input_arg=1024, **kwargs):
84        if isinstance(input_arg, int):
85            if input_arg == 0:
86                raise ValueError("vector length of 1 or more expected")
87            return numpy.zeros(input_arg, dtype=float_type, **kwargs)
88        else:
89            return numpy.array(input_arg, dtype=float_type, **kwargs)
Note: See TracBrowser for help on using the repository browser.