Browse Source

Added a ScopedNoDenormal class to temporarily disable denormals

tags/2021-05-28
hogliux 8 years ago
parent
commit
e2c8e30d72
10 changed files with 73 additions and 5 deletions
  1. +1
    -1
      examples/DSP module plugin demo/DSP module plugin demo.jucer
  2. +8
    -0
      examples/DSP module plugin demo/JuceLibraryCode/AppConfig.h
  3. +2
    -0
      examples/DSP module plugin demo/Source/PluginProcessor.cpp
  4. +2
    -1
      extras/Projucer/JuceLibraryCode/BinaryData.cpp
  5. +1
    -1
      extras/Projucer/JuceLibraryCode/BinaryData.h
  6. +1
    -0
      extras/Projucer/Source/BinaryData/jucer_AudioPluginFilterTemplate.cpp
  7. +30
    -0
      modules/juce_audio_basics/buffers/juce_FloatVectorOperations.h
  8. +1
    -0
      modules/juce_audio_basics/juce_audio_basics.h
  9. +25
    -0
      modules/juce_dsp/juce_dsp.h
  10. +2
    -2
      modules/juce_dsp/processors/juce_Oversampling.cpp

+ 1
- 1
examples/DSP module plugin demo/DSP module plugin demo.jucer View File

@@ -125,5 +125,5 @@
<MODULE id="juce_gui_extra" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
<MODULE id="juce_opengl" showAllCode="1" useLocalCopy="0" useGlobalPath="0"/>
</MODULES>
<JUCEOPTIONS JUCE_QUICKTIME="disabled"/>
<JUCEOPTIONS JUCE_QUICKTIME="disabled" JUCE_DSP_ENABLE_SNAP_TO_ZERO="disabled"/>
</JUCERPROJECT>

+ 8
- 0
examples/DSP module plugin demo/JuceLibraryCode/AppConfig.h View File

@@ -130,6 +130,10 @@
//#define JUCE_FORCE_USE_LEGACY_PARAM_IDS 1
#endif
#ifndef JUCE_FORCE_LEGACY_PARAMETER_AUTOMATION_TYPE
//#define JUCE_FORCE_LEGACY_PARAMETER_AUTOMATION_TYPE 1
#endif
#ifndef JUCE_USE_STUDIO_ONE_COMPATIBLE_PARAMETERS
//#define JUCE_USE_STUDIO_ONE_COMPATIBLE_PARAMETERS 1
#endif
@@ -214,6 +218,10 @@
//#define JUCE_DSP_USE_STATIC_FFTW 1
#endif
#ifndef JUCE_DSP_ENABLE_SNAP_TO_ZERO
#define JUCE_DSP_ENABLE_SNAP_TO_ZERO 0
#endif
//==============================================================================
// juce_events flags:


+ 2
- 0
examples/DSP module plugin demo/Source/PluginProcessor.cpp View File

