Skip to content

Commit

Permalink
Fix options menu crashing on track change
Browse files Browse the repository at this point in the history
and do device number checks with winmm calls instead of returning 1.
  • Loading branch information
MnHebi authored Mar 13, 2023
1 parent aa0e5e0 commit 487f901
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 32 deletions.
52 changes: 22 additions & 30 deletions wgmus.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void wgmus_config()

DWORD CALLBACK WasapiProc(void *buffer, DWORD length, void *user)
{
DWORD c = BASS_ChannelGetData(str, buffer, length);
DWORD c = BASS_ChannelGetData(dec, buffer, length);
bassDecodePos = BASS_ChannelGetPosition(dec, BASS_POS_DECODE);
DWORD bassActivity = BASS_ChannelIsActive(dec);
int bassError = BASS_ErrorGetCode();
Expand All @@ -289,7 +289,7 @@ DWORD CALLBACK WasapiProc(void *buffer, DWORD length, void *user)
dprintf(" BASS finished playback\r\n");
BASS_StreamFree(dec);
playing = 0;
SendMessageA((HWND)0xffff, MM_MCINOTIFY, MCI_NOTIFY_SUCCESSFUL, 0x0000000);
SendMessageA((HWND)0x0000, MM_MCINOTIFY, MCI_NOTIFY_SUCCESSFUL, 0x0000000);
dprintf(" BASS Error: %d\r\n", bassError);
dprintf(" BASS no activity\r\n");
}
Expand All @@ -310,7 +310,7 @@ int bass_init()
BASS_WASAPI_INFO info;
BASS_WASAPI_GetInfo(&info);

