aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/adldata.hh20
-rw-r--r--src/adlmidi.cpp2
-rw-r--r--src/adlmidi_load.cpp4
-rw-r--r--src/adlmidi_midiplay.cpp30
-rw-r--r--src/adlmidi_opl3.cpp33
-rw-r--r--src/adlmidi_private.hpp14
-rw-r--r--src/adlmidi_xmi2mid.c4
7 files changed, 73 insertions, 34 deletions
diff --git a/src/adldata.hh b/src/adldata.hh
index 8e15ff4..e9ff00b 100644
--- a/src/adldata.hh
+++ b/src/adldata.hh
@@ -24,24 +24,26 @@
#ifndef ADLDATA_H
#define ADLDATA_H
+#include <stdint.h>
+
extern const struct adldata
{
- unsigned int modulator_E862, carrier_E862; // See below
- unsigned char modulator_40, carrier_40; // KSL/attenuation settings
- unsigned char feedconn; // Feedback/connection bits for the channel
+ uint32_t modulator_E862, carrier_E862; // See below
+ uint8_t modulator_40, carrier_40; // KSL/attenuation settings
+ uint8_t feedconn; // Feedback/connection bits for the channel
- signed char finetune;
+ int8_t finetune;
} adl[];
extern const struct adlinsdata
{
enum { Flag_Pseudo4op = 0x01, Flag_NoSound = 0x02 };
- unsigned short adlno1, adlno2;
- unsigned char tone;
- unsigned char flags;
- unsigned short ms_sound_kon; // Number of milliseconds it produces sound;
- unsigned short ms_sound_koff;
+ uint16_t adlno1, adlno2;
+ uint8_t tone;
+ uint8_t flags;
+ uint16_t ms_sound_kon; // Number of milliseconds it produces sound;
+ uint16_t ms_sound_koff;
double voice2_fine_tune;
} adlins[];
int maxAdlBanks();
diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp
index 50163ac..f620b5e 100644
--- a/src/adlmidi.cpp
+++ b/src/adlmidi.cpp
@@ -471,7 +471,7 @@ ADLMIDI_EXPORT const Adl_MarkerEntry adl_metaMarker(struct ADL_MIDIPlayer *devic
MIDIplay::MIDI_MarkerEntry &mk = play->musMarkers[index];
marker.label = mk.label.c_str();
marker.pos_time = mk.pos_time;
- marker.pos_ticks = mk.pos_ticks;
+ marker.pos_ticks = (unsigned long)mk.pos_ticks;
}
return marker;
}
diff --git a/src/adlmidi_load.cpp b/src/adlmidi_load.cpp
index afe0610..4df4b32 100644
--- a/src/adlmidi_load.cpp
+++ b/src/adlmidi_load.cpp
@@ -58,7 +58,7 @@ bool MIDIplay::LoadBank(const std::string &filename)
bool MIDIplay::LoadBank(void *data, unsigned long size)
{
fileReader file;
- file.openData(data, size);
+ file.openData(data, (size_t)size);
return LoadBank(file);
}
@@ -339,7 +339,7 @@ bool MIDIplay::LoadMIDI(const std::string &filename)
bool MIDIplay::LoadMIDI(void *data, unsigned long size)
{
fileReader file;
- file.openData(data, size);
+ file.openData(data, (size_t)size);
return LoadMIDI(file);
}
diff --git a/src/adlmidi_midiplay.cpp b/src/adlmidi_midiplay.cpp
index 7b9a086..51da17e 100644
--- a/src/adlmidi_midiplay.cpp
+++ b/src/adlmidi_midiplay.cpp
@@ -175,6 +175,11 @@ void MIDIplay::MidiTrackRow::sortEvents(bool *noteStates)
EvtArr controllers;
EvtArr anyOther;
+ metas.reserve(events.size());
+ noteOffs.reserve(events.size());
+ controllers.reserve(events.size());
+ anyOther.reserve(events.size());
+
for(size_t i = 0; i < events.size(); i++)
{
if(events[i].type == MidiEvent::T_NOTEOFF)
@@ -340,6 +345,7 @@ bool MIDIplay::buildTrackData()
errorString += std::string(error, (size_t)len);
return false;
}
+
evtPos.events.push_back(event);
if(event.type == MidiEvent::T_SPECIAL)
{
@@ -433,7 +439,7 @@ bool MIDIplay::buildTrackData()
{
fraction<uint64_t> currentTempo = Tempo;
double time = 0.0;
- uint8_t abs_position = 0;
+ uint64_t abs_position = 0;
size_t tempo_change_index = 0;
MidiTrackQueue &track = trackDataNew[tk];
if(track.empty())
@@ -559,7 +565,6 @@ bool MIDIplay::buildTrackData()
//Initial loop position will begin at begin of track until passing of the loop point
LoopBeginPositionNew = CurrentPositionNew;
-
/********************************************************************************/
//Resolve "hell of all times" of too short drum notes:
//move too short percussion note-offs far far away as possible
@@ -655,7 +660,6 @@ bool MIDIplay::buildTrackData()
}
#endif
-
return true;
}
@@ -1049,7 +1053,7 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
int32_t c = -1;
int32_t bs = -0x7FFFFFFFl;
- for(uint32_t a = 0; a < opl.NumChannels; ++a)
+ for(size_t a = 0; a < (size_t)opl.NumChannels; ++a)
{
if(ccount == 1 && static_cast<int32_t>(a) == adlchannel[0]) continue;
// ^ Don't use the same channel for primary&secondary
@@ -1067,7 +1071,7 @@ bool MIDIplay::realTime_NoteOn(uint8_t channel, uint8_t note, uint8_t velocity)
expected_mode = PercussionMap[midiins & 0xFF];
}
- if(opl.four_op_category[a] != expected_mode)
+ if(opl.four_op_category[a] != (uint32_t)expected_mode)
continue;
}
else
@@ -1361,7 +1365,7 @@ void MIDIplay::NoteUpdate(uint16_t MidCh,
const int16_t tone = info.tone;
const uint8_t vol = info.vol;
const int midiins = info.midiins;
- const uint32_t insmeta = info.insmeta;
+ const size_t insmeta = info.insmeta;
const adlinsdata &ains = opl.GetAdlMetaIns(insmeta);
AdlChannel::Location my_loc;
my_loc.MidCh = MidCh;
@@ -1461,7 +1465,7 @@ void MIDIplay::NoteUpdate(uint16_t MidCh,
else
{
// The formula below: SOLVE(V=127^3 * 2^( (A-63.49999) / 8), A)
- volume = volume > 8725 ? static_cast<unsigned int>(std::log(volume) * 11.541561 + (0.5 - 104.22845)) : 0;
+ volume = volume > 8725 ? static_cast<unsigned int>(std::log((double)volume) * 11.541561 + (0.5 - 104.22845)) : 0;
// The incorrect formula below: SOLVE(V=127^3 * (2^(A/63)-1), A)
//opl.Touch_Real(c, volume>11210 ? 91.61112 * std::log(4.8819E-7*volume + 1.0)+0.5 : 0);
}
@@ -2033,7 +2037,7 @@ void MIDIplay::HandleEvent(size_t tk, const MIDIplay::MidiEvent &evt, int &statu
}
}
-long MIDIplay::CalculateAdlChannelGoodness(unsigned c, const MIDIchannel::NoteInfo::Phys &ins, uint16_t) const
+long MIDIplay::CalculateAdlChannelGoodness(unsigned c, const MIDIchannel::NoteInfo::Phys &ins, uint16_t)
{
long s = -ch[c].koff_time_until_neglible;
@@ -2453,12 +2457,12 @@ ADLMIDI_EXPORT void AdlInstrumentTester::FindAdlList()
ADLMIDI_EXPORT void AdlInstrumentTester::Touch(unsigned c, unsigned volume) // Volume maxes at 127*127*127
{
- if(opl->LogarithmicVolumes)// !!!ADL PRIVATE!!!
- opl->Touch_Real(c, volume * 127 / (127 * 127 * 127) / 2);// !!!ADL PRIVATE!!!
+ if(opl->LogarithmicVolumes)
+ opl->Touch_Real(c, volume * 127 / (127 * 127 * 127) / 2);
else
{
// The formula below: SOLVE(V=127^3 * 2^( (A-63.49999) / 8), A)
- opl->Touch_Real(c, volume > 8725 ? static_cast<unsigned int>(std::log(volume) * 11.541561 + (0.5 - 104.22845)) : 0);// !!!ADL PRIVATE!!!
+ opl->Touch_Real(c, volume > 8725 ? static_cast<unsigned int>(std::log((double)volume) * 11.541561 + (0.5 - 104.22845)) : 0);
// The incorrect formula below: SOLVE(V=127^3 * (2^(A/63)-1), A)
//Touch_Real(c, volume>11210 ? 91.61112 * std::log(4.8819E-7*volume + 1.0)+0.5 : 0);
}
@@ -2468,7 +2472,7 @@ ADLMIDI_EXPORT void AdlInstrumentTester::DoNote(int note)
{
if(adl_ins_list.empty()) FindAdlList();
const unsigned meta = adl_ins_list[ins_idx];
- const adlinsdata &ains = opl->GetAdlMetaIns(meta);// !!!ADL PRIVATE!!!
+ const adlinsdata &ains = opl->GetAdlMetaIns(meta);
int tone = (cur_gm & 128) ? (cur_gm & 127) : (note + 50);
if(ains.tone)
@@ -2602,7 +2606,7 @@ ADLMIDI_EXPORT bool AdlInstrumentTester::HandleInputChar(char ch)
#endif
return false;
default:
- const char *p = strchr(notes, ch);
+ const char *p = std::strchr(notes, ch);
if(p && *p)
DoNote((int)(p - notes) - 12);
}
diff --git a/src/adlmidi_opl3.cpp b/src/adlmidi_opl3.cpp
index 9db3803..f46d0ca 100644
--- a/src/adlmidi_opl3.cpp
+++ b/src/adlmidi_opl3.cpp
@@ -165,30 +165,56 @@ OPL3::OPL3() :
void OPL3::Poke(size_t card, uint32_t index, uint32_t value)
{
#ifdef ADLMIDI_HW_OPL
+ (void)card;
unsigned o = index >> 8;
unsigned port = OPLBase + o * 2;
+
+ #ifdef __DJGPP__
outportb(port, index);
for(unsigned c = 0; c < 6; ++c) inportb(port);
outportb(port + 1, value);
for(unsigned c = 0; c < 35; ++c) inportb(port);
- #else
+ #endif//__DJGPP__
+
+ #ifdef __WATCOMC__
+ outp(port, index);
+ for(uint16_t c = 0; c < 6; ++c) inp(port);
+ outp(port + 1, value);
+ for(uint16_t c = 0; c < 35; ++c) inp(port);
+ #endif//__WATCOMC__
+
+ #else//ADLMIDI_HW_OPL
+
#ifdef ADLMIDI_USE_DOSBOX_OPL
cards[card].WriteReg(index, static_cast<uint8_t>(value));
#else
OPL3_WriteReg(&cards[card], static_cast<Bit16u>(index), static_cast<Bit8u>(value));
#endif
- #endif
+
+ #endif//ADLMIDI_HW_OPL
}
void OPL3::PokeN(size_t card, uint16_t index, uint8_t value)
{
#ifdef ADLMIDI_HW_OPL
+ (void)card;
unsigned o = index >> 8;
unsigned port = OPLBase + o * 2;
+
+ #ifdef __DJGPP__
outportb(port, index);
for(unsigned c = 0; c < 6; ++c) inportb(port);
outportb(port + 1, value);
for(unsigned c = 0; c < 35; ++c) inportb(port);
+ #endif
+
+ #ifdef __WATCOMC__
+ outp(port, index);
+ for(uint16_t c = 0; c < 6; ++c) inp(port);
+ outp(port + 1, value);
+ for(uint16_t c = 0; c < 35; ++c) inp(port);
+ #endif//__WATCOMC__
+
#else
#ifdef ADLMIDI_USE_DOSBOX_OPL
cards[card].WriteReg(static_cast<Bit32u>(index), value);
@@ -452,15 +478,16 @@ void OPL3::ChangeVolumeRangesModel(ADLMIDI_VolumeModels volumeModel)
void OPL3::Reset(unsigned long PCM_RATE)
{
+ #ifndef ADLMIDI_HW_OPL
#ifdef ADLMIDI_USE_DOSBOX_OPL
DBOPL::Handler emptyChip; //Constructors inside are will initialize necessary fields
#else
_opl3_chip emptyChip;
std::memset(&emptyChip, 0, sizeof(_opl3_chip));
#endif
- #ifndef ADLMIDI_HW_OPL
cards.clear();
#endif
+ (void)PCM_RATE;
ins.clear();
pit.clear();
regBD.clear();
diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp
index c860a88..408fede 100644
--- a/src/adlmidi_private.hpp
+++ b/src/adlmidi_private.hpp
@@ -53,9 +53,10 @@ typedef __int32 ssize_t;
# include <windows.h>
#endif
-#ifdef __DJGPP__
+#if defined(__DJGPP__) || (defined(__WATCOMC__) && (defined(__DOS__) || defined(__DOS4G__) || defined(__DOS4GNZ__)))
#define ADLMIDI_HW_OPL
#include <conio.h>
+#ifdef __DJGPP__
#include <pc.h>
#include <dpmi.h>
#include <go32.h>
@@ -63,6 +64,8 @@ typedef __int32 ssize_t;
#include <dos.h>
#endif
+#endif
+
#include <vector>
#include <list>
#include <string>
@@ -72,6 +75,7 @@ typedef __int32 ssize_t;
#include <cstdlib>
#include <cstring>
#include <cmath>
+#include <cstdarg>
#include <cstdio>
#include <vector> // vector
#include <deque> // deque
@@ -89,11 +93,13 @@ typedef __int32 ssize_t;
#include "fraction.hpp"
+#ifndef ADLMIDI_HW_OPL
#ifdef ADLMIDI_USE_DOSBOX_OPL
#include "dbopl.h"
#else
#include "nukedopl3.h"
#endif
+#endif
#include "adldata.hh"
#include "adlmidi.h" //Main API
@@ -529,7 +535,7 @@ public:
users_t users;
// If the channel is keyoff'd
- long koff_time_until_neglible;
+ int64_t koff_time_until_neglible;
// For channel allocation:
AdlChannel(): users(), koff_time_until_neglible(0) { }
void AddAge(int64_t ms);
@@ -695,7 +701,7 @@ public:
{
std::string label;
double pos_time;
- unsigned long pos_ticks;
+ uint64_t pos_ticks;
};
std::vector<MIDIchannel> Ch;
@@ -893,7 +899,7 @@ private:
// Determine how good a candidate this adlchannel
// would be for playing a note from this instrument.
- long CalculateAdlChannelGoodness(unsigned c, const MIDIchannel::NoteInfo::Phys &ins, uint16_t /*MidCh*/) const;
+ long CalculateAdlChannelGoodness(unsigned c, const MIDIchannel::NoteInfo::Phys &ins, uint16_t /*MidCh*/);
// A new note will be played on this channel using this instrument.
// Kill existing notes on this channel (or don't, if we do arpeggio)
diff --git a/src/adlmidi_xmi2mid.c b/src/adlmidi_xmi2mid.c
index 4fae2a2..896b3d9 100644
--- a/src/adlmidi_xmi2mid.c
+++ b/src/adlmidi_xmi2mid.c
@@ -98,7 +98,7 @@ static uint32_t read2(struct xmi_ctx *ctx)
uint8_t b0, b1;
b0 = *ctx->src_ptr++;
b1 = *ctx->src_ptr++;
- return (b0 + (b1 << 8));
+ return (b0 + ((uint32_t)b1 << 8));
}
static uint32_t read4(struct xmi_ctx *ctx)
@@ -108,7 +108,7 @@ static uint32_t read4(struct xmi_ctx *ctx)
b2 = *ctx->src_ptr++;
b1 = *ctx->src_ptr++;
b0 = *ctx->src_ptr++;
- return (b0 + (b1<<8) + (b2<<16) + (b3<<24));
+ return (b0 + ((uint32_t)b1<<8) + ((uint32_t)b2<<16) + ((uint32_t)b3<<24));
}
static void copy(struct xmi_ctx *ctx, char *b, uint32_t len)