Skip to content

Commit

Permalink
Release of Infinight
Browse files Browse the repository at this point in the history
  • Loading branch information
sainsay committed Aug 18, 2021
1 parent b464a0f commit 71535cd
Show file tree
Hide file tree
Showing 12 changed files with 1,182 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@
*.exe
*.out
*.app

/build
/CMakeFiles
CMakeCache.txt
/.vscode
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.15)

project(AUDIO_PLUGINS VERSION 0.0.1)

add_subdirectory(deps/juce)
set_directory_properties(PROPERTIES JUCE_COMPANY_NAME "sainsay")
set_directory_properties(PROPERTIES JUCE_COMPANY_WEBSITE "https://github.com/sainsay/AudioPlugins" )

add_subdirectory(common)

target_compile_features(Common PRIVATE cxx_std_20)

add_subdirectory(infinight)
target_compile_features(Infinight PRIVATE cxx_std_20)

18 changes: 18 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.15)

set(PROJECT_NAME "Common")

project(${PROJECT_NAME})

file( GLOB_RECURSE common_source_list "${CMAKE_CURRENT_LIST_DIR}/src/*cpp" "${CMAKE_CURRENT_LIST_DIR}/src/*.c")
file( GLOB_RECURSE common_private_list "${CMAKE_CURRENT_LIST_DIR}/src/*h" "${CMAKE_CURRENT_LIST_DIR}/src/*hpp")
file( GLOB_RECURSE common_public_list "${CMAKE_CURRENT_LIST_DIR}/include/*h" "${CMAKE_CURRENT_LIST_DIR}/include/*hpp")

add_library(${PROJECT_NAME} STATIC
${common_public_list}
${common_private_list}
${common_source_list}
)

include_directories(${CMAKE_CURRENT_LIST_DIR}/include/)

73 changes: 73 additions & 0 deletions common/include/common/AudioSample.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once

namespace sain{



template<typename T, size_t size>
struct Sample
{
T Data[size];

T& operator[](const size_t idx)
{
return Data[idx];
}
};

using StereoSample = Sample<float, 2>;
template<>
struct Sample<float , 2>
{
float L;
float R;

float& operator[](const size_t idx)
{
jassert(idx < 2);
float* f = reinterpret_cast<float*>(this);
return *(f+idx);
// potentially dangerous code.

}

StereoSample& operator*( float rhs )
{
L *= rhs;
R *= rhs;
return *this;
}

StereoSample& operator+=( StereoSample& rhs )
{
L += rhs.L;
R += rhs.R;
return *this;
}

};


template<>
struct Sample<float , 6>
{
float L;
float R;
float C;
float Sub;
float SurL;
float SurR;

float& operator[](const size_t idx)
{
jassert(idx < 6);

float* f = reinterpret_cast<float*>(this);
return *(f+idx);
// potentially dangerous code.
}
};

using FiveOneSample = Sample<float, 6>;

}
50 changes: 50 additions & 0 deletions common/include/common/Bitflag.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

#define FLAG_IS_SET(var, flag) ((var) & (flag)) != static_cast<decltype(var)>(0)
#define SET_FLAG(var, flag) var |= (flag)
#define TOGGLE_FLAG(var, flag) var ^= (flag)
#define CLEAR_FLAG(var, flag) var &= ~(flag)

#define DEF_FLAG_OR_OP(type, internal_type) \
inline type operator|(const type& a, const type& b) \
{ \
return static_cast<type>(static_cast<internal_type>(a) | static_cast<internal_type>(b)); \
}

#define DEF_FLAG_ASSIGN_OR_OP(type, internal_type) \
inline type& operator|=(type& a, const type& b) \
{ \
a = static_cast<type>(static_cast<internal_type>(a) | static_cast<internal_type>(b)); \
return a; \
}

