• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 #include "Window.h"
18 
19 #include <stdlib.h>
20 #include <math.h>
21 
windowCreate(int size)22 void Window::windowCreate(int size) {
23     if (mWindowWeights && (mWindowSize < size)) {
24         delete [] mWindowWeights;
25         mWindowWeights = NULL;
26         mWindowSize = 0;
27     }
28     if (!mWindowWeights) {
29         mWindowWeights = new float[size];
30     }
31     if (mWindowSize != size) {
32         double arg = M_PI * 2.0 / size;
33         mWindowSize = size;
34         for (int i = 0; i < size; ++i) {
35             mWindowWeights[i] = 0.5 - (0.5 * cos((i + 0.5) * arg));
36         }
37     }
38 }
39 
windowCleanup()40 void Window::windowCleanup() {
41     mWindowSize = 0;
42     delete [] mWindowWeights;
43     mWindowWeights = NULL;
44 }
45 
46 /* Multiply the signal in data by the window weights.  Place the
47    resulting mWindowSize floating-point values in output.  If preemp
48    is != 0.0, apply a 1st-order preemphasis filter, and assume that
49    there are mWindowSize+1 samples available in data. */
window(short * data,float * output,float preemp)50 void Window::window(short* data, float* output, float preemp) {
51     if (preemp == 0.0) {
52         for (int i = 0; i < mWindowSize; ++i)
53             output[i] = data[i] * mWindowWeights[i];
54     } else {
55         for (int i = 0; i < mWindowSize; ++i)
56             output[i] = (data[i+1] - (preemp * data[i])) * mWindowWeights[i];
57     }
58 }
59 
60