Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate new preset parser and rewrite/refactor preset rendering. #716

Merged
merged 51 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7b2b60d
Added a new preset file parser class.
kblaschke Mar 23, 2022
41a6342
Build and run unit tests from now on.
kblaschke Mar 23, 2022
caee555
Added missing <functional> include GCC automatically includes for som…
kblaschke Mar 23, 2022
1c436c3
Format old parser code and fix a linker error.
kblaschke Mar 24, 2022
dfe08a1
Fix some errors in FileParser
kblaschke Mar 24, 2022
b9ef6a3
Remove old expression parser and add the new projectm-eval lib.
kblaschke Feb 14, 2023
3a0dcff
Shader refactoring.
kblaschke Feb 16, 2023
8823210
More rendering refactoring.
kblaschke Feb 19, 2023
74ca378
More rendering refactoring.
kblaschke Feb 28, 2023
922980f
Per-pixel mesh implementation.
kblaschke Feb 28, 2023
e7094aa
Remove "Pipeline" classes and temp fix all compilation issues.
kblaschke Mar 4, 2023
7c4e0c8
Delete MilkdropPresetFactory dir, left over from a previous rebase.
kblaschke Mar 4, 2023
95f3cb9
Move BlurTexture to MilkdropPreset.
kblaschke Mar 4, 2023
29b3d4a
Fix namespace issues in PCMTest.cpp
kblaschke Mar 4, 2023
ecea456
Remove unnecessary functions in PresetFileParser.
kblaschke Mar 4, 2023
5c5bb0a
PresetFileParser: Fix line reader and a compiler warning, re-add tests.
kblaschke Mar 4, 2023
a55fa07
Fix a few linker issues with the eval lib.
kblaschke Mar 4, 2023
e48e6f3
Remove call to deleted function.
kblaschke Mar 4, 2023
6e49989
Fixed some typo, added missing call to RegisterBuiltinVariables().
kblaschke Mar 4, 2023
7db50da
A few fixes for warnings etc.
kblaschke Mar 5, 2023
62b84ef
Added a framebuffer class for drawing the presets into.
kblaschke Mar 5, 2023
e73b0f3
Working on getting stuff being rendered again, focus on default wavef…
kblaschke Mar 6, 2023
102d4ba
Overhauled all primitives (waves, shapes and borders).
kblaschke Mar 8, 2023
09607a2
Fix issues with the framebuffer implementation and reenable it.
kblaschke Mar 9, 2023
e603793
Finished per-pixel mesh, started rework of warp/comp shaders and text…
kblaschke Mar 13, 2023
ce0e585
More work on shader stuff, warp/comp shaders now compile properly.
kblaschke Mar 14, 2023
904292e
Implemented motion vector grid.
kblaschke Mar 15, 2023
f88fe70
Fix wrong assignment in per-frame context.
kblaschke Mar 16, 2023
df7cd08
Fill both spectrum channels with data.
kblaschke Mar 18, 2023
0ac9fe2
Finished final composite implementation, more fixes and cleanups.
kblaschke Mar 18, 2023
2707a1d
Fix uv_orig coordinates in warp shader.
kblaschke Mar 18, 2023
75fe0f0
Fixed more UV coordinate issues in the warp shader.
kblaschke Mar 22, 2023
74bd99a
Fix idle preset and filters, load logo textures y-flipped.
kblaschke Mar 29, 2023
4b3226a
Added projectM-Eval as submodule, flipped rendering stuff around a bi…
kblaschke Apr 1, 2023
feb7a33
A few Windows build fixes
kblaschke Apr 3, 2023
ef62ddf
Add omptl to Renderer linked library list.
kblaschke Apr 27, 2023
d2780c5
Check out submodules (for projectM-eval) in GitHub Actions workflows.
kblaschke Apr 27, 2023
879c6c7
Split StaticGlShaders class into shader files and code templates, rem…
kblaschke Apr 29, 2023
e84acbc
Renamed simple textured/untextured shaders to be more readable.
kblaschke Apr 29, 2023
486c86c
Filename fix in comment.
kblaschke Apr 29, 2023
e9438ee
Deleted lots of unused files and code.
kblaschke Apr 29, 2023
b07163d
Check active preset after the preset switch event, as this might have…
kblaschke Jul 24, 2023
a294b8a
Fix two Emscripten/GLES compile issues.
kblaschke Jul 24, 2023
1c93302
Removed a few unused files.
kblaschke Jul 24, 2023
b7572ea
Use glDrawBuffers instead of glDrawBuffer with GLES.
kblaschke Jul 24, 2023
494718d
Added missing float precision specifiers in vertex/fragment shaders.
kblaschke Jul 28, 2023
b05a8cc
GLES: Use GL_BACK instead of GL_COLOR_ATTACHMENT0 with default frameb…
kblaschke Jul 28, 2023
561ea8c
Added methods to Framebuffer class to add externally created texture …
kblaschke Sep 9, 2023
c266599
Instead of color masking, attach/detach the motion vector u/v texture.
kblaschke Sep 9, 2023
48b8d6a
Restore framebuffer bindings after modifying texture attachments.
kblaschke Sep 9, 2023
c08de98
Properly initialize u/v texture size for motion vectors.
kblaschke Sep 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build_emscripten.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Setup emsdk
uses: mymindstorm/setup-emsdk@v11
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install Packages
run: |
Expand Down Expand Up @@ -53,6 +55,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install Packages
run: |
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build_osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install Packages
run: brew install sdl2 ninja googletest
Expand Down Expand Up @@ -51,6 +53,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install Packages
run: brew install sdl2 ninja googletest
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install Dependencies
run: vcpkg --triplet=x64-windows install glew gtest
Expand Down Expand Up @@ -51,6 +53,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Install Dependencies
run: vcpkg --triplet=x64-windows-static install glew gtest
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/run_tests.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
execute_process(COMMAND "${CMAKE_CTEST_COMMAND}" --build "$ENV{GITHUB_WORKSPACE}/cmake-build"
--build-config $ENV{BUILD_TYPE}
-V
WORKING_DIRECTORY "$ENV{GITHUB_WORKSPACE}/cmake-build"

RESULT_VARIABLE result
)

