OSDN Git Service

[WIP] Update to upstream 2018-10-05.This still not finish.May cause FTBFS.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmgen / opm.h
1 // ---------------------------------------------------------------------------
2 //      OPM-like Sound Generator
3 //      Copyright (C) cisc 1998, 2003.
4 // ---------------------------------------------------------------------------
5 //      $Id: opm.h,v 1.14 2003/06/07 08:25:53 cisc Exp $
6
7 #ifndef FM_OPM_H
8 #define FM_OPM_H
9
10 #include "fmgen.h"
11 #include "fmtimer.h"
12 #include "psg.h"
13
14 class CSP_Logger;
15 // ---------------------------------------------------------------------------
16 //      class OPM
17 //      OPM \82É\97Ç\82­\8e\97\82½(?)\89¹\82ð\90\90¬\82·\82é\89¹\8c¹\83\86\83j\83b\83g
18 //      
19 //      interface:
20 //      bool Init(uint clock, uint rate, bool);
21 //              \8f\89\8aú\89»\81D\82±\82Ì\83N\83\89\83X\82ð\8eg\97p\82·\82é\91O\82É\82©\82È\82ç\82¸\8cÄ\82ñ\82Å\82¨\82­\82±\82Æ\81D
22 //              \92\8d\88Ó: \90ü\8c`\95â\8a®\83\82\81[\83h\82Í\94p\8e~\82³\82ê\82Ü\82µ\82½
23 //
24 //              clock:  OPM \82Ì\83N\83\8d\83b\83N\8eü\94g\90\94(Hz)
25 //
26 //              rate:   \90\90¬\82·\82é PCM \82Ì\95W\96{\8eü\94g\90\94(Hz)
27 //
28 //                              
29 //              \95Ô\92l    \8f\89\8aú\89»\82É\90¬\8c÷\82·\82ê\82Πtrue
30 //
31 //      bool SetRate(uint clock, uint rate, bool)
32 //              \83N\83\8d\83b\83N\82â PCM \83\8c\81[\83g\82ð\95Ï\8dX\82·\82é
33 //              \88ø\90\94\93\99\82Í Init \82Æ\93¯\97l\81D
34 //      
35 //      void Mix(Sample* dest, int nsamples)
36 //              Stereo PCM \83f\81[\83^\82ð nsamples \95ª\8d\87\90¬\82µ\81C dest \82Å\8en\82Ü\82é\94z\97ñ\82É
37 //              \89Á\82¦\82é(\89Á\8eZ\82·\82é)
38 //              \81Edest \82É\82Í sample*2 \8cÂ\95ª\82Ì\97Ì\88æ\82ª\95K\97v
39 //              \81E\8ai\94[\8c`\8e®\82Í L, R, L, R... \82Æ\82È\82é\81D
40 //              \81E\82 \82­\82Ü\82Å\89Á\8eZ\82È\82Ì\82Å\81C\82 \82ç\82©\82\82ß\94z\97ñ\82ð\83[\83\8d\83N\83\8a\83A\82·\82é\95K\97v\82ª\82 \82é
41 //              \81EFM_SAMPLETYPE \82ª short \8c^\82Ì\8fê\8d\87\83N\83\8a\83b\83s\83\93\83O\82ª\8ds\82í\82ê\82é.
42 //              \81E\82±\82Ì\8aÖ\90\94\82Í\89¹\8c¹\93à\95\94\82Ì\83^\83C\83}\81[\82Æ\82Í\93Æ\97§\82µ\82Ä\82¢\82é\81D
43 //                Timer \82Í Count \82Æ GetNextEvent \82Å\91\80\8dì\82·\82é\95K\97v\82ª\82 \82é\81D
44 //      
45 //      void Reset()
46 //              \89¹\8c¹\82ð\83\8a\83Z\83b\83g(\8f\89\8aú\89»)\82·\82é
47 //
48 //      void SetReg(uint reg, uint data)
49 //              \89¹\8c¹\82Ì\83\8c\83W\83X\83^ reg \82É data \82ð\8f\91\82«\8d\9e\82Þ
50 //      
51 //      uint ReadStatus()
52 //              \89¹\8c¹\82Ì\83X\83e\81[\83^\83X\83\8c\83W\83X\83^\82ð\93Ç\82Ý\8fo\82·
53 //              busy \83t\83\89\83O\82Í\8fí\82É 0
54 //      
55 //      bool ReadIRQ()
56 //              IRQ \8fo\97Í\82ð\93Ç\82Ý\8fo\82·
57 //      
58 //      bool Count(uint32 t)
59 //              \89¹\8c¹\82Ì\83^\83C\83}\81[\82ð t [clock] \90i\82ß\82é\81D
60 //              \89¹\8c¹\82Ì\93à\95\94\8fó\91Ô\82É\95Ï\89»\82ª\82 \82Á\82½\8e\9e(timer \83I\81[\83o\81[\83t\83\8d\81[)
61 //              true \82ð\95Ô\82·
62 //
63 //      uint32 GetNextEvent()
64 //              \89¹\8c¹\82Ì\83^\83C\83}\81[\82Ì\82Ç\82¿\82ç\82©\82ª\83I\81[\83o\81[\83t\83\8d\81[\82·\82é\82Ü\82Å\82É\95K\97v\82È
65 //              \8e\9e\8aÔ[clock]\82ð\95Ô\82·
66 //              \83^\83C\83}\81[\82ª\92â\8e~\82µ\82Ä\82¢\82é\8fê\8d\87\82Í 0 \82ð\95Ô\82·\81D
67 //      
68 //      void SetVolume(int db_l, int db_r)
69 //              \8ae\89¹\8c¹\82Ì\89¹\97Ê\82ð\81{\81|\95û\8cü\82É\92²\90ß\82·\82é\81D\95W\8f\80\92l\82Í 0.
70 //              \92P\88Ê\82Í\96ñ 1/2 dB\81C\97L\8cø\94Í\88Í\82Ì\8fã\8cÀ\82Í 20 (10dB)
71 //
72 namespace FM
73 {
74         //      YM2151(OPM) ----------------------------------------------------
75         class DLL_PREFIX  OPM : public Timer
76         {
77         protected:
78                 int chip_num;
79         public:
80                 OPM();
81                 ~OPM() {}
82
83                 bool    Init(uint c, uint r, bool=false);
84                 bool    SetRate(uint c, uint r, bool);
85                 void    SetLPFCutoff(uint freq);
86                 void    Reset();
87                 bool    ReadIRQ();
88                 
89                 void    SetReg(uint addr, uint data);
90                 uint    GetReg(uint addr);
91                 uint    ReadStatus() { return status & 0x03; }
92                 
93                 void    Mix(Sample* buffer, int nsamples);
94                 
95                 void    SetVolume(int db_l, int db_r);
96                 void    SetChannelMask(uint mask);
97
98                 bool    ProcessState(void *f, bool loading);
99                 
100         private:
101                 void    Intr(bool value);
102         
103         private:
104                 enum
105                 {
106                         OPM_LFOENTS = 512,
107                 };
108                 
109                 void    SetStatus(uint bit);
110                 void    ResetStatus(uint bit);
111                 void    SetParameter(uint addr, uint data);
112                 void    TimerA();
113                 void    RebuildTimeTable();
114                 void    MixSub(int activech, ISample**);
115                 void    MixSubL(int activech, ISample**);
116                 void    LFO();
117                 uint    Noise();
118                 
119                 int             fmvolume_l;
120                 int             fmvolume_r;
121
122                 uint    clock;
123                 uint    rate;
124                 uint    pcmrate;
125
126                 uint    pmd;
127                 uint    amd;
128                 uint    lfocount;
129                 uint    lfodcount;
130
131                 uint    lfo_count_;
132                 uint    lfo_count_diff_;
133                 uint    lfo_step_;
134                 uint    lfo_count_prev_;
135
136                 uint    lfowaveform;
137                 uint    rateratio;
138                 uint    noise;
139                 int32   noisecount;
140                 uint32  noisedelta;
141                 
142                 bool    interpolation;
143                 uint8   lfofreq;
144                 uint8   status;
145                 bool    interrupt;
146                 uint8   reg01;
147
148                 uint8   kc[8];
149                 uint8   kf[8];
150                 uint8   pan[8];
151
152                 Channel4 ch[8];
153                 Chip    chip;
154
155                 static void     BuildLFOTable();
156                 static int amtable[4][OPM_LFOENTS];
157                 static int pmtable[4][OPM_LFOENTS];
158
159         public:
160                 int             dbgGetOpOut(int c, int s) { return ch[c].op[s].dbgopout_; }
161                 Channel4* dbgGetCh(int c) { return &ch[c]; }
162
163         };
164 }
165
166 #endif // FM_OPM_H