#include "pitch/pitchspecacf.h"
#include "pitch/pitch.h"
+#define DEFAULT_PITCH_SILENCE -50.
+
/** pitch detection algorithms */
typedef enum
{
aubio_pitch_detect_t detect_cb; /**< callback to get the pitch candidates */
aubio_pitch_convert_t conv_cb; /**< callback to convert it to the desired unit */
aubio_pitch_get_conf_t conf_cb; /**< pointer to the current confidence callback */
+ smpl_t silence; /**< silence threshold */
};
/* callback functions for pitch detection */
p->type = pitch_type;
aubio_pitch_set_unit (p, "default");
p->bufsize = bufsize;
+ p->silence = DEFAULT_PITCH_SILENCE;
p->conf_cb = NULL;
switch (p->type) {
case aubio_pitcht_yin:
uint_t
aubio_pitch_set_unit (aubio_pitch_t * p, char_t * pitch_unit)
{
+ uint_t err = AUBIO_OK;
aubio_pitch_mode pitch_mode;
if (strcmp (pitch_unit, "freq") == 0)
pitch_mode = aubio_pitchm_freq;
+ else if (strcmp (pitch_unit, "hertz") == 0)
+ pitch_mode = aubio_pitchm_freq;
+ else if (strcmp (pitch_unit, "Hz") == 0)
+ pitch_mode = aubio_pitchm_freq;
+ else if (strcmp (pitch_unit, "f0") == 0)
+ pitch_mode = aubio_pitchm_freq;
else if (strcmp (pitch_unit, "midi") == 0)
pitch_mode = aubio_pitchm_midi;
else if (strcmp (pitch_unit, "cent") == 0)
else {
AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit);
pitch_mode = aubio_pitchm_default;
+ err = AUBIO_FAIL;
}
p->mode = pitch_mode;
switch (p->mode) {
default:
break;
}
- return AUBIO_OK;
+ return err;
}
uint_t
return AUBIO_OK;
}
+uint_t
+aubio_pitch_set_silence (aubio_pitch_t * p, smpl_t silence)
+{
+ if (silence < 0 && silence > -200) {
+ p->silence = silence;
+ return AUBIO_OK;
+ } else {
+ AUBIO_ERR("pitch: could do set silence to %.2f", silence);
+ return AUBIO_FAIL;
+ }
+}
+
+smpl_t
+aubio_pitch_get_silence (aubio_pitch_t * p)
+{
+ return p->silence;
+}
+
/* do method, calling the detection callback, then the conversion callback */
void
aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
{
p->detect_cb (p, ibuf, obuf);
+ if (aubio_silence_detection(ibuf, p->silence) == 1) {
+ obuf->data[0] = 0.;
+ }
obuf->data[0] = p->conv_cb (obuf->data[0], p->samplerate, p->bufsize);
}