SoundEmitter: Make SE source count configurable
Default is still 6.
This commit is contained in:
		
							parent
							
								
									5ee62ba0fd
								
							
						
					
					
						commit
						b1ebc655f9
					
				
					 8 changed files with 48 additions and 22 deletions
				
			
		| 
						 | 
					@ -173,6 +173,14 @@
 | 
				
			||||||
# midi.reverb=false
 | 
					# midi.reverb=false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Number of OpenAL sources to allocate for SE playback.
 | 
				
			||||||
 | 
					# If there are a lot of sounds playing at the same time
 | 
				
			||||||
 | 
					# and audibly cutting each other off, try increasing
 | 
				
			||||||
 | 
					# this number. Maximum: 64.
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					# SE.sourceCount=6
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Give a hint on which language the game title as
 | 
					# Give a hint on which language the game title as
 | 
				
			||||||
# specified in the Game.ini is, useful if the encoding
 | 
					# specified in the Game.ini is, useful if the encoding
 | 
				
			||||||
# is being falsely detected. Relevant only if mkxp was
 | 
					# is being falsely detected. Relevant only if mkxp was
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -60,10 +60,11 @@ struct AudioPrivate
 | 
				
			||||||
		MeWatchState state;
 | 
							MeWatchState state;
 | 
				
			||||||
	} meWatch;
 | 
						} meWatch;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AudioPrivate()
 | 
						AudioPrivate(const Config &conf)
 | 
				
			||||||
	    : bgm(ALStream::Looped, "bgm"),
 | 
						    : bgm(ALStream::Looped, "bgm"),
 | 
				
			||||||
	      bgs(ALStream::Looped, "bgs"),
 | 
						      bgs(ALStream::Looped, "bgs"),
 | 
				
			||||||
	      me(ALStream::NotLooped, "me")
 | 
						      me(ALStream::NotLooped, "me"),
 | 
				
			||||||
 | 
						      se(conf)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		meWatch.active = false;
 | 
							meWatch.active = false;
 | 
				
			||||||
		meWatch.termReq = false;
 | 
							meWatch.termReq = false;
 | 
				
			||||||
| 
						 | 
					@ -238,8 +239,8 @@ struct AudioPrivate
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Audio::Audio()
 | 
					Audio::Audio(const Config &conf)
 | 
				
			||||||
	: p(new AudioPrivate)
 | 
						: p(new AudioPrivate(conf))
 | 
				
			||||||
{}
 | 
					{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,7 @@
 | 
				
			||||||
 *   quite make out their meaning yet) */
 | 
					 *   quite make out their meaning yet) */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct AudioPrivate;
 | 
					struct AudioPrivate;
 | 
				
			||||||
 | 
					struct Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Audio
 | 
					class Audio
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -75,7 +76,7 @@ public:
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	Audio();
 | 
						Audio(const Config &conf);
 | 
				
			||||||
	~Audio();
 | 
						~Audio();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	friend struct SharedStatePrivate;
 | 
						friend struct SharedStatePrivate;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,6 +141,7 @@ Config::Config()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	midi.chorus = false;
 | 
						midi.chorus = false;
 | 
				
			||||||
	midi.reverb = false;
 | 
						midi.reverb = false;
 | 
				
			||||||
 | 
						SE.sourceCount = 6;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Config::read(int argc, char *argv[])
 | 
					void Config::read(int argc, char *argv[])
 | 
				
			||||||
| 
						 | 
					@ -165,6 +166,7 @@ void Config::read(int argc, char *argv[])
 | 
				
			||||||
	PO_DESC(midi.soundFont, std::string) \
 | 
						PO_DESC(midi.soundFont, std::string) \
 | 
				
			||||||
	PO_DESC(midi.chorus, bool) \
 | 
						PO_DESC(midi.chorus, bool) \
 | 
				
			||||||
	PO_DESC(midi.reverb, bool) \
 | 
						PO_DESC(midi.reverb, bool) \
 | 
				
			||||||
 | 
						PO_DESC(SE.sourceCount, int) \
 | 
				
			||||||
	PO_DESC(customScript, std::string) \
 | 
						PO_DESC(customScript, std::string) \
 | 
				
			||||||
	PO_DESC(pathCache, bool) \
 | 
						PO_DESC(pathCache, bool) \
 | 
				
			||||||
	PO_DESC(useScriptNames, bool)
 | 
						PO_DESC(useScriptNames, bool)
 | 
				
			||||||
