1
0

Sndfile.h 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  1. /*
  2. * Sndfile.h
  3. * ---------
  4. * Purpose: Core class of the playback engine. Every song is represented by a CSoundFile object.
  5. * Notes : (currently none)
  6. * Authors: Olivier Lapicque
  7. * OpenMPT Devs
  8. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  9. */
  10. #pragma once
  11. #include "openmpt/all/BuildSettings.hpp"
  12. #include "SoundFilePlayConfig.h"
  13. #include "MixerSettings.h"
  14. #include "../common/misc_util.h"
  15. #include "../common/mptRandom.h"
  16. #include "../common/version.h"
  17. #include <vector>
  18. #include <bitset>
  19. #include <set>
  20. #include "Snd_defs.h"
  21. #include "tuningbase.h"
  22. #include "MIDIMacros.h"
  23. #ifdef MODPLUG_TRACKER
  24. #include "../mptrack/MIDIMapping.h"
  25. #endif // MODPLUG_TRACKER
  26. #include "Mixer.h"
  27. #include "Resampler.h"
  28. #ifndef NO_REVERB
  29. #include "../sounddsp/Reverb.h"
  30. #endif
  31. #ifndef NO_AGC
  32. #include "../sounddsp/AGC.h"
  33. #endif
  34. #ifndef NO_DSP
  35. #include "../sounddsp/DSP.h"
  36. #endif
  37. #ifndef NO_EQ
  38. #include "../sounddsp/EQ.h"
  39. #endif
  40. #include "modcommand.h"
  41. #include "ModSample.h"
  42. #include "ModInstrument.h"
  43. #include "ModChannel.h"
  44. #include "plugins/PluginStructs.h"
  45. #include "RowVisitor.h"
  46. #include "Message.h"
  47. #include "pattern.h"
  48. #include "patternContainer.h"
  49. #include "ModSequence.h"
  50. #include "mpt/audio/span.hpp"
  51. #include "../common/FileReaderFwd.h"
  52. OPENMPT_NAMESPACE_BEGIN
  53. bool SettingCacheCompleteFileBeforeLoading();
  54. // -----------------------------------------------------------------------------
  55. // MODULAR ModInstrument FIELD ACCESS : body content in InstrumentExtensions.cpp
  56. // -----------------------------------------------------------------------------
  57. #ifndef MODPLUG_NO_FILESAVE
  58. void WriteInstrumentHeaderStructOrField(ModInstrument * input, std::ostream &file, uint32 only_this_code = -1 /* -1 for all */, uint16 fixedsize = 0);
  59. #endif // !MODPLUG_NO_FILESAVE
  60. bool ReadInstrumentHeaderField(ModInstrument * input, uint32 fcode, uint16 fsize, FileReader &file);
  61. // --------------------------------------------------------------------------------------------
  62. // --------------------------------------------------------------------------------------------
  63. // Sample decompression routines in format-specific source files
  64. void AMSUnpack(const int8 * const source, size_t sourceSize, void * const dest, const size_t destSize, char packCharacter);
  65. uintptr_t DMFUnpack(FileReader &file, uint8 *psample, uint32 maxlen);
  66. #ifdef LIBOPENMPT_BUILD
  67. #ifndef NO_PLUGINS
  68. class CVstPluginManager;
  69. #endif
  70. #endif
  71. using PlayBehaviourSet = std::bitset<kMaxPlayBehaviours>;
  72. #ifdef MODPLUG_TRACKER
  73. // For WAV export (writing pattern positions to file)
  74. struct PatternCuePoint
  75. {
  76. uint64 offset; // offset in the file (in samples)
  77. ORDERINDEX order; // which order is this?
  78. bool processed; // has this point been processed by the main WAV render function yet?
  79. };
  80. #endif // MODPLUG_TRACKER
  81. // Return values for GetLength()
  82. struct GetLengthType
  83. {
  84. double duration = 0.0; // Total time in seconds
  85. ROWINDEX lastRow = ROWINDEX_INVALID; // Last parsed row (if no target is specified, this is the first row that is parsed twice, i.e. not the *last* played order)
  86. ROWINDEX endRow = ROWINDEX_INVALID; // Last row before module loops (UNDEFINED if a target is specified)
  87. ROWINDEX startRow = 0; // First row of parsed subsong
  88. ORDERINDEX lastOrder = ORDERINDEX_INVALID; // Last parsed order (see lastRow remark)
  89. ORDERINDEX endOrder = ORDERINDEX_INVALID; // Last order before module loops (UNDEFINED if a target is specified)
  90. ORDERINDEX startOrder = 0; // First order of parsed subsong
  91. bool targetReached = false; // True if the specified order/row combination or duration has been reached while going through the module
  92. };
  93. struct SubSong
  94. {
  95. double duration;
  96. ROWINDEX startRow, endRow, loopStartRow;
  97. ORDERINDEX startOrder, endOrder, loopStartOrder;
  98. SEQUENCEINDEX sequence;
  99. };
  100. // Target seek mode for GetLength()
  101. struct GetLengthTarget
  102. {
  103. ROWINDEX startRow;
  104. ORDERINDEX startOrder;
  105. SEQUENCEINDEX sequence;
  106. struct pos_type
  107. {
  108. ROWINDEX row;
  109. ORDERINDEX order;
  110. };
  111. union
  112. {
  113. double time;
  114. pos_type pos;
  115. };
  116. enum Mode
  117. {
  118. NoTarget, // Don't seek, i.e. return complete length of the first subsong.
  119. GetAllSubsongs, // Same as NoTarget (i.e. get complete length), but returns the length of all sub songs
  120. SeekPosition, // Seek to given pattern position.
  121. SeekSeconds, // Seek to given time.
  122. } mode;
  123. // Don't seek, i.e. return complete module length.
  124. GetLengthTarget(bool allSongs = false)
  125. {
  126. mode = allSongs ? GetAllSubsongs : NoTarget;
  127. sequence = SEQUENCEINDEX_INVALID;
  128. startOrder = 0;
  129. startRow = 0;
  130. }
  131. // Seek to given pattern position if position is valid.
  132. GetLengthTarget(ORDERINDEX order, ROWINDEX row)
  133. {
  134. mode = NoTarget;
  135. sequence = SEQUENCEINDEX_INVALID;
  136. startOrder = 0;
  137. startRow = 0;
  138. if(order != ORDERINDEX_INVALID && row != ROWINDEX_INVALID)
  139. {
  140. mode = SeekPosition;
  141. pos.row = row;
  142. pos.order = order;
  143. }
  144. }
  145. // Seek to given time if t is valid (i.e. not negative).
  146. GetLengthTarget(double t)
  147. {
  148. mode = NoTarget;
  149. sequence = SEQUENCEINDEX_INVALID;
  150. startOrder = 0;
  151. startRow = 0;
  152. if(t >= 0.0)
  153. {
  154. mode = SeekSeconds;
  155. time = t;
  156. }
  157. }
  158. // Set start position from which seeking should begin.
  159. GetLengthTarget &StartPos(SEQUENCEINDEX seq, ORDERINDEX order, ROWINDEX row)
  160. {
  161. sequence = seq;
  162. startOrder = order;
  163. startRow = row;
  164. return *this;
  165. }
  166. };
  167. // Reset mode for GetLength()
  168. enum enmGetLengthResetMode
  169. {
  170. // Never adjust global variables / mod parameters
  171. eNoAdjust = 0x00,
  172. // Mod parameters (such as global volume, speed, tempo, etc...) will always be memorized if the target was reached (i.e. they won't be reset to the previous values). If target couldn't be reached, they are reset to their default values.
  173. eAdjust = 0x01,
  174. // Same as above, but global variables will only be memorized if the target could be reached. This does *NOT* influence the visited rows vector - it will *ALWAYS* be adjusted in this mode.
  175. eAdjustOnSuccess = 0x02 | eAdjust,
  176. // Same as previous option, but will also try to emulate sample playback so that voices from previous patterns will sound when continuing playback at the target position.
  177. eAdjustSamplePositions = 0x04 | eAdjustOnSuccess,
  178. // Only adjust the visited rows state
  179. eAdjustOnlyVisitedRows = 0x08,
  180. };
  181. // Delete samples assigned to instrument
  182. enum deleteInstrumentSamples
  183. {
  184. deleteAssociatedSamples,
  185. doNoDeleteAssociatedSamples,
  186. };
  187. namespace Tuning {
  188. class CTuningCollection;
  189. } // namespace Tuning
  190. using CTuningCollection = Tuning::CTuningCollection;
  191. struct CModSpecifications;
  192. class OPL;
  193. class CModDoc;
  194. /////////////////////////////////////////////////////////////////////////
  195. // File edit history
  196. #define HISTORY_TIMER_PRECISION 18.2
  197. struct FileHistory
  198. {
  199. // Date when the file was loaded in the the tracker or created.
  200. tm loadDate = {};
  201. // Time the file was open in the editor, in 1/18.2th seconds (frequency of a standard DOS timer, to keep compatibility with Impulse Tracker easy).
  202. uint32 openTime = 0;
  203. // Return the date as a (possibly truncated if not enough precision is available) ISO 8601 formatted date.
  204. mpt::ustring AsISO8601() const;
  205. // Returns true if the date component is valid. Some formats only store edit time, not edit date.
  206. bool HasValidDate() const { return loadDate.tm_mday != 0; }
  207. };
  208. struct TimingInfo
  209. {
  210. double InputLatency = 0.0; // seconds
  211. double OutputLatency = 0.0; // seconds
  212. int64 StreamFrames = 0;
  213. uint64 SystemTimestamp = 0; // nanoseconds
  214. double Speed = 1.0;
  215. };
  216. enum class ModMessageHeuristicOrder
  217. {
  218. Instruments,
  219. Samples,
  220. InstrumentsSamples,
  221. SamplesInstruments,
  222. BothInstrumentsSamples,
  223. BothSamplesInstruments,
  224. Default = InstrumentsSamples,
  225. };
  226. struct ModFormatDetails
  227. {
  228. mpt::ustring formatName; // "FastTracker 2"
  229. mpt::ustring type; // "xm"
  230. mpt::ustring madeWithTracker; // "OpenMPT 1.28.01.00"
  231. mpt::ustring originalFormatName; // "FastTracker 2" in the case of converted formats like MO3 or GDM
  232. mpt::ustring originalType; // "xm" in the case of converted formats like MO3 or GDM
  233. mpt::Charset charset = mpt::Charset::UTF8;
  234. };
  235. class IAudioTarget
  236. {
  237. protected:
  238. virtual ~IAudioTarget() = default;
  239. public:
  240. virtual void Process(mpt::audio_span_interleaved<MixSampleInt> buffer) = 0;
  241. virtual void Process(mpt::audio_span_interleaved<MixSampleFloat> buffer) = 0;
  242. };
  243. class IAudioSource
  244. {
  245. public:
  246. virtual ~IAudioSource() = default;
  247. public:
  248. virtual void Process(mpt::audio_span_planar<MixSampleInt> buffer) = 0;
  249. virtual void Process(mpt::audio_span_planar<MixSampleFloat> buffer) = 0;
  250. };
  251. class IMonitorInput
  252. {
  253. public:
  254. virtual ~IMonitorInput() = default;
  255. public:
  256. virtual void Process(mpt::audio_span_planar<const MixSampleInt> buffer) = 0;
  257. virtual void Process(mpt::audio_span_planar<const MixSampleFloat> buffer) = 0;
  258. };
  259. class IMonitorOutput
  260. {
  261. public:
  262. virtual ~IMonitorOutput() = default;
  263. public:
  264. virtual void Process(mpt::audio_span_interleaved<const MixSampleInt> buffer) = 0;
  265. virtual void Process(mpt::audio_span_interleaved<const MixSampleFloat> buffer) = 0;
  266. };
  267. class AudioSourceNone
  268. : public IAudioSource
  269. {
  270. public:
  271. void Process(mpt::audio_span_planar<MixSampleInt> buffer) override
  272. {
  273. for(std::size_t channel = 0; channel < buffer.size_channels(); ++channel)
  274. {
  275. for(std::size_t frame = 0; frame < buffer.size_frames(); ++frame)
  276. {
  277. buffer(channel, frame) = 0;
  278. }
  279. }
  280. }
  281. void Process(mpt::audio_span_planar<MixSampleFloat> buffer) override
  282. {
  283. for(std::size_t channel = 0; channel < buffer.size_channels(); ++channel)
  284. {
  285. for(std::size_t frame = 0; frame < buffer.size_frames(); ++frame)
  286. {
  287. buffer(channel, frame) = MixSampleFloat(0.0);
  288. }
  289. }
  290. }
  291. };
  292. using NoteName = mpt::uchar[4];
  293. class CSoundFile
  294. {
  295. friend class GetLengthMemory;
  296. public:
  297. #ifdef MODPLUG_TRACKER
  298. void ChangeModTypeTo(const MODTYPE newType, bool adjust = true);
  299. #endif // MODPLUG_TRACKER
  300. // Returns value in seconds. If given position won't be played at all, returns -1.
  301. // If updateVars is true, the state of various playback variables will be updated according to the playback position.
  302. // If updateSamplePos is also true, the sample positions of samples still playing from previous patterns will be kept in sync.
  303. double GetPlaybackTimeAt(ORDERINDEX ord, ROWINDEX row, bool updateVars, bool updateSamplePos);
  304. std::vector<SubSong> GetAllSubSongs();
  305. //Tuning-->
  306. public:
  307. static std::unique_ptr<CTuning> CreateTuning12TET(const mpt::ustring &name);
  308. static CTuning *GetDefaultTuning() {return nullptr;}
  309. CTuningCollection& GetTuneSpecificTunings() {return *m_pTuningsTuneSpecific;}
  310. mpt::ustring GetNoteName(const ModCommand::NOTE note, const INSTRUMENTINDEX inst) const;
  311. mpt::ustring GetNoteName(const ModCommand::NOTE note) const;
  312. static mpt::ustring GetNoteName(const ModCommand::NOTE note, const NoteName *noteNames);
  313. #ifdef MODPLUG_TRACKER
  314. public:
  315. static void SetDefaultNoteNames();
  316. static const NoteName *GetDefaultNoteNames();
  317. static mpt::ustring GetDefaultNoteName(int note) // note = [0..11]
  318. {
  319. return m_NoteNames[note];
  320. }
  321. private:
  322. static const NoteName *m_NoteNames;
  323. #else
  324. private:
  325. const NoteName *m_NoteNames;
  326. #endif
  327. private:
  328. CTuningCollection* m_pTuningsTuneSpecific = nullptr;
  329. #ifdef MODPLUG_TRACKER
  330. public:
  331. CMIDIMapper& GetMIDIMapper() {return m_MIDIMapper;}
  332. const CMIDIMapper& GetMIDIMapper() const {return m_MIDIMapper;}
  333. private:
  334. CMIDIMapper m_MIDIMapper;
  335. #endif // MODPLUG_TRACKER
  336. private: //Misc private methods.
  337. static void SetModSpecsPointer(const CModSpecifications* &pModSpecs, const MODTYPE type);
  338. private: //Misc data
  339. const CModSpecifications *m_pModSpecs;
  340. private:
  341. // Interleaved Front Mix Buffer (Also room for interleaved rear mix)
  342. mixsample_t MixSoundBuffer[MIXBUFFERSIZE * 4];
  343. mixsample_t MixRearBuffer[MIXBUFFERSIZE * 2];
  344. // Non-interleaved plugin processing buffer
  345. float MixFloatBuffer[2][MIXBUFFERSIZE];
  346. mixsample_t MixInputBuffer[NUMMIXINPUTBUFFERS][MIXBUFFERSIZE];
  347. // End-of-sample pop reduction tail level
  348. mixsample_t m_dryLOfsVol = 0, m_dryROfsVol = 0;
  349. mixsample_t m_surroundLOfsVol = 0, m_surroundROfsVol = 0;
  350. public:
  351. MixerSettings m_MixerSettings;
  352. CResampler m_Resampler;
  353. #ifndef NO_REVERB
  354. mixsample_t ReverbSendBuffer[MIXBUFFERSIZE * 2];
  355. mixsample_t m_RvbROfsVol = 0, m_RvbLOfsVol = 0;
  356. CReverb m_Reverb;
  357. #endif
  358. #ifndef NO_DSP
  359. CSurround m_Surround;
  360. CMegaBass m_MegaBass;
  361. #endif
  362. #ifndef NO_EQ
  363. CEQ m_EQ;
  364. #endif
  365. #ifndef NO_AGC
  366. CAGC m_AGC;
  367. #endif
  368. #ifndef NO_DSP
  369. BitCrush m_BitCrush;
  370. #endif
  371. using samplecount_t = uint32; // Number of rendered samples
  372. static constexpr uint32 TICKS_ROW_FINISHED = uint32_max - 1u;
  373. public: // for Editing
  374. #ifdef MODPLUG_TRACKER
  375. CModDoc *m_pModDoc = nullptr; // Can be a null pointer for example when previewing samples from the treeview.
  376. #endif // MODPLUG_TRACKER
  377. Enum<MODTYPE> m_nType;
  378. private:
  379. MODCONTAINERTYPE m_ContainerType = MOD_CONTAINERTYPE_NONE;
  380. public:
  381. CHANNELINDEX m_nChannels = 0;
  382. SAMPLEINDEX m_nSamples = 0;
  383. INSTRUMENTINDEX m_nInstruments = 0;
  384. uint32 m_nDefaultSpeed, m_nDefaultGlobalVolume;
  385. TEMPO m_nDefaultTempo;
  386. FlagSet<SongFlags> m_SongFlags;
  387. CHANNELINDEX m_nMixChannels = 0;
  388. private:
  389. CHANNELINDEX m_nMixStat;
  390. public:
  391. ROWINDEX m_nDefaultRowsPerBeat, m_nDefaultRowsPerMeasure; // default rows per beat and measure for this module
  392. TempoMode m_nTempoMode = TempoMode::Classic;
  393. #ifdef MODPLUG_TRACKER
  394. // Lock playback between two rows. Lock is active if lock start != ROWINDEX_INVALID).
  395. ROWINDEX m_lockRowStart = ROWINDEX_INVALID, m_lockRowEnd = ROWINDEX_INVALID;
  396. // Lock playback between two orders. Lock is active if lock start != ORDERINDEX_INVALID).
  397. ORDERINDEX m_lockOrderStart = ORDERINDEX_INVALID, m_lockOrderEnd = ORDERINDEX_INVALID;
  398. #endif // MODPLUG_TRACKER
  399. uint32 m_nSamplePreAmp, m_nVSTiVolume;
  400. uint32 m_OPLVolumeFactor; // 16.16
  401. static constexpr uint32 m_OPLVolumeFactorScale = 1 << 16;
  402. constexpr bool IsGlobalVolumeUnset() const noexcept { return IsFirstTick(); }
  403. #ifndef MODPLUG_TRACKER
  404. uint32 m_nFreqFactor = 65536; // Pitch shift factor (65536 = no pitch shifting). Only used in libopenmpt (openmpt::ext::interactive::set_pitch_factor)
  405. uint32 m_nTempoFactor = 65536; // Tempo factor (65536 = no tempo adjustment). Only used in libopenmpt (openmpt::ext::interactive::set_tempo_factor)
  406. #endif
  407. // Row swing factors for modern tempo mode
  408. TempoSwing m_tempoSwing;
  409. // Min Period = highest possible frequency, Max Period = lowest possible frequency for current format
  410. // Note: Period is an Amiga metric that is inverse to frequency.
  411. // Periods in MPT are 4 times as fine as Amiga periods because of extra fine frequency slides (introduced in the S3M format).
  412. int32 m_nMinPeriod, m_nMaxPeriod;
  413. ResamplingMode m_nResampling; // Resampling mode (if overriding the globally set resampling)
  414. int32 m_nRepeatCount = 0; // -1 means repeat infinitely.
  415. ORDERINDEX m_nMaxOrderPosition;
  416. ModChannelSettings ChnSettings[MAX_BASECHANNELS]; // Initial channels settings
  417. CPatternContainer Patterns;
  418. ModSequenceSet Order; // Pattern sequences (order lists)
  419. protected:
  420. ModSample Samples[MAX_SAMPLES];
  421. public:
  422. ModInstrument *Instruments[MAX_INSTRUMENTS]; // Instrument Headers
  423. MIDIMacroConfig m_MidiCfg; // MIDI Macro config table
  424. #ifndef NO_PLUGINS
  425. SNDMIXPLUGIN m_MixPlugins[MAX_MIXPLUGINS]; // Mix plugins
  426. uint32 m_loadedPlugins = 0; // Not a PLUGINDEX because number of loaded plugins may exceed MAX_MIXPLUGINS during MIDI conversion
  427. #endif
  428. mpt::charbuf<MAX_SAMPLENAME> m_szNames[MAX_SAMPLES]; // Sample names
  429. Version m_dwCreatedWithVersion;
  430. Version m_dwLastSavedWithVersion;
  431. PlayBehaviourSet m_playBehaviour;
  432. protected:
  433. mpt::fast_prng m_PRNG;
  434. inline mpt::fast_prng & AccessPRNG() const { return const_cast<CSoundFile*>(this)->m_PRNG; }
  435. inline mpt::fast_prng & AccessPRNG() { return m_PRNG; }
  436. protected:
  437. // Mix level stuff
  438. CSoundFilePlayConfig m_PlayConfig;
  439. MixLevels m_nMixLevels;
  440. public:
  441. struct PlayState
  442. {
  443. friend class CSoundFile;
  444. public:
  445. samplecount_t m_lTotalSampleCount = 0; // Total number of rendered samples
  446. protected:
  447. samplecount_t m_nBufferCount = 0; // Remaining number samples to render for this tick
  448. double m_dBufferDiff = 0.0; // Modern tempo rounding error compensation
  449. public:
  450. uint32 m_nTickCount = 0; // Current tick being processed
  451. protected:
  452. uint32 m_nPatternDelay = 0; // Pattern delay (rows)
  453. uint32 m_nFrameDelay = 0; // Fine pattern delay (ticks)
  454. public:
  455. uint32 m_nSamplesPerTick = 0;
  456. ROWINDEX m_nCurrentRowsPerBeat = 0; // Current time signature
  457. ROWINDEX m_nCurrentRowsPerMeasure = 0; // Current time signature
  458. uint32 m_nMusicSpeed = 0; // Current speed
  459. TEMPO m_nMusicTempo; // Current tempo
  460. // Playback position
  461. ROWINDEX m_nRow = 0; // Current row being processed
  462. ROWINDEX m_nNextRow = 0; // Next row to process
  463. protected:
  464. ROWINDEX m_nextPatStartRow = 0; // For FT2's E60 bug
  465. ROWINDEX m_breakRow = 0; // Candidate target row for pattern break
  466. ROWINDEX m_patLoopRow = 0; // Candidate target row for pattern loop
  467. ORDERINDEX m_posJump = 0; // Candidate target order for position jump
  468. public:
  469. PATTERNINDEX m_nPattern = 0; // Current pattern being processed
  470. ORDERINDEX m_nCurrentOrder = 0; // Current order being processed
  471. ORDERINDEX m_nNextOrder = 0; // Next order to process
  472. ORDERINDEX m_nSeqOverride = ORDERINDEX_INVALID; // Queued order to be processed next, regardless of what order would normally follow
  473. // Global volume
  474. public:
  475. int32 m_nGlobalVolume = MAX_GLOBAL_VOLUME; // Current global volume (0...MAX_GLOBAL_VOLUME)
  476. protected:
  477. int32 m_nSamplesToGlobalVolRampDest = 0, m_nGlobalVolumeRampAmount = 0,
  478. m_nGlobalVolumeDestination = 0; // Global volume ramping
  479. int32 m_lHighResRampingGlobalVolume = 0; // Global volume ramping
  480. public:
  481. bool m_bPositionChanged = true; // Report to plugins that we jumped around in the module
  482. public:
  483. CHANNELINDEX ChnMix[MAX_CHANNELS]; // Index of channels in Chn to be actually mixed
  484. ModChannel Chn[MAX_CHANNELS]; // Mixing channels... First m_nChannels channels are master channels (i.e. they are never NNA channels)!
  485. struct MIDIMacroEvaluationResults
  486. {
  487. std::map<PLUGINDEX, float> pluginDryWetRatio;
  488. std::map<std::pair<PLUGINDEX, PlugParamIndex>, PlugParamValue> pluginParameter;
  489. };
  490. std::vector<uint8> m_midiMacroScratchSpace;
  491. std::optional<MIDIMacroEvaluationResults> m_midiMacroEvaluationResults;
  492. public:
  493. PlayState();
  494. void ResetGlobalVolumeRamping()
  495. {
  496. m_lHighResRampingGlobalVolume = m_nGlobalVolume << VOLUMERAMPPRECISION;
  497. m_nGlobalVolumeDestination = m_nGlobalVolume;
  498. m_nSamplesToGlobalVolRampDest = 0;
  499. m_nGlobalVolumeRampAmount = 0;
  500. }
  501. constexpr uint32 TicksOnRow() const noexcept
  502. {
  503. return (m_nMusicSpeed + m_nFrameDelay) * std::max(m_nPatternDelay, uint32(1));
  504. }
  505. };
  506. PlayState m_PlayState;
  507. protected:
  508. // For handling backwards jumps and stuff to prevent infinite loops when counting the mod length or rendering to wav.
  509. RowVisitor m_visitedRows;
  510. public:
  511. #ifdef MODPLUG_TRACKER
  512. std::bitset<MAX_BASECHANNELS> m_bChannelMuteTogglePending;
  513. std::bitset<MAX_MIXPLUGINS> m_pluginDryWetRatioChanged; // Dry/Wet ratio was changed by playback code (e.g. through MIDI macro), need to update UI
  514. std::vector<PatternCuePoint> *m_PatternCuePoints = nullptr; // For WAV export (writing pattern positions to file)
  515. std::vector<SmpLength> *m_SamplePlayLengths = nullptr; // For storing the maximum play length of each sample for automatic sample trimming
  516. #endif // MODPLUG_TRACKER
  517. std::unique_ptr<OPL> m_opl;
  518. public:
  519. #ifdef LIBOPENMPT_BUILD
  520. #ifndef NO_PLUGINS
  521. std::unique_ptr<CVstPluginManager> m_PluginManager;
  522. #endif
  523. #endif
  524. public:
  525. std::string m_songName;
  526. mpt::ustring m_songArtist;
  527. SongMessage m_songMessage;
  528. ModFormatDetails m_modFormat;
  529. protected:
  530. std::vector<FileHistory> m_FileHistory; // File edit history
  531. public:
  532. std::vector<FileHistory> &GetFileHistory() { return m_FileHistory; }
  533. const std::vector<FileHistory> &GetFileHistory() const { return m_FileHistory; }
  534. #ifdef MPT_EXTERNAL_SAMPLES
  535. // MPTM external on-disk sample paths
  536. protected:
  537. std::vector<mpt::PathString> m_samplePaths;
  538. public:
  539. void SetSamplePath(SAMPLEINDEX smp, mpt::PathString filename) { if(m_samplePaths.size() < smp) m_samplePaths.resize(smp); m_samplePaths[smp - 1] = std::move(filename); }
  540. void ResetSamplePath(SAMPLEINDEX smp) { if(m_samplePaths.size() >= smp) m_samplePaths[smp - 1] = mpt::PathString(); Samples[smp].uFlags.reset(SMP_KEEPONDISK | SMP_MODIFIED);}
  541. mpt::PathString GetSamplePath(SAMPLEINDEX smp) const { if(m_samplePaths.size() >= smp) return m_samplePaths[smp - 1]; else return mpt::PathString(); }
  542. bool SampleHasPath(SAMPLEINDEX smp) const { if(m_samplePaths.size() >= smp) return !m_samplePaths[smp - 1].empty(); else return false; }
  543. bool IsExternalSampleMissing(SAMPLEINDEX smp) const { return Samples[smp].uFlags[SMP_KEEPONDISK] && !Samples[smp].HasSampleData(); }
  544. bool LoadExternalSample(SAMPLEINDEX smp, const mpt::PathString &filename);
  545. #endif // MPT_EXTERNAL_SAMPLES
  546. bool m_bIsRendering = false;
  547. TimingInfo m_TimingInfo; // only valid if !m_bIsRendering
  548. private:
  549. // logging
  550. ILog *m_pCustomLog = nullptr;
  551. public:
  552. CSoundFile();
  553. CSoundFile(const CSoundFile &) = delete;
  554. CSoundFile & operator=(const CSoundFile &) = delete;
  555. ~CSoundFile();
  556. public:
  557. // logging
  558. void SetCustomLog(ILog *pLog) { m_pCustomLog = pLog; }
  559. void AddToLog(LogLevel level, const mpt::ustring &text) const;
  560. public:
  561. enum ModLoadingFlags
  562. {
  563. onlyVerifyHeader = 0x00,
  564. loadPatternData = 0x01, // If unset, advise loaders to not process any pattern data (if possible)
  565. loadSampleData = 0x02, // If unset, advise loaders to not process any sample data (if possible)
  566. loadPluginData = 0x04, // If unset, plugin data is not loaded (and as a consequence, plugins are not instanciated).
  567. loadPluginInstance = 0x08, // If unset, plugins are not instanciated.
  568. skipContainer = 0x10,
  569. skipModules = 0x20,
  570. // Shortcuts
  571. loadCompleteModule = loadSampleData | loadPatternData | loadPluginData | loadPluginInstance,
  572. loadNoPatternOrPluginData = loadSampleData,
  573. loadNoPluginInstance = loadSampleData | loadPatternData | loadPluginData,
  574. };
  575. #define PROBE_RECOMMENDED_SIZE 2048u
  576. static constexpr std::size_t ProbeRecommendedSize = PROBE_RECOMMENDED_SIZE;
  577. enum ProbeFlags
  578. {
  579. ProbeModules = 0x1,
  580. ProbeContainers = 0x2,
  581. ProbeFlagsDefault = ProbeModules | ProbeContainers,
  582. ProbeFlagsNone = 0
  583. };
  584. enum ProbeResult
  585. {
  586. ProbeSuccess = 1,
  587. ProbeFailure = 0,
  588. ProbeWantMoreData = -1
  589. };
  590. static ProbeResult ProbeAdditionalSize(MemoryFileReader &file, const uint64 *pfilesize, uint64 minimumAdditionalSize);
  591. static ProbeResult Probe(ProbeFlags flags, mpt::span<const std::byte> data, const uint64 *pfilesize);
  592. public:
  593. #ifdef MODPLUG_TRACKER
  594. // Get parent CModDoc. Can be nullptr if previewing from tree view, and is always nullptr if we're not actually compiling OpenMPT.
  595. CModDoc *GetpModDoc() const noexcept { return m_pModDoc; }
  596. #endif // MODPLUG_TRACKER
  597. bool Create(FileReader file, ModLoadingFlags loadFlags = loadCompleteModule, CModDoc *pModDoc = nullptr);
  598. private:
  599. bool CreateInternal(FileReader file, ModLoadingFlags loadFlags);
  600. public:
  601. bool Destroy();
  602. Enum<MODTYPE> GetType() const noexcept { return m_nType; }
  603. MODCONTAINERTYPE GetContainerType() const noexcept { return m_ContainerType; }
  604. // rough heuristic, could be improved
  605. mpt::Charset GetCharsetFile() const // 8bit string encoding of strings in the on-disk file
  606. {
  607. return m_modFormat.charset;
  608. }
  609. mpt::Charset GetCharsetInternal() const // 8bit string encoding of strings internal in CSoundFile
  610. {
  611. #if defined(MODPLUG_TRACKER)
  612. return mpt::Charset::Locale;
  613. #else // MODPLUG_TRACKER
  614. return GetCharsetFile();
  615. #endif // MODPLUG_TRACKER
  616. }
  617. ModMessageHeuristicOrder GetMessageHeuristic() const;
  618. void SetPreAmp(uint32 vol);
  619. uint32 GetPreAmp() const noexcept { return m_MixerSettings.m_nPreAmp; }
  620. void SetMixLevels(MixLevels levels);
  621. MixLevels GetMixLevels() const noexcept { return m_nMixLevels; }
  622. const CSoundFilePlayConfig &GetPlayConfig() const noexcept { return m_PlayConfig; }
  623. constexpr INSTRUMENTINDEX GetNumInstruments() const noexcept { return m_nInstruments; }
  624. constexpr SAMPLEINDEX GetNumSamples() const noexcept { return m_nSamples; }
  625. constexpr PATTERNINDEX GetCurrentPattern() const noexcept { return m_PlayState.m_nPattern; }
  626. constexpr ORDERINDEX GetCurrentOrder() const noexcept { return m_PlayState.m_nCurrentOrder; }
  627. constexpr CHANNELINDEX GetNumChannels() const noexcept { return m_nChannels; }
  628. constexpr bool CanAddMoreSamples(SAMPLEINDEX amount = 1) const noexcept { return (amount < MAX_SAMPLES) && m_nSamples < (MAX_SAMPLES - amount); }
  629. constexpr bool CanAddMoreInstruments(INSTRUMENTINDEX amount = 1) const noexcept { return (amount < MAX_INSTRUMENTS) && m_nInstruments < (MAX_INSTRUMENTS - amount); }
  630. #ifndef NO_PLUGINS
  631. IMixPlugin* GetInstrumentPlugin(INSTRUMENTINDEX instr) const noexcept;
  632. #endif
  633. const CModSpecifications& GetModSpecifications() const {return *m_pModSpecs;}
  634. static const CModSpecifications& GetModSpecifications(const MODTYPE type);
  635. static ChannelFlags GetChannelMuteFlag();
  636. #ifdef MODPLUG_TRACKER
  637. void PatternTranstionChnSolo(const CHANNELINDEX chnIndex);
  638. void PatternTransitionChnUnmuteAll();
  639. protected:
  640. void HandlePatternTransitionEvents();
  641. #endif // MODPLUG_TRACKER
  642. public:
  643. double GetCurrentBPM() const;
  644. void DontLoopPattern(PATTERNINDEX nPat, ROWINDEX nRow = 0);
  645. CHANNELINDEX GetMixStat() const { return m_nMixStat; }
  646. void ResetMixStat() { m_nMixStat = 0; }
  647. void ResetPlayPos();
  648. void SetCurrentOrder(ORDERINDEX nOrder);
  649. std::string GetTitle() const { return m_songName; }
  650. bool SetTitle(const std::string &newTitle); // Return true if title was changed.
  651. const char *GetSampleName(SAMPLEINDEX nSample) const;
  652. const char *GetInstrumentName(INSTRUMENTINDEX nInstr) const;
  653. uint32 GetMusicSpeed() const { return m_PlayState.m_nMusicSpeed; }
  654. TEMPO GetMusicTempo() const { return m_PlayState.m_nMusicTempo; }
  655. constexpr bool IsFirstTick() const noexcept { return (m_PlayState.m_lTotalSampleCount == 0); }
  656. // Get song duration in various cases: total length, length to specific order & row, etc.
  657. std::vector<GetLengthType> GetLength(enmGetLengthResetMode adjustMode, GetLengthTarget target = GetLengthTarget());
  658. public:
  659. void RecalculateSamplesPerTick();
  660. double GetRowDuration(TEMPO tempo, uint32 speed) const;
  661. uint32 GetTickDuration(PlayState &playState) const;
  662. // A repeat count value of -1 means infinite loop
  663. void SetRepeatCount(int n) { m_nRepeatCount = n; }
  664. int GetRepeatCount() const { return m_nRepeatCount; }
  665. bool IsPaused() const { return m_SongFlags[SONG_PAUSED | SONG_STEP]; } // Added SONG_STEP as it seems to be desirable in most cases to check for this as well.
  666. void LoopPattern(PATTERNINDEX nPat, ROWINDEX nRow = 0);
  667. bool InitChannel(CHANNELINDEX nChn);
  668. void InitAmigaResampler();
  669. void InitOPL();
  670. static constexpr bool SupportsOPL(MODTYPE type) noexcept { return type & (MOD_TYPE_S3M | MOD_TYPE_MPT); }
  671. bool SupportsOPL() const noexcept { return SupportsOPL(m_nType); }
  672. #if !defined(MPT_WITH_ANCIENT)
  673. static ProbeResult ProbeFileHeaderMMCMP(MemoryFileReader file, const uint64 *pfilesize);
  674. static ProbeResult ProbeFileHeaderPP20(MemoryFileReader file, const uint64 *pfilesize);
  675. static ProbeResult ProbeFileHeaderXPK(MemoryFileReader file, const uint64 *pfilesize);
  676. #endif // !MPT_WITH_ANCIENT
  677. static ProbeResult ProbeFileHeaderUMX(MemoryFileReader file, const uint64* pfilesize);
  678. static ProbeResult ProbeFileHeader669(MemoryFileReader file, const uint64 *pfilesize);
  679. static ProbeResult ProbeFileHeaderAM(MemoryFileReader file, const uint64 *pfilesize);
  680. static ProbeResult ProbeFileHeaderAMF_Asylum(MemoryFileReader file, const uint64 *pfilesize);
  681. static ProbeResult ProbeFileHeaderAMF_DSMI(MemoryFileReader file, const uint64 *pfilesize);
  682. static ProbeResult ProbeFileHeaderAMS(MemoryFileReader file, const uint64 *pfilesize);
  683. static ProbeResult ProbeFileHeaderAMS2(MemoryFileReader file, const uint64 *pfilesize);
  684. static ProbeResult ProbeFileHeaderC67(MemoryFileReader file, const uint64 *pfilesize);
  685. static ProbeResult ProbeFileHeaderDBM(MemoryFileReader file, const uint64 *pfilesize);
  686. static ProbeResult ProbeFileHeaderDTM(MemoryFileReader file, const uint64 *pfilesize);
  687. static ProbeResult ProbeFileHeaderDIGI(MemoryFileReader file, const uint64 *pfilesize);
  688. static ProbeResult ProbeFileHeaderDMF(MemoryFileReader file, const uint64 *pfilesize);
  689. static ProbeResult ProbeFileHeaderDSM(MemoryFileReader file, const uint64 *pfilesize);
  690. static ProbeResult ProbeFileHeaderDSym(MemoryFileReader file, const uint64 *pfilesize);
  691. static ProbeResult ProbeFileHeaderFAR(MemoryFileReader file, const uint64 *pfilesize);
  692. static ProbeResult ProbeFileHeaderFMT(MemoryFileReader file, const uint64* pfilesize);
  693. static ProbeResult ProbeFileHeaderGDM(MemoryFileReader file, const uint64 *pfilesize);
  694. static ProbeResult ProbeFileHeaderICE(MemoryFileReader file, const uint64 *pfilesize);
  695. static ProbeResult ProbeFileHeaderIMF(MemoryFileReader file, const uint64 *pfilesize);
  696. static ProbeResult ProbeFileHeaderIT(MemoryFileReader file, const uint64 *pfilesize);
  697. static ProbeResult ProbeFileHeaderITP(MemoryFileReader file, const uint64 *pfilesize);
  698. static ProbeResult ProbeFileHeaderJ2B(MemoryFileReader file, const uint64 *pfilesize);
  699. static ProbeResult ProbeFileHeaderMUS_KM(MemoryFileReader file, const uint64 *pfilesize);
  700. static ProbeResult ProbeFileHeaderM15(MemoryFileReader file, const uint64 *pfilesize);
  701. static ProbeResult ProbeFileHeaderMDL(MemoryFileReader file, const uint64 *pfilesize);
  702. static ProbeResult ProbeFileHeaderMED(MemoryFileReader file, const uint64 *pfilesize);
  703. static ProbeResult ProbeFileHeaderMO3(MemoryFileReader file, const uint64 *pfilesize);
  704. static ProbeResult ProbeFileHeaderMOD(MemoryFileReader file, const uint64 *pfilesize);
  705. static ProbeResult ProbeFileHeaderMT2(MemoryFileReader file, const uint64 *pfilesize);
  706. static ProbeResult ProbeFileHeaderMTM(MemoryFileReader file, const uint64 *pfilesize);
  707. static ProbeResult ProbeFileHeaderOKT(MemoryFileReader file, const uint64 *pfilesize);
  708. static ProbeResult ProbeFileHeaderPLM(MemoryFileReader file, const uint64 *pfilesize);
  709. static ProbeResult ProbeFileHeaderPSM(MemoryFileReader file, const uint64 *pfilesize);
  710. static ProbeResult ProbeFileHeaderPSM16(MemoryFileReader file, const uint64 *pfilesize);
  711. static ProbeResult ProbeFileHeaderPT36(MemoryFileReader file, const uint64 *pfilesize);
  712. static ProbeResult ProbeFileHeaderPTM(MemoryFileReader file, const uint64 *pfilesize);
  713. static ProbeResult ProbeFileHeaderS3M(MemoryFileReader file, const uint64 *pfilesize);
  714. static ProbeResult ProbeFileHeaderSFX(MemoryFileReader file, const uint64 *pfilesize);
  715. static ProbeResult ProbeFileHeaderSTM(MemoryFileReader file, const uint64 *pfilesize);
  716. static ProbeResult ProbeFileHeaderSTP(MemoryFileReader file, const uint64 *pfilesize);
  717. static ProbeResult ProbeFileHeaderSTX(MemoryFileReader file, const uint64 *pfilesize);
  718. static ProbeResult ProbeFileHeaderSymMOD(MemoryFileReader file, const uint64 *pfilesize);
  719. static ProbeResult ProbeFileHeaderULT(MemoryFileReader file, const uint64 *pfilesize);
  720. static ProbeResult ProbeFileHeaderXM(MemoryFileReader file, const uint64 *pfilesize);
  721. static ProbeResult ProbeFileHeaderMID(MemoryFileReader file, const uint64 *pfilesize);
  722. static ProbeResult ProbeFileHeaderUAX(MemoryFileReader file, const uint64 *pfilesize);
  723. static ProbeResult ProbeFileHeaderWAV(MemoryFileReader file, const uint64 *pfilesize);
  724. // Module Loaders
  725. bool Read669(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  726. bool ReadAM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  727. bool ReadAMF_Asylum(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  728. bool ReadAMF_DSMI(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  729. bool ReadAMS(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  730. bool ReadAMS2(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  731. bool ReadC67(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  732. bool ReadDBM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  733. bool ReadDTM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  734. bool ReadDIGI(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  735. bool ReadDMF(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  736. bool ReadDSM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  737. bool ReadDSym(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  738. bool ReadFAR(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  739. bool ReadFMT(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  740. bool ReadGDM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  741. bool ReadICE(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  742. bool ReadIMF(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  743. bool ReadIT(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  744. bool ReadITP(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  745. bool ReadJ2B(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  746. bool ReadMUS_KM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  747. bool ReadM15(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  748. bool ReadMDL(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  749. bool ReadMED(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  750. bool ReadMO3(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  751. bool ReadMOD(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  752. bool ReadMT2(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  753. bool ReadMTM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  754. bool ReadOKT(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  755. bool ReadPLM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  756. bool ReadPSM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  757. bool ReadPSM16(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  758. bool ReadPT36(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  759. bool ReadPTM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  760. bool ReadS3M(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  761. bool ReadSFX(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  762. bool ReadSTM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  763. bool ReadSTP(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  764. bool ReadSTX(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  765. bool ReadSymMOD(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  766. bool ReadULT(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  767. bool ReadXM(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  768. bool ReadMID(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  769. bool ReadUAX(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  770. bool ReadWAV(FileReader &file, ModLoadingFlags loadFlags = loadCompleteModule);
  771. static std::vector<const char *> GetSupportedExtensions(bool otherFormats);
  772. static bool IsExtensionSupported(std::string_view ext); // UTF8, casing of ext is ignored
  773. static mpt::ustring ModContainerTypeToString(MODCONTAINERTYPE containertype);
  774. static mpt::ustring ModContainerTypeToTracker(MODCONTAINERTYPE containertype);
  775. /// <summary>
  776. /// From version: 0.7.0
  777. /// Hakan DANISIK
  778. /// </summary>
  779. /// <param name="extension"></param>
  780. /// <returns></returns>
  781. static std::string ExtensionToTracker(std::string extension);
  782. // Repair non-standard stuff in modules saved with previous ModPlug versions
  783. void UpgradeModule();
  784. // Save Functions
  785. #ifndef MODPLUG_NO_FILESAVE
  786. bool SaveXM(std::ostream &f, bool compatibilityExport = false);
  787. bool SaveS3M(std::ostream &f) const;
  788. bool SaveMod(std::ostream &f) const;
  789. bool SaveIT(std::ostream &f, const mpt::PathString &filename, bool compatibilityExport = false);
  790. uint32 SaveMixPlugins(std::ostream *file=nullptr, bool bUpdate=true);
  791. void WriteInstrumentPropertyForAllInstruments(uint32 code, uint16 size, std::ostream &f, INSTRUMENTINDEX nInstruments) const;
  792. void SaveExtendedInstrumentProperties(INSTRUMENTINDEX nInstruments, std::ostream &f) const;
  793. void SaveExtendedSongProperties(std::ostream &f) const;
  794. #endif // MODPLUG_NO_FILESAVE
  795. void LoadExtendedSongProperties(FileReader &file, bool ignoreChannelCount, bool* pInterpretMptMade = nullptr);
  796. void LoadMPTMProperties(FileReader &file, uint16 cwtv);
  797. static mpt::ustring GetSchismTrackerVersion(uint16 cwtv, uint32 reserved);
  798. // Reads extended instrument properties(XM/IT/MPTM).
  799. // Returns true if extended instrument properties were found.
  800. bool LoadExtendedInstrumentProperties(FileReader &file);
  801. void SetDefaultPlaybackBehaviour(MODTYPE type);
  802. static PlayBehaviourSet GetSupportedPlaybackBehaviour(MODTYPE type);
  803. static PlayBehaviourSet GetDefaultPlaybackBehaviour(MODTYPE type);
  804. // MOD Convert function
  805. MODTYPE GetBestSaveFormat() const;
  806. static void ConvertModCommand(ModCommand &m);
  807. static void S3MConvert(ModCommand &m, bool fromIT);
  808. void S3MSaveConvert(uint8 &command, uint8 &param, bool toIT, bool compatibilityExport = false) const;
  809. void ModSaveCommand(uint8 &command, uint8 &param, const bool toXM, const bool compatibilityExport = false) const;
  810. static void ReadMODPatternEntry(FileReader &file, ModCommand &m);
  811. static void ReadMODPatternEntry(const std::array<uint8, 4> data, ModCommand &m);
  812. void SetupMODPanning(bool bForceSetup = false); // Setup LRRL panning, max channel volume
  813. public:
  814. // Real-time sound functions
  815. void SuspendPlugins();
  816. void ResumePlugins();
  817. void StopAllVsti();
  818. void RecalculateGainForAllPlugs();
  819. void ResetChannels();
  820. samplecount_t Read(samplecount_t count, IAudioTarget &target) { AudioSourceNone source; return Read(count, target, source); }
  821. samplecount_t Read(
  822. samplecount_t count,
  823. IAudioTarget &target,
  824. IAudioSource &source,
  825. std::optional<std::reference_wrapper<IMonitorOutput>> outputMonitor = std::nullopt,
  826. std::optional<std::reference_wrapper<IMonitorInput>> inputMonitor = std::nullopt
  827. );
  828. samplecount_t ReadOneTick();
  829. private:
  830. void CreateStereoMix(int count);
  831. public:
  832. bool FadeSong(uint32 msec);
  833. private:
  834. void ProcessDSP(uint32 countChunk);
  835. void ProcessPlugins(uint32 nCount);
  836. void ProcessInputChannels(IAudioSource &source, std::size_t countChunk);
  837. public:
  838. samplecount_t GetTotalSampleCount() const { return m_PlayState.m_lTotalSampleCount; }
  839. bool HasPositionChanged() { bool b = m_PlayState.m_bPositionChanged; m_PlayState.m_bPositionChanged = false; return b; }
  840. bool IsRenderingToDisc() const { return m_bIsRendering; }
  841. void PrecomputeSampleLoops(bool updateChannels = false);
  842. public:
  843. // Mixer Config
  844. void SetMixerSettings(const MixerSettings &mixersettings);
  845. void SetResamplerSettings(const CResamplerSettings &resamplersettings);
  846. void InitPlayer(bool bReset=false);
  847. void SetDspEffects(uint32 DSPMask);
  848. uint32 GetSampleRate() const { return m_MixerSettings.gdwMixingFreq; }
  849. #ifndef NO_EQ
  850. void SetEQGains(const uint32 *pGains, const uint32 *pFreqs, bool bReset = false) { m_EQ.SetEQGains(pGains, pFreqs, bReset, m_MixerSettings.gdwMixingFreq); } // 0=-12dB, 32=+12dB
  851. #endif // NO_EQ
  852. public:
  853. bool ReadNote();
  854. bool ProcessRow();
  855. bool ProcessEffects();
  856. std::pair<bool, bool> NextRow(PlayState &playState, const bool breakRow) const;
  857. void SetupNextRow(PlayState &playState, const bool patternLoop) const;
  858. CHANNELINDEX GetNNAChannel(CHANNELINDEX nChn) const;
  859. CHANNELINDEX CheckNNA(CHANNELINDEX nChn, uint32 instr, int note, bool forceCut);
  860. void NoteChange(ModChannel &chn, int note, bool bPorta = false, bool bResetEnv = true, bool bManual = false, CHANNELINDEX channelHint = CHANNELINDEX_INVALID) const;
  861. void InstrumentChange(ModChannel &chn, uint32 instr, bool bPorta = false, bool bUpdVol = true, bool bResetEnv = true) const;
  862. void ApplyInstrumentPanning(ModChannel &chn, const ModInstrument *instr, const ModSample *smp) const;
  863. uint32 CalculateXParam(PATTERNINDEX pat, ROWINDEX row, CHANNELINDEX chn, uint32 *extendedRows = nullptr) const;
  864. // Channel Effects
  865. void KeyOff(ModChannel &chn) const;
  866. // Global Effects
  867. void SetTempo(TEMPO param, bool setAsNonModcommand = false);
  868. void SetSpeed(PlayState &playState, uint32 param) const;
  869. static TEMPO ConvertST2Tempo(uint8 tempo);
  870. void ProcessRamping(ModChannel &chn) const;
  871. protected:
  872. // Global variable initializer for loader functions
  873. void SetType(MODTYPE type);
  874. void InitializeGlobals(MODTYPE type = MOD_TYPE_NONE);
  875. void InitializeChannels();
  876. // Channel effect processing
  877. int GetVibratoDelta(int type, int position) const;
  878. void ProcessVolumeSwing(ModChannel &chn, int &vol) const;
  879. void ProcessPanningSwing(ModChannel &chn) const;
  880. void ProcessTremolo(ModChannel &chn, int &vol) const;
  881. void ProcessTremor(CHANNELINDEX nChn, int &vol);
  882. bool IsEnvelopeProcessed(const ModChannel &chn, EnvelopeType env) const;
  883. void ProcessVolumeEnvelope(ModChannel &chn, int &vol) const;
  884. void ProcessPanningEnvelope(ModChannel &chn) const;
  885. int ProcessPitchFilterEnvelope(ModChannel &chn, int32 &period) const;
  886. void IncrementEnvelopePosition(ModChannel &chn, EnvelopeType envType) const;
  887. void IncrementEnvelopePositions(ModChannel &chn) const;
  888. void ProcessInstrumentFade(ModChannel &chn, int &vol) const;
  889. static void ProcessPitchPanSeparation(int32 &pan, int note, const ModInstrument &instr);
  890. void ProcessPanbrello(ModChannel &chn) const;
  891. void ProcessArpeggio(CHANNELINDEX nChn, int32 &period, Tuning::NOTEINDEXTYPE &arpeggioSteps);
  892. void ProcessVibrato(CHANNELINDEX nChn, int32 &period, Tuning::RATIOTYPE &vibratoFactor);
  893. void ProcessSampleAutoVibrato(ModChannel &chn, int32 &period, Tuning::RATIOTYPE &vibratoFactor, int &nPeriodFrac) const;
  894. std::pair<SamplePosition, uint32> GetChannelIncrement(const ModChannel &chn, uint32 period, int periodFrac) const;
  895. protected:
  896. // Type of panning command
  897. enum PanningType
  898. {
  899. Pan4bit = 4,
  900. Pan6bit = 6,
  901. Pan8bit = 8,
  902. };
  903. // Channel Effects
  904. void UpdateS3MEffectMemory(ModChannel &chn, ModCommand::PARAM param) const;
  905. void PortamentoUp(CHANNELINDEX nChn, ModCommand::PARAM param, const bool doFinePortamentoAsRegular = false);
  906. void PortamentoDown(CHANNELINDEX nChn, ModCommand::PARAM param, const bool doFinePortamentoAsRegular = false);
  907. void MidiPortamento(CHANNELINDEX nChn, int param, bool doFineSlides);
  908. void FinePortamentoUp(ModChannel &chn, ModCommand::PARAM param) const;
  909. void FinePortamentoDown(ModChannel &chn, ModCommand::PARAM param) const;
  910. void ExtraFinePortamentoUp(ModChannel &chn, ModCommand::PARAM param) const;
  911. void ExtraFinePortamentoDown(ModChannel &chn, ModCommand::PARAM param) const;
  912. void PortamentoMPT(ModChannel &chn, int);
  913. void PortamentoFineMPT(ModChannel &chn, int);
  914. void PortamentoExtraFineMPT(ModChannel &chn, int);
  915. void SetFinetune(CHANNELINDEX channel, PlayState &playState, bool isSmooth) const;
  916. void NoteSlide(ModChannel &chn, uint32 param, bool slideUp, bool retrig) const;
  917. std::pair<uint16, bool> GetVolCmdTonePorta(const ModCommand &m, uint32 startTick) const;
  918. void TonePortamento(ModChannel &chn, uint16 param) const;
  919. void Vibrato(ModChannel &chn, uint32 param) const;
  920. void FineVibrato(ModChannel &chn, uint32 param) const;
  921. void VolumeSlide(ModChannel &chn, ModCommand::PARAM param) const;
  922. void PanningSlide(ModChannel &chn, ModCommand::PARAM param, bool memory = true) const;
  923. void ChannelVolSlide(ModChannel &chn, ModCommand::PARAM param) const;
  924. void FineVolumeUp(ModChannel &chn, ModCommand::PARAM param, bool volCol) const;
  925. void FineVolumeDown(ModChannel &chn, ModCommand::PARAM param, bool volCol) const;
  926. void Tremolo(ModChannel &chn, uint32 param) const;
  927. void Panbrello(ModChannel &chn, uint32 param) const;
  928. void Panning(ModChannel &chn, uint32 param, PanningType panBits) const;
  929. void RetrigNote(CHANNELINDEX nChn, int param, int offset = 0);
  930. void ProcessSampleOffset(ModChannel &chn, CHANNELINDEX nChn, const PlayState &playState) const;
  931. void SampleOffset(ModChannel &chn, SmpLength param) const;
  932. void ReverseSampleOffset(ModChannel &chn, ModCommand::PARAM param) const;
  933. void DigiBoosterSampleReverse(ModChannel &chn, ModCommand::PARAM param) const;
  934. void HandleDigiSamplePlayDirection(PlayState &state, CHANNELINDEX chn) const;
  935. void NoteCut(CHANNELINDEX nChn, uint32 nTick, bool cutSample);
  936. void PatternLoop(PlayState &state, ModChannel &chn, ModCommand::PARAM param) const;
  937. bool HandleNextRow(PlayState &state, const ModSequence &order, bool honorPatternLoop) const;
  938. void ExtendedMODCommands(CHANNELINDEX nChn, ModCommand::PARAM param);
  939. void ExtendedS3MCommands(CHANNELINDEX nChn, ModCommand::PARAM param);
  940. void ExtendedChannelEffect(ModChannel &chn, uint32 param);
  941. void InvertLoop(ModChannel &chn);
  942. void PositionJump(PlayState &state, CHANNELINDEX chn) const;
  943. ROWINDEX PatternBreak(PlayState &state, CHANNELINDEX chn, uint8 param) const;
  944. void GlobalVolSlide(ModCommand::PARAM param, uint8 &nOldGlobalVolSlide);
  945. void ProcessMacroOnChannel(CHANNELINDEX nChn);
  946. void ProcessMIDIMacro(PlayState &playState, CHANNELINDEX nChn, bool isSmooth, const MIDIMacroConfigData::Macro &macro, uint8 param = 0, PLUGINDEX plugin = 0);
  947. void ParseMIDIMacro(PlayState &playState, CHANNELINDEX nChn, bool isSmooth, const mpt::span<const char> macro, mpt::span<uint8> &out, uint8 param = 0, PLUGINDEX plugin = 0) const;
  948. static float CalculateSmoothParamChange(const PlayState &playState, float currentValue, float param);
  949. void SendMIDIData(PlayState &playState, CHANNELINDEX nChn, bool isSmooth, const mpt::span<const uint8> macro, PLUGINDEX plugin);
  950. void SendMIDINote(CHANNELINDEX chn, uint16 note, uint16 volume);
  951. int SetupChannelFilter(ModChannel &chn, bool bReset, int envModifier = 256) const;
  952. // Low-Level effect processing
  953. void DoFreqSlide(ModChannel &chn, int32 &period, int32 amount, bool isTonePorta = false) const;
  954. void UpdateTimeSignature();
  955. public:
  956. // Convert frequency to IT cutoff (0...127)
  957. uint8 FrequencyToCutOff(double frequency) const;
  958. // Convert IT cutoff (0...127 + modifier) to frequency
  959. uint32 CutOffToFrequency(uint32 nCutOff, int envModifier = 256) const; // [0-127] => [1-10KHz]
  960. // Returns true if periods are actually plain frequency values in Hz.
  961. bool PeriodsAreFrequencies() const noexcept
  962. {
  963. return m_playBehaviour[kPeriodsAreHertz] && !UseFinetuneAndTranspose();
  964. }
  965. // Returns true if the current format uses transpose+finetune rather than frequency in Hz to specify middle-C.
  966. static constexpr bool UseFinetuneAndTranspose(MODTYPE type) noexcept
  967. {
  968. return (type & (MOD_TYPE_AMF0 | MOD_TYPE_DIGI | MOD_TYPE_MED | MOD_TYPE_MOD | MOD_TYPE_MTM | MOD_TYPE_OKT | MOD_TYPE_SFX | MOD_TYPE_STP | MOD_TYPE_XM));
  969. }
  970. bool UseFinetuneAndTranspose() const noexcept
  971. {
  972. return UseFinetuneAndTranspose(GetType());
  973. }
  974. bool DestroySample(SAMPLEINDEX nSample);
  975. bool DestroySampleThreadsafe(SAMPLEINDEX nSample);
  976. // Find an unused sample slot. If it is going to be assigned to an instrument, targetInstrument should be specified.
  977. // SAMPLEINDEX_INVLAID is returned if no free sample slot could be found.
  978. SAMPLEINDEX GetNextFreeSample(INSTRUMENTINDEX targetInstrument = INSTRUMENTINDEX_INVALID, SAMPLEINDEX start = 1) const;
  979. // Find an unused instrument slot.
  980. // INSTRUMENTINDEX_INVALID is returned if no free instrument slot could be found.
  981. INSTRUMENTINDEX GetNextFreeInstrument(INSTRUMENTINDEX start = 1) const;
  982. // Check whether a given sample is used by a given instrument.
  983. bool IsSampleReferencedByInstrument(SAMPLEINDEX sample, INSTRUMENTINDEX instr) const;
  984. ModInstrument *AllocateInstrument(INSTRUMENTINDEX instr, SAMPLEINDEX assignedSample = 0);
  985. bool DestroyInstrument(INSTRUMENTINDEX nInstr, deleteInstrumentSamples removeSamples);
  986. bool RemoveInstrumentSamples(INSTRUMENTINDEX nInstr, SAMPLEINDEX keepSample = SAMPLEINDEX_INVALID);
  987. SAMPLEINDEX DetectUnusedSamples(std::vector<bool> &sampleUsed) const;
  988. SAMPLEINDEX RemoveSelectedSamples(const std::vector<bool> &keepSamples);
  989. // Set the autovibrato settings for all samples associated to the given instrument.
  990. void PropagateXMAutoVibrato(INSTRUMENTINDEX ins, VibratoType type, uint8 sweep, uint8 depth, uint8 rate);
  991. // Samples file I/O
  992. bool ReadSampleFromFile(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize = false, bool includeInstrumentFormats = true);
  993. bool ReadWAVSample(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize = false, FileReader *wsmpChunk = nullptr);
  994. protected:
  995. bool ReadW64Sample(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize = false);
  996. bool ReadPATSample(SAMPLEINDEX nSample, FileReader &file);
  997. bool ReadS3ISample(SAMPLEINDEX nSample, FileReader &file);
  998. bool ReadSBISample(SAMPLEINDEX sample, FileReader &file);
  999. bool ReadCAFSample(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize = false);
  1000. bool ReadAIFFSample(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize = false);
  1001. bool ReadAUSample(SAMPLEINDEX nSample, FileReader &file, bool mayNormalize = false);
  1002. bool ReadXISample(SAMPLEINDEX nSample, FileReader &file);
  1003. bool ReadITSSample(SAMPLEINDEX nSample, FileReader &file, bool rewind = true);
  1004. bool ReadITISample(SAMPLEINDEX nSample, FileReader &file);
  1005. bool ReadIFFSample(SAMPLEINDEX sample, FileReader &file);
  1006. bool ReadBRRSample(SAMPLEINDEX sample, FileReader &file);
  1007. bool ReadFLACSample(SAMPLEINDEX sample, FileReader &file);
  1008. bool ReadOpusSample(SAMPLEINDEX sample, FileReader &file);
  1009. bool ReadVorbisSample(SAMPLEINDEX sample, FileReader &file);
  1010. bool ReadMP3Sample(SAMPLEINDEX sample, FileReader &file, bool raw = false, bool mo3Decode = false); // raw: ignore all encoder-/decodr-delays, decode just raw frames ; mod3Decode: skip metadata and loop-precompute
  1011. bool ReadMediaFoundationSample(SAMPLEINDEX sample, FileReader &file, bool mo3Decode = false); // mod3Decode: skip metadata and loop-precompute
  1012. public:
  1013. #ifdef MODPLUG_TRACKER
  1014. static std::vector<FileType> GetMediaFoundationFileTypes();
  1015. #endif // MODPLUG_TRACKER
  1016. #ifndef MODPLUG_NO_FILESAVE
  1017. bool SaveWAVSample(SAMPLEINDEX nSample, std::ostream &f) const;
  1018. bool SaveRAWSample(SAMPLEINDEX nSample, std::ostream &f) const;
  1019. bool SaveFLACSample(SAMPLEINDEX nSample, std::ostream &f) const;
  1020. bool SaveS3ISample(SAMPLEINDEX smp, std::ostream &f) const;
  1021. #endif
  1022. // Instrument file I/O
  1023. bool ReadInstrumentFromFile(INSTRUMENTINDEX nInstr, FileReader &file, bool mayNormalize = false);
  1024. bool ReadSampleAsInstrument(INSTRUMENTINDEX nInstr, FileReader &file, bool mayNormalize = false);
  1025. protected:
  1026. bool ReadXIInstrument(INSTRUMENTINDEX nInstr, FileReader &file);
  1027. bool ReadITIInstrument(INSTRUMENTINDEX nInstr, FileReader &file);
  1028. bool ReadPATInstrument(INSTRUMENTINDEX nInstr, FileReader &file);
  1029. bool ReadSFZInstrument(INSTRUMENTINDEX nInstr, FileReader &file);
  1030. public:
  1031. #ifndef MODPLUG_NO_FILESAVE
  1032. bool SaveXIInstrument(INSTRUMENTINDEX nInstr, std::ostream &f) const;
  1033. bool SaveITIInstrument(INSTRUMENTINDEX nInstr, std::ostream &f, const mpt::PathString &filename, bool compress, bool allowExternal) const;
  1034. bool SaveSFZInstrument(INSTRUMENTINDEX nInstr, std::ostream &f, const mpt::PathString &filename, bool useFLACsamples) const;
  1035. #endif
  1036. // I/O from another sound file
  1037. bool ReadInstrumentFromSong(INSTRUMENTINDEX targetInstr, const CSoundFile &srcSong, INSTRUMENTINDEX sourceInstr);
  1038. bool ReadSampleFromSong(SAMPLEINDEX targetSample, const CSoundFile &srcSong, SAMPLEINDEX sourceSample);
  1039. // Period/Note functions
  1040. uint32 GetNoteFromPeriod(uint32 period, int32 nFineTune = 0, uint32 nC5Speed = 0) const;
  1041. uint32 GetPeriodFromNote(uint32 note, int32 nFineTune, uint32 nC5Speed) const;
  1042. uint32 GetFreqFromPeriod(uint32 period, uint32 c5speed, int32 nPeriodFrac = 0) const;
  1043. // Misc functions
  1044. ModSample &GetSample(SAMPLEINDEX sample) { MPT_ASSERT(sample <= m_nSamples && sample < std::size(Samples)); return Samples[sample]; }
  1045. const ModSample &GetSample(SAMPLEINDEX sample) const { MPT_ASSERT(sample <= m_nSamples && sample < std::size(Samples)); return Samples[sample]; }
  1046. // Resolve note/instrument combination to real sample index. Return value is guaranteed to be in [0, GetNumSamples()].
  1047. SAMPLEINDEX GetSampleIndex(ModCommand::NOTE note, uint32 instr) const noexcept;
  1048. uint32 MapMidiInstrument(uint8 program, uint16 bank, uint8 midiChannel, uint8 note, bool isXG, std::bitset<16> drumChns);
  1049. size_t ITInstrToMPT(FileReader &file, ModInstrument &ins, uint16 trkvers);
  1050. bool LoadMixPlugins(FileReader &file);
  1051. #ifndef NO_PLUGINS
  1052. static void ReadMixPluginChunk(FileReader &file, SNDMIXPLUGIN &plugin);
  1053. void ProcessMidiOut(CHANNELINDEX nChn);
  1054. #endif // NO_PLUGINS
  1055. void ProcessGlobalVolume(long countChunk);
  1056. void ProcessStereoSeparation(long countChunk);
  1057. private:
  1058. PLUGINDEX GetChannelPlugin(const PlayState &playState, CHANNELINDEX nChn, PluginMutePriority respectMutes) const;
  1059. static PLUGINDEX GetActiveInstrumentPlugin(const ModChannel &chn, PluginMutePriority respectMutes);
  1060. IMixPlugin *GetChannelInstrumentPlugin(const ModChannel &chn) const;
  1061. public:
  1062. PLUGINDEX GetBestPlugin(const PlayState &playState, CHANNELINDEX nChn, PluginPriority priority, PluginMutePriority respectMutes) const;
  1063. };
  1064. #ifndef NO_PLUGINS
  1065. inline IMixPlugin* CSoundFile::GetInstrumentPlugin(INSTRUMENTINDEX instr) const noexcept
  1066. {
  1067. if(instr > 0 && instr <= GetNumInstruments() && Instruments[instr] && Instruments[instr]->nMixPlug && Instruments[instr]->nMixPlug <= MAX_MIXPLUGINS)
  1068. return m_MixPlugins[Instruments[instr]->nMixPlug - 1].pMixPlugin;
  1069. else
  1070. return nullptr;
  1071. }
  1072. #endif // NO_PLUGINS
  1073. ///////////////////////////////////////////////////////////
  1074. // Low-level Mixing functions
  1075. #define FADESONGDELAY 100
  1076. MPT_CONSTEXPRINLINE int8 MOD2XMFineTune(int v) { return static_cast<int8>(static_cast<uint8>(v) << 4); }
  1077. MPT_CONSTEXPRINLINE int8 XM2MODFineTune(int v) { return static_cast<int8>(static_cast<uint8>(v) >> 4); }
  1078. // Read instrument property with 'code' and 'size' from 'file' to instrument 'pIns'.
  1079. void ReadInstrumentExtensionField(ModInstrument* pIns, const uint32 code, const uint16 size, FileReader &file);
  1080. // Read instrument property with 'code' from 'file' to instrument 'pIns'.
  1081. void ReadExtendedInstrumentProperty(ModInstrument* pIns, const uint32 code, FileReader &file);
  1082. // Read extended instrument properties from 'file' to instrument 'pIns'.
  1083. void ReadExtendedInstrumentProperties(ModInstrument* pIns, FileReader &file);
  1084. OPENMPT_NAMESPACE_END