diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index b0bb0a1a0..080fcd287 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -64,7 +64,7 @@ jobs:
-sdk macosx \
-configuration "Release (Default)" \
-destination generic/platform=macOS \
- GCC_PREPROCESSOR_DEFINITIONS='MISSING_SOUND_DATA $(GCC_PREPROCESSOR_DEFINITIONS)' \
+ GCC_PREPROCESSOR_DEFINITIONS='$(GCC_PREPROCESSOR_DEFINITIONS)' \
-quiet \
clean archive
# @NOTE: Newer versions of Xcode will complain and refuse to build old XIB files or target old iOS versions
@@ -83,7 +83,7 @@ jobs:
# -sdk iphoneos \
# -configuration "Release (iOS)" \
# -destination generic/platform=iOS \
- # GCC_PREPROCESSOR_DEFINITIONS='MISSING_SOUND_DATA $(GCC_PREPROCESSOR_DEFINITIONS)' \
+ # GCC_PREPROCESSOR_DEFINITIONS='$(GCC_PREPROCESSOR_DEFINITIONS)' \
# -quiet \
# clean archive
android:
diff --git a/.gitignore b/.gitignore
index 85fe04251..20855b3ec 100644
--- a/.gitignore
+++ b/.gitignore
@@ -211,6 +211,12 @@ xcuserdata/
/game/assets/gui/touchgui2.png
/game/assets/item/arrows.png
/game/assets/item/sign.png
+# Sound
+/game/assets/sound
+/game/assets/newsound
+/game/assets/sound3
+/game/assets/music
+/game/assets/newmusic
# Java
/game/assets/terrain/sun.png
/game/assets/terrain/moon.png
@@ -242,11 +248,11 @@ xcuserdata/
# Ignore options.txt - where your configuration will be saved
/game/options.txt
/game/assetsO
-/game/assets/gui/feedback_fill.png
-/game/assets/gui/feedback_outer.png
-/game/assets/snow.png
-/game/assets/mob/pig.png
# CLion
/.idea
-/cmake-build-*
\ No newline at end of file
+/cmake-build-*
+
+# PCM sound extraction
+/tools/__pycache__
+/tools/venv
diff --git a/README.md b/README.md
index d72711ee5..db51a0e0f 100644
--- a/README.md
+++ b/README.md
@@ -68,12 +68,19 @@ This fetches the three dependencies we have:
- [coi-serviceworker](https://github.com/gzuidhof/coi-serviceworker)
- [gles-compatibility-layer](https://github.com/TheBrokenRail/gles-compatibility-layer.git)
-2. Load the sound assets into the `sound_data/` folder in the root of the project
-by **running the following command**:
-* `tools/grabsounds.py /path/to/the/apk/lib/armeabi-v7a/libminecraftpe.so`.
-
-After that, **prepare the assets folder** from the apk. You will need it for the platform specific
-build.
+2. Copy the assets (including sounds and textures) into the necessary folders within the project.
+ Do this by performing **one** of the following:
+ - To extract all assets from _Pocket Edition_:
+ - **Run the following command**:
+ - `tools/extract_apk.py /path/to/the/apk`
+ - You can also run it with an interactive GUI by not providing arguments.
+ - To extract only the sounds from _Pocket Edition_:
+ - **Run the following command**:
+ - `tools/grabsounds.py /path/to/the/apk/lib/armeabi-v7a/libminecraftpe.so`
+ - You will need to extract textures and other assets manually.
+ - To retrieve only the sounds from _Java Edition_:
+ - Locate the `resources` directory in the `.minecraft` folder and copy its contents (e.g. `music`, `sound`, etc.) into the `game/assets/` directory of the project.
+ - You will need to extract textures and other assets manually from _Pocket Edition_.
## Building
diff --git a/platforms/android/AppPlatform_android.cpp b/platforms/android/AppPlatform_android.cpp
index 0f6fd4a4e..d8de4b86b 100644
--- a/platforms/android/AppPlatform_android.cpp
+++ b/platforms/android/AppPlatform_android.cpp
@@ -357,3 +357,22 @@ int AppPlatform_android::getKeyboardUpOffset()
// For now we'll just return 1/2 of the screen height. That ought to cover most cases.
return m_ScreenHeight / 2;
}
+
+AssetFile AppPlatform_android::readAssetFile(const std::string& str, bool quiet) const
+{
+ std::string realPath = str;
+ if (realPath.size() && realPath[0] == '/')
+ // trim it off
+ realPath = realPath.substr(1);
+
+ AAsset* asset = AAssetManager_open(m_app->activity->assetManager, str.c_str(), AASSET_MODE_BUFFER);
+ if (!asset) {
+ if (!quiet) LOG_E("File %s couldn't be opened", realPath.c_str());
+ return AssetFile();
+ }
+ size_t cnt = AAsset_getLength(asset);
+ unsigned char* buffer = new unsigned char[cnt];
+ AAsset_read(asset, (void*)buffer, cnt);
+ AAsset_close(asset);
+ return AssetFile(ssize_t(cnt), buffer);
+}
\ No newline at end of file
diff --git a/platforms/android/AppPlatform_android.hpp b/platforms/android/AppPlatform_android.hpp
index 3e6de84f6..f7420a7c5 100644
--- a/platforms/android/AppPlatform_android.hpp
+++ b/platforms/android/AppPlatform_android.hpp
@@ -62,6 +62,8 @@ class AppPlatform_android : public AppPlatform
void initAndroidApp(android_app* ptr);
void setExternalStoragePath(const std::string& path);
+ AssetFile readAssetFile(const std::string&, bool) const override;
+
private:
void changeKeyboardVisibility(bool bShown);
diff --git a/platforms/macos/projects/Minecraft/Minecraft.xcodeproj/project.pbxproj b/platforms/macos/projects/Minecraft/Minecraft.xcodeproj/project.pbxproj
index c0dfd30a8..6bfc4cf21 100644
--- a/platforms/macos/projects/Minecraft/Minecraft.xcodeproj/project.pbxproj
+++ b/platforms/macos/projects/Minecraft/Minecraft.xcodeproj/project.pbxproj
@@ -200,6 +200,8 @@
8426107E2AE989730065905F /* RakNetInstance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 840DD64E2AC810620006A435 /* RakNetInstance.cpp */; };
8426107F2AE989730065905F /* ServerSideNetworkHandler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 840DD6502AC810620006A435 /* ServerSideNetworkHandler.cpp */; };
842610882AE98A4C0065905F /* libRakNet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 84FFBD7E2ACA2876005A8CCF /* libRakNet.a */; };
+ 8435BB192DCD47F400D38282 /* SoundStreamAL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8435BB182DCD47F400D38282 /* SoundStreamAL.cpp */; };
+ 8435BB1A2DCD47F400D38282 /* SoundStreamAL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8435BB182DCD47F400D38282 /* SoundStreamAL.cpp */; };
8441F98F2DB4E911005977BD /* SoundSystemAL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8441F9862DB4E911005977BD /* SoundSystemAL.cpp */; };
8441F9962DB4E911005977BD /* SoundSystemAL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8441F9862DB4E911005977BD /* SoundSystemAL.cpp */; };
8443B6EA2A98675F0086730C /* libSDL2.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 8443B6E92A98675F0086730C /* libSDL2.a */; };
@@ -393,6 +395,11 @@
849FF0DC2AF465340013BAE3 /* char.png in Resources */ = {isa = PBXBuildFile; fileRef = 84E0018E2AF3A28B009B9555 /* char.png */; };
849FF0DD2AF465340013BAE3 /* particles.png in Resources */ = {isa = PBXBuildFile; fileRef = 84E0018F2AF3A28B009B9555 /* particles.png */; };
849FF0DE2AF465340013BAE3 /* terrain.png in Resources */ = {isa = PBXBuildFile; fileRef = 84E001912AF3A28B009B9555 /* terrain.png */; };
+ 84A2FF162DB5B7B70090CE3E /* AssetFile.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 84A2FF152DB5B7B70090CE3E /* AssetFile.hpp */; };
+ 84A2FF182DB61D440090CE3E /* SoundPathRepository.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 84A2FF172DB61D3A0090CE3E /* SoundPathRepository.hpp */; };
+ 84A2FF1A2DB61D720090CE3E /* SoundPathRepository.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84A2FF192DB61D6D0090CE3E /* SoundPathRepository.cpp */; };
+ 84A2FF1C2DB61F650090CE3E /* SoundStream.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 84A2FF1B2DB61F610090CE3E /* SoundStream.hpp */; };
+ 84A2FF1E2DB61F6C0090CE3E /* SoundStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84A2FF1D2DB61F690090CE3E /* SoundStream.cpp */; };
84AA8B502B32F39A003F5B82 /* BinaryHeap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84AA8B482B32F39A003F5B82 /* BinaryHeap.cpp */; };
84AA8B512B32F39A003F5B82 /* BinaryHeap.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 84AA8B492B32F39A003F5B82 /* BinaryHeap.hpp */; };
84AA8B522B32F39A003F5B82 /* Node.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84AA8B4A2B32F39A003F5B82 /* Node.cpp */; };
@@ -1776,6 +1783,8 @@
84336BA52B1EB57E00097DB0 /* Settings_iOS_Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Settings_iOS_Debug.xcconfig; path = ../Configuration/Settings_iOS_Debug.xcconfig; sourceTree = ""; };
84336BA82B1EB88500097DB0 /* Settings_macOS.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Settings_macOS.xcconfig; path = ../Configuration/Settings_macOS.xcconfig; sourceTree = ""; };
84336BA92B1EB9C200097DB0 /* Settings_macOS_Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Settings_macOS_Debug.xcconfig; path = ../Configuration/Settings_macOS_Debug.xcconfig; sourceTree = ""; };
+ 8435BB172DCD47F400D38282 /* SoundStreamAL.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = SoundStreamAL.hpp; sourceTree = ""; };
+ 8435BB182DCD47F400D38282 /* SoundStreamAL.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SoundStreamAL.cpp; sourceTree = ""; };
8441F9852DB4E911005977BD /* CustomSoundSystem.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = CustomSoundSystem.hpp; sourceTree = ""; };
8441F9862DB4E911005977BD /* SoundSystemAL.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SoundSystemAL.cpp; sourceTree = ""; };
8443B6E92A98675F0086730C /* libSDL2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libSDL2.a; path = /opt/local/lib/libSDL2.a; sourceTree = ""; };
@@ -1925,6 +1934,11 @@
849488352C9284DA006DB706 /* Lighting.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Lighting.hpp; sourceTree = ""; };
8495E4872AF0905B00A06901 /* AppPlatform_iOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppPlatform_iOS.h; sourceTree = ""; };
8495E4882AF0905B00A06901 /* AppPlatform_iOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AppPlatform_iOS.mm; sourceTree = ""; };
+ 84A2FF152DB5B7B70090CE3E /* AssetFile.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = AssetFile.hpp; sourceTree = ""; };
+ 84A2FF172DB61D3A0090CE3E /* SoundPathRepository.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = SoundPathRepository.hpp; sourceTree = ""; };
+ 84A2FF192DB61D6D0090CE3E /* SoundPathRepository.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SoundPathRepository.cpp; sourceTree = ""; };
+ 84A2FF1B2DB61F610090CE3E /* SoundStream.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = SoundStream.hpp; sourceTree = ""; };
+ 84A2FF1D2DB61F690090CE3E /* SoundStream.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SoundStream.cpp; sourceTree = ""; };
84AA8B482B32F39A003F5B82 /* BinaryHeap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BinaryHeap.cpp; sourceTree = ""; };
84AA8B492B32F39A003F5B82 /* BinaryHeap.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = BinaryHeap.hpp; sourceTree = ""; };
84AA8B4A2B32F39A003F5B82 /* Node.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Node.cpp; sourceTree = ""; };
@@ -2314,14 +2328,15 @@
840DD57D2AC810620006A435 /* app */ = {
isa = PBXGroup;
children = (
- 840DD57E2AC810620006A435 /* App.cpp */,
840DD57F2AC810620006A435 /* App.hpp */,
- 840DD5802AC810620006A435 /* AppPlatform.cpp */,
+ 840DD57E2AC810620006A435 /* App.cpp */,
840DD5812AC810620006A435 /* AppPlatform.hpp */,
- 840DD5822AC810620006A435 /* Minecraft.cpp */,
+ 840DD5802AC810620006A435 /* AppPlatform.cpp */,
+ 84A2FF152DB5B7B70090CE3E /* AssetFile.hpp */,
840DD5832AC810620006A435 /* Minecraft.hpp */,
- 840DD5842AC810620006A435 /* NinecraftApp.cpp */,
+ 840DD5822AC810620006A435 /* Minecraft.cpp */,
840DD5852AC810620006A435 /* NinecraftApp.hpp */,
+ 840DD5842AC810620006A435 /* NinecraftApp.cpp */,
);
path = app;
sourceTree = "";
@@ -2531,15 +2546,19 @@
840DD61A2AC810620006A435 /* sound */ = {
isa = PBXGroup;
children = (
- 840DD61B2AC810620006A435 /* SoundData.cpp */,
+ 84A2FF172DB61D3A0090CE3E /* SoundPathRepository.hpp */,
+ 84A2FF192DB61D6D0090CE3E /* SoundPathRepository.cpp */,
840DD61C2AC810620006A435 /* SoundData.hpp */,
+ 840DD61B2AC810620006A435 /* SoundData.cpp */,
840DD61D2AC810620006A435 /* SoundDefs.hpp */,
- 840DD61E2AC810620006A435 /* SoundEngine.cpp */,
840DD61F2AC810620006A435 /* SoundEngine.hpp */,
- 840DD6202AC810620006A435 /* SoundRepository.cpp */,
+ 840DD61E2AC810620006A435 /* SoundEngine.cpp */,
840DD6212AC810620006A435 /* SoundRepository.hpp */,
- 840DD6222AC810620006A435 /* SoundSystem.cpp */,
+ 840DD6202AC810620006A435 /* SoundRepository.cpp */,
+ 84A2FF1B2DB61F610090CE3E /* SoundStream.hpp */,
+ 84A2FF1D2DB61F690090CE3E /* SoundStream.cpp */,
840DD6232AC810620006A435 /* SoundSystem.hpp */,
+ 840DD6222AC810620006A435 /* SoundSystem.cpp */,
);
path = sound;
sourceTree = "";
@@ -3383,6 +3402,8 @@
isa = PBXGroup;
children = (
8441F9852DB4E911005977BD /* CustomSoundSystem.hpp */,
+ 8435BB172DCD47F400D38282 /* SoundStreamAL.hpp */,
+ 8435BB182DCD47F400D38282 /* SoundStreamAL.cpp */,
8441F9862DB4E911005977BD /* SoundSystemAL.cpp */,
);
path = openal;
@@ -4081,9 +4102,11 @@
84AA8C232B32F3F3003F5B82 /* ItemInHandRenderer.hpp in Headers */,
84AA8C272B32F3F3003F5B82 /* LevelRenderer.hpp in Headers */,
84AA8C292B32F3F3003F5B82 /* LightLayer.hpp in Headers */,
+ 84A2FF182DB61D440090CE3E /* SoundPathRepository.hpp in Headers */,
84AA8C2B2B32F3F3003F5B82 /* LightUpdate.hpp in Headers */,
84AA8C2D2B32F3F3003F5B82 /* PatchManager.hpp in Headers */,
84AA8C2F2B32F3F3003F5B82 /* RenderChunk.hpp in Headers */,
+ 84A2FF162DB5B7B70090CE3E /* AssetFile.hpp in Headers */,
84AA8C312B32F3F3003F5B82 /* RenderList.hpp in Headers */,
84AA8C332B32F3F3003F5B82 /* Tesselator.hpp in Headers */,
84AA8C342B32F3F3003F5B82 /* Texture.hpp in Headers */,
@@ -4092,6 +4115,7 @@
84AA8C392B32F3F3003F5B82 /* VertexPT.hpp in Headers */,
84AA8C5B2B32F535003F5B82 /* ChickenModel.hpp in Headers */,
84AA8C5D2B32F535003F5B82 /* CowModel.hpp in Headers */,
+ 84A2FF1C2DB61F650090CE3E /* SoundStream.hpp in Headers */,
84AA8C5F2B32F535003F5B82 /* CreeperModel.hpp in Headers */,
84AA8C672B32F535003F5B82 /* ModelPart.hpp in Headers */,
84AA8C692B32F535003F5B82 /* PigModel.hpp in Headers */,
@@ -4856,6 +4880,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 8435BB192DCD47F400D38282 /* SoundStreamAL.cpp in Sources */,
84EAE8F72AF1EAFA000894E8 /* main.cpp in Sources */,
841DD8772AF8AA7A00AA3B66 /* AppPlatform_sdl_base.cpp in Sources */,
841DD8782AF8AA7A00AA3B66 /* AppPlatform_sdl.cpp in Sources */,
@@ -4877,6 +4902,7 @@
8441F98F2DB4E911005977BD /* SoundSystemAL.cpp in Sources */,
84CEF0032AE3C97D006C5829 /* EAGLView.m in Sources */,
8495E4892AF0905B00A06901 /* AppPlatform_iOS.mm in Sources */,
+ 8435BB1A2DCD47F400D38282 /* SoundStreamAL.cpp in Sources */,
8488C08A2B1EDD4F001AEC4F /* ShowKeyboardView.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -4984,6 +5010,7 @@
84AA8C182B32F3F3003F5B82 /* Font.cpp in Sources */,
84AA8C1A2B32F3F3003F5B82 /* Frustum.cpp in Sources */,
84AA8C1C2B32F3F3003F5B82 /* FrustumCuller.cpp in Sources */,
+ 84A2FF1A2DB61D720090CE3E /* SoundPathRepository.cpp in Sources */,
84AA8C1E2B32F3F3003F5B82 /* GameRenderer.cpp in Sources */,
84AA8C202B32F3F3003F5B82 /* GrassColor.cpp in Sources */,
84AA8C222B32F3F3003F5B82 /* ItemInHandRenderer.cpp in Sources */,
@@ -4998,6 +5025,7 @@
84AA8C302B32F3F3003F5B82 /* RenderList.cpp in Sources */,
84AA8C322B32F3F3003F5B82 /* Tesselator.cpp in Sources */,
84AA8C352B32F3F3003F5B82 /* Textures.cpp in Sources */,
+ 84A2FF1E2DB61F6C0090CE3E /* SoundStream.cpp in Sources */,
84AA8C372B32F3F3003F5B82 /* TileRenderer.cpp in Sources */,
84AA8C3A2B32F3F3003F5B82 /* WaterSideTexture.cpp in Sources */,
84AA8C3B2B32F3F3003F5B82 /* WaterTexture.cpp in Sources */,
diff --git a/platforms/sdl/base/AppPlatform_sdl_base.cpp b/platforms/sdl/base/AppPlatform_sdl_base.cpp
index aeeada144..dcbecc134 100644
--- a/platforms/sdl/base/AppPlatform_sdl_base.cpp
+++ b/platforms/sdl/base/AppPlatform_sdl_base.cpp
@@ -397,4 +397,31 @@ void AppPlatform_sdl_base::handleControllerAxisEvent(SDL_JoystickID controllerIn
Controller::feedTrigger(2, val);
break;
}
+}
+
+AssetFile AppPlatform_sdl_base::readAssetFile(const std::string& str, bool quiet) const
+{
+ std::string path = getAssetPath(str);
+ SDL_RWops *io = SDL_RWFromFile(path.c_str(), "rb");
+ // Open File
+ if (!io)
+ {
+ if (!quiet) LOG_W("Couldn't find asset file: %s", path.c_str());
+ return AssetFile();
+ }
+ // Get File Size
+ int64_t size = SDL_RWsize(io);
+ if (size < 0)
+ {
+ if (!quiet) LOG_E("Error determining the size of the asset file!");
+ SDL_RWclose(io);
+ return AssetFile();
+ }
+ // Read Data
+ unsigned char *buf = new unsigned char[size];
+ SDL_RWread(io, buf, size, 1);
+ // Close File
+ SDL_RWclose(io);
+ // Return
+ return AssetFile(size, buf);
}
\ No newline at end of file
diff --git a/platforms/sdl/base/AppPlatform_sdl_base.hpp b/platforms/sdl/base/AppPlatform_sdl_base.hpp
index 4e34e8285..7fe614cef 100644
--- a/platforms/sdl/base/AppPlatform_sdl_base.hpp
+++ b/platforms/sdl/base/AppPlatform_sdl_base.hpp
@@ -61,6 +61,9 @@ class AppPlatform_sdl_base : public AppPlatform
void handleKeyEvent(int key, uint8_t state);
void handleButtonEvent(SDL_JoystickID controllerIndex, uint8_t button, uint8_t state);
void handleControllerAxisEvent(SDL_JoystickID controllerIndex, uint8_t axis, int16_t value);
+
+ // Read Sounds
+ AssetFile readAssetFile(const std::string&, bool) const override;
protected:
SDL_Window *_window;
private:
diff --git a/platforms/sound/directsound/CustomSoundSystem.hpp b/platforms/sound/directsound/CustomSoundSystem.hpp
index de50e210c..bac276636 100644
--- a/platforms/sound/directsound/CustomSoundSystem.hpp
+++ b/platforms/sound/directsound/CustomSoundSystem.hpp
@@ -29,15 +29,13 @@ class SoundSystemDS : public SoundSystem
public:
SoundSystemDS();
~SoundSystemDS();
- virtual bool isAvailable();
- virtual void setListenerPos(float x, float y, float z);
- virtual void setListenerAngle(float yaw, float pitch);
- virtual void load(const std::string& sound);
- virtual void play(const std::string& sound);
- virtual void pause(const std::string& sound);
- virtual void stop(const std::string& sound);
- virtual void playAt(const SoundDesc& sound, float x, float y, float z, float a, float b);
+ virtual bool isAvailable() override;
+ virtual void setListenerPos(const Vec3& pos) override;
+ virtual void setListenerAngle(const Vec2& rot) override;
+ virtual void playAt(const SoundDesc& sound, const Vec3& pos, float volume, float pitch) override;
private:
+ WAVEFORMATEX _getWaveFormat(const PCMSoundHeader& header, float pitch) const;
+ void _cleanSources();
struct BufferInfo
{
diff --git a/platforms/sound/directsound/SoundSystemDS.cpp b/platforms/sound/directsound/SoundSystemDS.cpp
index a13a04241..26827c138 100644
--- a/platforms/sound/directsound/SoundSystemDS.cpp
+++ b/platforms/sound/directsound/SoundSystemDS.cpp
@@ -83,25 +83,25 @@ bool SoundSystemDS::isAvailable()
return m_available;
}
-void SoundSystemDS::setListenerPos(float x, float y, float z)
+void SoundSystemDS::setListenerPos(const Vec3& pos)
{
if (!isAvailable())
{
return;
}
- m_listener->SetPosition(x, y, -z, DS3D_IMMEDIATE);
+ m_listener->SetPosition(pos.x, pos.y, -pos.z, DS3D_IMMEDIATE);
}
-void SoundSystemDS::setListenerAngle(float degyaw, float degpitch)
+void SoundSystemDS::setListenerAngle(const Vec2& rot)
{
if (!isAvailable())
{
return;
}
- float yaw = degyaw * M_PI / 180.f;
- float pitch = degpitch * M_PI / 180.f;
+ float yaw = rot.x * M_PI / 180.f;
+ float pitch = rot.y * M_PI / 180.f;
float lx = cosf(pitch) * sinf(yaw);
float ly = -sinf(pitch);
@@ -114,71 +114,29 @@ void SoundSystemDS::setListenerAngle(float degyaw, float degpitch)
m_listener->SetOrientation(-lx,-ly,-lz, ux,uy,uz, DS3D_IMMEDIATE);
}
-void SoundSystemDS::load(const std::string& sound)
+void SoundSystemDS::playAt(const SoundDesc& sound, const Vec3& pos, float volume, float pitch)
{
-}
-
-void SoundSystemDS::play(const std::string& sound)
-{
-}
-
-void SoundSystemDS::pause(const std::string& sound)
-{
-}
-
-void SoundSystemDS::stop(const std::string& sound)
-{
-}
-
-
-void SoundSystemDS::playAt(const SoundDesc& sound, float x, float y, float z, float volume, float pitch)
-{
- //Directsound failed to initialize return to avoid crash.
if (!isAvailable())
{
+ // DirectSound failed to initialize. Return to avoid crash.
+ assert(!"DirectSound is not initialized!");
return;
}
- //Release sounds that finished playing
- for (size_t i = 0; i < m_buffers.size(); i++)
- {
- DWORD status;
- m_buffers[i].buffer->GetStatus(&status);
- if (status != DSBSTATUS_PLAYING) {
- m_buffers[i].buffer->Release();
- if (m_buffers[i].object3d != NULL)
- {
- m_buffers[i].object3d->Release();
- }
- m_buffers.erase(m_buffers.begin() + i);
- i--;
- }
- }
+ // Release sounds that finished playing
+ _cleanSources();
HRESULT result;
IDirectSoundBuffer* tempBuffer;
unsigned char* bufferPtr;
unsigned long bufferSize;
- int length = sound.m_pHeader->m_length * sound.m_pHeader->m_bytes_per_sample;
- bool is2D = sqrtf(x * x + y * y + z * z) == 0.f;
-
- //For some reason mojang made 3D sounds are REALLY quiet, with some of their volumes literally going below 0.1
- if (!is2D)
- {
- volume *= 5.f;
- }
+ int length = sound.m_header.m_length * sound.m_header.m_bytes_per_sample;
+ bool is2D = pos.length() == 0.0f;
LPDIRECTSOUNDBUFFER soundbuffer; //= (LPDIRECTSOUNDBUFFER*)calloc(1, sizeof(LPDIRECTSOUNDBUFFER));
- WAVEFORMATEX waveFormat;
- waveFormat.wFormatTag = WAVE_FORMAT_PCM;
- waveFormat.nSamplesPerSec = DWORD(float(sound.m_pHeader->m_sample_rate) * pitch);
- waveFormat.wBitsPerSample = 8 * sound.m_pHeader->m_bytes_per_sample;
- waveFormat.nChannels = sound.m_pHeader->m_channels;
- waveFormat.nBlockAlign = (waveFormat.wBitsPerSample / 8) * waveFormat.nChannels;
- waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign;
- waveFormat.cbSize = 0;
+ WAVEFORMATEX waveFormat = _getWaveFormat(sound.m_header, pitch);
// Set the buffer description of the secondary sound buffer that the wave file will be loaded onto.
DSBUFFERDESC bufferDesc;
@@ -230,7 +188,7 @@ void SoundSystemDS::playAt(const SoundDesc& sound, float x, float y, float z, fl
}
//Move the wave data into the buffer.
- memcpy(bufferPtr, sound.m_pData, length);
+ memcpy(bufferPtr, sound.m_buffer.m_pData, length);
// Unlock the secondary buffer after the data has been written to it.
result = soundbuffer->Unlock((void*)bufferPtr, bufferSize, NULL, 0);
@@ -245,12 +203,8 @@ void SoundSystemDS::playAt(const SoundDesc& sound, float x, float y, float z, fl
// https://learn.microsoft.com/en-us/previous-versions/windows/desktop/mt708939(v=vs.85)
// Conversion from 0-1 linear volume to directsound logarithmic volume..
// This seems to work for the most part, but accuracy testing should be done for actual MCPE, water splashing is pretty quiet.
- float attenuation = volume;//Lerp(DSBVOLUME_MIN, DSBVOLUME_MAX, volume);
// clamp the attenuation value
- if (attenuation < 0.0f)
- attenuation = 0.0f;
- else if (attenuation > 1.0f)
- attenuation = 1.0f;
+ float attenuation = Mth::clamp(volume, 0.0f, 1.0f);//Lerp(DSBVOLUME_MIN, DSBVOLUME_MAX, volume);
if (attenuation == 0)
{
@@ -267,8 +221,8 @@ void SoundSystemDS::playAt(const SoundDesc& sound, float x, float y, float z, fl
info.buffer = soundbuffer;
info.object3d = NULL;
- //Check if position is not 0,0,0 and for mono to play 3D sound
- if (!is2D && sound.m_pHeader->m_channels == 1)
+ //Check if position is not 0,0,0 to play 3D sound
+ if (!is2D)
{
LPDIRECTSOUND3DBUFFER object3d;
@@ -279,11 +233,7 @@ void SoundSystemDS::playAt(const SoundDesc& sound, float x, float y, float z, fl
return;
}
- object3d->SetPosition(
- x,
- y,
- -z,
- DS3D_IMMEDIATE);
+ object3d->SetPosition(pos.x, pos.y, -pos.z, DS3D_IMMEDIATE);
//Im not really sure what values original MCPE would use.
object3d->SetMinDistance(2.f, DS3D_IMMEDIATE);
@@ -295,4 +245,40 @@ void SoundSystemDS::playAt(const SoundDesc& sound, float x, float y, float z, fl
soundbuffer->Play(0, 0, 0);
m_buffers.push_back(info);
-}
\ No newline at end of file
+}
+
+WAVEFORMATEX SoundSystemDS::_getWaveFormat(const PCMSoundHeader& header, float pitch) const
+{
+ WAVEFORMATEX wf;
+
+ wf.wFormatTag = WAVE_FORMAT_PCM;
+ wf.nSamplesPerSec = DWORD(float(header.m_sample_rate) * pitch);
+ wf.wBitsPerSample = 8 * header.m_bytes_per_sample;
+ wf.nChannels = header.m_channels;
+ wf.nBlockAlign = (wf.wBitsPerSample / 8) * wf.nChannels;
+ wf.nAvgBytesPerSec = wf.nSamplesPerSec * wf.nBlockAlign;
+ wf.cbSize = 0;
+
+ return wf;
+}
+
+// Release sounds that finished playing
+void SoundSystemDS::_cleanSources()
+{
+ for (size_t i = 0; i < m_buffers.size(); i++)
+ {
+ DWORD status;
+ m_buffers[i].buffer->GetStatus(&status);
+ if (status != DSBSTATUS_PLAYING)
+ {
+ m_buffers[i].buffer->Release();
+ if (m_buffers[i].object3d != NULL)
+ {
+ m_buffers[i].object3d->Release();
+ }
+
+ m_buffers.erase(m_buffers.begin() + i);
+ i--;
+ }
+ }
+}
diff --git a/platforms/sound/openal/CMakeLists.txt b/platforms/sound/openal/CMakeLists.txt
index 101c05f28..881769405 100644
--- a/platforms/sound/openal/CMakeLists.txt
+++ b/platforms/sound/openal/CMakeLists.txt
@@ -4,6 +4,7 @@ project(reminecraftpe-openal)
# Build
add_library(reminecraftpe-sound STATIC
SoundSystemAL.cpp
+ SoundStreamAL.cpp
)
# Core
diff --git a/platforms/sound/openal/CustomSoundSystem.hpp b/platforms/sound/openal/CustomSoundSystem.hpp
index 639566914..c00e01d6f 100644
--- a/platforms/sound/openal/CustomSoundSystem.hpp
+++ b/platforms/sound/openal/CustomSoundSystem.hpp
@@ -1,18 +1,6 @@
#pragma once
-#ifdef __APPLE__
-#include
-#include
-#elif defined(__EMSCRIPTEN__)
-#include
-#include
-#else
-#include "al.h"
-#include "alc.h"
-#ifdef _WIN32
-#pragma comment( lib, "OpenAL32.lib" )
-#endif
-#endif
+#include "thirdparty/OpenAL.h"
#include
#include