| 
						 | 
					@ -221,6 +223,8 @@ void Config::read(int argc, char *argv[])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#undef PO_DESC
 | 
					#undef PO_DESC
 | 
				
			||||||
#undef PO_DESC_ALL
 | 
					#undef PO_DESC_ALL
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						SE.sourceCount = clamp(SE.sourceCount, 1, 64);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static std::string baseName(const std::string &path)
 | 
					static std::string baseName(const std::string &path)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,6 +66,11 @@ struct Config
 | 
				
			||||||
		bool reverb;
 | 
							bool reverb;
 | 
				
			||||||
	} midi;
 | 
						} midi;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							int sourceCount;
 | 
				
			||||||
 | 
						} SE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool useScriptNames;
 | 
						bool useScriptNames;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	std::string customScript;
 | 
						std::string customScript;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -107,6 +107,7 @@ struct SharedStatePrivate
 | 
				
			||||||
	      midiState(threadData->config),
 | 
						      midiState(threadData->config),
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	      graphics(threadData),
 | 
						      graphics(threadData),
 | 
				
			||||||
 | 
						      audio(threadData->config),
 | 
				
			||||||
	      fontState(threadData->config),
 | 
						      fontState(threadData->config),
 | 
				
			||||||
	      stampCounter(0)
 | 
						      stampCounter(0)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,7 @@
 | 
				
			||||||
#include "sharedstate.h"
 | 
					#include "sharedstate.h"
 | 
				
			||||||
#include "filesystem.h"
 | 
					#include "filesystem.h"
 | 
				
			||||||
#include "exception.h"
 | 
					#include "exception.h"
 | 
				
			||||||
 | 
					#include "config.h"
 | 
				
			||||||
#include "util.h"
 | 
					#include "util.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <SDL_sound.h>
 | 
					#include <SDL_sound.h>
 | 
				
			||||||
| 
						 | 
					@ -76,7 +77,7 @@ private:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Before: [a][b][c][d], After (index=1): [a][c][d][b] */
 | 
					/* Before: [a][b][c][d], After (index=1): [a][c][d][b] */
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
arrayPushBack(size_t array[], size_t size, size_t index)
 | 
					arrayPushBack(std::vector<size_t> &array, size_t size, size_t index)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	size_t v = array[index];
 | 
						size_t v = array[index];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -86,10 +87,14 @@ arrayPushBack(size_t array[], size_t size, size_t index)
 | 
				
			||||||
	array[size-1] = v;
 | 
						array[size-1] = v;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SoundEmitter::SoundEmitter()
 | 
					SoundEmitter::SoundEmitter(const Config &conf)
 | 
				
			||||||
	: bufferBytes(0)
 | 
					    : bufferBytes(0),
 | 
				
			||||||
 | 
					      srcCount(conf.SE.sourceCount),
 | 
				
			||||||
 | 
					      alSrcs(srcCount),
 | 
				
			||||||
 | 
					      atchBufs(srcCount),
 | 
				
			||||||
 | 
					      srcPrio(srcCount)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for (int i = 0; i < SE_SOURCES; ++i)
 | 
						for (size_t i = 0; i < srcCount; ++i)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		alSrcs[i] = AL::Source::gen();
 | 
							alSrcs[i] = AL::Source::gen();
 | 
				
			||||||
		atchBufs[i] = 0;
 | 
							atchBufs[i] = 0;
 | 
				
			||||||
| 
						 | 
					@ -99,7 +104,7 @@ SoundEmitter::SoundEmitter()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SoundEmitter::~SoundEmitter()
 | 
					SoundEmitter::~SoundEmitter()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for (int i = 0; i < SE_SOURCES; ++i)
 | 
						for (size_t i = 0; i < srcCount; ++i)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		AL::Source::stop(alSrcs[i]);
 | 
							AL::Source::stop(alSrcs[i]);
 | 
				
			||||||
		AL::Source::del(alSrcs[i]);
 | 
							AL::Source::del(alSrcs[i]);
 | 
				
			||||||
