This commit is contained in:
2024-02-27 10:10:02 +01:00
parent c0aea669c7
commit 547809c898
131 changed files with 65609 additions and 0 deletions

67
Engine/SoundStream.cpp Normal file
View File

@@ -0,0 +1,67 @@
#include "base.h"
#include <iostream>
#include "SoundStream.h"
SoundStream::SoundStream( const std::string& path )
:m_pMixMusic{ Mix_LoadMUS( path.c_str( )) }
{
if ( m_pMixMusic == nullptr )
{
std::string errorMsg = "SoundStream: Failed to load " + path + ",\nSDL_mixer Error: " + Mix_GetError( );
std::cerr << errorMsg;
}
}
SoundStream::~SoundStream( )
{
Mix_FreeMusic( m_pMixMusic );
m_pMixMusic = nullptr;
}
bool SoundStream::IsLoaded( ) const
{
return m_pMixMusic != nullptr;
}
bool SoundStream::Play(bool repeat ) const
{
if ( m_pMixMusic != nullptr )
{
int result{ Mix_PlayMusic( m_pMixMusic, repeat ? -1 : 1 ) };
return result == 0 ? true : false;
}
else
{
return false;
}
}
void SoundStream::Stop( )
{
Mix_HaltMusic( );
}
void SoundStream::Pause( )
{
Mix_PauseMusic( );
}
void SoundStream::Resume( )
{
Mix_ResumeMusic( );
}
int SoundStream::GetVolume( )
{
return Mix_VolumeMusic( -1 );
}
bool SoundStream::IsPlaying( )
{
return Mix_PlayingMusic( ) == 0 ? false : true;
}
void SoundStream::SetVolume( int value )
{
Mix_VolumeMusic( value );
}