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 
00048         for (i=0; i<6; i++) {
00049                 SINT16 *ptr = rhythmcfg.pcm[i].sample;
00050                 rhythmcfg.pcm[i].sample = NULL;
00051                 if (ptr) {
00052                         _MFREE(ptr);
00053                 }
00054         }
00055 }
00056 
00057 static void rhythm_load(void) {
00058 
00059         int             i;
00060         OEMCHAR path[MAX_PATH];
00061 
00062         for (i=0; i<6; i++) {
00063                 if (rhythmcfg.pcm[i].sample == NULL) {
00064                         getbiospath(path, rhythmfile[i], NELEMENTS(path));
00065                         pcmmix_regfile(rhythmcfg.pcm + i, path, rhythmcfg.rate);
00066                 }
00067         }
00068 }
00069 
00070 UINT rhythm_getcaps(void) {
00071 
00072         UINT    ret;
00073         UINT    i;
00074 
00075         ret = 0;
00076         for (i=0; i<6; i++) {
00077                 if (rhythmcfg.pcm[i].sample) {
00078                         ret |= 1 << i;
00079                 }
00080         }
00081         return(ret);
00082 }
00083 
00084 void rhythm_setvol(UINT vol) {
00085 
00086         rhythmcfg.vol = vol;
00087 }
00088 
00089 void rhythm_reset(RHYTHM rhy) {
00090 
00091         ZeroMemory(rhy, sizeof(_RHYTHM));
00092 }
00093 
00094 void rhythm_bind(RHYTHM rhy) {
00095 
00096         UINT    i;
00097 
00098         rhythm_load();
00099         rhy->hdr.enable = 0x3f;
00100         for (i=0; i<6; i++) {
00101                 rhy->trk[i].data = rhythmcfg.pcm[i];
00102         }
00103         rhythm_update(rhy);
00104 //      sound_streamregist(rhy, (SOUNDCB)pcmmix_getpcm);
00105 }
00106 
00107 void rhythm_update(RHYTHM rhy) {
00108 
00109         UINT    i;
00110 
00111         for (i=0; i<6; i++) {
00112                 rhy->trk[i].volume = (rhythmcfg.voltbl[rhy->vol + rhy->trkvol[i]] *
00113                                                                                                                 rhythmcfg.vol) >> 10;
00114         }
00115 }
00116 
00117 void rhythm_setreg(RHYTHM rhy, UINT reg, REG8 value) {
00118 
00119         PMIXTRK *trk;
00120         REG8    bit;
00121 
00122         if (reg == 0x10) {
00123                 sound_sync();
00124                 trk = rhy->trk;
00125                 bit = 0x01;
00126                 do {
00127                         if (value & bit) {
00128                                 if (value & 0x80) {
00129                                         rhy->hdr.playing &= ~((UINT)bit);
00130                                 }
00131                                 else if (trk->data.sample) {
00132                                         trk->pcm = trk->data.sample;
00133                                         trk->remain = trk->data.samples;
00134                                         rhy->hdr.playing |= bit;
00135                                 }
00136                         }
00137                         trk++;
00138                         bit <<= 1;
00139                 } while(bit < 0x40);
00140         }
00141         else if (reg == 0x11) {
00142                 sound_sync();
00143                 rhy->vol = (~value) & 0x3f;
00144                 rhythm_update(rhy);
00145         }
00146         else if ((reg >= 0x18) && (reg < 0x1e)) {
00147                 sound_sync();
00148                 trk = rhy->trk + (reg - 0x18);
00149                 trk->flag = ((value & 0x80) >> 7) + ((value & 0x40) >> 5);
00150                 value = (~value) & 0x1f;
00151                 rhy->trkvol[reg - 0x18] = (UINT8)value;
00152                 trk->volume = (rhythmcfg.voltbl[rhy->vol + value] *
00153                                                                                                                 rhythmcfg.vol) >> 10;
00154         }
00155 }
00156