diff --git a/include/mixer.h b/include/mixer.h index a2aff129..d352a804 100644 --- a/include/mixer.h +++ b/include/mixer.h @@ -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 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{ diff --git a/src/dos/cdrom.h b/src/dos/cdrom.h index 6e823be8..94630e25 100644 --- a/src/dos/cdrom.h +++ b/src/dos/cdrom.h @@ -221,16 +221,17 @@ public: private: static struct imagePlayer { - Bit16s buffer[MIXER_BUFSIZE * 2] = {0}; std::unique_ptr mutex = nullptr; - std::unique_ptr channel = nullptr; std::weak_ptr 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; diff --git a/src/dos/cdrom_image.cpp b/src/dos/cdrom_image.cpp index 1ccd220a..b9791653 100644 --- a/src/dos/cdrom_image.cpp +++ b/src/dos/cdrom_image.cpp @@ -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