Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • python/ext/py-musicutils.h

    r16e2bb0 rb532275  
    33
    44static char Py_aubio_window_doc[] = ""
    5 "window(window_type, size)\n"
     5"window(string, integer) -> fvec\n"
    66"\n"
    7 "Create a window of length `size`. `window_type` should be one\n"
    8 "of the following:\n"
     7"Create a window\n"
    98"\n"
    10 "- `default` (same as `hanningz`).\n"
    11 "- `ones`\n"
    12 "- `rectangle`\n"
    13 "- `hamming`\n"
    14 "- `hanning`\n"
    15 "- `hanningz` [1]_\n"
    16 "- `blackman`\n"
    17 "- `blackman_harris`\n"
    18 "- `gaussian`\n"
    19 "- `welch`\n"
    20 "- `parzen`\n"
     9"Example\n"
     10"-------\n"
    2111"\n"
    22 "Parameters\n"
    23 "----------\n"
    24 "window_type : str\n"
    25 "   Type of window.\n"
    26 "size : int\n"
    27 "   Length of window.\n"
    28 "\n"
    29 "Returns\n"
    30 "-------\n"
    31 "fvec\n"
    32 "   Array of shape `(length,)` containing the new window.\n"
    33 "\n"
    34 "See Also\n"
    35 "--------\n"
    36 "pvoc, fft\n"
    37 "\n"
    38 "Examples\n"
    39 "--------\n"
    40 "Compute a zero-phase Hann window on `1024` points:\n"
    41 "\n"
    42 ">>> aubio.window('hanningz', 1024)\n"
     12">>> window('hanningz', 1024)\n"
    4313"array([  0.00000000e+00,   9.41753387e-06,   3.76403332e-05, ...,\n"
    44 "         8.46982002e-05,   3.76403332e-05,   9.41753387e-06], dtype=float32)\n"
    45 "\n"
    46 "Plot different window types with `matplotlib <https://matplotlib.org/>`_:\n"
    47 "\n"
    48 ">>> import matplotlib.pyplot as plt\n"
    49 ">>> modes = ['default', 'ones', 'rectangle', 'hamming', 'hanning',\n"
    50 "...          'hanningz', 'blackman', 'blackman_harris', 'gaussian',\n"
    51 "...          'welch', 'parzen']; n = 2048\n"
    52 ">>> for m in modes: plt.plot(aubio.window(m, n), label=m)\n"
    53 "...\n"
    54 ">>> plt.legend(); plt.show()\n"
    55 "\n"
    56 "Note\n"
    57 "----\n"
    58 "The following examples contain the equivalent source code to compute\n"
    59 "each type of window with `NumPy <https://numpy.org>`_:\n"
    60 "\n"
    61 ">>> n = 1024; x = np.arange(n, dtype=aubio.float_type)\n"
    62 ">>> ones = np.ones(n).astype(aubio.float_type)\n"
    63 ">>> rectangle = 0.5 * ones\n"
    64 ">>> hanning = 0.5 - 0.5 * np.cos(2 * np.pi * x / n)\n"
    65 ">>> hanningz = 0.5 * (1 - np.cos(2 * np.pi * x / n))\n"
    66 ">>> hamming = 0.54 - 0.46 * np.cos(2.*np.pi * x / (n - 1))\n"
    67 ">>> blackman = 0.42 \\\n"
    68 "...          - 0.50 * np.cos(2 * np.pi * x / (n - 1)) \\\n"
    69 "...          + 0.08 * np.cos(4 * np.pi * x / (n - 1))\n"
    70 ">>> blackman_harris = 0.35875 \\\n"
    71 "...       - 0.48829 * np.cos(2 * np.pi * x / (n - 1)) \\\n"
    72 "...       + 0.14128 * np.cos(4 * np.pi * x / (n - 1)) \\\n"
    73 "...       + 0.01168 * np.cos(6 * np.pi * x / (n - 1))\n"
    74 ">>> gaussian = np.exp( - 0.5 * ((x - 0.5 * (n - 1)) \\\n"
    75 "...                            / (0.25 * (n - 1)) )**2 )\n"
    76 ">>> welch = 1 - ((2 * x - n) / (n + 1))**2\n"
    77 ">>> parzen = 1 - np.abs((2 * x - n) / (n + 1))\n"
    78 ">>> default = hanningz\n"
    79 "References\n"
    80 "----------\n"
    81 #if 0
    82 "`Window function <https://en.wikipedia.org/wiki/Window_function>`_ on\n"
    83 "Wikipedia.\n"
    84 "\n"
    85 #endif
    86 ".. [1] Amalia de Götzen, Nicolas Bernardini, and Daniel Arfib. Traditional\n"
    87 "   (?) implementations of a phase vocoder: the tricks of the trade.\n"
    88 "   In *Proceedings of the International Conference on Digital Audio\n"
    89 "   Effects* (DAFx-00), pages 37–44, University of Verona, Italy, 2000.\n"
    90 "   (`online version <"
    91 "https://www.cs.princeton.edu/courses/archive/spr09/cos325/Bernardini.pdf"
    92 ">`_).\n"
    93 "";
     14"         8.46982002e-05,   3.76403332e-05,   9.41753387e-06], dtype=float32)";
    9415
    9516PyObject * Py_aubio_window(PyObject *self, PyObject *args);
    9617
    9718static char Py_aubio_level_lin_doc[] = ""
    98 "level_lin(x)\n"
     19"level_lin(fvec) -> fvec\n"
    9920"\n"
    100 "Compute sound pressure level of `x`, on a linear scale.\n"
     21"Compute sound level on a linear scale.\n"
    10122"\n"
    102 "Parameters\n"
    103 "----------\n"
    104 "x : fvec\n"
    105 "   input vector\n"
    106 "\n"
    107 "Returns\n"
    108 "-------\n"
    109 "float\n"
    110 "   Linear level of `x`.\n"
     23"This gives the average of the square amplitudes.\n"
    11124"\n"
    11225"Example\n"
    11326"-------\n"
    11427"\n"
    115 ">>> aubio.level_lin(aubio.fvec(numpy.ones(1024)))\n"
    116 "1.0\n"
    117 "\n"
    118 "Note\n"
    119 "----\n"
    120 "Computed as the average of the squared amplitudes:\n"
    121 "\n"
    122 ".. math:: L = \\frac {\\sum_{n=0}^{N-1} {x_n}^2} {N}\n"
    123 "\n"
    124 "See Also\n"
    125 "--------\n"
    126 "db_spl, silence_detection, level_detection\n"
    127 "";
     28">>> level_Lin(numpy.ones(1024))\n"
     29"1.0";
    12830
    12931PyObject * Py_aubio_level_lin(PyObject *self, PyObject *args);
    13032
    13133static char Py_aubio_db_spl_doc[] = ""
    132 "db_spl(x)\n"
     34"Compute sound pressure level (SPL) in dB\n"
    13335"\n"
    134 "Compute Sound Pressure Level (SPL) of `x`, in dB.\n"
     36"This quantity is often wrongly called 'loudness'.\n"
    13537"\n"
    136 "Parameters\n"
    137 "----------\n"
    138 "x : fvec\n"
    139 "   input vector\n"
    140 "\n"
    141 "Returns\n"
    142 "-------\n"
    143 "float\n"
    144 "   Level of `x`, in dB SPL.\n"
     38"This gives ten times the log10 of the average of the square amplitudes.\n"
    14539"\n"
    14640"Example\n"
    14741"-------\n"
    14842"\n"
    149 ">>> aubio.db_spl(aubio.fvec(np.ones(1024)))\n"
    150 "1.0\n"
    151 ">>> aubio.db_spl(0.7*aubio.fvec(np.ones(32)))\n"
    152 "-3.098040819168091\n"
    153 "\n"
    154 "Note\n"
    155 "----\n"
    156 "Computed as `log10` of :py:func:`level_lin`:\n"
    157 "\n"
    158 ".. math::\n"
    159 "\n"
    160 "   {SPL}_{dB} = log10{\\frac {\\sum_{n=0}^{N-1}{x_n}^2} {N}}\n"
    161 "\n"
    162 "This quantity is often incorrectly called 'loudness'.\n"
    163 "\n"
    164 "See Also\n"
    165 "--------\n"
    166 "level_lin, silence_detection, level_detection\n"
    167 "";
     43">>> db_spl(numpy.ones(1024))\n"
     44"1.0";
    16845
    16946PyObject * Py_aubio_db_spl(PyObject *self, PyObject *args);
    17047
    17148static char Py_aubio_silence_detection_doc[] = ""
    172 "silence_detection(vec, level)\n"
     49"Check if buffer level in dB SPL is under a given threshold\n"
    17350"\n"
    174 "Check if level of `vec`, in dB SPL, is under a given threshold.\n"
     51"Return 0 if level is under the given threshold, 1 otherwise.\n"
    17552"\n"
    176 "Parameters\n"
    177 "----------\n"
    178 "vec : fvec\n"
    179 "   input vector\n"
    180 "level : float\n"
    181 "   level threshold, in dB SPL\n"
     53"Example\n"
     54"-------\n"
    18255"\n"
    183 "Returns\n"
    184 "-------\n"
    185 "int\n"
    186 "   `1` if level of `vec`, in dB SPL, is under `level`,\n"
    187 "   `0` otherwise.\n"
    188 "\n"
    189 "Examples\n"
    190 "--------\n"
    191 "\n"
    192 ">>> aubio.silence_detection(aubio.fvec(32), -100.)\n"
    193 "1\n"
    194 ">>> aubio.silence_detection(aubio.fvec(np.ones(32)), 0.)\n"
    195 "0\n"
    196 "\n"
    197 "See Also\n"
    198 "--------\n"
    199 "level_detection, db_spl, level_lin\n"
    200 "";
     56">>> import numpy\n"""
     57">>> silence_detection(numpy.ones(1024, dtype=\"float32\"), -80)\n"
     58"0";
    20159
    20260PyObject * Py_aubio_silence_detection(PyObject *self, PyObject *args);
    20361
    20462static char Py_aubio_level_detection_doc[] = ""
    205 "level_detection(vec, level)\n"
    206 "\n"
    207 "Check if `vec` is above threshold `level`, in dB SPL.\n"
    208 "\n"
    209 "Parameters\n"
    210 "----------\n"
    211 "vec : fvec\n"
    212 "   input vector\n"
    213 "level : float\n"
    214 "   level threshold, in dB SPL\n"
    215 "\n"
    216 "Returns\n"
    217 "-------\n"
    218 "float\n"
    219 "   `1.0` if level of `vec` in dB SPL is under `level`,\n"
    220 "   `db_spl(vec)` otherwise.\n"
     63"Get buffer level in dB SPL if over a given threshold, 1. otherwise.\n"
    22164"\n"
    22265"Example\n"
    22366"-------\n"
    22467"\n"
    225 ">>> aubio.level_detection(0.7*aubio.fvec(np.ones(1024)), -3.)\n"
    226 "1.0\n"
    227 ">>> aubio.level_detection(0.7*aubio.fvec(np.ones(1024)), -4.)\n"
    228 "-3.0980708599090576\n"
    229 "\n"
    230 "See Also\n"
    231 "--------\n"
    232 "silence_detection, db_spl, level_lin\n"
    233 "";
     68">>> import numpy\n"""
     69">>> level_detection(0.7*numpy.ones(1024, dtype=\"float32\"), -80)\n"
     70"0";
    23471
    23572PyObject * Py_aubio_level_detection(PyObject *self, PyObject *args);
    23673
    23774static char Py_aubio_shift_doc[] = ""
    238 "shift(vec)\n"
     75"Swap left and right partitions of a vector\n"
    23976"\n"
    240 "Swap left and right partitions of a vector, in-place.\n"
    241 "\n"
    242 "Parameters\n"
    243 "----------\n"
    244 "vec : fvec\n"
    245 "   input vector to shift\n"
    246 "\n"
    247 "Returns\n"
    248 "-------\n"
    249 "fvec\n"
    250 "   The swapped vector.\n"
    251 "\n"
    252 "Notes\n"
    253 "-----\n"
    254 "The input vector is also modified.\n"
     77"Returns the swapped vector. The input vector is also modified.\n"
    25578"\n"
    25679"For a vector of length N, the partition is split at index N - N//2.\n"
     
    25982"-------\n"
    26083"\n"
    261 ">>> aubio.shift(aubio.fvec(np.arange(3)))\n"
    262 "array([2., 0., 1.], dtype=" AUBIO_NPY_SMPL_STR ")\n"
    263 "\n"
    264 "See Also\n"
    265 "--------\n"
    266 "ishift\n"
    267 "";
     84">>> import numpy\n"
     85">>> shift(numpy.arange(3, dtype=aubio.float_type))\n"
     86"array([2., 0., 1.], dtype=" AUBIO_NPY_SMPL_STR ")";
    26887PyObject * Py_aubio_shift(PyObject *self, PyObject *args);
    26988
    27089static char Py_aubio_ishift_doc[] = ""
    271 "ishift(vec)\n"
     90"Swap right and left partitions of a vector\n"
    27291"\n"
    273 "Swap right and left partitions of a vector, in-place.\n"
     92"Returns the swapped vector. The input vector is also modified.\n"
    27493"\n"
    275 "Parameters\n"
    276 "----------\n"
    277 "vec : fvec\n"
    278 "   input vector to shift\n"
    279 "\n"
    280 "Returns\n"
    281 "-------\n"
    282 "fvec\n"
    283 "   The swapped vector.\n"
    284 "\n"
    285 "Notes\n"
    286 "-----\n"
    287 "The input vector is also modified.\n"
    288 "\n"
    289 "Unlike with :py:func:`shift`, the partition is split at index N//2.\n"
     94"Unlike with shift(), the partition is split at index N//2.\n"
    29095"\n"
    29196"Example\n"
    29297"-------\n"
    29398"\n"
    294 ">>> aubio.ishift(aubio.fvec(np.arange(3)))\n"
    295 "array([1., 2., 0.], dtype=" AUBIO_NPY_SMPL_STR ")\n"
    296 "\n"
    297 "See Also\n"
    298 "--------\n"
    299 "shift\n"
    300 "";
     99">>> import numpy\n"
     100">>> ishift(numpy.arange(3, dtype=aubio.float_type))\n"
     101"array([1., 2., 0.], dtype=" AUBIO_NPY_SMPL_STR ")";
    301102PyObject * Py_aubio_ishift(PyObject *self, PyObject *args);
    302103
Note: See TracChangeset for help on using the changeset viewer.