Commit 57b4598d authored by Gerhard Stein's avatar Gerhard Stein

Volume settings works again when IMF files ae being played

parent e8b6753f
......@@ -8,7 +8,6 @@
* but more stuff will come.
*/
//#include "engine/CEvent.h"
#include "GsEvent.h"
#include "Vector2D.h"
......
......@@ -9,6 +9,7 @@
#include <base/GsLogging.h>
#include <base/video/CVideoDriver.h>
#include <base/CInput.h>
#include <base/InputEvents.h>
#include <base/GsApp.h>
#include <widgets/GsTextSelectionList.h>
#include <widgets/GsBanner.h>
......
......@@ -58,6 +58,7 @@ void CAudioSettings::refresh()
mAudioSpec = gSound.getAudioSpec();
mSoundblaster = gSound.getSoundBlasterMode();
mSoundVolume = mpSoundVolume->getSelection();
mMusicVolume = mpMusicVolume->getSelection();
mpSoundVolume->setSelection(gSound.getSoundVolume());
mpMusicVolume->setSelection(gSound.getMusicVolume());
......@@ -85,9 +86,10 @@ void CAudioSettings::ponder(const float deltaT)
}
mSoundVolume = mpSoundVolume->getSelection();
mMusicVolume = mpMusicVolume->getSelection();
gSound.setSoundVolume( mSoundVolume );
gSound.setMusicVolume( mpMusicVolume->getSelection() );
gSound.setMusicVolume( mMusicVolume );
}
......
......@@ -48,6 +48,7 @@ private:
// This one does not really set the volume at all, it only verifies, if it changed...
int mSoundVolume;
int mMusicVolume;
};
......
......@@ -77,7 +77,6 @@ set(CXXSRC
menu/CAudioSettings.cpp
menu/CCameraSettings.cpp
menu/CConfirmMenu.cpp
menu/CControlsettings.cpp
menu/cheatsmenu.cpp
menu/CHelpMenu.cpp
menu/CLoadMenu.cpp
......@@ -165,7 +164,6 @@ set(HSRC
menu/CAudioSettings.h
menu/CCameraSettings.h
menu/CConfirmMenu.h
menu/CControlsettings.h
menu/cheatsmenu.h
menu/CHelpMenu.h
menu/CLoadMenu.h
......
......@@ -24,7 +24,6 @@
#include "menu/CMainMenu.h"
#include "menu/CSelectionMenu.h"
#include "menu/CControlsettings.h"
#include "playgame/CPlayGameVorticon.h"
......
......@@ -17,97 +17,3 @@
#include <base/utils/StringUtils.h>
#include "../VorticonEngine.h"
/*
namespace vorticon
{
CAudioSettings::CAudioSettings() :
VorticonMenu(GsRect<float>(0.075f, 0.24f, 0.85f, 0.4f) )
{
#if !defined(EMBEDDED)
mpRate = new ComboSelection( "Rate", gSound.getAvailableRateList());
mpMenuDialog->addControl( mpRate );
#endif
mpStereo = new Switch( "Stereo" );
mpMenuDialog->addControl( mpStereo );
#if !defined(EMBEDDED)
mpDepth = new ComboSelection( "Depth", filledStrList( 2, "8-bit", "16-bit" ) );
mpMenuDialog->addControl( mpDepth );
#endif
mpSBToggle = new ComboSelection( "Card", filledStrList( 2, "PC Speaker", "Soundblaster" ) );
mpMenuDialog->addControl( mpSBToggle );
mpSoundVolume = new NumberControl( "Sound Vol", 0, 100, 4, gSound.getSoundVolume(), true );
mpMenuDialog->addControl( mpSoundVolume );
mpMusicVolume = new NumberControl( "Music Vol", 0, 100, 4, gSound.getMusicVolume(), true );
mpMenuDialog->addControl( mpMusicVolume );
}
void CAudioSettings::refresh()
{
mAudioSpec = gSound.getAudioSpec();
mSoundblaster = gSound.getSoundBlasterMode();
mSoundVolume = mpSoundVolume->getSelection();
#if !defined(EMBEDDED)
mpRate->setSelection( itoa(mAudioSpec.freq) );
#endif
mpStereo->enable( mAudioSpec.channels == 2 );
#if !defined(EMBEDDED)
mpDepth->setSelection( mAudioSpec.format == AUDIO_U8 ? "8-bit" : "16-bit" );
#endif
mpSBToggle->setSelection( mSoundblaster ? "Soundblaster" : "PC Speaker" );
gMusicPlayer.play();
}
void CAudioSettings::ponder(const float deltaT)
{
CBaseMenu::ponder(0);
if( mSoundVolume != mpSoundVolume->getSelection() )
gSound.playSound(SOUND_GET_ITEM);
mSoundVolume = mpSoundVolume->getSelection();
gSound.setSoundVolume( mSoundVolume );
gSound.setMusicVolume( mpMusicVolume->getSelection() );
}
void CAudioSettings::release()
{
#if !defined(EMBEDDED)
mAudioSpec.freq = atoi( mpRate->getSelection().c_str() );
#endif
mAudioSpec.channels = mpStereo->isEnabled() ? 2 : 1;
#if !defined(EMBEDDED)
mAudioSpec.format = mpDepth->getSelection() == "8-bit" ? AUDIO_U8 : AUDIO_S16;
#endif
mSoundblaster = ( mpSBToggle->getSelection() == "Soundblaster" ? true : false );
gSound.unloadSoundData();
gSound.destroy();
gSound.setSettings(mAudioSpec, mSoundblaster);
gSound.init();
setupAudio();
gMusicPlayer.reload();
gSettings.saveDrvCfg();
}
}
*/
......@@ -16,38 +16,6 @@
#include "fileio/CExeFile.h"
#include <SDL.h>
#include <string>
/*
namespace vorticon
{
class CAudioSettings : public VorticonMenu
{
public:
CAudioSettings();
void refresh();
void ponder(const float deltaT);
void release();
private:
ComboSelection *mpRate;
Switch *mpStereo;
ComboSelection *mpDepth;
ComboSelection *mpSBToggle;
NumberControl *mpSoundVolume;
NumberControl *mpMusicVolume;
SDL_AudioSpec mAudioSpec;
bool mSoundblaster;
// This one does not really set the volume at all, it only verifies, if it changed...
int mSoundVolume;
};
}
*/
#endif /* __VORTICON_AUDIOSETTINGS_H_ */
/*
* CControlsettings.cpp
*
* Created on: 28.11.2009
* Author: gerstrong
*/
#include <base/utils/StringUtils.h>
#include "CSelectionMenu.h"
#include "CControlsettings.h"
#include "engine/core/CBehaviorEngine.h"
#include <base/CInput.h>
/*
namespace vorticon
{
*/
/**
* \brief This sets the default settings for a classic gameplay
*/
/*
class ReadInputEvent : public InvokeFunctorEvent
{
public:
ReadInputEvent( const int selPlayer,
const InputCommands command,
const std::string &commandName ) :
mSelPlayer(selPlayer),
mCommand(command),
mCommandName(commandName),
mpButton(NULL)
{}
void setButtonPtr(Button* button)
{
mpButton = button;
}
void operator()() const
{
gInput.setupNewEvent(mSelPlayer-1, mCommand);
const std::string buf = mCommandName;
mpButton->setText(buf + "=Reading=");
}
int mSelPlayer;
InputCommands mCommand;
const std::string mCommandName;
Button* mpButton;
};
*/
/**
* \brief This sets the default settings for a classic gameplay
*/
/*
class ResetInputEvent : public InvokeFunctorEvent
{
public:
ResetInputEvent( const int selPlayer ) :
mSelPlayer(selPlayer)
{}
void operator()() const
{
gInput.resetControls(mSelPlayer);
}
int mSelPlayer;
};
CControlsettings::CControlsettings( const int selectedPlayer ) :
VorticonMenu( GsRect<float>(0.1f, 0.25f, 0.8f, 0.5f) ),
mSelectedPlayer(selectedPlayer)
{
GsButton *button;
button = new Button( "Movement", new OpenMovementControlMenuEvent(mSelectedPlayer) );
mpMenuDialog->addControl( button );
button = new Button( "Buttons", new OpenButtonsControlMenuEvent(mSelectedPlayer) );
mpMenuDialog->addControl( button );
mpTwoButtonSwitch = new Switch( "Two Button Fire" );
mpTwoButtonSwitch->enable(gInput.getTwoButtonFiring(mSelectedPlayer-1));
mpAnalogSwitch = new Switch( "Analog Movement" );
mpAnalogSwitch->enable(gInput.isAnalog(mSelectedPlayer-1));
mpSuperPogoSwitch = new Switch( "Super Pogo" );
mpSuperPogoSwitch->enable(gInput.SuperPogo(mSelectedPlayer-1));
mpImpPogoSwitch = new Switch( "Impossible Pogo" );
mpImpPogoSwitch->enable(gInput.ImpossiblePogo(mSelectedPlayer-1));
mpAutoGunSwitch = new Switch( "Auto Gun" );
mpAutoGunSwitch->enable(gInput.AutoGun(mSelectedPlayer-1));
mpMenuDialog->addControl( mpTwoButtonSwitch );
mpMenuDialog->addControl( mpAnalogSwitch );
mpMenuDialog->addControl( mpSuperPogoSwitch );
mpMenuDialog->addControl( mpImpPogoSwitch );
mpMenuDialog->addControl( mpAutoGunSwitch );
mpMenuDialog->addControl( new Button( "Reset Controls", new ResetInputEvent(mSelectedPlayer-1) ) );
}
void CControlsettings::release()
{
gInput.setTwoButtonFiring(mSelectedPlayer-1, mpTwoButtonSwitch->isEnabled() );
gInput.enableAnalog(mSelectedPlayer-1, mpAnalogSwitch->isEnabled() );
gInput.setSuperPogo(mSelectedPlayer-1, mpSuperPogoSwitch->isEnabled() );
gInput.setImpossiblePogo(mSelectedPlayer-1, mpImpPogoSwitch->isEnabled() );
gInput.setAutoGun(mSelectedPlayer-1, mpAutoGunSwitch->isEnabled() );
gInput.saveControlconfig();
}
CControlSettingsBase::CControlSettingsBase(const int selectedPlayer) :
VorticonMenu( GsRect<float>(0.01f, (1.0f-((MAX_COMMANDS/2.0f)+2)*0.06f)*0.5f, 0.98f,(MAX_COMMANDS/2.0f+2)*0.06f) ),
mSelectedPlayer(selectedPlayer),
mapping(false)
{}
void CControlSettingsBase::ponder(const float deltaT)
{
if( !mapping && gInput.MappingInput() ) // mapping changed!
{
mapping = true;
}
else if( !gInput.MappingInput() )
{
if(mapping) // mapping changed!
{
mapping = false;
int pos; unsigned char input;
std::string evName = gInput.getNewMappedEvent(pos, input);
InputCommands com = static_cast<InputCommands>(pos);
if(pos >= MID_COMMANDS_OFFSETS)
pos -= MID_COMMANDS_OFFSETS;
mpButtonList[pos]->setText(mCommandName[com] + evName);
}
CBaseMenu::ponder(0);
}
}
void CControlSettingsBase::release()
{
if(!mCommandName.empty())
mCommandName.clear();
gInput.saveControlconfig();
}
// Movements Parts of the Control Settings
void CControlSettingsMovement::init()
{
mapping = false;
mCommandName[IC_LEFT] = "Left: ";
mCommandName[IC_RIGHT] = "Right: ";
mCommandName[IC_UP] = "Up: ";
mCommandName[IC_DOWN] = "Down: ";
mCommandName[IC_UPPERLEFT] = "U-left: ";
mCommandName[IC_UPPERRIGHT] = "U-right:";
mCommandName[IC_LOWERLEFT] = "D-left: ";
mCommandName[IC_LOWERRIGHT] = "D-right:";
if(!mpButtonList.empty())
mpButtonList.clear();
std::map<InputCommands, std::string>::iterator it = mCommandName.begin();
for ( ; it != mCommandName.end(); it++ )
{
const std::string buf = it->second;
const std::string buf2 = gInput.getEventShortName( it->first, mSelectedPlayer-1 );
ReadInputEvent *rie = new ReadInputEvent(mSelectedPlayer, it->first, it->second);
Button *guiButton = new Button( buf+buf2, rie );
rie->setButtonPtr(guiButton);
mpButtonList.push_back( guiButton );
mpMenuDialog->addControl( guiButton );
}
}
// Movements Parts of the Control Settings
void CControlSettingsButtons::init()
{
mapping = false;
mCommandName[IC_JUMP] = "Jump: ";
mCommandName[IC_POGO] = "Pogo: ";
mCommandName[IC_FIRE] = "Fire: ";
mCommandName[IC_RUN] = "Run: ";
mCommandName[IC_STATUS] = "Status: ";
mCommandName[IC_CAMLEAD] = "Camlead:";
mCommandName[IC_HELP] = "Help: ";
mCommandName[IC_BACK] = "Back: ";
if(!mpButtonList.empty())
mpButtonList.clear();
std::map<InputCommands, std::string>::iterator it = mCommandName.begin();
for ( ; it != mCommandName.end(); it++ )
{
const std::string buf = it->second;
const std::string buf2 = gInput.getEventShortName( it->first, mSelectedPlayer-1 );
ReadInputEvent *rie = new ReadInputEvent(mSelectedPlayer, it->first, it->second);
Button *guiButton = new Button( buf+buf2, rie );
rie->setButtonPtr(guiButton);
mpButtonList.push_back( guiButton );
mpMenuDialog->addControl( guiButton );
}
}
}
*/
/*
* CControlsettings.h
*
* Created on: 28.11.2009
* Author: gerstrong
*/
#ifndef CCONTROLSETTINGS_H_
#define CCONTROLSETTINGS_H_
/*
#include "VorticonMenu.h"
#include <base/utils/StringUtils.h>
#include "widgets/Button.h"
#include "widgets/Switch.h"
#include <vector>
#include <map>
#include <base/GsEvent.h>
#include "CSelectionMenu.h"
namespace vorticon
{
// Main Class for Controller Config
class CControlsettings : public VorticonMenu
{
public:
CControlsettings(const int selectedPlayer);
void release();
private:
int mSelectedPlayer;
Switch *mpTwoButtonSwitch;
Switch *mpAnalogSwitch;
Switch *mpSuperPogoSwitch;
Switch *mpImpPogoSwitch;
Switch *mpAutoGunSwitch;
};
class CControlSettingsBase : public VorticonMenu
{
public:
CControlSettingsBase(const int selectedPlayer);
virtual void ponder(const float deltaT);
void release();
protected:
int mSelectedPlayer;
std::vector<Button*> mpButtonList;
std::map<InputCommands, std::string> mCommandName;
bool mapping;
};
// Movement config Part
class CControlSettingsMovement : public CControlSettingsBase
{
public:
CControlSettingsMovement(const int selectedPlayer) :
CControlSettingsBase(selectedPlayer)
{
init();
}
void init();
};
// Buttons config Part
class CControlSettingsButtons : public CControlSettingsBase
{
public:
CControlSettingsButtons(const int selectedPlayer) :
CControlSettingsBase(selectedPlayer)
{
init();
}
void init();
};
// Create the Control-Menu for the indicated Player
struct OpenControlMenuEvent : SelectionEvent
{
OpenControlMenuEvent(const int players) :
SelectionEvent(players) {}
};
struct OpenButtonsControlMenuEvent : OpenControlMenuEvent
{
OpenButtonsControlMenuEvent(const int option) :
OpenControlMenuEvent(option) {}
};
struct OpenMovementControlMenuEvent : OpenControlMenuEvent
{
OpenMovementControlMenuEvent(const int option) :
OpenControlMenuEvent(option) {}
};
}
*/
#endif /* CCONTROLSETTINGS_H_ */
......@@ -16,7 +16,7 @@
#include "CAudioSettings.h"
#include "COptions.h"
#include "cheatsmenu.h"
#include "CControlsettings.h"
//#include "CControlsettings.h"
#include "CProfilesMenu.h"
#include "CSelectionMenu.h"
......
......@@ -272,6 +272,7 @@ void Audio::setMusicVolume(const Uint8 volume,
if(updateMixer)
{
setImfMusic(volume);
Mix_VolumeMusic(volume);
}
}
......@@ -307,20 +308,20 @@ void Audio::playStereofromCoord(const GameSound snd,
{
int bal = (xCoord - (320>>1)); // Faster calculation of balance transformation
if(bal < -255)
{
bal = -255;
}
else if(bal > 255)
{
bal = 255;
}
if(bal < -255)
{
bal = -255;
}
else if(bal > 255)
{
bal = 255;
}
playStereosound(snd, mode, bal);
}
else
{
playSound(snd, mode);
playSound(snd, mode);
}
}
......
......@@ -123,7 +123,7 @@ void CIMFPlayer::OPLUpdate(byte *buffer, const unsigned int length)
{
gLogging.textOut("Creating enough Audio Buffer for the IMF-Player");
mMixBuffer.assign(audioSpec.samples, 0);
}
}
m_opl_emulator.Chip__GenerateBlock2( length, mMixBuffer.data() );
......@@ -145,7 +145,8 @@ void CIMFPlayer::OPLUpdate(byte *buffer, const unsigned int length)
for (unsigned int j=0; j<audioSpec.channels; j++)
{
*buf16 = static_cast<Sint16>(mix + audioSpec.silence);
int val = mix + audioSpec.silence;
*buf16 = static_cast<Sint16>((val*mVolume)/MIX_MAX_VOLUME);
buf16++;
}
}
......@@ -163,7 +164,8 @@ void CIMFPlayer::OPLUpdate(byte *buffer, const unsigned int length)
for (unsigned int j=0; j<audioSpec.channels; j++)
{
*buffer = static_cast<byte>(mix + audioSpec.silence);
int val = mix + audioSpec.silence;
*buffer = static_cast<Sint16>((val*mVolume)/MIX_MAX_VOLUME);
buffer++;
}
}
......@@ -230,6 +232,11 @@ CIMFPlayer locIMFPlayer;
int locImfMusPos = 0;
void setImfMusic(const int vol)
{
locIMFPlayer.mVolume = vol;
}
bool loadIMFFile(const std::string &fname)
{
if(locIMFPlayer.playing())
......
......@@ -46,6 +46,8 @@ public:
bool loadMusicTrack(const int track) override;
int mVolume = 0;
private:
......@@ -61,11 +63,18 @@ private:
Uint32 m_samplesPerMusicTick =0;
unsigned int m_IMFDelay = 0;
std::vector<Sint32> mMixBuffer;
};
// External Music hooks for the imf player
/**
* @brief setImfMusic Set volume of external player
* @param vol
*/
void setImfMusic(const int vol);
/**
* @brief loadIMFFile
* @param fname
......
......@@ -48,17 +48,17 @@ bool CMusic::load(const std::string &musicfile)
Mix_HaltMusic();
if(mpMixMusic)
{
Mix_FreeMusic(mpMixMusic);
mpMixMusic = nullptr;
}
if(mpMixMusic)
{
Mix_FreeMusic(mpMixMusic);
mpMixMusic = nullptr;
}
unhookAll();
unhookAll();
if(musicfile == "") return false;
const SDL_AudioSpec &audioSpec = gSound.getAudioSpec();
const SDL_AudioSpec &audioSpec = gSound.getAudioSpec();
if(audioSpec.format != 0)
{
......@@ -133,7 +133,7 @@ void CMusic::play()
}
// Play music forever
if(Mix_FadeInMusic(mpMixMusic, -1, 2000) == -1)
if(Mix_PlayMusic(mpMixMusic, -1) == -1)
{
gLogging.ftextOut("Mix_PlayMusic: %s\n", Mix_GetError());
// well, there's no music, but most games don't break without music...
......
......@@ -142,37 +142,3 @@ void CSoundChannel::transintoStereoChannels(T* waveform, const Uint32 len)
}
}
}
/*void CSoundChannel::readWaveform( Uint8 * const waveform, const Uint32 len )
{
auto snddata = mpCurrentSndSlot->getSoundData();
const Uint32 sndlength = mpCurrentSndSlot->getSoundlength();
if ((mSoundPtr + len) >= sndlength)
{
// Fill up the buffer and the rest with silence
const Uint32 len_left = sndlength-mSoundPtr;
memcpy(waveform, snddata + mSoundPtr, len_left );
memset(waveform+len_left, m_AudioSpec.silence, len-len_left );
mSoundPtr = 0;
mSoundPlaying = false;
}
else
{
memcpy(waveform, snddata + mSoundPtr, len );
mSoundPtr += len;
}
if(m_AudioSpec.channels == 2)
{
if(m_AudioSpec.format == AUDIO_U16 || m_AudioSpec.format == AUDIO_S16)
{