DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
src/hardware/snd_pc98/sound/rhythmc.c
00001 #include    "np2glue.h"
00002 //#include      "compiler.h"
00003 #include        <math.h>
00004 //#include      "pccore.h"
00005 #include        "sound.h"
00006 #include        "rhythm.h"
00007 
00008 
00009 static const OEMCHAR file_2608bd[] = OEMTEXT("2608_bd.wav");
00010 static const OEMCHAR file_2608sd[] = OEMTEXT("2608_sd.wav");
00011 static const OEMCHAR file_2608top[] = OEMTEXT("2608_top.wav");
00012 static const OEMCHAR file_2608hh[] = OEMTEXT("2608_hh.wav");
00013 static const OEMCHAR file_2608tom[] = OEMTEXT("2608_tom.wav");
00014 static const OEMCHAR file_2608rim[] = OEMTEXT("2608_rim.wav");
00015 
00016 static const OEMCHAR *rhythmfile[6] = {
00017                                 file_2608bd,    file_2608sd,    file_2608top,
00018                                 file_2608hh,    file_2608tom,   file_2608rim};
00019 
00020 typedef struct {
00021         UINT    rate;
00022         UINT    pcmexist;
00023         PMIXDAT pcm[6];
00024         UINT    vol;
00025         UINT    voltbl[96];
00026 } RHYTHMCFG;
00027 
00028 static  RHYTHMCFG       rhythmcfg;
00029 
00030 
00031 void rhythm_initialize(UINT rate) {
00032 
00033         UINT    i;
00034 
00035         ZeroMemory(&rhythmcfg, sizeof(rhythmcfg));
00036         rhythmcfg.rate = rate;
00037 
00038         for (i=0; i<96; i++) {
00039                 rhythmcfg.voltbl[i] = (UINT)(32768.0 *
00040                                                                                 pow(2.0, (double)i * (-3.0) / 40.0));
00041         }
00042 }
00043 
00044 void rhythm_deinitialize(void) {
00045 
00046         UINT    i;
00047         SINT16  *ptr;
00048 
00049         for (i=0; i<6; i++) {
00050                 ptr = rhythmcfg.pcm[i].sample;
00051                 rhythmcfg.pcm[i].sample = NULL;
00052                 if (ptr) {
00053                         _MFREE(ptr);
00054                 }
00055         }
00056 }
00057 
00058 static void rhythm_load(void) {
00059 
00060         int             i;
00061         OEMCHAR path[MAX_PATH];
00062 
00063         for (i=0; i<6; i++) {
00064                 if (rhythmcfg.pcm[i].sample == NULL) {
00065                         getbiospath(path, rhythmfile[i], NELEMENTS(path));
00066                         pcmmix_regfile(rhythmcfg.pcm + i, path, rhythmcfg.rate);
00067                 }
00068         }
00069 }
00070 
00071 UINT rhythm_getcaps(void) {
00072 
00073         UINT    ret;
00074         UINT    i;
00075 
00076         ret = 0;
00077         for (i=0; i<6; i++) {
00078                 if (rhythmcfg.pcm[i].sample) {
00079                         ret |= 1 << i;
00080                 }
00081         }
00082         return(ret);
00083 }
00084 
00085 void rhythm_setvol(UINT vol) {
00086 
00087         rhythmcfg.vol = vol;
00088 }
00089 
00090 void rhythm_reset(RHYTHM rhy) {
00091 
00092         ZeroMemory(rhy, sizeof(_RHYTHM));
00093 }
00094 
00095 void rhythm_bind(RHYTHM rhy) {
00096 
00097         UINT    i;
00098 
00099         rhythm_load();
00100         rhy->hdr.enable = 0x3f;
00101         for (i=0; i<6; i++) {
00102                 rhy->trk[i].data = rhythmcfg.pcm[i];
00103         }
00104         rhythm_update(rhy);
00105 //      sound_streamregist(rhy, (SOUNDCB)pcmmix_getpcm);
00106 }
00107 
00108 void rhythm_update(RHYTHM rhy) {
00109 
00110         UINT    i;
00111 
00112         for (i=0; i<6; i++) {
00113                 rhy->trk[i].volume = (rhythmcfg.voltbl[rhy->vol + rhy->trkvol[i]] *
00114                                                                                                                 rhythmcfg.vol) >> 10;
00115         }
00116 }
00117 
00118 void rhythm_setreg(RHYTHM rhy, UINT reg, REG8 value) {
00119 
00120         PMIXTRK *trk;
00121         REG8    bit;
00122 
00123         if (reg == 0x10) {
00124                 sound_sync();
00125                 trk = rhy->trk;
00126                 bit = 0x01;
00127                 do {
00128                         if (value & bit) {
00129                                 if (value & 0x80) {
00130                                         rhy->hdr.playing &= ~((UINT)bit);
00131                                 }
00132                                 else if (trk->data.sample) {
00133                                         trk->pcm = trk->data.sample;
00134                                         trk->remain = trk->data.samples;
00135                                         rhy->hdr.playing |= bit;
00136                                 }
00137                         }
00138                         trk++;
00139                         bit <<= 1;
00140                 } while(bit < 0x40);
00141         }
00142         else if (reg == 0x11) {
00143                 sound_sync();
00144                 rhy->vol = (~value) & 0x3f;
00145                 rhythm_update(rhy);
00146         }
00147         else if ((reg >= 0x18) && (reg < 0x1e)) {
00148                 sound_sync();
00149                 trk = rhy->trk + (reg - 0x18);
00150                 trk->flag = ((value & 0x80) >> 7) + ((value & 0x40) >> 5);
00151                 value = (~value) & 0x1f;
00152                 rhy->trkvol[reg - 0x18] = (UINT8)value;
00153                 trk->volume = (rhythmcfg.voltbl[rhy->vol + value] *
00154                                                                                                                 rhythmcfg.vol) >> 10;
00155         }
00156 }
00157