コード例 #1
0
	void AudioDevice::stopAllAudio()
	{
		stopStreams();
		stopSounds();
		JL_DEBUG_LOG("Stopped all audio playback");

		audioCleanup();
	}
コード例 #2
0
ファイル: default.c プロジェクト: calumchisholm/XPilotNG-web
void defaultCleanup(void)
{
    XFREE(keydefs);
    XFREE(texturePath);
    XFREE(shipShape);

#ifdef SOUND
    audioCleanup();
#endif /* SOUND */
}
コード例 #3
0
	SoundHandle AudioDevice::createSound(const std::string &name)
	{
		// Perform cleanup before creating new sounds
		audioCleanup();

		auto itr = m_audioFiles.find(name);
		if(itr != m_audioFiles.end())
		{
			// Check if data hasn't been loaded for this file previously
			if(!alIsBuffer(itr->second.buffer) || itr->second.buffer == 0)
			{
				// Open file and save initial data
				SF_INFO fileInfo;
				SNDFILE *file = sf_open(itr->second.fileName.c_str(), SFM_READ, &fileInfo);

				if(file == NULL)
				{
					JL_WARNING_LOG("Could not open audio file '%s'", itr->second.fileName.c_str());
					return SoundHandle();
				}

				// Create new buffer
				alGenBuffers(1, &itr->second.buffer);

				// Read whole file
				int sampleCount = fileInfo.frames * fileInfo.channels;
				std::vector<ALshort> fileData(sampleCount);
				sf_read_short(file, &fileData[0], sampleCount);
				alBufferData(
					itr->second.buffer,
					AudioDevice::getFormatFromChannels(fileInfo.channels),
					&fileData[0],
					sampleCount*sizeof(ALushort),
					fileInfo.samplerate);

				sf_close(file);
			}

			// Create new audio source
			m_sounds.push_back(
				SoundHandle(new AudioChunk(itr->second.buffer, itr->second.fileName)));

			return m_sounds.back();
		}
		else
		{
			JL_WARNING_LOG("Couldn't find any sound by the name '%s'", name.c_str());
			return SoundHandle(nullptr);
		}
	}
コード例 #4
0
	StreamHandle AudioDevice::createStream(const std::string &name)
	{
		// Perform cleanup before creating new streams
		audioCleanup();

		auto itr = m_audioFiles.find(name);
		if(itr != m_audioFiles.end())
		{
			// Create new audio source
			m_streams.push_back(
				StreamHandle(new AudioStream(itr->second.fileName)));

			return m_streams.back();
		}
		else
		{
			JL_WARNING_LOG("Couldn't find any stream by the name '%s'", name.c_str());
			return StreamHandle();
		}
	}