예제 #1
0
void Foliage::SoundManager::SDL_Audio_Callback(void *userdata, Uint8 *stream, Sint32 len)
{
	if (len != (_audioSpec.samples * 4))
	{
		std::cout << "Invalid audio callback buffer length: " << len << std::endl;
		return;
	}
	Uint32 sample_sfx, sample_bg, sample_mixed;
	Uint32 *buf = (Uint32 *)stream;
	for (Sint32 i = 0; i < _audioSpec.samples; i++)
	{
		sample_bg = (_bg != NULL) ? _bg->getNextSample() : 0;
		sample_sfx = (_sfx != NULL) ? _sfx->getNextSample() : 0;
		sample_mixed = mixSamples(sample_bg, sample_sfx);
		*(buf++) = sample_mixed;
	}
	if (_bg != NULL && _bg->ended())
	{
		_bg = NULL;
	}
	if (_sfx != NULL && _sfx->ended())
	{
		_sfx = NULL;
	}
}
예제 #2
0
void SfxPlayer::readSamples(int8_t *buf, int len) {
	if (_delay == 0) {
		memset(buf, 0, len * 2);
	} else {
		int8_t bufin[len * 2];
		mixSamples(bufin, len);
		nr(bufin, len, buf);
	}
}
예제 #3
0
void Foliage::SoundManager::AC97_Callback(void *useless)
{
	Uint32 sample_sfx, sample_bg, sample_mixed;
	for (Sint32 i = 0; i < 256; i++)
	{
		sample_bg = (_bg != NULL) ? _bg->getNextSample() : 0;
		sample_sfx = (_sfx != NULL) ? _sfx->getNextSample() : 0;
		sample_mixed = mixSamples(sample_bg, sample_sfx);
		XAC97_WriteFifo(XPAR_AUDIO_CODEC_BASEADDR, sample_mixed);
	}
	if (_bg != NULL && _bg->ended())
	{
		_bg = NULL;
	}
	if (_sfx != NULL && _sfx->ended())
	{
		_sfx = NULL;
	}
}