ex
Fork of mbed-os-example-mbed5-blinky by
DuerOS-Light-SDK-v1.1.0/duer-os-light/external/speex/libspeex/vorbis_psy.h@47:9e361da97763, 2017-07-18 (annotated)
- Committer:
- TMBOY
- Date:
- Tue Jul 18 16:54:45 2017 +0800
- Revision:
- 47:9e361da97763
?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| TMBOY | 47:9e361da97763 | 1 | /* Copyright (C) 2005 Jean-Marc Valin, CSIRO, Christopher Montgomery |
| TMBOY | 47:9e361da97763 | 2 | File: vorbis_psy.h |
| TMBOY | 47:9e361da97763 | 3 | |
| TMBOY | 47:9e361da97763 | 4 | Redistribution and use in source and binary forms, with or without |
| TMBOY | 47:9e361da97763 | 5 | modification, are permitted provided that the following conditions |
| TMBOY | 47:9e361da97763 | 6 | are met: |
| TMBOY | 47:9e361da97763 | 7 | |
| TMBOY | 47:9e361da97763 | 8 | - Redistributions of source code must retain the above copyright |
| TMBOY | 47:9e361da97763 | 9 | notice, this list of conditions and the following disclaimer. |
| TMBOY | 47:9e361da97763 | 10 | |
| TMBOY | 47:9e361da97763 | 11 | - Redistributions in binary form must reproduce the above copyright |
| TMBOY | 47:9e361da97763 | 12 | notice, this list of conditions and the following disclaimer in the |
| TMBOY | 47:9e361da97763 | 13 | documentation and/or other materials provided with the distribution. |
| TMBOY | 47:9e361da97763 | 14 | |
| TMBOY | 47:9e361da97763 | 15 | - Neither the name of the Xiph.org Foundation nor the names of its |
| TMBOY | 47:9e361da97763 | 16 | contributors may be used to endorse or promote products derived from |
| TMBOY | 47:9e361da97763 | 17 | this software without specific prior written permission. |
| TMBOY | 47:9e361da97763 | 18 | |
| TMBOY | 47:9e361da97763 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| TMBOY | 47:9e361da97763 | 20 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| TMBOY | 47:9e361da97763 | 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| TMBOY | 47:9e361da97763 | 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR |
| TMBOY | 47:9e361da97763 | 23 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| TMBOY | 47:9e361da97763 | 24 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| TMBOY | 47:9e361da97763 | 25 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| TMBOY | 47:9e361da97763 | 26 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| TMBOY | 47:9e361da97763 | 27 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| TMBOY | 47:9e361da97763 | 28 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| TMBOY | 47:9e361da97763 | 29 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| TMBOY | 47:9e361da97763 | 30 | */ |
| TMBOY | 47:9e361da97763 | 31 | |
| TMBOY | 47:9e361da97763 | 32 | #ifndef VORBIS_PSY_H |
| TMBOY | 47:9e361da97763 | 33 | #define VORBIS_PSY_H |
| TMBOY | 47:9e361da97763 | 34 | |
| TMBOY | 47:9e361da97763 | 35 | #ifdef VORBIS_PSYCHO |
| TMBOY | 47:9e361da97763 | 36 | |
| TMBOY | 47:9e361da97763 | 37 | #include "smallft.h" |
| TMBOY | 47:9e361da97763 | 38 | #define P_BANDS 17 /* 62Hz to 16kHz */ |
| TMBOY | 47:9e361da97763 | 39 | #define NOISE_COMPAND_LEVELS 40 |
| TMBOY | 47:9e361da97763 | 40 | |
| TMBOY | 47:9e361da97763 | 41 | |
| TMBOY | 47:9e361da97763 | 42 | #define todB(x) ((x)==0?-400.f:log((x)*(x))*4.34294480f) |
| TMBOY | 47:9e361da97763 | 43 | #define fromdB(x) (exp((x)*.11512925f)) |
| TMBOY | 47:9e361da97763 | 44 | |
| TMBOY | 47:9e361da97763 | 45 | /* The bark scale equations are approximations, since the original |
| TMBOY | 47:9e361da97763 | 46 | table was somewhat hand rolled. The below are chosen to have the |
| TMBOY | 47:9e361da97763 | 47 | best possible fit to the rolled tables, thus their somewhat odd |
| TMBOY | 47:9e361da97763 | 48 | appearance (these are more accurate and over a longer range than |
| TMBOY | 47:9e361da97763 | 49 | the oft-quoted bark equations found in the texts I have). The |
| TMBOY | 47:9e361da97763 | 50 | approximations are valid from 0 - 30kHz (nyquist) or so. |
| TMBOY | 47:9e361da97763 | 51 | |
| TMBOY | 47:9e361da97763 | 52 | all f in Hz, z in Bark */ |
| TMBOY | 47:9e361da97763 | 53 | |
| TMBOY | 47:9e361da97763 | 54 | #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n)) |
| TMBOY | 47:9e361da97763 | 55 | #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f) |
| TMBOY | 47:9e361da97763 | 56 | |
| TMBOY | 47:9e361da97763 | 57 | /* Frequency to octave. We arbitrarily declare 63.5 Hz to be octave |
| TMBOY | 47:9e361da97763 | 58 | 0.0 */ |
| TMBOY | 47:9e361da97763 | 59 | |
| TMBOY | 47:9e361da97763 | 60 | #define toOC(n) (log(n)*1.442695f-5.965784f) |
| TMBOY | 47:9e361da97763 | 61 | #define fromOC(o) (exp(((o)+5.965784f)*.693147f)) |
| TMBOY | 47:9e361da97763 | 62 | |
| TMBOY | 47:9e361da97763 | 63 | |
| TMBOY | 47:9e361da97763 | 64 | typedef struct { |
| TMBOY | 47:9e361da97763 | 65 | |
| TMBOY | 47:9e361da97763 | 66 | float noisewindowlo; |
| TMBOY | 47:9e361da97763 | 67 | float noisewindowhi; |
| TMBOY | 47:9e361da97763 | 68 | int noisewindowlomin; |
| TMBOY | 47:9e361da97763 | 69 | int noisewindowhimin; |
| TMBOY | 47:9e361da97763 | 70 | int noisewindowfixed; |
| TMBOY | 47:9e361da97763 | 71 | float noiseoff[P_BANDS]; |
| TMBOY | 47:9e361da97763 | 72 | float noisecompand[NOISE_COMPAND_LEVELS]; |
| TMBOY | 47:9e361da97763 | 73 | |
| TMBOY | 47:9e361da97763 | 74 | } VorbisPsyInfo; |
| TMBOY | 47:9e361da97763 | 75 | |
| TMBOY | 47:9e361da97763 | 76 | |
| TMBOY | 47:9e361da97763 | 77 | |
| TMBOY | 47:9e361da97763 | 78 | typedef struct { |
| TMBOY | 47:9e361da97763 | 79 | int n; |
| TMBOY | 47:9e361da97763 | 80 | int rate; |
| TMBOY | 47:9e361da97763 | 81 | struct drft_lookup lookup; |
| TMBOY | 47:9e361da97763 | 82 | VorbisPsyInfo *vi; |
| TMBOY | 47:9e361da97763 | 83 | |
| TMBOY | 47:9e361da97763 | 84 | float *window; |
| TMBOY | 47:9e361da97763 | 85 | float *noiseoffset; |
| TMBOY | 47:9e361da97763 | 86 | long *bark; |
| TMBOY | 47:9e361da97763 | 87 | |
| TMBOY | 47:9e361da97763 | 88 | } VorbisPsy; |
| TMBOY | 47:9e361da97763 | 89 | |
| TMBOY | 47:9e361da97763 | 90 | |
| TMBOY | 47:9e361da97763 | 91 | VorbisPsy *vorbis_psy_init(int rate, int size); |
| TMBOY | 47:9e361da97763 | 92 | void vorbis_psy_destroy(VorbisPsy *psy); |
| TMBOY | 47:9e361da97763 | 93 | void compute_curve(VorbisPsy *psy, float *audio, float *curve); |
| TMBOY | 47:9e361da97763 | 94 | void curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int ord); |
| TMBOY | 47:9e361da97763 | 95 | |
| TMBOY | 47:9e361da97763 | 96 | #endif |
| TMBOY | 47:9e361da97763 | 97 | #endif |
