| 1 | /* |
| 2 | * This source code is public domain. |
| 3 | * |
| 4 | * Authors: Kenton Varda <[email protected]> (C interface wrapper) |
| 5 | */ |
| 6 | |
| 7 | #include "stdafx.h"cxx . . $ `<file>/ext/psmplug/stdafx.h`/ |
| 8 | #include "psmplug.h"cxx . . $ `<file>/ext/psmplug/psmplug.h`/ |
| 9 | #include "sndfile.h"cxx . . $ `<file>/ext/psmplug/sndfile.h`/ |
| 10 | |
| 11 | struct _ModPlugFilecxx . . $ _ModPlugFile# |
| 12 | { |
| 13 | CSoundFilecxx . . $ CSoundFile# mSoundFilecxx . . $ _ModPlugFile#mSoundFile.; |
| 14 | }; |
| 15 | |
| 16 | namespace ModPlugcxx . . $ ModPlug/ |
| 17 | { |
| 18 | ModPlug_Settings gSettingscxx . . $ ModPlug/gSettings. = |
| 19 | { |
| 20 | MODPLUG_ENABLE_OVERSAMPLING | MODPLUG_ENABLE_NOISE_REDUCTION, |
| 21 | |
| 22 | 2, // mChannels |
| 23 | 16, // mBits |
| 24 | 44100, // mFrequency |
| 25 | MODPLUG_RESAMPLE_LINEAR, //mResamplingMode |
| 26 | |
| 27 | 128, // mStereoSeparation |
| 28 | 32, // mMaxMixChannels |
| 29 | 0, |
| 30 | 0, |
| 31 | 0, |
| 32 | 0, |
| 33 | 0, |
| 34 | 0, |
| 35 | 0 |
| 36 | }; |
| 37 | |
| 38 | int gSampleSizecxx . . $ ModPlug/gSampleSize.; |
| 39 | |
| 40 | void UpdateSettingscxx . . $ ModPlug/UpdateSettings(b45ddcbc8423892c).(bool updateBasicConfig) |
| 41 | { |
| 42 | if(gSettingscxx . . $ ModPlug/gSettings..mFlags & MODPLUG_ENABLE_REVERB) |
| 43 | { |
| 44 | CSoundFilecxx . . $ CSoundFile#::SetReverbParameterscxx . . $ CSoundFile#SetReverbParameters(8e1b545ea3aecce3).(gSettingscxx . . $ ModPlug/gSettings..mReverbDepth, |
| 45 | gSettingscxx . . $ ModPlug/gSettings..mReverbDelay); |
| 46 | } |
| 47 | |
| 48 | if(gSettingscxx . . $ ModPlug/gSettings..mFlags & MODPLUG_ENABLE_MEGABASS) |
| 49 | { |
| 50 | CSoundFilecxx . . $ CSoundFile#::SetXBassParameterscxx . . $ CSoundFile#SetXBassParameters(8e1b545ea3aecce3).(gSettingscxx . . $ ModPlug/gSettings..mBassAmount, |
| 51 | gSettingscxx . . $ ModPlug/gSettings..mBassRange); |
| 52 | } |
| 53 | else // modplug seems to ignore the SetWaveConfigEx() setting for bass boost |
| 54 | CSoundFilecxx . . $ CSoundFile#::SetXBassParameterscxx . . $ CSoundFile#SetXBassParameters(8e1b545ea3aecce3).(0, 0); |
| 55 | |
| 56 | if(gSettingscxx . . $ ModPlug/gSettings..mFlags & MODPLUG_ENABLE_SURROUND) |
| 57 | { |
| 58 | CSoundFilecxx . . $ CSoundFile#::SetSurroundParameterscxx . . $ CSoundFile#SetSurroundParameters(8e1b545ea3aecce3).(gSettingscxx . . $ ModPlug/gSettings..mSurroundDepth, |
| 59 | gSettingscxx . . $ ModPlug/gSettings..mSurroundDelay); |
| 60 | } |
| 61 | |
| 62 | if(updateBasicConfig) |
| 63 | { |
| 64 | CSoundFilecxx . . $ CSoundFile#::SetWaveConfigcxx . . $ CSoundFile#SetWaveConfig(ba40b00a3e4c32e8).(gSettingscxx . . $ ModPlug/gSettings..mFrequency, |
| 65 | gSettingscxx . . $ ModPlug/gSettings..mBits, |
| 66 | gSettingscxx . . $ ModPlug/gSettings..mChannels); |
| 67 | CSoundFilecxx . . $ CSoundFile#::SetMixConfigcxx . . $ CSoundFile#SetMixConfig(8e1b545ea3aecce3).(gSettingscxx . . $ ModPlug/gSettings..mStereoSeparation, |
| 68 | gSettingscxx . . $ ModPlug/gSettings..mMaxMixChannels); |
| 69 | |
| 70 | gSampleSizecxx . . $ ModPlug/gSampleSize. = gSettingscxx . . $ ModPlug/gSettings..mBits / 8 * gSettingscxx . . $ ModPlug/gSettings..mChannels; |
| 71 | } |
| 72 | |
| 73 | CSoundFilecxx . . $ CSoundFile#::SetWaveConfigExcxx . . $ CSoundFile#SetWaveConfigEx(dde2bda68385446b).(gSettingscxx . . $ ModPlug/gSettings..mFlags & MODPLUG_ENABLE_SURROUND, |
| 74 | !(gSettingscxx . . $ ModPlug/gSettings..mFlags & MODPLUG_ENABLE_OVERSAMPLING), |
| 75 | gSettingscxx . . $ ModPlug/gSettings..mFlags & MODPLUG_ENABLE_REVERB, |
| 76 | true, |
| 77 | gSettingscxx . . $ ModPlug/gSettings..mFlags & MODPLUG_ENABLE_MEGABASS, |
| 78 | gSettingscxx . . $ ModPlug/gSettings..mFlags & MODPLUG_ENABLE_NOISE_REDUCTION, |
| 79 | false); |
| 80 | CSoundFilecxx . . $ CSoundFile#::SetResamplingModecxx . . $ CSoundFile#SetResamplingMode(dfa6e707f7696010).(gSettingscxx . . $ ModPlug/gSettings..mResamplingMode); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | ModPlugFile* ModPlug_Loadcxx . . $ ModPlug_Load(563b7b0e33ea35f6).(const void* data, int size) |
| 85 | { |
| 86 | ModPlugFile* result = new ModPlugFile; |
| 87 | ModPlugcxx . . $ ModPlug/::UpdateSettingscxx . . $ ModPlug/UpdateSettings(b45ddcbc8423892c).(true); |
| 88 | if(result->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..Createcxx . . $ CSoundFile#Create(41ee87f0602ae969).((const BYTEcxx . . $ BYTE#*)data, size)) |
| 89 | { |
| 90 | result->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..SetRepeatCountcxx . . $ CSoundFile#SetRepeatCount(d4f767463ce0a6b3).(ModPlugcxx . . $ ModPlug/::gSettingscxx . . $ ModPlug/gSettings..mLoopCount); |
| 91 | return result; |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | delete result; |
| 96 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | void ModPlug_Unloadcxx . . $ ModPlug_Unload(c7708ca50543e69f).(ModPlugFile* file) |
| 101 | { |
| 102 | file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..Destroycxx . . $ CSoundFile#Destroy(c9857a73d68e59ba).(); |
| 103 | delete file; |
| 104 | } |
| 105 | |
| 106 | int ModPlug_Readcxx . . $ ModPlug_Read(149b34bf0b9b3593).(ModPlugFile* file, void* buffer, int size) |
| 107 | { |
| 108 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..Readcxx . . $ CSoundFile#Read(35feec062aeef876).(buffer, size) * ModPlugcxx . . $ ModPlug/::gSampleSizecxx . . $ ModPlug/gSampleSize.; |
| 109 | } |
| 110 | |
| 111 | const char* ModPlug_GetNamecxx . . $ ModPlug_GetName(6ac1c8a97ef696f3).(ModPlugFile* file) |
| 112 | { |
| 113 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetTitlecxx . . $ CSoundFile#GetTitle(a9f41ea0e82d88cf).(); |
| 114 | } |
| 115 | |
| 116 | int ModPlug_GetLengthcxx . . $ ModPlug_GetLength(ae380be8f10fef9e).(ModPlugFile* file) |
| 117 | { |
| 118 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetSongTimecxx . . $ CSoundFile#GetSongTime(db52760e79bf9054).() * 1000; |
| 119 | } |
| 120 | |
| 121 | void ModPlug_InitMixerCallbackcxx . . $ ModPlug_InitMixerCallback(c762e93e3109d9d0).(ModPlugFile* file,ModPlugMixerProc proc) |
| 122 | { |
| 123 | file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..gpSndMixHookcxx . . $ CSoundFile#gpSndMixHook. = (LPSNDMIXHOOKPROCcxx . . $ LPSNDMIXHOOKPROC#)proc ; |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | void ModPlug_UnloadMixerCallbackcxx . . $ ModPlug_UnloadMixerCallback(c7708ca50543e69f).(ModPlugFile* file) |
| 128 | { |
| 129 | file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..gpSndMixHookcxx . . $ CSoundFile#gpSndMixHook. = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 130 | return ; |
| 131 | } |
| 132 | |
| 133 | unsigned int ModPlug_GetMasterVolumecxx . . $ ModPlug_GetMasterVolume(6b56b393242946de).(ModPlugFile* file) |
| 134 | { |
| 135 | return (unsigned int)file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nMasterVolumecxx . . $ CSoundFile#m_nMasterVolume.; |
| 136 | } |
| 137 | |
| 138 | void ModPlug_SetMasterVolumecxx . . $ ModPlug_SetMasterVolume(bdb34542c3d058fa).(ModPlugFile* file,unsigned int cvol) |
| 139 | { |
| 140 | (void)file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..SetMasterVolumecxx . . $ CSoundFile#SetMasterVolume(f97cc7cf123a0aff).( (UINTcxx . . $ UINT#)cvol, |
| 141 | FALSEcxx . . $ `ext/psmplug/stdafx.h:93:9`! ); |
| 142 | return ; |
| 143 | } |
| 144 | |
| 145 | unsigned int ModPlug_GetMusicTempoFactorcxx . . $ ModPlug_GetMusicTempoFactor(6b56b393242946de).(ModPlugFile* file) |
| 146 | { |
| 147 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nTempoFactorcxx . . $ CSoundFile#m_nTempoFactor.; |
| 148 | } |
| 149 | |
| 150 | void ModPlug_SetMusicTempoFactorcxx . . $ ModPlug_SetMusicTempoFactor(bdb34542c3d058fa).(ModPlugFile* file, unsigned int ctemp) |
| 151 | { |
| 152 | (void)file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..SetTempoFactorcxx . . $ CSoundFile#SetTempoFactor(dfa6e707f7696010).((UINTcxx . . $ UINT#)ctemp); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | int ModPlug_GetCurrentSpeedcxx . . $ ModPlug_GetCurrentSpeed(ae380be8f10fef9e).(ModPlugFile* file) |
| 157 | { |
| 158 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nMusicSpeedcxx . . $ CSoundFile#m_nMusicSpeed.; |
| 159 | } |
| 160 | |
| 161 | int ModPlug_GetCurrentTempocxx . . $ ModPlug_GetCurrentTempo(ae380be8f10fef9e).(ModPlugFile* file) |
| 162 | { |
| 163 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nMusicTempocxx . . $ CSoundFile#m_nMusicTempo.; |
| 164 | } |
| 165 | |
| 166 | int ModPlug_GetCurrentOrdercxx . . $ ModPlug_GetCurrentOrder(ae380be8f10fef9e).(ModPlugFile* file) |
| 167 | { |
| 168 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetCurrentOrdercxx . . $ CSoundFile#GetCurrentOrder(ddd8539a2fcdd4ce).(); |
| 169 | } |
| 170 | |
| 171 | int ModPlug_GetCurrentPatterncxx . . $ ModPlug_GetCurrentPattern(ae380be8f10fef9e).(ModPlugFile* file) |
| 172 | { |
| 173 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetCurrentPatterncxx . . $ CSoundFile#GetCurrentPattern(ddd8539a2fcdd4ce).(); |
| 174 | } |
| 175 | |
| 176 | int ModPlug_GetCurrentRowcxx . . $ ModPlug_GetCurrentRow(ae380be8f10fef9e).(ModPlugFile* file) |
| 177 | { |
| 178 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nRowcxx . . $ CSoundFile#m_nRow.; |
| 179 | } |
| 180 | |
| 181 | int ModPlug_GetPlayingChannelscxx . . $ ModPlug_GetPlayingChannels(ae380be8f10fef9e).(ModPlugFile* file) |
| 182 | { |
| 183 | return ( file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nMixChannelscxx . . $ CSoundFile#m_nMixChannels. < file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nMaxMixChannelscxx . . $ CSoundFile#m_nMaxMixChannels. ? file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nMixChannelscxx . . $ CSoundFile#m_nMixChannels. : file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nMaxMixChannelscxx . . $ CSoundFile#m_nMaxMixChannels. ); |
| 184 | } |
| 185 | |
| 186 | void ModPlug_SeekOrdercxx . . $ ModPlug_SeekOrder(c60734bc66628a05).(ModPlugFile* file,int order) |
| 187 | { |
| 188 | file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..SetCurrentOrdercxx . . $ CSoundFile#SetCurrentOrder(cb2f890c2fdad230).(order); |
| 189 | } |
| 190 | |
| 191 | int ModPlug_GetModuleTypecxx . . $ ModPlug_GetModuleType(ae380be8f10fef9e).(ModPlugFile* file) |
| 192 | { |
| 193 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nTypecxx . . $ CSoundFile#m_nType.; |
| 194 | } |
| 195 | |
| 196 | char* ModPlug_GetMessagecxx . . $ ModPlug_GetMessage(d2e5cec9d7e647cf).(ModPlugFile* file) |
| 197 | { |
| 198 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_lpszSongCommentscxx . . $ CSoundFile#m_lpszSongComments.; |
| 199 | } |
| 200 | |
| 201 | unsigned int ModPlug_NumInstrumentscxx . . $ ModPlug_NumInstruments(6b56b393242946de).(ModPlugFile* file) |
| 202 | { |
| 203 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nInstrumentscxx . . $ CSoundFile#m_nInstruments.; |
| 204 | } |
| 205 | |
| 206 | unsigned int ModPlug_NumSamplescxx . . $ ModPlug_NumSamples(6b56b393242946de).(ModPlugFile* file) |
| 207 | { |
| 208 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..m_nSamplescxx . . $ CSoundFile#m_nSamples.; |
| 209 | } |
| 210 | |
| 211 | unsigned int ModPlug_NumPatternscxx . . $ ModPlug_NumPatterns(6b56b393242946de).(ModPlugFile* file) |
| 212 | { |
| 213 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetNumPatternscxx . . $ CSoundFile#GetNumPatterns(ddd8539a2fcdd4ce).(); |
| 214 | } |
| 215 | |
| 216 | unsigned int ModPlug_NumChannelscxx . . $ ModPlug_NumChannels(6b56b393242946de).(ModPlugFile* file) |
| 217 | { |
| 218 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetNumChannelscxx . . $ CSoundFile#GetNumChannels(ddd8539a2fcdd4ce).(); |
| 219 | } |
| 220 | |
| 221 | unsigned int ModPlug_SampleNamecxx . . $ ModPlug_SampleName(f012c11a079d3cd1).(ModPlugFile* file,unsigned int qual,char* buff) |
| 222 | { |
| 223 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetSampleNamecxx . . $ CSoundFile#GetSampleName(bd66cc884609c19d).(qual,buff); |
| 224 | } |
| 225 | |
| 226 | unsigned int ModPlug_InstrumentNamecxx . . $ ModPlug_InstrumentName(f012c11a079d3cd1).(ModPlugFile* file,unsigned int qual,char* buff) |
| 227 | { |
| 228 | return file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetInstrumentNamecxx . . $ CSoundFile#GetInstrumentName(bd66cc884609c19d).(qual,buff); |
| 229 | } |
| 230 | |
| 231 | ModPlugNote* ModPlug_GetPatterncxx . . $ ModPlug_GetPattern(cbdfeebc6e485292).(ModPlugFile* file,int pattern,unsigned int* numrows) { |
| 232 | if ( pattern<MAX_PATTERNScxx . . $ `ext/psmplug/sndfile.h:24:9`! && pattern >= 0) { |
| 233 | if (file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..Patternscxx . . $ CSoundFile#Patterns.[pattern]) { |
| 234 | if (numrows) *numrows=(unsigned int)file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..PatternSizecxx . . $ CSoundFile#PatternSize.[pattern]; |
| 235 | return (ModPlugNote*)file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..Patternscxx . . $ CSoundFile#Patterns.[pattern]; |
| 236 | } |
| 237 | } |
| 238 | return NULLcxx . . $ `<external>/15298297234472979974/stddef.h:416:9`!; |
| 239 | } |
| 240 | |
| 241 | void ModPlug_Seekcxx . . $ ModPlug_Seek(c60734bc66628a05).(ModPlugFile* file, int millisecond) |
| 242 | { |
| 243 | int maxpos; |
| 244 | int maxtime = file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetSongTimecxx . . $ CSoundFile#GetSongTime(db52760e79bf9054).() * 1000; |
| 245 | float postime; |
| 246 | |
| 247 | if(millisecond > maxtime) |
| 248 | millisecond = maxtime; |
| 249 | maxpos = file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetMaxPositioncxx . . $ CSoundFile#GetMaxPosition(ddd8539a2fcdd4ce).(); |
| 250 | postime = 0.0f; |
| 251 | if (maxtime != 0) |
| 252 | postime = (float)maxpos / (float)maxtime; |
| 253 | |
| 254 | file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..SetCurrentPoscxx . . $ CSoundFile#SetCurrentPos(cb2f890c2fdad230).((int)(millisecond * postime)); |
| 255 | } |
| 256 | |
| 257 | int ModPlug_Tellcxx . . $ ModPlug_Tell(ae380be8f10fef9e).(ModPlugFile *file) |
| 258 | { |
| 259 | int currentPos = (int)file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetCurrentPoscxx . . $ CSoundFile#GetCurrentPos(ddd8539a2fcdd4ce).(); |
| 260 | int maxpos; |
| 261 | int maxtime = (int)file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetSongTimecxx . . $ CSoundFile#GetSongTime(db52760e79bf9054).() * 1000; |
| 262 | float postime; |
| 263 | maxpos = (int)file->mSoundFilecxx . . $ _ModPlugFile#mSoundFile..GetMaxPositioncxx . . $ CSoundFile#GetMaxPosition(ddd8539a2fcdd4ce).(); |
| 264 | postime = 0.0f; |
| 265 | if (maxtime != 0.0f) |
| 266 | postime = (float)maxpos / (float)maxtime; |
| 267 | if (postime == 0.0f) |
| 268 | return 0; |
| 269 | return (int) ((float)currentPos / postime); |
| 270 | } |
| 271 | |
| 272 | void ModPlug_GetSettingscxx . . $ ModPlug_GetSettings(a3d84609cb4f70ff).(ModPlug_Settings* settings) |
| 273 | { |
| 274 | memcpy(settings, &ModPlugcxx . . $ ModPlug/::gSettingscxx . . $ ModPlug/gSettings., sizeof(ModPlug_Settings)); |
| 275 | } |
| 276 | |
| 277 | void ModPlug_SetSettingscxx . . $ ModPlug_SetSettings(5183da0f62b50569).(const ModPlug_Settings* settings) |
| 278 | { |
| 279 | memcpy(&ModPlugcxx . . $ ModPlug/::gSettingscxx . . $ ModPlug/gSettings., settings, sizeof(ModPlug_Settings)); |
| 280 | ModPlugcxx . . $ ModPlug/::UpdateSettingscxx . . $ ModPlug/UpdateSettings(b45ddcbc8423892c).(false); // do not update basic config. |
| 281 | } |