if(NOT result EQUAL 0)
message(FATAL_ERROR "CTest returned bad exit status")
endif()
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "vendor/projectm-eval"]
path = vendor/projectm-eval
url = https://github.com/projectM-visualizer/projectm-eval.git
5 changes: 4 additions & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ If you want to use a stable version of projectM, download the latest release fro
the [Releases page on GitHub](https://github.com/projectM-visualizer/projectm/releases) and unpack it. You can then skip
to the next step.

If you prefer a bleeding-edge version or want to modify the code, clone the Git repository:
If you prefer a bleeding-edge version or want to modify the code, clone the Git repository and initialize any
submodules:

```bash
sudo apt install git # Probably already installed
git clone https://github.com/projectM-visualizer/projectm.git /path/to/local/repo
cd /path/to/local/repo
git fetch --all --tags
git submodule init
git submodule update
```

### Build and install projectM
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ option(ENABLE_SYSTEM_GLM "Enable use of system-install GLM library" OFF)
cmake_dependent_option(ENABLE_LLVM "Enable experimental LLVM JIT support" OFF "NOT ENABLE_EMSCRIPTEN" OFF)
option(ENABLE_CXX_INTERFACE "Enable exporting C++ symbols for ProjectM and PCM classes, not only the C API. Warning: This is not very portable." OFF)


if(ENABLE_SYSTEM_GLM)
find_package(GLM REQUIRED)
else()
Expand Down
10 changes: 10 additions & 0 deletions src/libprojectM/Audio/AudioConstants.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once

namespace libprojectM {
namespace Audio {

static constexpr int WaveformSamples = 576; //!< Number of waveform data samples available for rendering a frame.
static constexpr int SpectrumSamples = 512; //!< Number of spectrum analyzer samples.

} // namespace Audio
} // namespace libprojectM
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@
* you'll find it online
*/

#include <numeric>
#include <stdio.h>
#include <stdlib.h>

#include "wipemalloc.h"

#include "BeatDetect.hpp"
#include "PCM.hpp"

#include <algorithm>
#include <cmath>
#include <numeric>

namespace libprojectM {
namespace Audio {

BeatDetect::BeatDetect(Pcm& _pcm)
BeatDetect::BeatDetect(PCM& _pcm)
: pcm(_pcm)
{
}
Expand All @@ -64,6 +60,28 @@ auto BeatDetect::GetPCMScale() const noexcept -> float
}


auto BeatDetect::GetFrameAudioData() const -> FrameAudioData
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my knowledge of modern C++ is very poor. how does data get garbage-collected here? are we returning a struct copy? if so, since this is a hot path, can we return a pointer to a struct that frees itself when there are no more references or something? or is it not a big deal to copy 8 floats around?

Copy link
Member Author

@kblaschke kblaschke Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's an object that's - in theory - copied. The compiler optimizes such return values as implicit moves, so when the code actually runs, no copy is created, but the object instance created in the function is moved to the caller's context without creating another object.

The audio data is only requested once per frame, and changes every frame, so using shared pointers here would just add overhead. The presets will get a const reference of this object, so ideally, only this single instance exists during a render call.

{
FrameAudioData data{};

pcm.GetPcm(data.waveformLeft.data(), CHANNEL_L, WaveformSamples);
pcm.GetPcm(data.waveformRight.data(), CHANNEL_R, WaveformSamples);
pcm.GetSpectrum(data.spectrumLeft.data(), CHANNEL_L, SpectrumSamples);
pcm.GetSpectrum(data.spectrumRight.data(), CHANNEL_R, SpectrumSamples);

data.vol = vol;
data.volAtt = volAtt;

data.bass = bass;
data.bassAtt = bassAtt;
data.mid = mid;
data.midAtt = midAtt;
data.treb = treb;
data.trebAtt = trebAtt;

return data;
}

auto BeatDetect::CalculateBeatStatistics() -> void
{
volOld = vol;
Expand Down Expand Up @@ -112,6 +130,7 @@ auto BeatDetect::CalculateBeatStatistics() -> void
}



auto BeatDetect::LowPassFilter::Update(float nextValue) noexcept -> void
{
m_current -= m_buffer[m_bufferPos] / bufferLength;
Expand All @@ -127,3 +146,6 @@ auto BeatDetect::LowPassFilter::Get() const noexcept -> float
{
return m_current;
}

} // namespace Audio
} // namespace libprojectM
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/**
* @file BeatDetect.cpp
* @brief Beat detection class. Takes decompressed sound buffers and returns various characteristics.
*
* projectM -- Milkdrop-esque visualisation SDK
* Copyright (C)2003-2007 projectM Team
*
Expand All @@ -18,28 +21,22 @@
* See 'LICENSE.txt' included within this release
*
*/
/**
* $Id$
*
* Beat detection class. Takes decompressed sound buffers and returns
* various characteristics
*
* $Log$
*
*/
#pragma once

#ifndef _BEAT_DETECT_H
#define _BEAT_DETECT_H
#include "FrameAudioData.hpp"
#include "PCM.hpp"

#include "../PCM.hpp"
#include <array>

namespace libprojectM {
namespace Audio {

class BeatDetect
{
public:
// We should probably remove pcm from the constructor,
// and just pass it as an argument to CalculateBeatStatistics.
explicit BeatDetect(Pcm& pcm);
explicit BeatDetect(PCM& pcm);

auto Reset() noexcept -> void;

Expand All @@ -54,6 +51,13 @@ class BeatDetect
[[nodiscard]]
auto GetPCMScale() const noexcept -> float;

/**
* @brief Returns a filled FrameAudioData structure for the current frame.
* @return A FrameAudioData structure with waveform, spectrum beat detection data.
*/
[[nodiscard]]
auto GetFrameAudioData() const -> FrameAudioData;

float beatSensitivity{1.f};

float treb{0.f};
Expand All @@ -67,7 +71,7 @@ class BeatDetect
float vol{0.f};
float volAtt{0.f};

Pcm& pcm;
PCM& pcm;

private:
class LowPassFilter
Expand All @@ -92,4 +96,5 @@ class BeatDetect
LowPassFilter volSmoothed;
};

#endif /** !_BEAT_DETECT_H */
} // namespace Audio
} // namespace libprojectM
7 changes: 7 additions & 0 deletions src/libprojectM/Audio/FrameAudioData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "FrameAudioData.hpp"

namespace libprojectM {
namespace Audio {

} // namespace Audio
} // namespace libprojectM
38 changes: 38 additions & 0 deletions src/libprojectM/Audio/FrameAudioData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file FrameAudioData.hpp
* @brief Holds all audio data to be used to render a single frame.
*
* This includes the actual waveform data, spectrum and beat detection values.
*/
#pragma once

#include "projectM-4/projectM_export.h"
#include "AudioConstants.hpp"

#include <array>

namespace libprojectM {
namespace Audio {

class PROJECTM_EXPORT FrameAudioData
{
public:
float bass{0.f};
float bassAtt{0.f};
float mid{0.f};
float midAtt{0.f};
float treb{0.f};
float trebAtt{0.f};

float vol{0.f};
float volAtt{0.f};

std::array<float, WaveformSamples> waveformLeft;
std::array<float, WaveformSamples> waveformRight;

std::array<float, SpectrumSamples> spectrumLeft;
std::array<float, SpectrumSamples> spectrumRight;
};

} // namespace Audio
} // namespace libprojectM
Loading