From 512ab153d3232712713dd87bd0398ea6140dfc31 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Wed, 9 Apr 2014 01:27:38 -0300 Subject: [PATCH] src/notes/notes.c: add notes object basics --- src/aubio.h | 1 + src/notes/notes.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/notes/notes.h | 55 +++++++++++++++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 src/notes/notes.c create mode 100644 src/notes/notes.h diff --git a/src/aubio.h b/src/aubio.h index c615dd93..29082876 100644 --- a/src/aubio.h +++ b/src/aubio.h @@ -182,6 +182,7 @@ extern "C" #include "pitch/pitch.h" #include "onset/onset.h" #include "tempo/tempo.h" +#include "notes/notes.h" #include "io/source.h" #include "io/sink.h" #include "synth/sampler.h" diff --git a/src/notes/notes.c b/src/notes/notes.c new file mode 100644 index 00000000..67726836 --- /dev/null +++ b/src/notes/notes.c @@ -0,0 +1,82 @@ +/* + Copyright (C) 2014 Paul Brossier + + This file is part of aubio. + + aubio is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + aubio is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with aubio. If not, see . + +*/ + +#include "aubio_priv.h" +#include "fvec.h" +#include "pitch/pitch.h" +#include "onset/onset.h" +#include "notes/notes.h" + +struct _aubio_notes_t { + + uint_t onset_buf_size; + uint_t pitch_buf_size; + uint_t hop_size; + + uint_t samplerate; + + uint_t median; + fvec_t *note_buffer; + fvec_t *note_buffer2; + + aubio_pitch_t *pitch; + aubio_onset_t *onset; + fvec_t *onset_output; + fvec_t *pitch_output; + + smpl_t curnote; + smpl_t newnote; +}; + +aubio_notes_t * new_aubio_notes (char_t * notes_method, + uint_t buf_size, uint_t hop_size, uint_t samplerate) { + aubio_notes_t *o = AUBIO_NEW(aubio_notes_t); + + o->onset_buf_size = buf_size; + o->pitch_buf_size = buf_size * 4; + o->hop_size = hop_size; + + o->samplerate = samplerate; + + o->median = 9; + + if (strcmp(notes_method, "default") != 0) { + AUBIO_ERR("unknown notes detection method %s, using default.\n", + notes_method); + goto fail; + } + o->note_buffer = new_fvec(o->median); + o->note_buffer2 = new_fvec(o->median); + + o->curnote = -1.; + o->newnote = -1.; + + return o; + +fail: + del_aubio_notes(o); + return NULL; +} + +void del_aubio_notes (aubio_notes_t *o) { + if (o->note_buffer) del_fvec(o->note_buffer); + if (o->note_buffer2) del_fvec(o->note_buffer2); + AUBIO_FREE(o); +} diff --git a/src/notes/notes.h b/src/notes/notes.h new file mode 100644 index 00000000..fc8c5997 --- /dev/null +++ b/src/notes/notes.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2003-2014 Paul Brossier + + This file is part of aubio. + + aubio is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + aubio is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with aubio. If not, see . + +*/ + +#ifndef _AUBIO_NOTES_H +#define _AUBIO_NOTES_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** notes detection object */ +typedef struct _aubio_notes_t aubio_notes_t; + +/** create notes detection object + + \param method notes detection type as specified in specdesc.h + \param buf_size buffer size for phase vocoder + \param hop_size hop size for phase vocoder + \param samplerate sampling rate of the input signal + + \return newly created ::aubio_notes_t + +*/ +aubio_notes_t * new_aubio_notes (char_t * notes_method, + uint_t buf_size, uint_t hop_size, uint_t samplerate); + +/** delete notes detection object + + \param o notes detection object to delete + +*/ +void del_aubio_notes(aubio_notes_t * o); + +#ifdef __cplusplus +} +#endif + +#endif /* _AUBIO_NOTES_H */ -- 2.11.0