Mercurial > pmdwin
comparison fmgen/psg.c @ 3:8ad174416431
Convert the last EUC-JP file to UTF-8.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Tue, 21 May 2013 10:45:37 +0200 |
parents | c55ea9478c80 |
children |
comparison
equal
deleted
inserted
replaced
2:34086e667cc7 | 3:8ad174416431 |
---|---|
44 #include "psg.h" | 44 #include "psg.h" |
45 #define Max(a,b) ((a>b)?a:b) | 45 #define Max(a,b) ((a>b)?a:b) |
46 #define Min(a,b) ((a<b)?a:b) | 46 #define Min(a,b) ((a<b)?a:b) |
47 | 47 |
48 // --------------------------------------------------------------------------- | 48 // --------------------------------------------------------------------------- |
49 // ¥Æ¡¼¥Ö¥ë | 49 // テーブル |
50 // | 50 // |
51 int EmitTable[0x20] = { -1, }; | 51 int EmitTable[0x20] = { -1, }; |
52 uint enveloptable[16][64] = { 0, }; | 52 uint enveloptable[16][64] = { 0, }; |
53 | 53 |
54 // --------------------------------------------------------------------------- | 54 // --------------------------------------------------------------------------- |
73 void PSGSetClock(PSG *psg, uint32_t clock, uint32_t rate) | 73 void PSGSetClock(PSG *psg, uint32_t clock, uint32_t rate) |
74 { | 74 { |
75 psg->tperiodbase = (uint32_t)((1 << toneshift ) / 4.0f * clock / rate); | 75 psg->tperiodbase = (uint32_t)((1 << toneshift ) / 4.0f * clock / rate); |
76 psg->eperiodbase = (uint32_t)((1 << envshift ) / 4.0f * clock / rate); | 76 psg->eperiodbase = (uint32_t)((1 << envshift ) / 4.0f * clock / rate); |
77 | 77 |
78 // ³Æ¥Ç¡¼¥¿¤Î¹¹¿· | 78 // å„データã®æ›´æ–° |
79 int tmp; | 79 int tmp; |
80 tmp = ((psg->reg[0] + psg->reg[1] * 256) & 0xfff); | 80 tmp = ((psg->reg[0] + psg->reg[1] * 256) & 0xfff); |
81 psg->speriod[0] = tmp ? psg->tperiodbase / tmp : psg->tperiodbase; | 81 psg->speriod[0] = tmp ? psg->tperiodbase / tmp : psg->tperiodbase; |
82 tmp = ((psg->reg[2] + psg->reg[3] * 256) & 0xfff); | 82 tmp = ((psg->reg[2] + psg->reg[3] * 256) & 0xfff); |
83 psg->speriod[1] = tmp ? psg->tperiodbase / tmp : psg->tperiodbase; | 83 psg->speriod[1] = tmp ? psg->tperiodbase / tmp : psg->tperiodbase; |
88 tmp = ((psg->reg[11] + psg->reg[12] * 256) & 0xffff); | 88 tmp = ((psg->reg[11] + psg->reg[12] * 256) & 0xffff); |
89 psg->eperiod = tmp ? psg->eperiodbase / tmp : psg->eperiodbase * 2; | 89 psg->eperiod = tmp ? psg->eperiodbase / tmp : psg->eperiodbase * 2; |
90 } | 90 } |
91 | 91 |
92 // --------------------------------------------------------------------------- | 92 // --------------------------------------------------------------------------- |
93 // ¥¨¥ó¥Ù¥í¡¼¥×ÇÈ·Á¥Æ¡¼¥Ö¥ë | 93 // エンベãƒãƒ¼ãƒ—波形テーブル |
94 // | 94 // |
95 static uint8_t table3[4] = { 0, 1, -1, 0 }; | 95 static uint8_t table3[4] = { 0, 1, -1, 0 }; |
96 void MakeEnvelopTable(void) | 96 void MakeEnvelopTable(void) |
97 { | 97 { |
98 // 0 lo 1 up 2 down 3 hi | 98 // 0 lo 1 up 2 down 3 hi |
281 uint* p2 = ((psg->mask & 2) && (psg->reg[ 9] & 0x10)) ? &env : &psg->olevel[1]; | 281 uint* p2 = ((psg->mask & 2) && (psg->reg[ 9] & 0x10)) ? &env : &psg->olevel[1]; |
282 uint* p3 = ((psg->mask & 4) && (psg->reg[10] & 0x10)) ? &env : &psg->olevel[2]; | 282 uint* p3 = ((psg->mask & 4) && (psg->reg[10] & 0x10)) ? &env : &psg->olevel[2]; |
283 #define SCOUNT(ch) (psg->scount[ch] >> toneshift) | 283 #define SCOUNT(ch) (psg->scount[ch] >> toneshift) |
284 | 284 |
285 if (p1 != &env && p2 != &env && p3 != &env) { | 285 if (p1 != &env && p2 != &env && p3 != &env) { |
286 // ¥Î¥¤¥ºÍ¤ê | 286 // ノイズ有り |
287 for (i=0; i<nsamples; i++) { | 287 for (i=0; i<nsamples; i++) { |
288 psg->ncount++; | 288 psg->ncount++; |
289 if(psg->ncount >= psg->nperiod) { | 289 if(psg->ncount >= psg->nperiod) { |
290 if(psg->rng & 1) | 290 if(psg->rng & 1) |
291 psg->rng ^= 0x24000; | 291 psg->rng ^= 0x24000; |
308 } | 308 } |
309 dest[0] += sample; | 309 dest[0] += sample; |
310 dest += 1; | 310 dest += 1; |
311 } | 311 } |
312 | 312 |
313 // ¥¨¥ó¥Ù¥í¡¼¥×¤Î·×»»¤ò¤µ¤Ü¤Ã¤¿Ä¢¿¬¤¢¤ï¤» | 313 // エンベãƒãƒ¼ãƒ—ã®è¨ˆç®—ã‚’ã•ã¼ã£ãŸå¸³å°»ã‚ã‚ã› |
314 psg->ecount = (psg->ecount >> 8) + (psg->eperiod >> 8) * nsamples; | 314 psg->ecount = (psg->ecount >> 8) + (psg->eperiod >> 8) * nsamples; |
315 if (psg->ecount >= (1 << (envshift+6-8))) { | 315 if (psg->ecount >= (1 << (envshift+6-8))) { |
316 if ((psg->reg[0x0d] & 0x0b) != 0x0a) | 316 if ((psg->reg[0x0d] & 0x0b) != 0x0a) |
317 psg->ecount |= (1 << (envshift+5-8)); | 317 psg->ecount |= (1 << (envshift+5-8)); |
318 psg->ecount &= (1 << (envshift+6-8)) - 1; | 318 psg->ecount &= (1 << (envshift+6-8)) - 1; |
319 } | 319 } |
320 psg->ecount <<= 8; | 320 psg->ecount <<= 8; |
321 } else { | 321 } else { |
322 // ¥¨¥ó¥Ù¥í¡¼¥×¤¢¤ê | 322 // エンベãƒãƒ¼ãƒ—ã‚ã‚Š |
323 for (i=0; i<nsamples; i++) { | 323 for (i=0; i<nsamples; i++) { |
324 psg->ncount++; | 324 psg->ncount++; |
325 if(psg->ncount >= psg->nperiod) { | 325 if(psg->ncount >= psg->nperiod) { |
326 if(psg->rng & 1) | 326 if(psg->rng & 1) |
327 psg->rng ^= 0x24000; | 327 psg->rng ^= 0x24000; |