MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / AudioEffects

Class AudioEffects

CodenameOne/src/com/codename1/media/AudioEffects.java:32–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30/// normalized float PCM samples in the `[-1, 1]` range. They return new
31/// `AudioBuffer` instances and leave the source buffer unchanged.
32public final class AudioEffects {
33 private static final float DEFAULT_LOW_CUTOFF_HZ = 250.0f;
34 private static final float DEFAULT_HIGH_CUTOFF_HZ = 4000.0f;
35 private static boolean simdOptimizationsEnabled = Simd.get().isSupported();
36
37 private AudioEffects() {
38 }
39
40 /// Indicates whether `AudioEffects` should use SIMD-backed kernels when
41 /// the current platform supports them. Scalar fallbacks are always used for
42 /// effects whose stateful filters don't map to the current SIMD API.
43 ///
44 /// #### Returns
45 ///
46 /// true when SIMD optimizations are enabled.
47 public static boolean isSimdOptimizationsEnabled() {
48 return simdOptimizationsEnabled;
49 }
50
51 /// Enables or disables SIMD-backed `AudioEffects` optimizations.
52 ///
53 /// This only changes internal implementation choices. It doesn't change
54 /// output format or API behavior.
55 ///
56 /// #### Parameters
57 ///
58 /// - `enabled`: true to use SIMD where supported, false to force scalar loops.
59 public static void setSimdOptimizationsEnabled(boolean enabled) {
60 simdOptimizationsEnabled = enabled;
61 }
62
63 /// Restores the default SIMD optimization setting for this platform.
64 public static void resetSimdOptimizationsEnabled() {
65 simdOptimizationsEnabled = Simd.get().isSupported();
66 }
67
68 /// Applies gain to a PCM buffer.
69 ///
70 /// #### Parameters
71 ///
72 /// - `source`: The source buffer.
73 /// - `gain`: Gain multiplier. `1.0f` preserves level.
74 ///
75 /// #### Returns
76 ///
77 /// a new buffer with gain applied and samples clipped to `[-1, 1]`.
78 public static AudioBuffer gain(AudioBuffer source, float gain) {
79 validateBuffer(source);
80 validateFinite(gain, "gain");
81 float[] pcm = copySamples(source);
82 applyGainInPlace(pcm, gain);
83 return buffer(source.getSampleRate(), source.getNumChannels(), pcm);
84 }
85
86 /// Normalizes a PCM buffer so its largest absolute sample reaches `targetPeak`.
87 ///
88 /// #### Parameters
89 ///

Callers

nothing calls this directly

Calls 2

getMethod · 0.95
isSupportedMethod · 0.65

Tested by

no test coverage detected