@@ -114,6 +114,8 @@ void DspModulePluginDemoAudioProcessor::releaseResources()
void DspModulePluginDemoAudioProcessor::process (dsp::ProcessContextReplacing<float> context) noexcept
{
ScopedNoDenormals noDenormals;
// Input volume applied with a LinearSmoothedValue
inputVolume.process (context);


+ 2
- 1
extras/Projucer/JuceLibraryCode/BinaryData.cpp View File

@@ -1617,6 +1617,7 @@ static const unsigned char temp_binary_data_8[] =
"\r\n"
"void FILTERCLASSNAME::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)\r\n"
"{\r\n"
" ScopedNoDenormals noDenormals;\r\n"
" const int totalNumInputChannels = getTotalNumInputChannels();\r\n"
" const int totalNumOutputChannels = getTotalNumOutputChannels();\r\n"
"\r\n"
@@ -7028,7 +7029,7 @@ const char* getNamedResource (const char* resourceNameUTF8, int& numBytes) throw
case 0xafccbd3f: numBytes = 3141; return jucer_AudioComponentTemplate_cpp;
case 0x27c5a93a: numBytes = 1310; return jucer_AudioPluginEditorTemplate_cpp;
case 0x4d0721bf: numBytes = 938; return jucer_AudioPluginEditorTemplate_h;
case 0x51b49ac5: numBytes = 5611; return jucer_AudioPluginFilterTemplate_cpp;
case 0x51b49ac5: numBytes = 5647; return jucer_AudioPluginFilterTemplate_cpp;
case 0x488afa0a: numBytes = 2245; return jucer_AudioPluginFilterTemplate_h;
case 0xabad7041: numBytes = 2151; return jucer_ComponentTemplate_cpp;
case 0xfc72fe86: numBytes = 2064; return jucer_ComponentTemplate_h;


+ 1
- 1
extras/Projucer/JuceLibraryCode/BinaryData.h View File

@@ -33,7 +33,7 @@ namespace BinaryData
const int jucer_AudioPluginEditorTemplate_hSize = 938;
extern const char* jucer_AudioPluginFilterTemplate_cpp;
const int jucer_AudioPluginFilterTemplate_cppSize = 5611;
const int jucer_AudioPluginFilterTemplate_cppSize = 5647;
extern const char* jucer_AudioPluginFilterTemplate_h;
const int jucer_AudioPluginFilterTemplate_hSize = 2245;


+ 1
- 0
extras/Projucer/Source/BinaryData/jucer_AudioPluginFilterTemplate.cpp View File

@@ -131,6 +131,7 @@ bool FILTERCLASSNAME::isBusesLayoutSupported (const BusesLayout& layouts) const
void FILTERCLASSNAME::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
{
ScopedNoDenormals noDenormals;
const int totalNumInputChannels = getTotalNumInputChannels();
const int totalNumOutputChannels = getTotalNumOutputChannels();


+ 30
- 0
modules/juce_audio_basics/buffers/juce_FloatVectorOperations.h View File

@@ -221,4 +221,34 @@ public:
static void JUCE_CALLTYPE disableDenormalisedNumberSupport() noexcept;
};
//==============================================================================
/**
Helper class providing an RAII-based mechanism for temporarily disabling
denormals on your CPU.
*/
class ScopedNoDenormals
{
public:
inline ScopedNoDenormals() noexcept
{
#if JUCE_USE_SSE_INTRINSICS
mxcsr = _mm_getcsr();
_mm_setcsr (mxcsr | 0x8040); // add the DAZ and FZ bits
#endif
}
inline ~ScopedNoDenormals() noexcept
{
#if JUCE_USE_SSE_INTRINSICS
_mm_setcsr (mxcsr);
#endif
}
private:
#if JUCE_USE_SSE_INTRINSICS
unsigned int mxcsr;
#endif
};
} // namespace juce

+ 1
- 0
modules/juce_audio_basics/juce_audio_basics.h View File

@@ -51,6 +51,7 @@
#include <juce_core/juce_core.h>
//==============================================================================
#undef Complex // apparently some C libraries actually define these symbols (!)
#undef Factor


+ 25
- 0
modules/juce_dsp/juce_dsp.h View File

@@ -166,6 +166,23 @@
#define JUCE_DSP_USE_STATIC_FFTW 0
#endif
/** Config: JUCE_DSP_ENABLE_SNAP_TO_ZERO
Enables code in the dsp module to avoid floating point denormals during the
processing of some of the dsp module's filters.
Enabling this will add a slight performance overhead to the DSP module's
filters and algorithms. If your audio app already disables denormals altogether
(for exmaple, by using the ScopedNoDenormals class or the
FloatVectorOperations::disableDenormalisedNumberSupport method), then you
can safely disable this flag to shave off a few cpu cycles from the DSP module's
filters and algorithms.
*/
#ifndef JUCE_DSP_ENABLE_SNAP_TO_ZERO
#define JUCE_DSP_ENABLE_SNAP_TO_ZERO 1
#endif
//==============================================================================
#undef Complex // apparently some C libraries actually define these symbols (!)
#undef Factor
@@ -185,11 +202,19 @@ namespace juce
This function will work with both primitives and simple containers.
*/
#if JUCE_DSP_ENABLE_SNAP_TO_ZERO
inline void snapToZero (float& x) noexcept { JUCE_SNAP_TO_ZERO (x); }
#ifndef DOXYGEN
inline void snapToZero (double& x) noexcept { JUCE_SNAP_TO_ZERO (x); }
inline void snapToZero (long double& x) noexcept { JUCE_SNAP_TO_ZERO (x); }
#endif
#else
inline void snapToZero (float& x) noexcept { ignoreUnused (x); }
#ifndef DOXYGEN
inline void snapToZero (double& x) noexcept { ignoreUnused (x); }
inline void snapToZero (long double& x) noexcept { ignoreUnused (x); }
#endif
#endif
}
}
}


+ 2
- 2
modules/juce_dsp/processors/juce_Oversampling.cpp View File

@@ -444,7 +444,7 @@ public:
auto numStages = coefficientsUp.size();
for (auto n = 0; n < numStages; n++)
JUCE_SNAP_TO_ZERO (lv1[n]);
util::snapToZero (lv1[n]);
}
}
else
@@ -455,7 +455,7 @@ public:
auto numStages = coefficientsDown.size();
for (auto n = 0; n < numStages; n++)
JUCE_SNAP_TO_ZERO (lv1[n]);
util::snapToZero (lv1[n]);
}
}
}


Loading…
Cancel
Save