source: examples/aubiopitch.c @ b0b167a

feature/crepe_org
Last change on this file since b0b167a was 6b84d81, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[examples] remove unneeded cast

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[b14107f]1/*
[466dff3]2  Copyright (C) 2003-2013 Paul Brossier <piem@aubio.org>
[b14107f]3
[6a2478c]4  This file is part of aubio.
[b14107f]5
[6a2478c]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/>.
[b14107f]18
19*/
20
21#include "utils.h"
[1b25a70]22#define PROG_HAS_PITCH 1
[3da8187]23#define PROG_HAS_OUTPUT 1
[82ae9d7]24#define PROG_HAS_SILENCE 1
[3da8187]25#define PROG_HAS_JACK 1
[1b25a70]26#include "parse_args.h"
[b14107f]27
28aubio_pitch_t *o;
[f3617e7]29aubio_wavetable_t *wavetable;
[b14107f]30fvec_t *pitch;
31
[d389e23]32void process_block(fvec_t * ibuf, fvec_t * obuf)
33{
[fe87823]34  smpl_t freq;
[466dff3]35  aubio_pitch_do (o, ibuf, pitch);
[f4adefaa]36  if ( !usejack && ! sink_uri ) return;
37  fvec_zeros(obuf);
[fe87823]38  freq = fvec_get_sample(pitch, 0);
[466dff3]39  aubio_wavetable_set_amp ( wavetable, aubio_level_lin (ibuf) );
[3da8187]40  aubio_wavetable_set_freq ( wavetable, freq );
41  if (mix_input)
42    aubio_wavetable_do (wavetable, ibuf, obuf);
43  else
44    aubio_wavetable_do (wavetable, obuf, obuf);
[b14107f]45}
46
[d389e23]47void process_print (void)
48{
[c34336e]49  smpl_t pitch_found = fvec_get_sample(pitch, 0);
[340cb93]50  print_time(blocks * hop_size);
51  outmsg(" %f\n", pitch_found);
[b14107f]52}
53
54int main(int argc, char **argv) {
[61a1e5d]55  int ret = 0;
[fe6a393a]56
57  buffer_size = 2048;
58
[b14107f]59  examples_common_init(argc,argv);
60
[466dff3]61  verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
62  verbmsg ("pitch method: %s, ", pitch_method);
[134cd3a]63  verbmsg ("pitch unit: %s, ", pitch_unit);
[466dff3]64  verbmsg ("buffer_size: %d, ", buffer_size);
65  verbmsg ("hop_size: %d, ", hop_size);
66  verbmsg ("tolerance: %f\n", pitch_tolerance);
67
68  o = new_aubio_pitch (pitch_method, buffer_size, hop_size, samplerate);
[61a1e5d]69  if (o == NULL) { ret = 1; goto beach; }
[d626fac]70  if (pitch_tolerance != 0.)
71    aubio_pitch_set_tolerance (o, pitch_tolerance);
72  if (silence_threshold != -90.)
73    aubio_pitch_set_silence (o, silence_threshold);
74  if (pitch_unit != NULL)
75    aubio_pitch_set_unit (o, pitch_unit);
[c34336e]76
[4621cd6]77  pitch = new_fvec (1);
[b14107f]78
[466dff3]79  wavetable = new_aubio_wavetable (samplerate, hop_size);
[f3617e7]80  aubio_wavetable_play ( wavetable );
81
[6b84d81]82  examples_common_process(process_block, process_print);
[b14107f]83
84  del_aubio_pitch (o);
[f3617e7]85  del_aubio_wavetable (wavetable);
[b14107f]86  del_fvec (pitch);
87
[61a1e5d]88beach:
[b14107f]89  examples_common_del();
[61a1e5d]90  return ret;
[b14107f]91}
Note: See TracBrowser for help on using the repository browser.