File: develop.rst

package info (click to toggle)
aubio 0.4.9-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,720 kB
  • sloc: python: 20,447; ansic: 20,127; makefile: 348; sh: 232
file content (154 lines) | stat: -rw-r--r-- 4,022 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
.. _develop:

Developing with aubio
=====================

Here is a brief overview of the C library.

For a more detailed list of available functions, see the `API documentation
<https://aubio.org/doc/latest/>`_.

To report issues, ask questions, and request new features, use `Github Issues
<https://github.com/aubio/aubio/issues>`_

Design Basics
-------------

The library is written in C and is optimised for speed and portability.

All memory allocations take place in the `new_` methods. Each successful call
to `new_` should have a matching call to `del_` to deallocate the object.

.. code-block:: C

   // new_ to create an object foobar
   aubio_foobar_t * new_aubio_foobar(void * args);
   // del_ to delete foobar
   void del_aubio_foobar (aubio_foobar_t * foobar);

The main computations are done in the `_do` methods.

.. code-block:: C

   // _do to process output = foobar(input)
   audio_foobar_do (aubio_foobar_t * foobar, fvec_t * input, cvec_t * output);

Most parameters can be read and written at any time:

.. code-block:: C

   // _get_param to get foobar.param
   smpl_t aubio_foobar_get_a_parameter (aubio_foobar_t * foobar);
   // _set_param to set foobar.param
   uint_t aubio_foobar_set_a_parameter (aubio_foobar_t * foobar, smpl_t a_parameter);

In some case, more functions are available:

.. code-block:: C

   // non-real time functions
   uint_t aubio_foobar_reset(aubio_foobar_t * t);

Basic Types
-----------

.. code-block:: C

    // integers
    uint_t n = 10;                 // unsigned
    sint_t delay = -90;            // signed

    // float
    smpl_t a = -90.;               // simple precision
    lsmp_t f = 0.024;              // double precision

    // vector of floats (simple precision)
    fvec_t * vec = new_fvec(n);
    vec->data[0] = 1;
    vec->data[vec->length-1] = 1.; // vec->data has n elements
    fvec_print(vec);
    del_fvec(vec);

    // complex data
    cvec_t * fftgrain = new_cvec(n);
    vec->norm[0] = 1.;             // vec->norm has n/2+1 elements
    vec->phas[n/2] = 3.1415;       // vec->phas as well
    del_cvec(fftgrain);

    // matrix
    fmat_t * mat = new_fmat (height, length);
    mat->data[height-1][0] = 1;    // mat->data has height rows
    mat->data[0][length-1] = 10;   // mat->data[0] has length columns
    del_fmat(mat);


Reading a sound file
--------------------

In this example, `aubio_source <https://aubio.org/doc/latest/source_8h.html>`_
is used to read a media file.

First, define a few variables and allocate some memory.

.. literalinclude:: ../tests/src/io/test-source.c
   :language: C
   :lines: 22-24, 30-32, 34

.. note::
   With ``samplerate = 0``, ``aubio_source`` will be created with the file's
   original samplerate.

Now for the processing loop:

.. literalinclude:: ../tests/src/io/test-source.c
   :language: C
   :lines: 40-44

At the end of the processing loop, memory is deallocated:

.. literalinclude:: ../tests/src/io/test-source.c
   :language: C
   :lines: 55-56

See the complete example: :download:`test-source.c
<../tests/src/io/test-source.c>`.

Computing a spectrum
--------------------

Now let's create a phase vocoder:

.. literalinclude:: ../tests/src/spectral/test-phasevoc.c
   :language: C
   :lines: 6-11

The processing loop could now look like:

.. literalinclude:: ../tests/src/spectral/test-phasevoc.c
   :language: C
   :lines: 20-37

Time to clean up the previously allocated memory:

.. literalinclude:: ../tests/src/spectral/test-phasevoc.c
   :language: C
   :lines: 39-44

See the complete example: :download:`test-phasevoc.c
<../tests/src/spectral/test-phasevoc.c>`.

.. _doxygen-documentation:

Doxygen documentation
---------------------

The latest version of the API documentation is built using `Doxygen
<http://www.doxygen.org/>`_ and is available at:

    https://aubio.org/doc/latest/

Contribute
----------

Please report any issue and feature request at the `Github issue tracker
<https://github.com/aubio/aubio/issues>`_. Patches and pull-requests welcome!