Skip to content

Commit

Permalink
Merge pull request #117 from fallahn/golf-1.17
Browse files Browse the repository at this point in the history
Golf 1.17
  • Loading branch information
fallahn authored Jul 6, 2024
2 parents 7830a20 + af27371 commit dc23b18
Show file tree
Hide file tree
Showing 275 changed files with 23,077 additions and 3,651 deletions.
44 changes: 27 additions & 17 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
{
"version": 3,
"configurePresets": [
{
"name": "default",
"binaryDir": "build/${presetName}",
"cacheVariables": {
"BUILD_SAMPLES": true,
"CMAKE_INSTALL_PREFIX": "install/${presetName}"
}
}
],
"buildPresets": [
{
"name":"default",
"configurePreset": "default"
}
]
"version": 3,
"configurePresets": [
{
"name": "default",
"binaryDir": "build/${presetName}",
"cacheVariables": {
"BUILD_SAMPLES": true,
"CMAKE_INSTALL_PREFIX": "install/${presetName}"
}
},
{
"name": "vcpkg",
"inherits": [ "default" ],
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"condition": {
"type": "notEquals",
"lhs": "$env{VCPKG_ROOT}",
"rhs": ""
}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
}
]
}
21 changes: 6 additions & 15 deletions crogine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ cmake_minimum_required(VERSION 3.5.0)
if(APPLE)
#required for std::filesystem
SET(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment version")

#force macOS to use homebrew installed libs, eg OpenAL
SET(CMAKE_PREFIX_PATH
"/opt/homebrew"
"/opt/homebrew/opt/openal-soft/include"
"/opt/homebrew/opt/openal-soft/lib"
"/usr/local"
"/usr/local/opt/openal-soft/include"
"/usr/local/opt/openal-soft/lib")

SET(CMAKE_FIND_FRAMEWORK LAST)
endif()

Expand Down Expand Up @@ -73,8 +72,6 @@ else()
add_definitions(-DCRO_BUILD)
endif()

SET (CMAKE_CXX_FLAGS_DEBUG "-g -DCRO_DEBUG_ -DHAS_SOCKLEN_T")
SET (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -DHAS_SOCKLEN_T")
SET (CMAKE_DEBUG_POSTFIX -d)

# We're using c++17
Expand All @@ -83,16 +80,13 @@ SET (CMAKE_CXX_STANDARD_REQUIRED ON)

SET (OpenGL_GL_PREFERENCE "GLVND")

find_package(SDL2 REQUIRED)
find_package(SDL2 MODULE REQUIRED)
find_package(Freetype REQUIRED)
find_package(OpenGL REQUIRED)
find_package(OPUS REQUIRED)

if(USE_OPENAL)
#we were using mojoal on mac but now trying to get openal-soft to work from brew
#if(NOT APPLE)
find_package(OpenAL REQUIRED)
#endif()
find_package(OpenAL REQUIRED)
else()
find_package(SDL2_mixer REQUIRED)
endif()
Expand Down Expand Up @@ -123,9 +117,7 @@ SET(PROJECT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
include(${PROJECT_DIR}/CMakeLists.txt)

if(USE_OPENAL)
#if(NOT APPLE)
include_directories(${OPENAL_INCLUDE_DIR})
#endif()
include_directories(${OPENAL_INCLUDE_DIR})
SET(PROJECT_SRC ${PROJECT_SRC} ${project_src_openal})
else()
include_directories(${SDL2_MIXER_INCLUDE_DIR})
Expand Down Expand Up @@ -156,6 +148,7 @@ if(NOT TARGET crogine)
add_library(${PROJECT_NAME} SHARED ${PROJECT_SRC})
endif()

target_compile_definitions(${PROJECT_NAME} PUBLIC $<$<CONFIG:Debug>:CRO_DEBUG_>)

target_link_libraries(${PROJECT_NAME}
${SDL2_LIBRARY}
Expand All @@ -164,9 +157,7 @@ if(NOT TARGET crogine)
${OPENGL_LIBRARIES})

if(USE_OPENAL)
#if(NOT APPLE)
target_link_libraries(${PROJECT_NAME} ${OPENAL_LIBRARY})
#endif()
target_link_libraries(${PROJECT_NAME} ${OPENAL_LIBRARY})
else()
target_link_libraries(${PROJECT_NAME} ${SDL2_MIXER_LIBRARY})
endif()
Expand Down
12 changes: 10 additions & 2 deletions crogine/include/crogine/audio/DynamicAudioStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ namespace cro
class CRO_EXPORT_API DynamicAudioStream final : public AudioSource
{
public:
DynamicAudioStream();
/*!
\brief Constructor
\param channels Number of audio channels the stream should expect
\param samplerate The sample rate of the incoming data
Note that DynamicAudioStreams always expect 16 bit data
*/
DynamicAudioStream(std::uint32_t channels, std::uint32_t samplerate);
~DynamicAudioStream();
DynamicAudioStream(const DynamicAudioStream&) = delete;
DynamicAudioStream(DynamicAudioStream&&) noexcept;
Expand All @@ -59,8 +65,10 @@ namespace cro

/*!
\brief Allows submitting audio data to the internal buffer
Audio data must ALWAYS be 16 bit. The channel count and sample rate
should match the values with which this audio stream was constructed
*/
void updateBuffer(const std::vector<std::uint8_t>&);
void updateBuffer(const std::int16_t*, std::int32_t sampleCount);

/*!
\brief Returns the underlying data type
Expand Down
107 changes: 107 additions & 0 deletions crogine/include/crogine/audio/sound_system/OpusEncoder.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*-----------------------------------------------------------------------
Matt Marchant 2024
http://trederia.blogspot.com
crogine - Zlib license.
This software is provided 'as-is', without any express or
implied warranty.In no event will the authors be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions :
1. The origin of this software must not be misrepresented;
you must not claim that you wrote the original software.
If you use this software in a product, an acknowledgment
in the product documentation would be appreciated but
is not required.
2. Altered source versions must be plainly marked as such,
and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any
source distribution.
-----------------------------------------------------------------------*/

#pragma once

#include <crogine/Config.hpp>

#include <vector>
#include <cstdint>

namespace cro
{
/*!
\brief Creates an opus stream encoder and decoder from the given
opus encoder context.
*/

class CRO_EXPORT_API Opus
{
public:
struct CRO_EXPORT_API Context final
{
std::uint32_t channelCount = 1;
std::uint32_t sampleRate = 24000;

std::uint32_t maxPacketSize = 1276 * 3;
std::uint32_t bitrate = 64000;
};

explicit Opus(const Context& ctx);
~Opus();

Opus(const Opus&) = delete;
Opus(Opus&&) = delete;

const Opus& operator = (const Opus&) = delete;
const Opus& operator = (Opus&&) = delete;

/*!
\brief Encodes the given pcm data using the context settings
supplied in the constructor.
\param data Pointer to PCM data to encode. This should contain enough
data to fill one frame, which is calculated as (sampleRate / 25) * channelCount
\param dst A vector of bytes into which the packet is placed.
This will be empty if no encoding occurred
*/
void encode(const std::int16_t* data, std::vector<std::uint8_t>& dst) const;

/*!
\brief Encodes the given floating point pcm data using the context settings
supplied in the constructor.
\param data Pointer to PCM data to encode.This should contain enough
data to fill one frame, which is calculated as (sampleRate / 25) * channelCount
\param dst A vector of bytes into which the packet is placed.
This will be empty if no encoding occurred
*/
void encode(const float* data, std::vector<std::uint8_t>& dst) const;

/*!
\brief Attempts to decode the given opus packet using the channel count and sample rate
passed via context at construstion.
\param packet A std::vector of bytes containing the packet data
\returns std::vector of 16 bit PCM samples
*/
std::vector<std::int16_t> decode(const std::vector<std::uint8_t>& packet) const;

std::uint32_t getFrameSize() const { return m_frameSize; }

private:

void* m_encoder;
void* m_decoder;

const std::uint32_t m_frameSize;
const std::uint32_t m_maxFrameSize;
const std::uint32_t m_channelCount;

mutable std::vector<std::uint8_t> m_outBuffer;
mutable std::vector<std::int16_t> m_decodeBuffer;
};
}
Loading

0 comments on commit dc23b18

Please sign in to comment.