diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/adldata.cpp | 473 | ||||
| -rw-r--r-- | src/adlmidi.cpp | 22 | ||||
| -rw-r--r-- | src/adlmidi_load.cpp | 2 | ||||
| -rw-r--r-- | src/adlmidi_midiplay.cpp | 15 | ||||
| -rw-r--r-- | src/adlmidi_opl3.cpp | 30 | ||||
| -rw-r--r-- | src/adlmidi_private.cpp | 7 | ||||
| -rw-r--r-- | src/adlmidi_private.hpp | 12 | ||||
| -rw-r--r-- | src/chips/dosbox_opl3.cpp | 4 | ||||
| -rw-r--r-- | src/chips/dosbox_opl3.h | 1 | ||||
| -rw-r--r-- | src/chips/nuked_opl3.h | 1 | ||||
| -rw-r--r-- | src/chips/nuked_opl3_v174.h | 1 | ||||
| -rw-r--r-- | src/chips/opl_chip_base.h | 30 | ||||
| -rw-r--r-- | src/chips/opl_chip_base.tcc | 84 | 
13 files changed, 427 insertions, 255 deletions
diff --git a/src/adldata.cpp b/src/adldata.cpp index 49eb36c..7215d7c 100644 --- a/src/adldata.cpp +++ b/src/adldata.cpp @@ -4,7 +4,7 @@   * FROM A NUMBER OF SOURCES, MOSTLY PC GAMES.   * PREPROCESSED, CONVERTED, AND POSTPROCESSED OFF-SCREEN.   */ -const adldata adl[4535] = +const adldata adl[4537] =  { //    ,---------+-------- Wave select settings    //    | ,-------ч-+------ Sustain/release rates    //    | | ,-----ч-ч-+---- Attack/decay rates @@ -4205,34 +4205,34 @@ const adldata adl[4535] =      { 0x2C79613,0x4E45411, 0xD7,0x08, 0xA, +0 },      { 0x023E133,0x0F2F131, 0xA2,0x09, 0xE, +0 },      { 0x023F132,0x0F2F131, 0x24,0x0A, 0xE, +0 }, -    { 0x5C3C404,0x1B4B519, 0xA1,0x00, 0xC, -31 }, -    { 0x17A9913,0x0B4F213, 0x0F,0x00, 0x8, -19 }, -    { 0x223F832,0x4055421, 0x99,0x8A, 0xC, +0 }, +    { 0x4C3C404,0x4B4B519, 0x21,0x05, 0x0, -31 }, +    { 0x17A9913,0x0B4F213, 0x0F,0x00, 0x0, -19 }, +    { 0x223F832,0x4056421, 0x99,0x8A, 0xC, +0 },      { 0x433CB32,0x5057561, 0x9B,0x8A, 0xA, +0 },      { 0x1029033,0x4044561, 0x5B,0x85, 0x4, +0 },      { 0x4109033,0x2044520, 0xA8,0x85, 0xA, +0 }, -    { 0x2034170,0x0043671, 0x08,0x20, 0x9, +0 }, -    { 0x1022171,0x0042671, 0x0C,0x17, 0xB, +0 }, +    { 0x2034170,0x0043671, 0x0B,0x20, 0xB, +0 }, +    { 0x1024171,0x0043671, 0x0C,0x17, 0xB, +0 },      { 0x005A061,0x0F55022, 0x69,0x06, 0x0, +0 },      { 0x0008060,0x0F55021, 0x33,0x08, 0x0, +12 },      { 0x239B420,0x0076121, 0x50,0x05, 0x6, +0 },      { 0x139B462,0x00D7161, 0x91,0x14, 0x0, +0 }, -    { 0x05470F1,0x07460B1, 0x5A,0x80, 0x0, +0 }, -    { 0x054A0F1,0x07460B1, 0x5E,0x80, 0x0, +0 }, -    { 0x2436110,0x114D211, 0x90,0x00, 0xC, +0 }, -    { 0x1436192,0x145F312, 0x8F,0x00, 0xC, +0 }, +    { 0x05470F1,0x07440B1, 0x69,0x80, 0x0, +0 }, +    { 0x054A0F1,0x07430B1, 0x5E,0x80, 0x0, +0 }, +    { 0x2436110,0x714D211, 0xCD,0x00, 0xA, +0 }, +    { 0x5436192,0x745F312, 0xCB,0x00, 0xA, +0 },      { 0x0147421,0x0077521, 0x94,0x04, 0xE, +0 },      { 0x0178461,0x008AF28, 0x10,0xA6, 0xC, +0 },      { 0x0235271,0x0198161, 0x1E,0x08, 0xE, +0 },      { 0x0235361,0x0196161, 0x1D,0x03, 0xE, +0 },      { 0x0155331,0x0378261, 0x94,0x00, 0xA, +0 },      { 0x118543A,0x5177472, 0x1E,0x00, 0x4, -12 }, -    { 0x0364121,0x02B7221, 0x21,0x08, 0xC, +0 }, -    { 0x026F021,0x0056121, 0x26,0x03, 0xC, +0 }, +    { 0x0365121,0x0257221, 0x1E,0x08, 0x0, +0 }, +    { 0x2844521,0x20592A0, 0x23,0x03, 0x0, +0 },      { 0x0578321,0x117C021, 0x19,0x03, 0xC, +0 },      { 0x2E77530,0x307F520, 0x10,0x08, 0x8, +0 }, -    { 0x036F121,0x337F121, 0x92,0x08, 0xE, +0 }, -    { 0x0368121,0x037F121, 0x92,0x08, 0xE, +0 }, +    { 0x036F121,0x337F121, 0x95,0x08, 0xE, +0 }, +    { 0x0368121,0x037F121, 0x95,0x08, 0xE, +0 },      { 0x0A66121,0x0976121, 0x9B,0x08, 0xE, +0 },      { 0x5237731,0x1F65012, 0x4B,0x00, 0xA, +0 },      { 0x0137732,0x0F65011, 0xC7,0x0A, 0xA, +0 }, @@ -4300,8 +4300,8 @@ const adldata adl[4535] =      { 0x5522363,0x0131331, 0x1A,0x8D, 0x7, +0 },      { 0x0B67061,0x0928032, 0x9C,0x11, 0xA, +0 },      { 0x0057F21,0x0038F62, 0x9C,0x11, 0xA, +0 }, -    { 0x0025511,0x1748201, 0x94,0x06, 0xE, +0 }, -    { 0x2045501,0x2445501, 0x15,0x0D, 0xA, +0 }, +    { 0x0625331,0x1648221, 0x94,0x06, 0xE, +0 }, +    { 0x2645321,0x2445521, 0x15,0x0D, 0xA, +0 },      { 0x0B37121,0x5F48221, 0x16,0x08, 0x2, +0 },      { 0x2B37102,0x5F48221, 0x90,0x08, 0x6, +0 },      { 0x1127533,0x4F4F211, 0x58,0x03, 0x6, +0 }, @@ -4355,12 +4355,14 @@ const adldata adl[4535] =      { 0x048FA00,0x008F900, 0x00,0x00, 0x6, +12 },      { 0x287F702,0x678F802, 0x80,0x88, 0xE, +12 },      { 0x2F7F602,0x0F8F802, 0x00,0x88, 0xE, +12 }, +    { 0x008F700,0x007F609, 0x00,0x00, 0xD, -24 }, +    { 0x0F1F105,0x0078407, 0x00,0x08, 0xC, -12 },      { 0x05476C1,0x30892C5, 0x80,0x08, 0x0, +0 },      { 0x05477C1,0x30892C5, 0x00,0x08, 0xA, -2 },      { 0x007C604,0x007C604, 0x08,0x08, 0x1, +0 },      { 0x201F302,0x057AB09, 0x03,0x07, 0xC, +12 }, -    { 0x254F307,0x307F905, 0x04,0x08, 0x6, -5 }, -    { 0x254F307,0x207F905, 0x04,0x08, 0x8, +0 }, +    { 0x058F30B,0x308F90D, 0x04,0x08, 0x6, +0 }, +    { 0x255F308,0x308F909, 0x04,0x08, 0x8, +4 },      { 0x006C604,0x007C604, 0x08,0x08, 0x1, +0 },      { 0x201F312,0x057AB09, 0x03,0x07, 0xC, +12 },      { 0x254D307,0x3288905, 0x04,0x03, 0xA, -5 }, @@ -4552,7 +4554,7 @@ const adldata adl[4535] =      { 0x07BF003,0x07BF502, 0x8A,0x80, 0x8, +0 },      { 0x07BF003,0x07BF402, 0x8A,0x80, 0x8, +0 },  }; -const struct adlinsdata adlins[4803] = +const struct adlinsdata adlins[4804] =  {      {   0,   0,  0, 0,   9006,   133,0 },      {   1,   1,  0, 0,   9206,   146,0 }, @@ -9068,20 +9070,20 @@ const struct adlinsdata adlins[4803] =      {4183,4184,  0, 1,  40000,   440,0.078125 },      {4185,4186,  0, 1,   2160,   606,0.109375 },      {4187,4188,  0, 1,  14753,  2400,0.03125 }, -    {4189,4190,  0, 1,   7693,     0,0.03125 }, +    {4189,4190,  0, 1,   7680,   646,0.03125 },      {4191,4192,  0, 1,  40000,   446,0.0625 },      {4193,4194,  0, 1,  40000,   866,-0.0625 }, -    {4195,4195,  0, 1,  40000,  1226,0.109375 }, -    {4196,4196,  0, 1,  40000,  1960,0.109375 }, +    {4195,4195,  0, 1,  40000,  1220,0.078125 }, +    {4196,4196,  0, 1,  40000,  1960,0.0625 },      {4197,4198,  0, 1,  40000,   433,0.125 },      {4199,4200,  0, 1,  40000,   140,0.140625 }, -    {4201,4202,  0, 1,  40000,   706,0.15625 }, -    {4203,4204,  0, 1,   1640,     0,0.125 }, +    {4201,4202,  0, 1,  40000,   806,0.109375 }, +    {4203,4204,  0, 1,   2040,   486,0.125 },      {4205,4206,  0, 1,  40000,    86,0 },      {4207,4208,  0, 1,  40000,    80,0.03125 },      {4209,4209,  0, 0,  40000,    73,0 },      {4210,4210,  0, 0,  40000,   126,0 }, -    {4211,4212,  0, 1,  40000,   353,0.03125 }, +    {4211,4212,  0, 1,  40000,   400,0.0625 },      {4213,4214,  0, 1,  40000,   120,0.0625 },      {4215,4216,  0, 1,  40000,     0,0.09375 },      {4217,4217,  0, 1,  40000,     0,0.125 }, @@ -9124,7 +9126,7 @@ const struct adlinsdata adlins[4803] =      {4278,4279,  0, 1,   9000,  3186,0.125 },      {4280,4281,  0, 1,  40000,  1073,-0.078125 },      {4282,4283,  0, 1,  40000,  2093,0.140625 }, -    {4284,4285,  0, 1,   5640,   440,0.078125 }, +    {4284,4285,  0, 1,  40000,     0,0.078125 },      {4286,4287,  0, 1,   9580,   713,0.03125 },      {4288,4289,  0, 1,   6286,   380,0 },      {4290,4291,  0, 1,   2220,   426,0.03125 }, @@ -9160,203 +9162,204 @@ const struct adlinsdata adlins[4803] =      {4334,4335, 25, 1,    313,   153,0 },      {4336,4335, 25, 1,    206,   100,0 },      {4337,4338, 61, 1,    153,    93,0 }, -    {4339,4340, 37, 1,    206,    93,0 }, -    {4341,4342, 15, 1,    346,   153,0 }, -    {4343,4344, 48, 1,    280,   133,-1.90625 }, -    {4345,4346, 19, 1,    553,   200,0 }, -    {4347,4347, 48, 0,    180,    86,0 }, -    {4348,4349, 15, 1,    333,   153,0 }, -    {4350,4351, 12, 1,    340,   146,0 }, -    {4352,4353, 11, 1,    346,   146,0 }, -    {4354,4355, 61, 1,   2706,  1033,0.09375 }, -    {4356,4353,  8, 1,    340,   146,0 }, -    {4357,4358, 91, 1,   1166,   366,-0.046875 }, -    {4359,4359, 70, 0,    966,   346,0 }, -    {4360,4361, 80, 1,    300,    93,0.125 }, -    {4362,4362, 58, 0,    206,    53,0 }, -    {4363,4355, 62, 1,   2333,   820,0.09375 }, -    {4364,4365, 31, 1,    773,   200,0 }, -    {4366,4358, 91, 1,   1160,   360,-0.03125 }, -    {4367,4368, 41, 1,    373,   113,0 }, -    {4369,4370, 35, 1,    406,   126,0 }, -    {4371,4372, 29, 1,    146,   106,0 }, -    {4373,4374, 41, 1,    400,   126,0 }, -    {4373,4374, 37, 1,    400,   126,0 }, -    {4375,4376, 54, 1,    286,   133,0 }, -    {4375,4377, 48, 1,    286,   126,0 }, -    {4378,4379, 77, 1,    193,    93,0 }, -    {4380,4381, 72, 1,    200,    93,0 }, -    {4382,4382, 40, 0,    513,     0,0 }, -    {4383,4383, 38, 0,    200,    20,0 }, -    {4384,4384, 36, 0,    620,    20,0 }, -    {4385,4386, 60, 1,    120,    80,0 }, -    {4386,4387, 60, 1,    380,    80,0 }, -    {4388,4388, 73, 0,    166,    33,0 }, -    {4389,4390, 68, 1,    153,    40,0 }, -    {4391,4392, 18, 1,    200,    80,0 }, -    {4393,4394, 18, 1,    253,    73,0 }, -    {4395,4395, 90, 0,    193,    20,0 }, -    {4396,4396, 90, 0,    793,    40,0 }, -    {4397,4398, 64, 1,    373,    73,0.03125 }, -    {4399,4400, 80, 1,    406,   153,0.03125 }, -    {4401,4402, 64, 1,   1866,   606,0 }, -    {4403,4403, 67, 0,    106,    26,0 }, -    {4404,4405, 50, 1,    173,     0,0 }, -    {4406,4406, 36, 0,   4646,     0,0 }, -    {4407,4407,  0, 0,  40000,    86,0 }, -    {4408,4408,  0, 0,  40000,    73,0 }, -    {4409,4409,  0, 0,   2433,   700,0 }, -    {4410,4410,  0, 0,   1233,    26,0 }, -    {4411,4411,  0, 0,  40000,    66,0 }, -    {4412,4412,  0, 0,  40000,    60,0 }, -    {4413,4413,  0, 0,  40000,    60,0 }, -    {4414,4414,  0, 0,  40000,    66,0 }, -    {4415,4415,  0, 0,  40000,    66,0 }, -    {4416,4416,  0, 0,  40000,     0,0 }, -    {4416,4416, 73, 0,  40000,     0,0 }, -    {4417,4417,  0, 0,  40000,    60,0 }, -    {4418,4418,  0, 0,  40000,    60,0 }, -    {4419,4419,  0, 0,   7326,  2486,0 }, -    {4420,4420,  0, 0,   4886,  1586,0 }, -    {4421,4421,  0, 0,    646,    20,0 }, -    {4422,4422,  0, 0,    253,    20,0 }, -    {4422,4422, 12, 0,    253,    20,0 }, -    {4423,4423,  0, 0,    640,   100,0 }, -    {4423,4423,  1, 0,    640,   106,0 }, -    {4424,4424,  0, 0,    133,   106,0 }, -    {4424,4424, 23, 0,    133,   106,0 }, -    {4425,4425,  0, 0,    653,   100,0 }, -    {4426,4426,  0, 0,   4166,  1546,0 }, -    {4427,4427,  0, 0,  40000,    73,0 }, -    {4428,4428,  0, 0,  40000,    60,0 }, -    {4429,4429,  0, 0,  40000,    53,0 }, -    {4430,4430,  0, 0,  40000,     0,0 }, -    {4431,4431,  0, 0,    246,    20,0 }, -    {4432,4432,  0, 2,      6,     0,0 }, -    {4433,4433,  0, 0,   4946,   233,0 }, -    {4434,4434,  0, 0,   4946,   233,0 }, -    {4435,4435,  0, 0,   4953,   240,0 }, +    {4339,4340, 38, 1,    340,   133,0 }, +    {4341,4342, 37, 1,    206,    93,0 }, +    {4343,4344, 15, 1,    346,   153,0 }, +    {4345,4346,100, 1,    146,     0,0.140625 }, +    {4347,4348, 19, 1,    553,   200,0 }, +    {4349,4349, 48, 0,    180,    86,0 }, +    {4350,4351, 15, 1,    333,   153,0 }, +    {4352,4353, 12, 1,    340,   146,0 }, +    {4354,4355, 11, 1,    346,   146,0 }, +    {4356,4357, 61, 1,   2706,  1033,0.09375 }, +    {4358,4355,  8, 1,    340,   146,0 }, +    {4359,4360, 91, 1,   1166,   366,-0.046875 }, +    {4361,4361, 70, 0,    966,   346,0 }, +    {4362,4363, 80, 1,    300,    93,0.125 }, +    {4364,4364, 58, 0,    206,    53,0 }, +    {4365,4357, 62, 1,   2333,   820,0.09375 }, +    {4366,4367, 31, 1,    773,   200,0 }, +    {4368,4360, 91, 1,   1160,   360,-0.03125 }, +    {4369,4370, 41, 1,    373,   113,0 }, +    {4371,4372, 35, 1,    406,   126,0 }, +    {4373,4374, 29, 1,    146,   106,0 }, +    {4375,4376, 41, 1,    400,   126,0 }, +    {4375,4376, 37, 1,    400,   126,0 }, +    {4377,4378, 54, 1,    286,   133,0 }, +    {4377,4379, 48, 1,    286,   126,0 }, +    {4380,4381, 77, 1,    193,    93,0 }, +    {4382,4383, 72, 1,    200,    93,0 }, +    {4384,4384, 40, 0,    513,     0,0 }, +    {4385,4385, 38, 0,    200,    20,0 }, +    {4386,4386, 36, 0,    620,    20,0 }, +    {4387,4388, 60, 1,    120,    80,0 }, +    {4388,4389, 60, 1,    380,    80,0 }, +    {4390,4390, 73, 0,    166,    33,0 }, +    {4391,4392, 68, 1,    153,    40,0 }, +    {4393,4394, 18, 1,    200,    80,0 }, +    {4395,4396, 18, 1,    253,    73,0 }, +    {4397,4397, 90, 0,    193,    20,0 }, +    {4398,4398, 90, 0,    793,    40,0 }, +    {4399,4400, 64, 1,    373,    73,0.03125 }, +    {4401,4402, 80, 1,    406,   153,0.03125 }, +    {4403,4404, 64, 1,   1866,   606,0 }, +    {4405,4405, 67, 0,    106,    26,0 }, +    {4406,4407, 50, 1,    173,     0,0 }, +    {4408,4408, 36, 0,   4646,     0,0 }, +    {4409,4409,  0, 0,  40000,    86,0 }, +    {4410,4410,  0, 0,  40000,    73,0 }, +    {4411,4411,  0, 0,   2433,   700,0 }, +    {4412,4412,  0, 0,   1233,    26,0 }, +    {4413,4413,  0, 0,  40000,    66,0 }, +    {4414,4414,  0, 0,  40000,    60,0 }, +    {4415,4415,  0, 0,  40000,    60,0 }, +    {4416,4416,  0, 0,  40000,    66,0 }, +    {4417,4417,  0, 0,  40000,    66,0 }, +    {4418,4418,  0, 0,  40000,     0,0 }, +    {4418,4418, 73, 0,  40000,     0,0 }, +    {4419,4419,  0, 0,  40000,    60,0 }, +    {4420,4420,  0, 0,  40000,    60,0 }, +    {4421,4421,  0, 0,   7326,  2486,0 }, +    {4422,4422,  0, 0,   4886,  1586,0 }, +    {4423,4423,  0, 0,    646,    20,0 }, +    {4424,4424,  0, 0,    253,    20,0 }, +    {4424,4424, 12, 0,    253,    20,0 }, +    {4425,4425,  0, 0,    640,   100,0 }, +    {4425,4425,  1, 0,    640,   106,0 }, +    {4426,4426,  0, 0,    133,   106,0 }, +    {4426,4426, 23, 0,    133,   106,0 }, +    {4427,4427,  0, 0,    653,   100,0 }, +    {4428,4428,  0, 0,   4166,  1546,0 }, +    {4429,4429,  0, 0,  40000,    73,0 }, +    {4430,4430,  0, 0,  40000,    60,0 }, +    {4431,4431,  0, 0,  40000,    53,0 }, +    {4432,4432,  0, 0,  40000,     0,0 }, +    {4433,4433,  0, 0,    246,    20,0 }, +    {4434,4434,  0, 2,      6,     0,0 }, +    {4435,4435,  0, 0,   4946,   233,0 },      {4436,4436,  0, 0,   4946,   233,0 }, -    {4437,4437,  0, 0,  18233,    46,0 }, -    {4438,4438,  0, 0,   2386,    26,0 }, -    {4439,4439,  0, 0,   4640,   633,0 }, -    {4440,4440,  0, 0,  18466,   100,0 }, -    {4441,4441,  0, 0,  18440,    66,-2 }, -    {4442,4442,  0, 0,  18440,  6140,-2 }, -    {4443,4443,  0, 0,   1206,   433,-2 }, -    {4444,4444,  0, 0,   4626,   240,0 }, -    {4445,4445,  0, 0,    726,   400,0 }, -    {4446,4446,  0, 0,   5866,    73,0 }, -    {4447,4447,  0, 0,  40000,    73,0 }, -    {4448,4448,  0, 0,  40000,    73,0 }, +    {4437,4437,  0, 0,   4953,   240,0 }, +    {4438,4438,  0, 0,   4946,   233,0 }, +    {4439,4439,  0, 0,  18233,    46,0 }, +    {4440,4440,  0, 0,   2386,    26,0 }, +    {4441,4441,  0, 0,   4640,   633,0 }, +    {4442,4442,  0, 0,  18466,   100,0 }, +    {4443,4443,  0, 0,  18440,    66,-2 }, +    {4444,4444,  0, 0,  18440,  6140,-2 }, +    {4445,4445,  0, 0,   1206,   433,-2 }, +    {4446,4446,  0, 0,   4626,   240,0 }, +    {4447,4447,  0, 0,    726,   400,0 }, +    {4448,4448,  0, 0,   5866,    73,0 },      {4449,4449,  0, 0,  40000,    73,0 },      {4450,4450,  0, 0,  40000,    73,0 }, -    {4451,4451,  0, 0,   6500,   346,0 }, -    {4452,4452,  0, 0,   6506,   346,0 }, -    {4453,4453,  0, 0,  40000,    66,-2 }, -    {4454,4454,  0, 0,  40000,    66,-2 }, -    {4455,4455,  0, 0,  40000,     0,0 }, -    {4456,4456,  0, 0,  40000,    46,0 }, +    {4451,4451,  0, 0,  40000,    73,0 }, +    {4452,4452,  0, 0,  40000,    73,0 }, +    {4453,4453,  0, 0,   6500,   346,0 }, +    {4454,4454,  0, 0,   6506,   346,0 }, +    {4455,4455,  0, 0,  40000,    66,-2 }, +    {4456,4456,  0, 0,  40000,    66,-2 },      {4457,4457,  0, 0,  40000,     0,0 }, -    {4457,4457,  0, 0,  40000,     0,-2 }, -    {4458,4458,  0, 0,   2386,    26,0 }, -    {4459,4459,  0, 0,  40000,    73,-2 }, -    {4460,4460,  0, 0,   5866,    26,-2 }, -    {4461,4461,  0, 0,  40000,   133,0 }, -    {4462,4462,  0, 0,  40000,   133,0 }, -    {4463,4463,  0, 0,  40000,   126,0 }, -    {4464,4464,  0, 0,    253,    20,0 }, -    {4465,4465,  0, 0,   8866,  1366,0 }, -    {4466,4466,  0, 0,   1040,   766,0 }, -    {4467,4467,  0, 0,  40000,   146,-2 }, -    {4468,4468,  0, 0,  40000,   153,-2 }, -    {4469,4469,  0, 0,  40000,   466,-2 }, -    {4470,4470,  0, 0,  40000,    66,0 }, -    {4471,4471,  0, 0,   2333,   566,0 }, -    {4472,4472,  0, 0,  40000,   140,-2 }, -    {4473,4473,  0, 0,  40000,   100,-2 }, -    {4474,4474,  0, 0,  40000,   226,-2 }, -    {4475,4475,  0, 0,  40000,     0,0 }, +    {4458,4458,  0, 0,  40000,    46,0 }, +    {4459,4459,  0, 0,  40000,     0,0 }, +    {4459,4459,  0, 0,  40000,     0,-2 }, +    {4460,4460,  0, 0,   2386,    26,0 }, +    {4461,4461,  0, 0,  40000,    73,-2 }, +    {4462,4462,  0, 0,   5866,    26,-2 }, +    {4463,4463,  0, 0,  40000,   133,0 }, +    {4464,4464,  0, 0,  40000,   133,0 }, +    {4465,4465,  0, 0,  40000,   126,0 }, +    {4466,4466,  0, 0,    253,    20,0 }, +    {4467,4467,  0, 0,   8866,  1366,0 }, +    {4468,4468,  0, 0,   1040,   766,0 }, +    {4469,4469,  0, 0,  40000,   146,-2 }, +    {4470,4470,  0, 0,  40000,   153,-2 }, +    {4471,4471,  0, 0,  40000,   466,-2 }, +    {4472,4472,  0, 0,  40000,    66,0 }, +    {4473,4473,  0, 0,   2333,   566,0 }, +    {4474,4474,  0, 0,  40000,   140,-2 }, +    {4475,4475,  0, 0,  40000,   100,-2 }, +    {4476,4476,  0, 0,  40000,   226,-2 }, +    {4477,4477,  0, 0,  40000,     0,0 },      {3712,3712,  0, 0,  40000,   226,-2 }, -    {4476,4476,  0, 0,  40000,   140,-2 }, -    {4477,4477,  0, 0,  40000,    66,0 }, -    {4478,4478,  0, 0,  40000,    73,0 }, -    {4479,4479,  0, 0,  40000,    73,0 }, -    {4480,4480,  0, 0,  40000,    86,-2 }, -    {4481,4481,  0, 0,  40000,    80,0 }, -    {4482,4482,  0, 0,  40000,    73,-2 }, -    {4483,4483,  0, 0,  40000,    80,-2 }, +    {4478,4478,  0, 0,  40000,   140,-2 }, +    {4479,4479,  0, 0,  40000,    66,0 }, +    {4480,4480,  0, 0,  40000,    73,0 }, +    {4481,4481,  0, 0,  40000,    73,0 }, +    {4482,4482,  0, 0,  40000,    86,-2 }, +    {4483,4483,  0, 0,  40000,    80,0 },      {4484,4484,  0, 0,  40000,    73,-2 }, -    {4485,4485,  0, 0,  40000,    73,0 }, -    {4486,4486,  0, 0,  40000,    73,0 }, -    {4487,4487,  0, 0,  40000,    93,0 }, +    {4485,4485,  0, 0,  40000,    80,-2 }, +    {4486,4486,  0, 0,  40000,    73,-2 }, +    {4487,4487,  0, 0,  40000,    73,0 },      {4488,4488,  0, 0,  40000,    73,0 }, -    {4489,4489,  0, 0,  11946,    13,0 }, +    {4489,4489,  0, 0,  40000,    93,0 },      {4490,4490,  0, 0,  40000,    73,0 }, -    {4460,4460,  0, 0,   5866,    26,0 }, -    {4491,4491,  0, 0,  40000,   820,0 }, -    {4492,4492,  0, 0,   2153,   873,0 }, +    {4491,4491,  0, 0,  11946,    13,0 }, +    {4492,4492,  0, 0,  40000,    73,0 }, +    {4462,4462,  0, 0,   5866,    26,0 }, +    {4493,4493,  0, 0,  40000,   820,0 }, +    {4494,4494,  0, 0,   2153,   873,0 },      {1221,1221,  0, 0,  40000,   293,0.171875 }, -    {4493,4493,  0, 0,   1620,   120,0 }, -    {4494,4494,  0, 0,  15120,    93,0 }, -    {4495,4495,  0, 0,  14613,    93,0 }, -    {4496,4496,  0, 0,   2346,   793,0 }, -    {4497,4497,  0, 0,  40000,  2380,0 }, -    {4498,4498,  0, 0,  40000,  1280,0 }, -    {4499,4499,  0, 0,  40000,  1460,0 }, -    {4500,4500,  0, 0,  40000,  2513,0 }, -    {4501,4501,  0, 0,  14840,  1266,0 }, -    {4502,4502,  0, 0,   4513,   640,0 }, -    {4503,4503,  0, 0,   4680,   806,0 }, -    {4504,4504,  0, 0,  40000,   100,0 }, -    {4505,4505,  0, 0,  40000,    66,0 }, -    {4506,4506,  0, 0,   2420,   413,0 }, -    {4507,4507,  0, 0,    406,    73,-2 }, -    {4508,4508,  0, 0,   1166,   400,0 }, -    {4509,4509,  0, 0,   1213,   106,0 }, -    {4510,4510,  0, 0,    273,    60,-2 }, -    {4511,4511,  0, 0,  40000,  2380,0 }, -    {4512,4512,  0, 0,  40000,   440,0 }, +    {4495,4495,  0, 0,   1620,   120,0 }, +    {4496,4496,  0, 0,  15120,    93,0 }, +    {4497,4497,  0, 0,  14613,    93,0 }, +    {4498,4498,  0, 0,   2346,   793,0 }, +    {4499,4499,  0, 0,  40000,  2380,0 }, +    {4500,4500,  0, 0,  40000,  1280,0 }, +    {4501,4501,  0, 0,  40000,  1460,0 }, +    {4502,4502,  0, 0,  40000,  2513,0 }, +    {4503,4503,  0, 0,  14840,  1266,0 }, +    {4504,4504,  0, 0,   4513,   640,0 }, +    {4505,4505,  0, 0,   4680,   806,0 }, +    {4506,4506,  0, 0,  40000,   100,0 }, +    {4507,4507,  0, 0,  40000,    66,0 }, +    {4508,4508,  0, 0,   2420,   413,0 }, +    {4509,4509,  0, 0,    406,    73,-2 }, +    {4510,4510,  0, 0,   1166,   400,0 }, +    {4511,4511,  0, 0,   1213,   106,0 }, +    {4512,4512,  0, 0,    273,    60,-2 }, +    {4513,4513,  0, 0,  40000,  2380,0 }, +    {4514,4514,  0, 0,  40000,   440,0 },      {1261,1261,  0, 0,  40000,  2960,0 }, -    {4513,4513, 37, 0,    973,    73,-2 }, -    {4514,4514, 48, 0,    106,     0,-2 }, -    {4515,4515, 48, 0,    286,   133,-2 }, -    {4516,4516, 62, 0,    166,    60,0 }, -    {4517,4517, 44, 0,    980,   360,0 }, -    {4518,4518, 80, 0,    100,     0,0 }, -    {4517,4517, 50, 0,    980,   346,0 }, -    {4519,4519, 48, 0,    106,     0,-2 }, -    {4517,4517, 55, 0,    973,   360,0 }, -    {4520,4520, 61, 0,    513,    20,0 }, -    {4517,4517, 58, 0,    966,   353,0 }, -    {4517,4517, 63, 0,    973,   353,0 }, -    {4521,4521, 71, 0,   1366,   580,0 }, -    {4517,4517, 72, 0,    820,   306,0 }, -    {4522,4522, 70, 0,   1886,   666,0 }, -    {4521,4521, 88, 0,   1353,   560,0 }, -    {4523,4523, 76, 0,   1873,   653,0 }, -    {4524,4524, 84, 0,    260,   113,0 }, -    {4521,4521, 68, 0,   1366,   553,0 }, -    {4525,4525, 72, 0,    153,    53,0 }, -    {4526,4526, 28, 0,   1193,   413,0 }, -    {4522,4522, 81, 0,   1353,   480,0 }, -    {4527,4527, 58, 0,    246,   120,-2 }, -    {4527,4527, 55, 0,    246,   120,-2 }, -    {4527,4527, 44, 0,    246,   120,-2 }, -    {4527,4527, 49, 0,    246,   120,-2 }, -    {4527,4527, 40, 0,    286,   133,-2 }, -    {4528,4528, 55, 0,    740,   560,-2 }, -    {4528,4528, 48, 0,    893,   693,-2 }, -    {4529,4529, 52, 0,    513,   206,0 }, -    {4529,4529, 45, 0,    513,   206,0 }, -    {4530,4530, 48, 0,    173,   100,-2 }, -    {4531,4531, 48, 0,    120,   266,-2 }, -    {4532,4532, 48, 0,    253,    60,-2 }, -    {4507,4507, 73, 0,    160,    20,-2 }, -    {4507,4507, 68, 0,    160,    20,-2 }, -    {4507,4507, 63, 0,    193,    20,-2 }, -    {4533,4533,108, 0,    406,    26,0 }, -    {4534,4534,108, 0,    740,    26,0 }, +    {4515,4515, 37, 0,    973,    73,-2 }, +    {4516,4516, 48, 0,    106,     0,-2 }, +    {4517,4517, 48, 0,    286,   133,-2 }, +    {4518,4518, 62, 0,    166,    60,0 }, +    {4519,4519, 44, 0,    980,   360,0 }, +    {4520,4520, 80, 0,    100,     0,0 }, +    {4519,4519, 50, 0,    980,   346,0 }, +    {4521,4521, 48, 0,    106,     0,-2 }, +    {4519,4519, 55, 0,    973,   360,0 }, +    {4522,4522, 61, 0,    513,    20,0 }, +    {4519,4519, 58, 0,    966,   353,0 }, +    {4519,4519, 63, 0,    973,   353,0 }, +    {4523,4523, 71, 0,   1366,   580,0 }, +    {4519,4519, 72, 0,    820,   306,0 }, +    {4524,4524, 70, 0,   1886,   666,0 }, +    {4523,4523, 88, 0,   1353,   560,0 }, +    {4525,4525, 76, 0,   1873,   653,0 }, +    {4526,4526, 84, 0,    260,   113,0 }, +    {4523,4523, 68, 0,   1366,   553,0 }, +    {4527,4527, 72, 0,    153,    53,0 }, +    {4528,4528, 28, 0,   1193,   413,0 }, +    {4524,4524, 81, 0,   1353,   480,0 }, +    {4529,4529, 58, 0,    246,   120,-2 }, +    {4529,4529, 55, 0,    246,   120,-2 }, +    {4529,4529, 44, 0,    246,   120,-2 }, +    {4529,4529, 49, 0,    246,   120,-2 }, +    {4529,4529, 40, 0,    286,   133,-2 }, +    {4530,4530, 55, 0,    740,   560,-2 }, +    {4530,4530, 48, 0,    893,   693,-2 }, +    {4531,4531, 52, 0,    513,   206,0 }, +    {4531,4531, 45, 0,    513,   206,0 }, +    {4532,4532, 48, 0,    173,   100,-2 }, +    {4533,4533, 48, 0,    120,   266,-2 }, +    {4534,4534, 48, 0,    253,    60,-2 }, +    {4509,4509, 73, 0,    160,    20,-2 }, +    {4509,4509, 68, 0,    160,    20,-2 }, +    {4509,4509, 63, 0,    193,    20,-2 }, +    {4535,4535,108, 0,    406,    26,0 }, +    {4536,4536,108, 0,    740,    26,0 },  }; @@ -10753,16 +10756,16 @@ const unsigned short banks[75][256] =  4579,4580,4581,4582,4583,4584,4585,4586,4587,4588,4589,4590,4591,4592,4593,4594,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,4595,4596,4597,4598,4599, -4600,4601,4602,4603,4604,4605,4345,4606,4346,4607,4608,4609,4610,4611,4349,4612, -4613,4614,4615,4616,4352,4617,4618,4354,4619,4620,4621,4622,4623,4624,4625,4626, -4627,4628,4629,4630,4631, 320,4632,4633,4634,4635,4636,4637,4638,1374,4639,4640, -4641,4642,4643,4644,4645,4646,4647,4648, 295, 295, 295, 295, 295, 295, 295, 295, +4600,4601,4602,4603,4604,4605,4606,4607,4346,4608,4609,4610,4611,4612,4349,4613, +4614,4615,4616,4617,4352,4618,4619,4354,4620,4621,4622,4623,4624,4625,4626,4627, +4628,4629,4630,4631,4632, 320,4633,4634,4635,4636,4637,4638,4639,1374,4640,4641, +4642,4643,4644,4645,4646,4647,4648,4649, 295, 295, 295, 295, 295, 295, 295, 295,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,      },      { -4649,4650,4651,4652,4650,4653,4654,4655,4656,4657,4658,4660,4661,4662,4663,4664, -4665,4667,4669,4662,4671,4672,4673,4674,4675,4676,4677, 295,  28,  29,  30,  31, +4650,4651,4652,4653,4651,4654,4655,4656,4657,4658,4659,4661,4662,4663,4664,4665, +4666,4668,4670,4663,4672,4673,4674,4675,4676,4677,4678, 295,  28,  29,  30,  31,    32,  33,  34,  35,  36,  37,  38,  33,  39,  40,  41,  42,  43,  44,  45,  46,    47,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,    63,  64,  65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,  78, @@ -10771,28 +10774,28 @@ const unsigned short banks[75][256] =   111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, - 295, 295, 295, 127,4666, 128,4668, 130, 131, 132,4670, 134, 135, 136, 137, 138, - 139, 140, 141, 142, 143, 144,4659, 146, 147, 148, 149, 150, 151, 152, 153, 154, + 295, 295, 295, 127,4667, 128,4669, 130, 131, 132,4671, 134, 135, 136, 137, 138, + 139, 140, 141, 142, 143, 144,4660, 146, 147, 148, 149, 150, 151, 152, 153, 154,   155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,      },      { -4679,4680,4681,4682,4683,4684,4685,4686,4687,4688,4689,4690,4691,3423,4688,4692, -3426,4693,4694,3426,4695,4696,4696,4696, 868, 869, 870,4697,4698,4699,4700,4701, -4702,4703,4704,4704,4705,4702,4706,4707,3970,4708,4709,4709,4710,4711,4712,4713, -4714,4715,4716,4716,4717,4224,3450,4718,4719,4720,4721,4722,4723,4719,4719,4724, -3457, 769,3458,3459,4725,4726,4727,4728,4729,4730,4731,4732,4733,4730,1300,4734, -4735,4736,4730,4695,4737,4719,4738,4739,3475,4740,4741,4742,4743,1314,4744,4745, -4746,4747,4748,4741,4741,1322,4749,4750,4751,4752,4753,4752,3423,4754,3970,4755, -4756,1334,4756,4757,4758,4759, 792,4760,1341,1342,1343,1344,4761,4762,4763,1348, - 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, - 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, - 295, 295, 295,4764,4764,4765,4766,4765,4767,4768,4769,4770,4771,4772,4773,4774, -4775,4776,4777,4778,4779,4780,4781,4782,4783,4776,4784,4785,4786,4787,4788,4789, -4790,4791,4792,4793,4794,4795,4796,4793,4794,4795,4797,4798,4799,4800,1375, 295, -4801,4802, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, +4680,4681,4682,4683,4684,4685,4686,4687,4688,4689,4690,4691,4692,3423,4689,4693, +3426,4694,4695,3426,4696,4697,4697,4697, 868, 869, 870,4698,4699,4700,4701,4702, +4703,4704,4705,4705,4706,4703,4707,4708,3970,4709,4710,4710,4711,4712,4713,4714, +4715,4716,4717,4717,4718,4224,3450,4719,4720,4721,4722,4723,4724,4720,4720,4725, +3457, 769,3458,3459,4726,4727,4728,4729,4730,4731,4732,4733,4734,4731,1300,4735, +4736,4737,4731,4696,4738,4720,4739,4740,3475,4741,4742,4743,4744,1314,4745,4746, +4747,4748,4749,4742,4742,1322,4750,4751,4752,4753,4754,4753,3423,4755,3970,4756, +4757,1334,4757,4758,4759,4760, 792,4761,1341,1342,1343,1344,4762,4763,4764,1348, + 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, + 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, + 295, 295, 295,4765,4765,4766,4767,4766,4768,4769,4770,4771,4772,4773,4774,4775, +4776,4777,4778,4779,4780,4781,4782,4783,4784,4777,4785,4786,4787,4788,4789,4790, +4791,4792,4793,4794,4795,4796,4797,4794,4795,4796,4798,4799,4800,4801,1375, 295, +4802,4803, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,   295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295,      }, diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index a0c7d8a..9210b5b 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -511,11 +511,28 @@ ADLMIDI_EXPORT int adl_switchEmulator(struct ADL_MIDIPlayer *device, int emulato              adl_reset(device);              return 0;          } -        play->setErrorString("OPN2 MIDI: Unknown emulation core!"); +        play->setErrorString("OPL3 MIDI: Unknown emulation core!");      }      return -1;  } + +ADLMIDI_EXPORT int adl_setRunAtPcmRate(ADL_MIDIPlayer *device, int enabled) +{ +    if(device) +    { +        MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer); +        if(play) +        { +            play->m_setup.runAtPcmRate = (enabled != 0); +            adl_reset(device); +            return 0; +        } +    } +    return -1; +} + +  ADLMIDI_EXPORT const char *adl_linkedLibraryVersion()  {  #if !defined(ADLMIDI_ENABLE_HQ_RESAMPLER) @@ -574,7 +591,8 @@ ADLMIDI_EXPORT void adl_reset(struct ADL_MIDIPlayer *device)          return;      MIDIplay *play = reinterpret_cast<MIDIplay *>(device->adl_midiPlayer);      play->m_setup.tick_skip_samples_delay = 0; -    play->opl.Reset(play->m_setup.emulator, play->m_setup.PCM_RATE); +    play->opl.runAtPcmRate = play->m_setup.runAtPcmRate; +    play->opl.Reset(play->m_setup.emulator, play->m_setup.PCM_RATE, play);      play->ch.clear();      play->ch.resize((size_t)play->opl.NumChannels);  } diff --git a/src/adlmidi_load.cpp b/src/adlmidi_load.cpp index 9e19ab6..7f69e25 100644 --- a/src/adlmidi_load.cpp +++ b/src/adlmidi_load.cpp @@ -714,7 +714,7 @@ riffskip:          return false;      } -    opl.Reset(m_setup.emulator, m_setup.PCM_RATE); // Reset OPL3 chip +    opl.Reset(m_setup.emulator, m_setup.PCM_RATE, this); // Reset OPL3 chip      //opl.Reset(); // ...twice (just in case someone misprogrammed OPL3 previously)      ch.clear();      ch.resize(opl.NumChannels); diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp index 0623ce7..89c1a73 100644 --- a/src/adlmidi_midiplay.cpp +++ b/src/adlmidi_midiplay.cpp @@ -680,7 +680,8 @@ bool MIDIplay::buildTrackData()  MIDIplay::MIDIplay(unsigned long sampleRate):      cmf_percussion_mode(false), -    m_arpeggioCounter(0) +    m_arpeggioCounter(0), +    m_audioTickCounter(0)  #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER      , fullSongTimeLength(0.0),      postSongWaitDelay(1.0), @@ -696,6 +697,7 @@ MIDIplay::MIDIplay(unsigned long sampleRate):      devices.clear();      m_setup.emulator = ADLMIDI_EMU_NUKED; +    m_setup.runAtPcmRate = false;      m_setup.PCM_RATE   = sampleRate;      m_setup.mindelay = 1.0 / (double)m_setup.PCM_RATE; @@ -726,6 +728,8 @@ void MIDIplay::applySetup()  {      m_setup.tick_skip_samples_delay = 0; +    opl.runAtPcmRate = m_setup.runAtPcmRate; +      if(opl.AdlBank != ~0u)          opl.dynamic_bank_setup = adlbanksetup[m_setup.AdlBank]; @@ -752,7 +756,7 @@ void MIDIplay::applySetup()      opl.NumFourOps  = m_setup.NumFourOps;      cmf_percussion_mode = false; -    opl.Reset(m_setup.emulator, m_setup.PCM_RATE); +    opl.Reset(m_setup.emulator, m_setup.PCM_RATE, this);      ch.clear();      ch.resize(opl.NumChannels); @@ -1435,6 +1439,13 @@ void MIDIplay::realTime_panic()      KillSustainingNotes(-1, -1);  } +void MIDIplay::AudioTick(uint32_t chipId, uint32_t /*rate*/) +{ +    if(chipId != 0)  // do first chip ticks only +        return; + +    /*uint32_t tickNumber = */m_audioTickCounter++; +}  void MIDIplay::NoteUpdate(uint16_t MidCh,                            MIDIplay::MIDIchannel::activenoteiterator i, diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp index 16a481d..49e2e76 100644 --- a/src/adlmidi_opl3.cpp +++ b/src/adlmidi_opl3.cpp @@ -484,20 +484,24 @@ void OPL3::ClearChips()  }  #endif -void OPL3::Reset(int emulator, unsigned long PCM_RATE) +void OPL3::Reset(int emulator, unsigned long PCM_RATE, void *audioTickHandler)  { -    #ifndef ADLMIDI_HW_OPL +#ifndef ADLMIDI_HW_OPL      ClearChips(); -    #endif +#else      (void)emulator;      (void)PCM_RATE; +#endif +#if !defined(ADLMIDI_AUDIO_TICK_HANDLER) +    (void)audioTickHandler; +#endif      ins.clear();      pit.clear();      regBD.clear(); -    #ifndef ADLMIDI_HW_OPL +#ifndef ADLMIDI_HW_OPL      cardsOP2.resize(NumCards, AdlMIDI_SPtr<OPLChipBase>()); -    #endif +#endif      NumChannels = NumCards * 23;      ins.resize(NumChannels, adl[adlDefaultNumber]); @@ -522,24 +526,32 @@ void OPL3::Reset(int emulator, unsigned long PCM_RATE)      for(size_t i = 0; i < NumCards; ++i)      {  #ifndef ADLMIDI_HW_OPL +        OPLChipBase *chip;          switch(emulator)          {          default:  #ifndef ADLMIDI_DISABLE_NUKED_EMULATOR          case ADLMIDI_EMU_NUKED: /* Latest Nuked OPL3 */ -            cardsOP2[i].reset(new NukedOPL3()); +            chip = new NukedOPL3;              break;          case ADLMIDI_EMU_NUKED_174: /* Old Nuked OPL3 1.4.7 modified and optimized */ -            cardsOP2[i].reset(new NukedOPL3v174()); +            chip = new NukedOPL3v174;              break;  #endif  #ifndef ADLMIDI_DISABLE_DOSBOX_EMULATOR          case ADLMIDI_EMU_DOSBOX: -            cardsOP2[i].reset(new DosBoxOPL3()); +            chip = new DosBoxOPL3;              break;  #endif          } -        cardsOP2[i]->setRate((uint32_t)PCM_RATE); +        cardsOP2[i].reset(chip); +        chip->setChipId(i); +        chip->setRate((uint32_t)PCM_RATE); +        if(runAtPcmRate) +            chip->setRunningAtPcmRate(true); +#   if defined(ADLMIDI_AUDIO_TICK_HANDLER) +        chip->setAudioTickHandlerInstance(audioTickHandler); +#   endif  #endif // ADLMIDI_HW_OPL          for(unsigned a = 0; a < 18; ++a) Poke(i, 0xB0 + Channels[a], 0x00); diff --git a/src/adlmidi_private.cpp b/src/adlmidi_private.cpp index 77319d7..1ee7c4a 100644 --- a/src/adlmidi_private.cpp +++ b/src/adlmidi_private.cpp @@ -25,6 +25,13 @@  std::string ADLMIDI_ErrorString; +// Generator callback on audio rate ticks + +void adl_audioTickHandler(void *instance, uint32_t chipId, uint32_t rate) +{ +    reinterpret_cast<MIDIplay *>(instance)->AudioTick(chipId, rate); +} +  int adlRefreshNumCards(ADL_MIDIPlayer *device)  {      unsigned n_fourop[2] = {0, 0}, n_total[2] = {0, 0}; diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index 2499bad..0e63b5a 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -245,6 +245,8 @@ public:      bool AdlPercussionMode;      //! Carriers-only are scaled by default by volume level. This flag will tell to scale modulators too.      bool ScaleModulators; +    //! Run emulator at PCM rate if that possible. Reduces sounding accuracy, but decreases CPU usage on lower rates. +    bool runAtPcmRate;      // ! Required to play CMF files. Can be turned on by using of "CMF" volume model      //bool LogarithmicVolumes; //[REPLACED WITH "m_volumeScale == VOLUME_NATIVE", DEPRECATED!!!]      // ! Required to play EA-MUS files [REPLACED WITH "m_musicMode", DEPRECATED!!!] @@ -294,7 +296,7 @@ public:      #ifndef ADLMIDI_HW_OPL      void ClearChips();      #endif -    void Reset(int emulator, unsigned long PCM_RATE); +    void Reset(int emulator, unsigned long PCM_RATE, void *audioTickHandler);  }; @@ -933,6 +935,7 @@ public:      struct Setup      {          int          emulator; +        bool         runAtPcmRate;          unsigned int AdlBank;          unsigned int NumFourOps;          unsigned int NumCards; @@ -984,6 +987,9 @@ private:      //! Counter of arpeggio processing      size_t m_arpeggioCounter; +    //! Audio tick counter +    uint32_t m_audioTickCounter; +  #ifndef ADLMIDI_DISABLE_MIDI_SEQUENCER      std::vector<std::vector<uint8_t> > TrackData; @@ -1181,6 +1187,9 @@ public:      void realTime_panic(); +    // Audio rate tick handler +    void AudioTick(uint32_t chipId, uint32_t rate); +  private:      enum      { @@ -1249,6 +1258,7 @@ struct FourChars  };  */ +extern void adl_audioTickHandler(void *instance, uint32_t chipId, uint32_t rate);  extern int adlRefreshNumCards(ADL_MIDIPlayer *device); diff --git a/src/chips/dosbox_opl3.cpp b/src/chips/dosbox_opl3.cpp index af4cb08..30fa38e 100644 --- a/src/chips/dosbox_opl3.cpp +++ b/src/chips/dosbox_opl3.cpp @@ -23,7 +23,7 @@ void DosBoxOPL3::setRate(uint32_t rate)      DBOPL::Handler *chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);      chip_r->~Handler();      new(chip_r) DBOPL::Handler; -    chip_r->Init(49716); +    chip_r->Init(effectiveRate());  }  void DosBoxOPL3::reset() @@ -32,7 +32,7 @@ void DosBoxOPL3::reset()      DBOPL::Handler *chip_r = reinterpret_cast<DBOPL::Handler*>(m_chip);      chip_r->~Handler();      new(chip_r) DBOPL::Handler; -    chip_r->Init(49716); +    chip_r->Init(effectiveRate());  }  void DosBoxOPL3::writeReg(uint16_t addr, uint8_t data) diff --git a/src/chips/dosbox_opl3.h b/src/chips/dosbox_opl3.h index f4c68da..1928026 100644 --- a/src/chips/dosbox_opl3.h +++ b/src/chips/dosbox_opl3.h @@ -10,6 +10,7 @@ public:      DosBoxOPL3();      ~DosBoxOPL3() override; +    bool canRunAtPcmRate() const override { return true; }      void setRate(uint32_t rate) override;      void reset() override;      void writeReg(uint16_t addr, uint8_t data) override; diff --git a/src/chips/nuked_opl3.h b/src/chips/nuked_opl3.h index 25d9ed5..1b34e9a 100644 --- a/src/chips/nuked_opl3.h +++ b/src/chips/nuked_opl3.h @@ -10,6 +10,7 @@ public:      NukedOPL3();      ~NukedOPL3() override; +    bool canRunAtPcmRate() const override { return false; }      void setRate(uint32_t rate) override;      void reset() override;      void writeReg(uint16_t addr, uint8_t data) override; diff --git a/src/chips/nuked_opl3_v174.h b/src/chips/nuked_opl3_v174.h index b9c5ba6..f14221f 100644 --- a/src/chips/nuked_opl3_v174.h +++ b/src/chips/nuked_opl3_v174.h @@ -10,6 +10,7 @@ public:      NukedOPL3v174();      ~NukedOPL3v174() override; +    bool canRunAtPcmRate() const override { return false; }      void setRate(uint32_t rate) override;      void reset() override;      void writeReg(uint16_t addr, uint8_t data) override; diff --git a/src/chips/opl_chip_base.h b/src/chips/opl_chip_base.h index 5721a81..879d6da 100644 --- a/src/chips/opl_chip_base.h +++ b/src/chips/opl_chip_base.h @@ -13,15 +13,33 @@  class VResampler;  #endif +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) +extern void adl_audioTickHandler(void *instance, uint32_t chipId, uint32_t rate); +#endif +  class OPLChipBase  { +public: +    enum { nativeRate = 49716 };  protected: +    uint32_t m_id;      uint32_t m_rate;  public:      OPLChipBase();      virtual ~OPLChipBase(); +    uint32_t chipId() const { return m_id; } +    void setChipId(uint32_t id) { m_id = id; } + +    virtual bool canRunAtPcmRate() const = 0; +    virtual bool isRunningAtPcmRate() const = 0; +    virtual bool setRunningAtPcmRate(bool r) = 0; +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) +    virtual void setAudioTickHandlerInstance(void *instance) = 0; +#endif +      virtual void setRate(uint32_t rate) = 0; +    virtual uint32_t effectiveRate() const = 0;      virtual void reset() = 0;      virtual void writeReg(uint16_t addr, uint8_t data) = 0; @@ -49,13 +67,25 @@ public:      OPLChipBaseT();      virtual ~OPLChipBaseT(); +    bool isRunningAtPcmRate() const override; +    bool setRunningAtPcmRate(bool r) override; +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) +    void setAudioTickHandlerInstance(void *instance); +#endif +      virtual void setRate(uint32_t rate) override; +    uint32_t effectiveRate() const override;      virtual void reset() override;      void generate(int16_t *output, size_t frames) override;      void generateAndMix(int16_t *output, size_t frames) override;      void generate32(int32_t *output, size_t frames) override;      void generateAndMix32(int32_t *output, size_t frames) override;  private: +    bool m_runningAtPcmRate; +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) +    void *m_audioTickHandlerInstance; +#endif +    void nativeTick(int16_t *frame);      void setupResampler(uint32_t rate);      void resetResampler();      void resampledGenerate(int32_t *output); diff --git a/src/chips/opl_chip_base.tcc b/src/chips/opl_chip_base.tcc index 58145bc..48ad103 100644 --- a/src/chips/opl_chip_base.tcc +++ b/src/chips/opl_chip_base.tcc @@ -5,9 +5,22 @@  #include <zita-resampler/vresampler.h>  #endif +#if !defined(LIKELY) && defined(__GNUC__) +#define LIKELY(x) __builtin_expect((x), 1) +#elif !defined(LIKELY) +#define LIKELY(x) (x) +#endif + +#if !defined(UNLIKELY) && defined(__GNUC__) +#define UNLIKELY(x) __builtin_expect((x), 0) +#elif !defined(UNLIKELY) +#define UNLIKELY(x) (x) +#endif +  /* OPLChipBase */  inline OPLChipBase::OPLChipBase() : +    m_id(0),      m_rate(44100)  {  } @@ -20,7 +33,12 @@ inline OPLChipBase::~OPLChipBase()  template <class T>  OPLChipBaseT<T>::OPLChipBaseT() -    : OPLChipBase() +    : OPLChipBase(), +      m_runningAtPcmRate(false) +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) +    , +      m_audioTickHandlerInstance(NULL) +#endif  {  #if defined(ADLMIDI_ENABLE_HQ_RESAMPLER)      m_resampler = new VResampler; @@ -37,6 +55,33 @@ OPLChipBaseT<T>::~OPLChipBaseT()  }  template <class T> +bool OPLChipBaseT<T>::isRunningAtPcmRate() const +{ +    return m_runningAtPcmRate; +} + +template <class T> +bool OPLChipBaseT<T>::setRunningAtPcmRate(bool r) +{ +    if(r != m_runningAtPcmRate) +    { +        if(r && !static_cast<T *>(this)->canRunAtPcmRate()) +            return false; +        m_runningAtPcmRate = r; +        static_cast<T *>(this)->setRate(m_rate); +    } +    return true; +} + +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) +template <class T> +void OPLChipBaseT<T>::setAudioTickHandlerInstance(void *instance) +{ +    m_audioTickHandlerInstance = instance; +} +#endif + +template <class T>  void OPLChipBaseT<T>::setRate(uint32_t rate)  {      uint32_t oldRate = m_rate; @@ -48,6 +93,12 @@ void OPLChipBaseT<T>::setRate(uint32_t rate)  }  template <class T> +uint32_t OPLChipBaseT<T>::effectiveRate() const +{ +    return m_runningAtPcmRate ? m_rate : (uint32_t)nativeRate; +} + +template <class T>  void OPLChipBaseT<T>::reset()  {      resetResampler(); @@ -119,6 +170,15 @@ void OPLChipBaseT<T>::generateAndMix32(int32_t *output, size_t frames)  }  template <class T> +void OPLChipBaseT<T>::nativeTick(int16_t *frame) +{ +#if defined(ADLMIDI_AUDIO_TICK_HANDLER) +    adl_audioTickHandler(m_audioTickHandlerInstance, m_id, effectiveRate()); +#endif +    static_cast<T *>(this)->nativeGenerate(frame); +} + +template <class T>  void OPLChipBaseT<T>::setupResampler(uint32_t rate)  {  #if defined(ADLMIDI_ENABLE_HQ_RESAMPLER) @@ -147,6 +207,15 @@ void OPLChipBaseT<T>::resetResampler()  template <class T>  void OPLChipBaseT<T>::resampledGenerate(int32_t *output)  { +    if(UNLIKELY(m_runningAtPcmRate)) +    { +        int16_t in[2]; +        static_cast<T *>(this)->nativeTick(in); +        output[0] = (int32_t)in[0] * T::resamplerPreAmplify / T::resamplerPostAttenuate; +        output[1] = (int32_t)in[1] * T::resamplerPreAmplify / T::resamplerPostAttenuate; +        return; +    } +      VResampler *rsm = m_resampler;      float scale = (float)T::resamplerPreAmplify /          (float)T::resamplerPostAttenuate; @@ -159,7 +228,7 @@ void OPLChipBaseT<T>::resampledGenerate(int32_t *output)      while(rsm->process(), rsm->out_count != 0)      {          int16_t in[2]; -        static_cast<T *>(this)->nativeGenerate(in); +        static_cast<T *>(this)->nativeTick(in);          f_in[0] = scale * (float)in[0];          f_in[1] = scale * (float)in[1];          rsm->inp_count = 1; @@ -174,6 +243,15 @@ void OPLChipBaseT<T>::resampledGenerate(int32_t *output)  template <class T>  void OPLChipBaseT<T>::resampledGenerate(int32_t *output)  { +    if(UNLIKELY(m_runningAtPcmRate)) +    { +        int16_t in[2]; +        static_cast<T *>(this)->nativeTick(in); +        output[0] = (int32_t)in[0] * T::resamplerPreAmplify / T::resamplerPostAttenuate; +        output[1] = (int32_t)in[1] * T::resamplerPreAmplify / T::resamplerPostAttenuate; +        return; +    } +      int32_t samplecnt = m_samplecnt;      const int32_t rateratio = m_rateratio;      while(samplecnt >= rateratio) @@ -181,7 +259,7 @@ void OPLChipBaseT<T>::resampledGenerate(int32_t *output)          m_oldsamples[0] = m_samples[0];          m_oldsamples[1] = m_samples[1];          int16_t buffer[2]; -        static_cast<T *>(this)->nativeGenerate(buffer); +        static_cast<T *>(this)->nativeTick(buffer);          m_samples[0] = buffer[0] * T::resamplerPreAmplify;          m_samples[1] = buffer[1] * T::resamplerPreAmplify;          samplecnt -= rateratio;  |