mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-14 05:12:25 +08:00
+ Added SDL and SDL_Mixer to implement audio support
+ Added support for sound objects Supported formats: MP3, FLAC, OGG Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
4a221d0e9a
commit
7410f238ac
@ -11,10 +11,53 @@ find_package(OpenGL REQUIRED)
|
|||||||
find_package(GLUT REQUIRED)
|
find_package(GLUT REQUIRED)
|
||||||
find_package(ZLIB REQUIRED)
|
find_package(ZLIB REQUIRED)
|
||||||
find_package(Irrlicht REQUIRED)
|
find_package(Irrlicht REQUIRED)
|
||||||
|
find_package(SDL REQUIRED)
|
||||||
|
find_package(SDL_mixer REQUIRED)
|
||||||
find_package(LZ4 REQUIRED)
|
find_package(LZ4 REQUIRED)
|
||||||
|
|
||||||
include_directories(${X11_INCLUDE_DIR} ${IRRLICHT_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} .)
|
include_directories(${X11_INCLUDE_DIR} ${IRRLICHT_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} ${SDL_INCLUDE_DIRS} ${SDL_MIXER_INCLUDE_DIRS} .)
|
||||||
|
|
||||||
add_executable(wallengine main.cpp wallpaperengine/shaders/compiler.h wallpaperengine/shaders/compiler.cpp wallpaperengine/project.cpp wallpaperengine/project.h wallpaperengine/scene.cpp wallpaperengine/scene.h wallpaperengine/object.cpp wallpaperengine/object.h wallpaperengine/camera.cpp wallpaperengine/camera.h wallpaperengine/core.cpp wallpaperengine/core.h wallpaperengine/image.cpp wallpaperengine/image.h wallpaperengine/object3d.cpp wallpaperengine/object3d.h wallpaperengine/effect.cpp wallpaperengine/effect.h wallpaperengine/fs/utils.cpp wallpaperengine/fs/utils.h wallpaperengine/irrlicht.cpp wallpaperengine/irrlicht.h wallpaperengine/video/renderer.cpp wallpaperengine/video/renderer.h wallpaperengine/video/node.cpp wallpaperengine/video/node.h wallpaperengine/video/material.cpp wallpaperengine/video/material.h wallpaperengine/texture.cpp wallpaperengine/texture.h wallpaperengine/irr/CImageLoaderTEX.h wallpaperengine/irr/CImageLoaderTEX.cpp wallpaperengine/irr/CPkgReader.h wallpaperengine/irr/CPkgReader.cpp wallpaperengine/irr/CFileList.h wallpaperengine/irr/CFileList.cpp)
|
add_executable(
|
||||||
|
wallengine
|
||||||
|
main.cpp
|
||||||
|
wallpaperengine/shaders/compiler.h
|
||||||
|
wallpaperengine/shaders/compiler.cpp
|
||||||
|
wallpaperengine/project.cpp
|
||||||
|
wallpaperengine/project.h
|
||||||
|
wallpaperengine/scene.cpp
|
||||||
|
wallpaperengine/scene.h
|
||||||
|
wallpaperengine/object.cpp
|
||||||
|
wallpaperengine/object.h
|
||||||
|
wallpaperengine/camera.cpp
|
||||||
|
wallpaperengine/camera.h
|
||||||
|
wallpaperengine/core.cpp
|
||||||
|
wallpaperengine/core.h
|
||||||
|
wallpaperengine/image.cpp
|
||||||
|
wallpaperengine/image.h
|
||||||
|
wallpaperengine/object3d.cpp
|
||||||
|
wallpaperengine/object3d.h
|
||||||
|
wallpaperengine/effect.cpp
|
||||||
|
wallpaperengine/effect.h
|
||||||
|
wallpaperengine/fs/utils.cpp
|
||||||
|
wallpaperengine/fs/utils.h
|
||||||
|
wallpaperengine/irrlicht.cpp
|
||||||
|
wallpaperengine/irrlicht.h
|
||||||
|
wallpaperengine/video/renderer.cpp
|
||||||
|
wallpaperengine/video/renderer.h
|
||||||
|
wallpaperengine/video/node.cpp
|
||||||
|
wallpaperengine/video/node.h
|
||||||
|
wallpaperengine/video/material.cpp
|
||||||
|
wallpaperengine/video/material.h
|
||||||
|
wallpaperengine/texture.cpp
|
||||||
|
wallpaperengine/texture.h
|
||||||
|
wallpaperengine/irr/CImageLoaderTEX.h
|
||||||
|
wallpaperengine/irr/CImageLoaderTEX.cpp
|
||||||
|
wallpaperengine/irr/CPkgReader.h
|
||||||
|
wallpaperengine/irr/CPkgReader.cpp
|
||||||
|
wallpaperengine/irr/CFileList.h
|
||||||
|
wallpaperengine/irr/CFileList.cpp
|
||||||
|
wallpaperengine/sound.cpp
|
||||||
|
wallpaperengine/sound.h
|
||||||
|
)
|
||||||
|
|
||||||
target_link_libraries(wallengine ${X11_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY})
|
target_link_libraries(wallengine ${X11_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${IRRLICHT_LIBRARY} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES})
|
@ -13,6 +13,8 @@ Wallpaper Engine is a software designed by [Kristjan Skutta](https://store.steam
|
|||||||
- Irrlicht
|
- Irrlicht
|
||||||
- LZ4
|
- LZ4
|
||||||
- ZLIB
|
- ZLIB
|
||||||
|
- SDL
|
||||||
|
- SDL_mixer
|
||||||
|
|
||||||
# 5. How to use
|
# 5. How to use
|
||||||
## 5.1. Pre-requirements
|
## 5.1. Pre-requirements
|
||||||
|
25
main.cpp
25
main.cpp
@ -5,6 +5,8 @@
|
|||||||
#include <wallpaperengine/video/material.h>
|
#include <wallpaperengine/video/material.h>
|
||||||
#include <wallpaperengine/irr/CPkgReader.h>
|
#include <wallpaperengine/irr/CPkgReader.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
#include <SDL_mixer.h>
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
#include "wallpaperengine/shaders/compiler.h"
|
#include "wallpaperengine/shaders/compiler.h"
|
||||||
#include "wallpaperengine/project.h"
|
#include "wallpaperengine/project.h"
|
||||||
@ -77,6 +79,7 @@ void preconfigure_wallpaper_engine ()
|
|||||||
int main (int argc, char* argv[])
|
int main (int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int mode = 0;
|
int mode = 0;
|
||||||
|
bool audio_support = true;
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
// parse the integer if it exists
|
// parse the integer if it exists
|
||||||
@ -93,12 +96,13 @@ int main (int argc, char* argv[])
|
|||||||
{"win", required_argument, 0, 'w'},
|
{"win", required_argument, 0, 'w'},
|
||||||
{"pkg", required_argument, 0, 'p'},
|
{"pkg", required_argument, 0, 'p'},
|
||||||
{"dir", required_argument, 0, 'd'},
|
{"dir", required_argument, 0, 'd'},
|
||||||
|
{"silent", optional_argument, 0, 's'},
|
||||||
{nullptr, 0, 0, 0}
|
{nullptr, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int c = getopt_long (argc, argv, "w:p:d:", long_options, &option_index);
|
int c = getopt_long (argc, argv, "w:p:d:s", long_options, &option_index);
|
||||||
|
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
@ -120,6 +124,10 @@ int main (int argc, char* argv[])
|
|||||||
path = optarg;
|
path = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 's':
|
||||||
|
audio_support = false;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -162,6 +170,20 @@ int main (int argc, char* argv[])
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (audio_support == true)
|
||||||
|
{
|
||||||
|
int mixer_flags = MIX_INIT_MP3 | MIX_INIT_FLAC | MIX_INIT_OGG;
|
||||||
|
|
||||||
|
if (SDL_Init (SDL_INIT_AUDIO) < 0 || mixer_flags != Mix_Init (mixer_flags))
|
||||||
|
{
|
||||||
|
wp::irrlicht::device->getLogger ()->log ("Cannot initialize SDL audio system", irr::ELL_ERROR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// initialize audio engine
|
||||||
|
Mix_OpenAudio (22050, AUDIO_S16SYS, 2, 640);
|
||||||
|
}
|
||||||
|
|
||||||
wp::project* wp_project = new wp::project (project_path);
|
wp::project* wp_project = new wp::project (project_path);
|
||||||
|
|
||||||
if (wp_project->getScene ()->isOrthogonal() == true)
|
if (wp_project->getScene ()->isOrthogonal() == true)
|
||||||
@ -200,6 +222,7 @@ int main (int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_Quit ();
|
||||||
delete wp_project;
|
delete wp_project;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <wallpaperengine/core.h>
|
#include <wallpaperengine/core.h>
|
||||||
#include <wallpaperengine/object3d.h>
|
#include <wallpaperengine/object3d.h>
|
||||||
#include <wallpaperengine/image.h>
|
#include <wallpaperengine/image.h>
|
||||||
|
#include <wallpaperengine/sound.h>
|
||||||
|
|
||||||
namespace wp
|
namespace wp
|
||||||
{
|
{
|
||||||
@ -65,6 +66,7 @@ namespace wp
|
|||||||
json::const_iterator image = json_data.find ("image");
|
json::const_iterator image = json_data.find ("image");
|
||||||
json::const_iterator model = json_data.find ("model");
|
json::const_iterator model = json_data.find ("model");
|
||||||
json::const_iterator particle = json_data.find ("particle");
|
json::const_iterator particle = json_data.find ("particle");
|
||||||
|
json::const_iterator sound = json_data.find ("sound");
|
||||||
|
|
||||||
object3d::Type _type = object3d::Type::Type_None;
|
object3d::Type _type = object3d::Type::Type_None;
|
||||||
|
|
||||||
@ -83,6 +85,11 @@ namespace wp
|
|||||||
_type = object3d::Type::Type_Particle;
|
_type = object3d::Type::Type_Particle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sound != json_data.end () && (*sound).is_null () == false)
|
||||||
|
{
|
||||||
|
_type = object3d::Type::Type_Sound;
|
||||||
|
}
|
||||||
|
|
||||||
// load the effects first so we have access to the textures needed
|
// load the effects first so we have access to the textures needed
|
||||||
json::const_iterator effects = json_data.find ("effects");
|
json::const_iterator effects = json_data.find ("effects");
|
||||||
|
|
||||||
@ -108,6 +115,10 @@ namespace wp
|
|||||||
|
|
||||||
case object3d::Type::Type_Particle:
|
case object3d::Type::Type_Particle:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case object3d::Type::Type_Sound:
|
||||||
|
this->m_object3d = new wp::sound ((*sound), this);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,8 @@ namespace wp
|
|||||||
Type_Material = 0,
|
Type_Material = 0,
|
||||||
Type_Model = 1,
|
Type_Model = 1,
|
||||||
Type_Particle = 2,
|
Type_Particle = 2,
|
||||||
Type_None = 3
|
Type_Sound = 3,
|
||||||
|
Type_None = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
object3d (Type type, wp::object* parent);
|
object3d (Type type, wp::object* parent);
|
||||||
|
65
wallpaperengine/sound.cpp
Normal file
65
wallpaperengine/sound.cpp
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
//
|
||||||
|
// Created by almamu on 17/05/19.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <SDL_rwops.h>
|
||||||
|
#include <SDL_mixer.h>
|
||||||
|
#include "sound.h"
|
||||||
|
#include "irrlicht.h"
|
||||||
|
|
||||||
|
namespace wp
|
||||||
|
{
|
||||||
|
sound::sound (json json_data, wp::object* parent) : object3d (object3d::Type::Type_Material, parent)
|
||||||
|
{
|
||||||
|
json::const_iterator cur = json_data.begin ();
|
||||||
|
json::const_iterator end = json_data.end ();
|
||||||
|
|
||||||
|
for (; cur != end; cur ++)
|
||||||
|
{
|
||||||
|
this->m_filenames.push_back ((*cur).get <std::string> ());
|
||||||
|
}
|
||||||
|
|
||||||
|
this->play ();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sound::play ()
|
||||||
|
{
|
||||||
|
std::vector<std::string>::const_iterator cur = this->m_filenames.begin ();
|
||||||
|
std::vector<std::string>::const_iterator end = this->m_filenames.end ();
|
||||||
|
|
||||||
|
for (; cur != end; cur ++)
|
||||||
|
{
|
||||||
|
SDL_RWops* sdlRwops = nullptr;
|
||||||
|
Mix_Music* music = nullptr;
|
||||||
|
irr::io::IReadFile* readfile = wp::irrlicht::device->getFileSystem ()->createAndOpenFile ((*cur).c_str ());
|
||||||
|
int filesize = readfile->getSize ();
|
||||||
|
char* filebuffer = new char [filesize];
|
||||||
|
|
||||||
|
readfile->read (filebuffer, filesize);
|
||||||
|
|
||||||
|
sdlRwops = SDL_RWFromConstMem(filebuffer, filesize);
|
||||||
|
music = Mix_LoadMUS_RW (sdlRwops);
|
||||||
|
readfile->drop ();
|
||||||
|
|
||||||
|
if (music == nullptr)
|
||||||
|
{
|
||||||
|
wp::irrlicht::device->getLogger ()->log ("Cannot load audio", Mix_GetError (), irr::ELL_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->m_bufferReader.push_back (sdlRwops);
|
||||||
|
this->m_soundBuffer.push_back (filebuffer);
|
||||||
|
this->m_sdl.push_back (music);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Mix_Music*>::const_iterator mixcur = this->m_sdl.begin ();
|
||||||
|
std::vector<Mix_Music*>::const_iterator mixend = this->m_sdl.end ();
|
||||||
|
|
||||||
|
for (; mixcur != mixend; mixcur ++)
|
||||||
|
{
|
||||||
|
if (Mix_PlayMusic ((*mixcur), -1) == -1)
|
||||||
|
{
|
||||||
|
wp::irrlicht::device->getLogger ()->log ("Cannot play audio", Mix_GetError (), irr::ELL_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
wallpaperengine/sound.h
Normal file
31
wallpaperengine/sound.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef WALLENGINE_SOUND_H
|
||||||
|
#define WALLENGINE_SOUND_H
|
||||||
|
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
#include <irrlicht/irrlicht.h>
|
||||||
|
#include <SDL_mixer.h>
|
||||||
|
|
||||||
|
#include <wallpaperengine/object3d.h>
|
||||||
|
#include <wallpaperengine/object.h>
|
||||||
|
|
||||||
|
namespace wp
|
||||||
|
{
|
||||||
|
using json = nlohmann::json;
|
||||||
|
|
||||||
|
class sound : public wp::object3d
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
sound (json json_data, wp::object* parent);
|
||||||
|
|
||||||
|
void play ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::string> m_filenames;
|
||||||
|
std::vector <Mix_Music*> m_sdl;
|
||||||
|
std::vector <SDL_RWops*> m_bufferReader;
|
||||||
|
std::vector <void*> m_soundBuffer;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif //WALLENGINE_SOUND_H
|
Loading…
Reference in New Issue
Block a user