VCTR
Loading...
Searching...
No Matches
vctr_juce_helpers.h
1/*
2 ==============================================================================
3 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
5 Copyright 2023 by sonible GmbH.
6
7 This file is part of VCTR - Versatile Container Templates Reconceptualized.
8
9 VCTR is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License version 3
11 only, as published by the Free Software Foundation.
12
13 VCTR is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License version 3 for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 version 3 along with VCTR. If not, see <https://www.gnu.org/licenses/>.
20 ==============================================================================
21*/
22
23#pragma once
24
25#include "../vctr/vctr.h"
26#include <juce_dsp/juce_dsp.h>
27
33{
34
62template <is::anyVctr Src>
63auto toSIMDRegister (const Src& src, size_t i = 0)
64{
65 using SIMDRegister = juce::dsp::SIMDRegister<typename Src::value_type>;
66
67 VCTR_ASSERT (src.size() == SIMDRegister::SIMDNumElements);
68
69 if constexpr (Config::archARM)
70 {
71 return SIMDRegister { src.getNeon (i).value };
72 }
73 else
74 {
75 constexpr size_t registerSize = SIMDRegister::SIMDRegisterSize;
76
77 if constexpr (registerSize == 32)
78 {
79 return SIMDRegister { src.getAVX (i).value };
80 }
81
82 return SIMDRegister { src.getSSE (i).value };
83 }
84}
85
102template <class SampleType>
103auto blockChannelAsSpan (const juce::dsp::AudioBlock<SampleType>& block, size_t channelIdx)
104{
105 auto numSamples = block.getNumSamples();
106 return Span { block.getChannelPointer (channelIdx), numSamples };
107}
108
116template <class SampleType>
117auto blockChannelAsSpanSIMDAligned (const juce::dsp::AudioBlock<SampleType>& block, size_t channelIdx)
118{
119 auto numSamples = block.getNumSamples();
120 return Span { block.getChannelPointer (channelIdx), numSamples, simdAlignedSpanStorageInfo<SampleType>() };
121}
122
131template <class SampleType>
132auto audioBufferChannelAsSpan (juce::AudioBuffer<SampleType>& buffer, size_t channelIdx)
133{
134 auto numSamples = size_t (buffer.getNumSamples());
135 return Span { buffer.getWritePointer (int (channelIdx)), numSamples };
136}
137
146template <class SampleType>
147auto audioBufferChannelAsSpan (const juce::AudioBuffer<SampleType>& buffer, size_t channelIdx)
148{
149 auto numSamples = size_t (buffer.getNumSamples());
150 return Span { buffer.getReadPointer (int (channelIdx)), numSamples };
151}
152
153}
The view type.
Definition: Span.h:66
Helper functions to integrate vctr into dsp code written with JUCE (https://github....
Definition: vctr_juce_helpers.h:33
auto blockChannelAsSpanSIMDAligned(const juce::dsp::AudioBlock< SampleType > &block, size_t channelIdx)
Returns a Span that views a single channel of a juce::dsp::AudioBlock, expecting SIMD aligned memory.
Definition: vctr_juce_helpers.h:117
auto blockChannelAsSpan(const juce::dsp::AudioBlock< SampleType > &block, size_t channelIdx)
Returns a Span that views a single channel of a juce::dsp::AudioBlock.
Definition: vctr_juce_helpers.h:103
auto toSIMDRegister(const Src &src, size_t i=0)
Loads elements of src into a juce::SIMDRegister.
Definition: vctr_juce_helpers.h:63
auto audioBufferChannelAsSpan(juce::AudioBuffer< SampleType > &buffer, size_t channelIdx)
Returns a Span that views a single channel of a juce::AudioBuffer.
Definition: vctr_juce_helpers.h:132