2017-06-23 11:24:50 +08:00
|
|
|
#include "Sound.h"
|
|
|
|
#include "begin_code.h"
|
2017-06-23 14:16:15 +08:00
|
|
|
//private
|
2017-06-23 11:24:50 +08:00
|
|
|
void Sound::_set(Mix_Chunk* p)
|
|
|
|
{
|
|
|
|
_sound.reset(p,Mix_FreeChunk);
|
|
|
|
}
|
2017-06-23 14:16:15 +08:00
|
|
|
//private
|
|
|
|
void Sound::_clear()
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
|
|
|
_sound.reset();
|
|
|
|
}
|
2017-06-23 14:16:15 +08:00
|
|
|
//private
|
|
|
|
Mix_Chunk* Sound::_get() const
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
|
|
|
return _sound.get();
|
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
Sound::Sound(const std::string& WAVFilename)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
_set(Mix_LoadWAV(WAVFilename.c_str()));
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-07-04 22:38:33 +08:00
|
|
|
Sound::Sound(const RWOP& rwop)
|
|
|
|
{
|
|
|
|
_set(Mix_LoadWAV_RW(rwop._get(),0));
|
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
bool Sound::isReady() const
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return (_get()!=nullptr);
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
void Sound::release()
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
_clear();
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
//private
|
|
|
|
void Channel::_set(int ChannelID)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
_id=ChannelID;
|
|
|
|
}
|
|
|
|
//private
|
|
|
|
int Channel::_get() const
|
|
|
|
{
|
|
|
|
return _id;
|
|
|
|
}
|
|
|
|
//private
|
|
|
|
void Channel::_clear()
|
|
|
|
{
|
|
|
|
_id=-1;
|
|
|
|
}
|
|
|
|
//protected
|
|
|
|
Channel::Channel()
|
|
|
|
{
|
|
|
|
_id=-1;
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
Channel& Channel::playSound(Sound sound, int loops) throw (ErrorViewer)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
int cret=Mix_PlayChannel(_get(),sound._get(),loops);
|
|
|
|
if(cret==-1)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
2017-06-23 14:16:15 +08:00
|
|
|
_set(cret);
|
|
|
|
return *this;
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
Channel& Channel::fadeIn(Sound sound, int loops, int ms) throw (ErrorViewer)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
int cret=Mix_FadeInChannel(_get(),sound._get(),loops,ms);
|
|
|
|
if(cret==-1)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
|
|
|
ErrorViewer e;
|
|
|
|
e.fetch();
|
|
|
|
throw e;
|
|
|
|
}
|
2017-06-23 14:16:15 +08:00
|
|
|
_set(cret);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Channel::fadeOut(int ms)
|
|
|
|
{
|
|
|
|
return Mix_FadeOutChannel(_get(), ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Channel::pause()
|
|
|
|
{
|
|
|
|
Mix_Pause(_get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Channel::resume()
|
|
|
|
{
|
|
|
|
Mix_Resume(_get());
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
int Channel::stop()
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return Mix_HaltChannel(_get());
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
int Channel::setPanning(uint8_t left, uint8_t right)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return Mix_SetPanning(_get(),left,right);
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
int Channel::setPosition(int16_t angle, uint8_t distance)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return Mix_SetPosition(_get(),angle,distance);
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
int Channel::setDistance(uint8_t distance)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return Mix_SetDistance(_get(),distance);
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
int Channel::setReverseStereo(int flip)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return Mix_SetReverseStereo(_get(),flip);
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
int Channel::addEffect(Mix_EffectFunc_t f, Mix_EffectDone_t d, void* arg)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return Mix_RegisterEffect(_get(),f,d,arg);
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
int Channel::removeEffect(Mix_EffectFunc_t f)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return Mix_UnregisterEffect(_get(),f);
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
int Channel::removeAllEffect()
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return Mix_UnregisterAllEffects(_get());
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-06-23 14:16:15 +08:00
|
|
|
|
|
|
|
//static
|
|
|
|
int SoundPlayer::GetDecoderNum()
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
return Mix_GetNumChunkDecoders();
|
|
|
|
}
|
|
|
|
|
|
|
|
//static
|
|
|
|
std::string SoundPlayer::GetDecoderName(int index)
|
|
|
|
{
|
|
|
|
return std::string(Mix_GetChunkDecoder(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
SoundPlayer::SoundPlayer(int Channels)
|
|
|
|
{
|
|
|
|
Mix_AllocateChannels(Channels);
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-07-15 00:12:48 +08:00
|
|
|
Channel SoundPlayer::playSound(Sound sound, int loops)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
Channel c;
|
|
|
|
c.playSound(sound,loops);
|
|
|
|
return c;
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
|
2017-07-15 00:12:48 +08:00
|
|
|
Channel SoundPlayer::fadeIn(Sound sound, int loops, int ms)
|
2017-06-23 11:24:50 +08:00
|
|
|
{
|
2017-06-23 14:16:15 +08:00
|
|
|
Channel c;
|
|
|
|
c.fadeIn(sound,loops,ms);
|
|
|
|
return c;
|
2017-06-23 11:24:50 +08:00
|
|
|
}
|
|
|
|
#include "end_code.h"
|