Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Dsp.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2014, The Cinder Project
3 
4  This code is intended to be used with the Cinder C++ library, http://libcinder.org
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
7  the following conditions are met:
8 
9  * Redistributions of source code must retain the above copyright notice, this list of conditions and
10  the following disclaimer.
11  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12  the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
15  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
16  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
17  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
18  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
20  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21  POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 #pragma once
25 
26 #include "cinder/CinderAssert.h"
27 
28 #include "cinder/Cinder.h"
29 
30 #if defined( CINDER_COCOA )
31  #define CINDER_AUDIO_VDSP
32 #endif
33 
34 #include <atomic>
35 #include <vector>
36 #include <cmath>
37 
38 namespace cinder { namespace audio { namespace dsp {
39 
40 
42 void generateBlackmanWindow( float *window, size_t length );
44 void generateHammingWindow( float *window, size_t length );
46 void generateHannWindow( float *window, size_t length );
47 
49 enum class WindowType {
50  BLACKMAN,
51  HAMMING,
52  HANN,
53  RECT
54 };
55 
57 void generateWindow( WindowType windowType, float *window, size_t length );
58 
59 // Vector based math routines.
60 
62 void fill( float value, float *array, size_t length );
64 void add( const float *array, float scalar, float *result, size_t length );
66 void add( const float *arrayA, const float *arrayB, float *result, size_t length );
68 void sub( const float *array, float scalar, float *result, size_t length );
70 void sub( const float *arrayA, const float *arrayB, float *result, size_t length );
72 void mul( const float *array, float scalar, float *result, size_t length );
74 void mul( const float *arrayA, const float *arrayB, float *result, size_t length );
76 void divide( const float *array, float scalar, float *result, size_t length );
78 void divide( const float *arrayA, const float *arrayB, float *result, size_t length );
80 void addMul( const float *arrayA, const float *arrayB, float scalar, float *result, size_t length );
82 float sum( const float *array, size_t length );
84 float rms( const float *array, size_t length );
86 void normalize( float *array, size_t length, float maxValue = 1 );
87 
88 } } } // namespace cinder::audio::dsp
void generateWindow(WindowType windowType, float *window, size_t length)
fills window array with a windowing function specified by windowType
Definition: Dsp.cpp:77
void add(const float *array, float scalar, float *result, size_t length)
add scalar to array of length length, into result.
Definition: Dsp.cpp:183
void generateBlackmanWindow(float *window, size_t length)
Fills length samples of window with a Blackmann windowing function.
Definition: Dsp.cpp:40
float sum(const float *array, size_t length)
returns the sum of array
Definition: Dsp.cpp:175
void generateHammingWindow(float *window, size_t length)
Fills length samples of window with a Hamming windowing function.
Definition: Dsp.cpp:54
void mul(const float *array, float scalar, float *result, size_t length)
multiplies length elements of array by scalar and places the result at result.
Definition: Dsp.cpp:218
GLuint GLsizei GLsizei * length
Definition: GLee.h:2313
void fill(float value, float *array, size_t length)
fills array with value value
Definition: Dsp.cpp:169
GLsizei const GLfloat * value
Definition: GLee.h:2487
Window window
Definition: GLee.h:17134
void generateHannWindow(float *window, size_t length)
Fills length samples of window with a Hann windowing function.
Definition: Dsp.cpp:66
void sub(const float *array, float scalar, float *result, size_t length)
subtract scalar from array of length length, into result.
Definition: Dsp.cpp:195
void addMul(const float *arrayA, const float *arrayB, float scalar, float *result, size_t length)
sums length elements of arrayA by arrayB (element-wise), then scales by scalar and places the result ...
Definition: Dsp.cpp:241
void normalize(float *array, size_t length, float maxValue=1)
normalizes array to maxValue (default = 1)
Definition: Dsp.cpp:249
float rms(const float *array, size_t length)
returns the Root-Mean-Squared value of array
Definition: Dsp.cpp:207
void divide(const float *array, float scalar, float *result, size_t length)
divides length elements of array by scalar and places the result at result.
Definition: Dsp.cpp:230
WindowType
Describes the avaiable windowing functions.
Definition: Dsp.h:49