remove audio bass impl

This commit is contained in:
BlackMATov
2020-05-27 19:57:34 +07:00
parent 7fc811399e
commit 9aa1d88df7
17 changed files with 4 additions and 4008 deletions

View File

@@ -138,73 +138,6 @@ set_target_properties(libglew_static PROPERTIES FOLDER modules)
add_subdirectory(modules/spine/spine-c)
set_target_properties(spine-c PROPERTIES FOLDER modules)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_library(bass SHARED IMPORTED)
set_target_properties(bass PROPERTIES IMPORTED_IMPLIB
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/linux/x86/libbass.so)
set_target_properties(bass PROPERTIES IMPORTED_LOCATION
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/linux/x86/libbass.so)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_library(bass SHARED IMPORTED)
set_target_properties(bass PROPERTIES IMPORTED_IMPLIB
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/linux/x64/libbass.so)
set_target_properties(bass PROPERTIES IMPORTED_LOCATION
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/linux/x64/libbass.so)
endif()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
add_library(bass SHARED IMPORTED)
set_target_properties(bass PROPERTIES IMPORTED_LOCATION
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/macosx/libbass.dylib)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_library(bass SHARED IMPORTED)
set_target_properties(bass PROPERTIES IMPORTED_IMPLIB
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/windows/x86/bass.lib)
set_target_properties(bass PROPERTIES IMPORTED_LOCATION
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/windows/x86/bass.dll)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_library(bass SHARED IMPORTED)
set_target_properties(bass PROPERTIES IMPORTED_IMPLIB
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/windows/x64/bass.lib)
set_target_properties(bass PROPERTIES IMPORTED_LOCATION
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/windows/x64/bass.dll)
endif()
endif()
function(add_e2d_shared_libraries_to_target TO)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_custom_command(TARGET ${TO} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/linux/x86/libbass.so
$<TARGET_FILE_DIR:${TO}>)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_custom_command(TARGET ${TO} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/linux/x64/libbass.so
$<TARGET_FILE_DIR:${TO}>)
endif()
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
add_custom_command(TARGET ${TO} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/macosx/libbass.dylib
$<TARGET_FILE_DIR:${TO}>)
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
add_custom_command(TARGET ${TO} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/windows/x86/bass.dll
$<TARGET_FILE_DIR:${TO}>)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
add_custom_command(TARGET ${TO} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
${E2D_ROOT_DIRECTORY}/sources/3rdparty/bass/windows/x64/bass.dll
$<TARGET_FILE_DIR:${TO}>)
endif()
endif()
endfunction(add_e2d_shared_libraries_to_target)
#
# e2d library target
#
@@ -226,7 +159,6 @@ target_link_libraries(${PROJECT_NAME}
PUBLIC promise.hpp)
target_link_libraries(${PROJECT_NAME}
PRIVATE bass
PRIVATE glfw
PRIVATE libglew_static
PRIVATE spine-c

View File

@@ -110,19 +110,18 @@
//
#define E2D_AUDIO_MODE_NONE 1
#define E2D_AUDIO_MODE_BASS 2
#ifndef E2D_AUDIO_MODE
# if defined(E2D_PLATFORM) && E2D_PLATFORM == E2D_PLATFORM_IOS
# define E2D_AUDIO_MODE E2D_AUDIO_MODE_NONE
# elif defined(E2D_PLATFORM) && E2D_PLATFORM == E2D_PLATFORM_LINUX
# define E2D_AUDIO_MODE E2D_AUDIO_MODE_BASS
# define E2D_AUDIO_MODE E2D_AUDIO_MODE_NONE
# elif defined(E2D_PLATFORM) && E2D_PLATFORM == E2D_PLATFORM_MACOSX
# define E2D_AUDIO_MODE E2D_AUDIO_MODE_BASS
# define E2D_AUDIO_MODE E2D_AUDIO_MODE_NONE
# elif defined(E2D_PLATFORM) && E2D_PLATFORM == E2D_PLATFORM_WINDOWS
# define E2D_AUDIO_MODE E2D_AUDIO_MODE_BASS
# define E2D_AUDIO_MODE E2D_AUDIO_MODE_NONE
# elif defined(E2D_PLATFORM) && E2D_PLATFORM == E2D_PLATFORM_ANDROID
# define E2D_AUDIO_MODE E2D_AUDIO_MODE_BASS
# define E2D_AUDIO_MODE E2D_AUDIO_MODE_NONE
# endif
#endif

View File

@@ -35,7 +35,6 @@ function(add_e2d_sample NAME)
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/bin
$<TARGET_FILE_DIR:${SAMPLE_NAME}>/bin)
add_e2d_shared_libraries_to_target(${SAMPLE_NAME})
endfunction(add_e2d_sample)
add_e2d_sample(00)

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3ef2e8805975bbf0c199ebeae3f14b4423ad823c8ec4dd15669a195dee4b8ff7
size 242448

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c4d5e85e2a035acd0eab10aee040aac55acafa1b77e1dda7c9f77ebec8220f5b
size 210868

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:75bcaf5f506398e9ff1a3f5224207fd8d5ee622eeda4de5ebf8b8f277e05ba2d
size 514996

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:bdd23036f42b0f7a0366b7ce8a03d5547255f8ac80efa956a41cd92a9546be62
size 243712

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6697ab0a85d8577fcc7dcff43898d3f659f61960a3561fd55a7013be491e0d2b
size 23466

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4d6fa631ad7f46aaa4a1786d22c04671dde17ed41111e821f18c97c474fec92c
size 119477

