2 Copyright (C) 2018 Paul Brossier <piem@aubio.org>
4 This file is part of aubio.
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.
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.
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/>.
21 #include "aubio_priv.h"
22 #include "musicutils.h"
25 aubio_hztomel (smpl_t freq)
27 const smpl_t lin_space = 3./200.;
28 const smpl_t split_hz = 1000.;
29 const smpl_t split_mel = split_hz * lin_space;
30 const smpl_t log_space = 27./LOG(6400/1000.);
32 AUBIO_WRN("hztomel: input frequency should be >= 0\n");
37 return freq * lin_space;
39 return split_mel + log_space * LOG (freq / split_hz);
45 aubio_meltohz (smpl_t mel)
47 const smpl_t lin_space = 200./3.;
48 const smpl_t split_hz = 1000.;
49 const smpl_t split_mel = split_hz / lin_space;
50 const smpl_t logSpacing = POW(6400/1000., 1/27.);
52 AUBIO_WRN("meltohz: input mel should be >= 0\n");
55 if (mel < split_mel) {
56 return lin_space * mel;
58 return split_hz * POW(logSpacing, mel - split_mel);
63 aubio_hztomel_htk (smpl_t freq)
65 const smpl_t split_hz = 700.;
66 const smpl_t log_space = 1127.;
68 AUBIO_WRN("hztomel_htk: input frequency should be >= 0\n");
71 return log_space * LOG (1 + freq / split_hz);
75 aubio_meltohz_htk (smpl_t mel)
77 const smpl_t split_hz = 700.;
78 const smpl_t log_space = 1./1127.;
80 AUBIO_WRN("meltohz_htk: input frequency should be >= 0\n");
83 return split_hz * ( EXP ( mel * log_space) - 1.);