OSDN Git Service

[VM][Qt][OSD][CMake] Fix FTBFSs at least for FM-7 series with GCC/*nix/Qt.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fmgen / psg.h
1 // ---------------------------------------------------------------------------
2 //      PSG-like sound generator
3 //      Copyright (C) cisc 1997, 1999.
4 // ---------------------------------------------------------------------------
5 //      $Id: psg.h,v 1.8 2003/04/22 13:12:53 cisc Exp $
6
7 #ifndef PSG_H
8 #define PSG_H
9
10 //# include "types.h"
11 #include "../../common.h"
12
13 #define PSG_SAMPLETYPE          int32           // int32 or int16
14
15 // ---------------------------------------------------------------------------
16 //      class PSG
17 //      PSG \82É\97Ç\82­\8e\97\82½\89¹\82ð\90\90¬\82·\82é\89¹\8c¹\83\86\83j\83b\83g
18 //      
19 //      interface:
20 //      bool SetClock(uint clock, uint rate)
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 //              PSG \82Ì\83N\83\8d\83b\83N\82â PCM \83\8c\81[\83g\82ð\90Ý\92è\82·\82é
23 //
24 //              clock:  PSG \82Ì\93®\8dì\83N\83\8d\83b\83N
25 //              rate:   \90\90¬\82·\82é PCM \82Ì\83\8c\81[\83g
26 //              retval  \8f\89\8aú\89»\82É\90¬\8c÷\82·\82ê\82Πtrue
27 //
28 //      void Mix(Sample* dest, int nsamples)
29 //              PCM \82ð nsamples \95ª\8d\87\90¬\82µ\81C dest \82Å\8en\82Ü\82é\94z\97ñ\82É\89Á\82¦\82é(\89Á\8eZ\82·\82é)
30 //              \82 \82­\82Ü\82Å\89Á\8eZ\82È\82Ì\82Å\81C\8dÅ\8f\89\82É\94z\97ñ\82ð\83[\83\8d\83N\83\8a\83A\82·\82é\95K\97v\82ª\82 \82é
31 //      
32 //      void Reset()
33 //              \83\8a\83Z\83b\83g\82·\82é
34 //
35 //      void SetReg(uint reg, uint8 data)
36 //              \83\8c\83W\83X\83^ reg \82É data \82ð\8f\91\82«\8d\9e\82Þ
37 //      
38 //      uint GetReg(uint reg)
39 //              \83\8c\83W\83X\83^ reg \82Ì\93à\97e\82ð\93Ç\82Ý\8fo\82·
40 //      
41 //      void SetVolume(int db)
42 //              \8ae\89¹\8c¹\82Ì\89¹\97Ê\82ð\92²\90ß\82·\82é
43 //              \92P\88Ê\82Í\96ñ 1/2 dB
44 //
45 class PSG
46 {
47 public:
48         typedef PSG_SAMPLETYPE Sample;
49         
50         enum
51         {
52                 noisetablesize = 1 << 11,       // \81©\83\81\83\82\83\8a\8eg\97p\97Ê\82ð\8c¸\82ç\82µ\82½\82¢\82È\82ç\8c¸\82ç\82µ\82Ä
53                 toneshift = 24,
54                 envshift = 22,
55                 noiseshift = 14,
56                 oversampling = 2,               // \81© \89¹\8e¿\82æ\82è\91¬\93x\82ª\97D\90æ\82È\82ç\8c¸\82ç\82·\82Æ\82¢\82¢\82©\82à
57         };
58
59 public:
60         PSG();
61         ~PSG();
62
63         void Mix(Sample* dest, int nsamples);
64         void SetClock(int clock, int rate);
65         
66         void SetVolume(int vol);
67         void SetChannelMask(int c);
68         
69         void Reset();
70         void SetReg(uint regnum, uint8 data);
71         uint GetReg(uint regnum) { return reg[regnum & 0x0f]; }
72
73         void SaveState(void *f);
74         bool LoadState(void *f);
75         
76 protected:
77         void MakeNoiseTable();
78         void MakeEnvelopTable();
79         static void StoreSample(Sample& dest, int32 data);
80         
81         uint8 reg[16];
82
83         const uint* envelop;
84         uint olevel[3];
85         uint32 scount[3], speriod[3];
86         uint32 ecount, eperiod;
87         uint32 ncount, nperiod;
88         uint32 tperiodbase;
89         uint32 eperiodbase;
90         uint32 nperiodbase;
91         int mask;
92
93         static uint enveloptable[16][64];
94         static uint noisetable[noisetablesize];
95         static int EmitTable[32];
96 };
97
98 #endif // PSG_H