From abee80062051164aa4931527a54c07046dbc1394 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Tue, 6 Dec 2016 20:13:02 +0300 Subject: Added Nuked OPL3 emulator (which is more accurate than DosBox's) Also: - Fixed warnings in the CLang code model plugin for Qt Creator - Fixed bend coefficient which caused incorrect hi-hats in DMX banks --- src/nukedopl3.h | 151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/nukedopl3.h (limited to 'src/nukedopl3.h') diff --git a/src/nukedopl3.h b/src/nukedopl3.h new file mode 100644 index 0000000..e7f05ef --- /dev/null +++ b/src/nukedopl3.h @@ -0,0 +1,151 @@ +// +// Copyright (C) 2013-2016 Alexey Khokholov (Nuke.YKT) +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// +// Nuked OPL3 emulator. +// Thanks: +// MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh): +// Feedback and Rhythm part calculation information. +// forums.submarine.org.uk(carbon14, opl3): +// Tremolo and phase generator calculation information. +// OPLx decapsulated(Matthew Gambrell, Olli Niemitalo): +// OPL2 ROMs. +// +// version: 1.7.4 +// + +#ifndef OPL_OPL3_H +#define OPL_OPL3_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#define OPL_WRITEBUF_SIZE 1024 +#define OPL_WRITEBUF_DELAY 2 + +typedef uintptr_t Bitu; +typedef intptr_t Bits; +typedef uint64_t Bit64u; +typedef int64_t Bit64s; +typedef uint32_t Bit32u; +typedef int32_t Bit32s; +typedef uint16_t Bit16u; +typedef int16_t Bit16s; +typedef uint8_t Bit8u; +typedef int8_t Bit8s; + +typedef struct _opl3_slot opl3_slot; +typedef struct _opl3_channel opl3_channel; +typedef struct _opl3_chip opl3_chip; + +#pragma pack(1) +struct _opl3_slot +{ + opl3_channel *channel; + opl3_chip *chip; + Bit16s out; + Bit16s fbmod; + Bit16s *mod; + Bit16s prout; + Bit16s eg_rout; + Bit16s eg_out; + Bit8u eg_inc; + Bit8u eg_gen; + Bit8u eg_rate; + Bit8u eg_ksl; + Bit8u *trem; + Bit8u reg_vib; + Bit8u reg_type; + Bit8u reg_ksr; + Bit8u reg_mult; + Bit8u reg_ksl; + Bit8u reg_tl; + Bit8u reg_ar; + Bit8u reg_dr; + Bit8u reg_sl; + Bit8u reg_rr; + Bit8u reg_wf; + Bit8u key; + Bit32u pg_phase; + Bit32u timer; +}; + +struct _opl3_channel +{ + opl3_slot *slots[2]; + opl3_channel *pair; + opl3_chip *chip; + Bit16s *out[4]; + Bit8u chtype; + Bit16u f_num; + Bit8u block; + Bit8u fb; + Bit8u con; + Bit8u alg; + Bit8u ksv; + Bit16u cha, chb; +}; + +typedef struct _opl3_writebuf +{ + Bit64u time; + Bit16u reg; + Bit8u data; +} opl3_writebuf; +#pragma pack(0) + +struct _opl3_chip +{ + opl3_channel channel[18]; + opl3_slot slot[36]; + Bit16u timer; + Bit8u newm; + Bit8u nts; + Bit8u rhy; + Bit8u vibpos; + Bit8u vibshift; + Bit8u tremolo; + Bit8u tremolopos; + Bit8u tremoloshift; + Bit32u noise; + Bit16s zeromod; + Bit32s mixbuff[2]; + //OPL3L + Bit32s rateratio; + Bit32s samplecnt; + Bit16s oldsamples[2]; + Bit16s samples[2]; + + Bit64u writebuf_samplecnt; + Bit32u writebuf_cur; + Bit32u writebuf_last; + Bit64u writebuf_lasttime; + opl3_writebuf writebuf[OPL_WRITEBUF_SIZE]; +}; + +void OPL3_Generate(opl3_chip *chip, Bit16s *buf); +void OPL3_GenerateResampled(opl3_chip *chip, Bit16s *buf); +void OPL3_Reset(opl3_chip *chip, Bit32u samplerate); +void OPL3_WriteReg(opl3_chip *chip, Bit16u reg, Bit8u v); +void OPL3_WriteRegBuffered(opl3_chip *chip, Bit16u reg, Bit8u v); +void OPL3_GenerateStream(opl3_chip *chip, Bit16s *sndptr, Bit32u numsamples); +void OPL3_GenerateStreamMix(opl3_chip *chip, Bit16s *sndptr, Bit32u numsamples); + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.2.3 From b39cca1c30b0424a567d3826a8038946404cf0a6 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Wed, 7 Dec 2016 14:29:08 +0300 Subject: Fixed crash in the DosBox version (because after std::vector's resize, contents is uninitialized, Valgrind has been confirmed that) --- src/nukedopl3.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/nukedopl3.h') diff --git a/src/nukedopl3.h b/src/nukedopl3.h index e7f05ef..ea44de9 100644 --- a/src/nukedopl3.h +++ b/src/nukedopl3.h @@ -51,13 +51,13 @@ typedef struct _opl3_slot opl3_slot; typedef struct _opl3_channel opl3_channel; typedef struct _opl3_chip opl3_chip; -#pragma pack(1) struct _opl3_slot { opl3_channel *channel; opl3_chip *chip; Bit16s out; Bit16s fbmod; + Bit8u ___padding[4]; Bit16s *mod; Bit16s prout; Bit16s eg_rout; @@ -66,6 +66,7 @@ struct _opl3_slot Bit8u eg_gen; Bit8u eg_rate; Bit8u eg_ksl; + Bit8u ___padding2[6]; Bit8u *trem; Bit8u reg_vib; Bit8u reg_type; @@ -81,6 +82,7 @@ struct _opl3_slot Bit8u key; Bit32u pg_phase; Bit32u timer; + Bit8u ___padding3[4]; }; struct _opl3_channel @@ -90,13 +92,16 @@ struct _opl3_channel opl3_chip *chip; Bit16s *out[4]; Bit8u chtype; + Bit8u ___padding[1]; Bit16u f_num; Bit8u block; Bit8u fb; Bit8u con; Bit8u alg; Bit8u ksv; + Bit8u ___padding2[1]; Bit16u cha, chb; + Bit8u ___padding3[2]; }; typedef struct _opl3_writebuf @@ -104,8 +109,8 @@ typedef struct _opl3_writebuf Bit64u time; Bit16u reg; Bit8u data; + Bit8u ___padding[5]; } opl3_writebuf; -#pragma pack(0) struct _opl3_chip { -- cgit v1.2.3 From 4b7d6c631c96b515688fdc297a82e74ef45892c8 Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Thu, 8 Dec 2016 11:55:54 +0300 Subject: Rename "slots" into "chipslots" (including this header into Qt application will cause error, because "slots" in Qt just an dummy macro) --- src/nukedopl3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nukedopl3.h') diff --git a/src/nukedopl3.h b/src/nukedopl3.h index ea44de9..415ba3e 100644 --- a/src/nukedopl3.h +++ b/src/nukedopl3.h @@ -87,7 +87,7 @@ struct _opl3_slot struct _opl3_channel { - opl3_slot *slots[2]; + opl3_slot *chipslots[2]; opl3_channel *pair; opl3_chip *chip; Bit16s *out[4]; -- cgit v1.2.3 From b2890608189a69695a5119e1be771b89278dce9b Mon Sep 17 00:00:00 2001 From: Wohlstand Date: Mon, 16 Jan 2017 08:24:19 +0300 Subject: Split adlmidi.cpp now keeps API functions only other code has been moved into separated files --- src/nukedopl3.h | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'src/nukedopl3.h') diff --git a/src/nukedopl3.h b/src/nukedopl3.h index 415ba3e..0a686e2 100644 --- a/src/nukedopl3.h +++ b/src/nukedopl3.h @@ -1,28 +1,28 @@ -// -// Copyright (C) 2013-2016 Alexey Khokholov (Nuke.YKT) -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// -// Nuked OPL3 emulator. -// Thanks: -// MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh): -// Feedback and Rhythm part calculation information. -// forums.submarine.org.uk(carbon14, opl3): -// Tremolo and phase generator calculation information. -// OPLx decapsulated(Matthew Gambrell, Olli Niemitalo): -// OPL2 ROMs. -// -// version: 1.7.4 -// +/* + * Copyright (C) 2013-2016 Alexey Khokholov (Nuke.YKT) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * + * Nuked OPL3 emulator. + * Thanks: + * MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh): + * Feedback and Rhythm part calculation information. + * forums.submarine.org.uk(carbon14, opl3): + * Tremolo and phase generator calculation information. + * OPLx decapsulated(Matthew Gambrell, Olli Niemitalo): + * OPL2 ROMs. + * + * version: 1.7.4 + */ #ifndef OPL_OPL3_H #define OPL_OPL3_H @@ -128,7 +128,7 @@ struct _opl3_chip Bit32u noise; Bit16s zeromod; Bit32s mixbuff[2]; - //OPL3L + /* OPL3L */ Bit32s rateratio; Bit32s samplecnt; Bit16s oldsamples[2]; -- cgit v1.2.3