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
58template <is::anyVctr Src>
59auto toSIMDRegister (const Src& src)
60{
61 using SIMDRegister = juce::dsp::SIMDRegister<typename Src::value_type>;
62
63 VCTR_ASSERT (src.size() == SIMDRegister::SIMDNumElements);
64
65 if constexpr (Config::archARM)
66 {
67 return SIMDRegister { src.getNeon (0).value };
68 }
69 else
70 {
71 constexpr size_t registerSize = SIMDRegister::SIMDRegisterSize;
72
73 if constexpr (registerSize == 32)
74 {
75 return SIMDRegister { src.getAVX (0).value };
76 }
77
78 return SIMDRegister { src.getSSE (0).value };
79 }
80}
81
98template <class SampleType>
99auto blockChannelAsSpan (const juce::dsp::AudioBlock<SampleType>& block, size_t channelIdx)
100{
101 auto numSamples = block.getNumSamples();
102 return Span { block.getChannelPointer (channelIdx), numSamples };
103}
104
112template <class SampleType>
113auto blockChannelAsSpanSIMDAligned (const juce::dsp::AudioBlock<SampleType>& block, size_t channelIdx)
114{
115 auto numSamples = block.getNumSamples();
116 return Span { block.getChannelPointer (channelIdx), numSamples, simdAlignedSpanStorageInfo<SampleType>() };
117}
118
119}
The view type.
Definition: Span.h:51
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:113
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:99
auto toSIMDRegister(const Src &src)
Loads the first elements of src into a juce::SIMDRegister.
Definition: vctr_juce_helpers.h:59