1 /*- 2 * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss@yahoo.com.au> 3 * All rights reserved. 4 * 5 * This software is dedicated to the memory of - 6 * Baron James Anlezark (Barry) - 1 Jan 1949 - 13 May 2012. 7 * 8 * Barry was a man who loved his music. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. 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 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <math.h> 33 #include <stdio.h> 34 #include <stdint.h> 35 36 static const double sbc8_coeffs[] = { 37 0.00000000e+00, 1.56575398e-04, 3.43256425e-04, 5.54620202e-04, 38 8.23919506e-04, 1.13992507e-03, 1.47640169e-03, 1.78371725e-03, 39 2.01182542e-03, 2.10371989e-03, 1.99454554e-03, 1.61656283e-03, 40 9.02154502e-04, -1.78805361e-04, -1.64973098e-03, -3.49717454e-03, 41 5.65949473e-03, 8.02941163e-03, 1.04584443e-02, 1.27472335e-02, 42 1.46525263e-02, 1.59045603e-02, 1.62208471e-02, 1.53184106e-02, 43 1.29371806e-02, 8.85757540e-03, 2.92408442e-03, -4.91578024e-03, 44 -1.46404076e-02, -2.61098752e-02, -3.90751381e-02, -5.31873032e-02, 45 6.79989431e-02, 8.29847578e-02, 9.75753918e-02, 1.11196689e-01, 46 1.23264548e-01, 1.33264415e-01, 1.40753505e-01, 1.45389847e-01, 47 1.46955068e-01, 1.45389847e-01, 1.40753505e-01, 1.33264415e-01, 48 1.23264548e-01, 1.11196689e-01, 9.75753918e-02, 8.29847578e-02, 49 -6.79989431e-02, -5.31873032e-02, -3.90751381e-02, -2.61098752e-02, 50 -1.46404076e-02, -4.91578024e-03, 2.92408442e-03, 8.85757540e-03, 51 1.29371806e-02, 1.53184106e-02, 1.62208471e-02, 1.59045603e-02, 52 1.46525263e-02, 1.27472335e-02, 1.04584443e-02, 8.02941163e-03, 53 -5.65949473e-03, -3.49717454e-03, -1.64973098e-03, -1.78805361e-04, 54 9.02154502e-04, 1.61656283e-03, 1.99454554e-03, 2.10371989e-03, 55 2.01182542e-03, 1.78371725e-03, 1.47640169e-03, 1.13992507e-03, 56 8.23919506e-04, 5.54620202e-04, 3.43256425e-04, 1.56575398e-04, 57 }; 58 59 static const double sbc4_coeffs[] = { 60 0.00000000e+00, 5.36548976e-04, 1.49188357e-03, 2.73370904e-03, 61 3.83720193e-03, 3.89205149e-03, 1.86581691e-03, -3.06012286e-03, 62 1.09137620e-02, 2.04385087e-02, 2.88757392e-02, 3.21939290e-02, 63 2.58767811e-02, 6.13245186e-03, -2.88217274e-02, -7.76463494e-02, 64 1.35593274e-01, 1.94987841e-01, 2.46636662e-01, 2.81828203e-01, 65 2.94315332e-01, 2.81828203e-01, 2.46636662e-01, 1.94987841e-01, 66 -1.35593274e-01, -7.76463494e-02, -2.88217274e-02, 6.13245186e-03, 67 2.58767811e-02, 3.21939290e-02, 2.88757392e-02, 2.04385087e-02, 68 -1.09137620e-02, -3.06012286e-03, 1.86581691e-03, 3.89205149e-03, 69 3.83720193e-03, 2.73370904e-03, 1.49188357e-03, 5.36548976e-04, 70 }; 71 72 #define AC(x) (int)(sizeof(x) / sizeof((x)[0])) 73 74 int 75 main(int argc, char **argv) 76 { 77 float S[8][16]; 78 int i; 79 int k; 80 int count = 0; 81 82 printf("/* sbc_coeffs.h - Automatically generated by cosdata.c. */\n" 83 "\n"); 84 85 printf("static const float sbc_coeffs8[] = {\n "); 86 for (k = 0; k < AC(sbc8_coeffs); k++) { 87 if ((count % 8) == 0 && count != 0) 88 printf("\n "); 89 printf("%0.12ff, ", (float)sbc8_coeffs[k]); 90 count++; 91 } 92 printf("\n};\n"); 93 94 count = 0; 95 printf("static const float sbc_coeffs4[] = {\n "); 96 for (k = 0; k < AC(sbc4_coeffs); k++) { 97 if ((count % 8) == 0 && count != 0) 98 printf("\n "); 99 printf("%0.12ff, ", (float)sbc4_coeffs[k]); 100 count++; 101 } 102 printf("\n};\n"); 103 104 count = 0; 105 printf("static const float cosdata8[8][16] = {\n "); 106 for (i = 0; i < 8; i++) { 107 for (k = 0; k < 16; k++) { 108 S[i][k] = cosf((float)((i + 0.5) * (k - 4) * (M_PI / 8.0))); 109 110 if ((count % 8) == 0 && count != 0) 111 printf("\n "); 112 if (k == 0) 113 printf("{ "); 114 printf("%0.12ff, ", S[i][k]); 115 if (k == 15) 116 printf("},"); 117 count++; 118 } 119 } 120 printf("\n};\n"); 121 122 count = 0; 123 printf("static const float cosdata4[4][8] = {\n "); 124 for (i = 0; i < 4; i++) { 125 for (k = 0; k < 8; k++) { 126 S[i][k] = cosf((float)((i + 0.5) * (k - 2) * (M_PI / 4.0))); 127 128 if ((count % 8) == 0 && count != 0) 129 printf("\n "); 130 if (k == 0) 131 printf("{ "); 132 printf("%0.12ff, ", S[i][k]); 133 if (k == 7) 134 printf("},"); 135 count++; 136 } 137 } 138 printf("\n};\n"); 139 140 count = 0; 141 printf("static const float cosdecdata8[8][16] = {\n "); 142 for (i = 0; i < 8; i++) { 143 for (k = 0; k < 16; k++) { 144 S[i][k] = cosf((float)((i + 0.5) * (k + 4) * (M_PI / 8.0))); 145 146 if ((count % 8) == 0 && count != 0) 147 printf("\n "); 148 if (k == 0) 149 printf("{ "); 150 printf("%0.12ff, ", S[i][k]); 151 if (k == 15) 152 printf("},"); 153 count++; 154 } 155 } 156 printf("\n};\n"); 157 158 count = 0; 159 printf("static const float cosdecdata4[4][8] = {\n "); 160 for (i = 0; i < 4; i++) { 161 for (k = 0; k < 8; k++) { 162 S[i][k] = cosf((float)((i + 0.5) * (k + 2) * (M_PI / 4.0))); 163 164 if ((count % 8) == 0 && count != 0) 165 printf("\n "); 166 if (k == 0) 167 printf("{ "); 168 printf("%0.12ff, ", S[i][k]); 169 if (k == 7) 170 printf("},"); 171 count++; 172 } 173 } 174 printf("\n};\n"); 175 176 return (0); 177 } 178