📄 newsnd2.c
字号:
/* Digger Remastered
Copyright (c) Andrew Jenner 1998-2004 */
#include "def.h"
#include "device.h"
#include "sound.h"
#include "newsnd.h"
extern int rate;
extern Uint4 t0v,t2v,t0rate,t2rate;
extern bool t2sw;
extern Sint4 spkrmode,pulsewidth;
Sint5 t0=0,t2=0;
samp getsample2(void);
/* This is the sound generation engine specific code */
void s2settimer2(Uint4 t2)
{
if (t2==40)
t2rate=0;
else
if (t2==0)
t2rate=rate;
else
t2rate=(Uint4)((((Uint5)rate)<<16)/t2);
}
void s2timer2(Uint4 t2)
{
s2settimer2(t2);
}
void s2soundoff(void)
{
t2sw=FALSE;
}
void s2setspkrt2(void)
{
t2sw=TRUE;
}
void s2settimer0(Uint4 t0)
{
if (t0==0)
t0rate=rate;
else
t0rate=(Uint4)((((Uint5)rate)<<16)/t0);
}
void s2timer0(Uint4 t0)
{
s2settimer0(t0);
}
/*
Sint4 sinetab[512]={
0,402,804,1206,1607,2009,2410,2811,3211,3611,4011,4409,4807,5205,5601,5997,
6392,6786,7179,7571,7961,8351,8739,9126,9511,9895,10278,10659,11038,11416,
11792,12166,12539,12909,13278,13645,14009,14372,14732,15090,15446,15799,16150,
16499,16845,17189,17530,17868,18204,18537,18867,19194,19519,19840,20159,20474,
20787,21096,21402,21705,22004,22301,22594,22883,23169,23452,23731,24006,24278,
24546,24811,25072,25329,25582,25831,26077,26318,26556,26789,27019,27244,27466,
27683,27896,28105,28309,28510,28706,28897,29085,29268,29446,29621,29790,29955,
30116,30272,30424,30571,30713,30851,30984,31113,31236,31356,31470,31580,31684,
31785,31880,31970,32056,32137,32213,32284,32350,32412,32468,32520,32567,32609,
32646,32678,32705,32727,32744,32757,32764,32767,32764,32757,32744,32727,32705,
32678,32646,32609,32567,32520,32468,32412,32350,32284,32213,32137,32056,31970,
31880,31785,31684,31580,31470,31356,31236,31113,30984,30851,30713,30571,30424,
30272,30116,29955,29790,29621,29446,29268,29085,28897,28706,28510,28309,28105,
27896,27683,27466,27244,27019,26789,26556,26318,26077,25831,25582,25329,25072,
24811,24546,24278,24006,23731,23452,23169,22883,22594,22301,22004,21705,21402,
21096,20787,20474,20159,19840,19519,19194,18867,18537,18204,17868,17530,17189,
16845,16499,16150,15799,15446,15090,14732,14372,14009,13645,13278,12909,12539,
12166,11792,11416,11038,10659,10278,9895,9511,9126,8739,8351,7961,7571,7179,
6786,6392,5997,5601,5205,4807,4409,4011,3611,3211,2811,2410,2009,1607,1206,804,
402,0,-402,-804,-1206,-1607,-2009,-2410,-2811,-3211,-3611,-4011,-4409,-4807,
-5205,-5601,-5997,-6392,-6786,-7179,-7571,-7961,-8351,-8739,-9126,-9511,-9895,
-10278,-10659,-11038,-11416,-11792,-12166,-12539,-12909,-13278,-13645,-14009,
-14372,-14732,-15090,-15446,-15799,-16150,-16499,-16845,-17189,-17530,-17868,
-18204,-18537,-18867,-19194,-19519,-19840,-20159,-20474,-20787,-21096,-21402,
-21705,-22004,-22301,-22594,-22883,-23169,-23452,-23731,-24006,-24278,-24546,
-24811,-25072,-25329,-25582,-25831,-26077,-26318,-26556,-26789,-27019,-27244,
-27466,-27683,-27896,-28105,-28309,-28510,-28706,-28897,-29085,-29268,-29446,
-29621,-29790,-29955,-30116,-30272,-30424,-30571,-30713,-30851,-30984,-31113,
-31236,-31356,-31470,-31580,-31684,-31785,-31880,-31970,-32056,-32137,-32213,
-32284,-32350,-32412,-32468,-32520,-32567,-32609,-32646,-32678,-32705,-32727,
-32744,-32757,-32764,-32767,-32764,-32757,-32744,-32727,-32705,-32678,-32646,
-32609,-32567,-32520,-32468,-32412,-32350,-32284,-32213,-32137,-32056,-31970,
-31880,-31785,-31684,-31580,-31470,-31356,-31236,-31113,-30984,-30851,-30713,
-30571,-30424,-30272,-30116,-29955,-29790,-29621,-29446,-29268,-29085,-28897,
-28706,-28510,-28309,-28105,-27896,-27683,-27466,-27244,-27019,-26789,-26556,
-26318,-26077,-25831,-25582,-25329,-25072,-24811,-24546,-24278,-24006,-23731,
-23452,-23169,-22883,-22594,-22301,-22004,-21705,-21402,-21096,-20787,-20474,
-20159,-19840,-19519,-19194,-18867,-18537,-18204,-17868,-17530,-17189,-16845,
-16499,-16150,-15799,-15446,-15090,-14732,-14372,-14009,-13645,-13278,-12909,
-12539,-12166,-11792,-11416,-11038,-10659,-10278,-9895,-9511,-9126,-8739,-8351,
-7961,-7571,-7179,-6786,-6392,-5997,-5601,-5205,-4807,-4409,-4011,-3611,-3211,
-2811,-2410,-2009,-1607,-1206,-804,-402};
*/
samp getsample2(void)
{
if (addcarry(&t0v,t0rate)) {
if (addcarry(&timercount,timerrate)) {
soundint();
timercount-=0x4000;
}
}
t2v+=t2rate;
if (spkrmode!=0)
if (t0v>pulsewidth*655)
t0=-32767;
else
t0=32767;
if (t2rate!=0 && t2sw) {
if (t2v>32767)
t2=-32767;
else
t2=32767;
}
return (samp)(((t0+2*t2+98301L)*(MAX_SAMP-MIN_SAMP))/196605L)+MIN_SAMP;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -