├── README.md ├── speex.sln ├── speexdsp-1.2rc3 ├── include │ ├── Makefile.am │ ├── Makefile.in │ ├── config.h │ └── speex │ │ ├── Makefile.am │ │ ├── Makefile.in │ │ ├── speex_buffer.h │ │ ├── speex_echo.h │ │ ├── speex_jitter.h │ │ ├── speex_preprocess.h │ │ ├── speex_resampler.h │ │ ├── speexdsp_config_types.h.in │ │ └── speexdsp_types.h └── libspeexdsp │ ├── Makefile.am │ ├── Makefile.in │ ├── _kiss_fft_guts.h │ ├── arch.h │ ├── bfin.h │ ├── buffer.c │ ├── echo_diagnostic.m │ ├── fftwrap.c │ ├── fftwrap.h │ ├── filterbank.c │ ├── filterbank.h │ ├── fixed_arm4.h │ ├── fixed_arm5e.h │ ├── fixed_bfin.h │ ├── fixed_debug.h │ ├── fixed_generic.h │ ├── jitter.c │ ├── kiss_fft.c │ ├── kiss_fft.h │ ├── kiss_fftr.c │ ├── kiss_fftr.h │ ├── math_approx.h │ ├── mdf.c │ ├── misc_bfin.h │ ├── os_support.h │ ├── preprocess.c │ ├── pseudofloat.h │ ├── resample.c │ ├── resample_neon.h │ ├── resample_sse.h │ ├── scal.c │ ├── smallft.c │ ├── smallft.h │ ├── stack_alloc.h │ ├── testdenoise.c │ ├── testecho.c │ ├── testjitter.c │ ├── testresample.c │ └── vorbis_psy.h ├── testecho_mono ├── micin_16k_s16_mono.pcm ├── micin_32k_s16_mono.pcm ├── micin_48k_s16_mono.pcm ├── micin_8k_s16_mono.pcm ├── speaker_16k_s16_mono.pcm ├── speaker_32k_s16_mono.pcm ├── speaker_48k_s16_mono.pcm ├── speaker_8k_s16_mono.pcm ├── targetver.h ├── testecho.vcxproj ├── testecho.vcxproj.filters ├── testecho.vcxproj.user └── testecho_mono.cpp └── testecho_stereo ├── far48_stereo.pcm ├── near48_stereo.pcm ├── stdafx.cpp ├── stdafx.h ├── targetver.h ├── testecho_stereo.cpp ├── testecho_stereo.vcxproj ├── testecho_stereo.vcxproj.filters └── testecho_stereo.vcxproj.user /README.md: -------------------------------------------------------------------------------- 1 | # speex 2 | Some demes using speex. 3 | -------------------------------------------------------------------------------- /speex.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testecho_mono", "testecho_mono\testecho.vcxproj", "{CC2E2FB7-EE9D-4AF6-BE9C-87C16F49B4A4}" 5 | EndProject 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testecho_stereo", "testecho_stereo\testecho_stereo.vcxproj", "{9FD6B0B3-2668-4F23-8587-969ABAB8499A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Win32 = Debug|Win32 11 | Release|Win32 = Release|Win32 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {CC2E2FB7-EE9D-4AF6-BE9C-87C16F49B4A4}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {CC2E2FB7-EE9D-4AF6-BE9C-87C16F49B4A4}.Debug|Win32.Build.0 = Debug|Win32 16 | {CC2E2FB7-EE9D-4AF6-BE9C-87C16F49B4A4}.Release|Win32.ActiveCfg = Release|Win32 17 | {CC2E2FB7-EE9D-4AF6-BE9C-87C16F49B4A4}.Release|Win32.Build.0 = Release|Win32 18 | {9FD6B0B3-2668-4F23-8587-969ABAB8499A}.Debug|Win32.ActiveCfg = Debug|Win32 19 | {9FD6B0B3-2668-4F23-8587-969ABAB8499A}.Debug|Win32.Build.0 = Debug|Win32 20 | {9FD6B0B3-2668-4F23-8587-969ABAB8499A}.Release|Win32.ActiveCfg = Release|Win32 21 | {9FD6B0B3-2668-4F23-8587-969ABAB8499A}.Release|Win32.Build.0 = Release|Win32 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/include/Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | SUBDIRS = speex 3 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/include/config.h: -------------------------------------------------------------------------------- 1 | // Microsoft version of 'inline' 2 | #define inline __inline 3 | 4 | // In Visual Studio, _M_IX86_FP=1 means /arch:SSE was used, likewise 5 | // _M_IX86_FP=2 means /arch:SSE2 was used. 6 | // Also, enable both _USE_SSE and _USE_SSE2 if we're compiling for x86-64 7 | #if _M_IX86_FP >= 1 || defined(_M_X64) 8 | #define _USE_SSE 9 | #endif 10 | 11 | #if _M_IX86_FP >= 2 || defined(_M_X64) 12 | #define _USE_SSE2 13 | #endif 14 | 15 | // Visual Studio support alloca(), but it always align variables to 16-bit 16 | // boundary, while SSE need 128-bit alignment. So we disable alloca() when 17 | // SSE is enabled. 18 | #ifndef _USE_SSE 19 | # define USE_ALLOCA 20 | #endif 21 | 22 | /* Default to floating point */ 23 | #ifndef FIXED_POINT 24 | # define FLOATING_POINT 25 | # define USE_SMALLFT 26 | #else 27 | # define USE_KISS_FFT 28 | #endif 29 | 30 | /* We don't support visibility on Win32 */ 31 | #define EXPORT 32 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/include/speex/Makefile.am: -------------------------------------------------------------------------------- 1 | # Disable automatic dependency tracking if using other tools than gcc and gmake 2 | #AUTOMAKE_OPTIONS = no-dependencies 3 | 4 | # Historically, these headers were part of the speex package, so in order to 5 | # keep compatibility with existing software we need to keep installing them 6 | # in the same place as they were found then. If new functionality, with new 7 | # headers, are added later, some thought should be given as to whether they 8 | # should instead go somewhere other than $prefix/include/speex. 9 | 10 | speexincludedir = $(includedir)/speex 11 | 12 | nodist_speexinclude_HEADERS = speexdsp_config_types.h 13 | 14 | speexinclude_HEADERS = speex_echo.h speex_jitter.h speex_preprocess.h speex_resampler.h \ 15 | speexdsp_types.h 16 | 17 | noinst_HEADERS=speex_buffer.h 18 | 19 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/include/speex/speex_buffer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007 Jean-Marc Valin 2 | 3 | File: speex_buffer.h 4 | This is a very simple ring buffer implementation. It is not thread-safe 5 | so you need to do your own locking. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef SPEEX_BUFFER_H 35 | #define SPEEX_BUFFER_H 36 | 37 | #include "speexdsp_types.h" 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | struct SpeexBuffer_; 44 | typedef struct SpeexBuffer_ SpeexBuffer; 45 | 46 | SpeexBuffer *speex_buffer_init(int size); 47 | 48 | void speex_buffer_destroy(SpeexBuffer *st); 49 | 50 | int speex_buffer_write(SpeexBuffer *st, void *data, int len); 51 | 52 | int speex_buffer_writezeros(SpeexBuffer *st, int len); 53 | 54 | int speex_buffer_read(SpeexBuffer *st, void *data, int len); 55 | 56 | int speex_buffer_get_available(SpeexBuffer *st); 57 | 58 | int speex_buffer_resize(SpeexBuffer *st, int len); 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/include/speex/speex_echo.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) Jean-Marc Valin */ 2 | /** 3 | @file speex_echo.h 4 | @brief Echo cancellation 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef SPEEX_ECHO_H 35 | #define SPEEX_ECHO_H 36 | /** @defgroup SpeexEchoState SpeexEchoState: Acoustic echo canceller 37 | * This is the acoustic echo canceller module. 38 | * @{ 39 | */ 40 | #include "speexdsp_types.h" 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | /** Obtain frame size used by the AEC */ 47 | #define SPEEX_ECHO_GET_FRAME_SIZE 3 48 | 49 | /** Set sampling rate */ 50 | #define SPEEX_ECHO_SET_SAMPLING_RATE 24 51 | /** Get sampling rate */ 52 | #define SPEEX_ECHO_GET_SAMPLING_RATE 25 53 | 54 | /* Can't set window sizes */ 55 | /** Get size of impulse response (int32) */ 56 | #define SPEEX_ECHO_GET_IMPULSE_RESPONSE_SIZE 27 57 | 58 | /* Can't set window content */ 59 | /** Get impulse response (int32[]) */ 60 | #define SPEEX_ECHO_GET_IMPULSE_RESPONSE 29 61 | 62 | /** Internal echo canceller state. Should never be accessed directly. */ 63 | struct SpeexEchoState_; 64 | 65 | /** @class SpeexEchoState 66 | * This holds the state of the echo canceller. You need one per channel. 67 | */ 68 | 69 | /** Internal echo canceller state. Should never be accessed directly. */ 70 | typedef struct SpeexEchoState_ SpeexEchoState; 71 | 72 | /** Creates a new echo canceller state 73 | * @param frame_size Number of samples to process at one time (should correspond to 10-20 ms) 74 | * @param filter_length Number of samples of echo to cancel (should generally correspond to 100-500 ms) 75 | * @return Newly-created echo canceller state 76 | */ 77 | SpeexEchoState *speex_echo_state_init(int frame_size, int filter_length); 78 | 79 | /** Creates a new multi-channel echo canceller state 80 | * @param frame_size Number of samples to process at one time (should correspond to 10-20 ms) 81 | * @param filter_length Number of samples of echo to cancel (should generally correspond to 100-500 ms) 82 | * @param nb_mic Number of microphone channels 83 | * @param nb_speakers Number of speaker channels 84 | * @return Newly-created echo canceller state 85 | */ 86 | SpeexEchoState *speex_echo_state_init_mc(int frame_size, int filter_length, int nb_mic, int nb_speakers); 87 | 88 | /** Destroys an echo canceller state 89 | * @param st Echo canceller state 90 | */ 91 | void speex_echo_state_destroy(SpeexEchoState *st); 92 | 93 | /** Performs echo cancellation a frame, based on the audio sent to the speaker (no delay is added 94 | * to playback in this form) 95 | * 96 | * @param st Echo canceller state 97 | * @param rec Signal from the microphone (near end + far end echo) 98 | * @param play Signal played to the speaker (received from far end) 99 | * @param out Returns near-end signal with echo removed 100 | */ 101 | void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *rec, const spx_int16_t *play, spx_int16_t *out); 102 | 103 | /** Performs echo cancellation a frame (deprecated) */ 104 | void speex_echo_cancel(SpeexEchoState *st, const spx_int16_t *rec, const spx_int16_t *play, spx_int16_t *out, spx_int32_t *Yout); 105 | 106 | /** Perform echo cancellation using internal playback buffer, which is delayed by two frames 107 | * to account for the delay introduced by most soundcards (but it could be off!) 108 | * @param st Echo canceller state 109 | * @param rec Signal from the microphone (near end + far end echo) 110 | * @param out Returns near-end signal with echo removed 111 | */ 112 | void speex_echo_capture(SpeexEchoState *st, const spx_int16_t *rec, spx_int16_t *out); 113 | 114 | /** Let the echo canceller know that a frame was just queued to the soundcard 115 | * @param st Echo canceller state 116 | * @param play Signal played to the speaker (received from far end) 117 | */ 118 | void speex_echo_playback(SpeexEchoState *st, const spx_int16_t *play); 119 | 120 | /** Reset the echo canceller to its original state 121 | * @param st Echo canceller state 122 | */ 123 | void speex_echo_state_reset(SpeexEchoState *st); 124 | 125 | /** Used like the ioctl function to control the echo canceller parameters 126 | * 127 | * @param st Echo canceller state 128 | * @param request ioctl-type request (one of the SPEEX_ECHO_* macros) 129 | * @param ptr Data exchanged to-from function 130 | * @return 0 if no error, -1 if request in unknown 131 | */ 132 | int speex_echo_ctl(SpeexEchoState *st, int request, void *ptr); 133 | 134 | 135 | 136 | struct SpeexDecorrState_; 137 | 138 | typedef struct SpeexDecorrState_ SpeexDecorrState; 139 | 140 | 141 | /** Create a state for the channel decorrelation algorithm 142 | This is useful for multi-channel echo cancellation only 143 | * @param rate Sampling rate 144 | * @param channels Number of channels (it's a bit pointless if you don't have at least 2) 145 | * @param frame_size Size of the frame to process at ones (counting samples *per* channel) 146 | */ 147 | SpeexDecorrState *speex_decorrelate_new(int rate, int channels, int frame_size); 148 | 149 | /** Remove correlation between the channels by modifying the phase and possibly 150 | adding noise in a way that is not (or little) perceptible. 151 | * @param st Decorrelator state 152 | * @param in Input audio in interleaved format 153 | * @param out Result of the decorrelation (out *may* alias in) 154 | * @param strength How much alteration of the audio to apply from 0 to 100. 155 | */ 156 | void speex_decorrelate(SpeexDecorrState *st, const spx_int16_t *in, spx_int16_t *out, int strength); 157 | 158 | /** Destroy a Decorrelation state 159 | * @param st State to destroy 160 | */ 161 | void speex_decorrelate_destroy(SpeexDecorrState *st); 162 | 163 | 164 | #ifdef __cplusplus 165 | } 166 | #endif 167 | 168 | 169 | /** @}*/ 170 | #endif 171 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/include/speex/speex_jitter.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 Jean-Marc Valin */ 2 | /** 3 | @file speex_jitter.h 4 | @brief Adaptive jitter buffer for Speex 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #ifndef SPEEX_JITTER_H 37 | #define SPEEX_JITTER_H 38 | /** @defgroup JitterBuffer JitterBuffer: Adaptive jitter buffer 39 | * This is the jitter buffer that reorders UDP/RTP packets and adjusts the buffer size 40 | * to maintain good quality and low latency. 41 | * @{ 42 | */ 43 | 44 | #include "speexdsp_types.h" 45 | 46 | #ifdef __cplusplus 47 | extern "C" { 48 | #endif 49 | 50 | /** Generic adaptive jitter buffer state */ 51 | struct JitterBuffer_; 52 | 53 | /** Generic adaptive jitter buffer state */ 54 | typedef struct JitterBuffer_ JitterBuffer; 55 | 56 | /** Definition of an incoming packet */ 57 | typedef struct _JitterBufferPacket JitterBufferPacket; 58 | 59 | /** Definition of an incoming packet */ 60 | struct _JitterBufferPacket { 61 | char *data; /**< Data bytes contained in the packet */ 62 | spx_uint32_t len; /**< Length of the packet in bytes */ 63 | spx_uint32_t timestamp; /**< Timestamp for the packet */ 64 | spx_uint32_t span; /**< Time covered by the packet (same units as timestamp) */ 65 | spx_uint16_t sequence; /**< RTP Sequence number if available (0 otherwise) */ 66 | spx_uint32_t user_data; /**< Put whatever data you like here (it's ignored by the jitter buffer) */ 67 | }; 68 | 69 | /** Packet has been retrieved */ 70 | #define JITTER_BUFFER_OK 0 71 | /** Packet is lost or is late */ 72 | #define JITTER_BUFFER_MISSING 1 73 | /** A "fake" packet is meant to be inserted here to increase buffering */ 74 | #define JITTER_BUFFER_INSERTION 2 75 | /** There was an error in the jitter buffer */ 76 | #define JITTER_BUFFER_INTERNAL_ERROR -1 77 | /** Invalid argument */ 78 | #define JITTER_BUFFER_BAD_ARGUMENT -2 79 | 80 | 81 | /** Set minimum amount of extra buffering required (margin) */ 82 | #define JITTER_BUFFER_SET_MARGIN 0 83 | /** Get minimum amount of extra buffering required (margin) */ 84 | #define JITTER_BUFFER_GET_MARGIN 1 85 | /* JITTER_BUFFER_SET_AVAILABLE_COUNT wouldn't make sense */ 86 | 87 | /** Get the amount of available packets currently buffered */ 88 | #define JITTER_BUFFER_GET_AVAILABLE_COUNT 3 89 | /** Included because of an early misspelling (will remove in next release) */ 90 | #define JITTER_BUFFER_GET_AVALIABLE_COUNT 3 91 | 92 | /** Assign a function to destroy unused packet. When setting that, the jitter 93 | buffer no longer copies packet data. */ 94 | #define JITTER_BUFFER_SET_DESTROY_CALLBACK 4 95 | /** */ 96 | #define JITTER_BUFFER_GET_DESTROY_CALLBACK 5 97 | 98 | /** Tell the jitter buffer to only adjust the delay in multiples of the step parameter provided */ 99 | #define JITTER_BUFFER_SET_DELAY_STEP 6 100 | /** */ 101 | #define JITTER_BUFFER_GET_DELAY_STEP 7 102 | 103 | /** Tell the jitter buffer to only do concealment in multiples of the size parameter provided */ 104 | #define JITTER_BUFFER_SET_CONCEALMENT_SIZE 8 105 | #define JITTER_BUFFER_GET_CONCEALMENT_SIZE 9 106 | 107 | /** Absolute max amount of loss that can be tolerated regardless of the delay. Typical loss 108 | should be half of that or less. */ 109 | #define JITTER_BUFFER_SET_MAX_LATE_RATE 10 110 | #define JITTER_BUFFER_GET_MAX_LATE_RATE 11 111 | 112 | /** Equivalent cost of one percent late packet in timestamp units */ 113 | #define JITTER_BUFFER_SET_LATE_COST 12 114 | #define JITTER_BUFFER_GET_LATE_COST 13 115 | 116 | 117 | /** Initialises jitter buffer 118 | * 119 | * @param step_size Starting value for the size of concleanment packets and delay 120 | adjustment steps. Can be changed at any time using JITTER_BUFFER_SET_DELAY_STEP 121 | and JITTER_BUFFER_GET_CONCEALMENT_SIZE. 122 | * @return Newly created jitter buffer state 123 | */ 124 | JitterBuffer *jitter_buffer_init(int step_size); 125 | 126 | /** Restores jitter buffer to its original state 127 | * 128 | * @param jitter Jitter buffer state 129 | */ 130 | void jitter_buffer_reset(JitterBuffer *jitter); 131 | 132 | /** Destroys jitter buffer 133 | * 134 | * @param jitter Jitter buffer state 135 | */ 136 | void jitter_buffer_destroy(JitterBuffer *jitter); 137 | 138 | /** Put one packet into the jitter buffer 139 | * 140 | * @param jitter Jitter buffer state 141 | * @param packet Incoming packet 142 | */ 143 | void jitter_buffer_put(JitterBuffer *jitter, const JitterBufferPacket *packet); 144 | 145 | /** Get one packet from the jitter buffer 146 | * 147 | * @param jitter Jitter buffer state 148 | * @param packet Returned packet 149 | * @param desired_span Number of samples (or units) we wish to get from the buffer (no guarantee) 150 | * @param current_timestamp Timestamp for the returned packet 151 | */ 152 | int jitter_buffer_get(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t desired_span, spx_int32_t *start_offset); 153 | 154 | /** Used right after jitter_buffer_get() to obtain another packet that would have the same timestamp. 155 | * This is mainly useful for media where a single "frame" can be split into several packets. 156 | * 157 | * @param jitter Jitter buffer state 158 | * @param packet Returned packet 159 | */ 160 | int jitter_buffer_get_another(JitterBuffer *jitter, JitterBufferPacket *packet); 161 | 162 | /** Get pointer timestamp of jitter buffer 163 | * 164 | * @param jitter Jitter buffer state 165 | */ 166 | int jitter_buffer_get_pointer_timestamp(JitterBuffer *jitter); 167 | 168 | /** Advance by one tick 169 | * 170 | * @param jitter Jitter buffer state 171 | */ 172 | void jitter_buffer_tick(JitterBuffer *jitter); 173 | 174 | /** Telling the jitter buffer about the remaining data in the application buffer 175 | * @param jitter Jitter buffer state 176 | * @param rem Amount of data buffered by the application (timestamp units) 177 | */ 178 | void jitter_buffer_remaining_span(JitterBuffer *jitter, spx_uint32_t rem); 179 | 180 | /** Used like the ioctl function to control the jitter buffer parameters 181 | * 182 | * @param jitter Jitter buffer state 183 | * @param request ioctl-type request (one of the JITTER_BUFFER_* macros) 184 | * @param ptr Data exchanged to-from function 185 | * @return 0 if no error, -1 if request in unknown 186 | */ 187 | int jitter_buffer_ctl(JitterBuffer *jitter, int request, void *ptr); 188 | 189 | int jitter_buffer_update_delay(JitterBuffer *jitter, JitterBufferPacket *packet, spx_int32_t *start_offset); 190 | 191 | /* @} */ 192 | 193 | #ifdef __cplusplus 194 | } 195 | #endif 196 | 197 | #endif 198 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/include/speex/speex_preprocess.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2003 Epic Games 2 | Written by Jean-Marc Valin */ 3 | /** 4 | * @file speex_preprocess.h 5 | * @brief Speex preprocessor. The preprocess can do noise suppression, 6 | * residual echo suppression (after using the echo canceller), automatic 7 | * gain control (AGC) and voice activity detection (VAD). 8 | */ 9 | /* 10 | Redistribution and use in source and binary forms, with or without 11 | modification, are permitted provided that the following conditions are 12 | met: 13 | 14 | 1. Redistributions of source code must retain the above copyright notice, 15 | this list of conditions and the following disclaimer. 16 | 17 | 2. Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | 21 | 3. The name of the author may not be used to endorse or promote products 22 | derived from this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 28 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 33 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 34 | POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #ifndef SPEEX_PREPROCESS_H 38 | #define SPEEX_PREPROCESS_H 39 | /** @defgroup SpeexPreprocessState SpeexPreprocessState: The Speex preprocessor 40 | * This is the Speex preprocessor. The preprocess can do noise suppression, 41 | * residual echo suppression (after using the echo canceller), automatic 42 | * gain control (AGC) and voice activity detection (VAD). 43 | * @{ 44 | */ 45 | 46 | #include "speexdsp_types.h" 47 | 48 | #ifdef __cplusplus 49 | extern "C" { 50 | #endif 51 | 52 | /** State of the preprocessor (one per channel). Should never be accessed directly. */ 53 | struct SpeexPreprocessState_; 54 | 55 | /** State of the preprocessor (one per channel). Should never be accessed directly. */ 56 | typedef struct SpeexPreprocessState_ SpeexPreprocessState; 57 | 58 | 59 | /** Creates a new preprocessing state. You MUST create one state per channel processed. 60 | * @param frame_size Number of samples to process at one time (should correspond to 10-20 ms). Must be 61 | * the same value as that used for the echo canceller for residual echo cancellation to work. 62 | * @param sampling_rate Sampling rate used for the input. 63 | * @return Newly created preprocessor state 64 | */ 65 | SpeexPreprocessState *speex_preprocess_state_init(int frame_size, int sampling_rate); 66 | 67 | /** Destroys a preprocessor state 68 | * @param st Preprocessor state to destroy 69 | */ 70 | void speex_preprocess_state_destroy(SpeexPreprocessState *st); 71 | 72 | /** Preprocess a frame 73 | * @param st Preprocessor state 74 | * @param x Audio sample vector (in and out). Must be same size as specified in speex_preprocess_state_init(). 75 | * @return Bool value for voice activity (1 for speech, 0 for noise/silence), ONLY if VAD turned on. 76 | */ 77 | int speex_preprocess_run(SpeexPreprocessState *st, spx_int16_t *x); 78 | 79 | /** Preprocess a frame (deprecated, use speex_preprocess_run() instead)*/ 80 | int speex_preprocess(SpeexPreprocessState *st, spx_int16_t *x, spx_int32_t *echo); 81 | 82 | /** Update preprocessor state, but do not compute the output 83 | * @param st Preprocessor state 84 | * @param x Audio sample vector (in only). Must be same size as specified in speex_preprocess_state_init(). 85 | */ 86 | void speex_preprocess_estimate_update(SpeexPreprocessState *st, spx_int16_t *x); 87 | 88 | /** Used like the ioctl function to control the preprocessor parameters 89 | * @param st Preprocessor state 90 | * @param request ioctl-type request (one of the SPEEX_PREPROCESS_* macros) 91 | * @param ptr Data exchanged to-from function 92 | * @return 0 if no error, -1 if request in unknown 93 | */ 94 | int speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr); 95 | 96 | 97 | 98 | /** Set preprocessor denoiser state */ 99 | #define SPEEX_PREPROCESS_SET_DENOISE 0 100 | /** Get preprocessor denoiser state */ 101 | #define SPEEX_PREPROCESS_GET_DENOISE 1 102 | 103 | /** Set preprocessor Automatic Gain Control state */ 104 | #define SPEEX_PREPROCESS_SET_AGC 2 105 | /** Get preprocessor Automatic Gain Control state */ 106 | #define SPEEX_PREPROCESS_GET_AGC 3 107 | 108 | /** Set preprocessor Voice Activity Detection state */ 109 | #define SPEEX_PREPROCESS_SET_VAD 4 110 | /** Get preprocessor Voice Activity Detection state */ 111 | #define SPEEX_PREPROCESS_GET_VAD 5 112 | 113 | /** Set preprocessor Automatic Gain Control level (float) */ 114 | #define SPEEX_PREPROCESS_SET_AGC_LEVEL 6 115 | /** Get preprocessor Automatic Gain Control level (float) */ 116 | #define SPEEX_PREPROCESS_GET_AGC_LEVEL 7 117 | 118 | /** Set preprocessor dereverb state */ 119 | #define SPEEX_PREPROCESS_SET_DEREVERB 8 120 | /** Get preprocessor dereverb state */ 121 | #define SPEEX_PREPROCESS_GET_DEREVERB 9 122 | 123 | /** Set preprocessor dereverb level */ 124 | #define SPEEX_PREPROCESS_SET_DEREVERB_LEVEL 10 125 | /** Get preprocessor dereverb level */ 126 | #define SPEEX_PREPROCESS_GET_DEREVERB_LEVEL 11 127 | 128 | /** Set preprocessor dereverb decay */ 129 | #define SPEEX_PREPROCESS_SET_DEREVERB_DECAY 12 130 | /** Get preprocessor dereverb decay */ 131 | #define SPEEX_PREPROCESS_GET_DEREVERB_DECAY 13 132 | 133 | /** Set probability required for the VAD to go from silence to voice */ 134 | #define SPEEX_PREPROCESS_SET_PROB_START 14 135 | /** Get probability required for the VAD to go from silence to voice */ 136 | #define SPEEX_PREPROCESS_GET_PROB_START 15 137 | 138 | /** Set probability required for the VAD to stay in the voice state (integer percent) */ 139 | #define SPEEX_PREPROCESS_SET_PROB_CONTINUE 16 140 | /** Get probability required for the VAD to stay in the voice state (integer percent) */ 141 | #define SPEEX_PREPROCESS_GET_PROB_CONTINUE 17 142 | 143 | /** Set maximum attenuation of the noise in dB (negative number) */ 144 | #define SPEEX_PREPROCESS_SET_NOISE_SUPPRESS 18 145 | /** Get maximum attenuation of the noise in dB (negative number) */ 146 | #define SPEEX_PREPROCESS_GET_NOISE_SUPPRESS 19 147 | 148 | /** Set maximum attenuation of the residual echo in dB (negative number) */ 149 | #define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS 20 150 | /** Get maximum attenuation of the residual echo in dB (negative number) */ 151 | #define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS 21 152 | 153 | /** Set maximum attenuation of the residual echo in dB when near end is active (negative number) */ 154 | #define SPEEX_PREPROCESS_SET_ECHO_SUPPRESS_ACTIVE 22 155 | /** Get maximum attenuation of the residual echo in dB when near end is active (negative number) */ 156 | #define SPEEX_PREPROCESS_GET_ECHO_SUPPRESS_ACTIVE 23 157 | 158 | /** Set the corresponding echo canceller state so that residual echo suppression can be performed (NULL for no residual echo suppression) */ 159 | #define SPEEX_PREPROCESS_SET_ECHO_STATE 24 160 | /** Get the corresponding echo canceller state */ 161 | #define SPEEX_PREPROCESS_GET_ECHO_STATE 25 162 | 163 | /** Set maximal gain increase in dB/second (int32) */ 164 | #define SPEEX_PREPROCESS_SET_AGC_INCREMENT 26 165 | 166 | /** Get maximal gain increase in dB/second (int32) */ 167 | #define SPEEX_PREPROCESS_GET_AGC_INCREMENT 27 168 | 169 | /** Set maximal gain decrease in dB/second (int32) */ 170 | #define SPEEX_PREPROCESS_SET_AGC_DECREMENT 28 171 | 172 | /** Get maximal gain decrease in dB/second (int32) */ 173 | #define SPEEX_PREPROCESS_GET_AGC_DECREMENT 29 174 | 175 | /** Set maximal gain in dB (int32) */ 176 | #define SPEEX_PREPROCESS_SET_AGC_MAX_GAIN 30 177 | 178 | /** Get maximal gain in dB (int32) */ 179 | #define SPEEX_PREPROCESS_GET_AGC_MAX_GAIN 31 180 | 181 | /* Can't set loudness */ 182 | /** Get loudness */ 183 | #define SPEEX_PREPROCESS_GET_AGC_LOUDNESS 33 184 | 185 | /* Can't set gain */ 186 | /** Get current gain (int32 percent) */ 187 | #define SPEEX_PREPROCESS_GET_AGC_GAIN 35 188 | 189 | /* Can't set spectrum size */ 190 | /** Get spectrum size for power spectrum (int32) */ 191 | #define SPEEX_PREPROCESS_GET_PSD_SIZE 37 192 | 193 | /* Can't set power spectrum */ 194 | /** Get power spectrum (int32[] of squared values) */ 195 | #define SPEEX_PREPROCESS_GET_PSD 39 196 | 197 | /* Can't set noise size */ 198 | /** Get spectrum size for noise estimate (int32) */ 199 | #define SPEEX_PREPROCESS_GET_NOISE_PSD_SIZE 41 200 | 201 | /* Can't set noise estimate */ 202 | /** Get noise estimate (int32[] of squared values) */ 203 | #define SPEEX_PREPROCESS_GET_NOISE_PSD 43 204 | 205 | /* Can't set speech probability */ 206 | /** Get speech probability in last frame (int32). */ 207 | #define SPEEX_PREPROCESS_GET_PROB 45 208 | 209 | /** Set preprocessor Automatic Gain Control level (int32) */ 210 | #define SPEEX_PREPROCESS_SET_AGC_TARGET 46 211 | /** Get preprocessor Automatic Gain Control level (int32) */ 212 | #define SPEEX_PREPROCESS_GET_AGC_TARGET 47 213 | 214 | #ifdef __cplusplus 215 | } 216 | #endif 217 | 218 | /** @}*/ 219 | #endif 220 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/include/speex/speexdsp_config_types.h.in: -------------------------------------------------------------------------------- 1 | #ifndef __SPEEX_TYPES_H__ 2 | #define __SPEEX_TYPES_H__ 3 | 4 | #if defined HAVE_STDINT_H 5 | # include 6 | #elif defined HAVE_INTTYPES_H 7 | # include 8 | #elif defined HAVE_SYS_TYPES_H 9 | # include 10 | #endif 11 | 12 | typedef @SIZE16@ spx_int16_t; 13 | typedef @USIZE16@ spx_uint16_t; 14 | typedef @SIZE32@ spx_int32_t; 15 | typedef @USIZE32@ spx_uint32_t; 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/include/speex/speexdsp_types.h: -------------------------------------------------------------------------------- 1 | /* speexdsp_types.h taken from libogg */ 2 | /******************************************************************** 3 | * * 4 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 5 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 6 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 7 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 8 | * * 9 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 * 10 | * by the Xiph.Org Foundation http://www.xiph.org/ * 11 | * * 12 | ******************************************************************** 13 | 14 | function: #ifdef jail to whip a few platforms into the UNIX ideal. 15 | last mod: $Id: os_types.h 7524 2004-08-11 04:20:36Z conrad $ 16 | 17 | ********************************************************************/ 18 | /** 19 | @file speexdsp_types.h 20 | @brief Speex types 21 | */ 22 | #ifndef _SPEEX_TYPES_H 23 | #define _SPEEX_TYPES_H 24 | 25 | #if defined(_WIN32) 26 | 27 | # if defined(__CYGWIN__) 28 | # include <_G_config.h> 29 | typedef _G_int32_t spx_int32_t; 30 | typedef _G_uint32_t spx_uint32_t; 31 | typedef _G_int16_t spx_int16_t; 32 | typedef _G_uint16_t spx_uint16_t; 33 | # elif defined(__MINGW32__) 34 | typedef short spx_int16_t; 35 | typedef unsigned short spx_uint16_t; 36 | typedef int spx_int32_t; 37 | typedef unsigned int spx_uint32_t; 38 | # elif defined(__MWERKS__) 39 | typedef int spx_int32_t; 40 | typedef unsigned int spx_uint32_t; 41 | typedef short spx_int16_t; 42 | typedef unsigned short spx_uint16_t; 43 | # else 44 | /* MSVC/Borland */ 45 | typedef __int32 spx_int32_t; 46 | typedef unsigned __int32 spx_uint32_t; 47 | typedef __int16 spx_int16_t; 48 | typedef unsigned __int16 spx_uint16_t; 49 | # endif 50 | 51 | #elif defined(__MACOS__) 52 | 53 | # include 54 | typedef SInt16 spx_int16_t; 55 | typedef UInt16 spx_uint16_t; 56 | typedef SInt32 spx_int32_t; 57 | typedef UInt32 spx_uint32_t; 58 | 59 | #elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ 60 | 61 | # include 62 | typedef int16_t spx_int16_t; 63 | typedef u_int16_t spx_uint16_t; 64 | typedef int32_t spx_int32_t; 65 | typedef u_int32_t spx_uint32_t; 66 | 67 | #elif defined(__BEOS__) 68 | 69 | /* Be */ 70 | # include 71 | typedef int16_t spx_int16_t; 72 | typedef u_int16_t spx_uint16_t; 73 | typedef int32_t spx_int32_t; 74 | typedef u_int32_t spx_uint32_t; 75 | 76 | #elif defined (__EMX__) 77 | 78 | /* OS/2 GCC */ 79 | typedef short spx_int16_t; 80 | typedef unsigned short spx_uint16_t; 81 | typedef int spx_int32_t; 82 | typedef unsigned int spx_uint32_t; 83 | 84 | #elif defined (DJGPP) 85 | 86 | /* DJGPP */ 87 | typedef short spx_int16_t; 88 | typedef int spx_int32_t; 89 | typedef unsigned int spx_uint32_t; 90 | 91 | #elif defined(R5900) 92 | 93 | /* PS2 EE */ 94 | typedef int spx_int32_t; 95 | typedef unsigned spx_uint32_t; 96 | typedef short spx_int16_t; 97 | 98 | #elif defined(__SYMBIAN32__) 99 | 100 | /* Symbian GCC */ 101 | typedef signed short spx_int16_t; 102 | typedef unsigned short spx_uint16_t; 103 | typedef signed int spx_int32_t; 104 | typedef unsigned int spx_uint32_t; 105 | 106 | #elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) 107 | 108 | typedef short spx_int16_t; 109 | typedef unsigned short spx_uint16_t; 110 | typedef long spx_int32_t; 111 | typedef unsigned long spx_uint32_t; 112 | 113 | #elif defined(CONFIG_TI_C6X) 114 | 115 | typedef short spx_int16_t; 116 | typedef unsigned short spx_uint16_t; 117 | typedef int spx_int32_t; 118 | typedef unsigned int spx_uint32_t; 119 | 120 | #else 121 | 122 | #include "speexdsp_config_types.h" 123 | 124 | #endif 125 | 126 | #endif /* _SPEEX_TYPES_H */ 127 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/Makefile.am: -------------------------------------------------------------------------------- 1 | # Disable automatic dependency tracking if using other tools than gcc and gmake 2 | #AUTOMAKE_OPTIONS = no-dependencies 3 | 4 | EXTRA_DIST=echo_diagnostic.m 5 | 6 | AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include/speex -I$(top_builddir) @FFT_CFLAGS@ 7 | 8 | lib_LTLIBRARIES = libspeexdsp.la 9 | 10 | # Sources for compilation in the library 11 | if BUILD_KISS_FFT 12 | FFTSRC=kiss_fft.c _kiss_fft_guts.h kiss_fft.h kiss_fftr.c kiss_fftr.h 13 | else 14 | if BUILD_SMALLFT 15 | FFTSRC=smallft.c 16 | else 17 | FFTSRC= 18 | endif 19 | endif 20 | 21 | libspeexdsp_la_SOURCES = preprocess.c jitter.c mdf.c fftwrap.c filterbank.c resample.c buffer.c scal.c $(FFTSRC) 22 | 23 | noinst_HEADERS = arch.h bfin.h \ 24 | fixed_arm4.h \ 25 | fixed_arm5e.h fixed_bfin.h fixed_debug.h \ 26 | math_approx.h misc_bfin.h \ 27 | stack_alloc.h fftwrap.h \ 28 | filterbank.h fixed_generic.h os_support.h \ 29 | pseudofloat.h smallft.h vorbis_psy.h resample_sse.h resample_neon.h 30 | 31 | libspeexdsp_la_LDFLAGS = -no-undefined -version-info @SPEEXDSP_LT_CURRENT@:@SPEEXDSP_LT_REVISION@:@SPEEXDSP_LT_AGE@ 32 | libspeexdsp_la_LIBADD = $(LIBM) 33 | 34 | if BUILD_EXAMPLES 35 | noinst_PROGRAMS = testdenoise testecho testjitter testresample 36 | testdenoise_SOURCES = testdenoise.c 37 | testdenoise_LDADD = libspeexdsp.la @FFT_LIBS@ 38 | testecho_SOURCES = testecho.c 39 | testecho_LDADD = libspeexdsp.la @FFT_LIBS@ 40 | testjitter_SOURCES = testjitter.c 41 | testjitter_LDADD = libspeexdsp.la @FFT_LIBS@ 42 | testresample_SOURCES = testresample.c 43 | testresample_LDADD = libspeexdsp.la @FFT_LIBS@ @LIBM@ 44 | endif 45 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/_kiss_fft_guts.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2003-2004, Mark Borgerding 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | */ 14 | 15 | #define MIN(a,b) ((a)<(b) ? (a):(b)) 16 | #define MAX(a,b) ((a)>(b) ? (a):(b)) 17 | 18 | /* kiss_fft.h 19 | defines kiss_fft_scalar as either short or a float type 20 | and defines 21 | typedef struct { kiss_fft_scalar r; kiss_fft_scalar i; }kiss_fft_cpx; */ 22 | #include "kiss_fft.h" 23 | #include "math_approx.h" 24 | 25 | #define MAXFACTORS 32 26 | /* e.g. an fft of length 128 has 4 factors 27 | as far as kissfft is concerned 28 | 4*4*4*2 29 | */ 30 | 31 | struct kiss_fft_state{ 32 | int nfft; 33 | int inverse; 34 | int factors[2*MAXFACTORS]; 35 | kiss_fft_cpx twiddles[1]; 36 | }; 37 | 38 | /* 39 | Explanation of macros dealing with complex math: 40 | 41 | C_MUL(m,a,b) : m = a*b 42 | C_FIXDIV( c , div ) : if a fixed point impl., c /= div. noop otherwise 43 | C_SUB( res, a,b) : res = a - b 44 | C_SUBFROM( res , a) : res -= a 45 | C_ADDTO( res , a) : res += a 46 | * */ 47 | #ifdef FIXED_POINT 48 | #include "arch.h" 49 | # define FRACBITS 15 50 | # define SAMPPROD spx_int32_t 51 | #define SAMP_MAX 32767 52 | 53 | #define SAMP_MIN -SAMP_MAX 54 | 55 | #if defined(CHECK_OVERFLOW) 56 | # define CHECK_OVERFLOW_OP(a,op,b) \ 57 | if ( (SAMPPROD)(a) op (SAMPPROD)(b) > SAMP_MAX || (SAMPPROD)(a) op (SAMPPROD)(b) < SAMP_MIN ) { \ 58 | fprintf(stderr,"WARNING:overflow @ " __FILE__ "(%d): (%d " #op" %d) = %ld\n",__LINE__,(a),(b),(SAMPPROD)(a) op (SAMPPROD)(b) ); } 59 | #endif 60 | 61 | 62 | # define smul(a,b) ( (SAMPPROD)(a)*(b) ) 63 | # define sround( x ) (kiss_fft_scalar)( ( (x) + (1<<(FRACBITS-1)) ) >> FRACBITS ) 64 | 65 | # define S_MUL(a,b) sround( smul(a,b) ) 66 | 67 | # define C_MUL(m,a,b) \ 68 | do{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \ 69 | (m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); }while(0) 70 | 71 | # define C_MUL4(m,a,b) \ 72 | do{ (m).r = PSHR32( smul((a).r,(b).r) - smul((a).i,(b).i),17 ); \ 73 | (m).i = PSHR32( smul((a).r,(b).i) + smul((a).i,(b).r),17 ); }while(0) 74 | 75 | # define DIVSCALAR(x,k) \ 76 | (x) = sround( smul( x, SAMP_MAX/k ) ) 77 | 78 | # define C_FIXDIV(c,div) \ 79 | do { DIVSCALAR( (c).r , div); \ 80 | DIVSCALAR( (c).i , div); }while (0) 81 | 82 | # define C_MULBYSCALAR( c, s ) \ 83 | do{ (c).r = sround( smul( (c).r , s ) ) ;\ 84 | (c).i = sround( smul( (c).i , s ) ) ; }while(0) 85 | 86 | #else /* not FIXED_POINT*/ 87 | 88 | # define S_MUL(a,b) ( (a)*(b) ) 89 | #define C_MUL(m,a,b) \ 90 | do{ (m).r = (a).r*(b).r - (a).i*(b).i;\ 91 | (m).i = (a).r*(b).i + (a).i*(b).r; }while(0) 92 | 93 | #define C_MUL4(m,a,b) C_MUL(m,a,b) 94 | 95 | # define C_FIXDIV(c,div) /* NOOP */ 96 | # define C_MULBYSCALAR( c, s ) \ 97 | do{ (c).r *= (s);\ 98 | (c).i *= (s); }while(0) 99 | #endif 100 | 101 | #ifndef CHECK_OVERFLOW_OP 102 | # define CHECK_OVERFLOW_OP(a,op,b) /* noop */ 103 | #endif 104 | 105 | #define C_ADD( res, a,b)\ 106 | do { \ 107 | CHECK_OVERFLOW_OP((a).r,+,(b).r)\ 108 | CHECK_OVERFLOW_OP((a).i,+,(b).i)\ 109 | (res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \ 110 | }while(0) 111 | #define C_SUB( res, a,b)\ 112 | do { \ 113 | CHECK_OVERFLOW_OP((a).r,-,(b).r)\ 114 | CHECK_OVERFLOW_OP((a).i,-,(b).i)\ 115 | (res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \ 116 | }while(0) 117 | #define C_ADDTO( res , a)\ 118 | do { \ 119 | CHECK_OVERFLOW_OP((res).r,+,(a).r)\ 120 | CHECK_OVERFLOW_OP((res).i,+,(a).i)\ 121 | (res).r += (a).r; (res).i += (a).i;\ 122 | }while(0) 123 | 124 | #define C_SUBFROM( res , a)\ 125 | do {\ 126 | CHECK_OVERFLOW_OP((res).r,-,(a).r)\ 127 | CHECK_OVERFLOW_OP((res).i,-,(a).i)\ 128 | (res).r -= (a).r; (res).i -= (a).i; \ 129 | }while(0) 130 | 131 | 132 | #ifdef FIXED_POINT 133 | # define KISS_FFT_COS(phase) floor(MIN(32767,MAX(-32767,.5+32768 * cos (phase)))) 134 | # define KISS_FFT_SIN(phase) floor(MIN(32767,MAX(-32767,.5+32768 * sin (phase)))) 135 | # define HALF_OF(x) ((x)>>1) 136 | #elif defined(USE_SIMD) 137 | # define KISS_FFT_COS(phase) _mm_set1_ps( cos(phase) ) 138 | # define KISS_FFT_SIN(phase) _mm_set1_ps( sin(phase) ) 139 | # define HALF_OF(x) ((x)*_mm_set1_ps(.5)) 140 | #else 141 | # define KISS_FFT_COS(phase) (kiss_fft_scalar) cos(phase) 142 | # define KISS_FFT_SIN(phase) (kiss_fft_scalar) sin(phase) 143 | # define HALF_OF(x) ((x)*.5) 144 | #endif 145 | 146 | #define kf_cexp(x,phase) \ 147 | do{ \ 148 | (x)->r = KISS_FFT_COS(phase);\ 149 | (x)->i = KISS_FFT_SIN(phase);\ 150 | }while(0) 151 | #define kf_cexp2(x,phase) \ 152 | do{ \ 153 | (x)->r = spx_cos_norm((phase));\ 154 | (x)->i = spx_cos_norm((phase)-32768);\ 155 | }while(0) 156 | 157 | 158 | /* a debugging function */ 159 | #define pcpx(c)\ 160 | fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) ) 161 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/arch.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2003 Jean-Marc Valin */ 2 | /** 3 | @file arch.h 4 | @brief Various architecture definitions Speex 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef ARCH_H 36 | #define ARCH_H 37 | 38 | /* A couple test to catch stupid option combinations */ 39 | #ifdef FIXED_POINT 40 | 41 | #ifdef FLOATING_POINT 42 | #error You cannot compile as floating point and fixed point at the same time 43 | #endif 44 | #ifdef _USE_SSE 45 | #error SSE is only for floating-point 46 | #endif 47 | #if ((defined (ARM4_ASM)||defined (ARM4_ASM)) && defined(BFIN_ASM)) || (defined (ARM4_ASM)&&defined(ARM5E_ASM)) 48 | #error Make up your mind. What CPU do you have? 49 | #endif 50 | #ifdef VORBIS_PSYCHO 51 | #error Vorbis-psy model currently not implemented in fixed-point 52 | #endif 53 | 54 | #else 55 | 56 | #ifndef FLOATING_POINT 57 | #error You now need to define either FIXED_POINT or FLOATING_POINT 58 | #endif 59 | #if defined (ARM4_ASM) || defined(ARM5E_ASM) || defined(BFIN_ASM) 60 | #error I suppose you can have a [ARM4/ARM5E/Blackfin] that has float instructions? 61 | #endif 62 | #ifdef FIXED_POINT_DEBUG 63 | #error "Don't you think enabling fixed-point is a good thing to do if you want to debug that?" 64 | #endif 65 | 66 | 67 | #endif 68 | 69 | #ifndef OUTSIDE_SPEEX 70 | #include "speex/speexdsp_types.h" 71 | #endif 72 | 73 | #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ 74 | #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ 75 | #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 16-bit value. */ 76 | #define MAX16(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 16-bit value. */ 77 | #define ABS32(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 32-bit value. */ 78 | #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Maximum 32-bit value. */ 79 | #define MAX32(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum 32-bit value. */ 80 | 81 | #ifdef FIXED_POINT 82 | 83 | typedef spx_int16_t spx_word16_t; 84 | typedef spx_int32_t spx_word32_t; 85 | typedef spx_word32_t spx_mem_t; 86 | typedef spx_word16_t spx_coef_t; 87 | typedef spx_word16_t spx_lsp_t; 88 | typedef spx_word32_t spx_sig_t; 89 | 90 | #define Q15ONE 32767 91 | 92 | #define LPC_SCALING 8192 93 | #define SIG_SCALING 16384 94 | #define LSP_SCALING 8192. 95 | #define GAMMA_SCALING 32768. 96 | #define GAIN_SCALING 64 97 | #define GAIN_SCALING_1 0.015625 98 | 99 | #define LPC_SHIFT 13 100 | #define LSP_SHIFT 13 101 | #define SIG_SHIFT 14 102 | #define GAIN_SHIFT 6 103 | 104 | #define VERY_SMALL 0 105 | #define VERY_LARGE32 ((spx_word32_t)2147483647) 106 | #define VERY_LARGE16 ((spx_word16_t)32767) 107 | #define Q15_ONE ((spx_word16_t)32767) 108 | 109 | 110 | #ifdef FIXED_DEBUG 111 | #include "fixed_debug.h" 112 | #else 113 | 114 | #include "fixed_generic.h" 115 | 116 | #ifdef ARM5E_ASM 117 | #include "fixed_arm5e.h" 118 | #elif defined (ARM4_ASM) 119 | #include "fixed_arm4.h" 120 | #elif defined (BFIN_ASM) 121 | #include "fixed_bfin.h" 122 | #endif 123 | 124 | #endif 125 | 126 | 127 | #else 128 | 129 | typedef float spx_mem_t; 130 | typedef float spx_coef_t; 131 | typedef float spx_lsp_t; 132 | typedef float spx_sig_t; 133 | typedef float spx_word16_t; 134 | typedef float spx_word32_t; 135 | 136 | #define Q15ONE 1.0f 137 | #define LPC_SCALING 1.f 138 | #define SIG_SCALING 1.f 139 | #define LSP_SCALING 1.f 140 | #define GAMMA_SCALING 1.f 141 | #define GAIN_SCALING 1.f 142 | #define GAIN_SCALING_1 1.f 143 | 144 | 145 | #define VERY_SMALL 1e-15f 146 | #define VERY_LARGE32 1e15f 147 | #define VERY_LARGE16 1e15f 148 | #define Q15_ONE ((spx_word16_t)1.f) 149 | 150 | #define QCONST16(x,bits) (x) 151 | #define QCONST32(x,bits) (x) 152 | 153 | #define NEG16(x) (-(x)) 154 | #define NEG32(x) (-(x)) 155 | #define EXTRACT16(x) (x) 156 | #define EXTEND32(x) (x) 157 | #define SHR16(a,shift) (a) 158 | #define SHL16(a,shift) (a) 159 | #define SHR32(a,shift) (a) 160 | #define SHL32(a,shift) (a) 161 | #define PSHR16(a,shift) (a) 162 | #define PSHR32(a,shift) (a) 163 | #define VSHR32(a,shift) (a) 164 | #define SATURATE16(x,a) (x) 165 | #define SATURATE32(x,a) (x) 166 | #define SATURATE32PSHR(x,shift,a) (x) 167 | 168 | #define PSHR(a,shift) (a) 169 | #define SHR(a,shift) (a) 170 | #define SHL(a,shift) (a) 171 | #define SATURATE(x,a) (x) 172 | 173 | #define ADD16(a,b) ((a)+(b)) 174 | #define SUB16(a,b) ((a)-(b)) 175 | #define ADD32(a,b) ((a)+(b)) 176 | #define SUB32(a,b) ((a)-(b)) 177 | #define MULT16_16_16(a,b) ((a)*(b)) 178 | #define MULT16_16(a,b) ((spx_word32_t)(a)*(spx_word32_t)(b)) 179 | #define MAC16_16(c,a,b) ((c)+(spx_word32_t)(a)*(spx_word32_t)(b)) 180 | 181 | #define MULT16_32_Q11(a,b) ((a)*(b)) 182 | #define MULT16_32_Q13(a,b) ((a)*(b)) 183 | #define MULT16_32_Q14(a,b) ((a)*(b)) 184 | #define MULT16_32_Q15(a,b) ((a)*(b)) 185 | #define MULT16_32_P15(a,b) ((a)*(b)) 186 | 187 | #define MAC16_32_Q11(c,a,b) ((c)+(a)*(b)) 188 | #define MAC16_32_Q15(c,a,b) ((c)+(a)*(b)) 189 | 190 | #define MAC16_16_Q11(c,a,b) ((c)+(a)*(b)) 191 | #define MAC16_16_Q13(c,a,b) ((c)+(a)*(b)) 192 | #define MAC16_16_P13(c,a,b) ((c)+(a)*(b)) 193 | #define MULT16_16_Q11_32(a,b) ((a)*(b)) 194 | #define MULT16_16_Q13(a,b) ((a)*(b)) 195 | #define MULT16_16_Q14(a,b) ((a)*(b)) 196 | #define MULT16_16_Q15(a,b) ((a)*(b)) 197 | #define MULT16_16_P15(a,b) ((a)*(b)) 198 | #define MULT16_16_P13(a,b) ((a)*(b)) 199 | #define MULT16_16_P14(a,b) ((a)*(b)) 200 | 201 | #define DIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b)) 202 | #define PDIV32_16(a,b) (((spx_word32_t)(a))/(spx_word16_t)(b)) 203 | #define DIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b)) 204 | #define PDIV32(a,b) (((spx_word32_t)(a))/(spx_word32_t)(b)) 205 | 206 | 207 | #endif 208 | 209 | 210 | #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) 211 | 212 | /* 2 on TI C5x DSP */ 213 | #define BYTES_PER_CHAR 2 214 | #define BITS_PER_CHAR 16 215 | #define LOG2_BITS_PER_CHAR 4 216 | 217 | #else 218 | 219 | #define BYTES_PER_CHAR 1 220 | #define BITS_PER_CHAR 8 221 | #define LOG2_BITS_PER_CHAR 3 222 | 223 | #endif 224 | 225 | 226 | 227 | #ifdef FIXED_DEBUG 228 | extern long long spx_mips; 229 | #endif 230 | 231 | 232 | #endif 233 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/bfin.h: -------------------------------------------------------------------------------- 1 | /* Common Blackfin assembly defines 2 | * 3 | * Copyright (C) 2005-2009 Analog Devices 4 | */ 5 | 6 | #if __GNUC__ <= 3 7 | /* GCC-3.4 and older did not use hardware loops and thus did not have 8 | * register constraints for declaring clobbers. 9 | */ 10 | # define BFIN_HWLOOP0_REGS 11 | # define BFIN_HWLOOP1_REGS 12 | #else 13 | # define BFIN_HWLOOP0_REGS , "LB0", "LT0", "LC0" 14 | # define BFIN_HWLOOP1_REGS , "LB1", "LT1", "LC1" 15 | #endif 16 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/buffer.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007 Jean-Marc Valin 2 | 3 | File: buffer.c 4 | This is a very simple ring buffer implementation. It is not thread-safe 5 | so you need to do your own locking. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifdef HAVE_CONFIG_H 35 | #include "config.h" 36 | #endif 37 | 38 | 39 | #include "os_support.h" 40 | #include "arch.h" 41 | #include "speex/speex_buffer.h" 42 | 43 | struct SpeexBuffer_ { 44 | char *data; 45 | int size; 46 | int read_ptr; 47 | int write_ptr; 48 | int available; 49 | }; 50 | 51 | EXPORT SpeexBuffer *speex_buffer_init(int size) 52 | { 53 | SpeexBuffer *st = speex_alloc(sizeof(SpeexBuffer)); 54 | st->data = speex_alloc(size); 55 | st->size = size; 56 | st->read_ptr = 0; 57 | st->write_ptr = 0; 58 | st->available = 0; 59 | return st; 60 | } 61 | 62 | EXPORT void speex_buffer_destroy(SpeexBuffer *st) 63 | { 64 | speex_free(st->data); 65 | speex_free(st); 66 | } 67 | 68 | EXPORT int speex_buffer_write(SpeexBuffer *st, void *_data, int len) 69 | { 70 | int end; 71 | int end1; 72 | char *data = _data; 73 | if (len > st->size) 74 | { 75 | data += len-st->size; 76 | len = st->size; 77 | } 78 | end = st->write_ptr + len; 79 | end1 = end; 80 | if (end1 > st->size) 81 | end1 = st->size; 82 | SPEEX_COPY(st->data + st->write_ptr, data, end1 - st->write_ptr); 83 | if (end > st->size) 84 | { 85 | end -= st->size; 86 | SPEEX_COPY(st->data, data+end1 - st->write_ptr, end); 87 | } 88 | st->available += len; 89 | if (st->available > st->size) 90 | { 91 | st->available = st->size; 92 | st->read_ptr = st->write_ptr; 93 | } 94 | st->write_ptr += len; 95 | if (st->write_ptr > st->size) 96 | st->write_ptr -= st->size; 97 | return len; 98 | } 99 | 100 | EXPORT int speex_buffer_writezeros(SpeexBuffer *st, int len) 101 | { 102 | /* This is almost the same as for speex_buffer_write() but using 103 | SPEEX_MEMSET() instead of SPEEX_COPY(). Update accordingly. */ 104 | int end; 105 | int end1; 106 | if (len > st->size) 107 | { 108 | len = st->size; 109 | } 110 | end = st->write_ptr + len; 111 | end1 = end; 112 | if (end1 > st->size) 113 | end1 = st->size; 114 | SPEEX_MEMSET(st->data + st->write_ptr, 0, end1 - st->write_ptr); 115 | if (end > st->size) 116 | { 117 | end -= st->size; 118 | SPEEX_MEMSET(st->data, 0, end); 119 | } 120 | st->available += len; 121 | if (st->available > st->size) 122 | { 123 | st->available = st->size; 124 | st->read_ptr = st->write_ptr; 125 | } 126 | st->write_ptr += len; 127 | if (st->write_ptr > st->size) 128 | st->write_ptr -= st->size; 129 | return len; 130 | } 131 | 132 | EXPORT int speex_buffer_read(SpeexBuffer *st, void *_data, int len) 133 | { 134 | int end, end1; 135 | char *data = _data; 136 | if (len > st->available) 137 | { 138 | SPEEX_MEMSET(data+st->available, 0, st->size-st->available); 139 | len = st->available; 140 | } 141 | end = st->read_ptr + len; 142 | end1 = end; 143 | if (end1 > st->size) 144 | end1 = st->size; 145 | SPEEX_COPY(data, st->data + st->read_ptr, end1 - st->read_ptr); 146 | 147 | if (end > st->size) 148 | { 149 | end -= st->size; 150 | SPEEX_COPY(data+end1 - st->read_ptr, st->data, end); 151 | } 152 | st->available -= len; 153 | st->read_ptr += len; 154 | if (st->read_ptr > st->size) 155 | st->read_ptr -= st->size; 156 | return len; 157 | } 158 | 159 | EXPORT int speex_buffer_get_available(SpeexBuffer *st) 160 | { 161 | return st->available; 162 | } 163 | 164 | EXPORT int speex_buffer_resize(SpeexBuffer *st, int len) 165 | { 166 | int old_len = st->size; 167 | if (len > old_len) 168 | { 169 | st->data = speex_realloc(st->data, len); 170 | /* FIXME: move data/pointers properly for growing the buffer */ 171 | } else { 172 | /* FIXME: move data/pointers properly for shrinking the buffer */ 173 | st->data = speex_realloc(st->data, len); 174 | } 175 | return len; 176 | } 177 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/echo_diagnostic.m: -------------------------------------------------------------------------------- 1 | % Attempts to diagnose AEC problems from recorded samples 2 | % 3 | % out = echo_diagnostic(rec_file, play_file, out_file, tail_length) 4 | % 5 | % Computes the full matrix inversion to cancel echo from the 6 | % recording 'rec_file' using the far end signal 'play_file' using 7 | % a filter length of 'tail_length'. The output is saved to 'out_file'. 8 | function out = echo_diagnostic(rec_file, play_file, out_file, tail_length) 9 | 10 | F=fopen(rec_file,'rb'); 11 | rec=fread(F,Inf,'short'); 12 | fclose (F); 13 | F=fopen(play_file,'rb'); 14 | play=fread(F,Inf,'short'); 15 | fclose (F); 16 | 17 | rec = [rec; zeros(1024,1)]; 18 | play = [play; zeros(1024,1)]; 19 | 20 | N = length(rec); 21 | corr = real(ifft(fft(rec).*conj(fft(play)))); 22 | acorr = real(ifft(fft(play).*conj(fft(play)))); 23 | 24 | [a,b] = max(corr); 25 | 26 | if b > N/2 27 | b = b-N; 28 | end 29 | printf ("Far end to near end delay is %d samples\n", b); 30 | if (b > .3*tail_length) 31 | printf ('This is too much delay, try delaying the far-end signal a bit\n'); 32 | else if (b < 0) 33 | printf ('You have a negative delay, the echo canceller has no chance to cancel anything!\n'); 34 | else 35 | printf ('Delay looks OK.\n'); 36 | end 37 | end 38 | end 39 | N2 = round(N/2); 40 | corr1 = real(ifft(fft(rec(1:N2)).*conj(fft(play(1:N2))))); 41 | corr2 = real(ifft(fft(rec(N2+1:end)).*conj(fft(play(N2+1:end))))); 42 | 43 | [a,b1] = max(corr1); 44 | if b1 > N2/2 45 | b1 = b1-N2; 46 | end 47 | [a,b2] = max(corr2); 48 | if b2 > N2/2 49 | b2 = b2-N2; 50 | end 51 | drift = (b1-b2)/N2; 52 | printf ('Drift estimate is %f%% (%d samples)\n', 100*drift, b1-b2); 53 | if abs(b1-b2) < 10 54 | printf ('A drift of a few (+-10) samples is normal.\n'); 55 | else 56 | if abs(b1-b2) < 30 57 | printf ('There may be (not sure) excessive clock drift. Is the capture and playback done on the same soundcard?\n'); 58 | else 59 | printf ('Your clock is drifting! No way the AEC will be able to do anything with that. Most likely, you''re doing capture and playback from two different cards.\n'); 60 | end 61 | end 62 | end 63 | acorr(1) = .001+1.00001*acorr(1); 64 | AtA = toeplitz(acorr(1:tail_length)); 65 | bb = corr(1:tail_length); 66 | h = AtA\bb; 67 | 68 | out = (rec - filter(h, 1, play)); 69 | 70 | F=fopen(out_file,'w'); 71 | fwrite(F,out,'short'); 72 | fclose (F); 73 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/fftwrap.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2005 Jean-Marc Valin 2 | File: fftwrap.h 3 | 4 | Wrapper for various FFTs 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | - Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | 13 | - Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | - Neither the name of the Xiph.org Foundation nor the names of its 18 | contributors may be used to endorse or promote products derived from 19 | this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | 33 | */ 34 | 35 | #ifndef FFTWRAP_H 36 | #define FFTWRAP_H 37 | 38 | #include "arch.h" 39 | 40 | /** Compute tables for an FFT */ 41 | void *spx_fft_init(int size); 42 | 43 | /** Destroy tables for an FFT */ 44 | void spx_fft_destroy(void *table); 45 | 46 | /** Forward (real to half-complex) transform */ 47 | void spx_fft(void *table, spx_word16_t *in, spx_word16_t *out); 48 | 49 | /** Backward (half-complex to real) transform */ 50 | void spx_ifft(void *table, spx_word16_t *in, spx_word16_t *out); 51 | 52 | /** Forward (real to half-complex) transform of float data */ 53 | void spx_fft_float(void *table, float *in, float *out); 54 | 55 | /** Backward (half-complex to real) transform of float data */ 56 | void spx_ifft_float(void *table, float *in, float *out); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/filterbank.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2006 Jean-Marc Valin */ 2 | /** 3 | @file filterbank.c 4 | @brief Converting between psd and filterbank 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifdef HAVE_CONFIG_H 35 | #include "config.h" 36 | #endif 37 | 38 | #include "filterbank.h" 39 | #include "arch.h" 40 | #include 41 | #include "math_approx.h" 42 | #include "os_support.h" 43 | 44 | #ifdef FIXED_POINT 45 | 46 | #define toBARK(n) (MULT16_16(26829,spx_atan(SHR32(MULT16_16(97,n),2))) + MULT16_16(4588,spx_atan(MULT16_32_Q15(20,MULT16_16(n,n)))) + MULT16_16(3355,n)) 47 | 48 | #else 49 | #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n)) 50 | #endif 51 | 52 | #define toMEL(n) (2595.f*log10(1.f+(n)/700.f)) 53 | 54 | FilterBank *filterbank_new(int banks, spx_word32_t sampling, int len, int type) 55 | { 56 | FilterBank *bank; 57 | spx_word32_t df; 58 | spx_word32_t max_mel, mel_interval; 59 | int i; 60 | int id1; 61 | int id2; 62 | df = DIV32(SHL32(sampling,15),MULT16_16(2,len)); 63 | max_mel = toBARK(EXTRACT16(sampling/2)); 64 | mel_interval = PDIV32(max_mel,banks-1); 65 | 66 | bank = (FilterBank*)speex_alloc(sizeof(FilterBank)); 67 | bank->nb_banks = banks; 68 | bank->len = len; 69 | bank->bank_left = (int*)speex_alloc(len*sizeof(int)); 70 | bank->bank_right = (int*)speex_alloc(len*sizeof(int)); 71 | bank->filter_left = (spx_word16_t*)speex_alloc(len*sizeof(spx_word16_t)); 72 | bank->filter_right = (spx_word16_t*)speex_alloc(len*sizeof(spx_word16_t)); 73 | /* Think I can safely disable normalisation that for fixed-point (and probably float as well) */ 74 | #ifndef FIXED_POINT 75 | bank->scaling = (float*)speex_alloc(banks*sizeof(float)); 76 | #endif 77 | for (i=0;i max_mel) 85 | break; 86 | #ifdef FIXED_POINT 87 | id1 = DIV32(mel,mel_interval); 88 | #else 89 | id1 = (int)(floor(mel/mel_interval)); 90 | #endif 91 | if (id1>banks-2) 92 | { 93 | id1 = banks-2; 94 | val = Q15_ONE; 95 | } else { 96 | val = DIV32_16(mel - id1*mel_interval,EXTRACT16(PSHR32(mel_interval,15))); 97 | } 98 | id2 = id1+1; 99 | bank->bank_left[i] = id1; 100 | bank->filter_left[i] = SUB16(Q15_ONE,val); 101 | bank->bank_right[i] = id2; 102 | bank->filter_right[i] = val; 103 | } 104 | 105 | /* Think I can safely disable normalisation for fixed-point (and probably float as well) */ 106 | #ifndef FIXED_POINT 107 | for (i=0;inb_banks;i++) 108 | bank->scaling[i] = 0; 109 | for (i=0;ilen;i++) 110 | { 111 | int id = bank->bank_left[i]; 112 | bank->scaling[id] += bank->filter_left[i]; 113 | id = bank->bank_right[i]; 114 | bank->scaling[id] += bank->filter_right[i]; 115 | } 116 | for (i=0;inb_banks;i++) 117 | bank->scaling[i] = Q15_ONE/(bank->scaling[i]); 118 | #endif 119 | return bank; 120 | } 121 | 122 | void filterbank_destroy(FilterBank *bank) 123 | { 124 | speex_free(bank->bank_left); 125 | speex_free(bank->bank_right); 126 | speex_free(bank->filter_left); 127 | speex_free(bank->filter_right); 128 | #ifndef FIXED_POINT 129 | speex_free(bank->scaling); 130 | #endif 131 | speex_free(bank); 132 | } 133 | 134 | void filterbank_compute_bank32(FilterBank *bank, spx_word32_t *ps, spx_word32_t *mel) 135 | { 136 | int i; 137 | for (i=0;inb_banks;i++) 138 | mel[i] = 0; 139 | 140 | for (i=0;ilen;i++) 141 | { 142 | int id; 143 | id = bank->bank_left[i]; 144 | mel[id] += MULT16_32_P15(bank->filter_left[i],ps[i]); 145 | id = bank->bank_right[i]; 146 | mel[id] += MULT16_32_P15(bank->filter_right[i],ps[i]); 147 | } 148 | /* Think I can safely disable normalisation that for fixed-point (and probably float as well) */ 149 | #ifndef FIXED_POINT 150 | /*for (i=0;inb_banks;i++) 151 | mel[i] = MULT16_32_P15(Q15(bank->scaling[i]),mel[i]); 152 | */ 153 | #endif 154 | } 155 | 156 | void filterbank_compute_psd16(FilterBank *bank, spx_word16_t *mel, spx_word16_t *ps) 157 | { 158 | int i; 159 | for (i=0;ilen;i++) 160 | { 161 | spx_word32_t tmp; 162 | int id1, id2; 163 | id1 = bank->bank_left[i]; 164 | id2 = bank->bank_right[i]; 165 | tmp = MULT16_16(mel[id1],bank->filter_left[i]); 166 | tmp += MULT16_16(mel[id2],bank->filter_right[i]); 167 | ps[i] = EXTRACT16(PSHR32(tmp,15)); 168 | } 169 | } 170 | 171 | 172 | #ifndef FIXED_POINT 173 | void filterbank_compute_bank(FilterBank *bank, float *ps, float *mel) 174 | { 175 | int i; 176 | for (i=0;inb_banks;i++) 177 | mel[i] = 0; 178 | 179 | for (i=0;ilen;i++) 180 | { 181 | int id = bank->bank_left[i]; 182 | mel[id] += bank->filter_left[i]*ps[i]; 183 | id = bank->bank_right[i]; 184 | mel[id] += bank->filter_right[i]*ps[i]; 185 | } 186 | for (i=0;inb_banks;i++) 187 | mel[i] *= bank->scaling[i]; 188 | } 189 | 190 | void filterbank_compute_psd(FilterBank *bank, float *mel, float *ps) 191 | { 192 | int i; 193 | for (i=0;ilen;i++) 194 | { 195 | int id = bank->bank_left[i]; 196 | ps[i] = mel[id]*bank->filter_left[i]; 197 | id = bank->bank_right[i]; 198 | ps[i] += mel[id]*bank->filter_right[i]; 199 | } 200 | } 201 | 202 | void filterbank_psy_smooth(FilterBank *bank, float *ps, float *mask) 203 | { 204 | /* Low freq slope: 14 dB/Bark*/ 205 | /* High freq slope: 9 dB/Bark*/ 206 | /* Noise vs tone: 5 dB difference */ 207 | /* FIXME: Temporary kludge */ 208 | float bark[100]; 209 | int i; 210 | /* Assumes 1/3 Bark resolution */ 211 | float decay_low = 0.34145f; 212 | float decay_high = 0.50119f; 213 | filterbank_compute_bank(bank, ps, bark); 214 | for (i=1;inb_banks;i++) 215 | { 216 | /*float decay_high = 13-1.6*log10(bark[i-1]); 217 | decay_high = pow(10,(-decay_high/30.f));*/ 218 | bark[i] = bark[i] + decay_high*bark[i-1]; 219 | } 220 | for (i=bank->nb_banks-2;i>=0;i--) 221 | { 222 | bark[i] = bark[i] + decay_low*bark[i+1]; 223 | } 224 | filterbank_compute_psd(bank, bark, mask); 225 | } 226 | 227 | #endif 228 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/filterbank.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2006 Jean-Marc Valin */ 2 | /** 3 | @file filterbank.h 4 | @brief Converting between psd and filterbank 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef FILTERBANK_H 35 | #define FILTERBANK_H 36 | 37 | #include "arch.h" 38 | 39 | typedef struct { 40 | int *bank_left; 41 | int *bank_right; 42 | spx_word16_t *filter_left; 43 | spx_word16_t *filter_right; 44 | #ifndef FIXED_POINT 45 | float *scaling; 46 | #endif 47 | int nb_banks; 48 | int len; 49 | } FilterBank; 50 | 51 | 52 | FilterBank *filterbank_new(int banks, spx_word32_t sampling, int len, int type); 53 | 54 | void filterbank_destroy(FilterBank *bank); 55 | 56 | void filterbank_compute_bank32(FilterBank *bank, spx_word32_t *ps, spx_word32_t *mel); 57 | 58 | void filterbank_compute_psd16(FilterBank *bank, spx_word16_t *mel, spx_word16_t *psd); 59 | 60 | #ifndef FIXED_POINT 61 | void filterbank_compute_bank(FilterBank *bank, float *psd, float *mel); 62 | void filterbank_compute_psd(FilterBank *bank, float *mel, float *psd); 63 | #endif 64 | 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/fixed_arm4.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2004 Jean-Marc Valin */ 2 | /** 3 | @file fixed_arm4.h 4 | @brief ARM4 fixed-point operations 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef FIXED_ARM4_H 36 | #define FIXED_ARM4_H 37 | 38 | #undef MULT16_32_Q14 39 | static inline spx_word32_t MULT16_32_Q14(spx_word16_t x, spx_word32_t y) { 40 | int res; 41 | int dummy; 42 | asm ( 43 | "smull %0,%1,%2,%3 \n\t" 44 | "mov %0, %0, lsr #14 \n\t" 45 | "add %0, %0, %1, lsl #18 \n\t" 46 | : "=&r"(res), "=&r" (dummy) 47 | : "r"(y),"r"((int)x)); 48 | return(res); 49 | } 50 | 51 | #undef MULT16_32_Q15 52 | static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) { 53 | int res; 54 | int dummy; 55 | asm ( 56 | "smull %0,%1,%2,%3 \n\t" 57 | "mov %0, %0, lsr #15 \n\t" 58 | "add %0, %0, %1, lsl #17 \n\t" 59 | : "=&r"(res), "=&r" (dummy) 60 | : "r"(y),"r"((int)x)); 61 | return(res); 62 | } 63 | 64 | #undef DIV32_16 65 | static inline short DIV32_16(int a, int b) 66 | { 67 | int res=0; 68 | int dead1, dead2, dead3, dead4, dead5; 69 | __asm__ __volatile__ ( 70 | "\teor %5, %0, %1\n" 71 | "\tmovs %4, %0\n" 72 | "\trsbmi %0, %0, #0 \n" 73 | "\tmovs %4, %1\n" 74 | "\trsbmi %1, %1, #0 \n" 75 | "\tmov %4, #1\n" 76 | 77 | "\tsubs %3, %0, %1, asl #14 \n" 78 | "\tmovpl %0, %3 \n" 79 | "\torrpl %2, %2, %4, asl #14 \n" 80 | 81 | "\tsubs %3, %0, %1, asl #13 \n" 82 | "\tmovpl %0, %3 \n" 83 | "\torrpl %2, %2, %4, asl #13 \n" 84 | 85 | "\tsubs %3, %0, %1, asl #12 \n" 86 | "\tmovpl %0, %3 \n" 87 | "\torrpl %2, %2, %4, asl #12 \n" 88 | 89 | "\tsubs %3, %0, %1, asl #11 \n" 90 | "\tmovpl %0, %3 \n" 91 | "\torrpl %2, %2, %4, asl #11 \n" 92 | 93 | "\tsubs %3, %0, %1, asl #10 \n" 94 | "\tmovpl %0, %3 \n" 95 | "\torrpl %2, %2, %4, asl #10 \n" 96 | 97 | "\tsubs %3, %0, %1, asl #9 \n" 98 | "\tmovpl %0, %3 \n" 99 | "\torrpl %2, %2, %4, asl #9 \n" 100 | 101 | "\tsubs %3, %0, %1, asl #8 \n" 102 | "\tmovpl %0, %3 \n" 103 | "\torrpl %2, %2, %4, asl #8 \n" 104 | 105 | "\tsubs %3, %0, %1, asl #7 \n" 106 | "\tmovpl %0, %3 \n" 107 | "\torrpl %2, %2, %4, asl #7 \n" 108 | 109 | "\tsubs %3, %0, %1, asl #6 \n" 110 | "\tmovpl %0, %3 \n" 111 | "\torrpl %2, %2, %4, asl #6 \n" 112 | 113 | "\tsubs %3, %0, %1, asl #5 \n" 114 | "\tmovpl %0, %3 \n" 115 | "\torrpl %2, %2, %4, asl #5 \n" 116 | 117 | "\tsubs %3, %0, %1, asl #4 \n" 118 | "\tmovpl %0, %3 \n" 119 | "\torrpl %2, %2, %4, asl #4 \n" 120 | 121 | "\tsubs %3, %0, %1, asl #3 \n" 122 | "\tmovpl %0, %3 \n" 123 | "\torrpl %2, %2, %4, asl #3 \n" 124 | 125 | "\tsubs %3, %0, %1, asl #2 \n" 126 | "\tmovpl %0, %3 \n" 127 | "\torrpl %2, %2, %4, asl #2 \n" 128 | 129 | "\tsubs %3, %0, %1, asl #1 \n" 130 | "\tmovpl %0, %3 \n" 131 | "\torrpl %2, %2, %4, asl #1 \n" 132 | 133 | "\tsubs %3, %0, %1 \n" 134 | "\tmovpl %0, %3 \n" 135 | "\torrpl %2, %2, %4 \n" 136 | 137 | "\tmovs %5, %5, lsr #31 \n" 138 | "\trsbne %2, %2, #0 \n" 139 | : "=r" (dead1), "=r" (dead2), "=r" (res), 140 | "=r" (dead3), "=r" (dead4), "=r" (dead5) 141 | : "0" (a), "1" (b), "2" (res) 142 | : "cc" 143 | ); 144 | return res; 145 | } 146 | 147 | 148 | #endif 149 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/fixed_arm5e.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2003 Jean-Marc Valin */ 2 | /** 3 | @file fixed_arm5e.h 4 | @brief ARM-tuned fixed-point operations 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef FIXED_ARM5E_H 36 | #define FIXED_ARM5E_H 37 | 38 | #undef MULT16_16 39 | static inline spx_word32_t MULT16_16(spx_word16_t x, spx_word16_t y) { 40 | int res; 41 | asm ("smulbb %0,%1,%2;\n" 42 | : "=&r"(res) 43 | : "%r"(x),"r"(y)); 44 | return(res); 45 | } 46 | 47 | #undef MAC16_16 48 | static inline spx_word32_t MAC16_16(spx_word32_t a, spx_word16_t x, spx_word32_t y) { 49 | int res; 50 | asm ("smlabb %0,%1,%2,%3;\n" 51 | : "=&r"(res) 52 | : "%r"(x),"r"(y),"r"(a)); 53 | return(res); 54 | } 55 | 56 | #undef MULT16_32_Q15 57 | static inline spx_word32_t MULT16_32_Q15(spx_word16_t x, spx_word32_t y) { 58 | int res; 59 | asm ("smulwb %0,%1,%2;\n" 60 | : "=&r"(res) 61 | : "%r"(y<<1),"r"(x)); 62 | return(res); 63 | } 64 | 65 | #undef MAC16_32_Q15 66 | static inline spx_word32_t MAC16_32_Q15(spx_word32_t a, spx_word16_t x, spx_word32_t y) { 67 | int res; 68 | asm ("smlawb %0,%1,%2,%3;\n" 69 | : "=&r"(res) 70 | : "%r"(y<<1),"r"(x),"r"(a)); 71 | return(res); 72 | } 73 | 74 | #undef MULT16_32_Q11 75 | static inline spx_word32_t MULT16_32_Q11(spx_word16_t x, spx_word32_t y) { 76 | int res; 77 | asm ("smulwb %0,%1,%2;\n" 78 | : "=&r"(res) 79 | : "%r"(y<<5),"r"(x)); 80 | return(res); 81 | } 82 | 83 | #undef MAC16_32_Q11 84 | static inline spx_word32_t MAC16_32_Q11(spx_word32_t a, spx_word16_t x, spx_word32_t y) { 85 | int res; 86 | asm ("smlawb %0,%1,%2,%3;\n" 87 | : "=&r"(res) 88 | : "%r"(y<<5),"r"(x),"r"(a)); 89 | return(res); 90 | } 91 | 92 | #undef DIV32_16 93 | static inline short DIV32_16(int a, int b) 94 | { 95 | int res=0; 96 | int dead1, dead2, dead3, dead4, dead5; 97 | __asm__ __volatile__ ( 98 | "\teor %5, %0, %1\n" 99 | "\tmovs %4, %0\n" 100 | "\trsbmi %0, %0, #0 \n" 101 | "\tmovs %4, %1\n" 102 | "\trsbmi %1, %1, #0 \n" 103 | "\tmov %4, #1\n" 104 | 105 | "\tsubs %3, %0, %1, asl #14 \n" 106 | "\torrpl %2, %2, %4, asl #14 \n" 107 | "\tmovpl %0, %3 \n" 108 | 109 | "\tsubs %3, %0, %1, asl #13 \n" 110 | "\torrpl %2, %2, %4, asl #13 \n" 111 | "\tmovpl %0, %3 \n" 112 | 113 | "\tsubs %3, %0, %1, asl #12 \n" 114 | "\torrpl %2, %2, %4, asl #12 \n" 115 | "\tmovpl %0, %3 \n" 116 | 117 | "\tsubs %3, %0, %1, asl #11 \n" 118 | "\torrpl %2, %2, %4, asl #11 \n" 119 | "\tmovpl %0, %3 \n" 120 | 121 | "\tsubs %3, %0, %1, asl #10 \n" 122 | "\torrpl %2, %2, %4, asl #10 \n" 123 | "\tmovpl %0, %3 \n" 124 | 125 | "\tsubs %3, %0, %1, asl #9 \n" 126 | "\torrpl %2, %2, %4, asl #9 \n" 127 | "\tmovpl %0, %3 \n" 128 | 129 | "\tsubs %3, %0, %1, asl #8 \n" 130 | "\torrpl %2, %2, %4, asl #8 \n" 131 | "\tmovpl %0, %3 \n" 132 | 133 | "\tsubs %3, %0, %1, asl #7 \n" 134 | "\torrpl %2, %2, %4, asl #7 \n" 135 | "\tmovpl %0, %3 \n" 136 | 137 | "\tsubs %3, %0, %1, asl #6 \n" 138 | "\torrpl %2, %2, %4, asl #6 \n" 139 | "\tmovpl %0, %3 \n" 140 | 141 | "\tsubs %3, %0, %1, asl #5 \n" 142 | "\torrpl %2, %2, %4, asl #5 \n" 143 | "\tmovpl %0, %3 \n" 144 | 145 | "\tsubs %3, %0, %1, asl #4 \n" 146 | "\torrpl %2, %2, %4, asl #4 \n" 147 | "\tmovpl %0, %3 \n" 148 | 149 | "\tsubs %3, %0, %1, asl #3 \n" 150 | "\torrpl %2, %2, %4, asl #3 \n" 151 | "\tmovpl %0, %3 \n" 152 | 153 | "\tsubs %3, %0, %1, asl #2 \n" 154 | "\torrpl %2, %2, %4, asl #2 \n" 155 | "\tmovpl %0, %3 \n" 156 | 157 | "\tsubs %3, %0, %1, asl #1 \n" 158 | "\torrpl %2, %2, %4, asl #1 \n" 159 | "\tmovpl %0, %3 \n" 160 | 161 | "\tsubs %3, %0, %1 \n" 162 | "\torrpl %2, %2, %4 \n" 163 | "\tmovpl %0, %3 \n" 164 | 165 | "\tmovs %5, %5, lsr #31 \n" 166 | "\trsbne %2, %2, #0 \n" 167 | : "=r" (dead1), "=r" (dead2), "=r" (res), 168 | "=r" (dead3), "=r" (dead4), "=r" (dead5) 169 | : "0" (a), "1" (b), "2" (res) 170 | : "memory", "cc" 171 | ); 172 | return res; 173 | } 174 | 175 | 176 | 177 | 178 | #endif 179 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/fixed_bfin.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2005 Analog Devices 2 | Author: Jean-Marc Valin */ 3 | /** 4 | @file fixed_bfin.h 5 | @brief Blackfin fixed-point operations 6 | */ 7 | /* 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions 10 | are met: 11 | 12 | - Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | 15 | - Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | 19 | - Neither the name of the Xiph.org Foundation nor the names of its 20 | contributors may be used to endorse or promote products derived from 21 | this software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #ifndef FIXED_BFIN_H 37 | #define FIXED_BFIN_H 38 | 39 | #include "bfin.h" 40 | 41 | #undef PDIV32_16 42 | static inline spx_word16_t PDIV32_16(spx_word32_t a, spx_word16_t b) 43 | { 44 | spx_word32_t res, bb; 45 | bb = b; 46 | a += b>>1; 47 | __asm__ ( 48 | "P0 = 15;\n\t" 49 | "R0 = %1;\n\t" 50 | "R1 = %2;\n\t" 51 | //"R0 = R0 + R1;\n\t" 52 | "R0 <<= 1;\n\t" 53 | "DIVS (R0, R1);\n\t" 54 | "LOOP divide%= LC0 = P0;\n\t" 55 | "LOOP_BEGIN divide%=;\n\t" 56 | "DIVQ (R0, R1);\n\t" 57 | "LOOP_END divide%=;\n\t" 58 | "R0 = R0.L;\n\t" 59 | "%0 = R0;\n\t" 60 | : "=m" (res) 61 | : "m" (a), "m" (bb) 62 | : "P0", "R0", "R1", "ASTAT" BFIN_HWLOOP0_REGS); 63 | return res; 64 | } 65 | 66 | #undef DIV32_16 67 | static inline spx_word16_t DIV32_16(spx_word32_t a, spx_word16_t b) 68 | { 69 | spx_word32_t res, bb; 70 | bb = b; 71 | /* Make the roundinf consistent with the C version 72 | (do we need to do that?)*/ 73 | if (a<0) 74 | a += (b-1); 75 | __asm__ ( 76 | "P0 = 15;\n\t" 77 | "R0 = %1;\n\t" 78 | "R1 = %2;\n\t" 79 | "R0 <<= 1;\n\t" 80 | "DIVS (R0, R1);\n\t" 81 | "LOOP divide%= LC0 = P0;\n\t" 82 | "LOOP_BEGIN divide%=;\n\t" 83 | "DIVQ (R0, R1);\n\t" 84 | "LOOP_END divide%=;\n\t" 85 | "R0 = R0.L;\n\t" 86 | "%0 = R0;\n\t" 87 | : "=m" (res) 88 | : "m" (a), "m" (bb) 89 | : "P0", "R0", "R1", "ASTAT" BFIN_HWLOOP0_REGS); 90 | return res; 91 | } 92 | 93 | #undef MAX16 94 | static inline spx_word16_t MAX16(spx_word16_t a, spx_word16_t b) 95 | { 96 | spx_word32_t res; 97 | __asm__ ( 98 | "%1 = %1.L (X);\n\t" 99 | "%2 = %2.L (X);\n\t" 100 | "%0 = MAX(%1,%2);" 101 | : "=d" (res) 102 | : "%d" (a), "d" (b) 103 | : "ASTAT" 104 | ); 105 | return res; 106 | } 107 | 108 | #undef MULT16_32_Q15 109 | static inline spx_word32_t MULT16_32_Q15(spx_word16_t a, spx_word32_t b) 110 | { 111 | spx_word32_t res; 112 | __asm__ 113 | ( 114 | "A1 = %2.L*%1.L (M);\n\t" 115 | "A1 = A1 >>> 15;\n\t" 116 | "%0 = (A1 += %2.L*%1.H) ;\n\t" 117 | : "=&W" (res), "=&d" (b) 118 | : "d" (a), "1" (b) 119 | : "A1", "ASTAT" 120 | ); 121 | return res; 122 | } 123 | 124 | #undef MAC16_32_Q15 125 | static inline spx_word32_t MAC16_32_Q15(spx_word32_t c, spx_word16_t a, spx_word32_t b) 126 | { 127 | spx_word32_t res; 128 | __asm__ 129 | ( 130 | "A1 = %2.L*%1.L (M);\n\t" 131 | "A1 = A1 >>> 15;\n\t" 132 | "%0 = (A1 += %2.L*%1.H);\n\t" 133 | "%0 = %0 + %4;\n\t" 134 | : "=&W" (res), "=&d" (b) 135 | : "d" (a), "1" (b), "d" (c) 136 | : "A1", "ASTAT" 137 | ); 138 | return res; 139 | } 140 | 141 | #undef MULT16_32_Q14 142 | static inline spx_word32_t MULT16_32_Q14(spx_word16_t a, spx_word32_t b) 143 | { 144 | spx_word32_t res; 145 | __asm__ 146 | ( 147 | "%2 <<= 1;\n\t" 148 | "A1 = %1.L*%2.L (M);\n\t" 149 | "A1 = A1 >>> 15;\n\t" 150 | "%0 = (A1 += %1.L*%2.H);\n\t" 151 | : "=W" (res), "=d" (a), "=d" (b) 152 | : "1" (a), "2" (b) 153 | : "A1", "ASTAT" 154 | ); 155 | return res; 156 | } 157 | 158 | #undef MAC16_32_Q14 159 | static inline spx_word32_t MAC16_32_Q14(spx_word32_t c, spx_word16_t a, spx_word32_t b) 160 | { 161 | spx_word32_t res; 162 | __asm__ 163 | ( 164 | "%1 <<= 1;\n\t" 165 | "A1 = %2.L*%1.L (M);\n\t" 166 | "A1 = A1 >>> 15;\n\t" 167 | "%0 = (A1 += %2.L*%1.H);\n\t" 168 | "%0 = %0 + %4;\n\t" 169 | : "=&W" (res), "=&d" (b) 170 | : "d" (a), "1" (b), "d" (c) 171 | : "A1", "ASTAT" 172 | ); 173 | return res; 174 | } 175 | 176 | #endif 177 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/fixed_generic.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2003 Jean-Marc Valin */ 2 | /** 3 | @file fixed_generic.h 4 | @brief Generic fixed-point operations 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef FIXED_GENERIC_H 36 | #define FIXED_GENERIC_H 37 | 38 | #define QCONST16(x,bits) ((spx_word16_t)(.5+(x)*(((spx_word32_t)1)<<(bits)))) 39 | #define QCONST32(x,bits) ((spx_word32_t)(.5+(x)*(((spx_word32_t)1)<<(bits)))) 40 | 41 | #define NEG16(x) (-(x)) 42 | #define NEG32(x) (-(x)) 43 | #define EXTRACT16(x) ((spx_word16_t)(x)) 44 | #define EXTEND32(x) ((spx_word32_t)(x)) 45 | #define SHR16(a,shift) ((a) >> (shift)) 46 | #define SHL16(a,shift) ((a) << (shift)) 47 | #define SHR32(a,shift) ((a) >> (shift)) 48 | #define SHL32(a,shift) ((a) << (shift)) 49 | #define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift)) 50 | #define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift)) 51 | #define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift))) 52 | #define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 53 | #define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 54 | 55 | #define SATURATE32PSHR(x,shift,a) (((x)>=(SHL32(a,shift))) ? (a) : \ 56 | (x)<=-(SHL32(a,shift)) ? -(a) : \ 57 | (PSHR32(x, shift))) 58 | 59 | #define SHR(a,shift) ((a) >> (shift)) 60 | #define SHL(a,shift) ((spx_word32_t)(a) << (shift)) 61 | #define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift)) 62 | #define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x))) 63 | 64 | 65 | #define ADD16(a,b) ((spx_word16_t)((spx_word16_t)(a)+(spx_word16_t)(b))) 66 | #define SUB16(a,b) ((spx_word16_t)(a)-(spx_word16_t)(b)) 67 | #define ADD32(a,b) ((spx_word32_t)(a)+(spx_word32_t)(b)) 68 | #define SUB32(a,b) ((spx_word32_t)(a)-(spx_word32_t)(b)) 69 | 70 | 71 | /* result fits in 16 bits */ 72 | #define MULT16_16_16(a,b) ((((spx_word16_t)(a))*((spx_word16_t)(b)))) 73 | 74 | /* (spx_word32_t)(spx_word16_t) gives TI compiler a hint that it's 16x16->32 multiply */ 75 | #define MULT16_16(a,b) (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b))) 76 | 77 | #define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b)))) 78 | #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12)) 79 | #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13)) 80 | #define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14)) 81 | 82 | #define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)) 83 | #define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))) 84 | 85 | #define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15)) 86 | #define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)) 87 | #define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))) 88 | 89 | 90 | #define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11))) 91 | #define MAC16_16_Q13(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),13))) 92 | #define MAC16_16_P13(c,a,b) (ADD32((c),SHR(ADD32(4096,MULT16_16((a),(b))),13))) 93 | 94 | #define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11)) 95 | #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13)) 96 | #define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14)) 97 | #define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15)) 98 | 99 | #define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13)) 100 | #define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14)) 101 | #define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15)) 102 | 103 | #define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15)) 104 | 105 | #define DIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a))/((spx_word16_t)(b)))) 106 | #define PDIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a)+((spx_word16_t)(b)>>1))/((spx_word16_t)(b)))) 107 | #define DIV32(a,b) (((spx_word32_t)(a))/((spx_word32_t)(b))) 108 | #define PDIV32(a,b) (((spx_word32_t)(a)+((spx_word16_t)(b)>>1))/((spx_word32_t)(b))) 109 | 110 | #endif 111 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/kiss_fft.h: -------------------------------------------------------------------------------- 1 | #ifndef KISS_FFT_H 2 | #define KISS_FFT_H 3 | 4 | #include 5 | #include 6 | #include "arch.h" 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* 13 | ATTENTION! 14 | If you would like a : 15 | -- a utility that will handle the caching of fft objects 16 | -- real-only (no imaginary time component ) FFT 17 | -- a multi-dimensional FFT 18 | -- a command-line utility to perform ffts 19 | -- a command-line utility to perform fast-convolution filtering 20 | 21 | Then see kfc.h kiss_fftr.h kiss_fftnd.h fftutil.c kiss_fastfir.c 22 | in the tools/ directory. 23 | */ 24 | 25 | #ifdef USE_SIMD 26 | # include 27 | # define kiss_fft_scalar __m128 28 | #define KISS_FFT_MALLOC(nbytes) memalign(16,nbytes) 29 | #else 30 | #define KISS_FFT_MALLOC speex_alloc 31 | #endif 32 | 33 | 34 | #ifdef FIXED_POINT 35 | #include "arch.h" 36 | # define kiss_fft_scalar spx_int16_t 37 | #else 38 | # ifndef kiss_fft_scalar 39 | /* default is float */ 40 | # define kiss_fft_scalar float 41 | # endif 42 | #endif 43 | 44 | typedef struct { 45 | kiss_fft_scalar r; 46 | kiss_fft_scalar i; 47 | }kiss_fft_cpx; 48 | 49 | typedef struct kiss_fft_state* kiss_fft_cfg; 50 | 51 | /* 52 | * kiss_fft_alloc 53 | * 54 | * Initialize a FFT (or IFFT) algorithm's cfg/state buffer. 55 | * 56 | * typical usage: kiss_fft_cfg mycfg=kiss_fft_alloc(1024,0,NULL,NULL); 57 | * 58 | * The return value from fft_alloc is a cfg buffer used internally 59 | * by the fft routine or NULL. 60 | * 61 | * If lenmem is NULL, then kiss_fft_alloc will allocate a cfg buffer using malloc. 62 | * The returned value should be free()d when done to avoid memory leaks. 63 | * 64 | * The state can be placed in a user supplied buffer 'mem': 65 | * If lenmem is not NULL and mem is not NULL and *lenmem is large enough, 66 | * then the function places the cfg in mem and the size used in *lenmem 67 | * and returns mem. 68 | * 69 | * If lenmem is not NULL and ( mem is NULL or *lenmem is not large enough), 70 | * then the function returns NULL and places the minimum cfg 71 | * buffer size in *lenmem. 72 | * */ 73 | 74 | kiss_fft_cfg kiss_fft_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem); 75 | 76 | /* 77 | * kiss_fft(cfg,in_out_buf) 78 | * 79 | * Perform an FFT on a complex input buffer. 80 | * for a forward FFT, 81 | * fin should be f[0] , f[1] , ... ,f[nfft-1] 82 | * fout will be F[0] , F[1] , ... ,F[nfft-1] 83 | * Note that each element is complex and can be accessed like 84 | f[k].r and f[k].i 85 | * */ 86 | void kiss_fft(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout); 87 | 88 | /* 89 | A more generic version of the above function. It reads its input from every Nth sample. 90 | * */ 91 | void kiss_fft_stride(kiss_fft_cfg cfg,const kiss_fft_cpx *fin,kiss_fft_cpx *fout,int fin_stride); 92 | 93 | /* If kiss_fft_alloc allocated a buffer, it is one contiguous 94 | buffer and can be simply free()d when no longer needed*/ 95 | #define kiss_fft_free speex_free 96 | 97 | /* 98 | Cleans up some memory that gets managed internally. Not necessary to call, but it might clean up 99 | your compiler output to call this before you exit. 100 | */ 101 | void kiss_fft_cleanup(void); 102 | 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/kiss_fftr.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2003-2004, Mark Borgerding 3 | 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | * Neither the author nor the names of any contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | */ 14 | 15 | #ifdef HAVE_CONFIG_H 16 | #include "config.h" 17 | #endif 18 | 19 | #include "os_support.h" 20 | #include "kiss_fftr.h" 21 | #include "_kiss_fft_guts.h" 22 | 23 | struct kiss_fftr_state{ 24 | kiss_fft_cfg substate; 25 | kiss_fft_cpx * tmpbuf; 26 | kiss_fft_cpx * super_twiddles; 27 | #ifdef USE_SIMD 28 | long pad; 29 | #endif 30 | }; 31 | 32 | kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem,size_t * lenmem) 33 | { 34 | int i; 35 | kiss_fftr_cfg st = NULL; 36 | size_t subsize, memneeded; 37 | 38 | if (nfft & 1) { 39 | speex_warning("Real FFT optimization must be even.\n"); 40 | return NULL; 41 | } 42 | nfft >>= 1; 43 | 44 | kiss_fft_alloc (nfft, inverse_fft, NULL, &subsize); 45 | memneeded = sizeof(struct kiss_fftr_state) + subsize + sizeof(kiss_fft_cpx) * ( nfft * 2); 46 | 47 | if (lenmem == NULL) { 48 | st = (kiss_fftr_cfg) KISS_FFT_MALLOC (memneeded); 49 | } else { 50 | if (*lenmem >= memneeded) 51 | st = (kiss_fftr_cfg) mem; 52 | *lenmem = memneeded; 53 | } 54 | if (!st) 55 | return NULL; 56 | 57 | st->substate = (kiss_fft_cfg) (st + 1); /*just beyond kiss_fftr_state struct */ 58 | st->tmpbuf = (kiss_fft_cpx *) (((char *) st->substate) + subsize); 59 | st->super_twiddles = st->tmpbuf + nfft; 60 | kiss_fft_alloc(nfft, inverse_fft, st->substate, &subsize); 61 | 62 | #ifdef FIXED_POINT 63 | for (i=0;i>1); 65 | if (!inverse_fft) 66 | phase = -phase; 67 | kf_cexp2(st->super_twiddles+i, DIV32(SHL32(phase,16),nfft)); 68 | } 69 | #else 70 | for (i=0;isuper_twiddles+i, phase ); 76 | } 77 | #endif 78 | return st; 79 | } 80 | 81 | void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata) 82 | { 83 | /* input buffer timedata is stored row-wise */ 84 | int k,ncfft; 85 | kiss_fft_cpx fpnk,fpk,f1k,f2k,tw,tdc; 86 | 87 | if ( st->substate->inverse) { 88 | speex_fatal("kiss fft usage error: improper alloc\n"); 89 | } 90 | 91 | ncfft = st->substate->nfft; 92 | 93 | /*perform the parallel fft of two real signals packed in real,imag*/ 94 | kiss_fft( st->substate , (const kiss_fft_cpx*)timedata, st->tmpbuf ); 95 | /* The real part of the DC element of the frequency spectrum in st->tmpbuf 96 | * contains the sum of the even-numbered elements of the input time sequence 97 | * The imag part is the sum of the odd-numbered elements 98 | * 99 | * The sum of tdc.r and tdc.i is the sum of the input time sequence. 100 | * yielding DC of input time sequence 101 | * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... 102 | * yielding Nyquist bin of input time sequence 103 | */ 104 | 105 | tdc.r = st->tmpbuf[0].r; 106 | tdc.i = st->tmpbuf[0].i; 107 | C_FIXDIV(tdc,2); 108 | CHECK_OVERFLOW_OP(tdc.r ,+, tdc.i); 109 | CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i); 110 | freqdata[0].r = tdc.r + tdc.i; 111 | freqdata[ncfft].r = tdc.r - tdc.i; 112 | #ifdef USE_SIMD 113 | freqdata[ncfft].i = freqdata[0].i = _mm_set1_ps(0); 114 | #else 115 | freqdata[ncfft].i = freqdata[0].i = 0; 116 | #endif 117 | 118 | for ( k=1;k <= ncfft/2 ; ++k ) { 119 | fpk = st->tmpbuf[k]; 120 | fpnk.r = st->tmpbuf[ncfft-k].r; 121 | fpnk.i = - st->tmpbuf[ncfft-k].i; 122 | C_FIXDIV(fpk,2); 123 | C_FIXDIV(fpnk,2); 124 | 125 | C_ADD( f1k, fpk , fpnk ); 126 | C_SUB( f2k, fpk , fpnk ); 127 | C_MUL( tw , f2k , st->super_twiddles[k]); 128 | 129 | freqdata[k].r = HALF_OF(f1k.r + tw.r); 130 | freqdata[k].i = HALF_OF(f1k.i + tw.i); 131 | freqdata[ncfft-k].r = HALF_OF(f1k.r - tw.r); 132 | freqdata[ncfft-k].i = HALF_OF(tw.i - f1k.i); 133 | } 134 | } 135 | 136 | void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx *freqdata, kiss_fft_scalar *timedata) 137 | { 138 | /* input buffer timedata is stored row-wise */ 139 | int k, ncfft; 140 | 141 | if (st->substate->inverse == 0) { 142 | speex_fatal("kiss fft usage error: improper alloc\n"); 143 | } 144 | 145 | ncfft = st->substate->nfft; 146 | 147 | st->tmpbuf[0].r = freqdata[0].r + freqdata[ncfft].r; 148 | st->tmpbuf[0].i = freqdata[0].r - freqdata[ncfft].r; 149 | /*C_FIXDIV(st->tmpbuf[0],2);*/ 150 | 151 | for (k = 1; k <= ncfft / 2; ++k) { 152 | kiss_fft_cpx fk, fnkc, fek, fok, tmp; 153 | fk = freqdata[k]; 154 | fnkc.r = freqdata[ncfft - k].r; 155 | fnkc.i = -freqdata[ncfft - k].i; 156 | /*C_FIXDIV( fk , 2 ); 157 | C_FIXDIV( fnkc , 2 );*/ 158 | 159 | C_ADD (fek, fk, fnkc); 160 | C_SUB (tmp, fk, fnkc); 161 | C_MUL (fok, tmp, st->super_twiddles[k]); 162 | C_ADD (st->tmpbuf[k], fek, fok); 163 | C_SUB (st->tmpbuf[ncfft - k], fek, fok); 164 | #ifdef USE_SIMD 165 | st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0); 166 | #else 167 | st->tmpbuf[ncfft - k].i *= -1; 168 | #endif 169 | } 170 | kiss_fft (st->substate, st->tmpbuf, (kiss_fft_cpx *) timedata); 171 | } 172 | 173 | void kiss_fftr2(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_scalar *freqdata) 174 | { 175 | /* input buffer timedata is stored row-wise */ 176 | int k,ncfft; 177 | kiss_fft_cpx f2k,tdc; 178 | spx_word32_t f1kr, f1ki, twr, twi; 179 | 180 | if ( st->substate->inverse) { 181 | speex_fatal("kiss fft usage error: improper alloc\n"); 182 | } 183 | 184 | ncfft = st->substate->nfft; 185 | 186 | /*perform the parallel fft of two real signals packed in real,imag*/ 187 | kiss_fft( st->substate , (const kiss_fft_cpx*)timedata, st->tmpbuf ); 188 | /* The real part of the DC element of the frequency spectrum in st->tmpbuf 189 | * contains the sum of the even-numbered elements of the input time sequence 190 | * The imag part is the sum of the odd-numbered elements 191 | * 192 | * The sum of tdc.r and tdc.i is the sum of the input time sequence. 193 | * yielding DC of input time sequence 194 | * The difference of tdc.r - tdc.i is the sum of the input (dot product) [1,-1,1,-1... 195 | * yielding Nyquist bin of input time sequence 196 | */ 197 | 198 | tdc.r = st->tmpbuf[0].r; 199 | tdc.i = st->tmpbuf[0].i; 200 | C_FIXDIV(tdc,2); 201 | CHECK_OVERFLOW_OP(tdc.r ,+, tdc.i); 202 | CHECK_OVERFLOW_OP(tdc.r ,-, tdc.i); 203 | freqdata[0] = tdc.r + tdc.i; 204 | freqdata[2*ncfft-1] = tdc.r - tdc.i; 205 | 206 | for ( k=1;k <= ncfft/2 ; ++k ) 207 | { 208 | /*fpk = st->tmpbuf[k]; 209 | fpnk.r = st->tmpbuf[ncfft-k].r; 210 | fpnk.i = - st->tmpbuf[ncfft-k].i; 211 | C_FIXDIV(fpk,2); 212 | C_FIXDIV(fpnk,2); 213 | 214 | C_ADD( f1k, fpk , fpnk ); 215 | C_SUB( f2k, fpk , fpnk ); 216 | 217 | C_MUL( tw , f2k , st->super_twiddles[k]); 218 | 219 | freqdata[2*k-1] = HALF_OF(f1k.r + tw.r); 220 | freqdata[2*k] = HALF_OF(f1k.i + tw.i); 221 | freqdata[2*(ncfft-k)-1] = HALF_OF(f1k.r - tw.r); 222 | freqdata[2*(ncfft-k)] = HALF_OF(tw.i - f1k.i); 223 | */ 224 | 225 | /*f1k.r = PSHR32(ADD32(EXTEND32(st->tmpbuf[k].r), EXTEND32(st->tmpbuf[ncfft-k].r)),1); 226 | f1k.i = PSHR32(SUB32(EXTEND32(st->tmpbuf[k].i), EXTEND32(st->tmpbuf[ncfft-k].i)),1); 227 | f2k.r = PSHR32(SUB32(EXTEND32(st->tmpbuf[k].r), EXTEND32(st->tmpbuf[ncfft-k].r)),1); 228 | f2k.i = SHR32(ADD32(EXTEND32(st->tmpbuf[k].i), EXTEND32(st->tmpbuf[ncfft-k].i)),1); 229 | 230 | C_MUL( tw , f2k , st->super_twiddles[k]); 231 | 232 | freqdata[2*k-1] = HALF_OF(f1k.r + tw.r); 233 | freqdata[2*k] = HALF_OF(f1k.i + tw.i); 234 | freqdata[2*(ncfft-k)-1] = HALF_OF(f1k.r - tw.r); 235 | freqdata[2*(ncfft-k)] = HALF_OF(tw.i - f1k.i); 236 | */ 237 | f2k.r = SHR32(SUB32(EXTEND32(st->tmpbuf[k].r), EXTEND32(st->tmpbuf[ncfft-k].r)),1); 238 | f2k.i = PSHR32(ADD32(EXTEND32(st->tmpbuf[k].i), EXTEND32(st->tmpbuf[ncfft-k].i)),1); 239 | 240 | f1kr = SHL32(ADD32(EXTEND32(st->tmpbuf[k].r), EXTEND32(st->tmpbuf[ncfft-k].r)),13); 241 | f1ki = SHL32(SUB32(EXTEND32(st->tmpbuf[k].i), EXTEND32(st->tmpbuf[ncfft-k].i)),13); 242 | 243 | twr = SHR32(SUB32(MULT16_16(f2k.r,st->super_twiddles[k].r),MULT16_16(f2k.i,st->super_twiddles[k].i)), 1); 244 | twi = SHR32(ADD32(MULT16_16(f2k.i,st->super_twiddles[k].r),MULT16_16(f2k.r,st->super_twiddles[k].i)), 1); 245 | 246 | #ifdef FIXED_POINT 247 | freqdata[2*k-1] = PSHR32(f1kr + twr, 15); 248 | freqdata[2*k] = PSHR32(f1ki + twi, 15); 249 | freqdata[2*(ncfft-k)-1] = PSHR32(f1kr - twr, 15); 250 | freqdata[2*(ncfft-k)] = PSHR32(twi - f1ki, 15); 251 | #else 252 | freqdata[2*k-1] = .5f*(f1kr + twr); 253 | freqdata[2*k] = .5f*(f1ki + twi); 254 | freqdata[2*(ncfft-k)-1] = .5f*(f1kr - twr); 255 | freqdata[2*(ncfft-k)] = .5f*(twi - f1ki); 256 | 257 | #endif 258 | } 259 | } 260 | 261 | void kiss_fftri2(kiss_fftr_cfg st,const kiss_fft_scalar *freqdata,kiss_fft_scalar *timedata) 262 | { 263 | /* input buffer timedata is stored row-wise */ 264 | int k, ncfft; 265 | 266 | if (st->substate->inverse == 0) { 267 | speex_fatal ("kiss fft usage error: improper alloc\n"); 268 | } 269 | 270 | ncfft = st->substate->nfft; 271 | 272 | st->tmpbuf[0].r = freqdata[0] + freqdata[2*ncfft-1]; 273 | st->tmpbuf[0].i = freqdata[0] - freqdata[2*ncfft-1]; 274 | /*C_FIXDIV(st->tmpbuf[0],2);*/ 275 | 276 | for (k = 1; k <= ncfft / 2; ++k) { 277 | kiss_fft_cpx fk, fnkc, fek, fok, tmp; 278 | fk.r = freqdata[2*k-1]; 279 | fk.i = freqdata[2*k]; 280 | fnkc.r = freqdata[2*(ncfft - k)-1]; 281 | fnkc.i = -freqdata[2*(ncfft - k)]; 282 | /*C_FIXDIV( fk , 2 ); 283 | C_FIXDIV( fnkc , 2 );*/ 284 | 285 | C_ADD (fek, fk, fnkc); 286 | C_SUB (tmp, fk, fnkc); 287 | C_MUL (fok, tmp, st->super_twiddles[k]); 288 | C_ADD (st->tmpbuf[k], fek, fok); 289 | C_SUB (st->tmpbuf[ncfft - k], fek, fok); 290 | #ifdef USE_SIMD 291 | st->tmpbuf[ncfft - k].i *= _mm_set1_ps(-1.0); 292 | #else 293 | st->tmpbuf[ncfft - k].i *= -1; 294 | #endif 295 | } 296 | kiss_fft (st->substate, st->tmpbuf, (kiss_fft_cpx *) timedata); 297 | } 298 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/kiss_fftr.h: -------------------------------------------------------------------------------- 1 | #ifndef KISS_FTR_H 2 | #define KISS_FTR_H 3 | 4 | #include "kiss_fft.h" 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | 10 | /* 11 | 12 | Real optimized version can save about 45% cpu time vs. complex fft of a real seq. 13 | 14 | 15 | 16 | */ 17 | 18 | typedef struct kiss_fftr_state *kiss_fftr_cfg; 19 | 20 | 21 | kiss_fftr_cfg kiss_fftr_alloc(int nfft,int inverse_fft,void * mem, size_t * lenmem); 22 | /* 23 | nfft must be even 24 | 25 | If you don't care to allocate space, use mem = lenmem = NULL 26 | */ 27 | 28 | 29 | void kiss_fftr(kiss_fftr_cfg cfg,const kiss_fft_scalar *timedata,kiss_fft_cpx *freqdata); 30 | /* 31 | input timedata has nfft scalar points 32 | output freqdata has nfft/2+1 complex points 33 | */ 34 | 35 | void kiss_fftr2(kiss_fftr_cfg st,const kiss_fft_scalar *timedata,kiss_fft_scalar *freqdata); 36 | 37 | void kiss_fftri(kiss_fftr_cfg cfg,const kiss_fft_cpx *freqdata,kiss_fft_scalar *timedata); 38 | 39 | void kiss_fftri2(kiss_fftr_cfg st,const kiss_fft_scalar *freqdata, kiss_fft_scalar *timedata); 40 | 41 | /* 42 | input freqdata has nfft/2+1 complex points 43 | output timedata has nfft scalar points 44 | */ 45 | 46 | #define kiss_fftr_free speex_free 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | #endif 52 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/math_approx.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 Jean-Marc Valin */ 2 | /** 3 | @file math_approx.h 4 | @brief Various math approximation functions for Speex 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef MATH_APPROX_H 36 | #define MATH_APPROX_H 37 | 38 | #include "arch.h" 39 | 40 | #ifndef FIXED_POINT 41 | 42 | #define spx_sqrt sqrt 43 | #define spx_acos acos 44 | #define spx_exp exp 45 | #define spx_cos_norm(x) (cos((.5f*M_PI)*(x))) 46 | #define spx_atan atan 47 | 48 | /** Generate a pseudo-random number */ 49 | static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed) 50 | { 51 | const unsigned int jflone = 0x3f800000; 52 | const unsigned int jflmsk = 0x007fffff; 53 | union {int i; float f;} ran; 54 | *seed = 1664525 * *seed + 1013904223; 55 | ran.i = jflone | (jflmsk & *seed); 56 | ran.f -= 1.5; 57 | return 3.4642*std*ran.f; 58 | } 59 | 60 | 61 | #endif 62 | 63 | 64 | static inline spx_int16_t spx_ilog2(spx_uint32_t x) 65 | { 66 | int r=0; 67 | if (x>=(spx_int32_t)65536) 68 | { 69 | x >>= 16; 70 | r += 16; 71 | } 72 | if (x>=256) 73 | { 74 | x >>= 8; 75 | r += 8; 76 | } 77 | if (x>=16) 78 | { 79 | x >>= 4; 80 | r += 4; 81 | } 82 | if (x>=4) 83 | { 84 | x >>= 2; 85 | r += 2; 86 | } 87 | if (x>=2) 88 | { 89 | r += 1; 90 | } 91 | return r; 92 | } 93 | 94 | static inline spx_int16_t spx_ilog4(spx_uint32_t x) 95 | { 96 | int r=0; 97 | if (x>=(spx_int32_t)65536) 98 | { 99 | x >>= 16; 100 | r += 8; 101 | } 102 | if (x>=256) 103 | { 104 | x >>= 8; 105 | r += 4; 106 | } 107 | if (x>=16) 108 | { 109 | x >>= 4; 110 | r += 2; 111 | } 112 | if (x>=4) 113 | { 114 | r += 1; 115 | } 116 | return r; 117 | } 118 | 119 | #ifdef FIXED_POINT 120 | 121 | /** Generate a pseudo-random number */ 122 | static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed) 123 | { 124 | spx_word32_t res; 125 | *seed = 1664525 * *seed + 1013904223; 126 | res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); 127 | return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); 128 | } 129 | 130 | /* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25723*x^3 (for .25 < x < 1) */ 131 | /*#define C0 3634 132 | #define C1 21173 133 | #define C2 -12627 134 | #define C3 4215*/ 135 | 136 | /* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25659*x^3 (for .25 < x < 1) */ 137 | #define C0 3634 138 | #define C1 21173 139 | #define C2 -12627 140 | #define C3 4204 141 | 142 | static inline spx_word16_t spx_sqrt(spx_word32_t x) 143 | { 144 | int k; 145 | spx_word32_t rt; 146 | k = spx_ilog4(x)-6; 147 | x = VSHR32(x, (k<<1)); 148 | rt = ADD16(C0, MULT16_16_Q14(x, ADD16(C1, MULT16_16_Q14(x, ADD16(C2, MULT16_16_Q14(x, (C3))))))); 149 | rt = VSHR32(rt,7-k); 150 | return rt; 151 | } 152 | 153 | /* log(x) ~= -2.18151 + 4.20592*x - 2.88938*x^2 + 0.86535*x^3 (for .5 < x < 1) */ 154 | 155 | 156 | #define A1 16469 157 | #define A2 2242 158 | #define A3 1486 159 | 160 | static inline spx_word16_t spx_acos(spx_word16_t x) 161 | { 162 | int s=0; 163 | spx_word16_t ret; 164 | spx_word16_t sq; 165 | if (x<0) 166 | { 167 | s=1; 168 | x = NEG16(x); 169 | } 170 | x = SUB16(16384,x); 171 | 172 | x = x >> 1; 173 | sq = MULT16_16_Q13(x, ADD16(A1, MULT16_16_Q13(x, ADD16(A2, MULT16_16_Q13(x, (A3)))))); 174 | ret = spx_sqrt(SHL32(EXTEND32(sq),13)); 175 | 176 | /*ret = spx_sqrt(67108864*(-1.6129e-04 + 2.0104e+00*f + 2.7373e-01*f*f + 1.8136e-01*f*f*f));*/ 177 | if (s) 178 | ret = SUB16(25736,ret); 179 | return ret; 180 | } 181 | 182 | 183 | #define K1 8192 184 | #define K2 -4096 185 | #define K3 340 186 | #define K4 -10 187 | 188 | static inline spx_word16_t spx_cos(spx_word16_t x) 189 | { 190 | spx_word16_t x2; 191 | 192 | if (x<12868) 193 | { 194 | x2 = MULT16_16_P13(x,x); 195 | return ADD32(K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2)))))); 196 | } else { 197 | x = SUB16(25736,x); 198 | x2 = MULT16_16_P13(x,x); 199 | return SUB32(-K1, MULT16_16_P13(x2, ADD32(K2, MULT16_16_P13(x2, ADD32(K3, MULT16_16_P13(K4, x2)))))); 200 | } 201 | } 202 | 203 | #define L1 32767 204 | #define L2 -7651 205 | #define L3 8277 206 | #define L4 -626 207 | 208 | static inline spx_word16_t _spx_cos_pi_2(spx_word16_t x) 209 | { 210 | spx_word16_t x2; 211 | 212 | x2 = MULT16_16_P15(x,x); 213 | return ADD16(1,MIN16(32766,ADD32(SUB16(L1,x2), MULT16_16_P15(x2, ADD32(L2, MULT16_16_P15(x2, ADD32(L3, MULT16_16_P15(L4, x2)))))))); 214 | } 215 | 216 | static inline spx_word16_t spx_cos_norm(spx_word32_t x) 217 | { 218 | x = x&0x0001ffff; 219 | if (x>SHL32(EXTEND32(1), 16)) 220 | x = SUB32(SHL32(EXTEND32(1), 17),x); 221 | if (x&0x00007fff) 222 | { 223 | if (x14) 256 | return 0x7fffffff; 257 | else if (integer < -15) 258 | return 0; 259 | frac = SHL16(x-SHL16(integer,11),3); 260 | frac = ADD16(D0, MULT16_16_Q14(frac, ADD16(D1, MULT16_16_Q14(frac, ADD16(D2 , MULT16_16_Q14(D3,frac)))))); 261 | return VSHR32(EXTEND32(frac), -integer-2); 262 | } 263 | 264 | /* Input in Q11 format, output in Q16 */ 265 | static inline spx_word32_t spx_exp(spx_word16_t x) 266 | { 267 | if (x>21290) 268 | return 0x7fffffff; 269 | else if (x<-21290) 270 | return 0; 271 | else 272 | return spx_exp2(MULT16_16_P14(23637,x)); 273 | } 274 | #define M1 32767 275 | #define M2 -21 276 | #define M3 -11943 277 | #define M4 4936 278 | 279 | static inline spx_word16_t spx_atan01(spx_word16_t x) 280 | { 281 | return MULT16_16_P15(x, ADD32(M1, MULT16_16_P15(x, ADD32(M2, MULT16_16_P15(x, ADD32(M3, MULT16_16_P15(M4, x))))))); 282 | } 283 | 284 | #undef M1 285 | #undef M2 286 | #undef M3 287 | #undef M4 288 | 289 | /* Input in Q15, output in Q14 */ 290 | static inline spx_word16_t spx_atan(spx_word32_t x) 291 | { 292 | if (x <= 32767) 293 | { 294 | return SHR16(spx_atan01(x),1); 295 | } else { 296 | int e = spx_ilog2(x); 297 | if (e>=29) 298 | return 25736; 299 | x = DIV32_16(SHL32(EXTEND32(32767),29-e), EXTRACT16(SHR32(x, e-14))); 300 | return SUB16(25736, SHR16(spx_atan01(x),1)); 301 | } 302 | } 303 | #else 304 | 305 | #ifndef M_PI 306 | #define M_PI 3.14159265358979323846 /* pi */ 307 | #endif 308 | 309 | #define C1 0.9999932946f 310 | #define C2 -0.4999124376f 311 | #define C3 0.0414877472f 312 | #define C4 -0.0012712095f 313 | 314 | 315 | #define SPX_PI_2 1.5707963268 316 | static inline spx_word16_t spx_cos(spx_word16_t x) 317 | { 318 | if (x>2)-1), "0" (src), "1" (dest) 53 | : "R0", "I0", "L0", "memory" BFIN_HWLOOP0_REGS 54 | ); 55 | return dest; 56 | } 57 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/os_support.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007 Jean-Marc Valin 2 | 3 | File: os_support.h 4 | This is the (tiny) OS abstraction layer. Aside from math.h, this is the 5 | only place where system headers are allowed. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | 1. Redistributions of source code must retain the above copyright notice, 12 | this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | */ 33 | 34 | #ifndef OS_SUPPORT_H 35 | #define OS_SUPPORT_H 36 | 37 | #include 38 | #include 39 | #include 40 | 41 | #ifdef HAVE_CONFIG_H 42 | #include "config.h" 43 | #endif 44 | #ifdef OS_SUPPORT_CUSTOM 45 | #include "os_support_custom.h" 46 | #endif 47 | 48 | /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free 49 | NOTE: speex_alloc needs to CLEAR THE MEMORY */ 50 | #ifndef OVERRIDE_SPEEX_ALLOC 51 | static inline void *speex_alloc (int size) 52 | { 53 | /* WARNING: this is not equivalent to malloc(). If you want to use malloc() 54 | or your own allocator, YOU NEED TO CLEAR THE MEMORY ALLOCATED. Otherwise 55 | you will experience strange bugs */ 56 | return calloc(size,1); 57 | } 58 | #endif 59 | 60 | /** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ 61 | #ifndef OVERRIDE_SPEEX_ALLOC_SCRATCH 62 | static inline void *speex_alloc_scratch (int size) 63 | { 64 | /* Scratch space doesn't need to be cleared */ 65 | return calloc(size,1); 66 | } 67 | #endif 68 | 69 | /** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, speex_alloc and speex_free */ 70 | #ifndef OVERRIDE_SPEEX_REALLOC 71 | static inline void *speex_realloc (void *ptr, int size) 72 | { 73 | return realloc(ptr, size); 74 | } 75 | #endif 76 | 77 | /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_alloc */ 78 | #ifndef OVERRIDE_SPEEX_FREE 79 | static inline void speex_free (void *ptr) 80 | { 81 | free(ptr); 82 | } 83 | #endif 84 | 85 | /** Same as speex_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ 86 | #ifndef OVERRIDE_SPEEX_FREE_SCRATCH 87 | static inline void speex_free_scratch (void *ptr) 88 | { 89 | free(ptr); 90 | } 91 | #endif 92 | 93 | /** Copy n elements from src to dst. The 0* term provides compile-time type checking */ 94 | #ifndef OVERRIDE_SPEEX_COPY 95 | #define SPEEX_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) 96 | #endif 97 | 98 | /** Copy n elements from src to dst, allowing overlapping regions. The 0* term 99 | provides compile-time type checking */ 100 | #ifndef OVERRIDE_SPEEX_MOVE 101 | #define SPEEX_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) 102 | #endif 103 | 104 | /** For n elements worth of memory, set every byte to the value of c, starting at address dst */ 105 | #ifndef OVERRIDE_SPEEX_MEMSET 106 | #define SPEEX_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst)))) 107 | #endif 108 | 109 | 110 | #ifndef OVERRIDE_SPEEX_FATAL 111 | static inline void _speex_fatal(const char *str, const char *file, int line) 112 | { 113 | fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); 114 | exit(1); 115 | } 116 | #endif 117 | 118 | #ifndef OVERRIDE_SPEEX_WARNING 119 | static inline void speex_warning(const char *str) 120 | { 121 | #ifndef DISABLE_WARNINGS 122 | fprintf (stderr, "warning: %s\n", str); 123 | #endif 124 | } 125 | #endif 126 | 127 | #ifndef OVERRIDE_SPEEX_WARNING_INT 128 | static inline void speex_warning_int(const char *str, int val) 129 | { 130 | #ifndef DISABLE_WARNINGS 131 | fprintf (stderr, "warning: %s %d\n", str, val); 132 | #endif 133 | } 134 | #endif 135 | 136 | #ifndef OVERRIDE_SPEEX_NOTIFY 137 | static inline void speex_notify(const char *str) 138 | { 139 | #ifndef DISABLE_NOTIFICATIONS 140 | fprintf (stderr, "notification: %s\n", str); 141 | #endif 142 | } 143 | #endif 144 | 145 | #ifndef OVERRIDE_SPEEX_PUTC 146 | /** Speex wrapper for putc */ 147 | static inline void _speex_putc(int ch, void *file) 148 | { 149 | FILE *f = (FILE *)file; 150 | fprintf(f, "%c", ch); 151 | } 152 | #endif 153 | 154 | #define speex_fatal(str) _speex_fatal(str, __FILE__, __LINE__); 155 | #define speex_assert(cond) {if (!(cond)) {speex_fatal("assertion failed: " #cond);}} 156 | 157 | #ifndef RELEASE 158 | static inline void print_vec(float *vec, int len, char *name) 159 | { 160 | int i; 161 | printf ("%s ", name); 162 | for (i=0;i 51 | 52 | #ifdef FIXED_POINT 53 | 54 | typedef struct { 55 | spx_int16_t m; 56 | spx_int16_t e; 57 | } spx_float_t; 58 | 59 | static const spx_float_t FLOAT_ZERO = {0,0}; 60 | static const spx_float_t FLOAT_ONE = {16384,-14}; 61 | static const spx_float_t FLOAT_HALF = {16384,-15}; 62 | 63 | #define MIN(a,b) ((a)<(b)?(a):(b)) 64 | static inline spx_float_t PSEUDOFLOAT(spx_int32_t x) 65 | { 66 | int e=0; 67 | int sign=0; 68 | if (x<0) 69 | { 70 | sign = 1; 71 | x = -x; 72 | } 73 | if (x==0) 74 | { 75 | spx_float_t r = {0,0}; 76 | return r; 77 | } 78 | e = spx_ilog2(ABS32(x))-14; 79 | x = VSHR32(x, e); 80 | if (sign) 81 | { 82 | spx_float_t r; 83 | r.m = -x; 84 | r.e = e; 85 | return r; 86 | } 87 | else 88 | { 89 | spx_float_t r; 90 | r.m = x; 91 | r.e = e; 92 | return r; 93 | } 94 | } 95 | 96 | 97 | static inline spx_float_t FLOAT_ADD(spx_float_t a, spx_float_t b) 98 | { 99 | spx_float_t r; 100 | if (a.m==0) 101 | return b; 102 | else if (b.m==0) 103 | return a; 104 | if ((a).e > (b).e) 105 | { 106 | r.m = ((a).m>>1) + ((b).m>>MIN(15,(a).e-(b).e+1)); 107 | r.e = (a).e+1; 108 | } 109 | else 110 | { 111 | r.m = ((b).m>>1) + ((a).m>>MIN(15,(b).e-(a).e+1)); 112 | r.e = (b).e+1; 113 | } 114 | if (r.m>0) 115 | { 116 | if (r.m<16384) 117 | { 118 | r.m<<=1; 119 | r.e-=1; 120 | } 121 | } else { 122 | if (r.m>-16384) 123 | { 124 | r.m<<=1; 125 | r.e-=1; 126 | } 127 | } 128 | /*printf ("%f + %f = %f\n", REALFLOAT(a), REALFLOAT(b), REALFLOAT(r));*/ 129 | return r; 130 | } 131 | 132 | static inline spx_float_t FLOAT_SUB(spx_float_t a, spx_float_t b) 133 | { 134 | spx_float_t r; 135 | if (a.m==0) 136 | return b; 137 | else if (b.m==0) 138 | return a; 139 | if ((a).e > (b).e) 140 | { 141 | r.m = ((a).m>>1) - ((b).m>>MIN(15,(a).e-(b).e+1)); 142 | r.e = (a).e+1; 143 | } 144 | else 145 | { 146 | r.m = ((a).m>>MIN(15,(b).e-(a).e+1)) - ((b).m>>1); 147 | r.e = (b).e+1; 148 | } 149 | if (r.m>0) 150 | { 151 | if (r.m<16384) 152 | { 153 | r.m<<=1; 154 | r.e-=1; 155 | } 156 | } else { 157 | if (r.m>-16384) 158 | { 159 | r.m<<=1; 160 | r.e-=1; 161 | } 162 | } 163 | /*printf ("%f + %f = %f\n", REALFLOAT(a), REALFLOAT(b), REALFLOAT(r));*/ 164 | return r; 165 | } 166 | 167 | static inline int FLOAT_LT(spx_float_t a, spx_float_t b) 168 | { 169 | if (a.m==0) 170 | return b.m>0; 171 | else if (b.m==0) 172 | return a.m<0; 173 | if ((a).e > (b).e) 174 | return ((a).m>>1) < ((b).m>>MIN(15,(a).e-(b).e+1)); 175 | else 176 | return ((b).m>>1) > ((a).m>>MIN(15,(b).e-(a).e+1)); 177 | 178 | } 179 | 180 | static inline int FLOAT_GT(spx_float_t a, spx_float_t b) 181 | { 182 | return FLOAT_LT(b,a); 183 | } 184 | 185 | static inline spx_float_t FLOAT_MULT(spx_float_t a, spx_float_t b) 186 | { 187 | spx_float_t r; 188 | r.m = (spx_int16_t)((spx_int32_t)(a).m*(b).m>>15); 189 | r.e = (a).e+(b).e+15; 190 | if (r.m>0) 191 | { 192 | if (r.m<16384) 193 | { 194 | r.m<<=1; 195 | r.e-=1; 196 | } 197 | } else { 198 | if (r.m>-16384) 199 | { 200 | r.m<<=1; 201 | r.e-=1; 202 | } 203 | } 204 | /*printf ("%f * %f = %f\n", REALFLOAT(a), REALFLOAT(b), REALFLOAT(r));*/ 205 | return r; 206 | } 207 | 208 | static inline spx_float_t FLOAT_AMULT(spx_float_t a, spx_float_t b) 209 | { 210 | spx_float_t r; 211 | r.m = (spx_int16_t)((spx_int32_t)(a).m*(b).m>>15); 212 | r.e = (a).e+(b).e+15; 213 | return r; 214 | } 215 | 216 | 217 | static inline spx_float_t FLOAT_SHL(spx_float_t a, int b) 218 | { 219 | spx_float_t r; 220 | r.m = a.m; 221 | r.e = a.e+b; 222 | return r; 223 | } 224 | 225 | static inline spx_int16_t FLOAT_EXTRACT16(spx_float_t a) 226 | { 227 | if (a.e<0) 228 | return EXTRACT16((EXTEND32(a.m)+(EXTEND32(1)<<(-a.e-1)))>>-a.e); 229 | else 230 | return a.m<>-a.e; 237 | else 238 | return EXTEND32(a.m)<=SHL32(EXTEND32(b.m-1),15)) 275 | { 276 | a >>= 1; 277 | e++; 278 | } 279 | r.m = DIV32_16(a,b.m); 280 | r.e = e-b.e; 281 | return r; 282 | } 283 | 284 | 285 | /* Do NOT attempt to divide by a negative number */ 286 | static inline spx_float_t FLOAT_DIV32(spx_word32_t a, spx_word32_t b) 287 | { 288 | int e0=0,e=0; 289 | spx_float_t r; 290 | if (a==0) 291 | { 292 | return FLOAT_ZERO; 293 | } 294 | if (b>32767) 295 | { 296 | e0 = spx_ilog2(b)-14; 297 | b = VSHR32(b, e0); 298 | e0 = -e0; 299 | } 300 | e = spx_ilog2(ABS32(a))-spx_ilog2(b-1)-15; 301 | a = VSHR32(a, e); 302 | if (ABS32(a)>=SHL32(EXTEND32(b-1),15)) 303 | { 304 | a >>= 1; 305 | e++; 306 | } 307 | e += e0; 308 | r.m = DIV32_16(a,b); 309 | r.e = e; 310 | return r; 311 | } 312 | 313 | /* Do NOT attempt to divide by a negative number */ 314 | static inline spx_float_t FLOAT_DIVU(spx_float_t a, spx_float_t b) 315 | { 316 | int e=0; 317 | spx_int32_t num; 318 | spx_float_t r; 319 | if (b.m<=0) 320 | { 321 | speex_warning_int("Attempted to divide by", b.m); 322 | return FLOAT_ONE; 323 | } 324 | num = a.m; 325 | a.m = ABS16(a.m); 326 | while (a.m >= b.m) 327 | { 328 | e++; 329 | a.m >>= 1; 330 | } 331 | num = num << (15-e); 332 | r.m = DIV32_16(num,b.m); 333 | r.e = a.e-b.e-15+e; 334 | return r; 335 | } 336 | 337 | static inline spx_float_t FLOAT_SQRT(spx_float_t a) 338 | { 339 | spx_float_t r; 340 | spx_int32_t m; 341 | m = SHL32(EXTEND32(a.m), 14); 342 | r.e = a.e - 14; 343 | if (r.e & 1) 344 | { 345 | r.e -= 1; 346 | m <<= 1; 347 | } 348 | r.e >>= 1; 349 | r.m = spx_sqrt(m); 350 | return r; 351 | } 352 | 353 | #else 354 | 355 | #define spx_float_t float 356 | #define FLOAT_ZERO 0.f 357 | #define FLOAT_ONE 1.f 358 | #define FLOAT_HALF 0.5f 359 | #define PSEUDOFLOAT(x) (x) 360 | #define FLOAT_MULT(a,b) ((a)*(b)) 361 | #define FLOAT_AMULT(a,b) ((a)*(b)) 362 | #define FLOAT_MUL32(a,b) ((a)*(b)) 363 | #define FLOAT_DIV32(a,b) ((a)/(b)) 364 | #define FLOAT_EXTRACT16(a) (a) 365 | #define FLOAT_EXTRACT32(a) (a) 366 | #define FLOAT_ADD(a,b) ((a)+(b)) 367 | #define FLOAT_SUB(a,b) ((a)-(b)) 368 | #define REALFLOAT(x) (x) 369 | #define FLOAT_DIV32_FLOAT(a,b) ((a)/(b)) 370 | #define FLOAT_MUL32U(a,b) ((a)*(b)) 371 | #define FLOAT_SHL(a,b) (a) 372 | #define FLOAT_LT(a,b) ((a)<(b)) 373 | #define FLOAT_GT(a,b) ((a)>(b)) 374 | #define FLOAT_DIVU(a,b) ((a)/(b)) 375 | #define FLOAT_SQRT(a) (spx_sqrt(a)) 376 | 377 | #endif 378 | 379 | #endif 380 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/resample_neon.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007-2008 Jean-Marc Valin 2 | * Copyright (C) 2008 Thorvald Natvig 3 | * Copyright (C) 2011 Texas Instruments 4 | * author Jyri Sarha 5 | */ 6 | /** 7 | @file resample_neon.h 8 | @brief Resampler functions (NEON version) 9 | */ 10 | /* 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions 13 | are met: 14 | 15 | - Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 18 | - Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | - Neither the name of the Xiph.org Foundation nor the names of its 23 | contributors may be used to endorse or promote products derived from 24 | this software without specific prior written permission. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 27 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 28 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 29 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 30 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 31 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 32 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 33 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 34 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 35 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 36 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | */ 38 | 39 | #include 40 | 41 | #ifdef FIXED_POINT 42 | #ifdef __thumb2__ 43 | static inline int32_t saturate_32bit_to_16bit(int32_t a) { 44 | int32_t ret; 45 | asm ("ssat %[ret], #16, %[a]" 46 | : [ret] "=&r" (ret) 47 | : [a] "r" (a) 48 | : ); 49 | return ret; 50 | } 51 | #else 52 | static inline int32_t saturate_32bit_to_16bit(int32_t a) { 53 | int32_t ret; 54 | asm ("vmov.s32 d0[0], %[a]\n" 55 | "vqmovn.s32 d0, q0\n" 56 | "vmov.s16 %[ret], d0[0]\n" 57 | : [ret] "=&r" (ret) 58 | : [a] "r" (a) 59 | : "q0"); 60 | return ret; 61 | } 62 | #endif 63 | #undef WORD2INT 64 | #define WORD2INT(x) (saturate_32bit_to_16bit(x)) 65 | 66 | #define OVERRIDE_INNER_PRODUCT_SINGLE 67 | /* Only works when len % 4 == 0 */ 68 | static inline int32_t inner_product_single(const int16_t *a, const int16_t *b, unsigned int len) 69 | { 70 | int32_t ret; 71 | uint32_t remainder = len % 16; 72 | len = len - remainder; 73 | 74 | asm volatile (" cmp %[len], #0\n" 75 | " bne 1f\n" 76 | " vld1.16 {d16}, [%[b]]!\n" 77 | " vld1.16 {d20}, [%[a]]!\n" 78 | " subs %[remainder], %[remainder], #4\n" 79 | " vmull.s16 q0, d16, d20\n" 80 | " beq 5f\n" 81 | " b 4f\n" 82 | "1:" 83 | " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n" 84 | " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n" 85 | " subs %[len], %[len], #16\n" 86 | " vmull.s16 q0, d16, d20\n" 87 | " vmlal.s16 q0, d17, d21\n" 88 | " vmlal.s16 q0, d18, d22\n" 89 | " vmlal.s16 q0, d19, d23\n" 90 | " beq 3f\n" 91 | "2:" 92 | " vld1.16 {d16, d17, d18, d19}, [%[b]]!\n" 93 | " vld1.16 {d20, d21, d22, d23}, [%[a]]!\n" 94 | " subs %[len], %[len], #16\n" 95 | " vmlal.s16 q0, d16, d20\n" 96 | " vmlal.s16 q0, d17, d21\n" 97 | " vmlal.s16 q0, d18, d22\n" 98 | " vmlal.s16 q0, d19, d23\n" 99 | " bne 2b\n" 100 | "3:" 101 | " cmp %[remainder], #0\n" 102 | " beq 5f\n" 103 | "4:" 104 | " vld1.16 {d16}, [%[b]]!\n" 105 | " vld1.16 {d20}, [%[a]]!\n" 106 | " subs %[remainder], %[remainder], #4\n" 107 | " vmlal.s16 q0, d16, d20\n" 108 | " bne 4b\n" 109 | "5:" 110 | " vaddl.s32 q0, d0, d1\n" 111 | " vadd.s64 d0, d0, d1\n" 112 | " vqmovn.s64 d0, q0\n" 113 | " vqrshrn.s32 d0, q0, #15\n" 114 | " vmov.s16 %[ret], d0[0]\n" 115 | : [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b), 116 | [len] "+r" (len), [remainder] "+r" (remainder) 117 | : 118 | : "cc", "q0", 119 | "d16", "d17", "d18", "d19", 120 | "d20", "d21", "d22", "d23"); 121 | 122 | return ret; 123 | } 124 | #elif defined(FLOATING_POINT) 125 | 126 | static inline int32_t saturate_float_to_16bit(float a) { 127 | int32_t ret; 128 | asm ("vmov.f32 d0[0], %[a]\n" 129 | "vcvt.s32.f32 d0, d0, #15\n" 130 | "vqrshrn.s32 d0, q0, #15\n" 131 | "vmov.s16 %[ret], d0[0]\n" 132 | : [ret] "=&r" (ret) 133 | : [a] "r" (a) 134 | : "q0"); 135 | return ret; 136 | } 137 | #undef WORD2INT 138 | #define WORD2INT(x) (saturate_float_to_16bit(x)) 139 | 140 | #define OVERRIDE_INNER_PRODUCT_SINGLE 141 | /* Only works when len % 4 == 0 */ 142 | static inline float inner_product_single(const float *a, const float *b, unsigned int len) 143 | { 144 | float ret; 145 | uint32_t remainder = len % 16; 146 | len = len - remainder; 147 | 148 | asm volatile (" cmp %[len], #0\n" 149 | " bne 1f\n" 150 | " vld1.32 {q4}, [%[b]]!\n" 151 | " vld1.32 {q8}, [%[a]]!\n" 152 | " subs %[remainder], %[remainder], #4\n" 153 | " vmul.f32 q0, q4, q8\n" 154 | " bne 4f\n" 155 | " b 5f\n" 156 | "1:" 157 | " vld1.32 {q4, q5}, [%[b]]!\n" 158 | " vld1.32 {q8, q9}, [%[a]]!\n" 159 | " vld1.32 {q6, q7}, [%[b]]!\n" 160 | " vld1.32 {q10, q11}, [%[a]]!\n" 161 | " subs %[len], %[len], #16\n" 162 | " vmul.f32 q0, q4, q8\n" 163 | " vmul.f32 q1, q5, q9\n" 164 | " vmul.f32 q2, q6, q10\n" 165 | " vmul.f32 q3, q7, q11\n" 166 | " beq 3f\n" 167 | "2:" 168 | " vld1.32 {q4, q5}, [%[b]]!\n" 169 | " vld1.32 {q8, q9}, [%[a]]!\n" 170 | " vld1.32 {q6, q7}, [%[b]]!\n" 171 | " vld1.32 {q10, q11}, [%[a]]!\n" 172 | " subs %[len], %[len], #16\n" 173 | " vmla.f32 q0, q4, q8\n" 174 | " vmla.f32 q1, q5, q9\n" 175 | " vmla.f32 q2, q6, q10\n" 176 | " vmla.f32 q3, q7, q11\n" 177 | " bne 2b\n" 178 | "3:" 179 | " vadd.f32 q4, q0, q1\n" 180 | " vadd.f32 q5, q2, q3\n" 181 | " cmp %[remainder], #0\n" 182 | " vadd.f32 q0, q4, q5\n" 183 | " beq 5f\n" 184 | "4:" 185 | " vld1.32 {q6}, [%[b]]!\n" 186 | " vld1.32 {q10}, [%[a]]!\n" 187 | " subs %[remainder], %[remainder], #4\n" 188 | " vmla.f32 q0, q6, q10\n" 189 | " bne 4b\n" 190 | "5:" 191 | " vadd.f32 d0, d0, d1\n" 192 | " vpadd.f32 d0, d0, d0\n" 193 | " vmov.f32 %[ret], d0[0]\n" 194 | : [ret] "=&r" (ret), [a] "+r" (a), [b] "+r" (b), 195 | [len] "+l" (len), [remainder] "+l" (remainder) 196 | : 197 | : "cc", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", 198 | "q9", "q10", "q11"); 199 | return ret; 200 | } 201 | #endif 202 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/resample_sse.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007-2008 Jean-Marc Valin 2 | * Copyright (C) 2008 Thorvald Natvig 3 | */ 4 | /** 5 | @file resample_sse.h 6 | @brief Resampler functions (SSE version) 7 | */ 8 | /* 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | - Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 16 | - Redistributions in binary form must reproduce the above copyright 17 | notice, this list of conditions and the following disclaimer in the 18 | documentation and/or other materials provided with the distribution. 19 | 20 | - Neither the name of the Xiph.org Foundation nor the names of its 21 | contributors may be used to endorse or promote products derived from 22 | this software without specific prior written permission. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | */ 36 | 37 | #include 38 | 39 | #define OVERRIDE_INNER_PRODUCT_SINGLE 40 | static inline float inner_product_single(const float *a, const float *b, unsigned int len) 41 | { 42 | int i; 43 | float ret; 44 | __m128 sum = _mm_setzero_ps(); 45 | for (i=0;i 76 | #define OVERRIDE_INNER_PRODUCT_DOUBLE 77 | 78 | static inline double inner_product_double(const float *a, const float *b, unsigned int len) 79 | { 80 | int i; 81 | double ret; 82 | __m128d sum = _mm_setzero_pd(); 83 | __m128 t; 84 | for (i=0;i 53 | #include 54 | 55 | #ifndef M_PI 56 | #define M_PI 3.14159265358979323846 /* pi */ 57 | #endif 58 | 59 | #define ALLPASS_ORDER 20 60 | 61 | struct SpeexDecorrState_ { 62 | int rate; 63 | int channels; 64 | int frame_size; 65 | #ifdef VORBIS_PSYCHO 66 | VorbisPsy *psy; 67 | struct drft_lookup lookup; 68 | float *wola_mem; 69 | float *curve; 70 | #endif 71 | float *vorbis_win; 72 | int seed; 73 | float *y; 74 | 75 | /* Per-channel stuff */ 76 | float *buff; 77 | float (*ring)[ALLPASS_ORDER]; 78 | int *ringID; 79 | int *order; 80 | float *alpha; 81 | }; 82 | 83 | 84 | 85 | EXPORT SpeexDecorrState *speex_decorrelate_new(int rate, int channels, int frame_size) 86 | { 87 | int i, ch; 88 | SpeexDecorrState *st = speex_alloc(sizeof(SpeexDecorrState)); 89 | st->rate = rate; 90 | st->channels = channels; 91 | st->frame_size = frame_size; 92 | #ifdef VORBIS_PSYCHO 93 | st->psy = vorbis_psy_init(rate, 2*frame_size); 94 | spx_drft_init(&st->lookup, 2*frame_size); 95 | st->wola_mem = speex_alloc(frame_size*sizeof(float)); 96 | st->curve = speex_alloc(frame_size*sizeof(float)); 97 | #endif 98 | st->y = speex_alloc(frame_size*sizeof(float)); 99 | 100 | st->buff = speex_alloc(channels*2*frame_size*sizeof(float)); 101 | st->ringID = speex_alloc(channels*sizeof(int)); 102 | st->order = speex_alloc(channels*sizeof(int)); 103 | st->alpha = speex_alloc(channels*sizeof(float)); 104 | st->ring = speex_alloc(channels*ALLPASS_ORDER*sizeof(float)); 105 | 106 | /*FIXME: The +20 is there only as a kludge for ALL_PASS_OLA*/ 107 | st->vorbis_win = speex_alloc((2*frame_size+20)*sizeof(float)); 108 | for (i=0;i<2*frame_size;i++) 109 | st->vorbis_win[i] = sin(.5*M_PI* sin(M_PI*i/(2*frame_size))*sin(M_PI*i/(2*frame_size)) ); 110 | st->seed = rand(); 111 | 112 | for (ch=0;chring[ch][i] = 0; 116 | st->ringID[ch] = 0; 117 | st->alpha[ch] = 0; 118 | st->order[ch] = 10; 119 | } 120 | return st; 121 | } 122 | 123 | static float uni_rand(int *seed) 124 | { 125 | const unsigned int jflone = 0x3f800000; 126 | const unsigned int jflmsk = 0x007fffff; 127 | union {int i; float f;} ran; 128 | *seed = 1664525 * *seed + 1013904223; 129 | ran.i = jflone | (jflmsk & *seed); 130 | ran.f -= 1.5; 131 | return 2*ran.f; 132 | } 133 | 134 | static unsigned int irand(int *seed) 135 | { 136 | *seed = 1664525 * *seed + 1013904223; 137 | return ((unsigned int)*seed)>>16; 138 | } 139 | 140 | 141 | EXPORT void speex_decorrelate(SpeexDecorrState *st, const spx_int16_t *in, spx_int16_t *out, int strength) 142 | { 143 | int ch; 144 | float amount; 145 | 146 | if (strength<0) 147 | strength = 0; 148 | if (strength>100) 149 | strength = 100; 150 | 151 | amount = .01*strength; 152 | for (ch=0;chchannels;ch++) 153 | { 154 | int i; 155 | int N=2*st->frame_size; 156 | float beta, beta2; 157 | float *x; 158 | float max_alpha = 0; 159 | 160 | float *buff; 161 | float *ring; 162 | int ringID; 163 | int order; 164 | float alpha; 165 | 166 | buff = st->buff+ch*2*st->frame_size; 167 | ring = st->ring[ch]; 168 | ringID = st->ringID[ch]; 169 | order = st->order[ch]; 170 | alpha = st->alpha[ch]; 171 | 172 | for (i=0;iframe_size;i++) 173 | buff[i] = buff[i+st->frame_size]; 174 | for (i=0;iframe_size;i++) 175 | buff[i+st->frame_size] = in[i*st->channels+ch]; 176 | 177 | x = buff+st->frame_size; 178 | 179 | if (amount>1) 180 | beta = 1-sqrt(.4*amount); 181 | else 182 | beta = 1-0.63246*amount; 183 | if (beta<0) 184 | beta = 0; 185 | 186 | beta2 = beta; 187 | for (i=0;iframe_size;i++) 188 | { 189 | st->y[i] = alpha*(x[i-ALLPASS_ORDER+order]-beta*x[i-ALLPASS_ORDER+order-1])*st->vorbis_win[st->frame_size+i+order] 190 | + x[i-ALLPASS_ORDER]*st->vorbis_win[st->frame_size+i] 191 | - alpha*(ring[ringID] 192 | - beta*ring[ringID+1>=order?0:ringID+1]); 193 | ring[ringID++]=st->y[i]; 194 | st->y[i] *= st->vorbis_win[st->frame_size+i]; 195 | if (ringID>=order) 196 | ringID=0; 197 | } 198 | order = order+(irand(&st->seed)%3)-1; 199 | if (order < 5) 200 | order = 5; 201 | if (order > 10) 202 | order = 10; 203 | /*order = 5+(irand(&st->seed)%6);*/ 204 | max_alpha = pow(.96+.04*(amount-1),order); 205 | if (max_alpha > .98/(1.+beta2)) 206 | max_alpha = .98/(1.+beta2); 207 | 208 | alpha = alpha + .4*uni_rand(&st->seed); 209 | if (alpha > max_alpha) 210 | alpha = max_alpha; 211 | if (alpha < -max_alpha) 212 | alpha = -max_alpha; 213 | for (i=0;iframe_size;i++) 217 | { 218 | float tmp = alpha*(x[i-ALLPASS_ORDER+order]-beta*x[i-ALLPASS_ORDER+order-1])*st->vorbis_win[i+order] 219 | + x[i-ALLPASS_ORDER]*st->vorbis_win[i] 220 | - alpha*(ring[ringID] 221 | - beta*ring[ringID+1>=order?0:ringID+1]); 222 | ring[ringID++]=tmp; 223 | tmp *= st->vorbis_win[i]; 224 | if (ringID>=order) 225 | ringID=0; 226 | st->y[i] += tmp; 227 | } 228 | 229 | #ifdef VORBIS_PSYCHO 230 | float frame[N]; 231 | float scale = 1./N; 232 | for (i=0;i<2*st->frame_size;i++) 233 | frame[i] = buff[i]; 234 | //float coef = .5*0.78130; 235 | float coef = M_PI*0.075063 * 0.93763 * amount * .8 * 0.707; 236 | compute_curve(st->psy, buff, st->curve); 237 | for (i=1;iframe_size;i++) 238 | { 239 | float x1,x2; 240 | float gain; 241 | do { 242 | x1 = uni_rand(&st->seed); 243 | x2 = uni_rand(&st->seed); 244 | } while (x1*x1+x2*x2 > 1.); 245 | gain = coef*sqrt(.1+st->curve[i]); 246 | frame[2*i-1] = gain*x1; 247 | frame[2*i] = gain*x2; 248 | } 249 | frame[0] = coef*uni_rand(&st->seed)*sqrt(.1+st->curve[0]); 250 | frame[2*st->frame_size-1] = coef*uni_rand(&st->seed)*sqrt(.1+st->curve[st->frame_size-1]); 251 | spx_drft_backward(&st->lookup,frame); 252 | for (i=0;i<2*st->frame_size;i++) 253 | frame[i] *= st->vorbis_win[i]; 254 | #endif 255 | 256 | for (i=0;iframe_size;i++) 257 | { 258 | #ifdef VORBIS_PSYCHO 259 | float tmp = st->y[i] + frame[i] + st->wola_mem[i]; 260 | st->wola_mem[i] = frame[i+st->frame_size]; 261 | #else 262 | float tmp = st->y[i]; 263 | #endif 264 | if (tmp>32767) 265 | tmp = 32767; 266 | if (tmp < -32767) 267 | tmp = -32767; 268 | out[i*st->channels+ch] = tmp; 269 | } 270 | 271 | st->ringID[ch] = ringID; 272 | st->order[ch] = order; 273 | st->alpha[ch] = alpha; 274 | 275 | } 276 | } 277 | 278 | EXPORT void speex_decorrelate_destroy(SpeexDecorrState *st) 279 | { 280 | #ifdef VORBIS_PSYCHO 281 | vorbis_psy_destroy(st->psy); 282 | speex_free(st->wola_mem); 283 | speex_free(st->curve); 284 | #endif 285 | speex_free(st->buff); 286 | speex_free(st->ring); 287 | speex_free(st->ringID); 288 | speex_free(st->alpha); 289 | speex_free(st->vorbis_win); 290 | speex_free(st->order); 291 | speex_free(st->y); 292 | speex_free(st); 293 | } 294 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/smallft.h: -------------------------------------------------------------------------------- 1 | /******************************************************************** 2 | * * 3 | * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * 4 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 | * * 8 | * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 * 9 | * by the XIPHOPHORUS Company http://www.xiph.org/ * 10 | * * 11 | ******************************************************************** 12 | 13 | function: fft transform 14 | last mod: $Id: smallft.h,v 1.3 2003/09/16 18:35:45 jm Exp $ 15 | 16 | ********************************************************************/ 17 | /** 18 | @file smallft.h 19 | @brief Discrete Rotational Fourier Transform (DRFT) 20 | */ 21 | 22 | #ifndef _V_SMFT_H_ 23 | #define _V_SMFT_H_ 24 | 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /** Discrete Rotational Fourier Transform lookup */ 31 | struct drft_lookup{ 32 | int n; 33 | float *trigcache; 34 | int *splitcache; 35 | }; 36 | 37 | extern void spx_drft_forward(struct drft_lookup *l,float *data); 38 | extern void spx_drft_backward(struct drft_lookup *l,float *data); 39 | extern void spx_drft_init(struct drft_lookup *l,int n); 40 | extern void spx_drft_clear(struct drft_lookup *l); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/stack_alloc.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 Jean-Marc Valin */ 2 | /** 3 | @file stack_alloc.h 4 | @brief Temporary memory allocation on stack 5 | */ 6 | /* 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | - Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | - Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | - Neither the name of the Xiph.org Foundation nor the names of its 19 | contributors may be used to endorse or promote products derived from 20 | this software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | */ 34 | 35 | #ifndef STACK_ALLOC_H 36 | #define STACK_ALLOC_H 37 | 38 | #ifdef USE_ALLOCA 39 | # ifdef WIN32 40 | # include 41 | # else 42 | # ifdef HAVE_ALLOCA_H 43 | # include 44 | # else 45 | # include 46 | # endif 47 | # endif 48 | #endif 49 | 50 | /** 51 | * @def ALIGN(stack, size) 52 | * 53 | * Aligns the stack to a 'size' boundary 54 | * 55 | * @param stack Stack 56 | * @param size New size boundary 57 | */ 58 | 59 | /** 60 | * @def PUSH(stack, size, type) 61 | * 62 | * Allocates 'size' elements of type 'type' on the stack 63 | * 64 | * @param stack Stack 65 | * @param size Number of elements 66 | * @param type Type of element 67 | */ 68 | 69 | /** 70 | * @def VARDECL(var) 71 | * 72 | * Declare variable on stack 73 | * 74 | * @param var Variable to declare 75 | */ 76 | 77 | /** 78 | * @def ALLOC(var, size, type) 79 | * 80 | * Allocate 'size' elements of 'type' on stack 81 | * 82 | * @param var Name of variable to allocate 83 | * @param size Number of elements 84 | * @param type Type of element 85 | */ 86 | 87 | #ifdef ENABLE_VALGRIND 88 | 89 | #include 90 | 91 | #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) 92 | 93 | #define PUSH(stack, size, type) (VALGRIND_MAKE_NOACCESS(stack, 1000),ALIGN((stack),sizeof(type)),VALGRIND_MAKE_WRITABLE(stack, ((size)*sizeof(type))),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type)))) 94 | 95 | #else 96 | 97 | #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) 98 | 99 | #define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type)))) 100 | 101 | #endif 102 | 103 | #if defined(VAR_ARRAYS) 104 | #define VARDECL(var) 105 | #define ALLOC(var, size, type) type var[size] 106 | #elif defined(USE_ALLOCA) 107 | #define VARDECL(var) var 108 | #define ALLOC(var, size, type) var = alloca(sizeof(type)*(size)) 109 | #else 110 | #define VARDECL(var) var 111 | #define ALLOC(var, size, type) var = PUSH(stack, size, type) 112 | #endif 113 | 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/testdenoise.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #include "speex/speex_preprocess.h" 6 | #include 7 | 8 | #define NN 160 9 | 10 | int main() 11 | { 12 | short in[NN]; 13 | int i; 14 | SpeexPreprocessState *st; 15 | int count=0; 16 | float f; 17 | 18 | st = speex_preprocess_state_init(NN, 8000); 19 | i=1; 20 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DENOISE, &i); 21 | i=0; 22 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC, &i); 23 | i=8000; 24 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_AGC_LEVEL, &i); 25 | i=0; 26 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB, &i); 27 | f=.0; 28 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &f); 29 | f=.0; 30 | speex_preprocess_ctl(st, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &f); 31 | while (1) 32 | { 33 | int vad; 34 | fread(in, sizeof(short), NN, stdin); 35 | if (feof(stdin)) 36 | break; 37 | vad = speex_preprocess_run(st, in); 38 | /*fprintf (stderr, "%d\n", vad);*/ 39 | fwrite(in, sizeof(short), NN, stdout); 40 | count++; 41 | } 42 | speex_preprocess_state_destroy(st); 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/testecho.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #include "speex/speex_echo.h" 6 | #include "speex/speex_preprocess.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | #define NN 128 15 | #define TAIL 1024 16 | 17 | int main(int argc, char **argv) 18 | { 19 | FILE *echo_fd, *ref_fd, *e_fd; 20 | short echo_buf[NN], ref_buf[NN], e_buf[NN]; 21 | SpeexEchoState *st; 22 | SpeexPreprocessState *den; 23 | int sampleRate = 8000; 24 | 25 | if (argc != 4) 26 | { 27 | fprintf(stderr, "testecho mic_signal.sw speaker_signal.sw output.sw\n"); 28 | exit(1); 29 | } 30 | echo_fd = fopen(argv[2], "rb"); 31 | ref_fd = fopen(argv[1], "rb"); 32 | e_fd = fopen(argv[3], "wb"); 33 | 34 | st = speex_echo_state_init(NN, TAIL); 35 | den = speex_preprocess_state_init(NN, sampleRate); 36 | speex_echo_ctl(st, SPEEX_ECHO_SET_SAMPLING_RATE, &sampleRate); 37 | speex_preprocess_ctl(den, SPEEX_PREPROCESS_SET_ECHO_STATE, st); 38 | 39 | while (!feof(ref_fd) && !feof(echo_fd)) 40 | { 41 | fread(ref_buf, sizeof(short), NN, ref_fd); 42 | fread(echo_buf, sizeof(short), NN, echo_fd); 43 | speex_echo_cancellation(st, ref_buf, echo_buf, e_buf); 44 | speex_preprocess_run(den, e_buf); 45 | fwrite(e_buf, sizeof(short), NN, e_fd); 46 | } 47 | speex_echo_state_destroy(st); 48 | speex_preprocess_state_destroy(den); 49 | fclose(e_fd); 50 | fclose(echo_fd); 51 | fclose(ref_fd); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/testjitter.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #include "speex/speex_jitter.h" 6 | #include 7 | 8 | union jbpdata { 9 | unsigned int idx; 10 | unsigned char data[4]; 11 | }; 12 | 13 | void synthIn(JitterBufferPacket *in, int idx, int span) { 14 | union jbpdata d; 15 | d.idx = idx; 16 | 17 | in->data = d.data; 18 | in->len = sizeof(d); 19 | in->timestamp = idx * 10; 20 | in->span = span * 10; 21 | in->sequence = idx; 22 | in->user_data = 0; 23 | } 24 | 25 | void jitterFill(JitterBuffer *jb) { 26 | char buffer[65536]; 27 | JitterBufferPacket in, out; 28 | int i; 29 | 30 | out.data = buffer; 31 | 32 | jitter_buffer_reset(jb); 33 | 34 | for(i=0;i<100;++i) { 35 | synthIn(&in, i, 1); 36 | jitter_buffer_put(jb, &in); 37 | 38 | out.len = 65536; 39 | if (jitter_buffer_get(jb, &out, 10, NULL) != JITTER_BUFFER_OK) { 40 | printf("Fill test failed iteration %d\n", i); 41 | } 42 | if (out.timestamp != i * 10) { 43 | printf("Fill test expected %d got %d\n", i*10, out.timestamp); 44 | } 45 | jitter_buffer_tick(jb); 46 | } 47 | } 48 | 49 | int main() 50 | { 51 | char buffer[65536]; 52 | JitterBufferPacket in, out; 53 | int i; 54 | 55 | JitterBuffer *jb = jitter_buffer_init(10); 56 | 57 | out.data = buffer; 58 | 59 | /* Frozen sender case */ 60 | jitterFill(jb); 61 | for(i=0;i<100;++i) { 62 | out.len = 65536; 63 | jitter_buffer_get(jb, &out, 10, NULL); 64 | jitter_buffer_tick(jb); 65 | } 66 | synthIn(&in, 100, 1); 67 | jitter_buffer_put(jb, &in); 68 | out.len = 65536; 69 | if (jitter_buffer_get(jb, &out, 10, NULL) != JITTER_BUFFER_OK) { 70 | printf("Failed frozen sender resynchronize\n"); 71 | } else { 72 | printf("Frozen sender: Jitter %d\n", out.timestamp - 100*10); 73 | } 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /speexdsp-1.2rc3/libspeexdsp/testresample.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2007 Jean-Marc Valin 2 | 3 | File: testresample.c 4 | Testing the resampling code 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 17 | 3. The name of the author may not be used to endorse or promote products 18 | derived from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 24 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 29 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 | POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifdef HAVE_CONFIG_H 34 | #include "config.h" 35 | #endif 36 | 37 | #include "speex/speex_resampler.h" 38 | #include 39 | #include 40 | #include 41 | 42 | #define NN 256 43 | 44 | int main() 45 | { 46 | spx_uint32_t i; 47 | short *in; 48 | short *out; 49 | float *fin, *fout; 50 | int count = 0; 51 | SpeexResamplerState *st = speex_resampler_init(1, 8000, 12000, 10, NULL); 52 | speex_resampler_set_rate(st, 96000, 44100); 53 | speex_resampler_skip_zeros(st); 54 | 55 | in = malloc(NN*sizeof(short)); 56 | out = malloc(2*NN*sizeof(short)); 57 | fin = malloc(NN*sizeof(float)); 58 | fout = malloc(2*NN*sizeof(float)); 59 | while (1) 60 | { 61 | spx_uint32_t in_len; 62 | spx_uint32_t out_len; 63 | fread(in, sizeof(short), NN, stdin); 64 | if (feof(stdin)) 65 | break; 66 | for (i=0;i1e-13?log((x)*(x))*4.34294480f:-30) 43 | #define fromdB(x) (exp((x)*.11512925f)) 44 | 45 | /* The bark scale equations are approximations, since the original 46 | table was somewhat hand rolled. The below are chosen to have the 47 | best possible fit to the rolled tables, thus their somewhat odd 48 | appearance (these are more accurate and over a longer range than 49 | the oft-quoted bark equations found in the texts I have). The 50 | approximations are valid from 0 - 30kHz (nyquist) or so. 51 | 52 | all f in Hz, z in Bark */ 53 | 54 | #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n)) 55 | #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f) 56 | 57 | /* Frequency to octave. We arbitrarily declare 63.5 Hz to be octave 58 | 0.0 */ 59 | 60 | #define toOC(n) (log(n)*1.442695f-5.965784f) 61 | #define fromOC(o) (exp(((o)+5.965784f)*.693147f)) 62 | 63 | 64 | typedef struct { 65 | 66 | float noisewindowlo; 67 | float noisewindowhi; 68 | int noisewindowlomin; 69 | int noisewindowhimin; 70 | int noisewindowfixed; 71 | float noiseoff[P_BANDS]; 72 | float noisecompand[NOISE_COMPAND_LEVELS]; 73 | 74 | } VorbisPsyInfo; 75 | 76 | 77 | 78 | typedef struct { 79 | int n; 80 | int rate; 81 | struct drft_lookup lookup; 82 | VorbisPsyInfo *vi; 83 | 84 | float *window; 85 | float *noiseoffset; 86 | long *bark; 87 | 88 | } VorbisPsy; 89 | 90 | 91 | VorbisPsy *vorbis_psy_init(int rate, int size); 92 | void vorbis_psy_destroy(VorbisPsy *psy); 93 | void compute_curve(VorbisPsy *psy, float *audio, float *curve); 94 | void curve_to_lpc(VorbisPsy *psy, float *curve, float *awk1, float *awk2, int ord); 95 | 96 | #endif 97 | #endif 98 | -------------------------------------------------------------------------------- /testecho_mono/micin_16k_s16_mono.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_mono/micin_16k_s16_mono.pcm -------------------------------------------------------------------------------- /testecho_mono/micin_32k_s16_mono.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_mono/micin_32k_s16_mono.pcm -------------------------------------------------------------------------------- /testecho_mono/micin_48k_s16_mono.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_mono/micin_48k_s16_mono.pcm -------------------------------------------------------------------------------- /testecho_mono/micin_8k_s16_mono.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_mono/micin_8k_s16_mono.pcm -------------------------------------------------------------------------------- /testecho_mono/speaker_16k_s16_mono.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_mono/speaker_16k_s16_mono.pcm -------------------------------------------------------------------------------- /testecho_mono/speaker_32k_s16_mono.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_mono/speaker_32k_s16_mono.pcm -------------------------------------------------------------------------------- /testecho_mono/speaker_48k_s16_mono.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_mono/speaker_48k_s16_mono.pcm -------------------------------------------------------------------------------- /testecho_mono/speaker_8k_s16_mono.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_mono/speaker_8k_s16_mono.pcm -------------------------------------------------------------------------------- /testecho_mono/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_mono/targetver.h -------------------------------------------------------------------------------- /testecho_mono/testecho.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {CC2E2FB7-EE9D-4AF6-BE9C-87C16F49B4A4} 15 | Win32Proj 16 | speexDemo 17 | testecho_mono 18 | 19 | 20 | 21 | Application 22 | true 23 | MultiByte 24 | 25 | 26 | Application 27 | false 28 | true 29 | Unicode 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | true 43 | 44 | 45 | false 46 | 47 | 48 | 49 | NotUsing 50 | Level3 51 | Disabled 52 | WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_H;%(PreprocessorDefinitions) 53 | ..\speexdsp-1.2rc3\include;..\speexdsp-1.2rc3\libspeexdsp 54 | 55 | 56 | Console 57 | true 58 | 59 | 60 | 61 | 62 | Level3 63 | NotUsing 64 | MaxSpeed 65 | true 66 | true 67 | WIN32;NDEBUG;_CONSOLE;HAVE_CONFIG_H;%(PreprocessorDefinitions) 68 | ..\speexdsp-1.2rc3\include;..\speexdsp-1.2rc3\libspeexdsp 69 | 70 | 71 | Console 72 | true 73 | true 74 | true 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /testecho_mono/testecho.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {2912276e-7f2d-41eb-9e78-711f8b85f6fc} 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | libspeexdsp 26 | 27 | 28 | libspeexdsp 29 | 30 | 31 | libspeexdsp 32 | 33 | 34 | libspeexdsp 35 | 36 | 37 | libspeexdsp 38 | 39 | 40 | libspeexdsp 41 | 42 | 43 | libspeexdsp 44 | 45 | 46 | libspeexdsp 47 | 48 | 49 | libspeexdsp 50 | 51 | 52 | libspeexdsp 53 | 54 | 55 | libspeexdsp 56 | 57 | 58 | libspeexdsp 59 | 60 | 61 | libspeexdsp 62 | 63 | 64 | libspeexdsp 65 | 66 | 67 | libspeexdsp 68 | 69 | 70 | libspeexdsp 71 | 72 | 73 | libspeexdsp 74 | 75 | 76 | libspeexdsp 77 | 78 | 79 | libspeexdsp 80 | 81 | 82 | libspeexdsp 83 | 84 | 85 | libspeexdsp 86 | 87 | 88 | 89 | 90 | 源文件 91 | 92 | 93 | libspeexdsp 94 | 95 | 96 | libspeexdsp 97 | 98 | 99 | libspeexdsp 100 | 101 | 102 | libspeexdsp 103 | 104 | 105 | libspeexdsp 106 | 107 | 108 | libspeexdsp 109 | 110 | 111 | libspeexdsp 112 | 113 | 114 | libspeexdsp 115 | 116 | 117 | libspeexdsp 118 | 119 | 120 | libspeexdsp 121 | 122 | 123 | libspeexdsp 124 | 125 | 126 | 127 | 128 | libspeexdsp 129 | 130 | 131 | -------------------------------------------------------------------------------- /testecho_mono/testecho.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /testecho_mono/testecho_mono.cpp: -------------------------------------------------------------------------------- 1 | /**************************************************    2 | Author : ZL Guo    3 | Email : 1799580752@qq.com 4 | TechBlog : https://www.jianshu.com/u/b971a1d12a6f   5 | Description:  6 | 本程序主要用于利用speex进行单声道的回声消除测试。 7 | 主要包括两大部分。 8 | 1. 针对多个分辨率进行回声消除,分为8k 16k 32k 48k 9 | 2. 测试收敛时间   10 | **************************************************/ 11 | 12 | #ifdef HAVE_CONFIG_H 13 | #include "config.h" 14 | #endif 15 | 16 | #include "targetver.h" 17 | #include 18 | #include 19 | #include "arch.h" 20 | #include 21 | 22 | #ifdef __cplusplus 23 | extern "C" { //如果被C++文件引用 24 | #endif 25 | 26 | #include "speex/speex_echo.h" 27 | #include "speex/speex_preprocess.h" 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | enum EPxSampleRateFreq 34 | { 35 | kePxSampleRateFreq_Invalid = -1, 36 | kePxSampleRateFreq_8k = 8000, 37 | kePxSampleRateFreq_16k = 16000, 38 | kePxSampleRateFreq_32k = 32000, 39 | kePxSampleRateFreq_48k = 48000, 40 | kePxSampleRateFreq_Cnt 41 | }; 42 | 43 | int main(int argc, char **argv) 44 | { 45 | FILE *echo_fd, *ref_fd, *e_fd; 46 | SpeexEchoState *st; 47 | SpeexPreprocessState *den; 48 | int sampleRate = 48000; // 提供了8000 16000 32000 48000的测试样本 49 | 50 | int nFrameSizeInMS = 10; // 每次取多少毫秒的数据进行处理 51 | int nFilterLenInMS = 120; // 滤波器长度为多少毫秒 52 | 53 | SYSTEMTIME sysTime; 54 | ::GetLocalTime(&sysTime); 55 | 56 | int frame_size = (nFrameSizeInMS * sampleRate * 1.0) / 1000; 57 | int filter_length = (nFilterLenInMS * sampleRate * 1.0) / 1000; 58 | 59 | char szEchoFileName[512] = {0}; 60 | char szRefFileName[512] = {0}; 61 | 62 | #if 1 63 | // test 1 : 多采样率测试 64 | // 这里给出的micin 和 speaker的数据是完全对齐的 65 | if (kePxSampleRateFreq_8k == sampleRate) 66 | { 67 | sprintf(szEchoFileName, "%s", "micin_8k_s16_mono.pcm"); 68 | sprintf(szRefFileName, "%s", "speaker_8k_s16_mono.pcm"); 69 | } 70 | else if (kePxSampleRateFreq_16k == sampleRate) 71 | { 72 | sprintf(szEchoFileName, "%s", "micin_16k_s16_mono.pcm"); 73 | sprintf(szRefFileName, "%s", "speaker_16k_s16_mono.pcm"); 74 | } 75 | else if (kePxSampleRateFreq_32k == sampleRate) 76 | { 77 | sprintf(szEchoFileName, "%s", "micin_32k_s16_mono.pcm"); 78 | sprintf(szRefFileName, "%s", "speaker_32k_s16_mono.pcm"); 79 | } 80 | else if (kePxSampleRateFreq_48k == sampleRate) 81 | { 82 | sprintf(szEchoFileName, "%s", "micin_48k_s16_mono.pcm"); 83 | sprintf(szRefFileName, "%s", "speaker_48k_s16_mono.pcm"); 84 | } 85 | 86 | #else 87 | // test 2 : 测试收敛速度 88 | // 用同一个文件测试 看什么时候开始输出连续的静音 就是收敛了 89 | if (kePxSampleRateFreq_8k == sampleRate) 90 | { 91 | sprintf(szEchoFileName, "%s", "speaker_8k_s16_mono.pcm"); 92 | sprintf(szRefFileName, "%s", "speaker_8k_s16_mono.pcm"); 93 | } 94 | else if (kePxSampleRateFreq_16k == sampleRate) 95 | { 96 | sprintf(szEchoFileName, "%s", "speaker_16k_s16_mono.pcm"); 97 | sprintf(szRefFileName, "%s", "speaker_16k_s16_mono.pcm"); 98 | } 99 | else if (kePxSampleRateFreq_32k == sampleRate) 100 | { 101 | sprintf(szEchoFileName, "%s", "speaker_32k_s16_mono.pcm"); 102 | sprintf(szRefFileName, "%s", "speaker_32k_s16_mono.pcm"); 103 | } 104 | else if (kePxSampleRateFreq_48k == sampleRate) 105 | { 106 | sprintf(szEchoFileName, "%s", "speaker_48k_s16_mono.pcm"); 107 | sprintf(szRefFileName, "%s", "speaker_48k_s16_mono.pcm"); 108 | } 109 | #endif 110 | 111 | char szOutputFileName[512]; 112 | sprintf(szOutputFileName, ".\\output\\mono_%s_%s_%04d%02d%02d_%02d%02d%02d.pcm", 113 | szEchoFileName, szRefFileName, 114 | sysTime.wYear, sysTime.wMonth, sysTime.wDay, 115 | sysTime.wHour, sysTime.wMinute, sysTime.wSecond); 116 | printf("%s\n", szOutputFileName); 117 | 118 | ref_fd = fopen(szEchoFileName, "rb"); 119 | echo_fd = fopen(szRefFileName, "rb"); 120 | e_fd = fopen(szOutputFileName, "wb"); 121 | 122 | short *echo_buf; 123 | short *ref_buf; 124 | short *e_buf; 125 | 126 | echo_buf = new short[frame_size]; 127 | ref_buf = new short[frame_size]; 128 | e_buf = new short[frame_size]; 129 | 130 | // 非常重要的函数 直接影响收敛速度 131 | // TAIL越小,收敛速度越快,但对近端数据和远端数据的同步要求提高 132 | // 比如TAIL设置为100ms的samples,那么如果near和far数据相差超过100ms,则无法消除 133 | // TAIL过大, 收敛速度变慢,且可能造成滤波器不稳定 134 | st = speex_echo_state_init(frame_size, filter_length); 135 | 136 | den = speex_preprocess_state_init(frame_size, sampleRate); 137 | 138 | speex_echo_ctl(st, SPEEX_ECHO_SET_SAMPLING_RATE, &sampleRate); 139 | speex_preprocess_ctl(den, SPEEX_PREPROCESS_SET_ECHO_STATE, st); 140 | 141 | LARGE_INTEGER timeStartCount; 142 | LARGE_INTEGER timeEndCount; 143 | LARGE_INTEGER timeFreq; 144 | QueryPerformanceFrequency(&timeFreq); 145 | QueryPerformanceCounter(&timeStartCount); 146 | 147 | while (!feof(ref_fd) && !feof(echo_fd)) 148 | { 149 | fread(ref_buf, sizeof(short), frame_size, ref_fd); 150 | fread(echo_buf, sizeof(short), frame_size, echo_fd); 151 | 152 | // ref_buf : 从speaker处获取到的数据 153 | // echo_buf : 从麦克采集到的数据 154 | // e_buf : 回声消除后的数据 155 | speex_echo_cancellation(st, ref_buf, echo_buf, e_buf); 156 | speex_preprocess_run(den, e_buf); 157 | fwrite(e_buf, sizeof(short), frame_size, e_fd); 158 | } 159 | 160 | QueryPerformanceCounter(&timeEndCount); 161 | double elapsed = (((double)(timeEndCount.QuadPart - timeStartCount.QuadPart) * 1000/ timeFreq.QuadPart)); 162 | 163 | printf("AEC Done. TimeDuration: %.2f ms\n", elapsed); 164 | 165 | speex_echo_state_destroy(st); 166 | speex_preprocess_state_destroy(den); 167 | 168 | fclose(e_fd); 169 | fclose(echo_fd); 170 | fclose(ref_fd); 171 | 172 | if (echo_buf) 173 | { 174 | delete [] echo_buf; 175 | echo_buf = NULL; 176 | } 177 | 178 | if (ref_buf) 179 | { 180 | delete [] ref_buf; 181 | ref_buf = NULL; 182 | } 183 | 184 | if (e_buf) 185 | { 186 | delete [] e_buf; 187 | e_buf = NULL; 188 | } 189 | 190 | getchar(); 191 | 192 | return 0; 193 | } 194 | -------------------------------------------------------------------------------- /testecho_stereo/far48_stereo.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_stereo/far48_stereo.pcm -------------------------------------------------------------------------------- /testecho_stereo/near48_stereo.pcm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_stereo/near48_stereo.pcm -------------------------------------------------------------------------------- /testecho_stereo/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_stereo/stdafx.cpp -------------------------------------------------------------------------------- /testecho_stereo/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_stereo/stdafx.h -------------------------------------------------------------------------------- /testecho_stereo/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhaoliangGuo/speex/0556b54f9076358bef857d60ac2bfbfb798afe22/testecho_stereo/targetver.h -------------------------------------------------------------------------------- /testecho_stereo/testecho_stereo.cpp: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | #include "config.h" 3 | #endif 4 | 5 | #include "targetver.h" 6 | 7 | #include 8 | #include 9 | #include "arch.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include "speex/speex_echo.h" 16 | #include "speex/speex_preprocess.h" 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #include 23 | 24 | int main(int argc, char **argv) 25 | { 26 | int sampleRate = 48000; 27 | int nFrameSizeInMS = 10; 28 | int nFilterLenInMS = 120; 29 | 30 | SpeexEchoState *echo_state = NULL; 31 | SpeexPreprocessState *preprocess_state = NULL; 32 | 33 | SYSTEMTIME st; 34 | ::GetLocalTime(&st); 35 | 36 | int frame_size = (nFrameSizeInMS * sampleRate * 1.0) / 1000; 37 | int filter_length = (nFilterLenInMS * sampleRate * 1.0) / 1000; 38 | 39 | char szMicFileName[] = ".\\near48_stereo.pcm"; 40 | char szSpeakerFileName[] = ".\\far48_stereo.pcm"; 41 | 42 | char szOutputFileName[512]; 43 | sprintf(szOutputFileName, ".\\output_stereo_samplerate_%d_NN_%4d_TAIL_%4d_%04d%02d%02d_%02d%02d%02d.pcm", 44 | sampleRate, 45 | frame_size, filter_length, 46 | st.wYear, st.wMonth, st.wDay, 47 | st.wHour, st.wMinute, st.wSecond); 48 | printf("%s\n", szOutputFileName); 49 | 50 | LARGE_INTEGER timeStartCount; 51 | LARGE_INTEGER timeEndCount; 52 | LARGE_INTEGER timeFreq; 53 | QueryPerformanceFrequency(&timeFreq); 54 | QueryPerformanceCounter(&timeStartCount); 55 | 56 | FILE *echo_fd, *ref_fd, *e_fd; 57 | 58 | ref_fd = fopen(szMicFileName, "rb"); 59 | echo_fd = fopen(szSpeakerFileName, "rb"); 60 | e_fd = fopen(szOutputFileName, "wb"); 61 | 62 | echo_state = speex_echo_state_init_mc(frame_size, filter_length, 2, 2); // for stereo 63 | frame_size *= 2; // length read each time 64 | 65 | preprocess_state = speex_preprocess_state_init(frame_size, sampleRate); 66 | 67 | speex_echo_ctl(echo_state, SPEEX_ECHO_SET_SAMPLING_RATE, &sampleRate); 68 | speex_preprocess_ctl(preprocess_state, SPEEX_PREPROCESS_SET_ECHO_STATE, echo_state); 69 | 70 | short *echo_buf; 71 | short *ref_buf; 72 | short *e_buf; 73 | 74 | echo_buf = new short[frame_size]; 75 | ref_buf = new short[frame_size]; 76 | e_buf = new short[frame_size]; 77 | 78 | while (!feof(ref_fd) && !feof(echo_fd)) 79 | { 80 | int nLen = fread(ref_buf, sizeof(short), frame_size, ref_fd); 81 | if (nLen < 0) 82 | { 83 | break; 84 | } 85 | 86 | nLen = fread(echo_buf, sizeof(short), frame_size, echo_fd); 87 | if (nLen < 0) 88 | { 89 | break; 90 | } 91 | 92 | speex_echo_cancellation(echo_state, ref_buf, echo_buf, e_buf); 93 | speex_preprocess_run(preprocess_state, e_buf); 94 | 95 | fwrite(e_buf, sizeof(short), frame_size, e_fd); 96 | } 97 | 98 | // Destroys an echo canceller state 99 | speex_echo_state_destroy(echo_state); 100 | speex_preprocess_state_destroy(preprocess_state); 101 | 102 | fclose(e_fd); 103 | fclose(echo_fd); 104 | fclose(ref_fd); 105 | 106 | if (echo_buf) 107 | { 108 | delete [] echo_buf; 109 | echo_buf = NULL; 110 | } 111 | 112 | if (ref_buf) 113 | { 114 | delete [] ref_buf; 115 | ref_buf = NULL; 116 | } 117 | 118 | if (e_buf) 119 | { 120 | delete [] e_buf; 121 | e_buf = NULL; 122 | } 123 | 124 | QueryPerformanceCounter(&timeEndCount); 125 | double elapsed = (((double)(timeEndCount.QuadPart - timeStartCount.QuadPart) * 1000/ timeFreq.QuadPart)); 126 | 127 | printf("AEC Done. TimeDuration: %.2f ms\n", elapsed); 128 | 129 | getchar(); 130 | 131 | return 0; 132 | } -------------------------------------------------------------------------------- /testecho_stereo/testecho_stereo.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {9FD6B0B3-2668-4F23-8587-969ABAB8499A} 15 | Win32Proj 16 | testecho_v2 17 | testecho_stereo 18 | 19 | 20 | 21 | Application 22 | true 23 | MultiByte 24 | 25 | 26 | Application 27 | false 28 | true 29 | Unicode 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | true 43 | 44 | 45 | false 46 | 47 | 48 | 49 | NotUsing 50 | Level3 51 | Disabled 52 | WIN32;_DEBUG;_CONSOLE;HAVE_CONFIG_H;%(PreprocessorDefinitions) 53 | ..\speexdsp-1.2rc3\include;..\speexdsp-1.2rc3\libspeexdsp 54 | 55 | 56 | Console 57 | true 58 | 59 | 60 | 61 | 62 | Level3 63 | NotUsing 64 | MaxSpeed 65 | true 66 | true 67 | WIN32;NDEBUG;_CONSOLE;HAVE_CONFIG_H;%(PreprocessorDefinitions) 68 | ..\speexdsp-1.2rc3\include;..\speexdsp-1.2rc3\libspeexdsp 69 | 70 | 71 | Console 72 | true 73 | true 74 | true 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | Create 121 | Create 122 | 123 | 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /testecho_stereo/testecho_stereo.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {3666a875-addb-462f-818a-d3b0fc804fea} 18 | 19 | 20 | 21 | 22 | 23 | libspeexdsp 24 | 25 | 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | libspeexdsp 38 | 39 | 40 | libspeexdsp 41 | 42 | 43 | libspeexdsp 44 | 45 | 46 | libspeexdsp 47 | 48 | 49 | libspeexdsp 50 | 51 | 52 | libspeexdsp 53 | 54 | 55 | libspeexdsp 56 | 57 | 58 | libspeexdsp 59 | 60 | 61 | libspeexdsp 62 | 63 | 64 | libspeexdsp 65 | 66 | 67 | libspeexdsp 68 | 69 | 70 | libspeexdsp 71 | 72 | 73 | libspeexdsp 74 | 75 | 76 | libspeexdsp 77 | 78 | 79 | libspeexdsp 80 | 81 | 82 | libspeexdsp 83 | 84 | 85 | libspeexdsp 86 | 87 | 88 | libspeexdsp 89 | 90 | 91 | libspeexdsp 92 | 93 | 94 | libspeexdsp 95 | 96 | 97 | libspeexdsp 98 | 99 | 100 | 101 | 102 | 源文件 103 | 104 | 105 | 源文件 106 | 107 | 108 | libspeexdsp 109 | 110 | 111 | libspeexdsp 112 | 113 | 114 | libspeexdsp 115 | 116 | 117 | libspeexdsp 118 | 119 | 120 | libspeexdsp 121 | 122 | 123 | libspeexdsp 124 | 125 | 126 | libspeexdsp 127 | 128 | 129 | libspeexdsp 130 | 131 | 132 | libspeexdsp 133 | 134 | 135 | libspeexdsp 136 | 137 | 138 | libspeexdsp 139 | 140 | 141 | -------------------------------------------------------------------------------- /testecho_stereo/testecho_stereo.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | --------------------------------------------------------------------------------