ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

cms.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef AUDIO_SOFTSYNTH_CMS_H
00024 #define AUDIO_SOFTSYNTH_CMS_H
00025 
00026 #include "common/scummsys.h"
00027 
00028 /* this structure defines a channel */
00029 struct saa1099_channel {
00030     int frequency;              /* frequency (0x00..0xff) */
00031     int freq_enable;            /* frequency enable */
00032     int noise_enable;           /* noise enable */
00033     int octave;             /* octave (0x00..0x07) */
00034     int amplitude[2];           /* amplitude (0x00..0x0f) */
00035     int envelope[2];            /* envelope (0x00..0x0f or 0x10 == off) */
00036 
00037     /* vars to simulate the square wave */
00038     double counter;
00039     double freq;
00040     int level;
00041 };
00042 
00043 /* this structure defines a noise channel */
00044 struct saa1099_noise {
00045     /* vars to simulate the noise generator output */
00046     double counter;
00047     double freq;
00048     int level;              /* noise polynomal shifter */
00049 };
00050 
00051 /* this structure defines a SAA1099 chip */
00052 struct SAA1099 {
00053     int stream;             /* our stream */
00054     int noise_params[2];            /* noise generators parameters */
00055     int env_enable[2];          /* envelope generators enable */
00056     int env_reverse_right[2];       /* envelope reversed for right channel */
00057     int env_mode[2];            /* envelope generators mode */
00058     int env_bits[2];            /* non zero = 3 bits resolution */
00059     int env_clock[2];           /* envelope clock mode (non-zero external) */
00060     int env_step[2];            /* current envelope step */
00061     int all_ch_enable;          /* all channels enable */
00062     int sync_state;             /* sync all channels */
00063     int selected_reg;           /* selected register */
00064     struct saa1099_channel channels[6]; /* channels */
00065     struct saa1099_noise noise[2];      /* noise generators */
00066 };
00067 
00068 class CMSEmulator {
00069 public:
00070     CMSEmulator(uint32 sampleRate) {
00071         // In PCs the chips run at 7.15909 MHz instead of 8 MHz.
00072         // Adjust sampling rate upwards to bring pitch down.
00073         _sampleRate = (sampleRate * 352) / 315;
00074         memset(_saa1099, 0, sizeof(SAA1099)*2);
00075     }
00076 
00077     ~CMSEmulator() { }
00078 
00079     void portWrite(int port, int val);
00080     void readBuffer(int16 *buffer, const int numSamples);
00081 private:
00082     uint32 _sampleRate;
00083 
00084     SAA1099 _saa1099[2];
00085 
00086     void envelope(int chip, int ch);
00087     void update(int chip, int16 *buffer, int length);
00088     void portWriteIntern(int chip, int offset, int data);
00089 };
00090 
00091 
00092 #endif


Generated on Sat May 18 2019 05:00:57 for ResidualVM by doxygen 1.7.1
curved edge   curved edge