| 
						 | 
					@ -124,24 +129,24 @@ void SoundEmitter::play(const std::string &filename,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Try to find first free source */
 | 
						/* Try to find first free source */
 | 
				
			||||||
	size_t i;
 | 
						size_t i;
 | 
				
			||||||
	for (i = 0; i < SE_SOURCES; ++i)
 | 
						for (i = 0; i < srcCount; ++i)
 | 
				
			||||||
		if (AL::Source::getState(alSrcs[srcPrio[i]]) != AL_PLAYING)
 | 
							if (AL::Source::getState(alSrcs[srcPrio[i]]) != AL_PLAYING)
 | 
				
			||||||
			break;
 | 
								break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* If we didn't find any, try to find the lowest priority source
 | 
						/* If we didn't find any, try to find the lowest priority source
 | 
				
			||||||
	 * with the same buffer to overtake */
 | 
						 * with the same buffer to overtake */
 | 
				
			||||||
	if (i == SE_SOURCES)
 | 
						if (i == srcCount)
 | 
				
			||||||
		for (size_t j = 0; j < SE_SOURCES; ++j)
 | 
							for (size_t j = 0; j < srcCount; ++j)
 | 
				
			||||||
			if (atchBufs[srcPrio[j]] == buffer)
 | 
								if (atchBufs[srcPrio[j]] == buffer)
 | 
				
			||||||
				i = j;
 | 
									i = j;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* If we didn't find any, overtake the one with lowest priority */
 | 
						/* If we didn't find any, overtake the one with lowest priority */
 | 
				
			||||||
	if (i == SE_SOURCES)
 | 
						if (i == srcCount)
 | 
				
			||||||
		i = 0;
 | 
							i = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Push the used source to the back of the priority list */
 | 
						/* Push the used source to the back of the priority list */
 | 
				
			||||||
	size_t srcIndex = srcPrio[i];
 | 
						size_t srcIndex = srcPrio[i];
 | 
				
			||||||
	arrayPushBack(srcPrio, SE_SOURCES, i);
 | 
						arrayPushBack(srcPrio, srcCount, i);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AL::Source::ID src = alSrcs[srcIndex];
 | 
						AL::Source::ID src = alSrcs[srcIndex];
 | 
				
			||||||
	AL::Source::stop(src);
 | 
						AL::Source::stop(src);
 | 
				
			||||||
| 
						 | 
					@ -164,7 +169,7 @@ void SoundEmitter::play(const std::string &filename,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SoundEmitter::stop()
 | 
					void SoundEmitter::stop()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	for (int i = 0; i < SE_SOURCES; i++)
 | 
						for (size_t i = 0; i < srcCount; i++)
 | 
				
			||||||
		AL::Source::stop(alSrcs[i]);
 | 
							AL::Source::stop(alSrcs[i]);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,10 +27,10 @@
 | 
				
			||||||
#include "boost-hash.h"
 | 
					#include "boost-hash.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
 | 
					#include <vector>
 | 
				
			||||||
#define SE_SOURCES 6
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct SoundBuffer;
 | 
					struct SoundBuffer;
 | 
				
			||||||
 | 
					struct Config;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct SoundEmitter
 | 
					struct SoundEmitter
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -42,13 +42,14 @@ struct SoundEmitter
 | 
				
			||||||
	/* Byte count sum of all cached / playing buffers */
 | 
						/* Byte count sum of all cached / playing buffers */
 | 
				
			||||||
	uint32_t bufferBytes;
 | 
						uint32_t bufferBytes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AL::Source::ID alSrcs[SE_SOURCES];
 | 
						const size_t srcCount;
 | 
				
			||||||
	SoundBuffer *atchBufs[SE_SOURCES];
 | 
						std::vector<AL::Source::ID> alSrcs;
 | 
				
			||||||
 | 
						std::vector<SoundBuffer*> atchBufs;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Indices of sources, sorted by priority (lowest first) */
 | 
						/* Indices of sources, sorted by priority (lowest first) */
 | 
				
			||||||
	size_t srcPrio[SE_SOURCES];
 | 
						std::vector<size_t> srcPrio;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	SoundEmitter();
 | 
						SoundEmitter(const Config &conf);
 | 
				
			||||||
	~SoundEmitter();
 | 
						~SoundEmitter();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void play(const std::string &filename,
 | 
						void play(const std::string &filename,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue