Sfoglia il codice sorgente

Getting OpenAudio functional
- Fixing importer
- Fixing device enumeration
- Fixing uncompressed audio clip creation
New splash screen

BearishSun 9 anni fa
parent
commit
f786c98c14

+ 6 - 4
Source/BansheeCore/Include/BsAudioClipImportOptions.h

@@ -16,6 +16,8 @@ namespace BansheeEngine
 	class BS_CORE_EXPORT AudioClipImportOptions : public ImportOptions
 	{
 	public:
+		AudioClipImportOptions();
+
 		/** Returns the audio format to import the audio clip as. */
 		AudioFormat getFormat() const { return mFormat; }
 
@@ -46,10 +48,10 @@ namespace BansheeEngine
 		// Note: Add options to resample to a different frequency
 
 	private:
-		AudioFormat mFormat = AudioFormat::PCM;
-		AudioReadMode mReadMode = AudioReadMode::LoadDecompressed;
-		bool mIs3D = true;
-		UINT32 mBitDepth = 16;
+		AudioFormat mFormat;
+		AudioReadMode mReadMode;
+		bool mIs3D;
+		UINT32 mBitDepth;
 
 		/************************************************************************/
 		/* 								SERIALIZATION                      		*/

+ 6 - 0
Source/BansheeCore/Source/BsAudioClipImportOptions.cpp

@@ -5,6 +5,12 @@
 
 namespace BansheeEngine
 {
+	AudioClipImportOptions::AudioClipImportOptions()
+		:mFormat(AudioFormat::PCM), mReadMode(AudioReadMode::LoadDecompressed), mIs3D(true), mBitDepth(16)
+	{
+		
+	}
+
 	/************************************************************************/
 	/* 								SERIALIZATION                      		*/
 	/************************************************************************/

+ 2 - 2
Source/BansheeEngine/Source/BsSplashScreen.cpp

@@ -38,8 +38,8 @@ namespace BansheeEngine
 
 		WINDOW_DESC windowDesc;
 		windowDesc.border = WindowBorder::None;
-		windowDesc.width = 600;
-		windowDesc.height = 662;
+		windowDesc.width = 675;
+		windowDesc.height = 821;
 		windowDesc.left = -1;
 		windowDesc.top = -1;
 		windowDesc.title = "Banshee Splash";

+ 3 - 0
Source/BansheeOpenAudio/Include/BsOAImporter.h

@@ -26,6 +26,9 @@ namespace BansheeEngine
 
 		/** @copydoc SpecificImporter::import */
 		SPtr<Resource> import(const Path& filePath, SPtr<const ImportOptions> importOptions) override;
+
+		/** @copydoc SpecificImporter::createImportOptions */
+		SPtr<ImportOptions> createImportOptions() const override;
 	};
 
 	/** @} */

+ 6 - 1
Source/BansheeOpenAudio/Source/BsOAAudio.cpp

@@ -30,9 +30,14 @@ namespace BansheeEngine
 					if (deviceName.size() == 0)
 						break;
 
-					mAllDevices.push_back({ WString(deviceName.data(), deviceName.size()) });
+					// Clean up the name to get the actual hardware name
+					WString fixedName(deviceName.data(), deviceName.size());
+					fixedName = StringUtil::replaceAll(fixedName, L"OpenAL Soft on ", L"");
+
+					mAllDevices.push_back({ fixedName });
 					deviceName.clear();
 
+					devices++;
 					continue;
 				}
 

+ 29 - 17
Source/BansheeOpenAudio/Source/BsOAAudioClip.cpp

@@ -43,9 +43,10 @@ namespace BansheeEngine
 				mSourceStreamSize = mStreamSize;
 			}
 
-			if(mDesc.readMode == AudioReadMode::LoadDecompressed && mDesc.format == AudioFormat::VORBIS)
+			// Load decompressed data into a sound buffer
+			if(mDesc.readMode == AudioReadMode::LoadDecompressed)
 			{
-				// Read all uncompressed data into memory
+				// Read all data into memory
 				SPtr<DataStream> stream;
 				UINT32 offset = 0;
 				if (mSourceStreamData != nullptr) // If it's already loaded in memory, use it directly
@@ -57,28 +58,34 @@ namespace BansheeEngine
 				}
 
 				stream->seek(offset);
+				UINT32 bufferSize = info.numSamples * (info.bitDepth / 8);
+				UINT8* sampleBuffer = (UINT8*)bs_stack_alloc(bufferSize);
 
 				// Decompress from Ogg
-				OAOggVorbisReader reader;
-				if (reader.open(stream, info))
+				if (mDesc.format == AudioFormat::VORBIS)
 				{
-					UINT32 bufferSize = info.numSamples * info.bitDepth;
-					UINT8* sampleBuffer = (UINT8*)bs_stack_alloc(bufferSize);
+					OAOggVorbisReader reader;
+					if (reader.open(stream, info))
+						reader.read(sampleBuffer, info.numSamples);
+					else
+						LOGERR("Failed decompressing AudioClip stream.");
+				}
+				// Load directly
+				else
+				{
+					stream->read(sampleBuffer, bufferSize);
+				}
 
-					reader.read(sampleBuffer, info.numSamples);
+				alGenBuffers(1, &mBufferId);
+				gOAAudio()._writeToOpenALBuffer(mBufferId, sampleBuffer, info);
 
-					alGenBuffers(1, &mBufferId);
-					gOAAudio()._writeToOpenALBuffer(mBufferId, sampleBuffer, info);
+				mStreamData = nullptr;
+				mStreamOffset = 0;
+				mStreamSize = 0;
 
-					mStreamData = nullptr;
-					mStreamOffset = 0;
-					mStreamSize = 0;
-
-					bs_stack_free(sampleBuffer);
-				}
-				else
-					LOGERR("Failed decompressing AudioClip stream.");
+				bs_stack_free(sampleBuffer);
 			}
+			// Load compressed data for streaming from memory
 			else if(mDesc.readMode == AudioReadMode::LoadCompressed)
 			{
 				// If reading from file, make a copy of data in memory, otherwise just take ownership of the existing buffer
@@ -99,6 +106,11 @@ namespace BansheeEngine
 					mStreamOffset = 0;
 				}
 			}
+			// Keep original stream for streaming from file
+			else
+			{
+				// Do nothing
+			}
 
 			if (mDesc.format == AudioFormat::VORBIS && mDesc.readMode != AudioReadMode::LoadDecompressed)
 			{

+ 11 - 5
Source/BansheeOpenAudio/Source/BsOAImporter.cpp

@@ -37,6 +37,11 @@ namespace BansheeEngine
 		return true;
 	}
 
+	SPtr<ImportOptions> OAImporter::createImportOptions() const
+	{
+		return bs_shared_ptr_new<AudioClipImportOptions>();
+	}
+
 	SPtr<Resource> OAImporter::import(const Path& filePath, SPtr<const ImportOptions> importOptions)
 	{
 		SPtr<DataStream> stream = FileSystem::openFile(filePath);
@@ -45,11 +50,11 @@ namespace BansheeEngine
 		StringUtil::toLowerCase(extension);
 
 		UPtr<OAFileReader> reader(nullptr, nullptr);
-		if(extension == L"wav")
+		if(extension == L".wav")
 			reader = bs_unique_ptr<OAFileReader>(bs_new<OAWaveReader>());
-		else if(extension == L"flac")
+		else if(extension == L".flac")
 			reader = bs_unique_ptr<OAFileReader>(bs_new<OAFLACReader>());
-		else if(extension == L"ogg")
+		else if(extension == L".ogg")
 			reader = bs_unique_ptr<OAFileReader>(bs_new<OAOggVorbisReader>());
 
 		if (reader == nullptr)
@@ -62,7 +67,8 @@ namespace BansheeEngine
 		if (!reader->open(stream, info))
 			return nullptr;
 
-		UINT32 bufferSize = info.numSamples * info.bitDepth;
+		UINT32 bytesPerSample = info.bitDepth / 8;
+		UINT32 bufferSize = info.numSamples * bytesPerSample;
 		UINT8* sampleBuffer = (UINT8*)bs_alloc(bufferSize);
 		reader->read(sampleBuffer, info.numSamples);
 
@@ -73,7 +79,7 @@ namespace BansheeEngine
 		{
 			UINT32 numSamplesPerChannel = info.numSamples / info.numChannels;
 
-			UINT32 monoBufferSize = numSamplesPerChannel * info.bitDepth;
+			UINT32 monoBufferSize = numSamplesPerChannel * bytesPerSample;
 			UINT8* monoBuffer = (UINT8*)bs_alloc(monoBufferSize);
 
 			AudioUtility::convertToMono(sampleBuffer, monoBuffer, info.bitDepth, numSamplesPerChannel, info.numChannels);

+ 10 - 7
Source/BansheeOpenAudio/Source/BsOAWaveReader.cpp

@@ -59,37 +59,40 @@ namespace BansheeEngine
 				return false;
 
 			UINT32 subChunkSize = 0;
-			if (mStream->read(&subChunkSize, sizeof(subChunkSize) != sizeof(subChunkSize)))
+			if (mStream->read(&subChunkSize, sizeof(subChunkSize)) != sizeof(subChunkSize))
 				return false;
 
 			// FMT chunk
 			if (subChunkId[0] == 'f' && subChunkId[1] == 'm' && subChunkId[2] == 't' && subChunkId[3] == ' ')
 			{
 				UINT16 format = 0;
-				if (mStream->read(&format, sizeof(format) != sizeof(format)))
+				if (mStream->read(&format, sizeof(format)) != sizeof(format))
 					return false;
 
 				if (format != 1) // It's not PCM
+				{
+					LOGWRN("Wave file doesn't contain raw PCM data. Not supported.");
 					return false;
+				}
 
 				UINT16 numChannels = 0;
-				if (mStream->read(&numChannels, sizeof(numChannels) != sizeof(numChannels)))
+				if (mStream->read(&numChannels, sizeof(numChannels)) != sizeof(numChannels))
 					return false;
 
 				UINT32 sampleRate = 0;
-				if (mStream->read(&sampleRate, sizeof(sampleRate) != sizeof(sampleRate)))
+				if (mStream->read(&sampleRate, sizeof(sampleRate)) != sizeof(sampleRate))
 					return false;
 
 				UINT32 byteRate = 0;
-				if (mStream->read(&byteRate, sizeof(byteRate) != sizeof(byteRate)))
+				if (mStream->read(&byteRate, sizeof(byteRate)) != sizeof(byteRate))
 					return false;
 
 				UINT16 blockAlign = 0;
-				if (mStream->read(&blockAlign, sizeof(blockAlign) != sizeof(blockAlign)))
+				if (mStream->read(&blockAlign, sizeof(blockAlign)) != sizeof(blockAlign))
 					return false;
 
 				UINT16 bitDepth = 0;
-				if (mStream->read(&bitDepth, sizeof(bitDepth) != sizeof(bitDepth)))
+				if (mStream->read(&bitDepth, sizeof(bitDepth)) != sizeof(bitDepth))
 					return false;
 
 				info.numChannels = numChannels;

+ 2 - 0
Source/SBansheeEditor/Source/BsScriptImportOptions.cpp

@@ -44,6 +44,8 @@ namespace BansheeEngine
 			return ScriptFontImportOptions::create(std::static_pointer_cast<FontImportOptions>(importOptions));
 		case TID_ScriptCodeImportOptions:
 			return ScriptScriptCodeImportOptions::create(std::static_pointer_cast<ScriptCodeImportOptions>(importOptions));
+		case TID_AudioClipImportOptions:
+			return ScriptAudioClipImportOptions::create(std::static_pointer_cast<AudioClipImportOptions>(importOptions));
 		}
 
 		MonoObject* managedInstance = metaData.scriptClass->createInstance();