source: src/musicutils.c

Last change on this file was ff9c62a, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[api] add meltohz and hztomel, Slaney and Htk versions

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2  Copyright (C) 2018 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 "aubio_priv.h"
22#include "musicutils.h"
23
24smpl_t
25aubio_hztomel (smpl_t freq)
26{
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.);
31  if (freq < 0) {
32    AUBIO_WRN("hztomel: input frequency should be >= 0\n");
33    return 0;
34  }
35  if (freq < split_hz)
36  {
37    return freq * lin_space;
38  } else {
39    return split_mel + log_space * LOG (freq / split_hz);
40  }
41
42}
43
44smpl_t
45aubio_meltohz (smpl_t mel)
46{
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.);
51  if (mel < 0) {
52    AUBIO_WRN("meltohz: input mel should be >= 0\n");
53    return 0;
54  }
55  if (mel < split_mel) {
56    return lin_space * mel;
57  } else {
58    return split_hz * POW(logSpacing, mel - split_mel);
59  }
60}
61
62smpl_t
63aubio_hztomel_htk (smpl_t freq)
64{
65  const smpl_t split_hz = 700.;
66  const smpl_t log_space = 1127.;
67  if (freq < 0) {
68    AUBIO_WRN("hztomel_htk: input frequency should be >= 0\n");
69    return 0;
70  }
71  return log_space * LOG (1 + freq / split_hz);
72}
73
74smpl_t
75aubio_meltohz_htk (smpl_t mel)
76{
77  const smpl_t split_hz = 700.;
78  const smpl_t log_space = 1./1127.;
79  if (mel < 0) {
80    AUBIO_WRN("meltohz_htk: input frequency should be >= 0\n");
81    return 0;
82  }
83  return split_hz * ( EXP ( mel * log_space) - 1.);
84}
85
Note: See TracBrowser for help on using the repository browser.