#define DEF_FLAG_AND_OP(type, internal_type) \
inline type operator&(const type& a, const type& b) \
{ \
return static_cast<type>(static_cast<internal_type>(a) & static_cast<internal_type>(b)); \
}

#define DEF_FLAG_ASSIGN_AND_OP(type, internal_type) \
inline type operator&=(type& a, const type& b) \
{ \
a = static_cast<type>(static_cast<internal_type>(a) & static_cast<internal_type>(b)); \
return a; \
}

#define DEF_FLAG_XOR_OP(type, internal_type) \
inline type operator^(const type& a, const type& b) \
{ \
return static_cast<type>(static_cast<internal_type>(a) ^ static_cast<internal_type>(b)); \
}

#define DEF_FLAG_ASSIGN_XOR_OP(type, internal_type) \
inline type operator^=(type& a, const type& b) \
{ \
a = static_cast<type>(static_cast<internal_type>(a) ^ static_cast<internal_type>(b)); \
return a; \
}

#define DEF_FLAG_NOT_OP(type, internal_type) \
inline type operator~(const type& a) \
{ \
return static_cast<type>(~static_cast<internal_type>(a)); \
}
138 changes: 138 additions & 0 deletions common/include/common/Buffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#include <inttypes.h>
#include <array>

#include <iostream>

namespace sain
{
template <typename _Ty, size_t count>
class RingBuffer
{
public:
typedef _Ty value_type;
typedef _Ty* pointer;
typedef const _Ty* const_pointer;
typedef _Ty& reference;
typedef const _Ty& const_reference;

std::array<value_type, count> data;

private:

typedef typename std::array<_Ty, count>::iterator DataIterator;
typedef typename std::array<value_type, count>::reverse_iterator DataReverseIterator;

class RingBufferIterator
{
RingBuffer* myRingBuffer;
DataIterator it;
public:

RingBufferIterator() :
myRingBuffer(nullptr),
it(nullptr)
{
}

RingBufferIterator(RingBuffer* rb, DataIterator start) :
myRingBuffer(rb),
it(start)
{
}

RingBufferIterator(const RingBufferIterator& rhs)
{
this->it = rhs.it;
this->myRingBuffer = rhs.myRingBuffer;
}

RingBufferIterator& operator=(const RingBufferIterator& rhs)
{
this->it = rhs.it;
this->myRingBuffer = rhs.myRingBuffer;
return *this;
}

RingBufferIterator(RingBufferIterator&& rhs)
{
this->it = rhs.it;
this->myRingBuffer = rhs.myRingBuffer;

rhs.myRingBuffer = nullptr;
rhs.it = std::_Array_iterator<_Ty, count>( nullptr );
}

RingBufferIterator& operator=(RingBufferIterator&& rhs)
{
this->it = rhs.it;
this->myRingBuffer = rhs.myRingBuffer;

rhs.myRingBuffer = nullptr;
rhs.it = std::_Array_iterator<_Ty, count>( nullptr );
return *this;
}

RingBufferIterator& operator++()
{
++it;
if (it == myRingBuffer->data.end())
{
it = myRingBuffer->data.begin();
}
return *this;
}

RingBufferIterator& operator--(){
if(it == myRingBuffer->data.begin())
{
it = myRingBuffer->data.end();
--it;
return *this;
}
--it;
return *this;
}

size_t operator-(const RingBufferIterator& rhs) const
{
return this->it - rhs.it;
}

reference operator*() const
{
return *it;
}
};

public:
using iterator = RingBufferIterator;

RingBuffer( )
{
std::fill(data.begin(), data.end(), value_type());
}

~RingBuffer( ){}

iterator from(size_t idx)
{
return iterator(this, data.begin() + idx);
}

iterator begin()
{
return iterator(this, data.begin());
}

iterator end()
{
return iterator(this, data.end());
}

void Clear(){
std::fill(data.begin(), data.end(), value_type());
}

};

} // namespace sain
Loading

0 comments on commit 71535cd

Please sign in to comment.