str = BASS_Mixer_StreamCreate(info.freq, info.chans, BASS_STREAM_DECODE|BASS_SAMPLE_FLOAT|BASS_MIXER_NONSTOP);
str = BASS_Mixer_StreamCreate(info.freq, info.chans, BASS_STREAM_DECODE|BASS_SAMPLE_FLOAT);
playeractive = 1;
dprintf(" BASS_Init\r\n");
dprintf(" BASS WASAPI Device Number is: %d\r\n", BASS_WASAPI_GetDevice());
Expand Down Expand Up @@ -514,15 +514,20 @@ int bass_forceplay(const char *path)
{
if (noFiles == 0)
{
if (!BASS_Init(0, 48000, 0, 0, NULL))
wasapiDeviceCheck = BASS_WASAPI_GetDevice();
if(wasapiDeviceCheck == -1)
{
dprintf(" Bass Device Initialization FAILED\r\n");
}
if (!BASS_WASAPI_Init(-1, 0, 0, BASS_WASAPI_AUTOFORMAT, 0.1, 0, WasapiProc, NULL))
{
dprintf(" Wasapi Device Initialization FAILED\r\n");
if (!BASS_Init(0, 48000, 0, 0, NULL))
{
dprintf(" Bass Device Initialization FAILED\r\n");
}
if (!BASS_WASAPI_Init(-1, 0, 0, BASS_WASAPI_AUTOFORMAT, 0.1, 0, WasapiProc, NULL))
{
dprintf(" Wasapi Device Initialization FAILED\r\n");
}
}
playeractive = 1;
dprintf(" bass_forceplay\r\n");
dprintf(" BASS WASAPI Device Number is: %d\r\n", BASS_WASAPI_GetDevice());

if (PlaybackMode == 0)
Expand Down Expand Up @@ -552,6 +557,10 @@ int bass_play(const char *path)
{
if (noFiles == 0)
{
playeractive = 1;
dprintf(" bass_play\r\n");
dprintf(" BASS WASAPI Device Number is: %d\r\n", BASS_WASAPI_GetDevice());

if (PlaybackMode == 0)
{
PlaybackFinished = 0;
Expand All @@ -571,8 +580,6 @@ int bass_play(const char *path)
BASS_WASAPI_Start();
timesPlayed++;
}

dprintf(" BASS WASAPI Device Number is: %d\r\n", BASS_WASAPI_GetDevice());
}

return 0;
Expand Down Expand Up @@ -755,9 +762,9 @@ MCIERROR WINAPI wgmus_mciSendCommandA(MCIDEVICEID deviceID, UINT uintMsg, DWORD_
char trackMilliseconds[3];
if (AudioLibrary == 5)
{
QWORD bassLengthInSeconds = BASS_ChannelBytes2Seconds(str, BASS_ChannelGetLength(str, BASS_POS_BYTE));
QWORD bassLengthInSeconds = BASS_ChannelBytes2Seconds(dec, BASS_ChannelGetLength(dec, BASS_POS_BYTE));
dprintf(" BASS Length in seconds: %d\r\n", bassLengthInSeconds);
QWORD bassPosInSeconds = BASS_ChannelBytes2Seconds(str, BASS_ChannelGetPosition(str, BASS_POS_BYTE));
QWORD bassPosInSeconds = BASS_ChannelBytes2Seconds(dec, BASS_ChannelGetPosition(dec, BASS_POS_BYTE));
dprintf(" BASS Position in seconds: %d\r\n", bassPosInSeconds);
int bassMilliseconds = (bassLengthInSeconds - bassPosInSeconds) * 1000;
int bassSeconds = bassLengthInSeconds - bassPosInSeconds;
Expand Down Expand Up @@ -864,8 +871,8 @@ MCIERROR WINAPI wgmus_mciSendCommandA(MCIDEVICEID deviceID, UINT uintMsg, DWORD_
char trackMilliseconds[3];
if (AudioLibrary == 5)
{
QWORD bassLengthInSeconds = BASS_ChannelBytes2Seconds(str, BASS_ChannelGetLength(str, BASS_POS_BYTE));
QWORD bassPosInSeconds = BASS_ChannelBytes2Seconds(str, BASS_ChannelGetPosition(str, BASS_POS_BYTE));
QWORD bassLengthInSeconds = BASS_ChannelBytes2Seconds(dec, BASS_ChannelGetLength(dec, BASS_POS_BYTE));
QWORD bassPosInSeconds = BASS_ChannelBytes2Seconds(dec, BASS_ChannelGetPosition(dec, BASS_POS_BYTE));
int bassMilliseconds = (bassLengthInSeconds - bassPosInSeconds) * 1000;
int bassSeconds = bassLengthInSeconds - bassPosInSeconds;
int bassMinutes = (bassLengthInSeconds - bassPosInSeconds) / 60;
Expand Down Expand Up @@ -1256,11 +1263,6 @@ MCIERROR WINAPI wgmus_mciSendStringA(LPCTSTR lpszCmd, LPTSTR lpszRetStr, UINT cc
return err;
}

UINT WINAPI wgmus_auxGetNumDevs()
{
return 1;
}

MMRESULT WINAPI wgmus_auxGetDevCapsA(UINT_PTR uintptrDeviceID, LPAUXCAPSA lpCapsa, UINT cbCaps)
{
dprintf(" wgmus_auxGetDevCapsA(uintptrDeviceID=%08X, lpCapsa=%p, cbCaps=%08X\n", uintptrDeviceID, lpCapsa, cbCaps);
Expand Down Expand Up @@ -1378,15 +1380,5 @@ MMRESULT WINAPI wgmus_auxSetVolume(UINT uintDeviceID, DWORD dwVolume)
WasapiVolumeConfig(wasapiVolume, finalVolume);
}

if (dwVolume == oldVolume)
{
return MMSYSERR_NOERROR;
}

return MMSYSERR_NOERROR;
}

UINT WINAPI wgmus_waveOutGetNumDevs()
{
return 1;
}
4 changes: 2 additions & 2 deletions wgmus.def
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ EXPORTS
mciSendStringA = wgmus_mciSendStringA
mciSendCommandA = wgmus_mciSendCommandA
auxGetDevCapsA = wgmus_auxGetDevCapsA
auxGetNumDevs = wgmus_auxGetNumDevs
auxGetNumDevs = winmm.auxGetNumDevs
auxGetVolume = wgmus_auxGetVolume
auxSetVolume = wgmus_auxSetVolume
PlaySoundA = winmm.PlaySoundA
waveOutGetNumDevs = wgmus_waveOutGetNumDevs
waveOutGetNumDevs = winmm.waveOutGetNumDevs
waveOutGetVolume = winmm.waveOutGetVolume
waveOutSetVolume = winmm.waveOutSetVolume

0 comments on commit 487f901

Please sign in to comment.