Commit 5e9d2ef1 authored by Gerhard Stein's avatar Gerhard Stein

More sound fixes

parent f188da6a
......@@ -375,23 +375,39 @@ void Audio::playStereosoundSlot(unsigned char slotplay,
// first try to find an empty channel
for( auto sndChnl = mSndChnlVec.begin() ; sndChnl != mSndChnlVec.end() ; sndChnl++)
for( auto &sndChnl : mSndChnlVec)
{
CSoundSlot &currentSlot = *sndChnl->getCurrentSoundPtr();
// check if channel is still playing
if (!sndChnl->isPlaying()
||
chosenSlot.priority >= currentSlot.priority )
{
if(mAudioSpec.channels == 2)
auto slotPtr = sndChnl.getCurrentSoundPtr();
if(slotPtr)
{
CSoundSlot &currentSlot = *(slotPtr);
if (!sndChnl.isPlaying() ||
chosenSlot.priority >= currentSlot.priority )
{
sndChnl->setBalance(balance);
if(mAudioSpec.channels == 2)
{
sndChnl.setBalance(balance);
}
sndChnl.setupSound(chosenSlot,
(mode==SoundPlayMode::PLAY_FORCE) ? true : false );
break;
}
}
else if (!sndChnl.isPlaying())
{
if(mAudioSpec.channels == 2)
{
sndChnl.setBalance(balance);
}
sndChnl->setupSound(chosenSlot,
sndChnl.setupSound(chosenSlot,
(mode==SoundPlayMode::PLAY_FORCE) ? true : false );
break;
}
}
}
}
......
......@@ -49,24 +49,33 @@ void
CSoundChannel::
stopSound()
{
mpCurrentSndSlot = nullptr;
if(Mix_Playing(mId))
{
Mix_HaltChannel(mId);
}
mBalance = 0;
mSoundPtr = 0;
mSoundPaused = true;
mSoundPlaying = false;
}
/*
bool
CSoundChannel::isPlaying()
{
if(Mix_Playing(mId))
{
Mix_HaltChannel(mId);
}*/
return true;
}
else
{
return false;
}
}
void CSoundChannel::setupSound( CSoundSlot &SndSlottoPlay,
const bool sound_forced )
{
mpCurrentSndSlot = &SndSlottoPlay;
mSoundPlaying = true;
mSoundPtr = 0;
mSoundForced = sound_forced;
......@@ -128,7 +137,7 @@ void CSoundChannel::transintoStereoChannels(T* waveform, const Uint32 len)
}
}
void CSoundChannel::readWaveform( Uint8 * const waveform, const Uint32 len )
/*void CSoundChannel::readWaveform( Uint8 * const waveform, const Uint32 len )
{
auto snddata = mpCurrentSndSlot->getSoundData();
const Uint32 sndlength = mpCurrentSndSlot->getSoundlength();
......@@ -160,3 +169,4 @@ void CSoundChannel::readWaveform( Uint8 * const waveform, const Uint32 len )
}
}
}
*/
......@@ -55,8 +55,8 @@ public:
virtual ~CSoundChannel();
void stopSound();
bool isPlaying() { return mSoundPlaying; }
bool isForcedPlaying() { return (mSoundPlaying && mSoundForced); }
bool isPlaying();
bool isForcedPlaying() { return (isPlaying() && mSoundForced); }
CSoundSlot *getCurrentSoundPtr() { return mpCurrentSndSlot; }
/**
......@@ -66,7 +66,7 @@ public:
* \warning If there is no sound curently assigned to be played, please don't call that function.
* It might crash. Call setupSound first before you call this one!
*/
void readWaveform( Uint8 * const waveform, const Uint32 len );
//void readWaveform( Uint8 * const waveform, const Uint32 len );
template <typename T>
void transintoStereoChannels(T* waveform, const Uint32 len);
......@@ -82,7 +82,7 @@ public:
const bool sound_forced );
private:
bool mSoundPlaying; // true = a sound is currently playing
CSoundSlot *mpCurrentSndSlot = nullptr; // Pointer to the slot of the currently playing sound
Uint32 mSoundPtr = 0; // position within sound that we're at
bool mSoundPaused = true; // true = pause playback
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment