OSDN Git Service

[VM][General] Merge Upstream 2017-12-15.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmgen / psg_ay_3_891x.cpp
1 // ---------------------------------------------------------------------------
2 //      PSG Sound Implementation
3 //      Copyright (C) cisc 1997, 1999.
4 // ---------------------------------------------------------------------------
5 //      $Id: psg.cpp,v 1.10 2002/05/15 21:38:01 cisc Exp $
6
7 #include "headers.h"
8 #include "misc.h"
9 #include "./psg_ay_3_891x.h"
10 // for AY-3-8190/8192
11 //#include "../vm.h"
12
13 #include "../../fileio.h"
14
15 PSG_AY_3_891X::PSG_AY_3_891X() : PSG()
16 {
17         prescale = -1;
18 }
19
20 PSG_AY_3_891X::~PSG_AY_3_891X()
21 {
22 }
23
24 bool PSG_AY_3_891X::Init(uint c, uint r)
25 {
26         clock = c;
27         psgrate = r;
28         SetClock(c, r);
29         //SetPreScaler(ps);
30         Reset();
31         return true;
32 }
33
34 void PSG_AY_3_891X::SetPrescaler(int factor)
35 {
36         static const char table[3][2] = { { 6, 4 }, { 3, 2 }, { 2, 1 } };
37         static const uint8 table2[8] = { 108,  77,  71,  67,  62,  44,  8,  5 };
38         if((factor < 0) || (factor >= 3)) return;
39         if(prescale != factor)
40         {
41                 prescale = factor;
42                 SetClock(clock / table[factor][1], psgrate);
43         }
44 }
45
46 void PSG_AY_3_891X::SetVolume(int volume_l, int volume_r)
47 {
48         double base_l = 0x4000 / 3.0 * pow(10.0, volume_l / 40.0);
49         double base_r = 0x4000 / 3.0 * pow(10.0, volume_r / 40.0);
50 //#if defined(HAS_AY_3_8910) || defined(HAS_AY_3_8912)
51         // AY-3-8190/8192 (PSG): 16step
52         for (int i=31; i>=3; i-=2)
53         {
54                 EmitTableL[i] = EmitTableL[i-1] = int(base_l);
55                 EmitTableR[i] = EmitTableR[i-1] = int(base_r);
56                 base_l /= 1.189207115;
57                 base_l /= 1.189207115;
58                 base_r /= 1.189207115;
59                 base_r /= 1.189207115;
60         }
61 //#endif
62         EmitTableL[1] = 0;
63         EmitTableL[0] = 0;
64         EmitTableR[1] = 0;
65         EmitTableR[0] = 0;
66         MakeEnvelopTable();
67
68         SetChannelMask(~mask);
69 }