Skip to content

Commit

Permalink
Merge pull request #118 from fallahn/golf-1.17
Browse files Browse the repository at this point in the history
Golf 1.17.0b
  • Loading branch information
fallahn authored Jul 10, 2024
2 parents dc23b18 + 07c99ec commit c051ce7
Show file tree
Hide file tree
Showing 30 changed files with 908 additions and 294 deletions.
3 changes: 1 addition & 2 deletions crogine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ Global
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|ARM.ActiveCfg = Debug|Win32
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|ARM64.ActiveCfg = Debug|Win32
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|x64.ActiveCfg = Debug|x64
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|x64.Build.0 = Debug|x64
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.Debug|x86.ActiveCfg = Debug|Win32
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.DebugASan|Any CPU.ActiveCfg = DebugASan|Win32
{64579103-DEC3-41E4-971F-9C0DF996BE8B}.DebugASan|ARM.ActiveCfg = DebugASan|Win32
Expand All @@ -290,7 +291,6 @@ Global
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|ARM.ActiveCfg = Debug|Win32
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|ARM64.ActiveCfg = Debug|Win32
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|x64.ActiveCfg = Debug|x64
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|x64.Build.0 = Debug|x64
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|x86.ActiveCfg = Debug|Win32
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.Debug|x86.Build.0 = Debug|Win32
{B1559428-CDF8-4797-8766-0EA62BDD6D1B}.DebugASan|Any CPU.ActiveCfg = DebugASan|Win32
Expand Down Expand Up @@ -321,7 +321,6 @@ Global
{155BC29B-5143-44CF-AC90-82B82B056E48}.Debug|ARM64.ActiveCfg = Debug|x64
{155BC29B-5143-44CF-AC90-82B82B056E48}.Debug|ARM64.Build.0 = Debug|x64
{155BC29B-5143-44CF-AC90-82B82B056E48}.Debug|x64.ActiveCfg = Debug|x64
{155BC29B-5143-44CF-AC90-82B82B056E48}.Debug|x64.Build.0 = Debug|x64
{155BC29B-5143-44CF-AC90-82B82B056E48}.Debug|x86.ActiveCfg = Debug|Win32
{155BC29B-5143-44CF-AC90-82B82B056E48}.Debug|x86.Build.0 = Debug|Win32
{155BC29B-5143-44CF-AC90-82B82B056E48}.DebugASan|Any CPU.ActiveCfg = Debug|x64
Expand Down
116 changes: 116 additions & 0 deletions crogine/include/crogine/audio/sound_system/Playlist.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*-----------------------------------------------------------------------
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 <string>
#include <vector>
#include <array>
#include <thread>
#include <mutex>
#include <atomic>
#include <memory>

namespace cro
{
/*
\brief Loads and buffers audio files asynchronously so
that they may be streamed continuously to a buffer such
as DynamicAudioStream. Output is 48KHz 16 bit Stereo
files are resampled on load if necessary
*/
class CRO_EXPORT_API Playlist final
{
public:
Playlist();
~Playlist();

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


/*!
\brief Add a file path to a file to addd to the playlist
NOTE this must be the FULL PATH to the file, if a relative
path is intended, eg in the assets directory, then make
sure to prepend the path with FileSystem::getResourcePath()
*/
void addPath(const std::string&);


/*!
\brief returns a pointer 16 bit Stereo PCM samples
\param count A reference to a std::int32_t which is filled
with the number of *samples* pointed to by the return value
*/
const std::int16_t* getData(std::int32_t& count);

/*!
\brief Returns a COPY of the tracklist (as it otherwise gets manipulated
by multiple threads...)
*/
std::vector<std::string> getTrackList() const;

/*!
\brief Pre-loads the first buffer (if possible) - use this to
prime the audio input without having to wait until the first call to getData()
*/
void precache();

private:

static constexpr std::size_t MaxBuffers = 3u;

//main thread only
std::array<std::int16_t, 100u> m_silence = {}; //returned when no audio is available
std::atomic<std::size_t> m_outBuffer; //current buffer from which data is returned
std::int32_t m_outputOffset; //where we are in the current buffer

//worker thread only
std::atomic<std::size_t> m_inBuffer; //next buffer to be filled with data from thread

//touched by both threads
std::vector<std::string> m_filePaths;
std::atomic<std::size_t> m_fileIndex;

std::array<std::vector<std::int16_t>, MaxBuffers> m_buffers = {};


std::atomic_bool m_threadRunning;
std::atomic_bool m_loadNextFile;
std::thread m_thread;
mutable std::mutex m_mutex;

void threadFunc();
};
}
1 change: 1 addition & 0 deletions crogine/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(PROJECT_SRC

${PROJECT_DIR}/audio/sound_system/MusicPlayer.cpp
${PROJECT_DIR}/audio/sound_system/OpusEncoder.cpp
${PROJECT_DIR}/audio/sound_system/Playlist.cpp
${PROJECT_DIR}/audio/sound_system/SoundRecorder.cpp
${PROJECT_DIR}/audio/sound_system/SoundSource.cpp
${PROJECT_DIR}/audio/sound_system/SoundStream.cpp
Expand Down
Loading

0 comments on commit c051ce7

Please sign in to comment.