📄 tables.c
字号:
/* TiMidity++ -- MIDI to WAVE converter and player Copyright (C) 1999-2004 Masanao Izumo <iz@onicos.co.jp> Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA The 8-bit uLaw to 16-bit PCM and the 13-bit-PCM to 8-bit uLaw tables were lifted from the rsynth-2.0 sources. The README says: This is a text to speech system produced by integrating various pieces of code and tables of data, which are all (I believe) in the public domain. The bulk of the intergration was done by myself, that is Nick Ing-Simmons. I can be reached via my employer at nik@tiuk.ti.com.*/#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include <stdio.h>#include <math.h>#include "timidity.h"#include "common.h"#include "mt19937ar.h"#include "tables.h"int32 freq_table[128];int32 freq_table_zapped[128];int32 freq_table_tuning[128][128];int32 freq_table_pytha[24][128];int32 freq_table_meantone[48][128];int32 freq_table_pureint[48][128];int32 freq_table_user[4][48][128];void init_freq_table(void){ int i; for (i = 0; i < 128; i++) { freq_table[i] = 440 * pow(2.0, (i - 69) / 12.0) * 1000 + 0.5; freq_table_zapped[i] = freq_table[i]; }}void init_freq_table_tuning(void){ int p, i; double f; for (i = 0; i < 128; i++) freq_table_tuning[0][i] = freq_table_zapped[i]; for (i = 0; i < 128; i++) { f = 440 * pow(2.0, (i - 69) / 12.0); for (p = 1; p < 128; p++) freq_table_tuning[p][i] = f * 1000 + 0.5; }}void init_freq_table_pytha(void){ int i, j, k, l; double f; static const double major_ratio[] = { 1.0 / 1, 256.0 / 243, 9.0 / 8, 32.0 / 27, 81.0 / 64, 4.0 / 3, 729.0 / 512, 3.0 / 2, 128.0 / 81, 27.0 / 16, 16.0 / 9, 243.0 / 128 }; static const double minor_ratio[] = { 1.0 / 1, 2187.0 / 2048, 9.0 / 8, 19683.0 / 16384, 81.0 / 64, 4.0 / 3, 729.0 / 512, 3.0 / 2, 6561.0 / 4096, 27.0 / 16, 16.0 / 9, 243.0 / 128 }; for (i = 0; i < 12; i++) for (j = -1; j < 11; j++) { f = 440 * pow(2.0, (i - 9) / 12.0 + j - 5); for (k = 0; k < 12; k++) { l = i + j * 12 + k; if (l < 0 || l >= 128) continue; freq_table_pytha[i][l] = f * major_ratio[k] * 1000 + 0.5; freq_table_pytha[i + 12][l] = f * minor_ratio[k] * 1000 + 0.5; } }}void init_freq_table_meantone(void){ int i, j, k, l; double f; static double major_ratio[12], minor_ratio[12]; static const double sc = 81.0 / 80; major_ratio[0] = 1; major_ratio[1] = 8 / pow(5.0, 5.0 / 4); major_ratio[2] = pow(5.0, 1.0 / 2) / 2; major_ratio[3] = 4 / pow(5.0, 3.0 / 4); major_ratio[4] = 5.0 / 4; major_ratio[5] = 2 / pow(5.0, 1.0 / 4); major_ratio[6] = pow(5.0, 3.0 / 2) / 8; major_ratio[7] = pow(5.0, 1.0 / 4); major_ratio[8] = 8.0 / 5; major_ratio[9] = pow(5.0, 3.0 / 4) / 2; major_ratio[10] = 4 / pow(5.0, 1.0 / 2); major_ratio[11] = pow(5.0, 5.0 / 4) / 4; minor_ratio[0] = 1; minor_ratio[1] = pow(10.0 / 3, 7.0 / 3) / 16; minor_ratio[2] = pow(10.0 / 3, 2.0 / 3) / 2; minor_ratio[3] = 125.0 / 108; minor_ratio[4] = pow(10.0 / 3, 4.0 / 3) / 4; minor_ratio[5] = 2 / pow(10.0 / 3, 1.0 / 3); minor_ratio[6] = 25.0 / 18; minor_ratio[7] = pow(10.0 / 3, 1.0 / 3); minor_ratio[8] = pow(10.0 / 3, 8.0 / 3) / 16; minor_ratio[9] = 5.0 / 3; minor_ratio[10] = 4 / pow(10.0 / 3, 2.0 / 3); minor_ratio[11] = pow(10.0 / 3, 5.0 / 3) / 4; for (i = 0; i < 12; i++) for (j = -1; j < 11; j++) { f = 440 * pow(2.0, (i - 9) / 12.0 + j - 5); for (k = 0; k < 12; k++) { l = i + j * 12 + k; if (l < 0 || l >= 128) continue; freq_table_meantone[i][l] = f * major_ratio[k] * 1000 + 0.5; freq_table_meantone[i + 12][l] = f * minor_ratio[k] * sc * 1000 + 0.5; freq_table_meantone[i + 24][l] = f * minor_ratio[k] * 1000 + 0.5; freq_table_meantone[i + 36][l] = f * major_ratio[k] * sc * 1000 + 0.5; } }}void init_freq_table_pureint(void){ int i, j, k, l; double f; static const double major_ratio[] = { 1.0 / 1, 16.0 / 15, 9.0 / 8, 6.0 / 5, 5.0 / 4, 4.0 / 3, 45.0 / 32, 3.0 / 2, 8.0 / 5, 5.0 / 3, 9.0 / 5, 15.0 / 8 }; static const double minor_ratio[] = { 1.0 / 1, 25.0 / 24, 10.0 / 9, 75.0 / 64, 5.0 / 4, 4.0 / 3, 25.0 / 18, 3.0 / 2, 25.0 / 16, 5.0 / 3, 16.0 / 9, 15.0 / 8 }; static const double sc = 81.0 / 80; for (i = 0; i < 12; i++) for (j = -1; j < 11; j++) { f = 440 * pow(2.0, (i - 9) / 12.0 + j - 5); for (k = 0; k < 12; k++) { l = i + j * 12 + k; if (l < 0 || l >= 128) continue; freq_table_pureint[i][l] = f * major_ratio[k] * 1000 + 0.5; freq_table_pureint[i + 12][l] = f * minor_ratio[k] * sc * 1000 + 0.5; freq_table_pureint[i + 24][l] = f * minor_ratio[k] * 1000 + 0.5; freq_table_pureint[i + 36][l] = f * major_ratio[k] * sc * 1000 + 0.5; } }}void init_freq_table_user(void){ int p, i, j, k, l; double f; for (p = 0; p < 4; p++) for (i = 0; i < 12; i++) for (j = -1; j < 11; j++) { f = 440 * pow(2.0, (i - 9) / 12.0 + j - 5); for (k = 0; k < 12; k++) { l = i + j * 12 + k; if (l < 0 || l >= 128) continue; freq_table_user[p][i][l] = f * 1000 + 0.5;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -