source: examples/aubionotes.c @ 81abf91

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

[tools] add release_drop option to aubionotes

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
3
4  This file is part of aubio.
5
6  aubio is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10
11  aubio is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15
16  You should have received a copy of the GNU General Public License
17  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
18
19*/
20
21#include "utils.h"
22#define PROG_HAS_PITCH 1
23#define PROG_HAS_ONSET 1
24#define PROG_HAS_NOTES 1
25#define PROG_HAS_SILENCE 1
26#define PROG_HAS_JACK 1
27// TODO add PROG_HAS_OUTPUT
28#include "parse_args.h"
29
30aubio_notes_t *notes;
31smpl_t lastmidi = 0.;
32
33void process_block (fvec_t *ibuf, fvec_t *obuf)
34{
35  aubio_notes_do (notes, ibuf, obuf);
36  // did we get a note off?
37  if (obuf->data[2] != 0) {
38    lastmidi = obuf->data[2];
39    send_noteon(lastmidi, 0);
40  }
41  // did we get a note on?
42  if (obuf->data[0] != 0) {
43    lastmidi = obuf->data[0];
44    send_noteon(lastmidi, obuf->data[1]);
45  }
46}
47
48void process_print (void)
49{
50  //if (verbose) outmsg("%f\n",pitch_obuf->data[0]);
51}
52
53int main(int argc, char **argv) {
54  int ret = 0;
55
56  examples_common_init(argc,argv);
57
58  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
59
60  verbmsg ("onset method: %s, ", onset_method);
61  verbmsg ("buffer_size: %d, ", buffer_size);
62  verbmsg ("hop_size: %d, ", hop_size);
63  verbmsg ("threshold: %f\n", onset_threshold);
64
65  verbmsg ("pitch method: %s, ", pitch_method);
66  verbmsg ("buffer_size: %d, ", buffer_size * 4);
67  verbmsg ("hop_size: %d, ", hop_size);
68  verbmsg ("tolerance: %f\n", pitch_tolerance);
69
70  notes = new_aubio_notes ("default", buffer_size, hop_size, samplerate);
71  if (notes == NULL) { ret = 1; goto beach; }
72
73  if (onset_minioi != 0.) {
74    aubio_notes_set_minioi_ms(notes, onset_minioi);
75  }
76  if (onset_threshold != 0.) {
77    errmsg ("warning: onset threshold not supported yet\n");
78    //aubio_onset_set_threshold(aubio_notes_get_aubio_onset(o), onset_threshold);
79  }
80  if (silence_threshold != -90.) {
81    if (aubio_notes_set_silence (notes, silence_threshold) != 0) {
82      errmsg ("failed setting notes silence threshold to %.2f\n",
83          silence_threshold);
84    }
85  }
86  if (release_drop != 10.) {
87    if (aubio_notes_set_release_drop (notes, release_drop) != 0) {
88      errmsg ("failed setting notes release drop to %.2f\n",
89          release_drop);
90    }
91  }
92
93  examples_common_process((aubio_process_func_t)process_block, process_print);
94
95  // send a last note off if required
96  if (lastmidi) {
97    send_noteon (lastmidi, 0);
98  }
99
100  del_aubio_notes (notes);
101
102beach:
103  examples_common_del();
104  return ret;
105}
Note: See TracBrowser for help on using the repository browser.