View File

@@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:676d1c93cd85ed95a210331259f55a4f7b9bc69974a4f3455d25b21a72cd08bc
size 25182

View File

@@ -1,284 +0,0 @@
/*******************************************************************************
* This file is part of the "Enduro2D"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include "audio_bass_impl.hpp"
#if defined(E2D_AUDIO_MODE) && E2D_AUDIO_MODE == E2D_AUDIO_MODE_BASS
namespace
{
using namespace e2d;
u32 max_sound_channels = 4;
void CALLBACK sound_stream_close_proc(void* user) noexcept {
E2D_UNUSED(user);
}
QWORD CALLBACK sound_stream_length_proc(void* user) noexcept {
auto* self = static_cast<input_stream*>(user);
return math::numeric_cast<QWORD>(self->length());
}
DWORD CALLBACK sound_stream_read_proc(void* buffer, DWORD length, void* user) noexcept {
auto* self = static_cast<input_stream*>(user);
try {
return math::numeric_cast<DWORD>(self->read(buffer, length));
} catch (...) {
return -1;
}
}
BOOL CALLBACK sound_stream_seek_proc(QWORD offset, void* user) noexcept {
auto* self = static_cast<input_stream*>(user);
try {
return offset == self->seek(
math::numeric_cast<std::ptrdiff_t>(offset),
false);
} catch(...) {
return false;
}
}
}
namespace e2d
{
//
// sound_stream
//
sound_stream::sound_stream(internal_state_uptr state)
: state_(std::move(state)) {
E2D_ASSERT(state_);
}
const sound_stream::internal_state& sound_stream::state() const noexcept {
return *state_;
}
//
// sound_source
//
sound_source::sound_source(internal_state_uptr state)
: state_(std::move(state)) {
E2D_ASSERT(state_);
}
const sound_source::internal_state& sound_source::state() const noexcept {
return *state_;
}
void sound_source::play() noexcept {
if ( !BASS_ChannelPlay(state().channel(), TRUE) ) {
state_->dbg().error("AUDIO: Failed to play sound");
}
}
void sound_source::stop() noexcept {
BASS_ChannelStop(state().channel());
}
void sound_source::pause() noexcept {
BASS_ChannelPause(state().channel());
}
void sound_source::resume() noexcept {
if ( !BASS_ChannelPlay(state().channel(), FALSE) ) {
state_->dbg().error("AUDIO: Failed to resume sound");
}
}
bool sound_source::playing() const noexcept {
return BASS_ChannelIsActive(state().channel()) == BASS_ACTIVE_PLAYING;
}
void sound_source::looping(bool value) noexcept {
BASS_ChannelFlags(state().channel(), value ? BASS_SAMPLE_LOOP : 0, BASS_SAMPLE_LOOP);
}
bool sound_source::looping() noexcept {
return math::check_all_flags(
BASS_ChannelFlags(state().channel(), 0, 0),
static_cast<DWORD>(BASS_SAMPLE_LOOP));
}
void sound_source::volume(f32 value) noexcept {
BASS_ChannelSetAttribute(state().channel(), BASS_ATTRIB_VOL, value);
}
f32 sound_source::volume() const noexcept {
f32 volume = 1.0f;
BASS_ChannelGetAttribute(state().channel(), BASS_ATTRIB_VOL, &volume);
return volume;
}
void sound_source::position(f32 pos) noexcept {
QWORD byte_pos = BASS_ChannelSeconds2Bytes(state().channel(), pos);
BASS_ChannelSetPosition(state().channel(), byte_pos, BASS_POS_BYTE);
}
f32 sound_source::position() const noexcept {
QWORD byte_pos = BASS_ChannelGetPosition(state().channel(), BASS_POS_BYTE);
return math::numeric_cast<f32>(
BASS_ChannelBytes2Seconds(state().channel(), byte_pos));
}
f32 sound_source::duration() const noexcept {
QWORD byte_len = BASS_ChannelGetLength(state().channel(), BASS_POS_BYTE);
return math::numeric_cast<f32>(
BASS_ChannelBytes2Seconds(state().channel(), byte_len));
}
//
// audio
//
audio::audio(debug& d)
: state_(std::make_unique<internal_state>(d)) {}
audio::~audio() noexcept {
}
sound_stream_ptr audio::create_stream(
buffer_view sound_data)
{
if ( !state_->initialized() ) {
state_->dbg().error("AUDIO: Not initialized");
return nullptr;
}
if ( sound_data.empty() ) {
state_->dbg().error("AUDIO: Sound data is empty");
return nullptr;
}
E2D_PROFILER_SCOPE("audio.create_stream");
HSAMPLE sample = BASS_SampleLoad(
TRUE,
sound_data.data(),
0,
math::numeric_cast<DWORD>(sound_data.size()),
max_sound_channels,
BASS_SAMPLE_OVER_POS);
if ( sample == 0 ) {
state_->dbg().error(
"AUDIO: Failed to load sound sample, code (%0)",
BASS_ErrorGetCode());
return nullptr;
}
return std::make_shared<sound_stream>(
std::make_unique<sound_stream::internal_state>(
state_->dbg(), sample, nullptr));
}
sound_stream_ptr audio::create_stream(
input_stream_uptr file_stream)
{
if ( !state_->initialized() ) {
state_->dbg().error("AUDIO: Not initialized");
return nullptr;
}
if ( !file_stream ) {
state_->dbg().error("AUDIO: file stream is null");
return nullptr;
}
E2D_PROFILER_SCOPE("audio.create_stream");
BASS_FILEPROCS file_procs = {
sound_stream_close_proc,
sound_stream_length_proc,
sound_stream_read_proc,
sound_stream_seek_proc};
HSTREAM stream = BASS_StreamCreateFileUser(
STREAMFILE_NOBUFFER,
BASS_ASYNCFILE,
&file_procs,
file_stream.get());
if ( stream == 0 ) {
state_->dbg().error(
"AUDIO: Failed to create sound stream, code (%0)",
BASS_ErrorGetCode());
return nullptr;
}
return std::make_shared<sound_stream>(
std::make_unique<sound_stream::internal_state>(
state_->dbg(), stream, std::move(file_stream)));
}
sound_source_ptr audio::create_source(
const sound_stream_ptr& stream)
{
if ( !state_->initialized() ) {
state_->dbg().error("AUDIO: Not initialized");
return nullptr;
}
if ( !stream ) {
state_->dbg().error("AUDIO: stream is null");
return nullptr;
}
E2D_PROFILER_SCOPE("audio.create_source");
HCHANNEL channel = stream->state().stream()
? stream->state().sound()
: BASS_SampleGetChannel(stream->state().sound(), FALSE);
if ( !channel ) {
state_->dbg().error("AUDIO: can net retrive sound channel");
return nullptr;
}
return std::make_shared<sound_source>(
std::make_unique<sound_source::internal_state>(
state_->dbg(), stream, channel));
}
bool audio::initialized() const noexcept {
return state_->initialized();
}
void audio::volume(f32 value) noexcept {
BASS_SetVolume(value);
}
f32 audio::volume() const noexcept {
return BASS_GetVolume();
}
void audio::resume() noexcept {
if ( !state_->initialized() ) {
state_->dbg().error("AUDIO: Not initialized");
return;
}
if ( !BASS_Start() ) {
state_->dbg().error("AUDIO: Failed to resume audio output");
}
}
void audio::pause() noexcept {
if ( !state_->initialized() ) {
state_->dbg().error("AUDIO: Not initialized");
return;
}
if ( !BASS_Pause() ) {
state_->dbg().error("AUDIO: Failed to resume audio output");
}
}
}
#endif

View File

@@ -1,98 +0,0 @@
/*******************************************************************************
* This file is part of the "Enduro2D"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#include "audio_bass_impl.hpp"
#if defined(E2D_AUDIO_MODE) && E2D_AUDIO_MODE == E2D_AUDIO_MODE_BASS
namespace e2d
{
//
// sound_stream::internal_state
//
sound_stream::internal_state::internal_state(
debug& debug,
DWORD sound,
input_stream_uptr stream)
: debug_(debug)
, sound_(sound)
, stream_(std::move(stream)){
E2D_ASSERT(sound);
}
sound_stream::internal_state::~internal_state() noexcept {
if ( stream_ ) {
BASS_StreamFree(sound_);
} else {
BASS_SampleFree(sound_);
}
}
debug& sound_stream::internal_state::dbg() const noexcept {
return debug_;
}
HSAMPLE sound_stream::internal_state::sound() const noexcept {
return sound_;
}
const input_stream_uptr& sound_stream::internal_state::stream() const noexcept {
return stream_;
}
//
// sound_source::internal_state
//
sound_source::internal_state::internal_state(
debug& debug,
const sound_stream_ptr& stream,
HCHANNEL channel)
: debug_(debug)
, channel_(channel)
, stream_(stream) {
E2D_ASSERT(channel);
}
debug& sound_source::internal_state::dbg() const noexcept {
return debug_;
}
HCHANNEL sound_source::internal_state::channel() const noexcept {
return channel_;
}
//
// audio::internal_state
//
audio::internal_state::internal_state(debug& debug)
: debug_(debug) {
if ( !BASS_Init(-1, 44100, 0, nullptr, nullptr) ) {
debug_.error("AUDIO: Initialization failed");
return;
}
initialized_ = true;
BASS_SetConfig(BASS_CONFIG_UPDATETHREADS, 1);
}
audio::internal_state::~internal_state() noexcept {
if ( initialized_ ) {
BASS_Free();
}
}
debug& audio::internal_state::dbg() const noexcept {
return debug_;
}
bool audio::internal_state::initialized() const noexcept {
return initialized_;
}
}
#endif

View File

@@ -1,83 +0,0 @@
/*******************************************************************************
* This file is part of the "Enduro2D"
* For conditions of distribution and use, see copyright notice in LICENSE.md
* Copyright (C) 2018-2020, by Matvey Cherevko (blackmatov@gmail.com)
******************************************************************************/
#pragma once
#include "audio.hpp"
#if defined(E2D_AUDIO_MODE) && E2D_AUDIO_MODE == E2D_AUDIO_MODE_BASS
#if defined(E2D_PLATFORM)
# if E2D_PLATFORM == E2D_PLATFORM_LINUX
# include <3rdparty/bass/linux/bass.h>
# elif E2D_PLATFORM == E2D_PLATFORM_MACOSX
# include <3rdparty/bass/macosx/bass.h>
# elif E2D_PLATFORM == E2D_PLATFORM_WINDOWS
# include <3rdparty/bass/windows/bass.h>
# endif
#endif
namespace e2d
{
//
// sound_stream::internal_state
//
class sound_stream::internal_state final : private e2d::noncopyable {
public:
internal_state(
debug& debug,
DWORD sound,
input_stream_uptr stream);
~internal_state() noexcept;
public:
[[nodiscard]] debug& dbg() const noexcept;
[[nodiscard]] DWORD sound() const noexcept;
[[nodiscard]] const input_stream_uptr& stream() const noexcept;
private:
debug& debug_;
DWORD sound_;
input_stream_uptr stream_;
};
//
// sound_source::internal_state
//
class sound_source::internal_state final : private e2d::noncopyable {
public:
internal_state(
debug& debug,
const sound_stream_ptr& stream,
HCHANNEL channel);
~internal_state() noexcept = default;
public:
[[nodiscard]] debug& dbg() const noexcept;
[[nodiscard]] HCHANNEL channel() const noexcept;
private:
debug& debug_;
HCHANNEL channel_;
sound_stream_ptr stream_;
};
//
// audio::internal_state
//
class audio::internal_state final : private e2d::noncopyable {
public:
internal_state(debug& debug);
~internal_state() noexcept;
public:
[[nodiscard]] debug& dbg() const noexcept;
[[nodiscard]] bool initialized() const noexcept;
private:
debug& debug_;
bool initialized_{false};
};
}
#endif

View File

@@ -35,7 +35,6 @@ function(add_e2d_tests NAME)
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/bin
$<TARGET_FILE_DIR:${TESTS_NAME}>/bin)
add_e2d_shared_libraries_to_target(${TESTS_NAME})
#
# tests