123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- #pragma once
- #include "openmpt/all/BuildSettings.hpp"
- OPENMPT_NAMESPACE_BEGIN
- class CSoundFile;
- struct ModSample
- {
- SmpLength nLength;
- SmpLength nLoopStart, nLoopEnd;
- SmpLength nSustainStart, nSustainEnd;
- union
- {
- void *pSample;
- int8 *pSample8;
- int16 *pSample16;
- } pData;
- uint32 nC5Speed;
- uint16 nPan;
- uint16 nVolume;
- uint16 nGlobalVol;
- SampleFlags uFlags;
- int8 RelativeTone;
- int8 nFineTune;
- VibratoType nVibType;
- uint8 nVibSweep;
- uint8 nVibDepth;
- uint8 nVibRate;
- uint8 rootNote;
-
- mpt::charbuf<MAX_SAMPLEFILENAME> filename;
- std::string GetFilename() const { return filename; }
- union
- {
- std::array<SmpLength, 9> cues;
- OPLPatch adlib;
- };
- ModSample(MODTYPE type = MOD_TYPE_NONE)
- {
- pData.pSample = nullptr;
- Initialize(type);
- }
- bool HasSampleData() const noexcept
- {
- MPT_ASSERT(!pData.pSample || (pData.pSample && nLength > 0));
- return pData.pSample != nullptr && nLength != 0;
- }
- MPT_FORCEINLINE const void *samplev() const noexcept
- {
- return pData.pSample;
- }
- MPT_FORCEINLINE void *samplev() noexcept
- {
- return pData.pSample;
- }
- MPT_FORCEINLINE const std::byte *sampleb() const noexcept
- {
- return mpt::void_cast<const std::byte*>(pData.pSample);
- }
- MPT_FORCEINLINE std::byte *sampleb() noexcept
- {
- return mpt::void_cast<std::byte*>(pData.pSample);
- }
- MPT_FORCEINLINE const int8 *sample8() const noexcept
- {
- MPT_ASSERT(GetElementarySampleSize() == sizeof(int8));
- return pData.pSample8;
- }
- MPT_FORCEINLINE int8 *sample8() noexcept
- {
- MPT_ASSERT(GetElementarySampleSize() == sizeof(int8));
- return pData.pSample8;
- }
- MPT_FORCEINLINE const int16 *sample16() const noexcept
- {
- MPT_ASSERT(GetElementarySampleSize() == sizeof(int16));
- return pData.pSample16;
- }
- MPT_FORCEINLINE int16 *sample16() noexcept
- {
- MPT_ASSERT(GetElementarySampleSize() == sizeof(int16));
- return pData.pSample16;
- }
-
- uint8 GetElementarySampleSize() const noexcept { return (uFlags & CHN_16BIT) ? 2 : 1; }
-
- uint8 GetNumChannels() const noexcept { return (uFlags & CHN_STEREO) ? 2 : 1; }
-
- uint8 GetBytesPerSample() const noexcept { return GetElementarySampleSize() * GetNumChannels(); }
-
- SmpLength GetSampleSizeInBytes() const noexcept { return nLength * GetBytesPerSample(); }
-
-
- uint32 GetSampleRate(const MODTYPE type) const;
-
- void Convert(MODTYPE fromType, MODTYPE toType);
-
- void Initialize(MODTYPE type = MOD_TYPE_NONE);
-
- bool CopyWaveform(const ModSample &smpFrom);
-
-
- size_t AllocateSample();
-
- static void *AllocateSample(SmpLength numFrames, size_t bytesPerSample);
-
- static size_t GetRealSampleBufferSize(SmpLength numSamples, size_t bytesPerSample);
- void FreeSample();
- static void FreeSample(void *samplePtr);
-
- void SetLoop(SmpLength start, SmpLength end, bool enable, bool pingpong, CSoundFile &sndFile);
-
- void SetSustainLoop(SmpLength start, SmpLength end, bool enable, bool pingpong, CSoundFile &sndFile);
-
- void PrecomputeLoops(CSoundFile &sndFile, bool updateChannels = true);
- constexpr bool HasLoop() const noexcept { return uFlags[CHN_LOOP] && nLoopEnd > nLoopStart; }
- constexpr bool HasSustainLoop() const noexcept { return uFlags[CHN_SUSTAINLOOP] && nSustainEnd > nSustainStart; }
- constexpr bool HasPingPongLoop() const noexcept { return uFlags.test_all(CHN_LOOP | CHN_PINGPONGLOOP) && nLoopEnd > nLoopStart; }
- constexpr bool HasPingPongSustainLoop() const noexcept { return uFlags.test_all(CHN_SUSTAINLOOP | CHN_PINGPONGSUSTAIN) && nSustainEnd > nSustainStart; }
-
- void SanitizeLoops();
-
- static uint32 TransposeToFrequency(int transpose, int finetune = 0);
- void TransposeToFrequency();
- static std::pair<int8, int8> FrequencyToTranspose(uint32 freq);
- void FrequencyToTranspose();
-
- void Transpose(double amount);
-
- bool HasAnyCuePoints() const;
-
- bool HasCustomCuePoints() const;
- void SetDefaultCuePoints();
-
- void Set16BitCuePoints();
- void RemoveAllCuePoints();
- void SetAdlib(bool enable, OPLPatch patch = OPLPatch{{}});
- };
- OPENMPT_NAMESPACE_END
|