Enforce only one player at a time, pause any other

This commit is contained in:
Seth Polsley 2020-07-10 17:02:04 -05:00
parent 47fca465ba
commit 3e32a6da32
3 changed files with 40 additions and 9 deletions

View File

@ -249,11 +249,13 @@ static void stream_func(void *arg, uint8 *stream, int stream_len)
} else {
// Audio not active, play silence
silence: memset(stream, silence_byte, stream_len);
silence: memset(stream, silence_byte, stream_len);
}
#if defined(BINCUE)
MixAudio_bincue(stream, stream_len, audio_volume);
#endif
}

View File

@ -153,6 +153,7 @@ static uint8 silence_byte;
// CD Player state; multiple players supported through vectors
std::vector<CDPlayer*> players;
CDPlayer* current_player = NULL;
CDPlayer* CSToPlayer(CueSheet* cs)
{
@ -687,14 +688,25 @@ bool GetPosition_bincue(void *fh, uint8 *pos)
return false;
}
void CDPause_currentplayer(CDPlayer* player) {
if (current_player && current_player != player) {
current_player->audiostatus = CDROM_AUDIO_PAUSED;
current_player = NULL;
}
}
bool CDPause_bincue(void *fh)
{
CueSheet *cs = (CueSheet *) fh;
CDPlayer *player = CSToPlayer(cs);
if (cs && player) {
// Pause another player if needed
CDPause_currentplayer(player);
// doesn't matter if it was playing, just ensure it's now paused
player->audiostatus = CDROM_AUDIO_PAUSED;
current_player = NULL;
return true;
}
return false;
@ -706,11 +718,16 @@ bool CDStop_bincue(void *fh)
CDPlayer *player = CSToPlayer(cs);
if (cs && player) {
// Pause another player if needed
CDPause_currentplayer(player);
#ifdef OSX_CORE_AUDIO
player->soundoutput.stop();
#endif
if (player->audiostatus != CDROM_AUDIO_INVALID)
player->audiostatus = CDROM_AUDIO_NO_STATUS;
current_player = NULL;
return true;
}
return false;
@ -722,8 +739,12 @@ bool CDResume_bincue(void *fh)
CDPlayer *player = CSToPlayer(cs);
if (cs && player) {
// doesn't matter if it was paused, just ensure it now plays
// Pause another player if needed
CDPause_currentplayer(player);
// doesn't matter if it was paused, just ensure this one plays now
player->audiostatus = CDROM_AUDIO_PLAY;
current_player = player;
return true;
}
return false;
@ -736,6 +757,9 @@ bool CDPlay_bincue(void *fh, uint8 start_m, uint8 start_s, uint8 start_f,
CDPlayer *player = CSToPlayer(cs);
if (cs && player) {
// Pause another player if needed
CDPause_currentplayer(player);
int track;
MSF msf;
@ -796,6 +820,7 @@ bool CDPlay_bincue(void *fh, uint8 start_m, uint8 start_s, uint8 start_f,
// should be from current track !
player->soundoutput.start(16, 2, 44100);
#endif
current_player = player;
return true;
}
}
@ -926,9 +951,13 @@ static uint8 *fill_buffer(int stream_len, CDPlayer* player)
#ifdef USE_SDL_AUDIO
void MixAudio_bincue(uint8 *stream, int stream_len, int volume)
{
for (std::vector<CDPlayer*>::iterator it = players.begin(); it != players.end(); ++it)
{
CDPlayer *player = *it;
// for (std::vector<CDPlayer*>::iterator it = players.begin(); it != players.end(); ++it)
// {
// CDPlayer *player = *it;
if (current_player) {
CDPlayer *player = current_player;
if (player->audio_enabled && (player->audiostatus == CDROM_AUDIO_PLAY)) {
uint8 *buf = fill_buffer(stream_len, player);

View File

@ -76,8 +76,8 @@
08CD42DC14B7B85B009CA2A2 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08CD42DB14B7B85B009CA2A2 /* Cocoa.framework */; };
08CD42E814B7B8AA009CA2A2 /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08CD42E714B7B8AA009CA2A2 /* Carbon.framework */; };
3D2C25B5221092BA00B635DE /* SheepVM.icns in Resources */ = {isa = PBXBuildFile; fileRef = 3D2C25B4221092BA00B635DE /* SheepVM.icns */; };
5D2143D324B2DD81008BB372 /* bincue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5D2143D224B2DD81008BB372 /* bincue.cpp */; };
5D2143D524B2DD90008BB372 /* bincue.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D2143D424B2DD90008BB372 /* bincue.h */; };
5D35961124B8F5FB0081EC8A /* bincue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5D35961024B8F5FA0081EC8A /* bincue.cpp */; };
5D55CB40225584D000FF8E81 /* cdrom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5D55CB3F225584D000FF8E81 /* cdrom.cpp */; };
5DDE94F92255C70C004D0E79 /* MacOSX_sound_if.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DDE94F82255C70C004D0E79 /* MacOSX_sound_if.h */; };
5DDE94FB2255C712004D0E79 /* MacOSX_sound_if.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5DDE94FA2255C712004D0E79 /* MacOSX_sound_if.cpp */; };
@ -337,8 +337,8 @@
08CD42DB14B7B85B009CA2A2 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
08CD42E714B7B8AA009CA2A2 /* Carbon.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Carbon.framework; path = /System/Library/Frameworks/Carbon.framework; sourceTree = "<absolute>"; };
3D2C25B4221092BA00B635DE /* SheepVM.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = SheepVM.icns; sourceTree = "<group>"; };
5D2143D224B2DD81008BB372 /* bincue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bincue.cpp; path = ../bincue.cpp; sourceTree = "<group>"; };
5D2143D424B2DD90008BB372 /* bincue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bincue.h; sourceTree = "<group>"; };
5D35961024B8F5FA0081EC8A /* bincue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = bincue.cpp; path = ../../../BasiliskII/src/bincue.cpp; sourceTree = "<group>"; };
5D3967BF2328D315003925D6 /* adb.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = adb.cpp; path = ../../../BasiliskII/src/adb.cpp; sourceTree = "<group>"; };
5D55CB3F225584D000FF8E81 /* cdrom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cdrom.cpp; path = ../../../BasiliskII/src/cdrom.cpp; sourceTree = "<group>"; };
5DDE94F82255C70C004D0E79 /* MacOSX_sound_if.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MacOSX_sound_if.h; path = ../../../BasiliskII/src/MacOSX/MacOSX_sound_if.h; sourceTree = "<group>"; };
@ -488,7 +488,7 @@
087B91B11B780EC900825F7F /* CrossPlatform */,
5D3967BF2328D315003925D6 /* adb.cpp */,
5DF4CB7E22B5BD5D00512A86 /* audio.cpp */,
5D2143D224B2DD81008BB372 /* bincue.cpp */,
5D35961024B8F5FA0081EC8A /* bincue.cpp */,
5D55CB3F225584D000FF8E81 /* cdrom.cpp */,
0856CD7D14A99EEF000B1711 /* disk.cpp */,
0856CD7E14A99EEF000B1711 /* dummy */,
@ -1167,7 +1167,7 @@
0856D10E14A99EF1000B1711 /* sys_unix.cpp in Sources */,
E44C461720D262B0000583AE /* cksum.c in Sources */,
0856D10F14A99EF1000B1711 /* timer_unix.cpp in Sources */,
5D2143D324B2DD81008BB372 /* bincue.cpp in Sources */,
5D35961124B8F5FB0081EC8A /* bincue.cpp in Sources */,
0856D11114A99EF1000B1711 /* user_strings_unix.cpp in Sources */,
E44C461020D262B0000583AE /* slirp.c in Sources */,
0856D11614A99EF1000B1711 /* xpram_unix.cpp in Sources */,