1
0
Fork 0

small cleanup

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3390
This commit is contained in:
Sebastian Strohhäcker 2009-05-15 21:07:13 +00:00
parent 7696f4706c
commit 05da192ef7
3 changed files with 37 additions and 21 deletions

View file

@ -16,7 +16,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* $Id: adlib.cpp,v 1.39 2009-05-14 18:28:04 harekiet Exp $ */
/* $Id: adlib.cpp,v 1.40 2009-05-15 21:07:13 c2woody Exp $ */
#include <stdlib.h>
#include <string.h>
@ -93,7 +93,7 @@ namespace OPL3 {
}
virtual Bit32u WriteAddr( Bit32u port, Bit8u val ) {
adlib_write_index(port, val);
return index;
return opl_index;
}
virtual void Generate( MixerChannel* chan, Bitu samples ) {
Bit16s buf[1024*2];

View file

@ -26,7 +26,7 @@
#include <math.h>
#include <string.h>
#include <stdlib.h> // rand()
#include "dosbox.h"
#include "opl.h"
@ -44,8 +44,8 @@ static Bit32s tremval_const[BLOCKBUF_SIZE];
// vibrato value tables (used per-operator)
static Bit32s vibval_var1[BLOCKBUF_SIZE];
static Bit32s vibval_var2[BLOCKBUF_SIZE];
static Bit32s vibval_var3[BLOCKBUF_SIZE];
static Bit32s vibval_var4[BLOCKBUF_SIZE];
//static Bit32s vibval_var3[BLOCKBUF_SIZE];
//static Bit32s vibval_var4[BLOCKBUF_SIZE];
// vibrato/trmolo value table pointers
static Bit32s *vibval1, *vibval2, *vibval3, *vibval4;
@ -131,8 +131,18 @@ static Bit32u wavestart[8] = {
};
// envelope generator function constants
static fltype attackconst[4] = {1/2.82624,1/2.25280,1/1.88416,1/1.59744};
static fltype decrelconst[4] = {1/39.28064,1/31.41608,1/26.17344,1/22.44608};
static fltype attackconst[4] = {
(fltype)(1/2.82624),
(fltype)(1/2.25280),
(fltype)(1/1.88416),
(fltype)(1/1.59744)
};
static fltype decrelconst[4] = {
(fltype)(1/39.28064),
(fltype)(1/31.41608),
(fltype)(1/26.17344),
(fltype)(1/22.44608)
};
void operator_advance(op_type* op_pt, Bit32s vib) {
@ -280,9 +290,9 @@ void operator_attack(op_type* op_pt) {
op_pt->amp = 1.0;
op_pt->step_amp = 1.0;
}
op_pt->step_skip_pos <<= 1;
if (op_pt->step_skip_pos==0) op_pt->step_skip_pos = 1;
if (op_pt->step_skip_pos & op_pt->env_step_skip_a) { // check if required to skip next step
op_pt->step_skip_pos_a <<= 1;
if (op_pt->step_skip_pos_a==0) op_pt->step_skip_pos_a = 1;
if (op_pt->step_skip_pos_a & op_pt->env_step_skip_a) { // check if required to skip next step
op_pt->step_amp = op_pt->amp;
}
}
@ -493,7 +503,7 @@ void adlib_init(Bit32u samplerate) {
op[i].env_step_a = 0;
op[i].env_step_d = 0;
op[i].env_step_r = 0;
op[i].step_skip_pos = 0;
op[i].step_skip_pos_a = 0;
op[i].env_step_skip_a = 0;
#if defined(OPLTYPE_IS_OPL3)
@ -510,7 +520,7 @@ void adlib_init(Bit32u samplerate) {
}
status = 0;
index = 0;
opl_index = 0;
// create vibrato table
@ -558,9 +568,9 @@ void adlib_init(Bit32u samplerate) {
wavtable[(i<<1) +WAVEPREC] = (Bit16s)(16384*sin((fltype)((i<<1) )*PI*2/WAVEPREC));
wavtable[(i<<1)+1+WAVEPREC] = (Bit16s)(16384*sin((fltype)((i<<1)+1)*PI*2/WAVEPREC));
wavtable[i] = wavtable[(i<<1) +WAVEPREC];
// table to be verified, alternative: (zero-less)
/* wavtable[(i<<1) +WAVEPREC] = (Bit16s)(16384*sin((fltype)(((i*2+1)<<1)-1)*PI/WAVEPREC));
wavtable[(i<<1)+1+WAVEPREC] = (Bit16s)(16384*sin((fltype)(((i*2+1)<<1) )*PI/WAVEPREC));
// alternative: (zero-less)
/* wavtable[(i<<1) +WAVEPREC] = (Bit16s)(16384*sin((fltype)((i<<2)+1)*PI/WAVEPREC));
wavtable[(i<<1)+1+WAVEPREC] = (Bit16s)(16384*sin((fltype)((i<<2)+3)*PI/WAVEPREC));
wavtable[i] = wavtable[(i<<1)-1+WAVEPREC]; */
}
for (i=0;i<(WAVEPREC>>3);i++) {
@ -588,7 +598,6 @@ void adlib_init(Bit32u samplerate) {
void adlib_write(Bitu idx, Bit8u val) {
Bit32u second_set = idx&0x100;
Bit8u old_val = adlibreg[idx];
adlibreg[idx] = val;
switch (idx&0xf0) {
@ -900,16 +909,16 @@ Bitu adlib_reg_read(Bitu port) {
}
void adlib_write_index(Bitu port, Bit8u val) {
index = val;
opl_index = val;
#if defined(OPLTYPE_IS_OPL3)
if ((port&3)!=0) {
// possibly second set
if (((adlibreg[0x105]&1)!=0) || (index==5)) index |= ARC_SECONDSET;
if (((adlibreg[0x105]&1)!=0) || (opl_index==5)) opl_index |= ARC_SECONDSET;
}
#endif
}
static void INLINE clipit16(Bit32s ival, Bit16s* outval) {
static void OPL_INLINE clipit16(Bit32s ival, Bit16s* outval) {
if (ival<32768) {
if (ival>-32769) {
*outval=(Bit16s)ival;

View file

@ -42,6 +42,13 @@ typedef uint8_t Bit8u;
typedef int8_t Bit8s;
*/
/*
define attribution that inlines/forces inlining of a function (optional)
*/
#define OPL_INLINE INLINE
#undef NUM_CHANNELS
#if defined(OPLTYPE_IS_OPL3)
#define NUM_CHANNELS 18
@ -135,7 +142,7 @@ typedef struct operator_struct {
Bit32u generator_pos; // for non-standard sample rates we need to determine how many samples have passed
Bits cur_env_step; // current (standardized) sample position
Bits env_step_a,env_step_d,env_step_r; // number of std samples of one step (for attack/decay/release mode)
Bit8u step_skip_pos; // position of 8-cyclic step skipping (always 2^x to check against mask)
Bit8u step_skip_pos_a; // position of 8-cyclic step skipping (always 2^x to check against mask)
Bits env_step_skip_a; // bitmask that determines if a step is skipped (respective bit is zero then)
#if defined(OPLTYPE_IS_OPL3)
@ -151,7 +158,7 @@ op_type op[MAXOPERATORS];
Bits int_samplerate;
Bit8u status;
Bit32u index;
Bit32u opl_index;
#if defined(OPLTYPE_IS_OPL3)
Bit8u adlibreg[512]; // adlib register set (including second set)
Bit8u wave_sel[44]; // waveform selection