---------- Create one of virtual YM3812 ---------- */ 'rate' is sampling rate and 'bufsiz' is the size of the */
| 1206 | /* ---------- Create one of virtual YM3812 ---------- */ |
| 1207 | /* 'rate' is sampling rate and 'bufsiz' is the size of the */ |
| 1208 | FM_OPL *OPLCreate(int type, int clock, int rate) |
| 1209 | { |
| 1210 | char *ptr; |
| 1211 | FM_OPL *OPL; |
| 1212 | int state_size; |
| 1213 | int max_ch = 12; /* normally 9 channels */ |
| 1214 | |
| 1215 | if( OPL_LockTable() ==-1) return NULL; |
| 1216 | /* allocate OPL state space */ |
| 1217 | state_size = sizeof(FM_OPL); |
| 1218 | state_size += sizeof(OPL_CH)*max_ch; |
| 1219 | #if BUILD_Y8950 |
| 1220 | if(type&OPL_TYPE_ADPCM) state_size+= sizeof(YM_DELTAT); |
| 1221 | #endif |
| 1222 | /* allocate memory block */ |
| 1223 | ptr = (char*)malloc(state_size); |
| 1224 | if(ptr==NULL) return NULL; |
| 1225 | /* clear */ |
| 1226 | memset(ptr,0,state_size); |
| 1227 | OPL = (FM_OPL *)ptr; ptr+=sizeof(FM_OPL); |
| 1228 | OPL->P_CH = (OPL_CH *)ptr; ptr+=sizeof(OPL_CH)*max_ch; |
| 1229 | #if BUILD_Y8950 |
| 1230 | if(type&OPL_TYPE_ADPCM) OPL->deltat = (YM_DELTAT *)ptr; ptr+=sizeof(YM_DELTAT); |
| 1231 | #endif |
| 1232 | /* set channel state pointer */ |
| 1233 | OPL->type = type; |
| 1234 | OPL->clock = clock; |
| 1235 | OPL->rate = rate; |
| 1236 | OPL->max_ch = max_ch; |
| 1237 | /* init global tables */ |
| 1238 | OPL_initalize(OPL); |
| 1239 | /* reset chip */ |
| 1240 | OPLResetChip(OPL); |
| 1241 | #ifdef OPL_OUTPUT_LOG |
| 1242 | if(!opl_dbg_fp) |
| 1243 | { |
| 1244 | opl_dbg_fp = fopen("opllog.opl","wb"); |
| 1245 | opl_dbg_maxchip = 0; |
| 1246 | } |
| 1247 | if(opl_dbg_fp) |
| 1248 | { |
| 1249 | opl_dbg_opl[opl_dbg_maxchip] = OPL; |
| 1250 | fprintf(opl_dbg_fp,"%c%c%c%c%c%c",0x00+opl_dbg_maxchip, |
| 1251 | type, |
| 1252 | clock&0xff, |
| 1253 | (clock/0x100)&0xff, |
| 1254 | (clock/0x10000)&0xff, |
| 1255 | (clock/0x1000000)&0xff); |
| 1256 | opl_dbg_maxchip++; |
| 1257 | } |
| 1258 | #endif |
| 1259 | return OPL; |
| 1260 | } |
| 1261 | |
| 1262 | void OPLReInit(FM_OPL *OPL, int clock, int rate) |
| 1263 | { |
no test coverage detected