Use MixerObject's singleton-pattern to manage the channel
This commit is contained in:
parent
91cd907c4e
commit
1d123367a5
3 changed files with 9 additions and 19 deletions
|
@ -106,18 +106,6 @@ MixerChannel * MIXER_FindChannel(const char * name);
|
|||
/* Find the device you want to delete with findchannel "delchan gets deleted" */
|
||||
void MIXER_DelChannel(MixerChannel* delchan);
|
||||
|
||||
// A smart pointer deleter for MixerChannel objects
|
||||
// Use-case:
|
||||
// std::unique_ptr<MixerChannel, MixerChannelDeleter> myChannel;
|
||||
// myChannel.reset(MIXER_AddChannel(...));
|
||||
//
|
||||
struct MixerChannelDeleter {
|
||||
void operator()(MixerChannel *channel) {
|
||||
if (channel)
|
||||
MIXER_DelChannel(channel);
|
||||
}
|
||||
};
|
||||
|
||||
/* Object to maintain a mixerchannel; As all objects it registers itself with create
|
||||
* and removes itself when destroyed. */
|
||||
class MixerObject{
|
||||
|
|
|
@ -221,16 +221,17 @@ public:
|
|||
|
||||
private:
|
||||
static struct imagePlayer {
|
||||
Bit16s buffer[MIXER_BUFSIZE * 2] = {0};
|
||||
std::unique_ptr<SDL_mutex, SdlMutexDeleter> mutex = nullptr;
|
||||
std::unique_ptr<MixerChannel, MixerChannelDeleter> channel = nullptr;
|
||||
std::weak_ptr<TrackFile> trackFile;
|
||||
MixerObject channelManager;
|
||||
MixerChannel *channel = nullptr;
|
||||
CDROM_Interface_Image *cd = nullptr;
|
||||
void (MixerChannel::*addFrames) (Bitu, const Bit16s*) = nullptr;
|
||||
uint64_t playedTrackFrames = 0;
|
||||
uint64_t totalTrackFrames = 0;
|
||||
uint32_t startSector = 0;
|
||||
uint32_t totalRedbookFrames = 0;
|
||||
int16_t buffer[MIXER_BUFSIZE * REDBOOK_CHANNELS] = {0};
|
||||
bool isPlaying = false;
|
||||
bool isPaused = false;
|
||||
} player;
|
||||
|
|
|
@ -281,11 +281,12 @@ CDROM_Interface_Image::CDROM_Interface_Image(Bit8u _subUnit)
|
|||
images[subUnit] = this;
|
||||
if (refCount == 0) {
|
||||
player.mutex.reset(SDL_CreateMutex());
|
||||
// channel is kept dormant except during cdrom playback periods
|
||||
player.channel.reset(MIXER_AddChannel(&CDAudioCallBack, 0, "CDAUDIO"));
|
||||
player.channel->Enable(false);
|
||||
if (!player.channel) {
|
||||
player.channel = player.channelManager.Install(&CDAudioCallBack, 0, "CDAUDIO");
|
||||
player.channel->Enable(false); // only enabled during playback periods
|
||||
}
|
||||
#ifdef DEBUG
|
||||
LOG_MSG("CDROM: Initialized the CDAUDIO mixer channel and mutex");
|
||||
LOG_MSG("CDROM: Initialized the CDAUDIO mixer channel and mutex");
|
||||
#endif
|
||||
}
|
||||
refCount++;
|
||||
|
@ -807,7 +808,7 @@ void CDROM_Interface_Image::CDAudioCallBack(Bitu desired_track_frames)
|
|||
|
||||
// uses either the stereo or mono and native or
|
||||
// nonnative AddSamples call assigned during construction
|
||||
(player.channel.get()->*player.addFrames)(decoded_track_frames, player.buffer);
|
||||
(player.channel->*player.addFrames)(decoded_track_frames, player.buffer);
|
||||
|
||||
if (player.playedTrackFrames >= player.totalTrackFrames) {
|
||||
#ifdef DEBUG
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue