diff --git a/core/src/main/java/de/pottgames/tuningfork/ALExtension.java b/core/src/main/java/de/pottgames/tuningfork/ALExtension.java index 131b8e2..d49af87 100644 --- a/core/src/main/java/de/pottgames/tuningfork/ALExtension.java +++ b/core/src/main/java/de/pottgames/tuningfork/ALExtension.java @@ -77,12 +77,12 @@ public enum ALExtension { String getAlSpecifier() { - return this.alSpecifier; + return alSpecifier; } boolean isAlc() { - return this.alc; + return alc; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/AlEvent.java b/core/src/main/java/de/pottgames/tuningfork/AlEvent.java index be2b196..d7fc814 100644 --- a/core/src/main/java/de/pottgames/tuningfork/AlEvent.java +++ b/core/src/main/java/de/pottgames/tuningfork/AlEvent.java @@ -20,32 +20,32 @@ public AlEvent(int eventType, int object, int param, int length, long message, l public int getEventType() { - return this.eventType; + return eventType; } public int getObject() { - return this.object; + return object; } public int getParam() { - return this.param; + return param; } public int getLength() { - return this.length; + return length; } public long getMessage() { - return this.message; + return message; } public long getUserParam() { - return this.userParam; + return userParam; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/Audio.java b/core/src/main/java/de/pottgames/tuningfork/Audio.java index a5a3525..29107c6 100644 --- a/core/src/main/java/de/pottgames/tuningfork/Audio.java +++ b/core/src/main/java/de/pottgames/tuningfork/Audio.java @@ -113,7 +113,7 @@ public static Audio initSafe(AudioConfig config) throws OpenDeviceException, Uns private Audio(AudioDevice device, AudioConfig config) { - this.logger = config.getLogger(); + logger = config.getLogger(); // LOAD NATIVE LIBRARIES final SharedLibraryLoader loader = new SharedLibraryLoader(); @@ -123,33 +123,33 @@ private Audio(AudioDevice device, AudioConfig config) { loader.load("decoders_rs"); nativesLoaded = true; } catch (final Exception e) { - this.logger.warn(this.getClass(), e.getMessage()); - this.logger.warn(this.getClass(), "Native decoders aren't available on this platform"); + logger.warn(this.getClass(), e.getMessage()); + logger.warn(this.getClass(), "Native decoders aren't available on this platform"); } } - this.nativeDecoderAvailable = nativesLoaded; + nativeDecoderAvailable = nativesLoaded; // INIT this.device = device; - this.wavDecoderProvider = config.getResamplerProvider(); + wavDecoderProvider = config.getResamplerProvider(); Audio.instance = this; - this.publicFilter = new Filter(1f, 1f); - this.streamManager = new StreamManager(config, this.logger); + publicFilter = new Filter(1f, 1f); + streamManager = new StreamManager(config, logger); final AssetManager assetManager = config.getAssetManager(); if (assetManager != null) { - this.registerAssetManagerLoaders(assetManager); + registerAssetManagerLoaders(assetManager); } // SET DEFAULTS - this.setDistanceAttenuationModel(config.getDistanceAttenuationModel()); - this.defaultSettings.setVirtualization(config.getVirtualization()); - this.defaultSettings.setSpatialization(config.getSpatialization()); + setDistanceAttenuationModel(config.getDistanceAttenuationModel()); + defaultSettings.setVirtualization(config.getVirtualization()); + defaultSettings.setSpatialization(config.getSpatialization()); // CREATE LISTENER - this.listener = new SoundListener(); + listener = new SoundListener(); // CREATE SOURCES - this.sourcePool = new SoundSourcePool(config.getSimultaneousSources()); + sourcePool = new SoundSourcePool(config.getSimultaneousSources()); } @@ -170,7 +170,7 @@ public static Audio get() { * @return the device in charge */ public AudioDevice getDevice() { - return this.device; + return device; } @@ -190,9 +190,9 @@ public AudioDevice getDevice() { */ public void setDistanceAttenuationModel(DistanceAttenuationModel model) { AL10.alDistanceModel(model.getAlId()); - this.setDefaultAttenuationFactor(model.getAttenuationFactor()); - this.setDefaultAttenuationMinDistance(model.getAttenuationMinDistance()); - this.setDefaultAttenuationMaxDistance(model.getAttenuationMaxDistance()); + setDefaultAttenuationFactor(model.getAttenuationFactor()); + setDefaultAttenuationMinDistance(model.getAttenuationMinDistance()); + setDefaultAttenuationMaxDistance(model.getAttenuationMaxDistance()); } @@ -204,7 +204,7 @@ public void setDistanceAttenuationModel(DistanceAttenuationModel model) { * @param distance (default depends on the attenuation model) */ public void setDefaultAttenuationMinDistance(float distance) { - this.defaultSettings.setMinAttenuationDistance(distance); + defaultSettings.setMinAttenuationDistance(distance); } @@ -216,7 +216,7 @@ public void setDefaultAttenuationMinDistance(float distance) { * @param distance (default depends on the attenuation model) */ public void setDefaultAttenuationMaxDistance(float distance) { - this.defaultSettings.setMaxAttenuationDistance(distance); + defaultSettings.setMaxAttenuationDistance(distance); } @@ -229,7 +229,7 @@ public void setDefaultAttenuationMaxDistance(float distance) { * @param rolloff (default depends on the attenuation model) */ public void setDefaultAttenuationFactor(float rolloff) { - this.defaultSettings.setAttenuationFactor(rolloff); + defaultSettings.setAttenuationFactor(rolloff); } @@ -239,7 +239,7 @@ public void setDefaultAttenuationFactor(float rolloff) { * @return the default attenuation min distance */ public float getDefaultAttenuationMinDistance() { - return this.defaultSettings.getMinAttenuationDistance(); + return defaultSettings.getMinAttenuationDistance(); } @@ -249,7 +249,7 @@ public float getDefaultAttenuationMinDistance() { * @return the default attenuation max distance */ public float getDefaultAttenuationMaxDistance() { - return this.defaultSettings.getMaxAttenuationDistance(); + return defaultSettings.getMaxAttenuationDistance(); } @@ -259,7 +259,7 @@ public float getDefaultAttenuationMaxDistance() { * @return the default attenuation factor */ public float getDefaultAttenuationFactor() { - return this.defaultSettings.getAttenuationFactor(); + return defaultSettings.getAttenuationFactor(); } @@ -270,7 +270,7 @@ public float getDefaultAttenuationFactor() { * @return the virtualization method */ public Virtualization getDefaultVirtualization() { - return this.defaultSettings.getVirtualization(); + return defaultSettings.getVirtualization(); } @@ -280,7 +280,7 @@ public Virtualization getDefaultVirtualization() { * @return the default audio settings */ AudioSettings getDefaultAudioSettings() { - return this.defaultSettings; + return defaultSettings; } @@ -295,12 +295,12 @@ AudioSettings getDefaultAudioSettings() { * @param virtualization the virtualization */ public void setDefaultVirtualization(Virtualization virtualization) { - this.defaultSettings.setVirtualization(virtualization); - this.sourcePool.setVirtualization(virtualization); - this.streamManager.setDefaultVirtualization(virtualization); + defaultSettings.setVirtualization(virtualization); + sourcePool.setVirtualization(virtualization); + streamManager.setDefaultVirtualization(virtualization); - for (int i = 0; i < this.managedSources.size; i++) { - final SoundSource source = this.managedSources.get(i); + for (int i = 0; i < managedSources.size; i++) { + final SoundSource source = managedSources.get(i); if (source != null) { source.setVirtualization(virtualization); } @@ -309,17 +309,17 @@ public void setDefaultVirtualization(Virtualization virtualization) { public Spatialization getDefaultSpatialization() { - return this.defaultSettings.getSpatialization(); + return defaultSettings.getSpatialization(); } public void setDefaultSpatialization(Spatialization spatialization) { - this.defaultSettings.setSpatialization(spatialization); - this.sourcePool.setSpatialization(spatialization); - this.streamManager.setDefaultSpatialization(spatialization); + defaultSettings.setSpatialization(spatialization); + sourcePool.setSpatialization(spatialization); + streamManager.setDefaultSpatialization(spatialization); - for (int i = 0; i < this.managedSources.size; i++) { - final SoundSource source = this.managedSources.get(i); + for (int i = 0; i < managedSources.size; i++) { + final SoundSource source = managedSources.get(i); if (source != null) { source.setSpatialization(spatialization); } @@ -333,7 +333,7 @@ public void setDefaultSpatialization(Spatialization spatialization) { * @return the master volume in the range: 0 - 1 */ public float getMasterVolume() { - return this.listener.getMasterVolume(); + return listener.getMasterVolume(); } @@ -343,7 +343,7 @@ public float getMasterVolume() { * @param volume range: 0 - 1 */ public void setMasterVolume(float volume) { - this.listener.setMasterVolume(MathUtils.clamp(volume, 0f, 1f)); + listener.setMasterVolume(MathUtils.clamp(volume, 0f, 1f)); } @@ -371,7 +371,7 @@ public void setDopplerFactor(float dopplerFactor) { */ public BufferedSoundSource obtainSource(SoundBuffer buffer) { // FIND FREE SOUND SOURCE - final BufferedSoundSource source = this.sourcePool.findFreeSource(this.defaultSettings); + final BufferedSoundSource source = sourcePool.findFreeSource(defaultSettings); // PREPARE SOURCE source.obtained = true; @@ -384,7 +384,7 @@ public BufferedSoundSource obtainSource(SoundBuffer buffer) { private BufferedSoundSource obtainRelativeSource(SoundBuffer buffer, boolean looping) { // FIND FREE SOUND SOURCE - final BufferedSoundSource source = this.sourcePool.findFreeSource(this.defaultSettings); + final BufferedSoundSource source = sourcePool.findFreeSource(defaultSettings); // PREPARE SOURCE source.obtained = true; @@ -401,7 +401,7 @@ private BufferedSoundSource obtainRelativeSource(SoundBuffer buffer, boolean loo * @param buffer the sound buffer */ protected void play(SoundBuffer buffer) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.play(); source.obtained = false; } @@ -415,7 +415,7 @@ protected void play(SoundBuffer buffer) { * @param time the time in nanoseconds, use {@link AudioDevice#getClockTime()} to get the current time */ protected void playAtTime(SoundBuffer buffer, long time) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.playAtTime(time); source.obtained = false; } @@ -428,7 +428,7 @@ protected void playAtTime(SoundBuffer buffer, long time) { * @param effect the sound effect */ protected void play(SoundBuffer buffer, SoundEffect effect) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.attachEffect(effect); source.play(); source.obtained = false; @@ -442,7 +442,7 @@ protected void play(SoundBuffer buffer, SoundEffect effect) { * @param volume in the range of 0.0 - 1.0 with 0 being silent and 1 being the maximum volume. (default 1) */ protected void play(SoundBuffer buffer, float volume) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.setVolume(volume); source.play(); source.obtained = false; @@ -457,7 +457,7 @@ protected void play(SoundBuffer buffer, float volume) { * @param effect the sound effect */ protected void play(SoundBuffer buffer, float volume, SoundEffect effect) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.setVolume(volume); source.attachEffect(effect); source.play(); @@ -473,7 +473,7 @@ protected void play(SoundBuffer buffer, float volume, SoundEffect effect) { * @param pitch in the range of 0.5 - 2.0 with values < 1 making the sound slower and values > 1 making it faster (default 1) */ protected void play(SoundBuffer buffer, float volume, float pitch) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.setVolume(volume); source.setPitch(pitch); source.play(); @@ -491,7 +491,7 @@ protected void play(SoundBuffer buffer, float volume, float pitch) { * @param highFreqVolume the volume of high frequencies */ protected void play(SoundBuffer buffer, float volume, float pitch, float lowFreqVolume, float highFreqVolume) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.setVolume(volume); source.setPitch(pitch); source.setFilter(lowFreqVolume, highFreqVolume); @@ -509,7 +509,7 @@ protected void play(SoundBuffer buffer, float volume, float pitch, float lowFreq * @param effect the sound effect */ protected void play(SoundBuffer buffer, float volume, float pitch, SoundEffect effect) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.setVolume(volume); source.setPitch(pitch); source.attachEffect(effect); @@ -527,7 +527,7 @@ protected void play(SoundBuffer buffer, float volume, float pitch, SoundEffect e * @param pan in the range of -1.0 (full left) to 1.0 (full right). (default center 0.0) */ protected void play(SoundBuffer buffer, float volume, float pitch, float pan) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.setVolume(volume); source.setPitch(pitch); source.setAttenuationFactor(0f); @@ -547,7 +547,7 @@ protected void play(SoundBuffer buffer, float volume, float pitch, float pan) { * @param effect the sound effect */ protected void play(SoundBuffer buffer, float volume, float pitch, float pan, SoundEffect effect) { - final BufferedSoundSource source = this.obtainRelativeSource(buffer, false); + final BufferedSoundSource source = obtainRelativeSource(buffer, false); source.setVolume(volume); source.setPitch(pitch); source.setAttenuationFactor(0f); @@ -565,7 +565,7 @@ protected void play(SoundBuffer buffer, float volume, float pitch, float pan, So * @param position the position in 3D space */ protected void play3D(SoundBuffer buffer, Vector3 position) { - final BufferedSoundSource source = this.obtainSource(buffer); + final BufferedSoundSource source = obtainSource(buffer); source.setPosition(position); source.play(); source.obtained = false; @@ -581,7 +581,7 @@ protected void play3D(SoundBuffer buffer, Vector3 position) { * @param highFreqVolume the volume of high frequencies */ protected void play3D(SoundBuffer buffer, Vector3 position, float lowFreqVolume, float highFreqVolume) { - final BufferedSoundSource source = this.obtainSource(buffer); + final BufferedSoundSource source = obtainSource(buffer); source.setPosition(position); source.setFilter(lowFreqVolume, highFreqVolume); source.play(); @@ -597,7 +597,7 @@ protected void play3D(SoundBuffer buffer, Vector3 position, float lowFreqVolume, * @param effect the sound effect */ protected void play3D(SoundBuffer buffer, Vector3 position, SoundEffect effect) { - final BufferedSoundSource source = this.obtainSource(buffer); + final BufferedSoundSource source = obtainSource(buffer); source.setPosition(position); source.attachEffect(effect); source.play(); @@ -615,7 +615,7 @@ protected void play3D(SoundBuffer buffer, Vector3 position, SoundEffect effect) * @param effect the sound effect */ protected void play3D(SoundBuffer buffer, Vector3 position, float lowFreqVolume, float highFreqVolume, SoundEffect effect) { - final BufferedSoundSource source = this.obtainSource(buffer); + final BufferedSoundSource source = obtainSource(buffer); source.setPosition(position); source.attachEffect(effect); source.setFilter(lowFreqVolume, highFreqVolume); @@ -632,7 +632,7 @@ protected void play3D(SoundBuffer buffer, Vector3 position, float lowFreqVolume, * @param position the position in 3D space */ protected void play3D(SoundBuffer buffer, float volume, Vector3 position) { - final BufferedSoundSource source = this.obtainSource(buffer); + final BufferedSoundSource source = obtainSource(buffer); source.setVolume(volume); source.setPosition(position); source.play(); @@ -650,7 +650,7 @@ protected void play3D(SoundBuffer buffer, float volume, Vector3 position) { * @param highFreqVolume the volume of high frequencies */ protected void play3D(SoundBuffer buffer, float volume, Vector3 position, float lowFreqVolume, float highFreqVolume) { - final BufferedSoundSource source = this.obtainSource(buffer); + final BufferedSoundSource source = obtainSource(buffer); source.setVolume(volume); source.setPosition(position); source.setFilter(lowFreqVolume, highFreqVolume); @@ -668,7 +668,7 @@ protected void play3D(SoundBuffer buffer, float volume, Vector3 position, float * @param effect the sound effect */ protected void play3D(SoundBuffer buffer, float volume, Vector3 position, SoundEffect effect) { - final BufferedSoundSource source = this.obtainSource(buffer); + final BufferedSoundSource source = obtainSource(buffer); source.setVolume(volume); source.setPosition(position); source.attachEffect(effect); @@ -686,7 +686,7 @@ protected void play3D(SoundBuffer buffer, float volume, Vector3 position, SoundE * @param position the position in 3D space */ protected void play3D(SoundBuffer buffer, float volume, float pitch, Vector3 position) { - final BufferedSoundSource source = this.obtainSource(buffer); + final BufferedSoundSource source = obtainSource(buffer); source.setVolume(volume); source.setPitch(pitch); source.setPosition(position); @@ -705,7 +705,7 @@ protected void play3D(SoundBuffer buffer, float volume, float pitch, Vector3 pos * @param effect the sound effect */ protected void play3D(SoundBuffer buffer, float volume, float pitch, Vector3 position, SoundEffect effect) { - final BufferedSoundSource source = this.obtainSource(buffer); + final BufferedSoundSource source = obtainSource(buffer); source.setVolume(volume); source.setPitch(pitch); source.setPosition(position); @@ -727,14 +727,14 @@ protected void play3D(SoundBuffer buffer, float volume, float pitch, Vector3 pos */ public boolean setDefaultResampler(String resampler) { if (resampler != null) { - final int resamplerIndex = this.device.getResamplerIndexByName(resampler); + final int resamplerIndex = device.getResamplerIndexByName(resampler); if (resamplerIndex >= 0) { - this.sourcePool.setResamplerByIndex(resamplerIndex); + sourcePool.setResamplerByIndex(resamplerIndex); - this.streamManager.setDefaultResampler(resamplerIndex); + streamManager.setDefaultResampler(resamplerIndex); - for (int i = 0; i < this.managedSources.size; i++) { - final SoundSource source = this.managedSources.get(i); + for (int i = 0; i < managedSources.size; i++) { + final SoundSource source = managedSources.get(i); if (source != null) { source.setResamplerByIndex(resamplerIndex); } @@ -751,8 +751,8 @@ public boolean setDefaultResampler(String resampler) { * Resumes to play all {@link BufferedSoundSource}s and {@link StreamedSoundSource}s that are paused. */ public void resumeAll() { - this.resumeAllBufferedSources(); - this.resumeAllStreamedSources(); + resumeAllBufferedSources(); + resumeAllStreamedSources(); } @@ -760,7 +760,7 @@ public void resumeAll() { * Resumes to play all {@link StreamedSoundSource}s that are paused at the moment. */ public void resumeAllStreamedSources() { - this.streamManager.resumeAll(); + streamManager.resumeAll(); } @@ -768,7 +768,7 @@ public void resumeAllStreamedSources() { * Resumes to play all {@link BufferedSoundSource}s that are paused at the moment. */ public void resumeAllBufferedSources() { - this.sourcePool.resumeAll(); + sourcePool.resumeAll(); } @@ -776,8 +776,8 @@ public void resumeAllBufferedSources() { * Pauses all {@link BufferedSoundSource}s and {@link StreamedSoundSource}s. */ public void pauseAll() { - this.pauseAllBufferedSources(); - this.pauseAllStreamedSources(); + pauseAllBufferedSources(); + pauseAllStreamedSources(); } @@ -785,7 +785,7 @@ public void pauseAll() { * Pauses all {@link StreamedSoundSource}. */ public void pauseAllStreamedSources() { - this.streamManager.pauseAll(); + streamManager.pauseAll(); } @@ -793,7 +793,7 @@ public void pauseAllStreamedSources() { * Pauses all {@link BufferedSoundSource}s. */ public void pauseAllBufferedSources() { - this.sourcePool.pauseAll(); + sourcePool.pauseAll(); } @@ -801,8 +801,8 @@ public void pauseAllBufferedSources() { * Stops all {@link BufferedSoundSource}s and {@link StreamedSoundSource}s. */ public void stopAll() { - this.stopAllBufferedSources(); - this.stopAllStreamedSources(); + stopAllBufferedSources(); + stopAllStreamedSources(); } @@ -810,7 +810,7 @@ public void stopAll() { * Stops all {@link StreamedSoundSource}s. */ public void stopAllStreamedSources() { - this.streamManager.stopAll(); + streamManager.stopAll(); } @@ -818,22 +818,22 @@ public void stopAllStreamedSources() { * Stops all {@link BufferedSoundSource}s. */ public void stopAllBufferedSources() { - this.sourcePool.stopAll(); + sourcePool.stopAll(); } int getDefaultResamplerIndex() { - return this.defaultSettings.getResamplerIndex(); + return defaultSettings.getResamplerIndex(); } void registerManagedSource(SoundSource source) { - this.managedSources.add(source); + managedSources.add(source); } void removeManagedSource(SoundSource source) { - this.managedSources.removeValue(source, true); + managedSources.removeValue(source, true); } @@ -843,7 +843,7 @@ void removeManagedSource(SoundSource source) { * @return the {@link SoundListener} */ public SoundListener getListener() { - return this.listener; + return listener; } @@ -869,17 +869,17 @@ public void registerAssetManagerLoaders(AssetManager manager) { * @return the resampler provider */ public WavDecoderProvider getWavDecoderProvider() { - return this.wavDecoderProvider; + return wavDecoderProvider; } void onBufferDisposal(SoundBuffer buffer) { - this.sourcePool.onBufferDisposal(buffer); + sourcePool.onBufferDisposal(buffer); } public TuningForkLogger getLogger() { - return this.logger; + return logger; } @@ -889,7 +889,7 @@ public TuningForkLogger getLogger() { * @return native decoders available */ public boolean isNativeDecodersAvailable() { - return this.nativeDecoderAvailable; + return nativeDecoderAvailable; } @@ -898,13 +898,13 @@ public boolean isNativeDecodersAvailable() { */ @Override public void dispose() { - this.publicFilter.dispose(); - this.streamManager.dispose(); - this.stopAllBufferedSources(); - this.sourcePool.dispose(); + publicFilter.dispose(); + streamManager.dispose(); + stopAllBufferedSources(); + sourcePool.dispose(); // DISPOSE DEVICE LAST - this.device.dispose(true); + device.dispose(true); Audio.instance = null; } diff --git a/core/src/main/java/de/pottgames/tuningfork/AudioConfig.java b/core/src/main/java/de/pottgames/tuningfork/AudioConfig.java index e2cc10a..f40d014 100644 --- a/core/src/main/java/de/pottgames/tuningfork/AudioConfig.java +++ b/core/src/main/java/de/pottgames/tuningfork/AudioConfig.java @@ -90,19 +90,19 @@ public AudioConfig(AudioDeviceConfig deviceConfig, DistanceAttenuationModel dist */ public AudioConfig(AudioDeviceConfig deviceConfig, DistanceAttenuationModel distanceAttenuationModel, int simultaneousSources, int idleTasks, Virtualization virtualization, TuningForkLogger logger) { - this.setDeviceConfig(deviceConfig); - this.setDistanceAttenuationModel(distanceAttenuationModel); - this.setSimultaneousSources(simultaneousSources); - this.setIdleTasks(idleTasks); - this.setLogger(logger); - this.setVirtualization(virtualization); - this.setSpatialization(Spatialization.ON); - this.setWavDecoderProvider(new DefaultWavDecoderProvider()); + setDeviceConfig(deviceConfig); + setDistanceAttenuationModel(distanceAttenuationModel); + setSimultaneousSources(simultaneousSources); + setIdleTasks(idleTasks); + setLogger(logger); + setVirtualization(virtualization); + setSpatialization(Spatialization.ON); + setWavDecoderProvider(new DefaultWavDecoderProvider()); } public AudioDeviceConfig getDeviceConfig() { - return this.deviceConfig; + return deviceConfig; } @@ -123,7 +123,7 @@ public AudioConfig setDeviceConfig(AudioDeviceConfig deviceConfig) { public DistanceAttenuationModel getDistanceAttenuationModel() { - return this.distanceAttenuationModel; + return distanceAttenuationModel; } @@ -144,7 +144,7 @@ public AudioConfig setDistanceAttenuationModel(DistanceAttenuationModel distance public int getSimultaneousSources() { - return this.simultaneousSources; + return simultaneousSources; } @@ -165,7 +165,7 @@ public AudioConfig setSimultaneousSources(int simultaneousSources) { public int getIdleTasks() { - return this.idleTasks; + return idleTasks; } @@ -186,7 +186,7 @@ public AudioConfig setIdleTasks(int idleTasks) { public Spatialization getSpatialization() { - return this.spatialization; + return spatialization; } @@ -205,7 +205,7 @@ public AudioConfig setSpatialization(Spatialization spatialization) { public AssetManager getAssetManager() { - return this.assetManager; + return assetManager; } @@ -225,7 +225,7 @@ public AudioConfig setAssetManager(AssetManager assetManager) { public Virtualization getVirtualization() { - return this.virtualization; + return virtualization; } @@ -252,7 +252,7 @@ public AudioConfig setVirtualization(Virtualization virtualization) { * @return this */ public boolean useNativeDecoders() { - return this.useNativeDecoders; + return useNativeDecoders; } @@ -264,13 +264,13 @@ public boolean useNativeDecoders() { * @return this */ public AudioConfig setUseNativeDecoders(boolean value) { - this.useNativeDecoders = value; + useNativeDecoders = value; return this; } public TuningForkLogger getLogger() { - return this.logger; + return logger; } @@ -292,7 +292,7 @@ public AudioConfig setLogger(TuningForkLogger logger) { public WavDecoderProvider getResamplerProvider() { - return this.wavDecoderProvider; + return wavDecoderProvider; } @@ -305,7 +305,7 @@ public WavDecoderProvider getResamplerProvider() { */ public AudioConfig setWavDecoderProvider(WavDecoderProvider decoderProvider) { Objects.requireNonNull(decoderProvider); - this.wavDecoderProvider = decoderProvider; + wavDecoderProvider = decoderProvider; return this; } @@ -337,7 +337,7 @@ public enum Spatialization { int getAlId() { - return this.alId; + return alId; } @@ -395,7 +395,7 @@ public enum Virtualization { int getAlId() { - return this.alId; + return alId; } diff --git a/core/src/main/java/de/pottgames/tuningfork/AudioDevice.java b/core/src/main/java/de/pottgames/tuningfork/AudioDevice.java index 9748461..76e27c2 100644 --- a/core/src/main/java/de/pottgames/tuningfork/AudioDevice.java +++ b/core/src/main/java/de/pottgames/tuningfork/AudioDevice.java @@ -81,7 +81,7 @@ public static List availableDevices() { protected AudioDevice(AudioDeviceConfig config, TuningForkLogger logger) throws OpenDeviceException, UnsupportedAudioDeviceException { this.config = config; this.logger = logger; - this.errorLogger = new ErrorLogger(this.getClass(), logger); + errorLogger = new ErrorLogger(this.getClass(), logger); if (config == null) { throw new TuningForkRuntimeException("AudioDeviceConfig is null"); @@ -101,8 +101,8 @@ protected AudioDevice(AudioDeviceConfig config, TuningForkLogger logger) throws } // OPEN THE SOUND DEVICE - this.deviceHandle = ALC10.alcOpenDevice(deviceSpecifier); - if (this.deviceHandle == 0L) { + deviceHandle = ALC10.alcOpenDevice(deviceSpecifier); + if (deviceHandle == 0L) { throw new OpenDeviceException("Failed to open the " + deviceName + " OpenAL device."); } @@ -114,77 +114,77 @@ protected AudioDevice(AudioDeviceConfig config, TuningForkLogger logger) throws attributes[3] = config.isEnableOutputLimiter() ? ALC10.ALC_TRUE : ALC10.ALC_FALSE; attributes[4] = SOFTOutputMode.ALC_OUTPUT_MODE_SOFT; attributes[5] = config.outputMode.getAlId(); - this.contextAttributes = new ContextAttributes(attributes); - final ALCCapabilities deviceCapabilities = ALC.createCapabilities(this.deviceHandle); - this.context = ALC10.alcCreateContext(this.deviceHandle, this.contextAttributes.getBuffer()); - if (this.context == 0L) { + contextAttributes = new ContextAttributes(attributes); + final ALCCapabilities deviceCapabilities = ALC.createCapabilities(deviceHandle); + context = ALC10.alcCreateContext(deviceHandle, contextAttributes.getBuffer()); + if (context == 0L) { throw new IllegalStateException("Failed to create OpenAL context."); } - ALC10.alcMakeContextCurrent(this.context); + ALC10.alcMakeContextCurrent(context); AL.createCapabilities(deviceCapabilities); // CHECK OPENAL API SUPPORT - this.checkAL10Support(logger, deviceName, deviceCapabilities); - this.checkAL11Support(logger, deviceName, deviceCapabilities); + checkAL10Support(logger, deviceName, deviceCapabilities); + checkAL11Support(logger, deviceName, deviceCapabilities); // CHECK IF EXTENSIONS ARE PRESENT - this.checkAvailableExtensions(); - this.checkRequiredExtension(ALExtension.ALC_EXT_EFX); - this.checkRequiredExtension(ALExtension.AL_SOFT_DIRECT_CHANNELS); - this.checkRequiredExtension(ALExtension.AL_EXT_MCFORMATS); - this.checkRequiredExtension(ALExtension.AL_SOFTX_HOLD_ON_DISCONNECT); - this.checkRequiredExtension(ALExtension.ALC_SOFT_REOPEN_DEVICE); - this.checkRequiredExtension(ALExtension.ALC_ENUMERATE_ALL_EXT); - this.checkRequiredExtension(ALExtension.AL_SOFT_EVENTS); - this.checkRequiredExtension(ALExtension.AL_SOFT_DIRECT_CHANNELS_REMIX); - this.checkRequiredExtension(ALExtension.AL_SOFT_LOOP_POINTS); - this.checkRequiredExtension(ALExtension.ALC_SOFT_DEVICE_CLOCK); - this.checkRequiredExtension(ALExtension.AL_SOFT_SOURCE_SPATIALIZE); - this.checkRequiredExtension(ALExtension.ALC_SOFT_OUTPUT_MODE); - this.checkRequiredExtension(ALExtension.AL_EXT_SOURCE_RADIUS); - this.checkRequiredExtension(ALExtension.AL_SOFT_BUFFER_LENGTH_QUERY); - this.checkRequiredExtension(ALExtension.AL_SOFT_SOURCE_START_DELAY); + checkAvailableExtensions(); + checkRequiredExtension(ALExtension.ALC_EXT_EFX); + checkRequiredExtension(ALExtension.AL_SOFT_DIRECT_CHANNELS); + checkRequiredExtension(ALExtension.AL_EXT_MCFORMATS); + checkRequiredExtension(ALExtension.AL_SOFTX_HOLD_ON_DISCONNECT); + checkRequiredExtension(ALExtension.ALC_SOFT_REOPEN_DEVICE); + checkRequiredExtension(ALExtension.ALC_ENUMERATE_ALL_EXT); + checkRequiredExtension(ALExtension.AL_SOFT_EVENTS); + checkRequiredExtension(ALExtension.AL_SOFT_DIRECT_CHANNELS_REMIX); + checkRequiredExtension(ALExtension.AL_SOFT_LOOP_POINTS); + checkRequiredExtension(ALExtension.ALC_SOFT_DEVICE_CLOCK); + checkRequiredExtension(ALExtension.AL_SOFT_SOURCE_SPATIALIZE); + checkRequiredExtension(ALExtension.ALC_SOFT_OUTPUT_MODE); + checkRequiredExtension(ALExtension.AL_EXT_SOURCE_RADIUS); + checkRequiredExtension(ALExtension.AL_SOFT_BUFFER_LENGTH_QUERY); + checkRequiredExtension(ALExtension.AL_SOFT_SOURCE_START_DELAY); // LOG OUTPUT LIMITER STATE if (config.isEnableOutputLimiter()) { final int[] outputLimiterEnabled = new int[1]; outputLimiterEnabled[0] = ALC10.ALC_FALSE; - if (this.isExtensionAvailable(ALExtension.ALC_SOFT_OUTPUT_LIMITER)) { - ALC10.alcGetIntegerv(this.deviceHandle, SOFTOutputLimiter.ALC_OUTPUT_LIMITER_SOFT, outputLimiterEnabled); + if (isExtensionAvailable(ALExtension.ALC_SOFT_OUTPUT_LIMITER)) { + ALC10.alcGetIntegerv(deviceHandle, SOFTOutputLimiter.ALC_OUTPUT_LIMITER_SOFT, outputLimiterEnabled); } logger.debug(this.getClass(), "Output limiter: " + (outputLimiterEnabled[0] == ALC10.ALC_TRUE ? "enabled" : "disabled")); } // CHECK AND LOG HRTF SETTINGS - if (this.isExtensionAvailable(ALExtension.ALC_SOFT_HRTF)) { - final int hrtfSoftStatus = ALC10.alcGetInteger(this.deviceHandle, SOFTHRTF.ALC_HRTF_STATUS_SOFT); + if (isExtensionAvailable(ALExtension.ALC_SOFT_HRTF)) { + final int hrtfSoftStatus = ALC10.alcGetInteger(deviceHandle, SOFTHRTF.ALC_HRTF_STATUS_SOFT); switch (hrtfSoftStatus) { case SOFTHRTF.ALC_HRTF_DISABLED_SOFT: - this.hrtfEnabled = false; + hrtfEnabled = false; logger.debug(this.getClass(), "HRTF status is: ALC_HRTF_DISABLED_SOFT"); break; case SOFTHRTF.ALC_HRTF_ENABLED_SOFT: - this.hrtfEnabled = true; + hrtfEnabled = true; logger.debug(this.getClass(), "HRTF status is: ALC_HRTF_ENABLED_SOFT"); break; case SOFTHRTF.ALC_HRTF_DENIED_SOFT: - this.hrtfEnabled = false; + hrtfEnabled = false; logger.debug(this.getClass(), "HRTF status is: ALC_HRTF_DENIED_SOFT"); break; case SOFTHRTF.ALC_HRTF_REQUIRED_SOFT: - this.hrtfEnabled = true; + hrtfEnabled = true; logger.debug(this.getClass(), "HRTF status is: ALC_HRTF_REQUIRED_SOFT"); break; case SOFTHRTF.ALC_HRTF_HEADPHONES_DETECTED_SOFT: - this.hrtfEnabled = true; + hrtfEnabled = true; logger.debug(this.getClass(), "HRTF status is: ALC_HRTF_HEADPHONES_DETECTED_SOFT"); break; case SOFTHRTF.ALC_HRTF_UNSUPPORTED_FORMAT_SOFT: - this.hrtfEnabled = false; + hrtfEnabled = false; logger.debug(this.getClass(), "HRTF status is: ALC_HRTF_UNSUPPORTED_FORMAT_SOFT"); break; default: - this.hrtfEnabled = false; + hrtfEnabled = false; logger.debug(this.getClass(), "HRTF status is unknown: " + hrtfSoftStatus + " - TuningFork will report it as disabled."); break; } @@ -192,16 +192,16 @@ protected AudioDevice(AudioDeviceConfig config, TuningForkLogger logger) throws // CHECK AVAILABLE AUXILIARY SENDS final IntBuffer auxSends = BufferUtils.newIntBuffer(1); - ALC10.alcGetIntegerv(this.deviceHandle, EXTEfx.ALC_MAX_AUXILIARY_SENDS, auxSends); - this.effectSlots = auxSends.get(0); - logger.debug(this.getClass(), "Available auxiliary sends: " + this.effectSlots); - if (this.effectSlots != config.getEffectSlots()) { + ALC10.alcGetIntegerv(deviceHandle, EXTEfx.ALC_MAX_AUXILIARY_SENDS, auxSends); + effectSlots = auxSends.get(0); + logger.debug(this.getClass(), "Available auxiliary sends: " + effectSlots); + if (effectSlots != config.getEffectSlots()) { logger.error(this.getClass(), "The audio device rejected the requested number of effect slots (" + config.getEffectSlots() + ")."); } // FINAL SETUP - this.getAvailableResamplers(); - this.setDeviceRerouter(config.getRerouter()); + getAvailableResamplers(); + setDeviceRerouter(config.getRerouter()); AL10.alDisable(SOFTXHoldOnDisconnect.AL_STOP_SOURCES_ON_DISCONNECT_SOFT); SOFTEvents.alEventControlSOFT(new int[] { SOFTEvents.AL_EVENT_TYPE_DISCONNECTED_SOFT }, true); SOFTEvents.alEventCallbackSOFT((eventType, object, param, length, message, userParam) -> { @@ -210,15 +210,15 @@ protected AudioDevice(AudioDeviceConfig config, TuningForkLogger logger) throws }, (ByteBuffer) null); // LOG ERRORS - this.errorLogger.checkLogAlcError(this.deviceHandle, "There was at least one ALC error upon audio device initialization"); - this.errorLogger.checkLogError("There was at least one AL error upon audio device initialization"); + errorLogger.checkLogAlcError(deviceHandle, "There was at least one ALC error upon audio device initialization"); + errorLogger.checkLogError("There was at least one AL error upon audio device initialization"); } private void checkAL11Support(TuningForkLogger logger, String deviceName, final ALCCapabilities deviceCapabilities) throws OpenDeviceException { if (!deviceCapabilities.OpenALC11) { try { - this.dispose(false); + dispose(false); } catch (final Exception e) { logger.error(this.getClass(), "The device was opened successfully, but didn't support a required feature. The attempt " + "to close the device failed."); @@ -232,7 +232,7 @@ private void checkAL11Support(TuningForkLogger logger, String deviceName, final private void checkAL10Support(TuningForkLogger logger, String deviceName, final ALCCapabilities deviceCapabilities) throws OpenDeviceException { if (!deviceCapabilities.OpenALC10) { try { - this.dispose(false); + dispose(false); } catch (final Exception e) { logger.error(this.getClass(), "The device was opened successfully, but didn't support a required feature. The attempt " + "to close the device failed."); @@ -244,34 +244,34 @@ private void checkAL10Support(TuningForkLogger logger, String deviceName, final private void checkRequiredExtension(ALExtension extension) throws OpenDeviceException { - final Boolean checkResult = this.extensionAvailableMap.get(extension); + final Boolean checkResult = extensionAvailableMap.get(extension); if (checkResult == null || !checkResult) { try { - this.dispose(false); + dispose(false); } catch (final Exception e) { - this.logger.error(this.getClass(), + logger.error(this.getClass(), "The device was opened successfully, but didn't support " + extension.getAlSpecifier() + ". The attempt to close the device failed."); } throw new OpenDeviceException("The audio device doesn't support " + extension.getAlSpecifier() + " which is a requirement of TuningFork."); } - this.logger.trace(this.getClass(), "Extension available: " + extension.getAlSpecifier()); + logger.trace(this.getClass(), "Extension available: " + extension.getAlSpecifier()); } private void checkAvailableExtensions() { for (final ALExtension extension : ALExtension.values()) { if (extension.isAlc()) { - this.extensionAvailableMap.put(extension, ALC10.alcIsExtensionPresent(this.deviceHandle, extension.getAlSpecifier())); + extensionAvailableMap.put(extension, ALC10.alcIsExtensionPresent(deviceHandle, extension.getAlSpecifier())); } else { - this.extensionAvailableMap.put(extension, AL10.alIsExtensionPresent(extension.getAlSpecifier())); + extensionAvailableMap.put(extension, AL10.alIsExtensionPresent(extension.getAlSpecifier())); } } } protected boolean isExtensionAvailable(ALExtension extension) { - final Boolean result = this.extensionAvailableMap.get(extension); + final Boolean result = extensionAvailableMap.get(extension); if (result == null) { return false; } @@ -289,10 +289,10 @@ protected boolean isExtensionAvailable(ALExtension extension) { * @return true if the device is connected, false otherwise */ public boolean isConnected() { - if (this.isExtensionAvailable(ALExtension.ALC_EXT_DISCONNECT)) { + if (isExtensionAvailable(ALExtension.ALC_EXT_DISCONNECT)) { try (MemoryStack stack = MemoryStack.stackPush()) { final IntBuffer resultBuffer = stack.mallocInt(1); - ALC10.alcGetIntegerv(this.deviceHandle, EXTDisconnect.ALC_CONNECTED, resultBuffer); + ALC10.alcGetIntegerv(deviceHandle, EXTDisconnect.ALC_CONNECTED, resultBuffer); return resultBuffer.get(0) == ALC10.ALC_TRUE; } } @@ -310,9 +310,9 @@ public boolean isConnected() { * @return true if successful */ public boolean switchToDevice(String deviceSpecifier) { - final boolean success = SOFTReopenDevice.alcReopenDeviceSOFT(this.deviceHandle, deviceSpecifier, this.contextAttributes.getBuffer()); - if (success && this.deviceRerouter != null) { - this.deviceRerouter.updateDesiredDevice(deviceSpecifier); + final boolean success = SOFTReopenDevice.alcReopenDeviceSOFT(deviceHandle, deviceSpecifier, contextAttributes.getBuffer()); + if (success && deviceRerouter != null) { + deviceRerouter.updateDesiredDevice(deviceSpecifier); } return success; } @@ -325,12 +325,12 @@ public boolean switchToDevice(String deviceSpecifier) { * @param rerouter the rerouter */ public void setDeviceRerouter(AudioDeviceRerouter rerouter) { - if (this.deviceRerouter != null) { - this.deviceRerouter.dispose(); + if (deviceRerouter != null) { + deviceRerouter.dispose(); } - this.deviceRerouter = rerouter; + deviceRerouter = rerouter; if (rerouter != null) { - rerouter.setup(this.deviceHandle, this.config.deviceSpecifier, this.contextAttributes); + rerouter.setup(deviceHandle, config.deviceSpecifier, contextAttributes); rerouter.start(); } } @@ -342,7 +342,7 @@ public void setDeviceRerouter(AudioDeviceRerouter rerouter) { * @return the device rerouter */ public AudioDeviceRerouter getDeviceRerouter() { - return this.deviceRerouter; + return deviceRerouter; } @@ -352,7 +352,7 @@ public AudioDeviceRerouter getDeviceRerouter() { * @return the output mode */ public OutputMode getOutputMode() { - final int alId = ALC10.alcGetInteger(this.deviceHandle, SOFTOutputMode.ALC_OUTPUT_MODE_SOFT); + final int alId = ALC10.alcGetInteger(deviceHandle, SOFTOutputMode.ALC_OUTPUT_MODE_SOFT); return OutputMode.getByAlId(alId); } @@ -364,7 +364,7 @@ public OutputMode getOutputMode() { * @return true if supported */ public boolean isHrtfSupported() { - return this.isExtensionAvailable(ALExtension.ALC_SOFT_HRTF); + return isExtensionAvailable(ALExtension.ALC_SOFT_HRTF); } @@ -374,7 +374,7 @@ public boolean isHrtfSupported() { * @return true if enabled */ public boolean isHrtfEnabled() { - return this.hrtfEnabled; + return hrtfEnabled; } @@ -386,10 +386,10 @@ public boolean isHrtfEnabled() { public Array getAvailableHrtfs() { final Array hrtfs = new Array<>(); - if (this.isHrtfSupported()) { - final int num_hrtf = ALC10.alcGetInteger(this.deviceHandle, SOFTHRTF.ALC_NUM_HRTF_SPECIFIERS_SOFT); + if (isHrtfSupported()) { + final int num_hrtf = ALC10.alcGetInteger(deviceHandle, SOFTHRTF.ALC_NUM_HRTF_SPECIFIERS_SOFT); for (int i = 0; i < num_hrtf; i++) { - final String name = Objects.requireNonNull(SOFTHRTF.alcGetStringiSOFT(this.deviceHandle, SOFTHRTF.ALC_HRTF_SPECIFIER_SOFT, i)); + final String name = Objects.requireNonNull(SOFTHRTF.alcGetStringiSOFT(deviceHandle, SOFTHRTF.ALC_HRTF_SPECIFIER_SOFT, i)); hrtfs.add(name); } } @@ -406,13 +406,13 @@ public Array getAvailableHrtfs() { * @return true on success, false on failure */ public boolean enableHrtf(String specifier) { - if (this.isHrtfSupported()) { - final int num_hrtf = ALC10.alcGetInteger(this.deviceHandle, SOFTHRTF.ALC_NUM_HRTF_SPECIFIERS_SOFT); + if (isHrtfSupported()) { + final int num_hrtf = ALC10.alcGetInteger(deviceHandle, SOFTHRTF.ALC_NUM_HRTF_SPECIFIERS_SOFT); // FIND HRTF INDEX BY SPECIFIER int hrtfIndex = -1; for (int i = 0; i < num_hrtf; i++) { - final String name = Objects.requireNonNull(SOFTHRTF.alcGetStringiSOFT(this.deviceHandle, SOFTHRTF.ALC_HRTF_SPECIFIER_SOFT, i)); + final String name = Objects.requireNonNull(SOFTHRTF.alcGetStringiSOFT(deviceHandle, SOFTHRTF.ALC_HRTF_SPECIFIER_SOFT, i)); if (name.equals(specifier)) { hrtfIndex = i; break; @@ -421,47 +421,46 @@ public boolean enableHrtf(String specifier) { if (hrtfIndex >= 0) { // SET NEW DEVICE ATTRIBUTES - final ContextAttributes oldAttributes = this.contextAttributes; + final ContextAttributes oldAttributes = contextAttributes; final int[] attributes = new int[10]; attributes[0] = SOFTHRTF.ALC_HRTF_SOFT; attributes[1] = ALC10.ALC_TRUE; attributes[2] = SOFTHRTF.ALC_HRTF_ID_SOFT; attributes[3] = hrtfIndex; attributes[4] = EXTEfx.ALC_MAX_AUXILIARY_SENDS; - attributes[5] = this.config.getEffectSlots(); + attributes[5] = config.getEffectSlots(); attributes[6] = SOFTOutputLimiter.ALC_OUTPUT_LIMITER_SOFT; - attributes[7] = this.config.isEnableOutputLimiter() ? ALC10.ALC_TRUE : ALC10.ALC_FALSE; + attributes[7] = config.isEnableOutputLimiter() ? ALC10.ALC_TRUE : ALC10.ALC_FALSE; attributes[8] = SOFTOutputMode.ALC_OUTPUT_MODE_SOFT; - attributes[9] = this.config.getOutputMode().getAlId(); - this.contextAttributes = new ContextAttributes(attributes); + attributes[9] = config.getOutputMode().getAlId(); + contextAttributes = new ContextAttributes(attributes); // RESET DEVICE - if (!SOFTHRTF.alcResetDeviceSOFT(this.deviceHandle, this.contextAttributes.getBuffer())) { - this.logger.error(this.getClass(), - "Failed to reset device: " + ALC10.alcGetString(this.deviceHandle, ALC10.alcGetError(this.deviceHandle))); - this.hrtfEnabled = false; - this.contextAttributes = oldAttributes; + if (!SOFTHRTF.alcResetDeviceSOFT(deviceHandle, contextAttributes.getBuffer())) { + logger.error(this.getClass(), "Failed to reset device: " + ALC10.alcGetString(deviceHandle, ALC10.alcGetError(deviceHandle))); + hrtfEnabled = false; + contextAttributes = oldAttributes; return false; } // NOTIFY REROUTER ABOUT CONTEXT ATTRIBUTES CHANGE - if (this.deviceRerouter != null) { - this.deviceRerouter.updateContextAttributes(this.contextAttributes); + if (deviceRerouter != null) { + deviceRerouter.updateContextAttributes(contextAttributes); } // CHECK CURRENT HRTF STATE - final int hrtfState = ALC10.alcGetInteger(this.deviceHandle, SOFTHRTF.ALC_HRTF_SOFT); + final int hrtfState = ALC10.alcGetInteger(deviceHandle, SOFTHRTF.ALC_HRTF_SOFT); if (hrtfState != 0) { - final String name = ALC10.alcGetString(this.deviceHandle, SOFTHRTF.ALC_HRTF_SPECIFIER_SOFT); - this.logger.info(this.getClass(), "Using HRTF configuration: " + name); - this.hrtfEnabled = true; + final String name = ALC10.alcGetString(deviceHandle, SOFTHRTF.ALC_HRTF_SPECIFIER_SOFT); + logger.info(this.getClass(), "Using HRTF configuration: " + name); + hrtfEnabled = true; return true; } } } - this.logger.error(this.getClass(), "HRTF is not enabled, reason: unknown"); - this.hrtfEnabled = false; + logger.error(this.getClass(), "HRTF is not enabled, reason: unknown"); + hrtfEnabled = false; return false; } @@ -470,35 +469,35 @@ public boolean enableHrtf(String specifier) { * Disables hrtf on this device. */ public void disableHrtf() { - if (!this.isHrtfSupported()) { - this.logger.warn(this.getClass(), "HRTF is not supported by this device and was never enabled."); + if (!isHrtfSupported()) { + logger.warn(this.getClass(), "HRTF is not supported by this device and was never enabled."); return; } - if (this.isHrtfSupported()) { + if (isHrtfSupported()) { // SET NEW DEVICE ATTRIBUTES - final ContextAttributes oldAttributes = this.contextAttributes; + final ContextAttributes oldAttributes = contextAttributes; final int[] attributes = new int[8]; attributes[0] = SOFTHRTF.ALC_HRTF_SOFT; attributes[1] = ALC10.ALC_FALSE; attributes[2] = EXTEfx.ALC_MAX_AUXILIARY_SENDS; - attributes[3] = this.config.getEffectSlots(); + attributes[3] = config.getEffectSlots(); attributes[4] = SOFTOutputLimiter.ALC_OUTPUT_LIMITER_SOFT; - attributes[5] = this.config.isEnableOutputLimiter() ? ALC10.ALC_TRUE : ALC10.ALC_FALSE; + attributes[5] = config.isEnableOutputLimiter() ? ALC10.ALC_TRUE : ALC10.ALC_FALSE; attributes[6] = SOFTOutputMode.ALC_OUTPUT_MODE_SOFT; - attributes[7] = this.config.getOutputMode().getAlId(); - this.contextAttributes = new ContextAttributes(attributes); + attributes[7] = config.getOutputMode().getAlId(); + contextAttributes = new ContextAttributes(attributes); // RESET DEVICE - if (!SOFTHRTF.alcResetDeviceSOFT(this.deviceHandle, this.contextAttributes.getBuffer())) { - this.contextAttributes = oldAttributes; - this.logger.error(this.getClass(), "Failed to reset device: " + ALC10.alcGetString(this.deviceHandle, ALC10.alcGetError(this.deviceHandle))); + if (!SOFTHRTF.alcResetDeviceSOFT(deviceHandle, contextAttributes.getBuffer())) { + contextAttributes = oldAttributes; + logger.error(this.getClass(), "Failed to reset device: " + ALC10.alcGetString(deviceHandle, ALC10.alcGetError(deviceHandle))); return; } - this.hrtfEnabled = false; - this.logger.info(this.getClass(), "HRTF disabled."); - if (this.deviceRerouter != null) { - this.deviceRerouter.updateContextAttributes(this.contextAttributes); + hrtfEnabled = false; + logger.info(this.getClass(), "HRTF disabled."); + if (deviceRerouter != null) { + deviceRerouter.updateContextAttributes(contextAttributes); } } } @@ -515,15 +514,15 @@ public void disableHrtf() { * @return list of available resamplers */ public Array getAvailableResamplers() { - this.resamplers.clear(); + resamplers.clear(); final int numberOfResamplers = AL10.alGetInteger(SOFTSourceResampler.AL_NUM_RESAMPLERS_SOFT); for (int index = 0; index < numberOfResamplers; index++) { final String resamplerName = SOFTSourceResampler.alGetStringiSOFT(SOFTSourceResampler.AL_RESAMPLER_NAME_SOFT, index); - this.resamplers.add(resamplerName); + resamplers.add(resamplerName); } - return new Array<>(this.resamplers); + return new Array<>(resamplers); } @@ -533,7 +532,7 @@ public Array getAvailableResamplers() { * @return the number of effect slots available for each source */ public int getNumberOfEffectSlots() { - return this.effectSlots; + return effectSlots; } @@ -545,7 +544,7 @@ public int getNumberOfEffectSlots() { * @return the index of the first occurrence of the value in the array or -1 if no such value exists */ protected int getResamplerIndexByName(String name) { - return this.resamplers.indexOf(name, false); + return resamplers.indexOf(name, false); } @@ -565,7 +564,7 @@ protected int getDefaultResamplerIndex() { * @return name of the default resampler */ public String getDefaultResampler() { - return this.getResamplerNameByIndex(this.getDefaultResamplerIndex()); + return getResamplerNameByIndex(getDefaultResamplerIndex()); } @@ -577,7 +576,7 @@ public String getDefaultResampler() { */ public long getClockTime() { // no error check here because this should be as fast as possible - return SOFTDeviceClock.alcGetInteger64vSOFT(this.deviceHandle, SOFTDeviceClock.ALC_DEVICE_CLOCK_SOFT); + return SOFTDeviceClock.alcGetInteger64vSOFT(deviceHandle, SOFTDeviceClock.ALC_DEVICE_CLOCK_SOFT); } @@ -588,8 +587,8 @@ public long getClockTime() { * @return latency in nanoseconds */ public long getLatency() { - final long result = SOFTDeviceClock.alcGetInteger64vSOFT(this.deviceHandle, SOFTDeviceClock.ALC_DEVICE_LATENCY_SOFT); - this.errorLogger.checkLogAlcError(this.deviceHandle, "Error while fetching alc device latency"); + final long result = SOFTDeviceClock.alcGetInteger64vSOFT(deviceHandle, SOFTDeviceClock.ALC_DEVICE_LATENCY_SOFT); + errorLogger.checkLogAlcError(deviceHandle, "Error while fetching alc device latency"); return result; } @@ -604,12 +603,12 @@ public long getLatency() { public long[] getClockTimeAndLatency() { try (MemoryStack stack = MemoryStack.stackPush()) { final LongBuffer buffer = stack.mallocLong(2); - SOFTDeviceClock.alcGetInteger64vSOFT(this.deviceHandle, SOFTDeviceClock.ALC_DEVICE_CLOCK_LATENCY_SOFT, buffer); - this.clockLatencyCache[0] = buffer.get(0); - this.clockLatencyCache[1] = buffer.get(1); + SOFTDeviceClock.alcGetInteger64vSOFT(deviceHandle, SOFTDeviceClock.ALC_DEVICE_CLOCK_LATENCY_SOFT, buffer); + clockLatencyCache[0] = buffer.get(0); + clockLatencyCache[1] = buffer.get(1); } - return this.clockLatencyCache; + return clockLatencyCache; } @@ -626,21 +625,21 @@ protected void onAlEvent(AlEvent event) { protected void onDisconnect() { - if (this.deviceRerouter != null) { - this.deviceRerouter.onDisconnect(); + if (deviceRerouter != null) { + deviceRerouter.onDisconnect(); } } protected void dispose(boolean log) { - if (this.deviceRerouter != null) { - this.deviceRerouter.dispose(); + if (deviceRerouter != null) { + deviceRerouter.dispose(); } - if (this.context != 0L) { - ALC10.alcDestroyContext(this.context); + if (context != 0L) { + ALC10.alcDestroyContext(context); } - if (this.deviceHandle != 0L && !ALC10.alcCloseDevice(this.deviceHandle) && log) { - this.logger.error(this.getClass(), "The audio device did not close properly."); + if (deviceHandle != 0L && !ALC10.alcCloseDevice(deviceHandle) && log) { + logger.error(this.getClass(), "The audio device did not close properly."); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/AudioDeviceConfig.java b/core/src/main/java/de/pottgames/tuningfork/AudioDeviceConfig.java index c408a9b..eda743f 100644 --- a/core/src/main/java/de/pottgames/tuningfork/AudioDeviceConfig.java +++ b/core/src/main/java/de/pottgames/tuningfork/AudioDeviceConfig.java @@ -49,7 +49,7 @@ public class AudioDeviceConfig { public String getDeviceSpecifier() { - return this.deviceSpecifier; + return deviceSpecifier; } @@ -67,7 +67,7 @@ public AudioDeviceConfig setDeviceSpecifier(String deviceSpecifier) { public boolean isEnableOutputLimiter() { - return this.enableOutputLimiter; + return enableOutputLimiter; } @@ -85,7 +85,7 @@ public AudioDeviceConfig setEnableOutputLimiter(boolean enableOutputLimiter) { public int getEffectSlots() { - return this.effectSlots; + return effectSlots; } @@ -105,7 +105,7 @@ public AudioDeviceConfig setEffectSlots(int effectSlots) { public AudioDeviceRerouter getRerouter() { - return this.rerouter; + return rerouter; } @@ -125,7 +125,7 @@ public AudioDeviceConfig setRerouter(AudioDeviceRerouter rerouter) { public OutputMode getOutputMode() { - return this.outputMode; + return outputMode; } @@ -144,7 +144,7 @@ public AudioDeviceConfig setOutputMode(OutputMode mode) { if (mode == null) { mode = OutputMode.ANY; } - this.outputMode = mode; + outputMode = mode; return this; } diff --git a/core/src/main/java/de/pottgames/tuningfork/AudioSettings.java b/core/src/main/java/de/pottgames/tuningfork/AudioSettings.java index f2150a7..4ecc17e 100644 --- a/core/src/main/java/de/pottgames/tuningfork/AudioSettings.java +++ b/core/src/main/java/de/pottgames/tuningfork/AudioSettings.java @@ -25,32 +25,32 @@ class AudioSettings { public float getMinAttenuationDistance() { - return this.minAttenuationDistance; + return minAttenuationDistance; } public float getMaxAttenuationDistance() { - return this.maxAttenuationDistance; + return maxAttenuationDistance; } public float getAttenuationFactor() { - return this.attenuationFactor; + return attenuationFactor; } public Virtualization getVirtualization() { - return this.virtualization; + return virtualization; } public Spatialization getSpatialization() { - return this.spatialization; + return spatialization; } public int getResamplerIndex() { - return this.resamplerIndex; + return resamplerIndex; } diff --git a/core/src/main/java/de/pottgames/tuningfork/AutoWah.java b/core/src/main/java/de/pottgames/tuningfork/AutoWah.java index 5e4218a..2eaa6c1 100644 --- a/core/src/main/java/de/pottgames/tuningfork/AutoWah.java +++ b/core/src/main/java/de/pottgames/tuningfork/AutoWah.java @@ -105,16 +105,16 @@ public static AutoWah windyNights() { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_AUTOWAH); - EXTEfx.alEffectf(effectId, EXTEfx.AL_AUTOWAH_ATTACK_TIME, this.attackTime); - EXTEfx.alEffectf(effectId, EXTEfx.AL_AUTOWAH_RELEASE_TIME, this.releaseTime); - EXTEfx.alEffectf(effectId, EXTEfx.AL_AUTOWAH_RESONANCE, this.resonance); - EXTEfx.alEffectf(effectId, EXTEfx.AL_AUTOWAH_PEAK_GAIN, this.peakGain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_AUTOWAH_ATTACK_TIME, attackTime); + EXTEfx.alEffectf(effectId, EXTEfx.AL_AUTOWAH_RELEASE_TIME, releaseTime); + EXTEfx.alEffectf(effectId, EXTEfx.AL_AUTOWAH_RESONANCE, resonance); + EXTEfx.alEffectf(effectId, EXTEfx.AL_AUTOWAH_PEAK_GAIN, peakGain); } @Override public int hashCode() { - return Objects.hash(this.attackTime, this.peakGain, this.releaseTime, this.resonance); + return Objects.hash(attackTime, peakGain, releaseTime, resonance); } @@ -130,17 +130,16 @@ public boolean equals(Object obj) { return false; } final AutoWah other = (AutoWah) obj; - return Float.floatToIntBits(this.attackTime) == Float.floatToIntBits(other.attackTime) - && Float.floatToIntBits(this.peakGain) == Float.floatToIntBits(other.peakGain) - && Float.floatToIntBits(this.releaseTime) == Float.floatToIntBits(other.releaseTime) - && Float.floatToIntBits(this.resonance) == Float.floatToIntBits(other.resonance); + return Float.floatToIntBits(attackTime) == Float.floatToIntBits(other.attackTime) + && Float.floatToIntBits(peakGain) == Float.floatToIntBits(other.peakGain) + && Float.floatToIntBits(releaseTime) == Float.floatToIntBits(other.releaseTime) + && Float.floatToIntBits(resonance) == Float.floatToIntBits(other.resonance); } @Override public String toString() { - return "AutoWah [attackTime=" + this.attackTime + ", releaseTime=" + this.releaseTime + ", resonance=" + this.resonance + ", peakGain=" + this.peakGain - + "]"; + return "AutoWah [attackTime=" + attackTime + ", releaseTime=" + releaseTime + ", resonance=" + resonance + ", peakGain=" + peakGain + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/BufferedSoundSource.java b/core/src/main/java/de/pottgames/tuningfork/BufferedSoundSource.java index 3fc6dc1..9903b62 100644 --- a/core/src/main/java/de/pottgames/tuningfork/BufferedSoundSource.java +++ b/core/src/main/java/de/pottgames/tuningfork/BufferedSoundSource.java @@ -37,14 +37,14 @@ public class BufferedSoundSource extends SongSource { BufferedSoundSource() { final Audio audio = Audio.get(); - this.logger = audio.getLogger(); - this.errorLogger = new ErrorLogger(this.getClass(), this.logger); + logger = audio.getLogger(); + errorLogger = new ErrorLogger(this.getClass(), logger); } @Override public void setVolume(float volume) { - if (this.obtained) { + if (obtained) { super.setVolume(volume); } } @@ -52,7 +52,7 @@ public void setVolume(float volume) { @Override public void setPitch(float pitch) { - if (this.obtained) { + if (obtained) { super.setPitch(pitch); } } @@ -60,7 +60,7 @@ public void setPitch(float pitch) { @Override public void play() { - if (this.obtained) { + if (obtained) { super.play(); } } @@ -75,27 +75,27 @@ public void play() { */ public void playAtTime(long time) { if (time < 0) { - this.logger.error(this.getClass(), "Invalid time parameter: " + time); + logger.error(this.getClass(), "Invalid time parameter: " + time); return; } - if (this.obtained) { - SOFTSourceStartDelay.alSourcePlayAtTimeSOFT(this.sourceId, time); + if (obtained) { + SOFTSourceStartDelay.alSourcePlayAtTimeSOFT(sourceId, time); } } void setBuffer(SoundBuffer buffer) { - if (this.obtained) { + if (obtained) { this.buffer = buffer; - AL10.alSourcei(this.sourceId, AL10.AL_BUFFER, buffer != null ? buffer.getBufferId() : 0); + AL10.alSourcei(sourceId, AL10.AL_BUFFER, buffer != null ? buffer.getBufferId() : 0); } } @Override public void setRelative(boolean relative) { - if (this.obtained) { + if (obtained) { super.setRelative(relative); } } @@ -103,7 +103,7 @@ public void setRelative(boolean relative) { @Override public void setPosition(float x, float y, float z) { - if (this.obtained) { + if (obtained) { super.setPosition(x, y, z); } } @@ -111,7 +111,7 @@ public void setPosition(float x, float y, float z) { @Override public void enableAttenuation() { - if (this.obtained) { + if (obtained) { super.enableAttenuation(); } } @@ -119,7 +119,7 @@ public void enableAttenuation() { @Override public void disableAttenuation() { - if (this.obtained) { + if (obtained) { super.disableAttenuation(); } } @@ -127,7 +127,7 @@ public void disableAttenuation() { @Override public void setAttenuationFactor(float rolloff) { - if (this.obtained) { + if (obtained) { super.setAttenuationFactor(rolloff); } } @@ -135,7 +135,7 @@ public void setAttenuationFactor(float rolloff) { @Override public void setAttenuationMinDistance(float minDistance) { - if (this.obtained) { + if (obtained) { super.setAttenuationMinDistance(minDistance); } } @@ -143,7 +143,7 @@ public void setAttenuationMinDistance(float minDistance) { @Override public void setAttenuationMaxDistance(float maxDistance) { - if (this.obtained) { + if (obtained) { super.setAttenuationMaxDistance(maxDistance); } } @@ -151,7 +151,7 @@ public void setAttenuationMaxDistance(float maxDistance) { @Override public void makeDirectional(Vector3 direction, float coneInnerAngle, float coneOuterAngle, float outOfConeVolume) { - if (this.obtained) { + if (obtained) { super.makeDirectional(direction, coneInnerAngle, coneOuterAngle, outOfConeVolume); } } @@ -159,7 +159,7 @@ public void makeDirectional(Vector3 direction, float coneInnerAngle, float coneO @Override public void setDirection(Vector3 direction) { - if (this.obtained) { + if (obtained) { super.setDirection(direction); } } @@ -167,7 +167,7 @@ public void setDirection(Vector3 direction) { @Override public void makeOmniDirectional() { - if (this.obtained) { + if (obtained) { super.makeOmniDirectional(); } } @@ -175,7 +175,7 @@ public void makeOmniDirectional() { @Override public void setSpeed(float x, float y, float z) { - if (this.obtained) { + if (obtained) { super.setSpeed(x, y, z); } } @@ -183,7 +183,7 @@ public void setSpeed(float x, float y, float z) { @Override public void setLooping(boolean looping) { - if (this.obtained) { + if (obtained) { super.setLooping(looping); } } @@ -191,7 +191,7 @@ public void setLooping(boolean looping) { @Override public void pause() { - if (this.obtained) { + if (obtained) { super.pause(); } } @@ -199,7 +199,7 @@ public void pause() { @Override public void stop() { - if (this.obtained) { + if (obtained) { super.stop(); } } @@ -213,7 +213,7 @@ public void stop() { */ @Override public float getDuration() { - return this.buffer != null ? this.buffer.getDuration() : -1f; + return buffer != null ? buffer.getDuration() : -1f; } @@ -223,8 +223,8 @@ public float getDuration() { * @param seconds the position in seconds */ public void setPlaybackPosition(float seconds) { - AL10.alSourcef(this.sourceId, AL11.AL_SEC_OFFSET, seconds); - this.errorLogger.checkLogError("Failed to set playback position"); + AL10.alSourcef(sourceId, AL11.AL_SEC_OFFSET, seconds); + errorLogger.checkLogError("Failed to set playback position"); } @@ -235,13 +235,13 @@ public void setPlaybackPosition(float seconds) { */ @Override public float getPlaybackPosition() { - return AL10.alGetSourcef(this.sourceId, AL11.AL_SEC_OFFSET); + return AL10.alGetSourcef(sourceId, AL11.AL_SEC_OFFSET); } @Override public SoundEffect attachEffect(SoundEffect effect) { - if (this.obtained) { + if (obtained) { return super.attachEffect(effect); } @@ -251,7 +251,7 @@ public SoundEffect attachEffect(SoundEffect effect) { @Override public boolean detachEffect(SoundEffect effect) { - if (this.obtained) { + if (obtained) { return super.detachEffect(effect); } @@ -261,7 +261,7 @@ public boolean detachEffect(SoundEffect effect) { @Override public void detachAllEffects() { - if (this.obtained) { + if (obtained) { super.detachAllEffects(); } } @@ -273,30 +273,30 @@ public void detachAllEffects() { * @return the buffer */ public SoundBuffer getBuffer() { - return this.buffer; + return buffer; } void reset(AudioSettings defaultSettings) { - this.obtained = true; - AL10.alSourceRewind(this.sourceId); - this.setBuffer(null); - this.setFilter(1f, 1f); - this.setLooping(false); - this.setPitch(1f); - this.setVolume(1f); - this.setRelative(false); + obtained = true; + AL10.alSourceRewind(sourceId); + setBuffer(null); + setFilter(1f, 1f); + setLooping(false); + setPitch(1f); + setVolume(1f); + setRelative(false); this.setPosition(0f, 0f, 0f); this.setSpeed(0f, 0f, 0f); - this.setVirtualization(defaultSettings.getVirtualization()); - this.setSpatialization(defaultSettings.getSpatialization()); - this.setAttenuationFactor(defaultSettings.getAttenuationFactor()); - this.setAttenuationMaxDistance(defaultSettings.getMaxAttenuationDistance()); - this.setAttenuationMinDistance(defaultSettings.getMinAttenuationDistance()); - this.detachAllEffects(); - this.setResamplerByIndex(defaultSettings.getResamplerIndex()); - this.setRadius(0f); - this.obtained = false; + setVirtualization(defaultSettings.getVirtualization()); + setSpatialization(defaultSettings.getSpatialization()); + setAttenuationFactor(defaultSettings.getAttenuationFactor()); + setAttenuationMaxDistance(defaultSettings.getMaxAttenuationDistance()); + setAttenuationMinDistance(defaultSettings.getMinAttenuationDistance()); + detachAllEffects(); + setResamplerByIndex(defaultSettings.getResamplerIndex()); + setRadius(0f); + obtained = false; } @@ -304,13 +304,13 @@ void reset(AudioSettings defaultSettings) { * Releases this sound source which makes it available again. Always call this after you're done using it. */ public void free() { - if (!this.obtained) { + if (!obtained) { throw new TuningForkRuntimeException("Invalid call to BufferedSoundSource.free(), you are not the owner of this sound source."); } - this.stop(); - this.setBuffer(null); - this.detachAllEffects(); - this.obtained = false; + stop(); + setBuffer(null); + detachAllEffects(); + obtained = false; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/Chorus.java b/core/src/main/java/de/pottgames/tuningfork/Chorus.java index 4fae8b3..efebfcb 100644 --- a/core/src/main/java/de/pottgames/tuningfork/Chorus.java +++ b/core/src/main/java/de/pottgames/tuningfork/Chorus.java @@ -118,18 +118,18 @@ public static Chorus goofyRobot() { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_CHORUS); - EXTEfx.alEffecti(effectId, EXTEfx.AL_CHORUS_WAVEFORM, this.waveForm); - EXTEfx.alEffecti(effectId, EXTEfx.AL_CHORUS_PHASE, this.phase); - EXTEfx.alEffectf(effectId, EXTEfx.AL_CHORUS_RATE, this.rate); - EXTEfx.alEffectf(effectId, EXTEfx.AL_CHORUS_DEPTH, this.depth); - EXTEfx.alEffectf(effectId, EXTEfx.AL_CHORUS_FEEDBACK, this.feedback); - EXTEfx.alEffectf(effectId, EXTEfx.AL_CHORUS_DELAY, this.delay); + EXTEfx.alEffecti(effectId, EXTEfx.AL_CHORUS_WAVEFORM, waveForm); + EXTEfx.alEffecti(effectId, EXTEfx.AL_CHORUS_PHASE, phase); + EXTEfx.alEffectf(effectId, EXTEfx.AL_CHORUS_RATE, rate); + EXTEfx.alEffectf(effectId, EXTEfx.AL_CHORUS_DEPTH, depth); + EXTEfx.alEffectf(effectId, EXTEfx.AL_CHORUS_FEEDBACK, feedback); + EXTEfx.alEffectf(effectId, EXTEfx.AL_CHORUS_DELAY, delay); } @Override public int hashCode() { - return Objects.hash(this.delay, this.depth, this.feedback, this.phase, this.rate, this.waveForm); + return Objects.hash(delay, depth, feedback, phase, rate, waveForm); } @@ -145,16 +145,16 @@ public boolean equals(Object obj) { return false; } final Chorus other = (Chorus) obj; - return Float.floatToIntBits(this.delay) == Float.floatToIntBits(other.delay) && Float.floatToIntBits(this.depth) == Float.floatToIntBits(other.depth) - && Float.floatToIntBits(this.feedback) == Float.floatToIntBits(other.feedback) && this.phase == other.phase - && Float.floatToIntBits(this.rate) == Float.floatToIntBits(other.rate) && this.waveForm == other.waveForm; + return Float.floatToIntBits(delay) == Float.floatToIntBits(other.delay) && Float.floatToIntBits(depth) == Float.floatToIntBits(other.depth) + && Float.floatToIntBits(feedback) == Float.floatToIntBits(other.feedback) && phase == other.phase + && Float.floatToIntBits(rate) == Float.floatToIntBits(other.rate) && waveForm == other.waveForm; } @Override public String toString() { - return "Chorus [waveForm=" + this.waveForm + ", phase=" + this.phase + ", rate=" + this.rate + ", depth=" + this.depth + ", feedback=" + this.feedback - + ", delay=" + this.delay + "]"; + return "Chorus [waveForm=" + waveForm + ", phase=" + phase + ", rate=" + rate + ", depth=" + depth + ", feedback=" + feedback + ", delay=" + delay + + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/Compressor.java b/core/src/main/java/de/pottgames/tuningfork/Compressor.java index f8b23ad..66601a6 100644 --- a/core/src/main/java/de/pottgames/tuningfork/Compressor.java +++ b/core/src/main/java/de/pottgames/tuningfork/Compressor.java @@ -35,13 +35,13 @@ public class Compressor extends SoundEffectData { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_COMPRESSOR); - EXTEfx.alEffecti(effectId, EXTEfx.AL_COMPRESSOR_ONOFF, this.onOff); + EXTEfx.alEffecti(effectId, EXTEfx.AL_COMPRESSOR_ONOFF, onOff); } @Override public int hashCode() { - return Objects.hash(this.onOff); + return Objects.hash(onOff); } @@ -57,13 +57,13 @@ public boolean equals(Object obj) { return false; } final Compressor other = (Compressor) obj; - return this.onOff == other.onOff; + return onOff == other.onOff; } @Override public String toString() { - return "Compressor [onOff=" + this.onOff + "]"; + return "Compressor [onOff=" + onOff + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/ContextAttributes.java b/core/src/main/java/de/pottgames/tuningfork/ContextAttributes.java index 9dc9de4..6d63dd1 100644 --- a/core/src/main/java/de/pottgames/tuningfork/ContextAttributes.java +++ b/core/src/main/java/de/pottgames/tuningfork/ContextAttributes.java @@ -9,18 +9,18 @@ public class ContextAttributes { public ContextAttributes(int[] attributes) { - this.buffer = BufferUtils.newIntBuffer(attributes.length + 1); + buffer = BufferUtils.newIntBuffer(attributes.length + 1); for (final int value : attributes) { - this.buffer.put(value); + buffer.put(value); } - this.buffer.put(0); - this.buffer.flip(); + buffer.put(0); + buffer.flip(); } public IntBuffer getBuffer() { - this.buffer.rewind(); - return this.buffer; + buffer.rewind(); + return buffer; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/DistanceAttenuationModel.java b/core/src/main/java/de/pottgames/tuningfork/DistanceAttenuationModel.java index 68cdb2c..4635ada 100644 --- a/core/src/main/java/de/pottgames/tuningfork/DistanceAttenuationModel.java +++ b/core/src/main/java/de/pottgames/tuningfork/DistanceAttenuationModel.java @@ -106,22 +106,22 @@ public enum DistanceAttenuationModel { int getAlId() { - return this.alId; + return alId; } float getAttenuationFactor() { - return this.attenuationFactor; + return attenuationFactor; } float getAttenuationMinDistance() { - return this.attenuationMinDistance; + return attenuationMinDistance; } float getAttenuationMaxDistance() { - return this.attenuationMaxDistance; + return attenuationMaxDistance; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/Distortion.java b/core/src/main/java/de/pottgames/tuningfork/Distortion.java index 57258bc..e050836 100644 --- a/core/src/main/java/de/pottgames/tuningfork/Distortion.java +++ b/core/src/main/java/de/pottgames/tuningfork/Distortion.java @@ -80,17 +80,17 @@ public static Distortion rumble() { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_DISTORTION); - EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_EDGE, this.edge); - EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_GAIN, this.gain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_LOWPASS_CUTOFF, this.lowpassCutoff); - EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_EQCENTER, this.eqCenter); - EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_EQBANDWIDTH, this.eqBandwidth); + EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_EDGE, edge); + EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_GAIN, gain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_LOWPASS_CUTOFF, lowpassCutoff); + EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_EQCENTER, eqCenter); + EXTEfx.alEffectf(effectId, EXTEfx.AL_DISTORTION_EQBANDWIDTH, eqBandwidth); } @Override public int hashCode() { - return Objects.hash(this.edge, this.eqBandwidth, this.eqCenter, this.gain, this.lowpassCutoff); + return Objects.hash(edge, eqBandwidth, eqCenter, gain, lowpassCutoff); } @@ -106,18 +106,16 @@ public boolean equals(Object obj) { return false; } final Distortion other = (Distortion) obj; - return Float.floatToIntBits(this.edge) == Float.floatToIntBits(other.edge) - && Float.floatToIntBits(this.eqBandwidth) == Float.floatToIntBits(other.eqBandwidth) - && Float.floatToIntBits(this.eqCenter) == Float.floatToIntBits(other.eqCenter) - && Float.floatToIntBits(this.gain) == Float.floatToIntBits(other.gain) - && Float.floatToIntBits(this.lowpassCutoff) == Float.floatToIntBits(other.lowpassCutoff); + return Float.floatToIntBits(edge) == Float.floatToIntBits(other.edge) && Float.floatToIntBits(eqBandwidth) == Float.floatToIntBits(other.eqBandwidth) + && Float.floatToIntBits(eqCenter) == Float.floatToIntBits(other.eqCenter) && Float.floatToIntBits(gain) == Float.floatToIntBits(other.gain) + && Float.floatToIntBits(lowpassCutoff) == Float.floatToIntBits(other.lowpassCutoff); } @Override public String toString() { - return "Distortion [edge=" + this.edge + ", gain=" + this.gain + ", lowpassCutoff=" + this.lowpassCutoff + ", eqCenter=" + this.eqCenter - + ", eqBandwidth=" + this.eqBandwidth + "]"; + return "Distortion [edge=" + edge + ", gain=" + gain + ", lowpassCutoff=" + lowpassCutoff + ", eqCenter=" + eqCenter + ", eqBandwidth=" + eqBandwidth + + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/EaxReverb.java b/core/src/main/java/de/pottgames/tuningfork/EaxReverb.java index 6887f00..10e3377 100644 --- a/core/src/main/java/de/pottgames/tuningfork/EaxReverb.java +++ b/core/src/main/java/de/pottgames/tuningfork/EaxReverb.java @@ -3573,44 +3573,43 @@ public static EaxReverb smallWaterRoom() { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_EAXREVERB); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DENSITY, this.density); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DIFFUSION, this.diffusion); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_GAIN, this.gain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_GAINHF, this.gainHf); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_GAINLF, this.gainLf); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DECAY_TIME, this.decayTime); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DECAY_HFRATIO, this.decayHfRatio); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DECAY_LFRATIO, this.decayLfRatio); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_REFLECTIONS_GAIN, this.reflectionsGain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_REFLECTIONS_DELAY, this.reflectionsDelay); - this.reflectionsPanData[0] = this.reflectionsPan.x; - this.reflectionsPanData[1] = this.reflectionsPan.y; - this.reflectionsPanData[2] = this.reflectionsPan.z; - EXTEfx.alEffectfv(effectId, EXTEfx.AL_EAXREVERB_REFLECTIONS_PAN, this.reflectionsPanData); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_LATE_REVERB_GAIN, this.lateReverbGain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_LATE_REVERB_DELAY, this.lateReverbDelay); - this.lateReverbPanData[0] = this.lateReverbPan.x; - this.lateReverbPanData[1] = this.lateReverbPan.y; - this.lateReverbPanData[2] = this.lateReverbPan.z; - EXTEfx.alEffectfv(effectId, EXTEfx.AL_EAXREVERB_REFLECTIONS_PAN, this.lateReverbPanData); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_ECHO_TIME, this.echoTime); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_ECHO_DEPTH, this.echoDepth); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_MODULATION_TIME, this.modulationTime); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_MODULATION_DEPTH, this.modulationDepth); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_AIR_ABSORPTION_GAINHF, this.airAbsorptionGainHf); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_HFREFERENCE, this.hfReference); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_LFREFERENCE, this.lfReference); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, this.roomRolloffFactor); - EXTEfx.alEffecti(effectId, EXTEfx.AL_EAXREVERB_DECAY_HFLIMIT, this.decayHfLimit ? AL10.AL_TRUE : AL10.AL_FALSE); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DENSITY, density); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DIFFUSION, diffusion); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_GAIN, gain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_GAINHF, gainHf); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_GAINLF, gainLf); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DECAY_TIME, decayTime); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DECAY_HFRATIO, decayHfRatio); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_DECAY_LFRATIO, decayLfRatio); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_REFLECTIONS_GAIN, reflectionsGain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_REFLECTIONS_DELAY, reflectionsDelay); + reflectionsPanData[0] = reflectionsPan.x; + reflectionsPanData[1] = reflectionsPan.y; + reflectionsPanData[2] = reflectionsPan.z; + EXTEfx.alEffectfv(effectId, EXTEfx.AL_EAXREVERB_REFLECTIONS_PAN, reflectionsPanData); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_LATE_REVERB_GAIN, lateReverbGain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_LATE_REVERB_DELAY, lateReverbDelay); + lateReverbPanData[0] = lateReverbPan.x; + lateReverbPanData[1] = lateReverbPan.y; + lateReverbPanData[2] = lateReverbPan.z; + EXTEfx.alEffectfv(effectId, EXTEfx.AL_EAXREVERB_REFLECTIONS_PAN, lateReverbPanData); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_ECHO_TIME, echoTime); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_ECHO_DEPTH, echoDepth); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_MODULATION_TIME, modulationTime); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_MODULATION_DEPTH, modulationDepth); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_AIR_ABSORPTION_GAINHF, airAbsorptionGainHf); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_HFREFERENCE, hfReference); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_LFREFERENCE, lfReference); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EAXREVERB_ROOM_ROLLOFF_FACTOR, roomRolloffFactor); + EXTEfx.alEffecti(effectId, EXTEfx.AL_EAXREVERB_DECAY_HFLIMIT, decayHfLimit ? AL10.AL_TRUE : AL10.AL_FALSE); } @Override public int hashCode() { - return Objects.hash(this.airAbsorptionGainHf, this.decayHfLimit, this.decayHfRatio, this.decayLfRatio, this.decayTime, this.density, this.diffusion, - this.echoDepth, this.echoTime, this.gain, this.gainHf, this.gainLf, this.hfReference, this.lateReverbDelay, this.lateReverbGain, - this.lateReverbPan, this.lfReference, this.modulationDepth, this.modulationTime, this.reflectionsDelay, this.reflectionsGain, - this.reflectionsPan, this.roomRolloffFactor); + return Objects.hash(airAbsorptionGainHf, decayHfLimit, decayHfRatio, decayLfRatio, decayTime, density, diffusion, echoDepth, echoTime, gain, gainHf, + gainLf, hfReference, lateReverbDelay, lateReverbGain, lateReverbPan, lfReference, modulationDepth, modulationTime, reflectionsDelay, + reflectionsGain, reflectionsPan, roomRolloffFactor); } @@ -3626,39 +3625,35 @@ public boolean equals(Object obj) { return false; } final EaxReverb other = (EaxReverb) obj; - return Float.floatToIntBits(this.airAbsorptionGainHf) == Float.floatToIntBits(other.airAbsorptionGainHf) && this.decayHfLimit == other.decayHfLimit - && Float.floatToIntBits(this.decayHfRatio) == Float.floatToIntBits(other.decayHfRatio) - && Float.floatToIntBits(this.decayLfRatio) == Float.floatToIntBits(other.decayLfRatio) - && Float.floatToIntBits(this.decayTime) == Float.floatToIntBits(other.decayTime) - && Float.floatToIntBits(this.density) == Float.floatToIntBits(other.density) - && Float.floatToIntBits(this.diffusion) == Float.floatToIntBits(other.diffusion) - && Float.floatToIntBits(this.echoDepth) == Float.floatToIntBits(other.echoDepth) - && Float.floatToIntBits(this.echoTime) == Float.floatToIntBits(other.echoTime) - && Float.floatToIntBits(this.gain) == Float.floatToIntBits(other.gain) - && Float.floatToIntBits(this.gainHf) == Float.floatToIntBits(other.gainHf) - && Float.floatToIntBits(this.gainLf) == Float.floatToIntBits(other.gainLf) - && Float.floatToIntBits(this.hfReference) == Float.floatToIntBits(other.hfReference) - && Float.floatToIntBits(this.lateReverbDelay) == Float.floatToIntBits(other.lateReverbDelay) - && Float.floatToIntBits(this.lateReverbGain) == Float.floatToIntBits(other.lateReverbGain) - && Objects.equals(this.lateReverbPan, other.lateReverbPan) && Float.floatToIntBits(this.lfReference) == Float.floatToIntBits(other.lfReference) - && Float.floatToIntBits(this.modulationDepth) == Float.floatToIntBits(other.modulationDepth) - && Float.floatToIntBits(this.modulationTime) == Float.floatToIntBits(other.modulationTime) - && Float.floatToIntBits(this.reflectionsDelay) == Float.floatToIntBits(other.reflectionsDelay) - && Float.floatToIntBits(this.reflectionsGain) == Float.floatToIntBits(other.reflectionsGain) - && Objects.equals(this.reflectionsPan, other.reflectionsPan) - && Float.floatToIntBits(this.roomRolloffFactor) == Float.floatToIntBits(other.roomRolloffFactor); + return Float.floatToIntBits(airAbsorptionGainHf) == Float.floatToIntBits(other.airAbsorptionGainHf) && decayHfLimit == other.decayHfLimit + && Float.floatToIntBits(decayHfRatio) == Float.floatToIntBits(other.decayHfRatio) + && Float.floatToIntBits(decayLfRatio) == Float.floatToIntBits(other.decayLfRatio) + && Float.floatToIntBits(decayTime) == Float.floatToIntBits(other.decayTime) + && Float.floatToIntBits(density) == Float.floatToIntBits(other.density) + && Float.floatToIntBits(diffusion) == Float.floatToIntBits(other.diffusion) + && Float.floatToIntBits(echoDepth) == Float.floatToIntBits(other.echoDepth) + && Float.floatToIntBits(echoTime) == Float.floatToIntBits(other.echoTime) && Float.floatToIntBits(gain) == Float.floatToIntBits(other.gain) + && Float.floatToIntBits(gainHf) == Float.floatToIntBits(other.gainHf) && Float.floatToIntBits(gainLf) == Float.floatToIntBits(other.gainLf) + && Float.floatToIntBits(hfReference) == Float.floatToIntBits(other.hfReference) + && Float.floatToIntBits(lateReverbDelay) == Float.floatToIntBits(other.lateReverbDelay) + && Float.floatToIntBits(lateReverbGain) == Float.floatToIntBits(other.lateReverbGain) && Objects.equals(lateReverbPan, other.lateReverbPan) + && Float.floatToIntBits(lfReference) == Float.floatToIntBits(other.lfReference) + && Float.floatToIntBits(modulationDepth) == Float.floatToIntBits(other.modulationDepth) + && Float.floatToIntBits(modulationTime) == Float.floatToIntBits(other.modulationTime) + && Float.floatToIntBits(reflectionsDelay) == Float.floatToIntBits(other.reflectionsDelay) + && Float.floatToIntBits(reflectionsGain) == Float.floatToIntBits(other.reflectionsGain) && Objects.equals(reflectionsPan, other.reflectionsPan) + && Float.floatToIntBits(roomRolloffFactor) == Float.floatToIntBits(other.roomRolloffFactor); } @Override public String toString() { - return "EaxReverb [density=" + this.density + ", diffusion=" + this.diffusion + ", gain=" + this.gain + ", gainHf=" + this.gainHf + ", gainLf=" - + this.gainLf + ", decayTime=" + this.decayTime + ", decayHfRatio=" + this.decayHfRatio + ", decayLfRatio=" + this.decayLfRatio - + ", reflectionsGain=" + this.reflectionsGain + ", reflectionsDelay=" + this.reflectionsDelay + ", reflectionsPan=" + this.reflectionsPan - + ", lateReverbGain=" + this.lateReverbGain + ", lateReverbDelay=" + this.lateReverbDelay + ", lateReverbPan=" + this.lateReverbPan - + ", echoTime=" + this.echoTime + ", echoDepth=" + this.echoDepth + ", modulationTime=" + this.modulationTime + ", modulationDepth=" - + this.modulationDepth + ", airAbsorptionGainHf=" + this.airAbsorptionGainHf + ", hfReference=" + this.hfReference + ", lfReference=" - + this.lfReference + ", roomRolloffFactor=" + this.roomRolloffFactor + ", decayHfLimit=" + this.decayHfLimit + "]"; + return "EaxReverb [density=" + density + ", diffusion=" + diffusion + ", gain=" + gain + ", gainHf=" + gainHf + ", gainLf=" + gainLf + ", decayTime=" + + decayTime + ", decayHfRatio=" + decayHfRatio + ", decayLfRatio=" + decayLfRatio + ", reflectionsGain=" + reflectionsGain + + ", reflectionsDelay=" + reflectionsDelay + ", reflectionsPan=" + reflectionsPan + ", lateReverbGain=" + lateReverbGain + ", lateReverbDelay=" + + lateReverbDelay + ", lateReverbPan=" + lateReverbPan + ", echoTime=" + echoTime + ", echoDepth=" + echoDepth + ", modulationTime=" + + modulationTime + ", modulationDepth=" + modulationDepth + ", airAbsorptionGainHf=" + airAbsorptionGainHf + ", hfReference=" + hfReference + + ", lfReference=" + lfReference + ", roomRolloffFactor=" + roomRolloffFactor + ", decayHfLimit=" + decayHfLimit + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/Echo.java b/core/src/main/java/de/pottgames/tuningfork/Echo.java index 67c81b2..465f81d 100644 --- a/core/src/main/java/de/pottgames/tuningfork/Echo.java +++ b/core/src/main/java/de/pottgames/tuningfork/Echo.java @@ -121,17 +121,17 @@ public static Echo doppelganger() { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_ECHO); - EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_DELAY, this.delay); - EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_LRDELAY, this.lrDelay); - EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_DAMPING, this.damping); - EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_FEEDBACK, this.feedback); - EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_SPREAD, this.spread); + EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_DELAY, delay); + EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_LRDELAY, lrDelay); + EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_DAMPING, damping); + EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_FEEDBACK, feedback); + EXTEfx.alEffectf(effectId, EXTEfx.AL_ECHO_SPREAD, spread); } @Override public int hashCode() { - return Objects.hash(this.damping, this.delay, this.feedback, this.lrDelay, this.spread); + return Objects.hash(damping, delay, feedback, lrDelay, spread); } @@ -147,18 +147,15 @@ public boolean equals(Object obj) { return false; } final Echo other = (Echo) obj; - return Float.floatToIntBits(this.damping) == Float.floatToIntBits(other.damping) - && Float.floatToIntBits(this.delay) == Float.floatToIntBits(other.delay) - && Float.floatToIntBits(this.feedback) == Float.floatToIntBits(other.feedback) - && Float.floatToIntBits(this.lrDelay) == Float.floatToIntBits(other.lrDelay) - && Float.floatToIntBits(this.spread) == Float.floatToIntBits(other.spread); + return Float.floatToIntBits(damping) == Float.floatToIntBits(other.damping) && Float.floatToIntBits(delay) == Float.floatToIntBits(other.delay) + && Float.floatToIntBits(feedback) == Float.floatToIntBits(other.feedback) + && Float.floatToIntBits(lrDelay) == Float.floatToIntBits(other.lrDelay) && Float.floatToIntBits(spread) == Float.floatToIntBits(other.spread); } @Override public String toString() { - return "Echo [delay=" + this.delay + ", lrDelay=" + this.lrDelay + ", damping=" + this.damping + ", feedback=" + this.feedback + ", spread=" - + this.spread + "]"; + return "Echo [delay=" + delay + ", lrDelay=" + lrDelay + ", damping=" + damping + ", feedback=" + feedback + ", spread=" + spread + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/Equalizer.java b/core/src/main/java/de/pottgames/tuningfork/Equalizer.java index a8d6214..e9627f9 100644 --- a/core/src/main/java/de/pottgames/tuningfork/Equalizer.java +++ b/core/src/main/java/de/pottgames/tuningfork/Equalizer.java @@ -88,23 +88,22 @@ public class Equalizer extends SoundEffectData { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_EQUALIZER); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_LOW_GAIN, this.lowGain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_LOW_CUTOFF, this.lowCutoff); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID1_GAIN, this.mid1Gain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID1_CENTER, this.mid1Center); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID1_WIDTH, this.mid1Width); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID2_GAIN, this.mid2Gain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID2_CENTER, this.mid2Center); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID2_WIDTH, this.mid2Width); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_HIGH_GAIN, this.highGain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_HIGH_CUTOFF, this.highCutoff); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_LOW_GAIN, lowGain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_LOW_CUTOFF, lowCutoff); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID1_GAIN, mid1Gain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID1_CENTER, mid1Center); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID1_WIDTH, mid1Width); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID2_GAIN, mid2Gain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID2_CENTER, mid2Center); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_MID2_WIDTH, mid2Width); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_HIGH_GAIN, highGain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_EQUALIZER_HIGH_CUTOFF, highCutoff); } @Override public int hashCode() { - return Objects.hash(this.highCutoff, this.highGain, this.lowCutoff, this.lowGain, this.mid1Center, this.mid1Gain, this.mid1Width, this.mid2Center, - this.mid2Gain, this.mid2Width); + return Objects.hash(highCutoff, highGain, lowCutoff, lowGain, mid1Center, mid1Gain, mid1Width, mid2Center, mid2Gain, mid2Width); } @@ -120,24 +119,24 @@ public boolean equals(Object obj) { return false; } final Equalizer other = (Equalizer) obj; - return Float.floatToIntBits(this.highCutoff) == Float.floatToIntBits(other.highCutoff) - && Float.floatToIntBits(this.highGain) == Float.floatToIntBits(other.highGain) - && Float.floatToIntBits(this.lowCutoff) == Float.floatToIntBits(other.lowCutoff) - && Float.floatToIntBits(this.lowGain) == Float.floatToIntBits(other.lowGain) - && Float.floatToIntBits(this.mid1Center) == Float.floatToIntBits(other.mid1Center) - && Float.floatToIntBits(this.mid1Gain) == Float.floatToIntBits(other.mid1Gain) - && Float.floatToIntBits(this.mid1Width) == Float.floatToIntBits(other.mid1Width) - && Float.floatToIntBits(this.mid2Center) == Float.floatToIntBits(other.mid2Center) - && Float.floatToIntBits(this.mid2Gain) == Float.floatToIntBits(other.mid2Gain) - && Float.floatToIntBits(this.mid2Width) == Float.floatToIntBits(other.mid2Width); + return Float.floatToIntBits(highCutoff) == Float.floatToIntBits(other.highCutoff) + && Float.floatToIntBits(highGain) == Float.floatToIntBits(other.highGain) + && Float.floatToIntBits(lowCutoff) == Float.floatToIntBits(other.lowCutoff) + && Float.floatToIntBits(lowGain) == Float.floatToIntBits(other.lowGain) + && Float.floatToIntBits(mid1Center) == Float.floatToIntBits(other.mid1Center) + && Float.floatToIntBits(mid1Gain) == Float.floatToIntBits(other.mid1Gain) + && Float.floatToIntBits(mid1Width) == Float.floatToIntBits(other.mid1Width) + && Float.floatToIntBits(mid2Center) == Float.floatToIntBits(other.mid2Center) + && Float.floatToIntBits(mid2Gain) == Float.floatToIntBits(other.mid2Gain) + && Float.floatToIntBits(mid2Width) == Float.floatToIntBits(other.mid2Width); } @Override public String toString() { - return "Equalizer [lowGain=" + this.lowGain + ", lowCutoff=" + this.lowCutoff + ", mid1Gain=" + this.mid1Gain + ", mid1Center=" + this.mid1Center - + ", mid1Width=" + this.mid1Width + ", mid2Gain=" + this.mid2Gain + ", mid2Center=" + this.mid2Center + ", mid2Width=" + this.mid2Width - + ", highGain=" + this.highGain + ", highCutoff=" + this.highCutoff + "]"; + return "Equalizer [lowGain=" + lowGain + ", lowCutoff=" + lowCutoff + ", mid1Gain=" + mid1Gain + ", mid1Center=" + mid1Center + ", mid1Width=" + + mid1Width + ", mid2Gain=" + mid2Gain + ", mid2Center=" + mid2Center + ", mid2Width=" + mid2Width + ", highGain=" + highGain + ", highCutoff=" + + highCutoff + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/Filter.java b/core/src/main/java/de/pottgames/tuningfork/Filter.java index c0e9679..7784b42 100644 --- a/core/src/main/java/de/pottgames/tuningfork/Filter.java +++ b/core/src/main/java/de/pottgames/tuningfork/Filter.java @@ -39,23 +39,23 @@ class Filter { * @param volumeHf volume of the high frequencies, range: 0 - 1 */ Filter(float volumeLf, float volumeHf) { - this.logger = Audio.get().getLogger(); - this.errorLogger = new ErrorLogger(this.getClass(), this.logger); - this.errorLogger.dismissError(); - - this.id = EXTEfx.alGenFilters(); - EXTEfx.alFilteri(this.id, EXTEfx.AL_FILTER_TYPE, EXTEfx.AL_FILTER_BANDPASS); - if (!this.errorLogger.checkLogError("Failed to create filter")) { - this.logger.debug(this.getClass(), "Successfully created filter."); + logger = Audio.get().getLogger(); + errorLogger = new ErrorLogger(this.getClass(), logger); + errorLogger.dismissError(); + + id = EXTEfx.alGenFilters(); + EXTEfx.alFilteri(id, EXTEfx.AL_FILTER_TYPE, EXTEfx.AL_FILTER_BANDPASS); + if (!errorLogger.checkLogError("Failed to create filter")) { + logger.debug(this.getClass(), "Successfully created filter."); } - EXTEfx.alFilterf(this.id, EXTEfx.AL_BANDPASS_GAIN, 1f); - this.setLowFrequencyVolume(volumeLf); - this.setHighFrequencyVolume(volumeHf); + EXTEfx.alFilterf(id, EXTEfx.AL_BANDPASS_GAIN, 1f); + setLowFrequencyVolume(volumeLf); + setHighFrequencyVolume(volumeHf); } int getId() { - return this.id; + return id; } @@ -66,7 +66,7 @@ int getId() { */ void setLowFrequencyVolume(float volume) { volume = MathUtils.clamp(volume, 0f, 1f); - EXTEfx.alFilterf(this.id, EXTEfx.AL_BANDPASS_GAINLF, volume); + EXTEfx.alFilterf(id, EXTEfx.AL_BANDPASS_GAINLF, volume); } @@ -77,15 +77,15 @@ void setLowFrequencyVolume(float volume) { */ void setHighFrequencyVolume(float volume) { volume = MathUtils.clamp(volume, 0f, 1f); - EXTEfx.alFilterf(this.id, EXTEfx.AL_BANDPASS_GAINHF, volume); + EXTEfx.alFilterf(id, EXTEfx.AL_BANDPASS_GAINHF, volume); } void dispose() { - this.errorLogger.dismissError(); - EXTEfx.alDeleteFilters(this.id); - if (!this.errorLogger.checkLogError("Failed to dispose filter")) { - this.logger.debug(this.getClass(), "Filter disposed."); + errorLogger.dismissError(); + EXTEfx.alDeleteFilters(id); + if (!errorLogger.checkLogError("Failed to dispose filter")) { + logger.debug(this.getClass(), "Filter disposed."); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/Flanger.java b/core/src/main/java/de/pottgames/tuningfork/Flanger.java index 7f1edda..d68eab0 100644 --- a/core/src/main/java/de/pottgames/tuningfork/Flanger.java +++ b/core/src/main/java/de/pottgames/tuningfork/Flanger.java @@ -102,18 +102,18 @@ public static Flanger robotMetallic() { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_FLANGER); - EXTEfx.alEffecti(effectId, EXTEfx.AL_FLANGER_WAVEFORM, this.waveform); - EXTEfx.alEffecti(effectId, EXTEfx.AL_FLANGER_PHASE, this.phase); - EXTEfx.alEffectf(effectId, EXTEfx.AL_FLANGER_RATE, this.rate); - EXTEfx.alEffectf(effectId, EXTEfx.AL_FLANGER_DEPTH, this.depth); - EXTEfx.alEffectf(effectId, EXTEfx.AL_FLANGER_FEEDBACK, this.feedback); - EXTEfx.alEffectf(effectId, EXTEfx.AL_FLANGER_DELAY, this.delay); + EXTEfx.alEffecti(effectId, EXTEfx.AL_FLANGER_WAVEFORM, waveform); + EXTEfx.alEffecti(effectId, EXTEfx.AL_FLANGER_PHASE, phase); + EXTEfx.alEffectf(effectId, EXTEfx.AL_FLANGER_RATE, rate); + EXTEfx.alEffectf(effectId, EXTEfx.AL_FLANGER_DEPTH, depth); + EXTEfx.alEffectf(effectId, EXTEfx.AL_FLANGER_FEEDBACK, feedback); + EXTEfx.alEffectf(effectId, EXTEfx.AL_FLANGER_DELAY, delay); } @Override public int hashCode() { - return Objects.hash(this.delay, this.depth, this.feedback, this.phase, this.rate, this.waveform); + return Objects.hash(delay, depth, feedback, phase, rate, waveform); } @@ -129,16 +129,16 @@ public boolean equals(Object obj) { return false; } final Flanger other = (Flanger) obj; - return Float.floatToIntBits(this.delay) == Float.floatToIntBits(other.delay) && Float.floatToIntBits(this.depth) == Float.floatToIntBits(other.depth) - && Float.floatToIntBits(this.feedback) == Float.floatToIntBits(other.feedback) && this.phase == other.phase - && Float.floatToIntBits(this.rate) == Float.floatToIntBits(other.rate) && this.waveform == other.waveform; + return Float.floatToIntBits(delay) == Float.floatToIntBits(other.delay) && Float.floatToIntBits(depth) == Float.floatToIntBits(other.depth) + && Float.floatToIntBits(feedback) == Float.floatToIntBits(other.feedback) && phase == other.phase + && Float.floatToIntBits(rate) == Float.floatToIntBits(other.rate) && waveform == other.waveform; } @Override public String toString() { - return "Flanger [waveform=" + this.waveform + ", phase=" + this.phase + ", rate=" + this.rate + ", depth=" + this.depth + ", feedback=" + this.feedback - + ", delay=" + this.delay + "]"; + return "Flanger [waveform=" + waveform + ", phase=" + phase + ", rate=" + rate + ", depth=" + depth + ", feedback=" + feedback + ", delay=" + delay + + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/FrequencyShifter.java b/core/src/main/java/de/pottgames/tuningfork/FrequencyShifter.java index b5f2fe0..1253375 100644 --- a/core/src/main/java/de/pottgames/tuningfork/FrequencyShifter.java +++ b/core/src/main/java/de/pottgames/tuningfork/FrequencyShifter.java @@ -52,15 +52,15 @@ public class FrequencyShifter extends SoundEffectData { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_FREQUENCY_SHIFTER); - EXTEfx.alEffectf(effectId, EXTEfx.AL_FREQUENCY_SHIFTER_FREQUENCY, this.frequency); - EXTEfx.alEffecti(effectId, EXTEfx.AL_FREQUENCY_SHIFTER_LEFT_DIRECTION, this.leftDirection); - EXTEfx.alEffecti(effectId, EXTEfx.AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION, this.rightDirection); + EXTEfx.alEffectf(effectId, EXTEfx.AL_FREQUENCY_SHIFTER_FREQUENCY, frequency); + EXTEfx.alEffecti(effectId, EXTEfx.AL_FREQUENCY_SHIFTER_LEFT_DIRECTION, leftDirection); + EXTEfx.alEffecti(effectId, EXTEfx.AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION, rightDirection); } @Override public int hashCode() { - return Objects.hash(this.frequency, this.leftDirection, this.rightDirection); + return Objects.hash(frequency, leftDirection, rightDirection); } @@ -76,14 +76,14 @@ public boolean equals(Object obj) { return false; } final FrequencyShifter other = (FrequencyShifter) obj; - return Float.floatToIntBits(this.frequency) == Float.floatToIntBits(other.frequency) && this.leftDirection == other.leftDirection - && this.rightDirection == other.rightDirection; + return Float.floatToIntBits(frequency) == Float.floatToIntBits(other.frequency) && leftDirection == other.leftDirection + && rightDirection == other.rightDirection; } @Override public String toString() { - return "FrequencyShifter [frequency=" + this.frequency + ", leftDirection=" + this.leftDirection + ", rightDirection=" + this.rightDirection + "]"; + return "FrequencyShifter [frequency=" + frequency + ", leftDirection=" + leftDirection + ", rightDirection=" + rightDirection + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/OutputMode.java b/core/src/main/java/de/pottgames/tuningfork/OutputMode.java index 9d223a5..590684a 100644 --- a/core/src/main/java/de/pottgames/tuningfork/OutputMode.java +++ b/core/src/main/java/de/pottgames/tuningfork/OutputMode.java @@ -64,7 +64,7 @@ public enum OutputMode { int getAlId() { - return this.alId; + return alId; } diff --git a/core/src/main/java/de/pottgames/tuningfork/PcmFormat.java b/core/src/main/java/de/pottgames/tuningfork/PcmFormat.java index 5402ba2..2af8147 100644 --- a/core/src/main/java/de/pottgames/tuningfork/PcmFormat.java +++ b/core/src/main/java/de/pottgames/tuningfork/PcmFormat.java @@ -54,22 +54,22 @@ public enum PcmFormat { public int getAlId() { - return this.alId; + return alId; } public int getChannels() { - return this.channels; + return channels; } public int getBitsPerSample() { - return this.bitsPerSample; + return bitsPerSample; } public PcmDataType getDataType() { - return this.dataType; + return dataType; } diff --git a/core/src/main/java/de/pottgames/tuningfork/PcmSoundSource.java b/core/src/main/java/de/pottgames/tuningfork/PcmSoundSource.java index 90258d4..f75dc67 100644 --- a/core/src/main/java/de/pottgames/tuningfork/PcmSoundSource.java +++ b/core/src/main/java/de/pottgames/tuningfork/PcmSoundSource.java @@ -51,16 +51,16 @@ public class PcmSoundSource extends SoundSource implements Disposable { */ public PcmSoundSource(int sampleRate, PcmFormat pcmFormat) { final Audio audio = Audio.get(); - this.logger = audio.getLogger(); - this.errorLogger = new ErrorLogger(this.getClass(), this.logger); + logger = audio.getLogger(); + errorLogger = new ErrorLogger(this.getClass(), logger); this.sampleRate = sampleRate; - this.formatAlId = pcmFormat.getAlId(); - this.tempBuffer = BufferUtils.createByteBuffer(PcmSoundSource.BUFFER_SIZE); - this.tempFloatBuffer = BufferUtils.createFloatBuffer(PcmSoundSource.BUFFER_SIZE); + formatAlId = pcmFormat.getAlId(); + tempBuffer = BufferUtils.createByteBuffer(PcmSoundSource.BUFFER_SIZE); + tempFloatBuffer = BufferUtils.createFloatBuffer(PcmSoundSource.BUFFER_SIZE); for (int i = 0; i < PcmSoundSource.INITIAL_BUFFER_COUNT; i++) { - this.freeBufferIds.add(AL10.alGenBuffers()); + freeBufferIds.add(AL10.alGenBuffers()); } audio.registerManagedSource(this); @@ -82,15 +82,15 @@ public PcmSoundSource(int sampleRate, PcmFormat pcmFormat) { * @param length the length of the pcm data that should be read */ public void queueSamples(byte[] pcm, int offset, int length) { - this.unqueueProcessedBuffers(); + unqueueProcessedBuffers(); while (length > 0) { - final int alBufferId = this.getFreeBufferId(); + final int alBufferId = getFreeBufferId(); final int writtenLength = Math.min(PcmSoundSource.BUFFER_SIZE, length); - this.tempBuffer.clear(); - this.tempBuffer.put(pcm, offset, writtenLength).flip(); - AL10.alBufferData(alBufferId, this.formatAlId, this.tempBuffer, this.sampleRate); - AL10.alSourceQueueBuffers(this.sourceId, alBufferId); + tempBuffer.clear(); + tempBuffer.put(pcm, offset, writtenLength).flip(); + AL10.alBufferData(alBufferId, formatAlId, tempBuffer, sampleRate); + AL10.alSourceQueueBuffers(sourceId, alBufferId); length -= writtenLength; offset += writtenLength; } @@ -110,15 +110,15 @@ public void queueSamples(byte[] pcm, int offset, int length) { * @param length the length of the pcm data that should be read */ public void queueSamples(float[] pcm, int offset, int length) { - this.unqueueProcessedBuffers(); + unqueueProcessedBuffers(); while (length > 0) { - final int alBufferId = this.getFreeBufferId(); + final int alBufferId = getFreeBufferId(); final int writtenLength = Math.min(PcmSoundSource.BUFFER_SIZE, length); - this.tempFloatBuffer.clear(); - this.tempFloatBuffer.put(pcm, offset, writtenLength).flip(); - AL10.alBufferData(alBufferId, this.formatAlId, this.tempFloatBuffer, this.sampleRate); - AL10.alSourceQueueBuffers(this.sourceId, alBufferId); + tempFloatBuffer.clear(); + tempFloatBuffer.put(pcm, offset, writtenLength).flip(); + AL10.alBufferData(alBufferId, formatAlId, tempFloatBuffer, sampleRate); + AL10.alSourceQueueBuffers(sourceId, alBufferId); length -= writtenLength; offset += writtenLength; } @@ -138,10 +138,10 @@ public void queueSamples(float[] pcm, int offset, int length) { * @param pcm in native order */ public void queueSamples(ByteBuffer pcm) { - this.unqueueProcessedBuffers(); - final int alBufferId = this.getFreeBufferId(); - AL10.alBufferData(alBufferId, this.formatAlId, pcm, this.sampleRate); - AL10.alSourceQueueBuffers(this.sourceId, alBufferId); + unqueueProcessedBuffers(); + final int alBufferId = getFreeBufferId(); + AL10.alBufferData(alBufferId, formatAlId, pcm, sampleRate); + AL10.alSourceQueueBuffers(sourceId, alBufferId); } @@ -158,10 +158,10 @@ public void queueSamples(ByteBuffer pcm) { * @param pcm in native order */ public void queueSamples(ShortBuffer pcm) { - this.unqueueProcessedBuffers(); - final int alBufferId = this.getFreeBufferId(); - AL10.alBufferData(alBufferId, this.formatAlId, pcm, this.sampleRate); - AL10.alSourceQueueBuffers(this.sourceId, alBufferId); + unqueueProcessedBuffers(); + final int alBufferId = getFreeBufferId(); + AL10.alBufferData(alBufferId, formatAlId, pcm, sampleRate); + AL10.alSourceQueueBuffers(sourceId, alBufferId); } @@ -176,18 +176,18 @@ public void queueSamples(ShortBuffer pcm) { * @param pcm in native order */ public void queueSamples(FloatBuffer pcm) { - this.unqueueProcessedBuffers(); - final int alBufferId = this.getFreeBufferId(); - AL10.alBufferData(alBufferId, this.formatAlId, pcm, this.sampleRate); - AL10.alSourceQueueBuffers(this.sourceId, alBufferId); + unqueueProcessedBuffers(); + final int alBufferId = getFreeBufferId(); + AL10.alBufferData(alBufferId, formatAlId, pcm, sampleRate); + AL10.alSourceQueueBuffers(sourceId, alBufferId); } private int getFreeBufferId() { - if (this.freeBufferIds.isEmpty()) { + if (freeBufferIds.isEmpty()) { return AL10.alGenBuffers(); } - return this.freeBufferIds.pop(); + return freeBufferIds.pop(); } @@ -195,9 +195,9 @@ private int getFreeBufferId() { * Unqueues processed buffers. This is called automatically on each call to any of the queueSamples methods, so you never have to call it manually. */ public void unqueueProcessedBuffers() { - final int processedBuffers = AL10.alGetSourcei(this.sourceId, AL10.AL_BUFFERS_PROCESSED); + final int processedBuffers = AL10.alGetSourcei(sourceId, AL10.AL_BUFFERS_PROCESSED); for (int i = 0; i < processedBuffers; i++) { - this.freeBufferIds.add(AL10.alSourceUnqueueBuffers(this.sourceId)); + freeBufferIds.add(AL10.alSourceUnqueueBuffers(sourceId)); } } @@ -209,8 +209,8 @@ public void unqueueProcessedBuffers() { * @return the number of buffers queued */ public int queuedBuffers() { - this.unqueueProcessedBuffers(); - return AL10.alGetSourcei(this.sourceId, AL10.AL_BUFFERS_QUEUED); + unqueueProcessedBuffers(); + return AL10.alGetSourcei(sourceId, AL10.AL_BUFFERS_QUEUED); } @@ -219,21 +219,21 @@ public int queuedBuffers() { */ @Override public void dispose() { - this.stop(); + stop(); - final int processedBuffers = AL10.alGetSourcei(this.sourceId, AL10.AL_BUFFERS_PROCESSED); + final int processedBuffers = AL10.alGetSourcei(sourceId, AL10.AL_BUFFERS_PROCESSED); for (int i = 0; i < processedBuffers; i++) { - this.freeBufferIds.add(AL10.alSourceUnqueueBuffers(this.sourceId)); + freeBufferIds.add(AL10.alSourceUnqueueBuffers(sourceId)); } - for (int i = 0; i < this.freeBufferIds.size; i++) { - AL10.alDeleteBuffers(this.freeBufferIds.get(i)); + for (int i = 0; i < freeBufferIds.size; i++) { + AL10.alDeleteBuffers(freeBufferIds.get(i)); } final Audio audio = Audio.get(); audio.removeManagedSource(this); - this.errorLogger.checkLogError("Failed to dispose the SoundSource"); + errorLogger.checkLogError("Failed to dispose the SoundSource"); super.dispose(); } diff --git a/core/src/main/java/de/pottgames/tuningfork/PitchShifter.java b/core/src/main/java/de/pottgames/tuningfork/PitchShifter.java index 1dd7900..6f8f5ce 100644 --- a/core/src/main/java/de/pottgames/tuningfork/PitchShifter.java +++ b/core/src/main/java/de/pottgames/tuningfork/PitchShifter.java @@ -85,9 +85,9 @@ public PitchShifter correctPitch(float pitch) { pitch = MathUtils.clamp(pitch, 0.5f, 2f); final float semitones = (float) (12d / Math.log(2d) * Math.log(1d / pitch)); - this.coarseTune = Math.round(semitones); - final float rest = semitones - this.coarseTune; - this.fineTune = Math.round(rest * 100f); + coarseTune = Math.round(semitones); + final float rest = semitones - coarseTune; + fineTune = Math.round(rest * 100f); return this; } @@ -96,14 +96,14 @@ public PitchShifter correctPitch(float pitch) { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_PITCH_SHIFTER); - EXTEfx.alEffecti(effectId, EXTEfx.AL_PITCH_SHIFTER_COARSE_TUNE, this.coarseTune); - EXTEfx.alEffecti(effectId, EXTEfx.AL_PITCH_SHIFTER_FINE_TUNE, this.fineTune); + EXTEfx.alEffecti(effectId, EXTEfx.AL_PITCH_SHIFTER_COARSE_TUNE, coarseTune); + EXTEfx.alEffecti(effectId, EXTEfx.AL_PITCH_SHIFTER_FINE_TUNE, fineTune); } @Override public int hashCode() { - return Objects.hash(this.coarseTune, this.fineTune); + return Objects.hash(coarseTune, fineTune); } @@ -119,13 +119,13 @@ public boolean equals(Object obj) { return false; } final PitchShifter other = (PitchShifter) obj; - return this.coarseTune == other.coarseTune && this.fineTune == other.fineTune; + return coarseTune == other.coarseTune && fineTune == other.fineTune; } @Override public String toString() { - return "PitchShifter [coarseTune=" + this.coarseTune + ", fineTune=" + this.fineTune + "]"; + return "PitchShifter [coarseTune=" + coarseTune + ", fineTune=" + fineTune + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/ReadableSoundBuffer.java b/core/src/main/java/de/pottgames/tuningfork/ReadableSoundBuffer.java index 67d1ce1..1b7eb89 100644 --- a/core/src/main/java/de/pottgames/tuningfork/ReadableSoundBuffer.java +++ b/core/src/main/java/de/pottgames/tuningfork/ReadableSoundBuffer.java @@ -42,7 +42,7 @@ public class ReadableSoundBuffer extends SoundBuffer { */ public ReadableSoundBuffer(byte[] pcm, int channels, int sampleRate, int bitsPerSample, PcmDataType pcmDataType) { super(pcm, channels, sampleRate, bitsPerSample, pcmDataType); - this.bufferCopy = pcm; + bufferCopy = pcm; } @@ -67,7 +67,7 @@ public ReadableSoundBuffer(ShortBuffer pcm, int channels, int sampleRate, int bi while (pcm.hasRemaining()) { byteBuffer.putShort(pcm.get()); } - this.bufferCopy = byteBuffer.array(); + bufferCopy = byteBuffer.array(); } @@ -88,7 +88,7 @@ public ReadableSoundBuffer(ShortBuffer pcm, int channels, int sampleRate, int bi */ public ReadableSoundBuffer(byte[] pcm, int channels, int sampleRate, int bitsPerSample, PcmDataType pcmDataType, int blockAlign) { super(pcm, channels, sampleRate, bitsPerSample, pcmDataType, blockAlign); - this.bufferCopy = pcm; + bufferCopy = pcm; } @@ -99,7 +99,7 @@ public ReadableSoundBuffer(byte[] pcm, int channels, int sampleRate, int bitsPer * @return a copy of the audio data */ public byte[] getAudioData() { - return this.bufferCopy; + return bufferCopy; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/ReadableSoundBufferLoader.java b/core/src/main/java/de/pottgames/tuningfork/ReadableSoundBufferLoader.java index 037626b..d4d0f8b 100644 --- a/core/src/main/java/de/pottgames/tuningfork/ReadableSoundBufferLoader.java +++ b/core/src/main/java/de/pottgames/tuningfork/ReadableSoundBufferLoader.java @@ -42,14 +42,14 @@ public ReadableSoundBufferLoader(FileHandleResolver resolver) { private void reset() { - this.asset = null; + asset = null; } @SuppressWarnings("rawtypes") @Override public Array getDependencies(String fileName, FileHandle file, ReadableSoundBufferLoaderParameter parameter) { - return this.dependencies; + return dependencies; } @@ -71,22 +71,22 @@ public void loadAsync(AssetManager manager, String fileName, FileHandle file, Re } switch (type) { case FLAC: - this.asset = reverse ? FlacLoader.loadReadableReverse(file) : FlacLoader.loadReadable(file); + asset = reverse ? FlacLoader.loadReadableReverse(file) : FlacLoader.loadReadable(file); break; case OGG: - this.asset = reverse ? OggLoader.loadReadableReverse(file) : OggLoader.loadReadable(file); + asset = reverse ? OggLoader.loadReadableReverse(file) : OggLoader.loadReadable(file); break; case WAV: - this.asset = reverse ? WaveLoader.loadReadableReverse(file) : WaveLoader.loadReadable(file); + asset = reverse ? WaveLoader.loadReadableReverse(file) : WaveLoader.loadReadable(file); break; case MP3: - this.asset = reverse ? Mp3Loader.loadReadableReverse(file) : Mp3Loader.loadReadable(file); + asset = reverse ? Mp3Loader.loadReadableReverse(file) : Mp3Loader.loadReadable(file); break; case AIFF: - this.asset = reverse ? AiffLoader.loadReadableReverse(file) : AiffLoader.loadReadable(file); + asset = reverse ? AiffLoader.loadReadableReverse(file) : AiffLoader.loadReadable(file); break; case QOA: - this.asset = reverse ? QoaLoader.loadReadableReverse(file) : QoaLoader.loadReadable(file); + asset = reverse ? QoaLoader.loadReadableReverse(file) : QoaLoader.loadReadable(file); break; } } @@ -94,8 +94,8 @@ public void loadAsync(AssetManager manager, String fileName, FileHandle file, Re @Override public ReadableSoundBuffer loadSync(AssetManager manager, String fileName, FileHandle file, ReadableSoundBufferLoaderParameter parameter) { - final ReadableSoundBuffer result = this.asset; - this.reset(); + final ReadableSoundBuffer result = asset; + reset(); return result; } diff --git a/core/src/main/java/de/pottgames/tuningfork/Reverb.java b/core/src/main/java/de/pottgames/tuningfork/Reverb.java index f609857..17afff9 100644 --- a/core/src/main/java/de/pottgames/tuningfork/Reverb.java +++ b/core/src/main/java/de/pottgames/tuningfork/Reverb.java @@ -144,26 +144,26 @@ public class Reverb extends SoundEffectData { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_REVERB); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DENSITY, this.density); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DIFFUSION, this.diffusion); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_GAIN, this.gain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_GAINHF, this.gainHf); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DECAY_TIME, this.decayTime); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DECAY_HFRATIO, this.decayHfRatio); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_REFLECTIONS_GAIN, this.reflectionsGain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_REFLECTIONS_DELAY, this.reflectionsDelay); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_LATE_REVERB_GAIN, this.lateReverbGain); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_LATE_REVERB_DELAY, this.lateReverbDelay); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_AIR_ABSORPTION_GAINHF, this.airAbsorptionGainHf); - EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_ROOM_ROLLOFF_FACTOR, this.roomRolloffFactor); - EXTEfx.alEffecti(effectId, EXTEfx.AL_REVERB_DECAY_HFLIMIT, this.decayHfLimit ? AL10.AL_TRUE : AL10.AL_FALSE); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DENSITY, density); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DIFFUSION, diffusion); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_GAIN, gain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_GAINHF, gainHf); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DECAY_TIME, decayTime); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_DECAY_HFRATIO, decayHfRatio); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_REFLECTIONS_GAIN, reflectionsGain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_REFLECTIONS_DELAY, reflectionsDelay); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_LATE_REVERB_GAIN, lateReverbGain); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_LATE_REVERB_DELAY, lateReverbDelay); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_AIR_ABSORPTION_GAINHF, airAbsorptionGainHf); + EXTEfx.alEffectf(effectId, EXTEfx.AL_REVERB_ROOM_ROLLOFF_FACTOR, roomRolloffFactor); + EXTEfx.alEffecti(effectId, EXTEfx.AL_REVERB_DECAY_HFLIMIT, decayHfLimit ? AL10.AL_TRUE : AL10.AL_FALSE); } @Override public int hashCode() { - return Objects.hash(this.airAbsorptionGainHf, this.decayHfLimit, this.decayHfRatio, this.decayTime, this.density, this.diffusion, this.gain, - this.gainHf, this.lateReverbDelay, this.lateReverbGain, this.reflectionsDelay, this.reflectionsGain, this.roomRolloffFactor); + return Objects.hash(airAbsorptionGainHf, decayHfLimit, decayHfRatio, decayTime, density, diffusion, gain, gainHf, lateReverbDelay, lateReverbGain, + reflectionsDelay, reflectionsGain, roomRolloffFactor); } @@ -179,27 +179,26 @@ public boolean equals(Object obj) { return false; } final Reverb other = (Reverb) obj; - return Float.floatToIntBits(this.airAbsorptionGainHf) == Float.floatToIntBits(other.airAbsorptionGainHf) && this.decayHfLimit == other.decayHfLimit - && Float.floatToIntBits(this.decayHfRatio) == Float.floatToIntBits(other.decayHfRatio) - && Float.floatToIntBits(this.decayTime) == Float.floatToIntBits(other.decayTime) - && Float.floatToIntBits(this.density) == Float.floatToIntBits(other.density) - && Float.floatToIntBits(this.diffusion) == Float.floatToIntBits(other.diffusion) - && Float.floatToIntBits(this.gain) == Float.floatToIntBits(other.gain) - && Float.floatToIntBits(this.gainHf) == Float.floatToIntBits(other.gainHf) - && Float.floatToIntBits(this.lateReverbDelay) == Float.floatToIntBits(other.lateReverbDelay) - && Float.floatToIntBits(this.lateReverbGain) == Float.floatToIntBits(other.lateReverbGain) - && Float.floatToIntBits(this.reflectionsDelay) == Float.floatToIntBits(other.reflectionsDelay) - && Float.floatToIntBits(this.reflectionsGain) == Float.floatToIntBits(other.reflectionsGain) - && Float.floatToIntBits(this.roomRolloffFactor) == Float.floatToIntBits(other.roomRolloffFactor); + return Float.floatToIntBits(airAbsorptionGainHf) == Float.floatToIntBits(other.airAbsorptionGainHf) && decayHfLimit == other.decayHfLimit + && Float.floatToIntBits(decayHfRatio) == Float.floatToIntBits(other.decayHfRatio) + && Float.floatToIntBits(decayTime) == Float.floatToIntBits(other.decayTime) + && Float.floatToIntBits(density) == Float.floatToIntBits(other.density) + && Float.floatToIntBits(diffusion) == Float.floatToIntBits(other.diffusion) && Float.floatToIntBits(gain) == Float.floatToIntBits(other.gain) + && Float.floatToIntBits(gainHf) == Float.floatToIntBits(other.gainHf) + && Float.floatToIntBits(lateReverbDelay) == Float.floatToIntBits(other.lateReverbDelay) + && Float.floatToIntBits(lateReverbGain) == Float.floatToIntBits(other.lateReverbGain) + && Float.floatToIntBits(reflectionsDelay) == Float.floatToIntBits(other.reflectionsDelay) + && Float.floatToIntBits(reflectionsGain) == Float.floatToIntBits(other.reflectionsGain) + && Float.floatToIntBits(roomRolloffFactor) == Float.floatToIntBits(other.roomRolloffFactor); } @Override public String toString() { - return "Reverb [density=" + this.density + ", diffusion=" + this.diffusion + ", gain=" + this.gain + ", gainHf=" + this.gainHf + ", decayTime=" - + this.decayTime + ", decayHfRatio=" + this.decayHfRatio + ", reflectionsGain=" + this.reflectionsGain + ", reflectionsDelay=" - + this.reflectionsDelay + ", lateReverbGain=" + this.lateReverbGain + ", lateReverbDelay=" + this.lateReverbDelay + ", airAbsorptionGainHf=" - + this.airAbsorptionGainHf + ", roomRolloffFactor=" + this.roomRolloffFactor + ", decayHfLimit=" + this.decayHfLimit + "]"; + return "Reverb [density=" + density + ", diffusion=" + diffusion + ", gain=" + gain + ", gainHf=" + gainHf + ", decayTime=" + decayTime + + ", decayHfRatio=" + decayHfRatio + ", reflectionsGain=" + reflectionsGain + ", reflectionsDelay=" + reflectionsDelay + ", lateReverbGain=" + + lateReverbGain + ", lateReverbDelay=" + lateReverbDelay + ", airAbsorptionGainHf=" + airAbsorptionGainHf + ", roomRolloffFactor=" + + roomRolloffFactor + ", decayHfLimit=" + decayHfLimit + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/RingModulator.java b/core/src/main/java/de/pottgames/tuningfork/RingModulator.java index 8f91f0b..97f6ab8 100644 --- a/core/src/main/java/de/pottgames/tuningfork/RingModulator.java +++ b/core/src/main/java/de/pottgames/tuningfork/RingModulator.java @@ -77,15 +77,15 @@ public static RingModulator fastTremolo() { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_RING_MODULATOR); - EXTEfx.alEffectf(effectId, EXTEfx.AL_RING_MODULATOR_FREQUENCY, this.frequency); - EXTEfx.alEffectf(effectId, EXTEfx.AL_RING_MODULATOR_HIGHPASS_CUTOFF, this.highpassCutoff); - EXTEfx.alEffecti(effectId, EXTEfx.AL_RING_MODULATOR_WAVEFORM, this.waveform); + EXTEfx.alEffectf(effectId, EXTEfx.AL_RING_MODULATOR_FREQUENCY, frequency); + EXTEfx.alEffectf(effectId, EXTEfx.AL_RING_MODULATOR_HIGHPASS_CUTOFF, highpassCutoff); + EXTEfx.alEffecti(effectId, EXTEfx.AL_RING_MODULATOR_WAVEFORM, waveform); } @Override public int hashCode() { - return Objects.hash(this.frequency, this.highpassCutoff, this.waveform); + return Objects.hash(frequency, highpassCutoff, waveform); } @@ -101,14 +101,14 @@ public boolean equals(Object obj) { return false; } final RingModulator other = (RingModulator) obj; - return Float.floatToIntBits(this.frequency) == Float.floatToIntBits(other.frequency) - && Float.floatToIntBits(this.highpassCutoff) == Float.floatToIntBits(other.highpassCutoff) && this.waveform == other.waveform; + return Float.floatToIntBits(frequency) == Float.floatToIntBits(other.frequency) + && Float.floatToIntBits(highpassCutoff) == Float.floatToIntBits(other.highpassCutoff) && waveform == other.waveform; } @Override public String toString() { - return "RingModulator [frequency=" + this.frequency + ", highpassCutoff=" + this.highpassCutoff + ", waveform=" + this.waveform + "]"; + return "RingModulator [frequency=" + frequency + ", highpassCutoff=" + highpassCutoff + ", waveform=" + waveform + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/SoundBuffer.java b/core/src/main/java/de/pottgames/tuningfork/SoundBuffer.java index ab5def7..644a4ac 100644 --- a/core/src/main/java/de/pottgames/tuningfork/SoundBuffer.java +++ b/core/src/main/java/de/pottgames/tuningfork/SoundBuffer.java @@ -82,17 +82,17 @@ public SoundBuffer(byte[] pcm, int channels, int sampleRate, int bitsPerSample, * @param blockAlign the block alignment (currently only used for MS ADPCM data) */ public SoundBuffer(ShortBuffer pcm, int channels, int sampleRate, int bitsPerSample, PcmDataType pcmDataType, int blockAlign) { - this.audio = Audio.get(); - this.logger = this.audio.getLogger(); - this.errorLogger = new ErrorLogger(this.getClass(), this.logger); + audio = Audio.get(); + logger = audio.getLogger(); + errorLogger = new ErrorLogger(this.getClass(), logger); - this.pcmFormat = PcmFormat.determineFormat(channels, bitsPerSample, pcmDataType); - if (this.pcmFormat == null) { + pcmFormat = PcmFormat.determineFormat(channels, bitsPerSample, pcmDataType); + if (pcmFormat == null) { throw new TuningForkRuntimeException("Unsupported pcm format - channels: " + channels + ", sample depth: " + bitsPerSample); } - this.bufferId = this.generateBufferAndUpload(pcm, blockAlign, sampleRate); - this.samplesPerChannel = this.fetchSamplesPerChannel(); - this.duration = this.fetchDuration(); + bufferId = generateBufferAndUpload(pcm, blockAlign, sampleRate); + samplesPerChannel = fetchSamplesPerChannel(); + duration = fetchDuration(); } @@ -112,9 +112,9 @@ public SoundBuffer(ShortBuffer pcm, int channels, int sampleRate, int bitsPerSam * @param blockAlign the block alignment (currently only used for MS ADPCM data) */ public SoundBuffer(byte[] pcm, int channels, int sampleRate, int bitsPerSample, PcmDataType pcmDataType, int blockAlign) { - this.audio = Audio.get(); - this.logger = this.audio.getLogger(); - this.errorLogger = new ErrorLogger(this.getClass(), this.logger); + audio = Audio.get(); + logger = audio.getLogger(); + errorLogger = new ErrorLogger(this.getClass(), logger); // PCM ARRAY TO TEMP BUFFER final ByteBuffer buffer = ByteBuffer.allocateDirect(pcm.length); @@ -122,14 +122,14 @@ public SoundBuffer(byte[] pcm, int channels, int sampleRate, int bitsPerSample, buffer.put(pcm); buffer.flip(); - this.pcmFormat = PcmFormat.determineFormat(channels, bitsPerSample, pcmDataType); - if (this.pcmFormat == null) { + pcmFormat = PcmFormat.determineFormat(channels, bitsPerSample, pcmDataType); + if (pcmFormat == null) { throw new TuningForkRuntimeException("Unsupported pcm format - channels: " + channels + ", sample depth: " + bitsPerSample); } - this.bufferId = this.generateBufferAndUpload(buffer.asShortBuffer(), blockAlign, sampleRate); - this.samplesPerChannel = this.fetchSamplesPerChannel(); + bufferId = generateBufferAndUpload(buffer.asShortBuffer(), blockAlign, sampleRate); + samplesPerChannel = fetchSamplesPerChannel(); - this.duration = this.fetchDuration(); + duration = fetchDuration(); } @@ -138,10 +138,10 @@ protected int generateBufferAndUpload(ShortBuffer pcm, int blockAlign, int sampl if (blockAlign > 0) { AL11.alBufferi(bufferId, SOFTBlockAlignment.AL_UNPACK_BLOCK_ALIGNMENT_SOFT, blockAlign); } - AL10.alBufferData(bufferId, this.pcmFormat.getAlId(), pcm, sampleRate); + AL10.alBufferData(bufferId, pcmFormat.getAlId(), pcm, sampleRate); - if (!this.errorLogger.checkLogError("Failed to create the SoundBuffer")) { - this.logger.debug(this.getClass(), "SoundBuffer successfully created"); + if (!errorLogger.checkLogError("Failed to create the SoundBuffer")) { + logger.debug(this.getClass(), "SoundBuffer successfully created"); } return bufferId; @@ -149,12 +149,12 @@ protected int generateBufferAndUpload(ShortBuffer pcm, int blockAlign, int sampl protected int fetchSamplesPerChannel() { - return AL10.alGetBufferi(this.bufferId, SOFTBufferLengthQuery.AL_SAMPLE_LENGTH_SOFT); + return AL10.alGetBufferi(bufferId, SOFTBufferLengthQuery.AL_SAMPLE_LENGTH_SOFT); } protected float fetchDuration() { - return AL10.alGetBufferf(this.bufferId, SOFTBufferLengthQuery.AL_SEC_LENGTH_SOFT); + return AL10.alGetBufferf(bufferId, SOFTBufferLengthQuery.AL_SEC_LENGTH_SOFT); } @@ -181,19 +181,19 @@ public void setLoopPoints(float start, float end) { throw new TuningForkRuntimeException("Invalid loop points: start and end must not be < 0"); } - int startSample = (int) (start / this.duration * this.samplesPerChannel); - startSample = MathUtils.clamp(startSample, 0, this.samplesPerChannel - 1); - int endSample = (int) (end / this.duration * this.samplesPerChannel); - endSample = MathUtils.clamp(endSample, 1, this.samplesPerChannel); + int startSample = (int) (start / duration * samplesPerChannel); + startSample = MathUtils.clamp(startSample, 0, samplesPerChannel - 1); + int endSample = (int) (end / duration * samplesPerChannel); + endSample = MathUtils.clamp(endSample, 1, samplesPerChannel); try (MemoryStack stack = MemoryStack.stackPush()) { final IntBuffer params = stack.mallocInt(2); params.put(0, startSample); params.put(1, endSample); - AL11.alBufferiv(this.bufferId, SOFTLoopPoints.AL_LOOP_POINTS_SOFT, params); + AL11.alBufferiv(bufferId, SOFTLoopPoints.AL_LOOP_POINTS_SOFT, params); } - this.errorLogger.checkLogError("Error setting loop points on the buffer"); + errorLogger.checkLogError("Error setting loop points on the buffer"); } @@ -214,15 +214,15 @@ public float[] getLoopPoints() { try (MemoryStack stack = MemoryStack.stackPush()) { final IntBuffer params = stack.mallocInt(2); - AL11.alGetBufferiv(this.bufferId, SOFTLoopPoints.AL_LOOP_POINTS_SOFT, params); + AL11.alGetBufferiv(bufferId, SOFTLoopPoints.AL_LOOP_POINTS_SOFT, params); startSample = params.get(0); endSample = params.get(1); } - this.loopPointCache[0] = (float) startSample / this.samplesPerChannel * this.duration; - this.loopPointCache[1] = (float) endSample / this.samplesPerChannel * this.duration; + loopPointCache[0] = (float) startSample / samplesPerChannel * duration; + loopPointCache[1] = (float) endSample / samplesPerChannel * duration; - return this.loopPointCache; + return loopPointCache; } @@ -230,7 +230,7 @@ public float[] getLoopPoints() { * Plays the sound. */ public void play() { - this.audio.play(this); + audio.play(this); } @@ -242,10 +242,10 @@ public void play() { */ public void playAtTime(long time) { if (time < 0) { - this.logger.error(this.getClass(), "Invalid time parameter on playAtTime(): " + time); + logger.error(this.getClass(), "Invalid time parameter on playAtTime(): " + time); return; } - this.audio.playAtTime(this, time); + audio.playAtTime(this, time); } @@ -255,7 +255,7 @@ public void playAtTime(long time) { * @param effect the sound effect */ public void play(SoundEffect effect) { - this.audio.play(this, effect); + audio.play(this, effect); } @@ -265,7 +265,7 @@ public void play(SoundEffect effect) { * @param volume in the range of 0.0 - 1.0 with 0 being silent and 1 being the maximum volume. (default 1) */ public void play(float volume) { - this.audio.play(this, volume); + audio.play(this, volume); } @@ -276,7 +276,7 @@ public void play(float volume) { * @param effect the sound effect */ public void play(float volume, SoundEffect effect) { - this.audio.play(this, volume, effect); + audio.play(this, volume, effect); } @@ -287,7 +287,7 @@ public void play(float volume, SoundEffect effect) { * @param pitch in the range of 0.5 - 2.0 with values < 1 making the sound slower and values > 1 making it faster (default 1) */ public void play(float volume, float pitch) { - this.audio.play(this, volume, pitch); + audio.play(this, volume, pitch); } @@ -300,7 +300,7 @@ public void play(float volume, float pitch) { * @param highFreqVolume range: 0 - 1, 0 means completely silent, 1 means full loudness */ public void play(float volume, float pitch, float lowFreqVolume, float highFreqVolume) { - this.audio.play(this, volume, pitch, lowFreqVolume, highFreqVolume); + audio.play(this, volume, pitch, lowFreqVolume, highFreqVolume); } @@ -312,7 +312,7 @@ public void play(float volume, float pitch, float lowFreqVolume, float highFreqV * @param effect the sound effect */ public void play(float volume, float pitch, SoundEffect effect) { - this.audio.play(this, volume, pitch, effect); + audio.play(this, volume, pitch, effect); } @@ -324,7 +324,7 @@ public void play(float volume, float pitch, SoundEffect effect) { * @param pan in the range of -1.0 (full left) to 1.0 (full right). (default center 0.0) */ public void play(float volume, float pitch, float pan) { - this.audio.play(this, volume, pitch, pan); + audio.play(this, volume, pitch, pan); } @@ -337,7 +337,7 @@ public void play(float volume, float pitch, float pan) { * @param effect the sound effect */ public void play(float volume, float pitch, float pan, SoundEffect effect) { - this.audio.play(this, volume, pitch, pan, effect); + audio.play(this, volume, pitch, pan, effect); } @@ -347,7 +347,7 @@ public void play(float volume, float pitch, float pan, SoundEffect effect) { * @param position the position in 3D space */ public void play3D(Vector3 position) { - this.audio.play3D(this, position); + audio.play3D(this, position); } @@ -359,7 +359,7 @@ public void play3D(Vector3 position) { * @param highFreqVolume range: 0 - 1, 0 means completely silent, 1 means full loudness */ public void play3D(Vector3 position, float lowFreqVolume, float highFreqVolume) { - this.audio.play3D(this, position, lowFreqVolume, highFreqVolume); + audio.play3D(this, position, lowFreqVolume, highFreqVolume); } @@ -370,7 +370,7 @@ public void play3D(Vector3 position, float lowFreqVolume, float highFreqVolume) * @param effect the sound effect */ public void play3D(Vector3 position, SoundEffect effect) { - this.audio.play3D(this, position, effect); + audio.play3D(this, position, effect); } @@ -383,7 +383,7 @@ public void play3D(Vector3 position, SoundEffect effect) { * @param effect the sound effect */ public void play3D(Vector3 position, float lowFreqVolume, float highFreqVolume, SoundEffect effect) { - this.audio.play3D(this, position, lowFreqVolume, highFreqVolume, effect); + audio.play3D(this, position, lowFreqVolume, highFreqVolume, effect); } @@ -394,7 +394,7 @@ public void play3D(Vector3 position, float lowFreqVolume, float highFreqVolume, * @param position the position in 3D space */ public void play3D(float volume, Vector3 position) { - this.audio.play3D(this, volume, position); + audio.play3D(this, volume, position); } @@ -407,7 +407,7 @@ public void play3D(float volume, Vector3 position) { * @param highFreqVolume range: 0 - 1, 0 means completely silent, 1 means full loudness */ public void play3D(float volume, Vector3 position, float lowFreqVolume, float highFreqVolume) { - this.audio.play3D(this, volume, position, lowFreqVolume, highFreqVolume); + audio.play3D(this, volume, position, lowFreqVolume, highFreqVolume); } @@ -419,7 +419,7 @@ public void play3D(float volume, Vector3 position, float lowFreqVolume, float hi * @param effect the sound effect */ public void play3D(float volume, Vector3 position, SoundEffect effect) { - this.audio.play3D(this, volume, position, effect); + audio.play3D(this, volume, position, effect); } @@ -431,7 +431,7 @@ public void play3D(float volume, Vector3 position, SoundEffect effect) { * @param position the position in 3D space */ public void play3D(float volume, float pitch, Vector3 position) { - this.audio.play3D(this, volume, pitch, position); + audio.play3D(this, volume, pitch, position); } @@ -444,12 +444,12 @@ public void play3D(float volume, float pitch, Vector3 position) { * @param effect the effect */ public void play3D(float volume, float pitch, Vector3 position, SoundEffect effect) { - this.audio.play3D(this, volume, pitch, position, effect); + audio.play3D(this, volume, pitch, position, effect); } int getBufferId() { - return this.bufferId; + return bufferId; } @@ -459,7 +459,7 @@ int getBufferId() { * @return the PcmFormat */ public PcmFormat getPcmFormat() { - return this.pcmFormat; + return pcmFormat; } @@ -469,16 +469,16 @@ public PcmFormat getPcmFormat() { * @return the playback duration in seconds. */ public float getDuration() { - return this.duration; + return duration; } @Override public void dispose() { Audio.get().onBufferDisposal(this); - AL10.alDeleteBuffers(this.bufferId); - if (!this.errorLogger.checkLogError("Failed to dispose the SoundBuffer")) { - this.logger.debug(this.getClass(), "SoundBuffer successfully disposed"); + AL10.alDeleteBuffers(bufferId); + if (!errorLogger.checkLogError("Failed to dispose the SoundBuffer")) { + logger.debug(this.getClass(), "SoundBuffer successfully disposed"); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/SoundBufferLoader.java b/core/src/main/java/de/pottgames/tuningfork/SoundBufferLoader.java index 8c91822..bbe750f 100644 --- a/core/src/main/java/de/pottgames/tuningfork/SoundBufferLoader.java +++ b/core/src/main/java/de/pottgames/tuningfork/SoundBufferLoader.java @@ -42,14 +42,14 @@ public SoundBufferLoader(FileHandleResolver resolver) { private void reset() { - this.asset = null; + asset = null; } @SuppressWarnings("rawtypes") @Override public Array getDependencies(String fileName, FileHandle file, SoundBufferLoaderParameter parameter) { - return this.dependencies; + return dependencies; } @@ -71,22 +71,22 @@ public void loadAsync(AssetManager manager, String fileName, FileHandle file, So } switch (type) { case FLAC: - this.asset = reverse ? FlacLoader.loadReverse(file) : FlacLoader.load(file); + asset = reverse ? FlacLoader.loadReverse(file) : FlacLoader.load(file); break; case OGG: - this.asset = reverse ? OggLoader.loadReverse(file) : OggLoader.load(file); + asset = reverse ? OggLoader.loadReverse(file) : OggLoader.load(file); break; case WAV: - this.asset = reverse ? WaveLoader.loadReverse(file) : WaveLoader.load(file); + asset = reverse ? WaveLoader.loadReverse(file) : WaveLoader.load(file); break; case MP3: - this.asset = reverse ? Mp3Loader.loadReverse(file) : Mp3Loader.load(file); + asset = reverse ? Mp3Loader.loadReverse(file) : Mp3Loader.load(file); break; case AIFF: - this.asset = reverse ? AiffLoader.loadReverse(file) : AiffLoader.load(file); + asset = reverse ? AiffLoader.loadReverse(file) : AiffLoader.load(file); break; case QOA: - this.asset = reverse ? QoaLoader.loadReverse(file) : QoaLoader.load(file); + asset = reverse ? QoaLoader.loadReverse(file) : QoaLoader.load(file); break; } } @@ -94,8 +94,8 @@ public void loadAsync(AssetManager manager, String fileName, FileHandle file, So @Override public SoundBuffer loadSync(AssetManager manager, String fileName, FileHandle file, SoundBufferLoaderParameter parameter) { - final SoundBuffer result = this.asset; - this.reset(); + final SoundBuffer result = asset; + reset(); return result; } diff --git a/core/src/main/java/de/pottgames/tuningfork/SoundEffect.java b/core/src/main/java/de/pottgames/tuningfork/SoundEffect.java index d1f6d99..745b096 100644 --- a/core/src/main/java/de/pottgames/tuningfork/SoundEffect.java +++ b/core/src/main/java/de/pottgames/tuningfork/SoundEffect.java @@ -45,22 +45,22 @@ public class SoundEffect implements Disposable { * @see The wiki entry */ public SoundEffect(SoundEffectData data) { - this.logger = Audio.get().getLogger(); - this.errorLogger = new ErrorLogger(this.getClass(), this.logger); + logger = Audio.get().getLogger(); + errorLogger = new ErrorLogger(this.getClass(), logger); // CREATE AUX SLOT - this.auxSlotId = EXTEfx.alGenAuxiliaryEffectSlots(); - this.setEnvironmental(false); + auxSlotId = EXTEfx.alGenAuxiliaryEffectSlots(); + setEnvironmental(false); // CREATE EFFECT - this.effectId = EXTEfx.alGenEffects(); - data.apply(this.effectId); + effectId = EXTEfx.alGenEffects(); + data.apply(effectId); // SET EFFECT TO AUX SLOT - EXTEfx.alAuxiliaryEffectSloti(this.auxSlotId, EXTEfx.AL_EFFECTSLOT_EFFECT, this.effectId); + EXTEfx.alAuxiliaryEffectSloti(auxSlotId, EXTEfx.AL_EFFECTSLOT_EFFECT, effectId); - if (!this.errorLogger.checkLogError("Failed to create the SoundEffect")) { - this.logger.debug(this.getClass(), "SoundEffect successfully created"); + if (!errorLogger.checkLogError("Failed to create the SoundEffect")) { + logger.debug(this.getClass(), "SoundEffect successfully created"); } } @@ -74,11 +74,11 @@ public SoundEffect(SoundEffectData data) { */ public void updateEffect(SoundEffectData data) { // AL wants us to do it this way: detach effect from aux slot, re-attach altered effect to aux slot - EXTEfx.alAuxiliaryEffectSloti(this.auxSlotId, EXTEfx.AL_EFFECTSLOT_EFFECT, EXTEfx.AL_EFFECT_NULL); - data.apply(this.effectId); - EXTEfx.alAuxiliaryEffectSloti(this.auxSlotId, EXTEfx.AL_EFFECTSLOT_EFFECT, this.effectId); + EXTEfx.alAuxiliaryEffectSloti(auxSlotId, EXTEfx.AL_EFFECTSLOT_EFFECT, EXTEfx.AL_EFFECT_NULL); + data.apply(effectId); + EXTEfx.alAuxiliaryEffectSloti(auxSlotId, EXTEfx.AL_EFFECTSLOT_EFFECT, effectId); - this.errorLogger.checkLogError("Failed to update SoundEffect"); + errorLogger.checkLogError("Failed to update SoundEffect"); } @@ -89,10 +89,10 @@ public void updateEffect(SoundEffectData data) { * @param value whether this effect should be environmental or "pure" */ public void setEnvironmental(boolean value) { - EXTEfx.alAuxiliaryEffectSloti(this.auxSlotId, EXTEfx.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, value ? AL10.AL_TRUE : AL10.AL_FALSE); + EXTEfx.alAuxiliaryEffectSloti(auxSlotId, EXTEfx.AL_EFFECTSLOT_AUXILIARY_SEND_AUTO, value ? AL10.AL_TRUE : AL10.AL_FALSE); - if (!this.errorLogger.checkLogError("Something went wrong")) { - this.logger.trace(this.getClass(), "SoundEffect set to environmental"); + if (!errorLogger.checkLogError("Something went wrong")) { + logger.trace(this.getClass(), "SoundEffect set to environmental"); } } @@ -103,7 +103,7 @@ public void setEnvironmental(boolean value) { * @return true if attached, false otherwise */ public boolean isAttached() { - return !this.attachedSources.isEmpty(); + return !attachedSources.isEmpty(); } @@ -115,26 +115,26 @@ public boolean isAttached() { * @return true if the effect is attached to at least one source */ public boolean getAttachedSources(Array saveToList) { - if (this.attachedSources.isEmpty()) { + if (attachedSources.isEmpty()) { return false; } - saveToList.addAll(this.attachedSources); + saveToList.addAll(attachedSources); return true; } int getAuxSlotId() { - return this.auxSlotId; + return auxSlotId; } void addSource(SoundSource source) { - this.attachedSources.add(source); + attachedSources.add(source); } void removeSource(SoundSource source) { - this.attachedSources.removeValue(source, true); + attachedSources.removeValue(source, true); } @@ -143,15 +143,15 @@ void removeSource(SoundSource source) { */ @Override public void dispose() { - EXTEfx.alDeleteEffects(this.effectId); - for (final SoundSource source : this.attachedSources) { + EXTEfx.alDeleteEffects(effectId); + for (final SoundSource source : attachedSources) { source.onEffectDisposal(this); } - this.attachedSources.clear(); - EXTEfx.alDeleteAuxiliaryEffectSlots(this.auxSlotId); + attachedSources.clear(); + EXTEfx.alDeleteAuxiliaryEffectSlots(auxSlotId); - if (!this.errorLogger.checkLogError("Something went wrong")) { - this.logger.trace(this.getClass(), "SoundEffect successfully disposed"); + if (!errorLogger.checkLogError("Something went wrong")) { + logger.trace(this.getClass(), "SoundEffect successfully disposed"); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/SoundListener.java b/core/src/main/java/de/pottgames/tuningfork/SoundListener.java index f43a4ac..ed2e6e6 100644 --- a/core/src/main/java/de/pottgames/tuningfork/SoundListener.java +++ b/core/src/main/java/de/pottgames/tuningfork/SoundListener.java @@ -65,22 +65,22 @@ public SoundListener setPosition(float x, float y, float z) { public SoundListener setOrientation(Camera camera) { - this.tempVector.set(camera.direction); - this.tempVector.crs(camera.up); - this.tempVector.crs(camera.direction); - this.setOrientation(camera.direction, this.tempVector); + tempVector.set(camera.direction); + tempVector.crs(camera.up); + tempVector.crs(camera.direction); + this.setOrientation(camera.direction, tempVector); return this; } public SoundListener setOrientation(Vector3 at, Vector3 up) { - this.orientation[0] = at.x; - this.orientation[1] = at.y; - this.orientation[2] = at.z; - this.orientation[3] = up.x; - this.orientation[4] = up.y; - this.orientation[5] = up.z; - AL10.alListenerfv(AL10.AL_ORIENTATION, this.orientation); + orientation[0] = at.x; + orientation[1] = at.y; + orientation[2] = at.z; + orientation[3] = up.x; + orientation[4] = up.y; + orientation[5] = up.z; + AL10.alListenerfv(AL10.AL_ORIENTATION, orientation); return this; } diff --git a/core/src/main/java/de/pottgames/tuningfork/SoundSource.java b/core/src/main/java/de/pottgames/tuningfork/SoundSource.java index 1afea6e..d8877f6 100644 --- a/core/src/main/java/de/pottgames/tuningfork/SoundSource.java +++ b/core/src/main/java/de/pottgames/tuningfork/SoundSource.java @@ -49,25 +49,25 @@ public abstract class SoundSource { protected SoundSource() { final Audio audio = Audio.get(); - this.logger = audio.getLogger(); - this.errorLogger = new ErrorLogger(this.getClass(), this.logger); - this.effects = new SoundEffect[audio.getDevice().getNumberOfEffectSlots()]; + logger = audio.getLogger(); + errorLogger = new ErrorLogger(this.getClass(), logger); + effects = new SoundEffect[audio.getDevice().getNumberOfEffectSlots()]; - this.sourceId = AL10.alGenSources(); - AL10.alSourcef(this.sourceId, EXTEfx.AL_AIR_ABSORPTION_FACTOR, 1f); + sourceId = AL10.alGenSources(); + AL10.alSourcef(sourceId, EXTEfx.AL_AIR_ABSORPTION_FACTOR, 1f); - if (!this.errorLogger.checkLogError("Failed to create the SoundSource")) { - this.logger.trace(this.getClass(), "SoundSource successfully created"); + if (!errorLogger.checkLogError("Failed to create the SoundSource")) { + logger.trace(this.getClass(), "SoundSource successfully created"); } // SET DEFAULTS final AudioSettings defaultSettings = audio.getDefaultAudioSettings(); - this.setAttenuationFactor(defaultSettings.getAttenuationFactor()); - this.setAttenuationMinDistance(defaultSettings.getMinAttenuationDistance()); - this.setAttenuationMaxDistance(defaultSettings.getMaxAttenuationDistance()); - this.setVirtualization(defaultSettings.getVirtualization()); - this.setSpatialization(defaultSettings.getSpatialization()); - this.setResamplerByIndex(defaultSettings.getResamplerIndex()); + setAttenuationFactor(defaultSettings.getAttenuationFactor()); + setAttenuationMinDistance(defaultSettings.getMinAttenuationDistance()); + setAttenuationMaxDistance(defaultSettings.getMaxAttenuationDistance()); + setVirtualization(defaultSettings.getVirtualization()); + setSpatialization(defaultSettings.getSpatialization()); + setResamplerByIndex(defaultSettings.getResamplerIndex()); } @@ -77,7 +77,7 @@ protected SoundSource() { * @param volume in the range of 0.0 - 1.0 with 0 being silent and 1 being the maximum volume. (default 1) */ public void setVolume(float volume) { - AL10.alSourcef(this.sourceId, AL10.AL_GAIN, MathUtils.clamp(volume, 0f, 1f)); + AL10.alSourcef(sourceId, AL10.AL_GAIN, MathUtils.clamp(volume, 0f, 1f)); } @@ -87,7 +87,7 @@ public void setVolume(float volume) { * @return volume in the range of 0.0 - 1.0 with 0 being silent and 1 being the maximum volume */ public float getVolume() { - return AL10.alGetSourcef(this.sourceId, AL10.AL_GAIN); + return AL10.alGetSourcef(sourceId, AL10.AL_GAIN); } @@ -101,7 +101,7 @@ public void setPitch(float pitch) { if (pitch < 0f) { pitch = 0f; } - AL10.alSourcef(this.sourceId, AL10.AL_PITCH, pitch); + AL10.alSourcef(sourceId, AL10.AL_PITCH, pitch); } @@ -111,7 +111,7 @@ public void setPitch(float pitch) { * @return pitch in the range of 0.5 - 2.0 with values < 1 making the sound slower and values > 1 making it faster */ public float getPitch() { - return AL10.alGetSourcef(this.sourceId, AL10.AL_PITCH); + return AL10.alGetSourcef(sourceId, AL10.AL_PITCH); } @@ -119,8 +119,8 @@ public float getPitch() { * Starts the playback of this sound source. */ public void play() { - if (!this.isPlaying()) { - AL10.alSourcePlay(this.sourceId); + if (!isPlaying()) { + AL10.alSourcePlay(sourceId); } } @@ -133,7 +133,7 @@ public void play() { * @param relative true = relative, false = absolute */ public void setRelative(boolean relative) { - AL10.alSourcei(this.sourceId, AL10.AL_SOURCE_RELATIVE, relative ? AL10.AL_TRUE : AL10.AL_FALSE); + AL10.alSourcei(sourceId, AL10.AL_SOURCE_RELATIVE, relative ? AL10.AL_TRUE : AL10.AL_FALSE); } @@ -143,7 +143,7 @@ public void setRelative(boolean relative) { * @return relative */ public boolean isRelative() { - return AL10.alGetSourcei(this.sourceId, AL10.AL_SOURCE_RELATIVE) == AL10.AL_TRUE; + return AL10.alGetSourcei(sourceId, AL10.AL_SOURCE_RELATIVE) == AL10.AL_TRUE; } @@ -165,8 +165,8 @@ public void setPosition(Vector3 position) { * @param z z */ public void setPosition(float x, float y, float z) { - this.position.set(this.position); - AL10.alSource3f(this.sourceId, AL10.AL_POSITION, x, y, z); + position.set(position); + AL10.alSource3f(sourceId, AL10.AL_POSITION, x, y, z); } @@ -178,7 +178,7 @@ public void setPosition(float x, float y, float z) { * @return returns the saveTo parameter vector that contains the result */ public Vector3 getPosition(Vector3 saveTo) { - return saveTo.set(this.position); + return saveTo.set(position); } @@ -191,7 +191,7 @@ public Vector3 getPosition(Vector3 saveTo) { */ public void setRadius(float radius) { radius = MathUtils.clamp(radius, 0f, Float.MAX_VALUE); - AL10.alSourcef(this.sourceId, EXTSourceRadius.AL_SOURCE_RADIUS, radius); + AL10.alSourcef(sourceId, EXTSourceRadius.AL_SOURCE_RADIUS, radius); } @@ -201,7 +201,7 @@ public void setRadius(float radius) { * @return the radius */ public float getRadius() { - return AL10.alGetSourcef(this.sourceId, EXTSourceRadius.AL_SOURCE_RADIUS); + return AL10.alGetSourcef(sourceId, EXTSourceRadius.AL_SOURCE_RADIUS); } @@ -227,7 +227,7 @@ public void setSpeed(Vector3 speed) { * @param z the speed on the z-axis */ public void setSpeed(float x, float y, float z) { - AL10.alSource3f(this.sourceId, AL10.AL_VELOCITY, x, y, z); + AL10.alSource3f(sourceId, AL10.AL_VELOCITY, x, y, z); } @@ -242,12 +242,12 @@ public void setSpeed(float x, float y, float z) { * @param outOfConeVolume the volume of the sound source when outside of the cone */ public void makeDirectional(Vector3 direction, float coneInnerAngle, float coneOuterAngle, float outOfConeVolume) { - this.directional = true; - AL10.alSourcef(this.sourceId, AL10.AL_CONE_INNER_ANGLE, coneInnerAngle); - AL10.alSourcef(this.sourceId, AL10.AL_CONE_OUTER_ANGLE, coneOuterAngle); - AL10.alSourcef(this.sourceId, AL10.AL_CONE_OUTER_GAIN, outOfConeVolume); - this.setDirection(direction); - this.logger.trace(this.getClass(), "SoundSource successfully set to directional"); + directional = true; + AL10.alSourcef(sourceId, AL10.AL_CONE_INNER_ANGLE, coneInnerAngle); + AL10.alSourcef(sourceId, AL10.AL_CONE_OUTER_ANGLE, coneOuterAngle); + AL10.alSourcef(sourceId, AL10.AL_CONE_OUTER_GAIN, outOfConeVolume); + setDirection(direction); + logger.trace(this.getClass(), "SoundSource successfully set to directional"); } @@ -258,8 +258,8 @@ public void makeDirectional(Vector3 direction, float coneInnerAngle, float coneO * @param direction the direction */ public void setDirection(Vector3 direction) { - if (this.directional) { - AL10.alSource3f(this.sourceId, AL10.AL_DIRECTION, direction.x, direction.y, direction.z); + if (directional) { + AL10.alSource3f(sourceId, AL10.AL_DIRECTION, direction.x, direction.y, direction.z); } } @@ -268,9 +268,9 @@ public void setDirection(Vector3 direction) { * Makes this sound source omni-directional. This is the default, so you only need to call it if you have made the source directional earlier. */ public void makeOmniDirectional() { - this.directional = false; - AL10.alSource3f(this.sourceId, AL10.AL_DIRECTION, 0f, 0f, 0f); - this.logger.trace(this.getClass(), "SoundSource successfully set to omnidirectional"); + directional = false; + AL10.alSource3f(sourceId, AL10.AL_DIRECTION, 0f, 0f, 0f); + logger.trace(this.getClass(), "SoundSource successfully set to omnidirectional"); } @@ -280,7 +280,7 @@ public void makeOmniDirectional() { * @return directional = true, omni-directional = false */ public boolean isDirectional() { - return this.directional; + return directional; } @@ -288,7 +288,7 @@ public boolean isDirectional() { * Enables the distance attenuation of this sound source. */ public void enableAttenuation() { - AL10.alSourcef(this.sourceId, AL10.AL_ROLLOFF_FACTOR, this.attenuationFactor); + AL10.alSourcef(sourceId, AL10.AL_ROLLOFF_FACTOR, attenuationFactor); } @@ -296,7 +296,7 @@ public void enableAttenuation() { * Disables the distance attenuation of this sound source. */ public void disableAttenuation() { - AL10.alSourcef(this.sourceId, AL10.AL_ROLLOFF_FACTOR, 0f); + AL10.alSourcef(sourceId, AL10.AL_ROLLOFF_FACTOR, 0f); } @@ -307,8 +307,8 @@ public void disableAttenuation() { * @param rolloff (default depends on the attenuation model) */ public void setAttenuationFactor(float rolloff) { - this.attenuationFactor = rolloff; - AL10.alSourcef(this.sourceId, AL10.AL_ROLLOFF_FACTOR, rolloff); + attenuationFactor = rolloff; + AL10.alSourcef(sourceId, AL10.AL_ROLLOFF_FACTOR, rolloff); } @@ -319,7 +319,7 @@ public void setAttenuationFactor(float rolloff) { * @param minDistance (default depends on the attenuation model) */ public void setAttenuationMinDistance(float minDistance) { - AL10.alSourcef(this.sourceId, AL10.AL_REFERENCE_DISTANCE, minDistance); + AL10.alSourcef(sourceId, AL10.AL_REFERENCE_DISTANCE, minDistance); } @@ -330,7 +330,7 @@ public void setAttenuationMinDistance(float minDistance) { * @param maxDistance (default depends on the attenuation model) */ public void setAttenuationMaxDistance(float maxDistance) { - AL10.alSourcef(this.sourceId, AL10.AL_MAX_DISTANCE, maxDistance); + AL10.alSourcef(sourceId, AL10.AL_MAX_DISTANCE, maxDistance); } @@ -340,7 +340,7 @@ public void setAttenuationMaxDistance(float maxDistance) { * @return the attenuation factor (default depends on the attenuation model) */ public float getAttenuationFactor() { - return AL10.alGetSourcef(this.sourceId, AL10.AL_ROLLOFF_FACTOR); + return AL10.alGetSourcef(sourceId, AL10.AL_ROLLOFF_FACTOR); } @@ -350,7 +350,7 @@ public float getAttenuationFactor() { * @return the attenuation min distance (default depends on the attenuation model) */ public float getAttenuationMinDistance() { - return AL10.alGetSourcef(this.sourceId, AL10.AL_REFERENCE_DISTANCE); + return AL10.alGetSourcef(sourceId, AL10.AL_REFERENCE_DISTANCE); } @@ -360,7 +360,7 @@ public float getAttenuationMinDistance() { * @return the attenuation max distance (default depends on the attenuation model) */ public float getAttenuationMaxDistance() { - return AL10.alGetSourcef(this.sourceId, AL10.AL_MAX_DISTANCE); + return AL10.alGetSourcef(sourceId, AL10.AL_MAX_DISTANCE); } @@ -381,7 +381,7 @@ public float getAttenuationMaxDistance() { */ public void setVirtualization(Virtualization virtualization) { if (virtualization != null) { - AL10.alSourcei(this.sourceId, SOFTDirectChannels.AL_DIRECT_CHANNELS_SOFT, virtualization.getAlId()); + AL10.alSourcei(sourceId, SOFTDirectChannels.AL_DIRECT_CHANNELS_SOFT, virtualization.getAlId()); } } @@ -392,7 +392,7 @@ public void setVirtualization(Virtualization virtualization) { * @return the virtualization mode */ public Virtualization getVirtualization() { - final int alId = AL10.alGetSourcei(this.sourceId, SOFTDirectChannels.AL_DIRECT_CHANNELS_SOFT); + final int alId = AL10.alGetSourcei(sourceId, SOFTDirectChannels.AL_DIRECT_CHANNELS_SOFT); return Virtualization.getByAlId(alId); } @@ -404,7 +404,7 @@ public Virtualization getVirtualization() { */ public void setSpatialization(Spatialization spatialization) { if (spatialization != null) { - AL10.alSourcei(this.sourceId, SOFTSourceSpatialize.AL_SOURCE_SPATIALIZE_SOFT, spatialization.getAlId()); + AL10.alSourcei(sourceId, SOFTSourceSpatialize.AL_SOURCE_SPATIALIZE_SOFT, spatialization.getAlId()); } } @@ -415,7 +415,7 @@ public void setSpatialization(Spatialization spatialization) { * @return the spatialization mode */ public Spatialization getSpatialization() { - final int alId = AL10.alGetSourcei(this.sourceId, SOFTSourceSpatialize.AL_SOURCE_SPATIALIZE_SOFT); + final int alId = AL10.alGetSourcei(sourceId, SOFTSourceSpatialize.AL_SOURCE_SPATIALIZE_SOFT); return Spatialization.getByAlId(alId); } @@ -426,7 +426,7 @@ public Spatialization getSpatialization() { * @param looping true for looped playback */ public void setLooping(boolean looping) { - AL10.alSourcei(this.sourceId, AL10.AL_LOOPING, looping ? AL10.AL_TRUE : AL10.AL_FALSE); + AL10.alSourcei(sourceId, AL10.AL_LOOPING, looping ? AL10.AL_TRUE : AL10.AL_FALSE); } @@ -436,7 +436,7 @@ public void setLooping(boolean looping) { * @return true when this sound source is playing, false otherwise. */ public boolean isPlaying() { - return AL10.alGetSourcei(this.sourceId, AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING; + return AL10.alGetSourcei(sourceId, AL10.AL_SOURCE_STATE) == AL10.AL_PLAYING; } @@ -446,7 +446,7 @@ public boolean isPlaying() { * @return true when this sound source is paused, false otherwise. */ public boolean isPaused() { - return AL10.alGetSourcei(this.sourceId, AL10.AL_SOURCE_STATE) == AL10.AL_PAUSED; + return AL10.alGetSourcei(sourceId, AL10.AL_SOURCE_STATE) == AL10.AL_PAUSED; } @@ -454,7 +454,7 @@ public boolean isPaused() { * Pauses the sound playback. */ public void pause() { - AL10.alSourcePause(this.sourceId); + AL10.alSourcePause(sourceId); } @@ -462,7 +462,7 @@ public void pause() { * Stops the sound playback and rewinds it. */ public void stop() { - AL10.alSourceRewind(this.sourceId); + AL10.alSourceRewind(sourceId); } @@ -473,14 +473,14 @@ public void stop() { * @param highFreqVolume range: 0 - 1, 0 means completely silent, 1 means full loudness */ public void setFilter(float lowFreqVolume, float highFreqVolume) { - this.directFilter = lowFreqVolume != 1f || highFreqVolume != 1f; + directFilter = lowFreqVolume != 1f || highFreqVolume != 1f; Filter filter = null; - if (this.directFilter) { + if (directFilter) { filter = Audio.get().publicFilter; filter.setLowFrequencyVolume(lowFreqVolume); filter.setHighFrequencyVolume(highFreqVolume); } - AL10.alSourcei(this.sourceId, EXTEfx.AL_DIRECT_FILTER, filter != null ? filter.getId() : EXTEfx.AL_FILTER_NULL); + AL10.alSourcei(sourceId, EXTEfx.AL_DIRECT_FILTER, filter != null ? filter.getId() : EXTEfx.AL_FILTER_NULL); } @@ -490,7 +490,7 @@ public void setFilter(float lowFreqVolume, float highFreqVolume) { * @return result */ public boolean hasFilter() { - return this.directFilter; + return directFilter; } @@ -525,25 +525,25 @@ public SoundEffect attachEffect(SoundEffect effect) { * @return the effect that was kicked out or null otherwise */ public SoundEffect attachEffect(SoundEffect effect, float lowFreqVolume, float highFreqVolume) { - if (this.effects.length == 0) { - this.logger.error(this.getClass(), "Attaching an effect failed: no effect slots available, check your AudioDeviceConfig."); + if (effects.length == 0) { + logger.error(this.getClass(), "Attaching an effect failed: no effect slots available, check your AudioDeviceConfig."); return null; } SoundEffect result = null; // CANCEL IF THE EFFECT IS ALREADY ATTACHED TO THIS SOURCE - for (final SoundEffect effect2 : this.effects) { + for (final SoundEffect effect2 : effects) { if (effect2 == effect) { return null; } } // REMOVE OLD EFFECT IF ANY - if (this.effects[this.nextSoundEffectSendId] != null) { - this.effects[this.nextSoundEffectSendId].removeSource(this); - result = this.effects[this.nextSoundEffectSendId]; - this.effects[this.nextSoundEffectSendId] = null; + if (effects[nextSoundEffectSendId] != null) { + effects[nextSoundEffectSendId].removeSource(this); + result = effects[nextSoundEffectSendId]; + effects[nextSoundEffectSendId] = null; } // ADD EFFECT @@ -554,14 +554,14 @@ public SoundEffect attachEffect(SoundEffect effect, float lowFreqVolume, float h filter.setHighFrequencyVolume(highFreqVolume); } final int filterHandle = filter != null ? filter.getId() : EXTEfx.AL_FILTER_NULL; - AL11.alSource3i(this.sourceId, EXTEfx.AL_AUXILIARY_SEND_FILTER, effect.getAuxSlotId(), this.nextSoundEffectSendId, filterHandle); - this.effects[this.nextSoundEffectSendId] = effect; + AL11.alSource3i(sourceId, EXTEfx.AL_AUXILIARY_SEND_FILTER, effect.getAuxSlotId(), nextSoundEffectSendId, filterHandle); + effects[nextSoundEffectSendId] = effect; effect.addSource(this); // SET NEXT SOUND EFFECT SEND ID - this.nextSoundEffectSendId++; - if (this.nextSoundEffectSendId >= this.effects.length) { - this.nextSoundEffectSendId = 0; + nextSoundEffectSendId++; + if (nextSoundEffectSendId >= effects.length) { + nextSoundEffectSendId = 0; } return result; @@ -576,11 +576,11 @@ public SoundEffect attachEffect(SoundEffect effect, float lowFreqVolume, float h * @return true if the effect was successfully detached, false if the effect isn't attached to this source (anymore) */ public boolean detachEffect(SoundEffect effect) { - for (int i = 0; i < this.effects.length; i++) { - if (this.effects[i] == effect) { - AL11.alSource3i(this.sourceId, EXTEfx.AL_AUXILIARY_SEND_FILTER, EXTEfx.AL_EFFECTSLOT_NULL, i, EXTEfx.AL_FILTER_NULL); - this.effects[i].removeSource(this); - this.effects[i] = null; + for (int i = 0; i < effects.length; i++) { + if (effects[i] == effect) { + AL11.alSource3i(sourceId, EXTEfx.AL_AUXILIARY_SEND_FILTER, EXTEfx.AL_EFFECTSLOT_NULL, i, EXTEfx.AL_FILTER_NULL); + effects[i].removeSource(this); + effects[i] = null; return true; } } @@ -593,21 +593,21 @@ public boolean detachEffect(SoundEffect effect) { * Detaches all currently attached sound effects from this sound source. */ public void detachAllEffects() { - for (int i = 0; i < this.effects.length; i++) { - if (this.effects[i] != null) { - AL11.alSource3i(this.sourceId, EXTEfx.AL_AUXILIARY_SEND_FILTER, EXTEfx.AL_EFFECTSLOT_NULL, i, EXTEfx.AL_FILTER_NULL); - this.effects[i].removeSource(this); - this.effects[i] = null; + for (int i = 0; i < effects.length; i++) { + if (effects[i] != null) { + AL11.alSource3i(sourceId, EXTEfx.AL_AUXILIARY_SEND_FILTER, EXTEfx.AL_EFFECTSLOT_NULL, i, EXTEfx.AL_FILTER_NULL); + effects[i].removeSource(this); + effects[i] = null; } } - this.nextSoundEffectSendId = 0; + nextSoundEffectSendId = 0; } protected void setResamplerByIndex(int index) { - if (index >= 0 && index != this.resamplerIndex) { - this.resamplerIndex = index; - AL10.alSourcei(this.sourceId, SOFTSourceResampler.AL_SOURCE_RESAMPLER_SOFT, index); + if (index >= 0 && index != resamplerIndex) { + resamplerIndex = index; + AL10.alSourcei(sourceId, SOFTSourceResampler.AL_SOURCE_RESAMPLER_SOFT, index); } } @@ -625,7 +625,7 @@ public boolean setResampler(String resampler) { final AudioDevice device = Audio.get().getDevice(); final int resamplerIndex = device.getResamplerIndexByName(resampler); if (resamplerIndex >= 0) { - this.setResamplerByIndex(resamplerIndex); + setResamplerByIndex(resamplerIndex); return true; } @@ -640,17 +640,17 @@ public boolean setResampler(String resampler) { */ public String getResampler() { final AudioDevice device = Audio.get().getDevice(); - final int resamplerIndex = AL10.alGetSourcei(this.sourceId, SOFTSourceResampler.AL_SOURCE_RESAMPLER_SOFT); + final int resamplerIndex = AL10.alGetSourcei(sourceId, SOFTSourceResampler.AL_SOURCE_RESAMPLER_SOFT); return device.getResamplerNameByIndex(resamplerIndex); } void onEffectDisposal(SoundEffect effect) { - for (int i = 0; i < this.effects.length; i++) { - if (this.effects[i] == effect) { - AL11.alSource3i(this.sourceId, EXTEfx.AL_AUXILIARY_SEND_FILTER, EXTEfx.AL_EFFECTSLOT_NULL, i, EXTEfx.AL_FILTER_NULL); - this.effects[i] = null; - this.nextSoundEffectSendId = i; + for (int i = 0; i < effects.length; i++) { + if (effects[i] == effect) { + AL11.alSource3i(sourceId, EXTEfx.AL_AUXILIARY_SEND_FILTER, EXTEfx.AL_EFFECTSLOT_NULL, i, EXTEfx.AL_FILTER_NULL); + effects[i] = null; + nextSoundEffectSendId = i; break; } } @@ -658,10 +658,10 @@ void onEffectDisposal(SoundEffect effect) { protected void dispose() { - this.detachAllEffects(); - AL10.alDeleteSources(this.sourceId); - if (!this.errorLogger.checkLogError("Failed to dispose the SoundSource")) { - this.logger.debug(this.getClass(), "SoundSource successfully disposed"); + detachAllEffects(); + AL10.alDeleteSources(sourceId); + if (!errorLogger.checkLogError("Failed to dispose the SoundSource")) { + logger.debug(this.getClass(), "SoundSource successfully disposed"); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/SoundSourcePool.java b/core/src/main/java/de/pottgames/tuningfork/SoundSourcePool.java index 02e41ec..61c0591 100644 --- a/core/src/main/java/de/pottgames/tuningfork/SoundSourcePool.java +++ b/core/src/main/java/de/pottgames/tuningfork/SoundSourcePool.java @@ -24,26 +24,26 @@ class SoundSourcePool { SoundSourcePool(int simultaneousSources) { for (int i = 0; i < simultaneousSources; i++) { - this.sources.add(new BufferedSoundSource()); + sources.add(new BufferedSoundSource()); } } BufferedSoundSource findFreeSource(AudioSettings defaultSettings) { BufferedSoundSource result = null; - final int startSourceIndex = this.nextSourceIndex; + final int startSourceIndex = nextSourceIndex; // FIND FREE SOUND SOURCE while (result == null) { - final BufferedSoundSource candidate = this.sources.get(this.nextSourceIndex); + final BufferedSoundSource candidate = sources.get(nextSourceIndex); if (!candidate.obtained && !candidate.isPlaying()) { result = candidate; } - this.nextSourceIndex++; - if (this.nextSourceIndex >= this.sources.size) { - this.nextSourceIndex = 0; + nextSourceIndex++; + if (nextSourceIndex >= sources.size) { + nextSourceIndex = 0; } - if (this.nextSourceIndex == startSourceIndex) { + if (nextSourceIndex == startSourceIndex) { break; } } @@ -51,7 +51,7 @@ BufferedSoundSource findFreeSource(AudioSettings defaultSettings) { // IF NO SOURCE WAS FOUND, CREATE A NEW ONE ON THE FLY if (result == null) { result = new BufferedSoundSource(); - this.sources.add(result); + sources.add(result); } result.reset(defaultSettings); @@ -60,7 +60,7 @@ BufferedSoundSource findFreeSource(AudioSettings defaultSettings) { void resumeAll() { - for (final BufferedSoundSource source : this.sources) { + for (final BufferedSoundSource source : sources) { if (source.isPaused()) { final boolean obtainedState = source.obtained; source.obtained = true; @@ -72,7 +72,7 @@ void resumeAll() { void pauseAll() { - for (final BufferedSoundSource source : this.sources) { + for (final BufferedSoundSource source : sources) { if (source.isPlaying()) { final boolean obtainedState = source.obtained; source.obtained = true; @@ -84,7 +84,7 @@ void pauseAll() { void stopAll() { - for (final BufferedSoundSource source : this.sources) { + for (final BufferedSoundSource source : sources) { final boolean obtainedState = source.obtained; source.obtained = true; source.stop(); @@ -97,28 +97,28 @@ void stopAll() { void setResamplerByIndex(int index) { - for (final BufferedSoundSource source : this.sources) { + for (final BufferedSoundSource source : sources) { source.setResamplerByIndex(index); } } void setVirtualization(Virtualization virtualization) { - for (final BufferedSoundSource source : this.sources) { + for (final BufferedSoundSource source : sources) { source.setVirtualization(virtualization); } } void setSpatialization(Spatialization spatialization) { - for (final BufferedSoundSource source : this.sources) { + for (final BufferedSoundSource source : sources) { source.setSpatialization(spatialization); } } void onBufferDisposal(SoundBuffer buffer) { - for (final BufferedSoundSource source : this.sources) { + for (final BufferedSoundSource source : sources) { if (source.getBuffer() == buffer) { source.obtained = true; source.stop(); @@ -130,8 +130,8 @@ void onBufferDisposal(SoundBuffer buffer) { void dispose() { - this.sources.forEach(BufferedSoundSource::dispose); - this.sources.clear(); + sources.forEach(BufferedSoundSource::dispose); + sources.clear(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/StreamManager.java b/core/src/main/java/de/pottgames/tuningfork/StreamManager.java index 6aadcce..9d1f052 100644 --- a/core/src/main/java/de/pottgames/tuningfork/StreamManager.java +++ b/core/src/main/java/de/pottgames/tuningfork/StreamManager.java @@ -26,11 +26,11 @@ protected StreamManager(AudioConfig config, TuningForkLogger logger) { // INITIAL IDLE TASK CREATION FOR THE POOL for (int i = 0; i < config.getIdleTasks() - 1; i++) { - this.idleTasks.add(new AsyncTask()); + idleTasks.add(new AsyncTask()); } // CREATE THE TASK SERVICE - this.taskService = Executors.newSingleThreadExecutor(runnable -> { + taskService = Executors.newSingleThreadExecutor(runnable -> { final Thread thread = Executors.defaultThreadFactory().newThread(runnable); thread.setName("TuningFork-Task-Thread"); thread.setDaemon(true); @@ -38,12 +38,12 @@ protected StreamManager(AudioConfig config, TuningForkLogger logger) { }); // adding the last task by executing it for warm up - this.taskService.execute(new AsyncTask()); + taskService.execute(new AsyncTask()); // START UPDATE THREAD - this.updateThread = new Thread(() -> { - while (this.running) { - this.updateAsync(); + updateThread = new Thread(() -> { + while (running) { + updateAsync(); try { Thread.sleep(100); } catch (final InterruptedException e) { @@ -51,16 +51,16 @@ protected StreamManager(AudioConfig config, TuningForkLogger logger) { } } }); - this.updateThread.setName("TuningFork-Update-Thread"); - this.updateThread.setDaemon(true); - this.updateThread.start(); + updateThread.setName("TuningFork-Update-Thread"); + updateThread.setDaemon(true); + updateThread.start(); } protected void updateAsync() { - synchronized (this.lock) { - for (int i = 0; i < this.soundsToUpdate.size; i++) { - final StreamedSoundSource sound = this.soundsToUpdate.get(i); + synchronized (lock) { + for (int i = 0; i < soundsToUpdate.size; i++) { + final StreamedSoundSource sound = soundsToUpdate.get(i); this.postTask(sound, TaskAction.UPDATE); } } @@ -68,9 +68,9 @@ protected void updateAsync() { protected void setDefaultResampler(int resamplerIndex) { - synchronized (this.lock) { - for (int i = 0; i < this.soundsToUpdate.size; i++) { - final StreamedSoundSource sound = this.soundsToUpdate.get(i); + synchronized (lock) { + for (int i = 0; i < soundsToUpdate.size; i++) { + final StreamedSoundSource sound = soundsToUpdate.get(i); sound.setResamplerByIndex(resamplerIndex); } } @@ -78,9 +78,9 @@ protected void setDefaultResampler(int resamplerIndex) { protected void setDefaultVirtualization(Virtualization virtualization) { - synchronized (this.lock) { - for (int i = 0; i < this.soundsToUpdate.size; i++) { - final StreamedSoundSource sound = this.soundsToUpdate.get(i); + synchronized (lock) { + for (int i = 0; i < soundsToUpdate.size; i++) { + final StreamedSoundSource sound = soundsToUpdate.get(i); sound.setVirtualization(virtualization); } } @@ -88,9 +88,9 @@ protected void setDefaultVirtualization(Virtualization virtualization) { protected void setDefaultSpatialization(Spatialization spatialization) { - synchronized (this.lock) { - for (int i = 0; i < this.soundsToUpdate.size; i++) { - final StreamedSoundSource sound = this.soundsToUpdate.get(i); + synchronized (lock) { + for (int i = 0; i < soundsToUpdate.size; i++) { + final StreamedSoundSource sound = soundsToUpdate.get(i); sound.setSpatialization(spatialization); } } @@ -98,15 +98,15 @@ protected void setDefaultSpatialization(Spatialization spatialization) { protected void registerSource(StreamedSoundSource source) { - synchronized (this.lock) { - this.soundsToUpdate.add(source); + synchronized (lock) { + soundsToUpdate.add(source); } } protected void removeSource(StreamedSoundSource sound) { - synchronized (this.lock) { - this.soundsToUpdate.removeValue(sound, true); + synchronized (lock) { + soundsToUpdate.removeValue(sound, true); } } @@ -127,7 +127,7 @@ protected void stopAll() { protected void addIdleTask(AsyncTask task) { - this.idleTasks.offer(task); + idleTasks.offer(task); } @@ -137,44 +137,44 @@ protected void postTask(StreamedSoundSource sound, TaskAction action) { protected void postTask(StreamedSoundSource sound, TaskAction action, float floatParam) { - AsyncTask task = this.idleTasks.poll(); + AsyncTask task = idleTasks.poll(); if (task == null) { task = new AsyncTask(); } task.sound = sound; task.taskAction = action; task.floatParam = floatParam; - this.taskService.execute(task); + taskService.execute(task); } protected void postTask(TaskAction action) { - AsyncTask task = this.idleTasks.poll(); + AsyncTask task = idleTasks.poll(); if (task == null) { task = new AsyncTask(); } task.taskAction = action; - this.taskService.execute(task); + taskService.execute(task); } protected void dispose() { // TERMINATE UPDATE THREAD - this.running = false; + running = false; try { - this.updateThread.join(2000); + updateThread.join(2000); } catch (final InterruptedException e1) { // ignore } // SHUTDOWN TASK SERVICE - this.taskService.shutdown(); + taskService.shutdown(); try { - if (!this.taskService.awaitTermination(500L, TimeUnit.MILLISECONDS)) { - this.logger.debug(this.getClass(), "The task service timed out on shutdown."); + if (!taskService.awaitTermination(500L, TimeUnit.MILLISECONDS)) { + logger.debug(this.getClass(), "The task service timed out on shutdown."); } } catch (final InterruptedException e) { - this.taskService.shutdownNow(); + taskService.shutdownNow(); } } @@ -192,63 +192,63 @@ public class AsyncTask implements Runnable { @Override public void run() { - if (this.sound != null) { - synchronized (StreamManager.this.lock) { - switch (this.taskAction) { + if (sound != null) { + synchronized (lock) { + switch (taskAction) { case PAUSE: - this.sound.pauseAsync(); + sound.pauseAsync(); break; case PLAY: - this.sound.playAsync(); + sound.playAsync(); break; case STOP: - this.sound.stopAsync(); + sound.stopAsync(); break; case UPDATE: - this.sound.updateAsync(); + sound.updateAsync(); break; case SET_PLAYBACK_POSITION: - this.sound.setPlaybackPositionAsync(this.floatParam); + sound.setPlaybackPositionAsync(floatParam); break; case STOP_ALL: - for (int i = 0; i < StreamManager.this.soundsToUpdate.size; i++) { - final StreamedSoundSource sound = StreamManager.this.soundsToUpdate.get(i); + for (int i = 0; i < soundsToUpdate.size; i++) { + final StreamedSoundSource sound = soundsToUpdate.get(i); sound.stopAsync(); } break; case PAUSE_ALL: - for (int i = 0; i < StreamManager.this.soundsToUpdate.size; i++) { - final StreamedSoundSource sound = StreamManager.this.soundsToUpdate.get(i); + for (int i = 0; i < soundsToUpdate.size; i++) { + final StreamedSoundSource sound = soundsToUpdate.get(i); if (sound.isPlaying()) { sound.pauseAsync(); } } break; case RESUME_ALL: - for (int i = 0; i < StreamManager.this.soundsToUpdate.size; i++) { - final StreamedSoundSource sound = StreamManager.this.soundsToUpdate.get(i); + for (int i = 0; i < soundsToUpdate.size; i++) { + final StreamedSoundSource sound = soundsToUpdate.get(i); if (sound.isPaused()) { sound.playAsync(); } } break; case DISPOSE_CALLBACK: - this.sound.readyToDispose(); + sound.readyToDispose(); break; } } // CLEAN UP - this.reset(); - StreamManager.this.addIdleTask(this); + reset(); + addIdleTask(this); } } protected void reset() { - this.sound = null; - this.taskAction = null; - this.floatParam = 0f; + sound = null; + taskAction = null; + floatParam = 0f; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/StreamedSoundSource.java b/core/src/main/java/de/pottgames/tuningfork/StreamedSoundSource.java index b21b6ce..cfd9ef6 100644 --- a/core/src/main/java/de/pottgames/tuningfork/StreamedSoundSource.java +++ b/core/src/main/java/de/pottgames/tuningfork/StreamedSoundSource.java @@ -95,56 +95,56 @@ public StreamedSoundSource(AudioStream stream) { } // FETCH AND SET DEPENDENCIES - this.bufferTimeQueue = new FloatArray(true, StreamedSoundSource.BUFFER_COUNT + 1); - this.audio = Audio.get(); - if (this.audio == null) { + bufferTimeQueue = new FloatArray(true, StreamedSoundSource.BUFFER_COUNT + 1); + audio = Audio.get(); + if (audio == null) { throw new TuningForkRuntimeException("StreamedSoundSource cannot be created before Audio is initialized."); } - this.logger = this.audio.getLogger(); - this.errorLogger = new ErrorLogger(this.getClass(), this.logger); - this.audioStream = stream; + logger = audio.getLogger(); + errorLogger = new ErrorLogger(this.getClass(), logger); + audioStream = stream; // FETCH DATA & FORMAT FROM INPUT STREAM - this.duration = stream.getDuration(); - if (this.duration < 0f) { - this.logger.debug(this.getClass(), "Unable to measure sound duration"); + duration = stream.getDuration(); + if (duration < 0f) { + logger.debug(this.getClass(), "Unable to measure sound duration"); } - final int sampleRate = this.audioStream.getSampleRate(); - final int channels = this.audioStream.getChannels(); - final int sampleDepth = this.audioStream.getBitsPerSample(); + final int sampleRate = audioStream.getSampleRate(); + final int channels = audioStream.getChannels(); + final int sampleDepth = audioStream.getBitsPerSample(); final int bytesPerSample = sampleDepth / 8; - final PcmDataType pcmDataType = this.audioStream.getPcmDataType(); - this.pcmFormat = PcmFormat.determineFormat(channels, sampleDepth, pcmDataType); - if (this.pcmFormat == null) { + final PcmDataType pcmDataType = audioStream.getPcmDataType(); + pcmFormat = PcmFormat.determineFormat(channels, sampleDepth, pcmDataType); + if (pcmFormat == null) { throw new TuningForkRuntimeException("Unsupported pcm format - channels: " + channels + ", sample depth: " + sampleDepth); } // CREATE BUFFERS - final int blockSize = this.audioStream.getBlockSize(); - final int bufferSize = this.determineBufferSize(channels, blockSize, (int) Math.ceil(this.audioStream.getBitsPerSample() / 8d)); - this.tempBuffer = BufferUtils.createByteBuffer(bufferSize); - this.tempBytes = new byte[bufferSize]; - this.secondsPerBuffer = (float) bufferSize / (bytesPerSample * channels * sampleRate); - this.bytesPerSecond = bytesPerSample * channels * sampleRate; - this.buffers = BufferUtils.createIntBuffer(StreamedSoundSource.BUFFER_COUNT); - AL10.alGenBuffers(this.buffers); - this.errorLogger.checkLogError("Buffers couldn't be created"); + final int blockSize = audioStream.getBlockSize(); + final int bufferSize = determineBufferSize(channels, blockSize, (int) Math.ceil(audioStream.getBitsPerSample() / 8d)); + tempBuffer = BufferUtils.createByteBuffer(bufferSize); + tempBytes = new byte[bufferSize]; + secondsPerBuffer = (float) bufferSize / (bytesPerSample * channels * sampleRate); + bytesPerSecond = bytesPerSample * channels * sampleRate; + buffers = BufferUtils.createIntBuffer(StreamedSoundSource.BUFFER_COUNT); + AL10.alGenBuffers(buffers); + errorLogger.checkLogError("Buffers couldn't be created"); if (blockSize > 0) { for (int i = 0; i < StreamedSoundSource.BUFFER_COUNT; i++) { - final int bufferId = this.buffers.get(i); - final int blockAlign = this.audioStream.getBlockAlign(); + final int bufferId = buffers.get(i); + final int blockAlign = audioStream.getBlockAlign(); AL11.alBufferi(bufferId, SOFTBlockAlignment.AL_UNPACK_BLOCK_ALIGNMENT_SOFT, blockAlign); - this.errorLogger.checkLogError("Couldn't set blockAlign"); - this.logger.trace(this.getClass(), "setting block align to " + blockAlign); + errorLogger.checkLogError("Couldn't set blockAlign"); + logger.trace(this.getClass(), "setting block align to " + blockAlign); } } // INITIAL BUFFER FILL - this.fillAllBuffersInternal(); - this.errorLogger.checkLogError("An error occured while pre-buffering"); + fillAllBuffersInternal(); + errorLogger.checkLogError("An error occured while pre-buffering"); // REGISTER IN AUDIO - this.audio.streamManager.registerSource(this); + audio.streamManager.registerSource(this); } @@ -166,24 +166,24 @@ private int determineBufferSize(int channels, int blockSize, int bytesPerSample) private void resetStream() { - this.audioStream = this.audioStream.reset(); + audioStream = audioStream.reset(); } void updateAsync() { synchronized (this) { - int processedBufferCount = AL10.alGetSourcei(this.sourceId, AL10.AL_BUFFERS_PROCESSED); - this.checkPlaybackPosResetAsync(); + int processedBufferCount = AL10.alGetSourcei(sourceId, AL10.AL_BUFFERS_PROCESSED); + checkPlaybackPosResetAsync(); boolean end = false; while (processedBufferCount > 0) { processedBufferCount--; - final float processedSeconds = this.bufferTimeQueue.removeIndex(0); - this.processedTime += processedSeconds; - this.checkPlaybackPosResetAsync(); + final float processedSeconds = bufferTimeQueue.removeIndex(0); + processedTime += processedSeconds; + checkPlaybackPosResetAsync(); - final int bufferId = AL10.alSourceUnqueueBuffers(this.sourceId); + final int bufferId = AL10.alSourceUnqueueBuffers(sourceId); if (bufferId == AL10.AL_INVALID_VALUE) { break; } @@ -191,35 +191,35 @@ void updateAsync() { if (end) { continue; } - if (this.fillBufferInternal(bufferId)) { - AL10.alSourceQueueBuffers(this.sourceId, bufferId); + if (fillBufferInternal(bufferId)) { + AL10.alSourceQueueBuffers(sourceId, bufferId); } else { end = true; } } - final int queuedBuffers = AL10.alGetSourcei(this.sourceId, AL10.AL_BUFFERS_QUEUED); + final int queuedBuffers = AL10.alGetSourcei(sourceId, AL10.AL_BUFFERS_QUEUED); if (end && queuedBuffers == 0) { - this.stopInternal(); - this.manuallySetBehindLoopEnd = false; - } else if (this.playing.get() && AL10.alGetSourcei(this.sourceId, AL10.AL_SOURCE_STATE) != AL10.AL_PLAYING && queuedBuffers > 0) { + stopInternal(); + manuallySetBehindLoopEnd = false; + } else if (playing.get() && AL10.alGetSourcei(sourceId, AL10.AL_SOURCE_STATE) != AL10.AL_PLAYING && queuedBuffers > 0) { // A buffer underflow will cause the source to stop, so we should resume playback in this case. - AL10.alSourcePlay(this.sourceId); + AL10.alSourcePlay(sourceId); } } } private void checkPlaybackPosResetAsync() { - if (this.bufferTimeQueue.size > 0) { - final float value = this.bufferTimeQueue.get(0); + if (bufferTimeQueue.size > 0) { + final float value = bufferTimeQueue.get(0); if (value == Float.MAX_VALUE) { - this.bufferTimeQueue.removeIndex(0); - this.processedTime = 0f; + bufferTimeQueue.removeIndex(0); + processedTime = 0f; } else if (value == Float.MIN_VALUE) { - this.bufferTimeQueue.removeIndex(0); - this.processedTime = this.loopStart; + bufferTimeQueue.removeIndex(0); + processedTime = loopStart; } } } @@ -233,7 +233,7 @@ private void checkPlaybackPosResetAsync() { */ @Override public float getPlaybackPosition() { - return this.processedTime + AL10.alGetSourcef(this.sourceId, AL11.AL_SEC_OFFSET); + return processedTime + AL10.alGetSourcef(sourceId, AL11.AL_SEC_OFFSET); } @@ -256,19 +256,19 @@ public void setLoopPoints(float start, float end) { throw new TuningForkRuntimeException("Invalid loop points: start and end must not be > 0"); } - this.loopStart = start; - this.loopEnd = end; + loopStart = start; + loopEnd = end; } void skipStreamToPosition(final float seconds) { synchronized (this) { - this.resetStream(); - int bytesToSkip = (int) (seconds * this.bytesPerSecond); - final int overbytes = bytesToSkip % (this.audioStream.getBitsPerSample() / 8); + resetStream(); + int bytesToSkip = (int) (seconds * bytesPerSecond); + final int overbytes = bytesToSkip % (audioStream.getBitsPerSample() / 8); bytesToSkip -= overbytes; final byte[] buffer = new byte[bytesToSkip]; - this.audioStream.read(buffer); + audioStream.read(buffer); } } @@ -280,9 +280,9 @@ void skipStreamToPosition(final float seconds) { */ public void setPlaybackPosition(float seconds) { if (seconds >= 0f) { - this.audio.streamManager.postTask(this, TaskAction.SET_PLAYBACK_POSITION, seconds); + audio.streamManager.postTask(this, TaskAction.SET_PLAYBACK_POSITION, seconds); } else { - this.logger.error(this.getClass(), "Can't set playback position to values < 0"); + logger.error(this.getClass(), "Can't set playback position to values < 0"); } } @@ -293,51 +293,51 @@ void setPlaybackPositionAsync(final float seconds) { final boolean stopped = this.stopped.get(); // FULL RESET - AL10.alSourceStop(this.sourceId); - this.resetStream(); - this.bufferTimeQueue.clear(); + AL10.alSourceStop(sourceId); + resetStream(); + bufferTimeQueue.clear(); // SKIP THE INPUT STREAM UNTIL THE NEW POSITION IS IN REACH float currentSeconds = 0f; boolean unreachable = false; - while (currentSeconds < seconds - this.secondsPerBuffer) { - final int skippedBytes = this.audioStream.read(this.tempBytes); + while (currentSeconds < seconds - secondsPerBuffer) { + final int skippedBytes = audioStream.read(tempBytes); if (skippedBytes <= 0) { unreachable = true; break; } - currentSeconds += skippedBytes / this.bytesPerSecond; + currentSeconds += skippedBytes / bytesPerSecond; } - this.processedTime = currentSeconds; - this.queuedSeconds = currentSeconds; - this.manuallySetBehindLoopEnd = this.queuedSeconds > this.loopEnd && this.loopEnd > 0f; + processedTime = currentSeconds; + queuedSeconds = currentSeconds; + manuallySetBehindLoopEnd = queuedSeconds > loopEnd && loopEnd > 0f; if (unreachable) { - this.stopInternal(); - if (this.looping && playing) { - this.playInternal(); + stopInternal(); + if (looping && playing) { + playInternal(); } return; } // REFILL BUFFERS - final int filledBufferCount = this.fillAllBuffersInternal(); + final int filledBufferCount = fillAllBuffersInternal(); // SKIP TO PERFECT POSITION IN BUFFER if (filledBufferCount > 0) { - AL10.alSourcef(this.sourceId, AL11.AL_SEC_OFFSET, seconds - currentSeconds); + AL10.alSourcef(sourceId, AL11.AL_SEC_OFFSET, seconds - currentSeconds); } // RESTORE SOURCE STATE if (filledBufferCount > 0 && playing) { - AL10.alSourcePlay(this.sourceId); + AL10.alSourcePlay(sourceId); } else if (filledBufferCount > 0 && !stopped) { - AL10.alSourcePlay(this.sourceId); - AL10.alSourcePause(this.sourceId); + AL10.alSourcePlay(sourceId); + AL10.alSourcePause(sourceId); } else if (playing) { - this.stopInternal(); - if (this.looping) { - this.playInternal(); + stopInternal(); + if (looping) { + playInternal(); } } } @@ -346,142 +346,142 @@ void setPlaybackPositionAsync(final float seconds) { @Override public void setLooping(boolean value) { - this.looping = value; + looping = value; } void pauseAsync() { synchronized (this) { - this.pauseInternal(); + pauseInternal(); } } void pauseInternal() { super.pause(); - this.playing.set(false); - this.stopped.set(false); + playing.set(false); + stopped.set(false); } @Override public void pause() { - if (this.playing.compareAndSet(true, false)) { - this.audio.streamManager.postTask(this, TaskAction.PAUSE); - this.stopped.set(false); + if (playing.compareAndSet(true, false)) { + audio.streamManager.postTask(this, TaskAction.PAUSE); + stopped.set(false); } } void playAsync() { synchronized (this) { - this.playInternal(); + playInternal(); } } void playInternal() { super.play(); - this.playing.set(true); - this.stopped.set(false); + playing.set(true); + stopped.set(false); } @Override public void play() { - if (this.playing.compareAndSet(false, true)) { - this.audio.streamManager.postTask(this, TaskAction.PLAY); - this.stopped.set(false); + if (playing.compareAndSet(false, true)) { + audio.streamManager.postTask(this, TaskAction.PLAY); + stopped.set(false); } } void stopAsync() { synchronized (this) { - this.stopInternal(); + stopInternal(); } } void stopInternal() { super.stop(); - AL10.alSourcei(this.sourceId, AL10.AL_BUFFER, 0); // removes all buffers from the source - this.resetStream(); - this.processedTime = 0f; - this.queuedSeconds = 0f; - this.bufferTimeQueue.clear(); - this.fillAllBuffersInternal(); - this.playing.set(false); - this.stopped.set(true); + AL10.alSourcei(sourceId, AL10.AL_BUFFER, 0); // removes all buffers from the source + resetStream(); + processedTime = 0f; + queuedSeconds = 0f; + bufferTimeQueue.clear(); + fillAllBuffersInternal(); + playing.set(false); + stopped.set(true); } @Override public void stop() { - if (!this.stopped.get()) { - this.audio.streamManager.postTask(this, TaskAction.STOP); - this.playing.set(false); - this.stopped.set(true); + if (!stopped.get()) { + audio.streamManager.postTask(this, TaskAction.STOP); + playing.set(false); + stopped.set(true); } } private boolean fillBufferInternal(int bufferId) { - int length = this.audioStream.read(this.tempBytes); + int length = audioStream.read(tempBytes); if (length <= 0) { - if (!this.looping || this.manuallySetBehindLoopEnd) { - this.bufferTimeQueue.add(Float.MAX_VALUE); + if (!looping || manuallySetBehindLoopEnd) { + bufferTimeQueue.add(Float.MAX_VALUE); return false; } - this.skipStreamToPosition(this.loopStart); - this.queuedSeconds = this.loopStart; - this.bufferTimeQueue.add(Float.MIN_VALUE); - length = this.audioStream.read(this.tempBytes); + skipStreamToPosition(loopStart); + queuedSeconds = loopStart; + bufferTimeQueue.add(Float.MIN_VALUE); + length = audioStream.read(tempBytes); if (length <= 0) { return false; } } - float secondsInUploadBuffer = length / this.bytesPerSecond; + float secondsInUploadBuffer = length / bytesPerSecond; int bytesToUpload = length; boolean loopEndCut = false; - if (this.looping && this.loopEnd > 0f && this.loopEnd > this.loopStart) { - if (this.queuedSeconds + secondsInUploadBuffer >= this.loopEnd && !this.manuallySetBehindLoopEnd) { - secondsInUploadBuffer = this.loopEnd - this.queuedSeconds; - bytesToUpload = (int) (this.bytesPerSecond * secondsInUploadBuffer); - final int overbytes = bytesToUpload % (this.audioStream.getBitsPerSample() / 8); + if (looping && loopEnd > 0f && loopEnd > loopStart) { + if (queuedSeconds + secondsInUploadBuffer >= loopEnd && !manuallySetBehindLoopEnd) { + secondsInUploadBuffer = loopEnd - queuedSeconds; + bytesToUpload = (int) (bytesPerSecond * secondsInUploadBuffer); + final int overbytes = bytesToUpload % (audioStream.getBitsPerSample() / 8); bytesToUpload = MathUtils.clamp(bytesToUpload - overbytes, 0, length); loopEndCut = true; - this.skipStreamToPosition(this.loopStart); - this.queuedSeconds = this.loopStart; + skipStreamToPosition(loopStart); + queuedSeconds = loopStart; } } - this.bufferTimeQueue.add(secondsInUploadBuffer); - this.queuedSeconds += secondsInUploadBuffer; + bufferTimeQueue.add(secondsInUploadBuffer); + queuedSeconds += secondsInUploadBuffer; if (loopEndCut) { - this.bufferTimeQueue.add(Float.MIN_VALUE); - this.queuedSeconds = this.loopStart; + bufferTimeQueue.add(Float.MIN_VALUE); + queuedSeconds = loopStart; } - this.tempBuffer.clear(); - this.tempBuffer.put(this.tempBytes, 0, bytesToUpload).flip(); - AL10.alBufferData(bufferId, this.pcmFormat.getAlId(), this.tempBuffer, this.audioStream.getSampleRate()); + tempBuffer.clear(); + tempBuffer.put(tempBytes, 0, bytesToUpload).flip(); + AL10.alBufferData(bufferId, pcmFormat.getAlId(), tempBuffer, audioStream.getSampleRate()); return true; } private int fillAllBuffersInternal() { - AL10.alSourcei(this.sourceId, AL10.AL_BUFFER, 0); // removes all buffers from the source - this.errorLogger.checkLogError("error removing buffers from the source"); + AL10.alSourcei(sourceId, AL10.AL_BUFFER, 0); // removes all buffers from the source + errorLogger.checkLogError("error removing buffers from the source"); int filledBufferCount = 0; for (int i = 0; i < StreamedSoundSource.BUFFER_COUNT; i++) { - final int bufferId = this.buffers.get(i); - if (!this.fillBufferInternal(bufferId)) { + final int bufferId = buffers.get(i); + if (!fillBufferInternal(bufferId)) { break; } filledBufferCount++; - AL10.alSourceQueueBuffers(this.sourceId, bufferId); - this.errorLogger.checkLogError("error queueing buffers on the source"); + AL10.alSourceQueueBuffers(sourceId, bufferId); + errorLogger.checkLogError("error queueing buffers on the source"); } return filledBufferCount; @@ -490,13 +490,13 @@ private int fillAllBuffersInternal() { @Override public boolean isPlaying() { - return this.playing.get(); + return playing.get(); } @Override public boolean isPaused() { - return !this.playing.get() && !this.stopped.get(); + return !playing.get() && !stopped.get(); } @@ -508,12 +508,12 @@ public boolean isPaused() { */ @Override public float getDuration() { - return this.duration; + return duration; } void readyToDispose() { - this.readyToDispose = true; + readyToDispose = true; } @@ -554,10 +554,10 @@ private static AudioStream createAudioStream(FileHandle file) { */ @Override public void dispose() { - this.audio.streamManager.removeSource(this); - this.audio.streamManager.postTask(this, TaskAction.STOP); - this.audio.streamManager.postTask(this, TaskAction.DISPOSE_CALLBACK); - while (!this.readyToDispose) { + audio.streamManager.removeSource(this); + audio.streamManager.postTask(this, TaskAction.STOP); + audio.streamManager.postTask(this, TaskAction.DISPOSE_CALLBACK); + while (!readyToDispose) { try { Thread.sleep(1); } catch (final InterruptedException e) { @@ -565,9 +565,9 @@ public void dispose() { } } super.dispose(); - AL10.alDeleteBuffers(this.buffers); - this.errorLogger.checkLogError("Failed to dispose the SoundSources buffers"); - StreamUtils.closeQuietly(this.audioStream); + AL10.alDeleteBuffers(buffers); + errorLogger.checkLogError("Failed to dispose the SoundSources buffers"); + StreamUtils.closeQuietly(audioStream); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/VocalMorpher.java b/core/src/main/java/de/pottgames/tuningfork/VocalMorpher.java index fb54e56..9335e9e 100644 --- a/core/src/main/java/de/pottgames/tuningfork/VocalMorpher.java +++ b/core/src/main/java/de/pottgames/tuningfork/VocalMorpher.java @@ -70,18 +70,18 @@ public class VocalMorpher extends SoundEffectData { @Override protected void apply(int effectId) { EXTEfx.alEffecti(effectId, EXTEfx.AL_EFFECT_TYPE, EXTEfx.AL_EFFECT_VOCAL_MORPHER); - EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_PHONEMEA, this.phonemea); - EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_PHONEMEB, this.phonemeb); - EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_PHONEMEA_COARSE_TUNING, this.phonemeaCoarseTuning); - EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_PHONEMEB_COARSE_TUNING, this.phonemebCoarseTuning); - EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_WAVEFORM, this.waveform); - EXTEfx.alEffectf(effectId, EXTEfx.AL_VOCMORPHER_RATE, this.rate); + EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_PHONEMEA, phonemea); + EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_PHONEMEB, phonemeb); + EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_PHONEMEA_COARSE_TUNING, phonemeaCoarseTuning); + EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_PHONEMEB_COARSE_TUNING, phonemebCoarseTuning); + EXTEfx.alEffecti(effectId, EXTEfx.AL_VOCMORPHER_WAVEFORM, waveform); + EXTEfx.alEffectf(effectId, EXTEfx.AL_VOCMORPHER_RATE, rate); } @Override public int hashCode() { - return Objects.hash(this.phonemea, this.phonemeaCoarseTuning, this.phonemeb, this.phonemebCoarseTuning, this.rate, this.waveform); + return Objects.hash(phonemea, phonemeaCoarseTuning, phonemeb, phonemebCoarseTuning, rate, waveform); } @@ -97,16 +97,16 @@ public boolean equals(Object obj) { return false; } final VocalMorpher other = (VocalMorpher) obj; - return this.phonemea == other.phonemea && this.phonemeaCoarseTuning == other.phonemeaCoarseTuning && this.phonemeb == other.phonemeb - && this.phonemebCoarseTuning == other.phonemebCoarseTuning && Float.floatToIntBits(this.rate) == Float.floatToIntBits(other.rate) - && this.waveform == other.waveform; + return phonemea == other.phonemea && phonemeaCoarseTuning == other.phonemeaCoarseTuning && phonemeb == other.phonemeb + && phonemebCoarseTuning == other.phonemebCoarseTuning && Float.floatToIntBits(rate) == Float.floatToIntBits(other.rate) + && waveform == other.waveform; } @Override public String toString() { - return "VocalMorpher [phonemea=" + this.phonemea + ", phonemeb=" + this.phonemeb + ", phonemeaCoarseTuning=" + this.phonemeaCoarseTuning - + ", phonemebCoarseTuning=" + this.phonemebCoarseTuning + ", waveform=" + this.waveform + ", rate=" + this.rate + "]"; + return "VocalMorpher [phonemea=" + phonemea + ", phonemeb=" + phonemeb + ", phonemeaCoarseTuning=" + phonemeaCoarseTuning + ", phonemebCoarseTuning=" + + phonemebCoarseTuning + ", waveform=" + waveform + ", rate=" + rate + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/capture/CaptureConfig.java b/core/src/main/java/de/pottgames/tuningfork/capture/CaptureConfig.java index 3f4513a..f2b374a 100644 --- a/core/src/main/java/de/pottgames/tuningfork/capture/CaptureConfig.java +++ b/core/src/main/java/de/pottgames/tuningfork/capture/CaptureConfig.java @@ -33,11 +33,11 @@ public class CaptureConfig { * Creates a new {@link CaptureConfig} with default settings. */ public CaptureConfig() { - this.pcmFormat = PcmFormat.MONO_16_BIT; - this.frequency = 44100; - this.bufferSize = 4096 * 10; - this.deviceSpecifier = null; - this.logger = new GdxLogger(); + pcmFormat = PcmFormat.MONO_16_BIT; + frequency = 44100; + bufferSize = 4096 * 10; + deviceSpecifier = null; + logger = new GdxLogger(); } @@ -65,7 +65,7 @@ public CaptureConfig(String deviceSpecifier, PcmFormat pcmFormat, int frequency, * @return the pcm format */ public PcmFormat getPcmFormat() { - return this.pcmFormat; + return pcmFormat; } @@ -75,7 +75,7 @@ public PcmFormat getPcmFormat() { * @return the frequency */ public int getFrequency() { - return this.frequency; + return frequency; } @@ -85,7 +85,7 @@ public int getFrequency() { * @return the buffer size */ public int getBufferSize() { - return this.bufferSize; + return bufferSize; } @@ -95,7 +95,7 @@ public int getBufferSize() { * @return the device specifier */ public String getDeviceSpecifier() { - return this.deviceSpecifier; + return deviceSpecifier; } @@ -105,7 +105,7 @@ public String getDeviceSpecifier() { * @return the logger */ public TuningForkLogger getLogger() { - return this.logger; + return logger; } diff --git a/core/src/main/java/de/pottgames/tuningfork/capture/CaptureDevice.java b/core/src/main/java/de/pottgames/tuningfork/capture/CaptureDevice.java index db51adc..35aede6 100644 --- a/core/src/main/java/de/pottgames/tuningfork/capture/CaptureDevice.java +++ b/core/src/main/java/de/pottgames/tuningfork/capture/CaptureDevice.java @@ -48,12 +48,12 @@ private CaptureDevice(long handle, PcmFormat format, int frequency, int bufferSi } else { this.logger = logger; } - this.errorLogger = new ErrorLogger(this.getClass(), logger); - this.alDeviceHandle = handle; + errorLogger = new ErrorLogger(this.getClass(), logger); + alDeviceHandle = handle; this.format = format; this.frequency = frequency; this.bufferSize = bufferSize; - this.alDeviceName = ALC10.alcGetString(handle, ALC11.ALC_CAPTURE_DEVICE_SPECIFIER); + alDeviceName = ALC10.alcGetString(handle, ALC11.ALC_CAPTURE_DEVICE_SPECIFIER); } @@ -61,9 +61,9 @@ private CaptureDevice(long handle, PcmFormat format, int frequency, int bufferSi * Starts the capture. If there were previously recorded samples, they will be overwritten by this method. */ public void startCapture() { - ALC11.alcCaptureStart(this.alDeviceHandle); - if (!this.errorLogger.checkLogAlcError(this.alDeviceHandle, "failed to start capturing")) { - this.logger.trace(this.getClass(), "capturing started"); + ALC11.alcCaptureStart(alDeviceHandle); + if (!errorLogger.checkLogAlcError(alDeviceHandle, "failed to start capturing")) { + logger.trace(this.getClass(), "capturing started"); } } @@ -74,7 +74,7 @@ public void startCapture() { * @return number of samples */ public int capturedSamples() { - return ALC10.alcGetInteger(this.alDeviceHandle, ALC11.ALC_CAPTURE_SAMPLES); + return ALC10.alcGetInteger(alDeviceHandle, ALC11.ALC_CAPTURE_SAMPLES); } @@ -85,7 +85,7 @@ public int capturedSamples() { * @param samples number of samples to fetch */ public void fetch8BitSamples(ByteBuffer buffer, int samples) { - ALC11.alcCaptureSamples(this.alDeviceHandle, buffer, samples); + ALC11.alcCaptureSamples(alDeviceHandle, buffer, samples); } @@ -96,7 +96,7 @@ public void fetch8BitSamples(ByteBuffer buffer, int samples) { * @param samples number of samples to fetch */ public void fetch16BitSamples(short[] buffer, int samples) { - ALC11.alcCaptureSamples(this.alDeviceHandle, buffer, samples); + ALC11.alcCaptureSamples(alDeviceHandle, buffer, samples); } @@ -107,7 +107,7 @@ public void fetch16BitSamples(short[] buffer, int samples) { * @param samples number of samples to fetch */ public void fetch16BitSamples(ShortBuffer buffer, int samples) { - ALC11.alcCaptureSamples(this.alDeviceHandle, buffer, samples); + ALC11.alcCaptureSamples(alDeviceHandle, buffer, samples); } @@ -115,9 +115,9 @@ public void fetch16BitSamples(ShortBuffer buffer, int samples) { * Stops the capture. */ public void stopCapture() { - ALC11.alcCaptureStop(this.alDeviceHandle); - if (!this.errorLogger.checkLogAlcError(this.alDeviceHandle, "failed to stop capturing")) { - this.logger.trace(this.getClass(), "capturing stopped"); + ALC11.alcCaptureStop(alDeviceHandle); + if (!errorLogger.checkLogAlcError(alDeviceHandle, "failed to stop capturing")) { + logger.trace(this.getClass(), "capturing stopped"); } } @@ -128,7 +128,7 @@ public void stopCapture() { * @return the device name */ public String getDeviceName() { - return this.alDeviceName; + return alDeviceName; } @@ -138,7 +138,7 @@ public String getDeviceName() { * @return the format */ public PcmFormat getPcmFormat() { - return this.format; + return format; } @@ -148,7 +148,7 @@ public PcmFormat getPcmFormat() { * @return the frequency */ public int getFrequency() { - return this.frequency; + return frequency; } @@ -158,14 +158,14 @@ public int getFrequency() { * @return the buffer size */ public int getBufferSize() { - return this.bufferSize; + return bufferSize; } @Override public void dispose() { - if (!ALC11.alcCaptureCloseDevice(this.alDeviceHandle)) { - this.logger.error(this.getClass(), "Failed to dispose the CaptureDevice"); + if (!ALC11.alcCaptureCloseDevice(alDeviceHandle)) { + logger.error(this.getClass(), "Failed to dispose the CaptureDevice"); } } @@ -210,8 +210,8 @@ public static CaptureDevice open() { public static CaptureDevice open(CaptureConfig config) { CaptureDevice captureDevice = null; - final long deviceHandle = ALC11.alcCaptureOpenDevice(config.getDeviceSpecifier(), config.getFrequency(), config.getPcmFormat().getAlId(), - config.getBufferSize()); + final long deviceHandle = + ALC11.alcCaptureOpenDevice(config.getDeviceSpecifier(), config.getFrequency(), config.getPcmFormat().getAlId(), config.getBufferSize()); if (deviceHandle != 0L) { captureDevice = new CaptureDevice(deviceHandle, config.getPcmFormat(), config.getFrequency(), config.getBufferSize(), config.getLogger()); } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff16BitDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff16BitDecoder.java index bff561e..6ac4077 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff16BitDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff16BitDecoder.java @@ -34,7 +34,7 @@ public Aiff16BitDecoder(int bitsPerSample) { @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.inputBytesRemaining = streamLength; + inputBytesRemaining = streamLength; } @@ -42,27 +42,27 @@ public void setup(InputStream stream, long streamLength) { public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance - if (this.inputBytesRemaining <= 0) { + if (inputBytesRemaining <= 0) { return -1; } int writeOffset = 0; while (writeOffset < output.length) { - if (this.bufferOffset >= this.bufferLength - 1) { - this.bufferLength = this.fillBuffer(); - if (this.bufferLength < 2) { + if (bufferOffset >= bufferLength - 1) { + bufferLength = fillBuffer(); + if (bufferLength < 2) { return writeOffset == 0 ? -1 : writeOffset; } } - while (this.bufferOffset + 1 < this.bufferLength && writeOffset < output.length - 1) { - final byte byte1 = this.buffer[this.bufferOffset++]; - final byte byte2 = this.buffer[this.bufferOffset++]; + while (bufferOffset + 1 < bufferLength && writeOffset < output.length - 1) { + final byte byte1 = buffer[bufferOffset++]; + final byte byte2 = buffer[bufferOffset++]; output[writeOffset++] = byte2; output[writeOffset++] = byte1; - this.inputBytesRemaining -= 2; - if (this.inputBytesRemaining <= 0) { + inputBytesRemaining -= 2; + if (inputBytesRemaining <= 0) { return writeOffset; } } @@ -73,14 +73,14 @@ public int read(byte[] output) throws IOException { private int fillBuffer() throws IOException { - this.bufferOffset = 0; - return this.stream.read(this.buffer, 0, this.buffer.length); + bufferOffset = 0; + return stream.read(buffer, 0, buffer.length); } @Override public int inputBitsPerSample() { - return this.bitsPerSample; + return bitsPerSample; } @@ -98,7 +98,7 @@ public PcmDataType outputPcmDataType() { @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff24BitDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff24BitDecoder.java index 4eb73a2..0465e3b 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff24BitDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff24BitDecoder.java @@ -34,7 +34,7 @@ public Aiff24BitDecoder(int bitsPerSample) { @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.inputBytesRemaining = streamLength; + inputBytesRemaining = streamLength; } @@ -42,29 +42,29 @@ public void setup(InputStream stream, long streamLength) { public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance - if (this.inputBytesRemaining <= 0) { + if (inputBytesRemaining <= 0) { return -1; } int writeOffset = 0; while (writeOffset < output.length) { - if (this.bufferOffset >= this.bufferLength - 1) { - this.bufferLength = this.fillBuffer(); - if (this.bufferLength < 2) { + if (bufferOffset >= bufferLength - 1) { + bufferLength = fillBuffer(); + if (bufferLength < 2) { return writeOffset == 0 ? -1 : writeOffset; } } - while (this.bufferOffset + 1 < this.bufferLength && writeOffset < output.length - 1) { - final byte byte1 = this.buffer[this.bufferOffset++]; - final byte byte2 = this.buffer[this.bufferOffset++]; - this.bufferOffset++; // we skip byte3 because OpenAL only supports 16-Bit integer sound (float + while (bufferOffset + 1 < bufferLength && writeOffset < output.length - 1) { + final byte byte1 = buffer[bufferOffset++]; + final byte byte2 = buffer[bufferOffset++]; + bufferOffset++; // we skip byte3 because OpenAL only supports 16-Bit integer sound (float // formats = no surround sound) output[writeOffset++] = byte2; output[writeOffset++] = byte1; - this.inputBytesRemaining -= 3; - if (this.inputBytesRemaining <= 0) { + inputBytesRemaining -= 3; + if (inputBytesRemaining <= 0) { return writeOffset; } } @@ -75,14 +75,14 @@ public int read(byte[] output) throws IOException { private int fillBuffer() throws IOException { - this.bufferOffset = 0; - return this.stream.read(this.buffer, 0, this.buffer.length); + bufferOffset = 0; + return stream.read(buffer, 0, buffer.length); } @Override public int inputBitsPerSample() { - return this.bitsPerSample; + return bitsPerSample; } @@ -100,7 +100,7 @@ public PcmDataType outputPcmDataType() { @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff32BitDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff32BitDecoder.java index 98e13ff..4ed0fb9 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff32BitDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff32BitDecoder.java @@ -34,7 +34,7 @@ public Aiff32BitDecoder(int bitsPerSample) { @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.inputBytesRemaining = streamLength; + inputBytesRemaining = streamLength; } @@ -42,29 +42,29 @@ public void setup(InputStream stream, long streamLength) { public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance - if (this.inputBytesRemaining <= 0) { + if (inputBytesRemaining <= 0) { return -1; } int writeOffset = 0; while (writeOffset < output.length) { - if (this.bufferOffset >= this.bufferLength) { - this.bufferLength = this.fillBuffer(); - if (this.bufferLength < 2) { + if (bufferOffset >= bufferLength) { + bufferLength = fillBuffer(); + if (bufferLength < 2) { return writeOffset == 0 ? -1 : writeOffset; } } - while (this.bufferOffset + 1 < this.bufferLength && writeOffset < output.length - 1) { - final byte byte1 = this.buffer[this.bufferOffset++]; - final byte byte2 = this.buffer[this.bufferOffset++]; - this.bufferOffset++; // skip bytes to downsample to 16 bit - this.bufferOffset++; + while (bufferOffset + 1 < bufferLength && writeOffset < output.length - 1) { + final byte byte1 = buffer[bufferOffset++]; + final byte byte2 = buffer[bufferOffset++]; + bufferOffset++; // skip bytes to downsample to 16 bit + bufferOffset++; output[writeOffset++] = byte2; output[writeOffset++] = byte1; - this.inputBytesRemaining -= 4; - if (this.inputBytesRemaining <= 0) { + inputBytesRemaining -= 4; + if (inputBytesRemaining <= 0) { return writeOffset; } } @@ -75,14 +75,14 @@ public int read(byte[] output) throws IOException { private int fillBuffer() throws IOException { - this.bufferOffset = 0; - return this.stream.read(this.buffer, 0, this.buffer.length); + bufferOffset = 0; + return stream.read(buffer, 0, buffer.length); } @Override public int inputBitsPerSample() { - return this.bitsPerSample; + return bitsPerSample; } @@ -100,7 +100,7 @@ public PcmDataType outputPcmDataType() { @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff32BitFloatDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff32BitFloatDecoder.java index 772281b..679280b 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff32BitFloatDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff32BitFloatDecoder.java @@ -28,7 +28,7 @@ public class Aiff32BitFloatDecoder implements AiffDecoder { @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.inputBytesRemaining = streamLength; + inputBytesRemaining = streamLength; } @@ -36,31 +36,31 @@ public void setup(InputStream stream, long streamLength) { public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance - if (this.inputBytesRemaining <= 0) { + if (inputBytesRemaining <= 0) { return -1; } int writeOffset = 0; while (writeOffset < output.length) { - if (this.bufferOffset >= this.bufferLength - 3) { - this.bufferLength = this.fillBuffer(); - if (this.bufferLength < 4) { + if (bufferOffset >= bufferLength - 3) { + bufferLength = fillBuffer(); + if (bufferLength < 4) { return writeOffset == 0 ? -1 : writeOffset; } } - while (this.bufferOffset + 3 < this.bufferLength && writeOffset < output.length - 3) { - final byte byte1 = this.buffer[this.bufferOffset++]; - final byte byte2 = this.buffer[this.bufferOffset++]; - final byte byte3 = this.buffer[this.bufferOffset++]; - final byte byte4 = this.buffer[this.bufferOffset++]; + while (bufferOffset + 3 < bufferLength && writeOffset < output.length - 3) { + final byte byte1 = buffer[bufferOffset++]; + final byte byte2 = buffer[bufferOffset++]; + final byte byte3 = buffer[bufferOffset++]; + final byte byte4 = buffer[bufferOffset++]; output[writeOffset++] = byte4; output[writeOffset++] = byte3; output[writeOffset++] = byte2; output[writeOffset++] = byte1; - this.inputBytesRemaining -= 4; - if (this.inputBytesRemaining <= 0) { + inputBytesRemaining -= 4; + if (inputBytesRemaining <= 0) { return writeOffset; } } @@ -71,8 +71,8 @@ public int read(byte[] output) throws IOException { private int fillBuffer() throws IOException { - this.bufferOffset = 0; - return this.stream.read(this.buffer, 0, this.buffer.length); + bufferOffset = 0; + return stream.read(buffer, 0, buffer.length); } @@ -96,7 +96,7 @@ public PcmDataType outputPcmDataType() { @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff64BitFloatDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff64BitFloatDecoder.java index 78abce6..66b5a01 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff64BitFloatDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff64BitFloatDecoder.java @@ -28,7 +28,7 @@ public class Aiff64BitFloatDecoder implements AiffDecoder { @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.inputBytesRemaining = streamLength; + inputBytesRemaining = streamLength; } @@ -36,29 +36,29 @@ public void setup(InputStream stream, long streamLength) { public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance - if (this.inputBytesRemaining <= 0) { + if (inputBytesRemaining <= 0) { return -1; } int writeOffset = 0; while (writeOffset < output.length) { - if (this.bufferOffset >= this.bufferLength - 7) { - this.bufferLength = this.fillBuffer(); - if (this.bufferLength < 8) { + if (bufferOffset >= bufferLength - 7) { + bufferLength = fillBuffer(); + if (bufferLength < 8) { return writeOffset == 0 ? -1 : writeOffset; } } - while (this.bufferOffset + 7 < this.bufferLength && writeOffset < output.length - 7) { - final byte byte1 = this.buffer[this.bufferOffset++]; - final byte byte2 = this.buffer[this.bufferOffset++]; - final byte byte3 = this.buffer[this.bufferOffset++]; - final byte byte4 = this.buffer[this.bufferOffset++]; - final byte byte5 = this.buffer[this.bufferOffset++]; - final byte byte6 = this.buffer[this.bufferOffset++]; - final byte byte7 = this.buffer[this.bufferOffset++]; - final byte byte8 = this.buffer[this.bufferOffset++]; + while (bufferOffset + 7 < bufferLength && writeOffset < output.length - 7) { + final byte byte1 = buffer[bufferOffset++]; + final byte byte2 = buffer[bufferOffset++]; + final byte byte3 = buffer[bufferOffset++]; + final byte byte4 = buffer[bufferOffset++]; + final byte byte5 = buffer[bufferOffset++]; + final byte byte6 = buffer[bufferOffset++]; + final byte byte7 = buffer[bufferOffset++]; + final byte byte8 = buffer[bufferOffset++]; output[writeOffset++] = byte8; output[writeOffset++] = byte7; output[writeOffset++] = byte6; @@ -67,8 +67,8 @@ public int read(byte[] output) throws IOException { output[writeOffset++] = byte3; output[writeOffset++] = byte2; output[writeOffset++] = byte1; - this.inputBytesRemaining -= 8; - if (this.inputBytesRemaining <= 0) { + inputBytesRemaining -= 8; + if (inputBytesRemaining <= 0) { return writeOffset; } } @@ -79,8 +79,8 @@ public int read(byte[] output) throws IOException { private int fillBuffer() throws IOException { - this.bufferOffset = 0; - return this.stream.read(this.buffer, 0, this.buffer.length); + bufferOffset = 0; + return stream.read(buffer, 0, buffer.length); } @@ -104,7 +104,7 @@ public PcmDataType outputPcmDataType() { @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff8BitDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff8BitDecoder.java index de52939..5bbbc79 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff8BitDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/Aiff8BitDecoder.java @@ -34,7 +34,7 @@ public Aiff8BitDecoder(int bitsPerSample) { @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.inputBytesRemaining = streamLength; + inputBytesRemaining = streamLength; } @@ -42,25 +42,25 @@ public void setup(InputStream stream, long streamLength) { public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance - if (this.inputBytesRemaining <= 0) { + if (inputBytesRemaining <= 0) { return -1; } int writeOffset = 0; while (writeOffset < output.length) { - if (this.bufferOffset >= this.bufferLength) { - this.bufferLength = this.fillBuffer(); - if (this.bufferLength <= 0) { + if (bufferOffset >= bufferLength) { + bufferLength = fillBuffer(); + if (bufferLength <= 0) { return writeOffset == 0 ? -1 : writeOffset; } } - while (this.bufferOffset < this.bufferLength && writeOffset < output.length) { - final byte byte1 = this.buffer[this.bufferOffset++]; + while (bufferOffset < bufferLength && writeOffset < output.length) { + final byte byte1 = buffer[bufferOffset++]; output[writeOffset++] = (byte) (byte1 + 128); - this.inputBytesRemaining -= 1; - if (this.inputBytesRemaining <= 0) { + inputBytesRemaining -= 1; + if (inputBytesRemaining <= 0) { return writeOffset; } } @@ -71,14 +71,14 @@ public int read(byte[] output) throws IOException { private int fillBuffer() throws IOException { - this.bufferOffset = 0; - return this.stream.read(this.buffer, 0, this.buffer.length); + bufferOffset = 0; + return stream.read(buffer, 0, buffer.length); } @Override public int inputBitsPerSample() { - return this.bitsPerSample; + return bitsPerSample; } @@ -96,7 +96,7 @@ public PcmDataType outputPcmDataType() { @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/AiffInputStream.java b/core/src/main/java/de/pottgames/tuningfork/decoder/AiffInputStream.java index 83c64ba..b4e2d41 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/AiffInputStream.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/AiffInputStream.java @@ -45,11 +45,11 @@ public class AiffInputStream implements AudioStream { * @param file the file */ public AiffInputStream(FileHandle file) { - this.stream = file.read(); + stream = file.read(); this.file = file; - this.logger = Audio.get().getLogger(); + logger = Audio.get().getLogger(); try { - this.setup(); + setup(); } catch (final IOException e) { this.throwRuntimeError("Error reading aiff file", e); } @@ -64,10 +64,10 @@ public AiffInputStream(FileHandle file) { */ public AiffInputStream(InputStream stream) { this.stream = stream; - this.file = null; - this.logger = Audio.get().getLogger(); + file = null; + logger = Audio.get().getLogger(); try { - this.setup(); + setup(); } catch (final IOException e) { this.throwRuntimeError("Error reading aiff file", e); } @@ -75,117 +75,116 @@ public AiffInputStream(InputStream stream) { private void setup() throws IOException { - final boolean aifc = this.readFormChunk(); - this.readCommChunk(aifc); + final boolean aifc = readFormChunk(); + readCommChunk(aifc); // SKIP TO SOUND DATA CHUNK - final long dataChunkSize = this.skipToChunk('S', 'S', 'N', 'D'); - final long offset = this.readUnsignedLong(); - final long blockSize = this.readUnsignedLong(); + final long dataChunkSize = skipToChunk('S', 'S', 'N', 'D'); + final long offset = readUnsignedLong(); + final long blockSize = readUnsignedLong(); if (blockSize > 0) { - this.logger.warn(this.getClass(), "This aiff file uses block-aligned sound data, which TuningFork does not fully support."); + logger.warn(this.getClass(), "This aiff file uses block-aligned sound data, which TuningFork does not fully support."); } - this.skip(offset); + skip(offset); // SETUP DECODER int inputBytesPerSample = 0; - if (this.inputBitsPerSample == 64) { + if (inputBitsPerSample == 64) { inputBytesPerSample = 8; - } else if (this.inputBitsPerSample > 24) { + } else if (inputBitsPerSample > 24) { inputBytesPerSample = 4; - } else if (this.inputBitsPerSample > 16) { + } else if (inputBitsPerSample > 16) { inputBytesPerSample = 3; - } else if (this.inputBitsPerSample > 8) { + } else if (inputBitsPerSample > 8) { inputBytesPerSample = 2; } else { inputBytesPerSample = 1; } - if ("NONE".equalsIgnoreCase(this.compressionId)) { + if ("NONE".equalsIgnoreCase(compressionId)) { switch (inputBytesPerSample) { case 1: - this.decoder = new Aiff8BitDecoder(this.inputBitsPerSample); + decoder = new Aiff8BitDecoder(inputBitsPerSample); break; case 2: - this.decoder = new Aiff16BitDecoder(this.inputBitsPerSample); + decoder = new Aiff16BitDecoder(inputBitsPerSample); break; case 3: - this.decoder = new Aiff24BitDecoder(this.inputBitsPerSample); + decoder = new Aiff24BitDecoder(inputBitsPerSample); break; case 4: - this.decoder = new Aiff32BitDecoder(this.inputBitsPerSample); + decoder = new Aiff32BitDecoder(inputBitsPerSample); break; } - } else if ("alaw".equalsIgnoreCase(this.compressionId) && inputBytesPerSample == 1) { - this.decoder = new LawDecoder(this.channels, this.sampleRate, Encoding.A_LAW, true); - } else if ("ulaw".equalsIgnoreCase(this.compressionId) && inputBytesPerSample == 1) { - this.decoder = new LawDecoder(this.channels, this.sampleRate, Encoding.U_LAW, true); - } else if ("FL32".equalsIgnoreCase(this.compressionId) && inputBytesPerSample == 4) { - this.decoder = new Aiff32BitFloatDecoder(); - } else if ("FL64".equalsIgnoreCase(this.compressionId) && inputBytesPerSample == 8) { - this.decoder = new Aiff64BitFloatDecoder(); + } else if ("alaw".equalsIgnoreCase(compressionId) && inputBytesPerSample == 1) { + decoder = new LawDecoder(channels, sampleRate, Encoding.A_LAW, true); + } else if ("ulaw".equalsIgnoreCase(compressionId) && inputBytesPerSample == 1) { + decoder = new LawDecoder(channels, sampleRate, Encoding.U_LAW, true); + } else if ("FL32".equalsIgnoreCase(compressionId) && inputBytesPerSample == 4) { + decoder = new Aiff32BitFloatDecoder(); + } else if ("FL64".equalsIgnoreCase(compressionId) && inputBytesPerSample == 8) { + decoder = new Aiff64BitFloatDecoder(); } - if (this.decoder == null) { - this.throwRuntimeError( - "Unsupported aiff format: bits per sample (" + this.inputBitsPerSample + ")" + ", compression type (" + this.compressionId + ")"); + if (decoder == null) { + this.throwRuntimeError("Unsupported aiff format: bits per sample (" + inputBitsPerSample + ")" + ", compression type (" + compressionId + ")"); } - this.decoder.setup(this.stream, dataChunkSize - 8 - offset); + decoder.setup(stream, dataChunkSize - 8 - offset); } private void readCommChunk(boolean aifc) throws IOException { - final int commChunkSize = this.skipToChunk('C', 'O', 'M', 'M'); + final int commChunkSize = skipToChunk('C', 'O', 'M', 'M'); if (!aifc && commChunkSize != 18 || aifc && commChunkSize < 22) { this.throwRuntimeError("Not a valid aiff file, COMM chunk not found"); } - this.channels = this.readShort(); - this.totalSampleFrames = this.readUnsignedLong(); - this.inputBitsPerSample = this.readShort(); - this.sampleRate = (int) this.readExtendedPrecision(); + channels = readShort(); + totalSampleFrames = readUnsignedLong(); + inputBitsPerSample = readShort(); + sampleRate = (int) readExtendedPrecision(); if (aifc) { - final char char1 = (char) this.stream.read(); - final char char2 = (char) this.stream.read(); - final char char3 = (char) this.stream.read(); - final char char4 = (char) this.stream.read(); + final char char1 = (char) stream.read(); + final char char2 = (char) stream.read(); + final char char3 = (char) stream.read(); + final char char4 = (char) stream.read(); final StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(char1).append(char2).append(char3).append(char4); - this.compressionId = stringBuilder.toString(); + compressionId = stringBuilder.toString(); - this.readPString(); + readPString(); } - this.duration = (float) this.totalSampleFrames / (float) this.sampleRate; + duration = (float) totalSampleFrames / (float) sampleRate; - this.endChunk(commChunkSize); + endChunk(commChunkSize); } private short readShort() throws IOException { - final int byte1 = this.stream.read(); - final int byte2 = this.stream.read(); + final int byte1 = stream.read(); + final int byte2 = stream.read(); return (short) (byte1 << 8 | byte2); } private boolean readFormChunk() throws IOException { // FORM CHUNK ID - final boolean form = this.stream.read() == 'F' && this.stream.read() == 'O' && this.stream.read() == 'R' && this.stream.read() == 'M'; + final boolean form = stream.read() == 'F' && stream.read() == 'O' && stream.read() == 'R' && stream.read() == 'M'; if (!form) { this.throwRuntimeError("Not a valid aiff file, FORM container chunk missing"); } // SKIP CHUNK SIZE - this.stream.read(); - this.stream.read(); - this.stream.read(); - this.stream.read(); + stream.read(); + stream.read(); + stream.read(); + stream.read(); // FORM TYPE - final int char1 = this.stream.read(); - final int char2 = this.stream.read(); - final int char3 = this.stream.read(); - final int char4 = this.stream.read(); + final int char1 = stream.read(); + final int char2 = stream.read(); + final int char3 = stream.read(); + final int char4 = stream.read(); final boolean aiff = char1 == 'A' && char2 == 'I' && char3 == 'F' && char4 == 'F'; final boolean aifc = char1 == 'A' && char2 == 'I' && char3 == 'F' && char4 == 'C'; if (!aiff && !aifc) { @@ -199,26 +198,26 @@ private boolean readFormChunk() throws IOException { private int skipToChunk(char byte1, char byte2, char byte3, char byte4) throws IOException { int chunkSize = -1; while (chunkSize < 0) { - final int read1 = this.stream.read(); + final int read1 = stream.read(); if ((char) read1 != byte1) { continue; } if (read1 < 0) { this.throwRuntimeError("Not a valid aiff file, unexpected end of file"); } - final char read2 = (char) this.stream.read(); + final char read2 = (char) stream.read(); if (read2 != byte2) { continue; } - final char read3 = (char) this.stream.read(); + final char read3 = (char) stream.read(); if (read3 != byte3) { continue; } - final char read4 = (char) this.stream.read(); + final char read4 = (char) stream.read(); if (read4 != byte4) { continue; } - chunkSize = this.readLong(); + chunkSize = readLong(); } return chunkSize; } @@ -226,14 +225,14 @@ private int skipToChunk(char byte1, char byte2, char byte3, char byte4) throws I private void skip(long bytes) throws IOException { for (int i = 0; i < bytes; i++) { - this.stream.read(); + stream.read(); } } public void endChunk(long chunkSize) throws IOException { if (Util.isOdd(chunkSize)) { - this.stream.read(); + stream.read(); } } @@ -241,7 +240,7 @@ public void endChunk(long chunkSize) throws IOException { @Override public int read(byte[] bytes) { try { - return this.decoder.read(bytes); + return decoder.read(bytes); } catch (final IOException e) { throw new TuningForkRuntimeException(e); } @@ -249,79 +248,79 @@ public int read(byte[] bytes) { public long totalSamplesPerChannel() { - return this.totalSampleFrames; + return totalSampleFrames; } @Override public float getDuration() { - return this.duration; + return duration; } @Override public AudioStream reset() { - if (this.file == null) { + if (file == null) { throw new TuningForkRuntimeException("This AudioStream doesn't support resetting."); } StreamUtils.closeQuietly(this); - return new AiffInputStream(this.file); + return new AiffInputStream(file); } @Override public int getChannels() { - return this.channels; + return channels; } @Override public int getSampleRate() { - return this.sampleRate; + return sampleRate; } @Override public int getBitsPerSample() { - return this.decoder.outputBitsPerSample(); + return decoder.outputBitsPerSample(); } @Override public PcmDataType getPcmDataType() { - return this.decoder.outputPcmDataType(); + return decoder.outputPcmDataType(); } @Override public boolean isClosed() { - return this.closed; + return closed; } private int readLong() throws IOException { - return this.stream.read() << 24 | this.stream.read() << 16 | this.stream.read() << 8 | this.stream.read(); + return stream.read() << 24 | stream.read() << 16 | stream.read() << 8 | stream.read(); } private long readUnsignedLong() throws IOException { - return (long) this.stream.read() << 24 | this.stream.read() << 16 | this.stream.read() << 8 | this.stream.read(); + return (long) stream.read() << 24 | stream.read() << 16 | stream.read() << 8 | stream.read(); } private String readPString() throws IOException { - final int stringLength = this.stream.read(); + final int stringLength = stream.read(); final StringBuilder builder = new StringBuilder(); for (int i = 0; i < stringLength; i++) { - builder.append((char) this.stream.read()); + builder.append((char) stream.read()); } // XXX pad byte should be included even if stringLength is 0 according to the specification, // but the Audacity encoder doesn't do this?! // may also be a bug in this code I haven't thought about yet if (stringLength > 0 && Util.isEven(stringLength)) { - this.stream.read(); + stream.read(); } return builder.toString(); @@ -329,16 +328,16 @@ private String readPString() throws IOException { private float readExtendedPrecision() throws IOException { - final int byte1 = this.stream.read(); - final int byte2 = this.stream.read(); - final int byte3 = this.stream.read(); - final int byte4 = this.stream.read(); - final int byte5 = this.stream.read(); - final int byte6 = this.stream.read(); - final int byte7 = this.stream.read(); - final int byte8 = this.stream.read(); - final int byte9 = this.stream.read(); - final int byte10 = this.stream.read(); + final int byte1 = stream.read(); + final int byte2 = stream.read(); + final int byte3 = stream.read(); + final int byte4 = stream.read(); + final int byte5 = stream.read(); + final int byte6 = stream.read(); + final int byte7 = stream.read(); + final int byte8 = stream.read(); + final int byte9 = stream.read(); + final int byte10 = stream.read(); final boolean sign = byte1 >>> 7 != 0; final int exponent = (byte1 & 0b01111111) << 8 | byte2; final long fraction = (long) byte3 << 56L | (long) byte4 << 48 | (long) byte5 << 40 | (long) byte6 << 32 | (long) byte7 << 24 | (long) byte8 << 16 @@ -362,25 +361,25 @@ private void throwRuntimeError(String message) { private void throwRuntimeError(String message, Exception e) { if (e == null) { - throw new TuningForkRuntimeException(message + ": " + this.file.toString()); + throw new TuningForkRuntimeException(message + ": " + file.toString()); } - throw new TuningForkRuntimeException(message + ". " + e.getMessage() + ": " + this.file.toString(), e); + throw new TuningForkRuntimeException(message + ". " + e.getMessage() + ": " + file.toString(), e); } @Override public void close() throws IOException { try { - if (this.decoder != null) { - this.decoder.close(); + if (decoder != null) { + decoder.close(); } else { - this.stream.close(); + stream.close(); } } catch (final IOException e) { // ignore but log it - this.logger.error(this.getClass(), "AiffInputStream didn't close successfully: " + e.getMessage()); + logger.error(this.getClass(), "AiffInputStream didn't close successfully: " + e.getMessage()); } finally { - this.closed = true; + closed = true; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/DefaultWavDecoderProvider.java b/core/src/main/java/de/pottgames/tuningfork/decoder/DefaultWavDecoderProvider.java index 600f2c6..38b1f36 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/DefaultWavDecoderProvider.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/DefaultWavDecoderProvider.java @@ -21,7 +21,7 @@ public WavDecoder getDecoder(WavFmtChunk fmtChunk, boolean forStreaming) { switch (inputBitsPerSample) { case 4: - return this.getAdpcmDecoder(audioFormat, channels, blockAlign, sampleRate, forStreaming); + return getAdpcmDecoder(audioFormat, channels, blockAlign, sampleRate, forStreaming); case 8: if (audioFormat == WavAudioFormat.WAVE_FORMAT_PCM.getRegNumber()) { return new PcmDecoder(inputBitsPerSample, channels, sampleRate, PcmDataType.INTEGER); diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/FlacInputStream.java b/core/src/main/java/de/pottgames/tuningfork/decoder/FlacInputStream.java index c948443..8f97b17 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/FlacInputStream.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/FlacInputStream.java @@ -57,10 +57,10 @@ public FlacInputStream(File file) { * @param stream the input stream */ public FlacInputStream(InputStream stream) { - this.fileHandle = null; + fileHandle = null; try { - this.decoder = new FlacDecoder(stream); - while (this.decoder.readAndHandleMetadataBlock() != null) { + decoder = new FlacDecoder(stream); + while (decoder.readAndHandleMetadataBlock() != null) { // read all meta data blocks } } catch (final IOException e) { @@ -68,7 +68,7 @@ public FlacInputStream(InputStream stream) { throw new TuningForkRuntimeException(e); } - this.initialize(); + initialize(); } @@ -78,10 +78,10 @@ public FlacInputStream(InputStream stream) { * @param file the file handle */ public FlacInputStream(FileHandle file) { - this.fileHandle = file; + fileHandle = file; try { - this.decoder = new FlacDecoder(file.read()); - while (this.decoder.readAndHandleMetadataBlock() != null) { + decoder = new FlacDecoder(file.read()); + while (decoder.readAndHandleMetadataBlock() != null) { // read all meta data blocks } } catch (final IOException e) { @@ -89,77 +89,77 @@ public FlacInputStream(FileHandle file) { throw new TuningForkRuntimeException(e); } - this.initialize(); + initialize(); } private void initialize() { - if (this.decoder.streamInfo == null) { + if (decoder.streamInfo == null) { throw new TuningForkRuntimeException("Missing StreamInfo in flac file."); } - final int numChannels = this.decoder.streamInfo.numChannels; + final int numChannels = decoder.streamInfo.numChannels; if (!PcmFormat.isSupportedChannelCount(numChannels)) { throw new TuningForkRuntimeException("Unsupported number of channels in flac file. Must be 1, 2, 4, 6, 7 or 8 but is: " + numChannels); } - final int bitsPerSample = this.decoder.streamInfo.sampleDepth; + final int bitsPerSample = decoder.streamInfo.sampleDepth; if (bitsPerSample != 8 && bitsPerSample != 16) { throw new TuningForkRuntimeException("Unsupported bits per sample in flac file, only 8 and 16 Bit is supported."); } - if (this.decoder.streamInfo.maxBlockSize > StreamedSoundSource.BUFFER_SIZE_PER_CHANNEL * numChannels) { + if (decoder.streamInfo.maxBlockSize > StreamedSoundSource.BUFFER_SIZE_PER_CHANNEL * numChannels) { throw new TuningForkRuntimeException( "Flac file exceeds maximum supported block size by TuningFork which is: " + StreamedSoundSource.BUFFER_SIZE_PER_CHANNEL + " per channel"); } - this.sampleBuffer = new int[this.decoder.streamInfo.numChannels][65536]; - this.bytesPerSample = this.decoder.streamInfo.sampleDepth / 8; + sampleBuffer = new int[decoder.streamInfo.numChannels][65536]; + bytesPerSample = decoder.streamInfo.sampleDepth / 8; - this.readBlock(); + readBlock(); - this.duration = (float) this.totalSamples() / this.getSampleRate(); + duration = (float) totalSamples() / getSampleRate(); } @Override public float getDuration() { - return this.duration; + return duration; } @Override public AudioStream reset() { - if (this.fileHandle == null) { + if (fileHandle == null) { throw new TuningForkRuntimeException("This AudioStream doesn't support resetting."); } StreamUtils.closeQuietly(this); - return new FlacInputStream(this.fileHandle); + return new FlacInputStream(fileHandle); } @Override public int read(byte[] bytes) { - if (this.sampleBufferBlockSize == 0) { + if (sampleBufferBlockSize == 0) { return -1; } int availableBytes = bytes.length; int bytesIndex = 0; - while (availableBytes >= this.sampleBufferBlockSize * this.decoder.streamInfo.numChannels * this.bytesPerSample) { - for (int i = 0; i < this.sampleBufferBlockSize; i++) { - for (int channelIndex = 0; channelIndex < this.decoder.streamInfo.numChannels; channelIndex++) { - int sample = this.sampleBuffer[channelIndex][i]; - if (this.bytesPerSample == 1) { + while (availableBytes >= sampleBufferBlockSize * decoder.streamInfo.numChannels * bytesPerSample) { + for (int i = 0; i < sampleBufferBlockSize; i++) { + for (int channelIndex = 0; channelIndex < decoder.streamInfo.numChannels; channelIndex++) { + int sample = sampleBuffer[channelIndex][i]; + if (bytesPerSample == 1) { sample += 128; // because OpenAL expects an unsigned byte } - for (int j = 0; j < this.bytesPerSample; j++, bytesIndex++) { + for (int j = 0; j < bytesPerSample; j++, bytesIndex++) { bytes[bytesIndex] = (byte) (sample >>> (j << 3)); } } } - availableBytes -= this.sampleBufferBlockSize * this.decoder.streamInfo.numChannels * this.bytesPerSample; - this.readBlock(); - if (this.sampleBufferBlockSize == 0) { + availableBytes -= sampleBufferBlockSize * decoder.streamInfo.numChannels * bytesPerSample; + readBlock(); + if (sampleBufferBlockSize == 0) { break; } } @@ -170,7 +170,7 @@ public int read(byte[] bytes) { private void readBlock() { try { - this.sampleBufferBlockSize = this.decoder.readAudioBlock(this.sampleBuffer, 0); + sampleBufferBlockSize = decoder.readAudioBlock(sampleBuffer, 0); } catch (final IOException e) { throw new TuningForkRuntimeException(e); } @@ -178,30 +178,30 @@ private void readBlock() { public long totalSamples() { - return this.decoder.streamInfo.numSamples; + return decoder.streamInfo.numSamples; } @Override public int getChannels() { - return this.decoder.streamInfo.numChannels; + return decoder.streamInfo.numChannels; } @Override public int getSampleRate() { - return this.decoder.streamInfo.sampleRate; + return decoder.streamInfo.sampleRate; } @Override public int getBitsPerSample() { - return this.decoder.streamInfo.sampleDepth; + return decoder.streamInfo.sampleDepth; } public int getBytesPerSample() { - return this.bytesPerSample; + return bytesPerSample; } @@ -213,16 +213,16 @@ public PcmDataType getPcmDataType() { @Override public boolean isClosed() { - return this.closed; + return closed; } @Override public void close() throws IOException { try { - this.decoder.close(); + decoder.close(); } finally { - this.closed = true; + closed = true; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/ImaAdpcmDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/ImaAdpcmDecoder.java index 160b682..8e60515 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/ImaAdpcmDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/ImaAdpcmDecoder.java @@ -27,28 +27,28 @@ public class ImaAdpcmDecoder implements WavDecoder { public ImaAdpcmDecoder(int blockSize, int channels, int sampleRate) { assert channels == 1 || channels == 2; this.channels = channels; - this.stereo = channels == 2; + stereo = channels == 2; this.blockSize = blockSize; this.sampleRate = sampleRate; - this.outputSamples = new byte[blockSize * 4 - 4 * channels]; - this.prediction[0] = new Prediction(); - this.prediction[1] = new Prediction(); + outputSamples = new byte[blockSize * 4 - 4 * channels]; + prediction[0] = new Prediction(); + prediction[1] = new Prediction(); } @Override public void setup(InputStream stream, long streamLength) { - this.bytesRemaining = streamLength; - this.stream = new BufferedInputStream(stream, this.blockSize * 2); + bytesRemaining = streamLength; + this.stream = new BufferedInputStream(stream, blockSize * 2); // CALC TOTAL SAMPLES - long numberOfBlocks = streamLength / this.blockSize; - if (streamLength % this.blockSize > 0) { + long numberOfBlocks = streamLength / blockSize; + if (streamLength % blockSize > 0) { numberOfBlocks++; } - final long blockBytes = numberOfBlocks * 4L * this.channels; - this.totalOutputSamplesPerChannel = (streamLength * 2L - blockBytes * 2L) / this.channels; - this.outputBytesRemaining = this.totalOutputSamplesPerChannel * this.channels * 2; + final long blockBytes = numberOfBlocks * 4L * channels; + totalOutputSamplesPerChannel = (streamLength * 2L - blockBytes * 2L) / channels; + outputBytesRemaining = totalOutputSamplesPerChannel * channels * 2; } @@ -56,17 +56,17 @@ public void setup(InputStream stream, long streamLength) { public int read(byte[] output) throws IOException { for (int i = 0; i < output.length; i++) { // DECODE NEXT BLOCK IF NECESSARY - if (this.outputSamplePosition >= this.outputSampleSize) { - if (this.decodeNextBlock() == ImaAdpcmDecoder.END_OF_STREAM) { + if (outputSamplePosition >= outputSampleSize) { + if (decodeNextBlock() == ImaAdpcmDecoder.END_OF_STREAM) { return i > 0 ? i : -1; } } // COPY OUTPUT BYTE - output[i] = this.outputSamples[this.outputSamplePosition++]; + output[i] = outputSamples[outputSamplePosition++]; } - this.outputBytesRemaining -= output.length; + outputBytesRemaining -= output.length; return output.length; } @@ -76,49 +76,49 @@ private int decodeNextBlock() throws IOException { int preambleBytes = 0; // READ LEFT CHANNEL PREAMBLE - this.prediction[0].predictor = (short) (this.readByte() | this.readByte() << 8); - this.prediction[0].stepIndex = MathUtils.clamp(this.readByte(), 0, 88); - this.prediction[0].step = Prediction.STEP_TABLE[this.prediction[0].stepIndex]; - final int skipValue = this.readByte(); + prediction[0].predictor = (short) (readByte() | readByte() << 8); + prediction[0].stepIndex = MathUtils.clamp(readByte(), 0, 88); + prediction[0].step = Prediction.STEP_TABLE[prediction[0].stepIndex]; + final int skipValue = readByte(); if (skipValue < 0) { return ImaAdpcmDecoder.END_OF_STREAM; } preambleBytes += 4; // READ RIGHT CHANNEL PREAMBLE - if (this.stereo) { - this.prediction[1].predictor = (short) (this.readByte() | this.readByte() << 8); - this.prediction[1].stepIndex = MathUtils.clamp(this.readByte(), 0, 88); - this.prediction[1].step = Prediction.STEP_TABLE[this.prediction[1].stepIndex]; - final int skipValue2 = this.readByte(); - if (skipValue2 < 0 || this.bytesRemaining < 0) { + if (stereo) { + prediction[1].predictor = (short) (readByte() | readByte() << 8); + prediction[1].stepIndex = MathUtils.clamp(readByte(), 0, 88); + prediction[1].step = Prediction.STEP_TABLE[prediction[1].stepIndex]; + final int skipValue2 = readByte(); + if (skipValue2 < 0 || bytesRemaining < 0) { return ImaAdpcmDecoder.END_OF_STREAM; } preambleBytes += 4; } // DECODE BLOCK - this.outputSamplePosition = 0; + outputSamplePosition = 0; int outputSamples = 0; int byteChannelCounter = 0; int predictionIndex = 0; int outputSamplesIndexLeft = 0; int outputSamplesIndexRight = 2; - final int outputSampleStep = this.stereo ? 3 : 1; - for (int i = 0; i < this.blockSize - preambleBytes; i++) { + final int outputSampleStep = stereo ? 3 : 1; + for (int i = 0; i < blockSize - preambleBytes; i++) { // READ INPUT BYTE - final int inputByte = this.readByte(); - if (inputByte < 0 || this.bytesRemaining < 0) { - this.outputSampleSize = outputSamples * 2; + final int inputByte = readByte(); + if (inputByte < 0 || bytesRemaining < 0) { + outputSampleSize = outputSamples * 2; return ImaAdpcmDecoder.END_OF_STREAM; } // DECODE final int nibble1 = inputByte & 0b1111; final int nibble2 = inputByte >>> 4; - final int sample1 = this.decodeNibble(nibble1, this.prediction[predictionIndex]); - final int sample2 = this.decodeNibble(nibble2, this.prediction[predictionIndex]); + final int sample1 = decodeNibble(nibble1, prediction[predictionIndex]); + final int sample2 = decodeNibble(nibble2, prediction[predictionIndex]); final byte outputSample1Byte1 = (byte) sample1; final byte outputSample1Byte2 = (byte) (sample1 >>> 8); final byte outputSample2Byte1 = (byte) sample2; @@ -147,7 +147,7 @@ private int decodeNextBlock() throws IOException { outputSamples += 2; // SETUP PREDICTION FOR NEXT BYTE - if (this.stereo) { + if (stereo) { byteChannelCounter += 1; if (byteChannelCounter >= 4) { byteChannelCounter = 0; @@ -157,8 +157,8 @@ private int decodeNextBlock() throws IOException { } - this.outputSampleSize = outputSamples * 2; - return this.outputSampleSize; + outputSampleSize = outputSamples * 2; + return outputSampleSize; } @@ -193,8 +193,8 @@ private int decodeNibble(int nibble, Prediction prediction) { private int readByte() throws IOException { - this.bytesRemaining -= 1; - return this.stream.read(); + bytesRemaining -= 1; + return stream.read(); } @@ -212,19 +212,19 @@ public int outputBitsPerSample() { @Override public int outputChannels() { - return this.channels; + return channels; } @Override public int outputSampleRate() { - return this.sampleRate; + return sampleRate; } @Override public long outputTotalSamplesPerChannel() { - return this.totalOutputSamplesPerChannel; + return totalOutputSamplesPerChannel; } @@ -236,13 +236,13 @@ public PcmDataType outputPcmDataType() { @Override public long bytesRemaining() { - return this.outputBytesRemaining; + return outputBytesRemaining; } @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/ImaAdpcmRsDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/ImaAdpcmRsDecoder.java index 49402d1..a605175 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/ImaAdpcmRsDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/ImaAdpcmRsDecoder.java @@ -32,15 +32,15 @@ public ImaAdpcmRsDecoder(int blockSize, int channels, int sampleRate) { public void setup(InputStream stream, long streamLength) { this.streamLength = streamLength; this.stream = stream; - long numberOfBlocks = streamLength / this.blockSize; - if (streamLength % this.blockSize > 0) { + long numberOfBlocks = streamLength / blockSize; + if (streamLength % blockSize > 0) { numberOfBlocks++; } - final long blockBytes = numberOfBlocks * 4L * this.channels; - this.totalOutputSamplesPerChannel = (streamLength * 2L - blockBytes * 2L) / this.channels; + final long blockBytes = numberOfBlocks * 4L * channels; + totalOutputSamplesPerChannel = (streamLength * 2L - blockBytes * 2L) / channels; try { - this.decode(); + decode(); } catch (final IOException e) { throw new TuningForkRuntimeException("Error decoding IMA ADPCM data", e); } @@ -49,22 +49,22 @@ public void setup(InputStream stream, long streamLength) { private void decode() throws IOException { final ImaAdpcmRs nativeDecoder = new ImaAdpcmRs(); - final byte[] data = new byte[(int) this.streamLength]; - Util.readAll(this.stream, data, data.length); - this.audioData = nativeDecoder.decode(data, this.blockSize, this.channels == 2); - this.bytesRemaining = this.audioData.length; - this.readIndex = 0; + final byte[] data = new byte[(int) streamLength]; + Util.readAll(stream, data, data.length); + audioData = nativeDecoder.decode(data, blockSize, channels == 2); + bytesRemaining = audioData.length; + readIndex = 0; } @Override public int read(byte[] output) throws IOException { - final int copiedBytes = (int) Math.min(this.bytesRemaining, output.length); + final int copiedBytes = (int) Math.min(bytesRemaining, output.length); if (copiedBytes <= 0) { return -1; } - System.arraycopy(this.audioData, this.readIndex, output, 0, copiedBytes); - this.bytesRemaining -= copiedBytes; + System.arraycopy(audioData, readIndex, output, 0, copiedBytes); + bytesRemaining -= copiedBytes; return copiedBytes; } @@ -83,19 +83,19 @@ public int outputBitsPerSample() { @Override public int outputChannels() { - return this.channels; + return channels; } @Override public int outputSampleRate() { - return this.sampleRate; + return sampleRate; } @Override public long outputTotalSamplesPerChannel() { - return this.totalOutputSamplesPerChannel; + return totalOutputSamplesPerChannel; } @@ -107,13 +107,13 @@ public PcmDataType outputPcmDataType() { @Override public long bytesRemaining() { - return this.bytesRemaining; + return bytesRemaining; } @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/Int24To16PcmDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/Int24To16PcmDecoder.java index 4b162ef..9b7b549 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/Int24To16PcmDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/Int24To16PcmDecoder.java @@ -25,8 +25,8 @@ public Int24To16PcmDecoder(int channels, int sampleRate) { @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.bytesRemaining = streamLength; - this.totalOutputSamplesPerChannel = this.bytesRemaining / 3L / this.channels; + bytesRemaining = streamLength; + totalOutputSamplesPerChannel = bytesRemaining / 3L / channels; } @@ -35,7 +35,7 @@ public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance for (int i = 0; i < output.length; i++) { - final int outputByte = this.fetchNextOutputByte(); + final int outputByte = fetchNextOutputByte(); if (outputByte == Int24To16PcmDecoder.END_OF_STREAM) { return i == 0 ? -1 : i; } @@ -47,23 +47,23 @@ public int read(byte[] output) throws IOException { private int fetchNextOutputByte() throws IOException { - if (this.outputSampleFetchedBytes >= 2) { - this.outputSample = this.fetchNextOutputSample(); - if (this.outputSample == Int24To16PcmDecoder.END_OF_STREAM) { + if (outputSampleFetchedBytes >= 2) { + outputSample = fetchNextOutputSample(); + if (outputSample == Int24To16PcmDecoder.END_OF_STREAM) { return Int24To16PcmDecoder.END_OF_STREAM; } - this.outputSampleFetchedBytes = 0; + outputSampleFetchedBytes = 0; } - final int outputByte = this.outputSample >>> this.outputSampleFetchedBytes * 8 & 0xff; - this.outputSampleFetchedBytes++; + final int outputByte = outputSample >>> outputSampleFetchedBytes * 8 & 0xff; + outputSampleFetchedBytes++; return outputByte; } private int fetchNextOutputSample() throws IOException { - final int inputSample = this.fetchNextInputSample(); + final int inputSample = fetchNextInputSample(); if (inputSample == Int24To16PcmDecoder.END_OF_STREAM) { return Int24To16PcmDecoder.END_OF_STREAM; } @@ -73,20 +73,20 @@ private int fetchNextOutputSample() throws IOException { private int fetchNextInputSample() throws IOException { - if (this.bytesRemaining < 3) { + if (bytesRemaining < 3) { return Int24To16PcmDecoder.END_OF_STREAM; } - final int byte1 = this.stream.read(); - final int byte2 = this.stream.read(); - final int byte3 = this.stream.read(); + final int byte1 = stream.read(); + final int byte2 = stream.read(); + final int byte3 = stream.read(); if (byte3 < 0) { - this.bytesRemaining = 0; + bytesRemaining = 0; return Int24To16PcmDecoder.END_OF_STREAM; } - this.bytesRemaining -= 3; - if (this.bytesRemaining < 0) { - this.bytesRemaining = 0; + bytesRemaining -= 3; + if (bytesRemaining < 0) { + bytesRemaining = 0; } return byte1 | byte2 << 8 | byte3 << 16; @@ -107,19 +107,19 @@ public int outputBitsPerSample() { @Override public int outputChannels() { - return this.channels; + return channels; } @Override public int outputSampleRate() { - return this.sampleRate; + return sampleRate; } @Override public long outputTotalSamplesPerChannel() { - return this.totalOutputSamplesPerChannel; + return totalOutputSamplesPerChannel; } @@ -131,13 +131,13 @@ public PcmDataType outputPcmDataType() { @Override public long bytesRemaining() { - return (long) (this.bytesRemaining / 3f * 2f); + return (long) (bytesRemaining / 3f * 2f); } @Override public void close() throws IOException, NullPointerException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/Int32To16PcmDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/Int32To16PcmDecoder.java index f96ec5d..d252716 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/Int32To16PcmDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/Int32To16PcmDecoder.java @@ -25,8 +25,8 @@ public Int32To16PcmDecoder(int channels, int sampleRate) { @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.bytesRemaining = streamLength; - this.totalOutputSamplesPerChannel = this.bytesRemaining / 4L / this.channels; + bytesRemaining = streamLength; + totalOutputSamplesPerChannel = bytesRemaining / 4L / channels; } @@ -35,7 +35,7 @@ public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance for (int i = 0; i < output.length; i++) { - final long outputByte = this.fetchNextOutputByte(); + final long outputByte = fetchNextOutputByte(); if (outputByte == Int32To16PcmDecoder.END_OF_STREAM) { return i == 0 ? -1 : i; } @@ -47,23 +47,23 @@ public int read(byte[] output) throws IOException { private long fetchNextOutputByte() throws IOException { - if (this.outputSampleFetchedBytes >= 2) { - this.outputSample = this.fetchNextOutputSample(); - if (this.outputSample == Int32To16PcmDecoder.END_OF_STREAM) { + if (outputSampleFetchedBytes >= 2) { + outputSample = fetchNextOutputSample(); + if (outputSample == Int32To16PcmDecoder.END_OF_STREAM) { return Int32To16PcmDecoder.END_OF_STREAM; } - this.outputSampleFetchedBytes = 0; + outputSampleFetchedBytes = 0; } - final long outputByte = this.outputSample >>> this.outputSampleFetchedBytes * 8 & 0xffL; - this.outputSampleFetchedBytes++; + final long outputByte = outputSample >>> outputSampleFetchedBytes * 8 & 0xffL; + outputSampleFetchedBytes++; return outputByte; } private long fetchNextOutputSample() throws IOException { - final long inputSample = this.fetchNextInputSample(); + final long inputSample = fetchNextInputSample(); if (inputSample == Int32To16PcmDecoder.END_OF_STREAM) { return Int32To16PcmDecoder.END_OF_STREAM; } @@ -73,21 +73,21 @@ private long fetchNextOutputSample() throws IOException { private long fetchNextInputSample() throws IOException { - if (this.bytesRemaining < 3) { + if (bytesRemaining < 3) { return Int32To16PcmDecoder.END_OF_STREAM; } - final int byte1 = this.stream.read(); - final int byte2 = this.stream.read(); - final int byte3 = this.stream.read(); - final int byte4 = this.stream.read(); + final int byte1 = stream.read(); + final int byte2 = stream.read(); + final int byte3 = stream.read(); + final int byte4 = stream.read(); if (byte4 < 0) { - this.bytesRemaining = 0; + bytesRemaining = 0; return Int32To16PcmDecoder.END_OF_STREAM; } - this.bytesRemaining -= 4; - if (this.bytesRemaining < 0) { - this.bytesRemaining = 0; + bytesRemaining -= 4; + if (bytesRemaining < 0) { + bytesRemaining = 0; } return byte1 | (long) byte2 << 8 | (long) byte3 << 16 | (long) byte4 << 24; @@ -108,19 +108,19 @@ public int outputBitsPerSample() { @Override public int outputChannels() { - return this.channels; + return channels; } @Override public int outputSampleRate() { - return this.sampleRate; + return sampleRate; } @Override public long outputTotalSamplesPerChannel() { - return this.totalOutputSamplesPerChannel; + return totalOutputSamplesPerChannel; } @@ -132,13 +132,13 @@ public PcmDataType outputPcmDataType() { @Override public long bytesRemaining() { - return this.bytesRemaining / 2L; + return bytesRemaining / 2L; } @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/LawDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/LawDecoder.java index 74f900b..d03f22d 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/LawDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/LawDecoder.java @@ -45,28 +45,27 @@ public LawDecoder(int channels, int sampleRate, Encoding encoding, boolean bigEn @Override public void setup(InputStream stream, long streamLength) { - this.bytesRemaining = streamLength; - this.totalOutputSamplesPerChannel = streamLength / this.channels; + bytesRemaining = streamLength; + totalOutputSamplesPerChannel = streamLength / channels; // INPUT STREAM - final AudioFormat.Encoding inputEncoding = this.encoding == Encoding.U_LAW ? AudioFormat.Encoding.ULAW : AudioFormat.Encoding.ALAW; - final AudioFormat inputFormat = new AudioFormat(inputEncoding, this.sampleRate, 8, this.channels, this.channels, this.sampleRate, this.bigEndian); - this.inputStream = new AudioInputStream(stream, inputFormat, this.totalOutputSamplesPerChannel); + final AudioFormat.Encoding inputEncoding = encoding == Encoding.U_LAW ? AudioFormat.Encoding.ULAW : AudioFormat.Encoding.ALAW; + final AudioFormat inputFormat = new AudioFormat(inputEncoding, sampleRate, 8, channels, channels, sampleRate, bigEndian); + inputStream = new AudioInputStream(stream, inputFormat, totalOutputSamplesPerChannel); // OUTPUT STREAM - final AudioFormat outputFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, this.sampleRate, 16, this.channels, this.channels * 2, - this.sampleRate, false); - this.outputStream = AudioSystem.getAudioInputStream(outputFormat, this.inputStream); + final AudioFormat outputFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, sampleRate, 16, channels, channels * 2, sampleRate, false); + outputStream = AudioSystem.getAudioInputStream(outputFormat, inputStream); } @Override public int read(byte[] output) throws IOException { - final int read = this.outputStream.read(output); + final int read = outputStream.read(output); if (read <= 0) { - this.bytesRemaining = -1; + bytesRemaining = -1; } else { - this.bytesRemaining = MathUtils.clamp(this.bytesRemaining - read, -1, Long.MAX_VALUE); + bytesRemaining = MathUtils.clamp(bytesRemaining - read, -1, Long.MAX_VALUE); } return read; } @@ -86,19 +85,19 @@ public int outputBitsPerSample() { @Override public int outputChannels() { - return this.channels; + return channels; } @Override public int outputSampleRate() { - return this.sampleRate; + return sampleRate; } @Override public long outputTotalSamplesPerChannel() { - return this.totalOutputSamplesPerChannel; + return totalOutputSamplesPerChannel; } @@ -110,13 +109,13 @@ public PcmDataType outputPcmDataType() { @Override public long bytesRemaining() { - return this.bytesRemaining * 2; + return bytesRemaining * 2; } @Override public void close() throws IOException { - this.inputStream.close(); + inputStream.close(); } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/Mp3InputStream.java b/core/src/main/java/de/pottgames/tuningfork/decoder/Mp3InputStream.java index 4b78149..669edf9 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/Mp3InputStream.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/Mp3InputStream.java @@ -28,24 +28,24 @@ public class Mp3InputStream implements AudioStream { public Mp3InputStream(FileHandle file) { - this.init(file); + init(file); } protected void init(FileHandle file) { this.file = file; - this.bitstream = new Bitstream(file.read()); - this.decoder = new MP3Decoder(); + bitstream = new Bitstream(file.read()); + decoder = new MP3Decoder(); try { - final Header header = this.bitstream.readFrame(); + final Header header = bitstream.readFrame(); if (header == null) { throw new TuningForkRuntimeException("Empty MP3"); } - this.channels = header.mode() == Header.SINGLE_CHANNEL ? 1 : 2; - this.duration = header.total_ms((int) file.length()) / 1000f; - this.outputBuffer = new OutputBuffer(this.channels, false); - this.decoder.setOutputBuffer(this.outputBuffer); - this.sampleRate = header.getSampleRate(); + channels = header.mode() == Header.SINGLE_CHANNEL ? 1 : 2; + duration = header.total_ms((int) file.length()) / 1000f; + outputBuffer = new OutputBuffer(channels, false); + decoder.setOutputBuffer(outputBuffer); + sampleRate = header.getSampleRate(); } catch (final BitstreamException e) { throw new TuningForkRuntimeException("error while preloading mp3", e); } @@ -58,24 +58,24 @@ public int read(byte[] bytes) { int totalLength = 0; final int minRequiredLength = bytes.length - OutputBuffer.BUFFERSIZE * 2; while (totalLength <= minRequiredLength) { - final Header header = this.bitstream.readFrame(); + final Header header = bitstream.readFrame(); if (header == null) { break; } try { - this.decoder.decodeFrame(header, this.bitstream); + decoder.decodeFrame(header, bitstream); } catch (final Exception ignored) { // JLayer's decoder throws ArrayIndexOutOfBoundsException sometimes?! } - this.bitstream.closeFrame(); + bitstream.closeFrame(); - final int length = this.outputBuffer.reset(); - System.arraycopy(this.outputBuffer.getBuffer(), 0, bytes, totalLength, length); + final int length = outputBuffer.reset(); + System.arraycopy(outputBuffer.getBuffer(), 0, bytes, totalLength, length); totalLength += length; } return totalLength; } catch (final Throwable ex) { - this.reset(); + reset(); throw new TuningForkRuntimeException("Error reading audio data.", ex); } } @@ -83,27 +83,27 @@ public int read(byte[] bytes) { @Override public float getDuration() { - return this.duration; + return duration; } @Override public AudioStream reset() { - this.close(); - this.init(this.file); + close(); + init(file); return this; } @Override public int getChannels() { - return this.channels; + return channels; } @Override public int getSampleRate() { - return this.sampleRate; + return sampleRate; } @@ -121,22 +121,22 @@ public PcmDataType getPcmDataType() { @Override public void close() { - if (!this.closed) { - this.outputBuffer = null; - this.decoder = null; + if (!closed) { + outputBuffer = null; + decoder = null; try { - this.bitstream.close(); + bitstream.close(); } catch (final BitstreamException e) { // ignore } - this.bitstream = null; + bitstream = null; } } @Override public boolean isClosed() { - return this.closed; + return closed; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/MsAdpcmDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/MsAdpcmDecoder.java index 70c852a..2aaa35b 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/MsAdpcmDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/MsAdpcmDecoder.java @@ -35,16 +35,16 @@ public MsAdpcmDecoder(int blockSize, int channels, int sampleRate) { this.channels = channels; this.sampleRate = sampleRate; this.blockSize = blockSize; - this.blockAlign = (blockSize / channels - 7) * 2 + 2; + blockAlign = (blockSize / channels - 7) * 2 + 2; } @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.bytesRemaining = streamLength; - final int numberOfBlocks = (int) (streamLength / this.blockSize); - this.totalSamplesPerChannel = numberOfBlocks * this.blockAlign; + bytesRemaining = streamLength; + final int numberOfBlocks = (int) (streamLength / blockSize); + totalSamplesPerChannel = numberOfBlocks * blockAlign; } @@ -52,23 +52,23 @@ public void setup(InputStream stream, long streamLength) { public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance - if (this.bytesRemaining <= 0) { + if (bytesRemaining <= 0) { return -1; } int bytesToRead = output.length; int offset = 0; - while (bytesToRead > 0 && this.bytesRemaining > 0) { - final int bytesRead = this.stream.read(output, offset, (int) Math.min(bytesToRead, this.bytesRemaining)); + while (bytesToRead > 0 && bytesRemaining > 0) { + final int bytesRead = stream.read(output, offset, (int) Math.min(bytesToRead, bytesRemaining)); if (bytesRead == -1) { if (offset > 0) { return offset; } - this.bytesRemaining = 0; + bytesRemaining = 0; return -1; } - this.bytesRemaining -= bytesRead; + bytesRemaining -= bytesRead; bytesToRead -= bytesRead; offset += bytesRead; } @@ -91,31 +91,31 @@ public int outputBitsPerSample() { @Override public int blockAlign() { - return this.blockAlign; + return blockAlign; } @Override public int blockSize() { - return this.blockSize; + return blockSize; } @Override public int outputChannels() { - return this.channels; + return channels; } @Override public int outputSampleRate() { - return this.sampleRate; + return sampleRate; } @Override public long outputTotalSamplesPerChannel() { - return this.totalSamplesPerChannel; + return totalSamplesPerChannel; } @@ -127,13 +127,13 @@ public PcmDataType outputPcmDataType() { @Override public long bytesRemaining() { - return this.bytesRemaining; + return bytesRemaining; } @Override public void close() throws IOException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/OggInputStream.java b/core/src/main/java/de/pottgames/tuningfork/decoder/OggInputStream.java index 2816503..4f8f720 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/OggInputStream.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/OggInputStream.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.InputStream; -import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -101,15 +100,15 @@ public class OggInputStream implements AudioStream { /** * The comment read from the OGG file */ - private final Comment comment = new Comment(); // struct that stores all the bitstream user comments + private final Comment comment = new Comment(); // struct that stores all the bitstream user comments /** * The Vorbis DSP stat eused to decode the OGG */ - private final DspState dspState = new DspState(); // central working state for the packet->PCM decoder + private final DspState dspState = new DspState(); // central working state for the packet->PCM decoder /** * The OGG block we're currently working with to convert PCM */ - private final Block vorbisBlock = new Block(this.dspState); // local working space for packet->PCM decode + private final Block vorbisBlock = new Block(dspState); // local working space for packet->PCM decode /** * Temporary scratch buffer @@ -155,15 +154,15 @@ public class OggInputStream implements AudioStream { * @param previousStream may be null */ public OggInputStream(FileHandle file, OggInputStream previousStream) { - this.logger = Audio.get().getLogger(); + logger = Audio.get().getLogger(); if (previousStream != null) { - this.convbuffer = previousStream.convbuffer; - this.pcmBuffer = previousStream.pcmBuffer; - this.duration = previousStream.duration; + convbuffer = previousStream.convbuffer; + pcmBuffer = previousStream.pcmBuffer; + duration = previousStream.duration; } else { - this.convbuffer = new byte[this.convsize]; - this.pcmBuffer = BufferUtils.createByteBuffer(4096 * 500); + convbuffer = new byte[convsize]; + pcmBuffer = BufferUtils.createByteBuffer(4096 * 500); float duration = -1f; final FileType fileType = file.type(); @@ -172,26 +171,26 @@ public OggInputStream(FileHandle file, OggInputStream previousStream) { final VorbisFile vorbisFile = new VorbisFile(file.file().getAbsolutePath()); duration = vorbisFile.time_total(-1); } catch (final Throwable e) { - this.logger.warn(this.getClass(), "Couldn't measure the duration: " + e.getMessage()); + logger.warn(this.getClass(), "Couldn't measure the duration: " + e.getMessage()); } } else { final StringBuilder builder = new StringBuilder(); builder.append("Can't measure the duration of: "); builder.append(file.path()); builder.append(" - solution: use Gdx.files.absolute() and exclude it from being packed in the jar on " + "distribution"); - this.logger.warn(this.getClass(), builder.toString()); + logger.warn(this.getClass(), builder.toString()); } this.duration = duration; } - this.input = file.read(); + input = file.read(); try { - this.total = this.input.available(); + total = input.available(); } catch (final IOException ex) { throw new TuningForkRuntimeException(ex); } - this.init(); + init(); this.file = file; @@ -205,39 +204,39 @@ public OggInputStream(FileHandle file, OggInputStream previousStream) { * @param stream the input stream */ public OggInputStream(InputStream stream) { - this.logger = Audio.get().getLogger(); + logger = Audio.get().getLogger(); - this.convbuffer = new byte[this.convsize]; - this.pcmBuffer = BufferUtils.createByteBuffer(4096 * 500); + convbuffer = new byte[convsize]; + pcmBuffer = BufferUtils.createByteBuffer(4096 * 500); - this.input = stream; + input = stream; try { - this.total = this.input.available(); + total = input.available(); } catch (final IOException ex) { throw new TuningForkRuntimeException(ex); } - this.init(); + init(); - this.file = null; + file = null; - this.duration = -1f; + duration = -1f; } @Override public AudioStream reset() { - if (this.file == null) { + if (file == null) { throw new TuningForkRuntimeException("This AudioStream doesn't support resetting."); } - this.close(); - return new OggInputStream(this.file, this); + close(); + return new OggInputStream(file, this); } @Override public float getDuration() { - return this.duration; + return duration; } @@ -247,19 +246,19 @@ public float getDuration() { * @return The number of the bytes on the stream */ public int getLength() { - return this.total; + return total; } @Override public int getChannels() { - return this.oggInfo.channels; + return oggInfo.channels; } @Override public int getSampleRate() { - return this.oggInfo.rate; + return oggInfo.rate; } @@ -273,8 +272,8 @@ public int getBitsPerSample() { * Initialise the streams and thread involved in the streaming of OGG data */ private void init() { - this.initVorbis(); - this.readPCM(); + initVorbis(); + readPCM(); } @@ -282,7 +281,7 @@ private void init() { * Initialise the vorbis decoding */ private void initVorbis() { - this.syncState.init(); + syncState.init(); } @@ -298,28 +297,28 @@ private boolean getPageAndPacket() { // serialno. // submit a 4k block to libvorbis' Ogg layer - int index = this.syncState.buffer(OggInputStream.BUFFER_SIZE); + int index = syncState.buffer(OggInputStream.BUFFER_SIZE); if (index == -1) { return false; } - this.buffer = this.syncState.data; - if (this.buffer == null) { - this.endOfStream = true; + buffer = syncState.data; + if (buffer == null) { + endOfStream = true; return false; } try { - this.bytes = this.input.read(this.buffer, index, OggInputStream.BUFFER_SIZE); + bytes = input.read(buffer, index, OggInputStream.BUFFER_SIZE); } catch (final Exception e) { throw new TuningForkRuntimeException("Failure reading Vorbis.", e); } - this.syncState.wrote(this.bytes); + syncState.wrote(bytes); // Get the first page. - if (this.syncState.pageout(this.page) != 1) { + if (syncState.pageout(page) != 1) { // have we simply run out of data? If so, we're done. - if (this.bytes < OggInputStream.BUFFER_SIZE) { + if (bytes < OggInputStream.BUFFER_SIZE) { return false; } @@ -329,7 +328,7 @@ private boolean getPageAndPacket() { // Get the serial number and set up the rest of decode. // serialno first; use it to set up a logical stream - this.streamState.init(this.page.serialno()); + streamState.init(page.serialno()); // extract the initial header from the first page and verify that the // Ogg bitstream is in fact Vorbis data @@ -339,19 +338,19 @@ private boolean getPageAndPacket() { // header is an easy way to identify a Vorbis bitstream and it's // useful to see that functionality seperated out. - this.oggInfo.init(); - this.comment.init(); - if (this.streamState.pagein(this.page) < 0) { + oggInfo.init(); + comment.init(); + if (streamState.pagein(page) < 0) { // error; stream version mismatch perhaps throw new TuningForkRuntimeException("Error reading first page of Ogg bitstream."); } - if (this.streamState.packetout(this.packet) != 1) { + if (streamState.packetout(packet) != 1) { // no page? must not be vorbis throw new TuningForkRuntimeException("Error reading initial header packet."); } - if (this.oggInfo.synthesis_headerin(this.comment, this.packet) < 0) { + if (oggInfo.synthesis_headerin(comment, packet) < 0) { // error case; not a vorbis header throw new TuningForkRuntimeException("Ogg bitstream does not contain Vorbis audio data."); } @@ -369,7 +368,7 @@ private boolean getPageAndPacket() { int i = 0; while (i < 2) { while (i < 2) { - int result = this.syncState.pageout(this.page); + int result = syncState.pageout(page); if (result == 0) { break; // Need more data // Don't complain about missing or corrupt data yet. We'll @@ -377,11 +376,11 @@ private boolean getPageAndPacket() { } if (result == 1) { - this.streamState.pagein(this.page); // we can ignore any errors here + streamState.pagein(page); // we can ignore any errors here // as they'll also become apparent // at packetout while (i < 2) { - result = this.streamState.packetout(this.packet); + result = streamState.packetout(packet); if (result == 0) { break; } @@ -391,34 +390,34 @@ private boolean getPageAndPacket() { throw new TuningForkRuntimeException("Corrupt secondary header."); } - this.oggInfo.synthesis_headerin(this.comment, this.packet); + oggInfo.synthesis_headerin(comment, packet); i++; } } } // no harm in not checking before adding more - index = this.syncState.buffer(OggInputStream.BUFFER_SIZE); + index = syncState.buffer(OggInputStream.BUFFER_SIZE); if (index == -1) { return false; } - this.buffer = this.syncState.data; + buffer = syncState.data; try { - this.bytes = this.input.read(this.buffer, index, OggInputStream.BUFFER_SIZE); + bytes = input.read(buffer, index, OggInputStream.BUFFER_SIZE); } catch (final Exception e) { throw new TuningForkRuntimeException("Failed to read Vorbis.", e); } - if (this.bytes == 0 && i < 2) { + if (bytes == 0 && i < 2) { throw new TuningForkRuntimeException("End of file before finding all Vorbis headers."); } - this.syncState.wrote(this.bytes); + syncState.wrote(bytes); } - this.convsize = OggInputStream.BUFFER_SIZE / this.oggInfo.channels; + convsize = OggInputStream.BUFFER_SIZE / oggInfo.channels; // OK, got and parsed all three headers. Initialize the Vorbis // packet->PCM decoder. - this.dspState.synthesis_init(this.oggInfo); // central decode state - this.vorbisBlock.init(this.dspState); // local state for most of the decode + dspState.synthesis_init(oggInfo); // central decode state + vorbisBlock.init(dspState); // local state for most of the decode // so multiple block decodes can // proceed in parallel. We could init // multiple vorbis_block structures @@ -435,36 +434,36 @@ private void readPCM() { boolean wrote = false; while (true) { // we repeat if the bitstream is chained - if (this.endOfBitStream) { - if (!this.getPageAndPacket()) { + if (endOfBitStream) { + if (!getPageAndPacket()) { break; } - this.endOfBitStream = false; + endOfBitStream = false; } - if (!this.inited) { - this.inited = true; + if (!inited) { + inited = true; return; } final float[][][] _pcm = new float[1][][]; - final int[] _index = new int[this.oggInfo.channels]; + final int[] _index = new int[oggInfo.channels]; // The rest is just a straight decode loop until end of stream - while (!this.endOfBitStream) { - while (!this.endOfBitStream) { - int result = this.syncState.pageout(this.page); + while (!endOfBitStream) { + while (!endOfBitStream) { + int result = syncState.pageout(page); if (result == 0) { break; // need more data } if (result == -1) { // missing or corrupt data at this page position - this.logger.error(this.getClass(), "Error reading OGG: Corrupt or missing data in bitstream."); + logger.error(this.getClass(), "Error reading OGG: Corrupt or missing data in bitstream."); } else { - this.streamState.pagein(this.page); // can safely ignore errors at + streamState.pagein(page); // can safely ignore errors at // this point while (true) { - result = this.streamState.packetout(this.packet); + result = streamState.packetout(packet); if (result == 0) { break; // need more data @@ -474,8 +473,8 @@ private void readPCM() { } else { // we have a packet. Decode it int samples; - if (this.vorbisBlock.synthesis(this.packet) == 0) { // test for success! - this.dspState.synthesis_blockin(this.vorbisBlock); + if (vorbisBlock.synthesis(packet) == 0) { // test for success! + dspState.synthesis_blockin(vorbisBlock); } // **pcm is a multichannel float vector. In stereo, for @@ -483,14 +482,14 @@ private void readPCM() { // the size of each channel. Convert the float values // (-1.<=range<=1.) to whatever PCM format and write it out - while ((samples = this.dspState.synthesis_pcmout(_pcm, _index)) > 0) { + while ((samples = dspState.synthesis_pcmout(_pcm, _index)) > 0) { final float[][] pcm = _pcm[0]; // boolean clipflag = false; - final int bout = samples < this.convsize ? samples : this.convsize; + final int bout = samples < convsize ? samples : convsize; // convert floats to 16 bit signed ints (host order) and // interleave - for (int i = 0; i < this.oggInfo.channels; i++) { + for (int i = 0; i < oggInfo.channels; i++) { int ptr = i * 2; // int ptr=i; final int mono = _index[i]; @@ -507,101 +506,101 @@ private void readPCM() { val = val | 0x8000; } - if (this.bigEndian) { - this.convbuffer[ptr] = (byte) (val >>> 8); - this.convbuffer[ptr + 1] = (byte) val; + if (bigEndian) { + convbuffer[ptr] = (byte) (val >>> 8); + convbuffer[ptr + 1] = (byte) val; } else { - this.convbuffer[ptr] = (byte) val; - this.convbuffer[ptr + 1] = (byte) (val >>> 8); + convbuffer[ptr] = (byte) val; + convbuffer[ptr + 1] = (byte) (val >>> 8); } - ptr += 2 * this.oggInfo.channels; + ptr += 2 * oggInfo.channels; } } - final int bytesToWrite = 2 * this.oggInfo.channels * bout; - if (bytesToWrite > this.pcmBuffer.remaining()) { + final int bytesToWrite = 2 * oggInfo.channels * bout; + if (bytesToWrite > pcmBuffer.remaining()) { throw new TuningForkRuntimeException( - "Ogg block too big to be buffered: " + bytesToWrite + " :: " + this.pcmBuffer.remaining()); + "Ogg block too big to be buffered: " + bytesToWrite + " :: " + pcmBuffer.remaining()); } - this.pcmBuffer.put(this.convbuffer, 0, bytesToWrite); + pcmBuffer.put(convbuffer, 0, bytesToWrite); wrote = true; - this.dspState.synthesis_read(bout); // tell libvorbis how + dspState.synthesis_read(bout); // tell libvorbis how // many samples we // actually consumed } } } - if (this.page.eos() != 0) { - this.endOfBitStream = true; + if (page.eos() != 0) { + endOfBitStream = true; } - if (!this.endOfBitStream && wrote) { + if (!endOfBitStream && wrote) { return; } } } - if (!this.endOfBitStream) { - this.bytes = 0; - final int index = this.syncState.buffer(OggInputStream.BUFFER_SIZE); + if (!endOfBitStream) { + bytes = 0; + final int index = syncState.buffer(OggInputStream.BUFFER_SIZE); if (index >= 0) { - this.buffer = this.syncState.data; + buffer = syncState.data; try { - this.bytes = this.input.read(this.buffer, index, OggInputStream.BUFFER_SIZE); + bytes = input.read(buffer, index, OggInputStream.BUFFER_SIZE); } catch (final Exception e) { throw new TuningForkRuntimeException("Error during Vorbis decoding.", e); } } else { - this.bytes = 0; + bytes = 0; } - this.syncState.wrote(this.bytes); - if (this.bytes == 0) { - this.endOfBitStream = true; + syncState.wrote(bytes); + if (bytes == 0) { + endOfBitStream = true; } } } // clean up this logical bitstream; before exit we see if we're // followed by another [chained] - this.streamState.clear(); + streamState.clear(); // ogg_page and ogg_packet structs always point to storage in // libvorbis. They're never freed or manipulated directly - this.vorbisBlock.clear(); - this.dspState.clear(); - this.oggInfo.clear(); // must be called last + vorbisBlock.clear(); + dspState.clear(); + oggInfo.clear(); // must be called last } // OK, clean up the framer - this.syncState.clear(); - this.endOfStream = true; + syncState.clear(); + endOfStream = true; } public int read() { - if (this.readIndex >= this.pcmBuffer.position()) { - ((Buffer) this.pcmBuffer).clear(); - this.readPCM(); - this.readIndex = 0; + if (readIndex >= pcmBuffer.position()) { + pcmBuffer.clear(); + readPCM(); + readIndex = 0; } - if (this.readIndex >= this.pcmBuffer.position()) { + if (readIndex >= pcmBuffer.position()) { return -1; } - int value = this.pcmBuffer.get(this.readIndex); + int value = pcmBuffer.get(readIndex); if (value < 0) { value = 256 + value; } - this.readIndex++; + readIndex++; return value; } public boolean atEnd() { - return this.endOfStream && this.readIndex >= this.pcmBuffer.position(); + return endOfStream && readIndex >= pcmBuffer.position(); } @@ -635,14 +634,14 @@ public PcmDataType getPcmDataType() { @Override public void close() { - StreamUtils.closeQuietly(this.input); - this.closed = true; + StreamUtils.closeQuietly(input); + closed = true; } @Override public boolean isClosed() { - return this.closed; + return closed; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/PcmDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/PcmDecoder.java index e11af99..2e37977 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/PcmDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/PcmDecoder.java @@ -27,68 +27,68 @@ public PcmDecoder(int bitsPerSample, int channels, int sampleRate, PcmDataType p @Override public void setup(InputStream stream, long streamLength) { this.stream = stream; - this.bytesRemaining = streamLength; - this.totalOutputSamplesPerChannel = this.bytesRemaining / (this.bitsPerSample / 8L) / this.channels; + bytesRemaining = streamLength; + totalOutputSamplesPerChannel = bytesRemaining / (bitsPerSample / 8L) / channels; } @Override public int read(byte[] output) throws IOException { // we don't check if the decoder has been set up properly because this method is crucial for performance - if (this.bytesRemaining <= 0) { + if (bytesRemaining <= 0) { return -1; } - final int bytesRead = Util.readAll(this.stream, output, (int) Math.min(this.bytesRemaining, output.length)); - this.bytesRemaining -= bytesRead; + final int bytesRead = Util.readAll(stream, output, (int) Math.min(bytesRemaining, output.length)); + bytesRemaining -= bytesRead; return bytesRead; } @Override public int inputBitsPerSample() { - return this.bitsPerSample; + return bitsPerSample; } @Override public int outputBitsPerSample() { - return this.bitsPerSample; + return bitsPerSample; } @Override public int outputChannels() { - return this.channels; + return channels; } @Override public int outputSampleRate() { - return this.sampleRate; + return sampleRate; } @Override public long outputTotalSamplesPerChannel() { - return this.totalOutputSamplesPerChannel; + return totalOutputSamplesPerChannel; } @Override public PcmDataType outputPcmDataType() { - return this.pcmDataType; + return pcmDataType; } @Override public long bytesRemaining() { - return this.bytesRemaining; + return bytesRemaining; } @Override public void close() throws IOException, NullPointerException { - this.stream.close(); + stream.close(); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/QoaDecoder.java b/core/src/main/java/de/pottgames/tuningfork/decoder/QoaDecoder.java index eedc20e..5c5db21 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/QoaDecoder.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/QoaDecoder.java @@ -34,8 +34,8 @@ public class QoaDecoder { private final int sampleRate; private FrameHeader currentFrameHeader = new FrameHeader(); private byte[] rawFrameData = null; - private final LmsState[] lmsStates = { new LmsState(), new LmsState(), new LmsState(), new LmsState(), new LmsState(), new LmsState(), - new LmsState(), new LmsState() }; + private final LmsState[] lmsStates = + { new LmsState(), new LmsState(), new LmsState(), new LmsState(), new LmsState(), new LmsState(), new LmsState(), new LmsState() }; private short[] buffer; private int bufferCursor = 0; private int bufferLength = 0; @@ -43,12 +43,12 @@ public class QoaDecoder { public QoaDecoder(InputStream stream, long samplesPerChannel) throws IOException, TuningForkException { this.stream = stream; - this.totalOutputSamplesPerChannel = samplesPerChannel; + totalOutputSamplesPerChannel = samplesPerChannel; // decode first frame to know channels & sample rate - this.decodeFrame(true); - this.channels = this.currentFrameHeader.channels(); - this.sampleRate = this.currentFrameHeader.sampleRate(); + decodeFrame(true); + channels = currentFrameHeader.channels(); + sampleRate = currentFrameHeader.sampleRate(); } @@ -56,17 +56,17 @@ public int read(byte[] output) throws IOException, TuningForkException { boolean nextSample = false; int writtenBytes = 0; for (int i = 0; i < output.length; i++) { - if (this.bufferCursor >= this.bufferLength) { - this.decodeFrame(false); - if (this.bufferLength <= 0) { + if (bufferCursor >= bufferLength) { + decodeFrame(false); + if (bufferLength <= 0) { return writtenBytes; } } if (nextSample) { - output[i] = (byte) (this.buffer[this.bufferCursor++] >>> 8 & 0xFF); + output[i] = (byte) (buffer[bufferCursor++] >>> 8 & 0xFF); } else { - output[i] = (byte) (this.buffer[this.bufferCursor] & 0xFF); + output[i] = (byte) (buffer[bufferCursor] & 0xFF); } nextSample = !nextSample; writtenBytes++; @@ -77,11 +77,11 @@ public int read(byte[] output) throws IOException, TuningForkException { private void decodeFrame(boolean firstFrame) throws IOException, TuningForkException { - this.bufferCursor = 0; - Util.readAll(this.stream, this.currentFrameHeader.data, 8); - final int channels = this.currentFrameHeader.channels(); - final int samples = this.currentFrameHeader.samplesPerChannel(); - final int frameSize = this.currentFrameHeader.frameSize(); + bufferCursor = 0; + Util.readAll(stream, currentFrameHeader.data, 8); + final int channels = currentFrameHeader.channels(); + final int samples = currentFrameHeader.samplesPerChannel(); + final int frameSize = currentFrameHeader.frameSize(); // Here it would be nice to check whether this frame still has the same sample rate and number of channels, // but we are optimizing for performance, not data validity. @@ -90,31 +90,31 @@ private void decodeFrame(boolean firstFrame) throws IOException, TuningForkExcep final int numSlices = sliceDataSize / 8; final int totalSamples = numSlices * 20; - final int dataSize = this.currentFrameHeader.frameSize() - 8; + final int dataSize = currentFrameHeader.frameSize() - 8; if (firstFrame) { // 16 bytes lms * 8 channels max + 8 bytes per slice * 256 slices max * 8 channels max - this.rawFrameData = new byte[16 * channels + 8 * 256 * channels]; - this.buffer = new short[256 * 20 * channels]; + rawFrameData = new byte[16 * channels + 8 * 256 * channels]; + buffer = new short[256 * 20 * channels]; } - Util.readAll(this.stream, this.rawFrameData, dataSize); + Util.readAll(stream, rawFrameData, dataSize); int cursor = 0; for (int channel = 0; channel < channels; channel++) { - this.lmsStates[channel].history[0] = (short) ((this.rawFrameData[cursor++] & 0xFF) << 8 | this.rawFrameData[cursor++] & 0xFF); - this.lmsStates[channel].history[1] = (short) ((this.rawFrameData[cursor++] & 0xFF) << 8 | this.rawFrameData[cursor++] & 0xFF); - this.lmsStates[channel].history[2] = (short) ((this.rawFrameData[cursor++] & 0xFF) << 8 | this.rawFrameData[cursor++] & 0xFF); - this.lmsStates[channel].history[3] = (short) ((this.rawFrameData[cursor++] & 0xFF) << 8 | this.rawFrameData[cursor++] & 0xFF); - this.lmsStates[channel].weights[0] = (short) ((this.rawFrameData[cursor++] & 0xFF) << 8 | this.rawFrameData[cursor++] & 0xFF); - this.lmsStates[channel].weights[1] = (short) ((this.rawFrameData[cursor++] & 0xFF) << 8 | this.rawFrameData[cursor++] & 0xFF); - this.lmsStates[channel].weights[2] = (short) ((this.rawFrameData[cursor++] & 0xFF) << 8 | this.rawFrameData[cursor++] & 0xFF); - this.lmsStates[channel].weights[3] = (short) ((this.rawFrameData[cursor++] & 0xFF) << 8 | this.rawFrameData[cursor++] & 0xFF); + lmsStates[channel].history[0] = (short) ((rawFrameData[cursor++] & 0xFF) << 8 | rawFrameData[cursor++] & 0xFF); + lmsStates[channel].history[1] = (short) ((rawFrameData[cursor++] & 0xFF) << 8 | rawFrameData[cursor++] & 0xFF); + lmsStates[channel].history[2] = (short) ((rawFrameData[cursor++] & 0xFF) << 8 | rawFrameData[cursor++] & 0xFF); + lmsStates[channel].history[3] = (short) ((rawFrameData[cursor++] & 0xFF) << 8 | rawFrameData[cursor++] & 0xFF); + lmsStates[channel].weights[0] = (short) ((rawFrameData[cursor++] & 0xFF) << 8 | rawFrameData[cursor++] & 0xFF); + lmsStates[channel].weights[1] = (short) ((rawFrameData[cursor++] & 0xFF) << 8 | rawFrameData[cursor++] & 0xFF); + lmsStates[channel].weights[2] = (short) ((rawFrameData[cursor++] & 0xFF) << 8 | rawFrameData[cursor++] & 0xFF); + lmsStates[channel].weights[3] = (short) ((rawFrameData[cursor++] & 0xFF) << 8 | rawFrameData[cursor++] & 0xFF); } for (int sampleIndex = 0; sampleIndex < samples; sampleIndex += 20) { final int sliceStartBase = sampleIndex * channels; for (int channel = 0; channel < channels; channel++) { - long slice = Util.longOfBigEndianBytes(this.rawFrameData, cursor); + long slice = Util.longOfBigEndianBytes(rawFrameData, cursor); cursor += 8; final int scaleFactor = (int) (slice >> 60 & 0xF); @@ -122,7 +122,7 @@ private void decodeFrame(boolean firstFrame) throws IOException, TuningForkExcep final int sliceEnd = Util.limit(sampleIndex + 20, samples) * channels + channel; for (int si = sliceStart; si < sliceEnd; si += channels) { - final int predicted = this.lmsStates[channel].predict(); + final int predicted = lmsStates[channel].predict(); final int quantizedResidual = (int) (slice >> 57 & 0x7); final int residual = QoaDecoder.DEQUANT_LUT[scaleFactor][quantizedResidual]; final int unclamped_sample = predicted + residual; @@ -141,14 +141,14 @@ private void decodeFrame(boolean firstFrame) throws IOException, TuningForkExcep } final short decodedSample = (short) clampedSample; - this.lmsStates[channel].update(decodedSample, residual); - this.buffer[si] = decodedSample; + lmsStates[channel].update(decodedSample, residual); + buffer[si] = decodedSample; slice <<= 3; } } } - this.bufferLength = totalSamples; + bufferLength = totalSamples; } @@ -158,17 +158,17 @@ public int outputBitsPerSample() { public int outputChannels() { - return this.channels; + return channels; } public int outputSampleRate() { - return this.sampleRate; + return sampleRate; } public long outputTotalSamplesPerChannel() { - return this.totalOutputSamplesPerChannel; + return totalOutputSamplesPerChannel; } @@ -178,7 +178,7 @@ public PcmDataType outputPcmDataType() { public void close() throws IOException, NullPointerException { - this.stream.close(); + stream.close(); } @@ -189,25 +189,25 @@ private static class LmsState { private int predict() { int prediction = 0; - prediction += this.weights[0] * this.history[0]; - prediction += this.weights[1] * this.history[1]; - prediction += this.weights[2] * this.history[2]; - prediction += this.weights[3] * this.history[3]; + prediction += weights[0] * history[0]; + prediction += weights[1] * history[1]; + prediction += weights[2] * history[2]; + prediction += weights[3] * history[3]; return prediction >> 13; } private void update(short sample, int residual) { final int delta = residual >> 4; - this.weights[0] += (short) (this.history[0] < 0 ? -delta : delta); - this.weights[1] += (short) (this.history[1] < 0 ? -delta : delta); - this.weights[2] += (short) (this.history[2] < 0 ? -delta : delta); - this.weights[3] += (short) (this.history[3] < 0 ? -delta : delta); - - this.history[0] = this.history[1]; - this.history[1] = this.history[2]; - this.history[2] = this.history[3]; - this.history[3] = sample; + weights[0] += (short) (history[0] < 0 ? -delta : delta); + weights[1] += (short) (history[1] < 0 ? -delta : delta); + weights[2] += (short) (history[2] < 0 ? -delta : delta); + weights[3] += (short) (history[3] < 0 ? -delta : delta); + + history[0] = history[1]; + history[1] = history[2]; + history[2] = history[3]; + history[3] = sample; } } @@ -217,22 +217,22 @@ private static class FrameHeader { private int channels() { - return this.data[0] & 0xFF; + return data[0] & 0xFF; } private int sampleRate() { - return (this.data[1] & 0xFF) << 16 | (this.data[2] & 0xFF) << 8 | this.data[3] & 0xFF; + return (data[1] & 0xFF) << 16 | (data[2] & 0xFF) << 8 | data[3] & 0xFF; } private int samplesPerChannel() { - return (this.data[4] & 0xFF) << 8 | this.data[5] & 0xFF; + return (data[4] & 0xFF) << 8 | data[5] & 0xFF; } private int frameSize() { - return (this.data[6] & 0xFF) << 8 | this.data[7] & 0xFF; + return (data[6] & 0xFF) << 8 | data[7] & 0xFF; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/QoaInputStream.java b/core/src/main/java/de/pottgames/tuningfork/decoder/QoaInputStream.java index 0a1f0a0..c4463cd 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/QoaInputStream.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/QoaInputStream.java @@ -56,11 +56,11 @@ public QoaInputStream(FileHandle file) { * @param forStreaming true if this will be used for streaming */ public QoaInputStream(FileHandle file, boolean forStreaming) { - this.stream = file.read(); + stream = file.read(); this.file = file; - this.logger = Audio.get().getLogger(); - this.setup(forStreaming); - this.duration = (float) this.totalSamplesPerChannel() / this.getSampleRate(); + logger = Audio.get().getLogger(); + setup(forStreaming); + duration = (float) totalSamplesPerChannel() / getSampleRate(); } @@ -84,17 +84,17 @@ public QoaInputStream(InputStream stream) { */ public QoaInputStream(InputStream stream, boolean forStreaming) { this.stream = stream; - this.file = null; - this.logger = Audio.get().getLogger(); - this.setup(forStreaming); - this.duration = (float) this.totalSamplesPerChannel() / this.getSampleRate(); + file = null; + logger = Audio.get().getLogger(); + setup(forStreaming); + duration = (float) totalSamplesPerChannel() / getSampleRate(); } private void setup(boolean forStreaming) { final byte[] header = new byte[8]; try { - if (Util.readAll(this.stream, header, header.length) < 8) { + if (Util.readAll(stream, header, header.length) < 8) { this.throwRuntimeError("Not a valid QOA file, header too short"); } } catch (final IOException e) { @@ -108,7 +108,7 @@ private void setup(boolean forStreaming) { this.throwRuntimeError("Invalid static QOA file, streamed QOA isn't supported by TuningFork"); } try { - this.decoder = new QoaDecoder(this.stream, totalSamples); + decoder = new QoaDecoder(stream, totalSamples); } catch (final IOException | TuningForkException e) { this.throwRuntimeError("Error creating QOA decoder", e); } @@ -118,7 +118,7 @@ private void setup(boolean forStreaming) { @Override public int read(byte[] bytes) { try { - return this.decoder.read(bytes); + return decoder.read(bytes); } catch (final IOException | TuningForkException e) { throw new TuningForkRuntimeException(e); } @@ -127,46 +127,46 @@ public int read(byte[] bytes) { @Override public float getDuration() { - return this.duration; + return duration; } @Override public AudioStream reset() { - if (this.file == null) { + if (file == null) { this.throwRuntimeError("This AudioStream doesn't support resetting."); } StreamUtils.closeQuietly(this); - return new QoaInputStream(this.file); + return new QoaInputStream(file); } public long totalSamplesPerChannel() { - return this.decoder.outputTotalSamplesPerChannel(); + return decoder.outputTotalSamplesPerChannel(); } @Override public int getChannels() { - return this.decoder.outputChannels(); + return decoder.outputChannels(); } @Override public int getSampleRate() { - return this.decoder.outputSampleRate(); + return decoder.outputSampleRate(); } @Override public int getBitsPerSample() { - return this.decoder.outputBitsPerSample(); + return decoder.outputBitsPerSample(); } @Override public PcmDataType getPcmDataType() { - return this.decoder.outputPcmDataType(); + return decoder.outputPcmDataType(); } @@ -177,31 +177,31 @@ private void throwRuntimeError(String message) { private void throwRuntimeError(String message, Exception e) { if (e == null) { - throw new TuningForkRuntimeException(message + ": " + this.file.toString()); + throw new TuningForkRuntimeException(message + ": " + file.toString()); } - throw new TuningForkRuntimeException(message + ". " + e.getMessage() + ": " + this.file.toString(), e); + throw new TuningForkRuntimeException(message + ". " + e.getMessage() + ": " + file.toString(), e); } @Override public boolean isClosed() { - return this.closed; + return closed; } @Override public void close() throws IOException { try { - if (this.decoder != null) { - this.decoder.close(); + if (decoder != null) { + decoder.close(); } else { - this.stream.close(); + stream.close(); } } catch (final IOException e) { // ignore but log it - this.logger.error(this.getClass(), "QoaInputStream didn't close successfully: " + e.getMessage()); + logger.error(this.getClass(), "QoaInputStream didn't close successfully: " + e.getMessage()); } finally { - this.closed = true; + closed = true; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/WavAudioFormat.java b/core/src/main/java/de/pottgames/tuningfork/decoder/WavAudioFormat.java index 99513c1..405aae6 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/WavAudioFormat.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/WavAudioFormat.java @@ -128,12 +128,12 @@ public enum WavAudioFormat { public int getRegNumber() { - return this.regNumber; + return regNumber; } public String getWFormatTagId() { - return this.wFormatTagId; + return wFormatTagId; } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/WavFmtChunk.java b/core/src/main/java/de/pottgames/tuningfork/decoder/WavFmtChunk.java index 99783a8..a146c23 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/WavFmtChunk.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/WavFmtChunk.java @@ -17,23 +17,23 @@ public class WavFmtChunk { public WavFmtChunk(int[] data) { this.data = data; - this.length = data.length; + length = data.length; - this.wFormatTag = data[0] | data[1] << 8; - this.nChannels = data[2] | data[3] << 8; - this.nSamplesPerSec = data[4] | (long) data[5] << 8L | (long) data[6] << 16L | (long) data[7] << 24L; - this.nAvgBytesPerSec = data[8] | (long) data[9] << 8L | (long) data[10] << 16L | (long) data[11] << 24L; - this.nBlockAlign = data[12] | data[13] << 8; - this.wBitsPerSample = data[14] | data[15] << 8; + wFormatTag = data[0] | data[1] << 8; + nChannels = data[2] | data[3] << 8; + nSamplesPerSec = data[4] | (long) data[5] << 8L | (long) data[6] << 16L | (long) data[7] << 24L; + nAvgBytesPerSec = data[8] | (long) data[9] << 8L | (long) data[10] << 16L | (long) data[11] << 24L; + nBlockAlign = data[12] | data[13] << 8; + wBitsPerSample = data[14] | data[15] << 8; if (data.length > 16) { - this.cbSize = data[16] | data[17] << 8; + cbSize = data[16] | data[17] << 8; if (data.length > 18) { - this.wValidBitsPerSample = data[18] | data[19] << 8; + wValidBitsPerSample = data[18] | data[19] << 8; if (data.length > 20) { - this.dwChannelMask = data[20] | data[21] << 8 | data[22] << 16 | data[23] << 24; + dwChannelMask = data[20] | data[21] << 8 | data[22] << 16 | data[23] << 24; if (data.length > 24) { - this.subFormatDataCode = data[24] | data[25] << 8; + subFormatDataCode = data[24] | data[25] << 8; // The remaining 14 bytes contain a fixed string, // \x00\x00\x00\x00\x10\x00\x80\x00\x00\xAA\x00\x38\x9B\x71. Encoders don't seem to @@ -52,7 +52,7 @@ public WavFmtChunk(int[] data) { * @return cbSize or -1 if the field is not present */ public int getCbSize() { - return this.cbSize; + return cbSize; } @@ -62,7 +62,7 @@ public int getCbSize() { * @return wValidBitsPerSample or -1 if the field is not present */ public int getwValidBitsPerSample() { - return this.wValidBitsPerSample; + return wValidBitsPerSample; } @@ -72,7 +72,7 @@ public int getwValidBitsPerSample() { * @return dwChannelMask or -1 if the field is not present */ public int getDwChannelMask() { - return this.dwChannelMask; + return dwChannelMask; } @@ -82,7 +82,7 @@ public int getDwChannelMask() { * @return subFormatDataCode or -1 if the field is not present */ public int getSubFormatDataCode() { - return this.subFormatDataCode; + return subFormatDataCode; } @@ -92,7 +92,7 @@ public int getSubFormatDataCode() { * @return wFormatTag */ public int getwFormatTag() { - return this.wFormatTag; + return wFormatTag; } @@ -102,7 +102,7 @@ public int getwFormatTag() { * @return nChannels */ public int getnChannels() { - return this.nChannels; + return nChannels; } @@ -112,7 +112,7 @@ public int getnChannels() { * @return nSamplesPerSec */ public long getnSamplesPerSec() { - return this.nSamplesPerSec; + return nSamplesPerSec; } @@ -122,7 +122,7 @@ public long getnSamplesPerSec() { * @return nAvgBytesPerSec */ public long getnAvgBytesPerSec() { - return this.nAvgBytesPerSec; + return nAvgBytesPerSec; } @@ -132,7 +132,7 @@ public long getnAvgBytesPerSec() { * @return nBlockAlign */ public int getnBlockAlign() { - return this.nBlockAlign; + return nBlockAlign; } @@ -142,7 +142,7 @@ public int getnBlockAlign() { * @return wBitsPerSample */ public int getwBitsPerSample() { - return this.wBitsPerSample; + return wBitsPerSample; } @@ -154,7 +154,7 @@ public int getwBitsPerSample() { * @return an int containing the byte of the original data */ public int getRaw(int index) { - return this.data[index]; + return data[index]; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/decoder/WavInputStream.java b/core/src/main/java/de/pottgames/tuningfork/decoder/WavInputStream.java index ad7258f..daa63bc 100644 --- a/core/src/main/java/de/pottgames/tuningfork/decoder/WavInputStream.java +++ b/core/src/main/java/de/pottgames/tuningfork/decoder/WavInputStream.java @@ -55,11 +55,11 @@ public WavInputStream(FileHandle file) { * @param forStreaming true if this will be used for streaming */ public WavInputStream(FileHandle file, boolean forStreaming) { - this.stream = file.read(); + stream = file.read(); this.file = file; - this.logger = Audio.get().getLogger(); - this.setup(forStreaming); - this.duration = (float) this.totalSamplesPerChannel() / this.getSampleRate(); + logger = Audio.get().getLogger(); + setup(forStreaming); + duration = (float) totalSamplesPerChannel() / getSampleRate(); } @@ -83,30 +83,30 @@ public WavInputStream(InputStream stream) { */ public WavInputStream(InputStream stream, boolean forStreaming) { this.stream = stream; - this.file = null; - this.logger = Audio.get().getLogger(); - this.setup(forStreaming); - this.duration = (float) this.totalSamplesPerChannel() / this.getSampleRate(); + file = null; + logger = Audio.get().getLogger(); + setup(forStreaming); + duration = (float) totalSamplesPerChannel() / getSampleRate(); } private void setup(boolean forStreaming) { - this.readRiffChunk(); - final WavFmtChunk fmtChunk = this.readFmtChunk(); + readRiffChunk(); + final WavFmtChunk fmtChunk = readFmtChunk(); - final long bytesRemaining = this.skipToChunk('d', 'a', 't', 'a'); + final long bytesRemaining = skipToChunk('d', 'a', 't', 'a'); if (bytesRemaining < 0L) { this.throwRuntimeError("Not a valid wav file, audio data not found"); } // FIND DECODER final WavDecoderProvider provider = Audio.get().getWavDecoderProvider(); - this.decoder = provider.getDecoder(fmtChunk, forStreaming); - if (this.decoder == null) { + decoder = provider.getDecoder(fmtChunk, forStreaming); + if (decoder == null) { this.throwRuntimeError("Unsupported wav file format"); } - this.decoder.setup(this.stream, bytesRemaining); - if (PcmFormat.determineFormat(this.decoder.outputChannels(), this.decoder.outputBitsPerSample(), this.decoder.outputPcmDataType()) == null) { + decoder.setup(stream, bytesRemaining); + if (PcmFormat.determineFormat(decoder.outputChannels(), decoder.outputBitsPerSample(), decoder.outputPcmDataType()) == null) { this.throwRuntimeError("Unsupported format found in wav file"); } } @@ -115,19 +115,19 @@ private void setup(boolean forStreaming) { private void readRiffChunk() { try { // RIFF LITERAL - final boolean riff = this.stream.read() == 'R' && this.stream.read() == 'I' && this.stream.read() == 'F' && this.stream.read() == 'F'; + final boolean riff = stream.read() == 'R' && stream.read() == 'I' && stream.read() == 'F' && stream.read() == 'F'; if (!riff) { this.throwRuntimeError("Not a valid wav file, RIFF header missing"); } // CHUNK SIZE - final long fileSizeMinus8 = this.read4Bytes(); + final long fileSizeMinus8 = read4Bytes(); if (fileSizeMinus8 < 0) { this.throwRuntimeError("Invalid wav file, unexpected end of file"); } // WAVE LITERAL - final boolean wave = this.stream.read() == 'W' && this.stream.read() == 'A' && this.stream.read() == 'V' && this.stream.read() == 'E'; + final boolean wave = stream.read() == 'W' && stream.read() == 'A' && stream.read() == 'V' && stream.read() == 'E'; if (!wave) { this.throwRuntimeError("Not a valid wav file, WAVE literal missing"); } @@ -140,20 +140,20 @@ private void readRiffChunk() { private WavFmtChunk readFmtChunk() { try { // FMT LITERAL - final boolean fmt = this.stream.read() == 'f' && this.stream.read() == 'm' && this.stream.read() == 't' && this.stream.read() == ' '; + final boolean fmt = stream.read() == 'f' && stream.read() == 'm' && stream.read() == 't' && stream.read() == ' '; if (!fmt) { this.throwRuntimeError("Not a valid wav file, FMT header missing"); } // SUB CHUNK SIZE - final int chunkSize = (int) this.read4Bytes(); + final int chunkSize = (int) read4Bytes(); if (chunkSize < 0) { this.throwRuntimeError("Invalid wav file, unexpected end of file"); } final int[] chunkData = new int[chunkSize]; for (int i = 0; i < chunkSize; i++) { - chunkData[i] = this.stream.read(); + chunkData[i] = stream.read(); } return new WavFmtChunk(chunkData); @@ -166,10 +166,10 @@ private WavFmtChunk readFmtChunk() { private long read4Bytes() throws IOException { - final int byte1 = this.stream.read(); - final int byte2 = this.stream.read(); - final int byte3 = this.stream.read(); - final int byte4 = this.stream.read(); + final int byte1 = stream.read(); + final int byte2 = stream.read(); + final int byte3 = stream.read(); + final int byte4 = stream.read(); if (byte1 < 0 || byte2 < 0 || byte3 < 0 || byte4 < 0) { return -1L; } @@ -179,7 +179,7 @@ private long read4Bytes() throws IOException { private void skipBytes(long n) throws IOException { while (n > 0) { - final long skipped = this.stream.skip(n); + final long skipped = stream.skip(n); if (skipped <= 0) { this.throwRuntimeError("An error occured while reading wav file"); } @@ -193,17 +193,17 @@ private long skipToChunk(char byte1, char byte2, char byte3, char byte4) { try { while (true) { // READ CHUNK ID - final int read1 = this.stream.read(); - final int read2 = this.stream.read(); - final int read3 = this.stream.read(); - final int read4 = this.stream.read(); + final int read1 = stream.read(); + final int read2 = stream.read(); + final int read3 = stream.read(); + final int read4 = stream.read(); if (read1 < 0 || read2 < 0 || read3 < 0 || read4 < 0) { return -1L; } // CHECK IF FOUND final boolean foundChunk = read1 == byte1 && read2 == byte2 && read3 == byte3 && read4 == byte4; - chunkSize = this.read4Bytes(); + chunkSize = read4Bytes(); if (chunkSize < 0) { return -1L; } @@ -212,7 +212,7 @@ private long skipToChunk(char byte1, char byte2, char byte3, char byte4) { } // NOT FOUND, SKIP TO NEXT CHUNK - this.skipBytes(chunkSize); + skipBytes(chunkSize); } } catch (final IOException e) { this.throwRuntimeError("An error occured while reading the wav file", e); @@ -224,7 +224,7 @@ private long skipToChunk(char byte1, char byte2, char byte3, char byte4) { @Override public int read(byte[] bytes) { try { - return this.decoder.read(bytes); + return decoder.read(bytes); } catch (final IOException e) { throw new TuningForkRuntimeException(e); } @@ -233,63 +233,63 @@ public int read(byte[] bytes) { @Override public float getDuration() { - return this.duration; + return duration; } @Override public AudioStream reset() { - if (this.file == null) { + if (file == null) { throw new TuningForkRuntimeException("This AudioStream doesn't support resetting."); } StreamUtils.closeQuietly(this); - return new WavInputStream(this.file); + return new WavInputStream(file); } public long totalSamplesPerChannel() { - return this.decoder.outputTotalSamplesPerChannel(); + return decoder.outputTotalSamplesPerChannel(); } @Override public int getChannels() { - return this.decoder.outputChannels(); + return decoder.outputChannels(); } @Override public int getSampleRate() { - return this.decoder.outputSampleRate(); + return decoder.outputSampleRate(); } @Override public int getBitsPerSample() { - return this.decoder.outputBitsPerSample(); + return decoder.outputBitsPerSample(); } @Override public PcmDataType getPcmDataType() { - return this.decoder.outputPcmDataType(); + return decoder.outputPcmDataType(); } @Override public int getBlockAlign() { - return this.decoder.blockAlign(); + return decoder.blockAlign(); } @Override public int getBlockSize() { - return this.decoder.blockSize(); + return decoder.blockSize(); } public long bytesRemaining() { - return this.decoder.bytesRemaining(); + return decoder.bytesRemaining(); } @@ -300,31 +300,31 @@ private void throwRuntimeError(String message) { private void throwRuntimeError(String message, Exception e) { if (e == null) { - throw new TuningForkRuntimeException(message + ": " + this.file.toString()); + throw new TuningForkRuntimeException(message + ": " + file.toString()); } - throw new TuningForkRuntimeException(message + ". " + e.getMessage() + ": " + this.file.toString(), e); + throw new TuningForkRuntimeException(message + ". " + e.getMessage() + ": " + file.toString(), e); } @Override public boolean isClosed() { - return this.closed; + return closed; } @Override public void close() throws IOException { try { - if (this.decoder != null) { - this.decoder.close(); + if (decoder != null) { + decoder.close(); } else { - this.stream.close(); + stream.close(); } } catch (final IOException e) { // ignore but log it - this.logger.error(this.getClass(), "WavInputStream didn't close successfully: " + e.getMessage()); + logger.error(this.getClass(), "WavInputStream didn't close successfully: " + e.getMessage()); } finally { - this.closed = true; + closed = true; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/jukebox/JukeBox.java b/core/src/main/java/de/pottgames/tuningfork/jukebox/JukeBox.java index b914e01..80e73f2 100644 --- a/core/src/main/java/de/pottgames/tuningfork/jukebox/JukeBox.java +++ b/core/src/main/java/de/pottgames/tuningfork/jukebox/JukeBox.java @@ -69,48 +69,48 @@ public JukeBox(PlayListProvider playListProvider) { * Updates the JukeBox. This method should be called every frame. */ public void update() { - if (this.stopped) { - this.handleEvents(); + if (stopped) { + handleEvents(); return; } SongSource source = null; SongSettings settings = null; - if (this.currentSong != null) { - source = this.currentSong.getSource(); - settings = this.currentSong.getSettings(); + if (currentSong != null) { + source = currentSong.getSource(); + settings = currentSong.getSettings(); } if (source != null && source.isPlaying()) { - final float fadeVolume = this.determineFadeVolume(source, settings); - if (this.softStop) { - this.softStopFade(source); + final float fadeVolume = determineFadeVolume(source, settings); + if (softStop) { + softStopFade(source); } else { - source.setVolume(fadeVolume * this.volume); + source.setVolume(fadeVolume * volume); } } else { - this.resetSoftStop(true); - if (this.currentSong != null) { - this.pushEvent(JukeBoxEventType.SONG_END, this.currentSong); + resetSoftStop(true); + if (currentSong != null) { + this.pushEvent(JukeBoxEventType.SONG_END, currentSong); } - this.nextSong(); + nextSong(); } - this.handleEvents(); + handleEvents(); } protected void softStopFade(SongSource source) { - final float secondsSinceSoftStop = (System.currentTimeMillis() - this.softStopStartTime) / 1000f; - final float alpha = secondsSinceSoftStop / this.softStopFadeDuration; + final float secondsSinceSoftStop = (System.currentTimeMillis() - softStopStartTime) / 1000f; + final float alpha = secondsSinceSoftStop / softStopFadeDuration; if (alpha < 1f) { - final float softFadeVolume = (1f - this.softStopFadeCurve.apply(alpha)) * this.softStopFadeStartVolume; - source.setVolume(softFadeVolume * this.volume); + final float softFadeVolume = (1f - softStopFadeCurve.apply(alpha)) * softStopFadeStartVolume; + source.setVolume(softFadeVolume * volume); } else { - this.stop(); - if (this.softStopResume) { - this.currentPlayList = null; - this.play(); + stop(); + if (softStopResume) { + currentPlayList = null; + play(); } } } @@ -118,8 +118,8 @@ protected void softStopFade(SongSource source) { protected float determineFadeVolume(SongSource source, SongSettings settings) { final float playbackPos = source.getPlaybackPosition(); - final float fadeIn = this.fadeIn(source, settings, playbackPos); - final float fadeOut = this.fadeOut(source, settings, playbackPos, source.getDuration()); + final float fadeIn = fadeIn(source, settings, playbackPos); + final float fadeOut = fadeOut(source, settings, playbackPos, source.getDuration()); if (fadeIn >= 0f) { return fadeIn; @@ -177,7 +177,7 @@ public void setVolume(float volume) { * @return the master volume in the range of 0.0 - 1.0 with 0 being silent and 1 being the maximum volume */ public float getVolume() { - return this.volume; + return volume; } @@ -185,10 +185,10 @@ public float getVolume() { * Starts playback. */ public void play() { - this.stopped = false; + stopped = false; this.pushEvent(JukeBoxEventType.JUKEBOX_START); - if (this.currentSong != null) { - this.currentSong.getSource().play(); + if (currentSong != null) { + currentSong.getSource().play(); } } @@ -197,10 +197,10 @@ public void play() { * Pauses playback. Calling {@link #play()} will resume playback. */ public void pause() { - this.stopped = true; + stopped = true; this.pushEvent(JukeBoxEventType.JUKEBOX_PAUSE); - if (this.currentSong != null) { - this.currentSong.getSource().pause(); + if (currentSong != null) { + currentSong.getSource().pause(); } } @@ -209,27 +209,27 @@ public void pause() { * Stops playback and resets the current {@link PlayList} if applicable. */ public void stop() { - if (!this.stopped) { + if (!stopped) { this.pushEvent(JukeBoxEventType.JUKEBOX_END); } - if (this.currentSong != null) { - this.currentSong.getSource().stop(); - this.pushEvent(JukeBoxEventType.SONG_END, this.currentSong); + if (currentSong != null) { + currentSong.getSource().stop(); + this.pushEvent(JukeBoxEventType.SONG_END, currentSong); } - if (this.currentPlayList != null) { - this.currentPlayList.reset(); + if (currentPlayList != null) { + currentPlayList.reset(); } - this.currentSong = null; - this.stopped = true; - this.resetSoftStop(false); + currentSong = null; + stopped = true; + resetSoftStop(false); } protected void resetSoftStop(boolean clearResume) { - this.softStop = false; - this.softStopFadeCurve = null; + softStop = false; + softStopFadeCurve = null; if (clearResume) { - this.softStopResume = false; + softStopResume = false; } } @@ -249,30 +249,30 @@ protected void resetSoftStop(boolean clearResume) { * @return false if a soft stop couldn't be performed and it is stopped right away */ public boolean softStop(Interpolation fadeOutCurve, float fadeOutDuration) { - if (this.stopped || this.currentSong == null || fadeOutCurve == null || fadeOutDuration <= 0f) { - this.stop(); + if (stopped || currentSong == null || fadeOutCurve == null || fadeOutDuration <= 0f) { + stop(); return false; } - final SongSource source = this.currentSong.getSource(); - final SongSettings settings = this.currentSong.getSettings(); + final SongSource source = currentSong.getSource(); + final SongSettings settings = currentSong.getSettings(); final float duration = source.getDuration(); final float position = source.getPlaybackPosition(); if (duration <= 0f) { - this.stop(); + stop(); return false; } - this.softStop = true; - this.softStopResume = false; - this.softStopStartTime = System.currentTimeMillis(); - this.softStopFadeDuration = fadeOutDuration; - this.softStopFadeCurve = fadeOutCurve; + softStop = true; + softStopResume = false; + softStopStartTime = System.currentTimeMillis(); + softStopFadeDuration = fadeOutDuration; + softStopFadeCurve = fadeOutCurve; if (duration - position < fadeOutDuration) { - this.softStopFadeDuration = duration - position; + softStopFadeDuration = duration - position; } - this.softStopFadeStartVolume = this.determineFadeVolume(source, settings); + softStopFadeStartVolume = determineFadeVolume(source, settings); return true; } @@ -292,13 +292,13 @@ public boolean softStop(Interpolation fadeOutCurve, float fadeOutDuration) { * @param fadeOutDuration the fade-out duration in seconds */ public void softStopAndResume(Interpolation fadeOutCurve, float fadeOutDuration) { - final boolean softStopResult = this.softStop(fadeOutCurve, fadeOutDuration); + final boolean softStopResult = softStop(fadeOutCurve, fadeOutDuration); if (!softStopResult) { - this.currentPlayList = null; - this.play(); + currentPlayList = null; + play(); return; } - this.softStopResume = true; + softStopResume = true; } @@ -306,17 +306,17 @@ public void softStopAndResume(Interpolation fadeOutCurve, float fadeOutDuration) * Immediately stops playback, removes all observers and sets the {@link JukeBox} into a stopped state. */ public void clear() { - this.stopped = true; - if (this.currentSong != null) { - this.currentSong.getSource().stop(); + stopped = true; + if (currentSong != null) { + currentSong.getSource().stop(); } - this.currentPlayList = null; - this.currentSong = null; - this.observer.clear(); - for (final JukeBoxEvent event : this.eventHistory) { - this.eventPool.free(event); + currentPlayList = null; + currentSong = null; + observer.clear(); + for (final JukeBoxEvent event : eventHistory) { + eventPool.free(event); } - this.eventHistory.clear(); + eventHistory.clear(); } @@ -326,7 +326,7 @@ public void clear() { * @return the song */ public Song getCurrentSong() { - return this.currentSong; + return currentSong; } @@ -336,52 +336,52 @@ public Song getCurrentSong() { * @return true if playing */ public boolean isPlaying() { - return !this.stopped; + return !stopped; } protected void nextSong() { - this.currentSong = null; - if (this.currentPlayList == null) { - if (this.playListProvider.hasNext()) { - this.currentPlayList = this.playListProvider.next(); + currentSong = null; + if (currentPlayList == null) { + if (playListProvider.hasNext()) { + currentPlayList = playListProvider.next(); } - if (this.currentPlayList != null) { - this.pushEvent(JukeBoxEventType.PLAYLIST_START, this.currentPlayList); + if (currentPlayList != null) { + this.pushEvent(JukeBoxEventType.PLAYLIST_START, currentPlayList); } } // SET TO NEXT PLAYLIST OR LOOP CURRENT PLAYLIST - if (this.currentPlayList != null && this.currentPlayList.isPlayedThrough()) { - if (!this.playListProvider.hasNext() && this.currentPlayList.isLoop()) { - this.currentPlayList.reset(); + if (currentPlayList != null && currentPlayList.isPlayedThrough()) { + if (!playListProvider.hasNext() && currentPlayList.isLoop()) { + currentPlayList.reset(); } else { - final PlayList lastPlayList = this.currentPlayList; - this.currentPlayList = this.playListProvider.hasNext() ? this.playListProvider.next() : null; - if (this.currentPlayList == null) { + final PlayList lastPlayList = currentPlayList; + currentPlayList = playListProvider.hasNext() ? playListProvider.next() : null; + if (currentPlayList == null) { this.pushEvent(JukeBoxEventType.PLAYLIST_END, lastPlayList); this.pushEvent(JukeBoxEventType.JUKEBOX_END); - this.stopped = true; + stopped = true; return; } this.pushEvent(JukeBoxEventType.PLAYLIST_END, lastPlayList); - this.pushEvent(JukeBoxEventType.PLAYLIST_START, this.currentPlayList); + this.pushEvent(JukeBoxEventType.PLAYLIST_START, currentPlayList); } } // REQUEST NEXT SONG - if (this.currentPlayList != null) { - this.currentSong = this.currentPlayList.nextSong(); + if (currentPlayList != null) { + currentSong = currentPlayList.nextSong(); } // PLAY NEXT SONG AND APPLY FADING - if (this.currentSong != null) { - final SongSource source = this.currentSong.getSource(); - this.fadeIn(source, this.currentSong.getSettings(), 0f); - this.currentSong.getSource().play(); - this.pushEvent(JukeBoxEventType.SONG_START, this.currentSong); + if (currentSong != null) { + final SongSource source = currentSong.getSource(); + fadeIn(source, currentSong.getSettings(), 0f); + currentSong.getSource().play(); + this.pushEvent(JukeBoxEventType.SONG_START, currentSong); } else { - this.stopped = true; + stopped = true; this.pushEvent(JukeBoxEventType.JUKEBOX_END); } } @@ -408,9 +408,9 @@ public void removeObserver(JukeBoxObserver observer) { protected void pushEvent(JukeBoxEventType type) { - final JukeBoxEvent event = this.eventPool.obtain(); + final JukeBoxEvent event = eventPool.obtain(); event.setType(type); - this.eventHistory.add(event); + eventHistory.add(event); } @@ -418,56 +418,56 @@ protected void pushEvent(JukeBoxEventType type, Song song) { if (song == null) { throw new RuntimeException("song is null"); } - final JukeBoxEvent event = this.eventPool.obtain(); + final JukeBoxEvent event = eventPool.obtain(); event.setType(type); event.setSong(song); - this.eventHistory.add(event); + eventHistory.add(event); } protected void pushEvent(JukeBoxEventType type, PlayList playList) { - final JukeBoxEvent event = this.eventPool.obtain(); + final JukeBoxEvent event = eventPool.obtain(); event.setType(type); event.setPlayList(playList); - this.eventHistory.add(event); + eventHistory.add(event); } protected void handleEvents() { - for (final JukeBoxEvent event : this.eventHistory) { + for (final JukeBoxEvent event : eventHistory) { switch (event.getType()) { case JUKEBOX_END: - this.notifyJukeBoxEnd(); + notifyJukeBoxEnd(); break; case JUKEBOX_PAUSE: - this.notifyJukeBoxPause(); + notifyJukeBoxPause(); break; case JUKEBOX_START: - this.notifyJukeBoxStart(); + notifyJukeBoxStart(); break; case PLAYLIST_END: - this.notifyPlayListEnd(event.getPlayList()); + notifyPlayListEnd(event.getPlayList()); break; case PLAYLIST_START: - this.notifyPlayListStart(event.getPlayList()); + notifyPlayListStart(event.getPlayList()); break; case SONG_END: - this.notifySongEnd(event.getSong()); + notifySongEnd(event.getSong()); break; case SONG_START: - this.notifySongStart(event.getSong()); + notifySongStart(event.getSong()); break; case NONE: break; } - this.eventPool.free(event); + eventPool.free(event); } - this.eventHistory.clear(); + eventHistory.clear(); } protected void notifySongStart(Song song) { - for (int i = 0; i < this.observer.size; i++) { + for (int i = 0; i < observer.size; i++) { final JukeBoxObserver observer = this.observer.get(i); observer.onSongStart(song); } @@ -475,7 +475,7 @@ protected void notifySongStart(Song song) { protected void notifySongEnd(Song song) { - for (int i = 0; i < this.observer.size; i++) { + for (int i = 0; i < observer.size; i++) { final JukeBoxObserver observer = this.observer.get(i); observer.onSongEnd(song); } @@ -483,7 +483,7 @@ protected void notifySongEnd(Song song) { protected void notifyPlayListStart(PlayList playList) { - for (int i = 0; i < this.observer.size; i++) { + for (int i = 0; i < observer.size; i++) { final JukeBoxObserver observer = this.observer.get(i); observer.onPlayListStart(playList); } @@ -491,7 +491,7 @@ protected void notifyPlayListStart(PlayList playList) { protected void notifyPlayListEnd(PlayList playList) { - for (int i = 0; i < this.observer.size; i++) { + for (int i = 0; i < observer.size; i++) { final JukeBoxObserver observer = this.observer.get(i); observer.onPlayListEnd(playList); } @@ -499,7 +499,7 @@ protected void notifyPlayListEnd(PlayList playList) { protected void notifyJukeBoxEnd() { - for (int i = 0; i < this.observer.size; i++) { + for (int i = 0; i < observer.size; i++) { final JukeBoxObserver observer = this.observer.get(i); observer.onJukeBoxEnd(); } @@ -507,7 +507,7 @@ protected void notifyJukeBoxEnd() { protected void notifyJukeBoxStart() { - for (int i = 0; i < this.observer.size; i++) { + for (int i = 0; i < observer.size; i++) { final JukeBoxObserver observer = this.observer.get(i); observer.onJukeBoxStart(); } @@ -515,7 +515,7 @@ protected void notifyJukeBoxStart() { protected void notifyJukeBoxPause() { - for (int i = 0; i < this.observer.size; i++) { + for (int i = 0; i < observer.size; i++) { final JukeBoxObserver observer = this.observer.get(i); observer.onJukeBoxPause(); } diff --git a/core/src/main/java/de/pottgames/tuningfork/jukebox/JukeBoxEvent.java b/core/src/main/java/de/pottgames/tuningfork/jukebox/JukeBoxEvent.java index b22833c..9520795 100644 --- a/core/src/main/java/de/pottgames/tuningfork/jukebox/JukeBoxEvent.java +++ b/core/src/main/java/de/pottgames/tuningfork/jukebox/JukeBoxEvent.java @@ -15,16 +15,16 @@ public class JukeBoxEvent implements Poolable { @Override public void reset() { - this.setType(JukeBoxEventType.NONE); - this.setSong(null); - this.setPlayList(null); - this.oldVolume = -1f; - this.newVolume = -1f; + setType(JukeBoxEventType.NONE); + setSong(null); + setPlayList(null); + oldVolume = -1f; + newVolume = -1f; } public Song getSong() { - return this.song; + return song; } @@ -34,7 +34,7 @@ public void setSong(Song song) { public PlayList getPlayList() { - return this.playList; + return playList; } @@ -44,7 +44,7 @@ public void setPlayList(PlayList playList) { public JukeBoxEventType getType() { - return this.type; + return type; } @@ -57,7 +57,7 @@ public void setType(JukeBoxEventType type) { public float getOldVolume() { - return this.oldVolume; + return oldVolume; } @@ -67,7 +67,7 @@ public void setOldVolume(float oldVolume) { public float getNewVolume() { - return this.newVolume; + return newVolume; } diff --git a/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/CircularPlayListProvider.java b/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/CircularPlayListProvider.java index dcf2b7c..5ea95f6 100644 --- a/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/CircularPlayListProvider.java +++ b/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/CircularPlayListProvider.java @@ -33,7 +33,7 @@ public class CircularPlayListProvider implements PlayListProvider { * @return the CircularPlayListProvider for chaining */ public CircularPlayListProvider add(PlayList list) { - this.lists.add(list); + lists.add(list); return this; } @@ -59,17 +59,17 @@ public CircularPlayListProvider addAll(Array lists) { * @return the CircularPlayListProvider for chaining */ public CircularPlayListProvider remove(PlayList list) { - this.lists.removeValue(list, false); + lists.removeValue(list, false); return this; } @Override public PlayList next() { - final PlayList result = this.lists.get(this.index); - this.index++; - if (this.index >= this.lists.size) { - this.index = 0; + final PlayList result = lists.get(index); + index++; + if (index >= lists.size) { + index = 0; } return result; } @@ -77,13 +77,13 @@ public PlayList next() { @Override public boolean hasNext() { - return this.lists.size > 0; + return lists.size > 0; } @Override public String toString() { - return "CircularPlayListProvider [lists=" + this.lists + ", index=" + this.index + "]"; + return "CircularPlayListProvider [lists=" + lists + ", index=" + index + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/DefaultPlayListProvider.java b/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/DefaultPlayListProvider.java index 94416c0..9a1d5a8 100644 --- a/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/DefaultPlayListProvider.java +++ b/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/DefaultPlayListProvider.java @@ -32,7 +32,7 @@ public class DefaultPlayListProvider implements PlayListProvider { * @return the DefaultPlayListProvider for chaining */ public DefaultPlayListProvider add(PlayList list) { - this.lists.add(list); + lists.add(list); return this; } @@ -58,26 +58,26 @@ public DefaultPlayListProvider addAll(Array lists) { * @return the DefaultPlayListProvider for chaining */ public DefaultPlayListProvider remove(PlayList list) { - this.lists.removeValue(list, false); + lists.removeValue(list, false); return this; } @Override public PlayList next() { - return this.lists.removeIndex(0); + return lists.removeIndex(0); } @Override public boolean hasNext() { - return this.lists.size > 0; + return lists.size > 0; } @Override public String toString() { - return "DefaultPlayListProvider [lists=" + this.lists + "]"; + return "DefaultPlayListProvider [lists=" + lists + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/PlayList.java b/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/PlayList.java index 0a4b047..9b51f47 100644 --- a/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/PlayList.java +++ b/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/PlayList.java @@ -33,7 +33,7 @@ public class PlayList { public PlayList() { - this.logger = Audio.get().getLogger(); + logger = Audio.get().getLogger(); } @@ -43,7 +43,7 @@ public PlayList() { * @param song the song */ public void addSong(Song song) { - this.songs.add(song); + songs.add(song); } @@ -53,18 +53,18 @@ public void addSong(Song song) { * @return the next {@link Song} in the list */ public Song nextSong() { - if (this.songs.isEmpty()) { - this.logger.warn(this.getClass(), "Requested nextSong on empty PlayList: " + this); + if (songs.isEmpty()) { + logger.warn(this.getClass(), "Requested nextSong on empty PlayList: " + this); return null; } - final Song song = this.songs.get(this.songIndex); - this.songIndex++; - if (this.songIndex >= this.songs.size) { - this.songIndex = 0; - this.playedThrough = true; - if (this.shuffleAfterPlaytrough) { - this.shuffle(); + final Song song = songs.get(songIndex); + songIndex++; + if (songIndex >= songs.size) { + songIndex = 0; + playedThrough = true; + if (shuffleAfterPlaytrough) { + shuffle(); } } return song; @@ -76,8 +76,8 @@ public Song nextSong() { * afterwards. */ public void reset() { - this.songIndex = 0; - this.playedThrough = false; + songIndex = 0; + playedThrough = false; } @@ -87,7 +87,7 @@ public void reset() { * @return true if all songs have been fetched */ public boolean isPlayedThrough() { - return this.playedThrough; + return playedThrough; } @@ -95,7 +95,7 @@ public boolean isPlayedThrough() { * Shuffles the internal list of {@link Song}s. */ public void shuffle() { - this.songs.shuffle(); + songs.shuffle(); } @@ -105,7 +105,7 @@ public void shuffle() { * @param value if set to true, the playlist will be shuffled after a complete play through */ public void setShuffleAfterPlaytrough(boolean value) { - this.shuffleAfterPlaytrough = value; + shuffleAfterPlaytrough = value; } @@ -125,14 +125,14 @@ public void setLooping(boolean loop) { * @return true for repeat */ public boolean isLoop() { - return this.loop; + return loop; } @Override public String toString() { - return "PlayList [songs=" + this.songs + ", songIndex=" + this.songIndex + ", playedThrough=" + this.playedThrough + ", loop=" + this.loop - + ", shuffleAfterPlaytrough=" + this.shuffleAfterPlaytrough + "]"; + return "PlayList [songs=" + songs + ", songIndex=" + songIndex + ", playedThrough=" + playedThrough + ", loop=" + loop + ", shuffleAfterPlaytrough=" + + shuffleAfterPlaytrough + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/ThemePlayListProvider.java b/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/ThemePlayListProvider.java index 7ef3e5b..2b1089e 100644 --- a/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/ThemePlayListProvider.java +++ b/core/src/main/java/de/pottgames/tuningfork/jukebox/playlist/ThemePlayListProvider.java @@ -30,7 +30,7 @@ public class ThemePlayListProvider implements PlayListProvider { public ThemePlayListProvider() { - this.logger = Audio.get().getLogger(); + logger = Audio.get().getLogger(); } @@ -42,8 +42,8 @@ public ThemePlayListProvider() { * @return the ThemePlayListProvider for chaining */ public ThemePlayListProvider setTheme(int theme) { - if (this.lists.get(theme) == null) { - this.logger.warn(this.getClass(), "There is no corresponding playlist for the selected theme: " + theme); + if (lists.get(theme) == null) { + logger.warn(this.getClass(), "There is no corresponding playlist for the selected theme: " + theme); } this.theme = theme; return this; @@ -56,7 +56,7 @@ public ThemePlayListProvider setTheme(int theme) { * @return the theme */ public int getTheme() { - return this.theme; + return theme; } @@ -69,7 +69,7 @@ public int getTheme() { * @return the ThemePlayListProvider for chaining */ public ThemePlayListProvider add(PlayList list, int theme) { - this.lists.put(theme, list); + lists.put(theme, list); return this; } @@ -82,27 +82,27 @@ public ThemePlayListProvider add(PlayList list, int theme) { * @return the ThemePlayListProvider for chaining */ public ThemePlayListProvider remove(int theme) { - this.lists.remove(theme); + lists.remove(theme); return this; } @Override public PlayList next() { - return this.lists.get(this.theme); + return lists.get(theme); } @Override public boolean hasNext() { - final PlayList list = this.lists.get(this.theme); + final PlayList list = lists.get(theme); return list != null; } @Override public String toString() { - return "ThemePlayListProvider [lists=" + this.lists + ", theme=" + this.theme + "]"; + return "ThemePlayListProvider [lists=" + lists + ", theme=" + theme + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/jukebox/song/Song.java b/core/src/main/java/de/pottgames/tuningfork/jukebox/song/Song.java index d4d7c55..f7735f6 100644 --- a/core/src/main/java/de/pottgames/tuningfork/jukebox/song/Song.java +++ b/core/src/main/java/de/pottgames/tuningfork/jukebox/song/Song.java @@ -79,7 +79,7 @@ public Song(SongSource source, SongSettings settings, SongMeta metaData) { * @return the source */ public SongSource getSource() { - return this.source; + return source; } @@ -89,7 +89,7 @@ public SongSource getSource() { * @return the settings */ public SongSettings getSettings() { - return this.settings; + return settings; } @@ -99,13 +99,13 @@ public SongSettings getSettings() { * @return the meta data */ public SongMeta getMeta() { - return this.metaData; + return metaData; } @Override public String toString() { - return "Song [source=" + this.source + ", settings=" + this.settings + ", metaData=" + this.metaData + "]"; + return "Song [source=" + source + ", settings=" + settings + ", metaData=" + metaData + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/jukebox/song/SongMeta.java b/core/src/main/java/de/pottgames/tuningfork/jukebox/song/SongMeta.java index 0bf4ff6..4a47a5c 100644 --- a/core/src/main/java/de/pottgames/tuningfork/jukebox/song/SongMeta.java +++ b/core/src/main/java/de/pottgames/tuningfork/jukebox/song/SongMeta.java @@ -72,7 +72,7 @@ public SongMeta setAlbum(String album) { * @return the artist */ public String getArtist() { - return this.artist; + return artist; } @@ -82,7 +82,7 @@ public String getArtist() { * @return the title */ public String getTitle() { - return this.title; + return title; } @@ -92,7 +92,7 @@ public String getTitle() { * @return the album */ public String getAlbum() { - return this.album; + return album; } @@ -105,10 +105,10 @@ public String getAlbum() { * @return the SongMeta for chaining */ public SongMeta addAttribute(Object key, Object value) { - if (this.attributes == null) { - this.attributes = new ObjectMap<>(); + if (attributes == null) { + attributes = new ObjectMap<>(); } - this.attributes.put(key, value); + attributes.put(key, value); return this; } @@ -121,16 +121,16 @@ public SongMeta addAttribute(Object key, Object value) { * @return value */ public Object getAttribute(Object key) { - if (this.attributes == null) { + if (attributes == null) { return null; } - return this.attributes.get(key); + return attributes.get(key); } @Override public String toString() { - return "SongMeta [artist=" + this.artist + ", title=" + this.title + ", album=" + this.album + ", attributes=" + this.attributes + "]"; + return "SongMeta [artist=" + artist + ", title=" + title + ", album=" + album + ", attributes=" + attributes + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/jukebox/song/SongSettings.java b/core/src/main/java/de/pottgames/tuningfork/jukebox/song/SongSettings.java index e819de0..cd2a014 100644 --- a/core/src/main/java/de/pottgames/tuningfork/jukebox/song/SongSettings.java +++ b/core/src/main/java/de/pottgames/tuningfork/jukebox/song/SongSettings.java @@ -100,12 +100,12 @@ public SongSettings(float volume, float fadeInDuration, Interpolation fadeInCurv */ public float fadeVolume(FadeType type, float alpha) { if (type == FadeType.IN) { - return MathUtils.clamp(this.fadeInCurve.apply(alpha) * this.volume, 0f, 1f); + return MathUtils.clamp(fadeInCurve.apply(alpha) * volume, 0f, 1f); } if (type == FadeType.OUT) { - return MathUtils.clamp(this.fadeOutCurve.apply(alpha) * this.volume, 0f, 1f); + return MathUtils.clamp(fadeOutCurve.apply(alpha) * volume, 0f, 1f); } - return this.volume; + return volume; } @@ -115,7 +115,7 @@ public float fadeVolume(FadeType type, float alpha) { * @return fade-in duration in seconds */ public float getFadeInDuration() { - return this.fadeInDuration; + return fadeInDuration; } @@ -125,7 +125,7 @@ public float getFadeInDuration() { * @return fade-out duration in seconds */ public float getFadeOutDuration() { - return this.fadeOutDuration; + return fadeOutDuration; } @@ -135,7 +135,7 @@ public float getFadeOutDuration() { * @return fade-in curve */ public Interpolation getFadeInCurve() { - return this.fadeInCurve; + return fadeInCurve; } @@ -145,7 +145,7 @@ public Interpolation getFadeInCurve() { * @return fade-out curve */ public Interpolation getFadeOutCurve() { - return this.fadeOutCurve; + return fadeOutCurve; } @@ -155,7 +155,7 @@ public Interpolation getFadeOutCurve() { * @return volume, ranging from 0-1 */ public float getVolume() { - return this.volume; + return volume; } @@ -182,7 +182,7 @@ public float apply(float a) { @Override public int hashCode() { - return Objects.hash(this.fadeInCurve, this.fadeInDuration, this.fadeOutCurve, this.fadeOutDuration, this.volume); + return Objects.hash(fadeInCurve, fadeInDuration, fadeOutCurve, fadeOutDuration, volume); } @@ -198,17 +198,16 @@ public boolean equals(Object obj) { return false; } final SongSettings other = (SongSettings) obj; - return Objects.equals(this.fadeInCurve, other.fadeInCurve) && Float.floatToIntBits(this.fadeInDuration) == Float.floatToIntBits(other.fadeInDuration) - && Objects.equals(this.fadeOutCurve, other.fadeOutCurve) - && Float.floatToIntBits(this.fadeOutDuration) == Float.floatToIntBits(other.fadeOutDuration) - && Float.floatToIntBits(this.volume) == Float.floatToIntBits(other.volume); + return Objects.equals(fadeInCurve, other.fadeInCurve) && Float.floatToIntBits(fadeInDuration) == Float.floatToIntBits(other.fadeInDuration) + && Objects.equals(fadeOutCurve, other.fadeOutCurve) && Float.floatToIntBits(fadeOutDuration) == Float.floatToIntBits(other.fadeOutDuration) + && Float.floatToIntBits(volume) == Float.floatToIntBits(other.volume); } @Override public String toString() { - return "SongSettings [fadeInDuration=" + this.fadeInDuration + ", fadeOutDuration=" + this.fadeOutDuration + ", fadeInCurve=" + this.fadeInCurve - + ", fadeOutCurve=" + this.fadeOutCurve + ", volume=" + this.volume + "]"; + return "SongSettings [fadeInDuration=" + fadeInDuration + ", fadeOutDuration=" + fadeOutDuration + ", fadeInCurve=" + fadeInCurve + ", fadeOutCurve=" + + fadeOutCurve + ", volume=" + volume + "]"; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/logger/ConsoleLogger.java b/core/src/main/java/de/pottgames/tuningfork/logger/ConsoleLogger.java index e6f0b69..bfbc6af 100644 --- a/core/src/main/java/de/pottgames/tuningfork/logger/ConsoleLogger.java +++ b/core/src/main/java/de/pottgames/tuningfork/logger/ConsoleLogger.java @@ -22,7 +22,7 @@ public ConsoleLogger() { public ConsoleLogger(LogLevel logLevel) { - this.setLogLevel(logLevel); + setLogLevel(logLevel); } @@ -39,12 +39,12 @@ public enum LogLevel { public int getValue() { - return this.value; + return value; } boolean allowedToLog(LogLevel logLevel) { - return this.value >= logLevel.value; + return value >= logLevel.value; } } @@ -61,7 +61,7 @@ public void setLogLevel(LogLevel logLevel) { @Override public void error(Class clazz, String message) { - if (this.logLevel.allowedToLog(LogLevel.ERROR)) { + if (logLevel.allowedToLog(LogLevel.ERROR)) { System.out.println(clazz.getName() + ": " + message); } } @@ -69,7 +69,7 @@ public void error(Class clazz, String message) { @Override public void warn(Class clazz, String message) { - if (this.logLevel.allowedToLog(LogLevel.WARN_ERROR)) { + if (logLevel.allowedToLog(LogLevel.WARN_ERROR)) { System.out.println(clazz.getName() + ": " + message); } } @@ -77,7 +77,7 @@ public void warn(Class clazz, String message) { @Override public void info(Class clazz, String message) { - if (this.logLevel.allowedToLog(LogLevel.INFO_WARN_ERROR)) { + if (logLevel.allowedToLog(LogLevel.INFO_WARN_ERROR)) { System.out.println(clazz.getName() + ": " + message); } } @@ -85,7 +85,7 @@ public void info(Class clazz, String message) { @Override public void debug(Class clazz, String message) { - if (this.logLevel.allowedToLog(LogLevel.DEBUG_INFO_WARN_ERROR)) { + if (logLevel.allowedToLog(LogLevel.DEBUG_INFO_WARN_ERROR)) { System.out.println(clazz.getName() + ": " + message); } } @@ -93,7 +93,7 @@ public void debug(Class clazz, String message) { @Override public void trace(Class clazz, String message) { - if (this.logLevel.allowedToLog(LogLevel.TRACE_DEBUG_INFO_WARN_ERROR)) { + if (logLevel.allowedToLog(LogLevel.TRACE_DEBUG_INFO_WARN_ERROR)) { System.out.println(clazz.getName() + ": " + message); } } diff --git a/core/src/main/java/de/pottgames/tuningfork/logger/ErrorLogger.java b/core/src/main/java/de/pottgames/tuningfork/logger/ErrorLogger.java index c8b0a9d..082adf8 100644 --- a/core/src/main/java/de/pottgames/tuningfork/logger/ErrorLogger.java +++ b/core/src/main/java/de/pottgames/tuningfork/logger/ErrorLogger.java @@ -45,7 +45,7 @@ public void dismissError() { public boolean checkLogAlcError(long deviceHandle, String message) { final int alcError = ALC10.alcGetError(deviceHandle); if (alcError != ALC10.ALC_NO_ERROR) { - this.logger.error(this.clazz, message + " - " + ErrorLogger.alcErrorToString(alcError)); + logger.error(clazz, message + " - " + ErrorLogger.alcErrorToString(alcError)); return true; } @@ -56,7 +56,7 @@ public boolean checkLogAlcError(long deviceHandle, String message) { public boolean checkLogError(String message) { final int alError = AL10.alGetError(); if (alError != AL10.AL_NO_ERROR) { - this.logger.error(this.clazz, message + " - " + ErrorLogger.alErrorToString(alError)); + logger.error(clazz, message + " - " + ErrorLogger.alErrorToString(alError)); return true; } diff --git a/core/src/main/java/de/pottgames/tuningfork/router/KeepAliveDeviceRerouter.java b/core/src/main/java/de/pottgames/tuningfork/router/KeepAliveDeviceRerouter.java index 913c615..9831fdb 100644 --- a/core/src/main/java/de/pottgames/tuningfork/router/KeepAliveDeviceRerouter.java +++ b/core/src/main/java/de/pottgames/tuningfork/router/KeepAliveDeviceRerouter.java @@ -34,7 +34,7 @@ public class KeepAliveDeviceRerouter implements AudioDeviceRerouter { public void setup(long device, String desiredDeviceSpecifier, ContextAttributes attributes) { this.device = device; this.attributes = attributes; - this.setup = true; + setup = true; } @@ -52,17 +52,17 @@ public void updateContextAttributes(ContextAttributes attributes) { @Override public void start() { - this.started = true; + started = true; } @Override public void onDisconnect() { - if (!this.setup || !this.started) { + if (!setup || !started) { return; } - if (!SOFTReopenDevice.alcReopenDeviceSOFT(this.device, (String) null, this.attributes.getBuffer())) { + if (!SOFTReopenDevice.alcReopenDeviceSOFT(device, (String) null, attributes.getBuffer())) { final TuningForkLogger logger = Audio.get().getLogger(); if (logger != null) { logger.error(this.getClass(), "Failed to reopen audio device"); @@ -73,7 +73,7 @@ public void onDisconnect() { @Override public void dispose() { - this.started = false; + started = false; } } diff --git a/core/src/main/java/de/pottgames/tuningfork/router/SmartDeviceRerouter.java b/core/src/main/java/de/pottgames/tuningfork/router/SmartDeviceRerouter.java index 26d1769..7778240 100644 --- a/core/src/main/java/de/pottgames/tuningfork/router/SmartDeviceRerouter.java +++ b/core/src/main/java/de/pottgames/tuningfork/router/SmartDeviceRerouter.java @@ -74,16 +74,16 @@ public SmartDeviceRerouter(long checkInterval) { public void setup(long device, String desiredDeviceSpecifier, ContextAttributes attributes) { this.device = device; this.attributes = attributes; - this.currentDeviceSpecifier = this.fetchCurrentDeviceSpecifier(); - this.updateDesiredDevice(desiredDeviceSpecifier); - this.setup = true; + currentDeviceSpecifier = fetchCurrentDeviceSpecifier(); + updateDesiredDevice(desiredDeviceSpecifier); + setup = true; } @Override public void updateDesiredDevice(String desiredDeviceSpecifier) { this.desiredDeviceSpecifier = desiredDeviceSpecifier; - this.currentDeviceSpecifier = this.fetchCurrentDeviceSpecifier(); + currentDeviceSpecifier = fetchCurrentDeviceSpecifier(); } @@ -98,11 +98,11 @@ public void updateContextAttributes(ContextAttributes attributes) { */ @Override public void start() { - if (!this.setup) { + if (!setup) { throw new TuningForkRuntimeException("SmartDeviceRerouter wasn't set up properly"); } - this.active = true; + active = true; final Thread thread = new Thread(SmartDeviceRerouter.this::loop); thread.setName("TuningFork-SmartDeviceRerouter-Thread"); thread.setDaemon(true); @@ -112,52 +112,52 @@ public void start() { @Override public void onDisconnect() { - if (!this.active) { + if (!active) { return; } - this.currentDeviceSpecifier = "none"; - this.tryReopen(); + currentDeviceSpecifier = "none"; + tryReopen(); } private void loop() { - while (this.active) { - this.tryReopen(); + while (active) { + tryReopen(); try { - Thread.sleep(this.checkInterval); + Thread.sleep(checkInterval); } catch (final InterruptedException e) { - this.dispose(); + dispose(); } } } private synchronized void tryReopen() { - if (this.desiredDeviceSpecifier == null) { - this.tryReopenOnDefaultDevice(); + if (desiredDeviceSpecifier == null) { + tryReopenOnDefaultDevice(); } else { - this.tryReopenOnDesiredDevice(); + tryReopenOnDesiredDevice(); } } private void tryReopenOnDesiredDevice() { - if (!this.currentDeviceSpecifier.equals(this.desiredDeviceSpecifier)) { + if (!currentDeviceSpecifier.equals(desiredDeviceSpecifier)) { final List availableDevices = AudioDevice.availableDevices(); - if (availableDevices != null && availableDevices.contains(this.desiredDeviceSpecifier)) { - this.reopen(this.desiredDeviceSpecifier); + if (availableDevices != null && availableDevices.contains(desiredDeviceSpecifier)) { + reopen(desiredDeviceSpecifier); } else { - this.tryReopenOnDefaultDevice(); + tryReopenOnDefaultDevice(); } } } private void tryReopenOnDefaultDevice() { - final String defaultDeviceSpecifier = this.fetchDefaultDeviceSpecifier(); - if (!this.currentDeviceSpecifier.equals(defaultDeviceSpecifier)) { - this.reopen(defaultDeviceSpecifier); + final String defaultDeviceSpecifier = fetchDefaultDeviceSpecifier(); + if (!currentDeviceSpecifier.equals(defaultDeviceSpecifier)) { + reopen(defaultDeviceSpecifier); } } @@ -168,20 +168,20 @@ private String fetchDefaultDeviceSpecifier() { private String fetchCurrentDeviceSpecifier() { - return ALC10.alcGetString(this.device, EnumerateAllExt.ALC_ALL_DEVICES_SPECIFIER); + return ALC10.alcGetString(device, EnumerateAllExt.ALC_ALL_DEVICES_SPECIFIER); } private void reopen(String deviceSpecifier) { - if (SOFTReopenDevice.alcReopenDeviceSOFT(this.device, deviceSpecifier, this.attributes.getBuffer())) { - this.currentDeviceSpecifier = this.fetchCurrentDeviceSpecifier(); + if (SOFTReopenDevice.alcReopenDeviceSOFT(device, deviceSpecifier, attributes.getBuffer())) { + currentDeviceSpecifier = fetchCurrentDeviceSpecifier(); } } @Override public void dispose() { - this.active = false; + active = false; } } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/AifcALawTest.java b/core/src/test/java/de/pottgames/tuningfork/test/AifcALawTest.java index 41cb3aa..376fd9e 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/AifcALawTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/AifcALawTest.java @@ -34,37 +34,37 @@ public class AifcALawTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = AiffLoader.load(Gdx.files.internal(AifcALawTest.FILE_PATH)); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(AifcALawTest.FILE_PATH)); - this.bufferedSource = this.audio.obtainSource(this.sound); - System.out.println("Sound duration (streamed): " + this.streamedSource.getDuration() + "s"); - System.out.println("Sound duration (buffered): " + this.sound.getDuration() + "s"); + audio = Audio.init(); + sound = AiffLoader.load(Gdx.files.internal(AifcALawTest.FILE_PATH)); + streamedSource = new StreamedSoundSource(Gdx.files.internal(AifcALawTest.FILE_PATH)); + bufferedSource = audio.obtainSource(sound); + System.out.println("Sound duration (streamed): " + streamedSource.getDuration() + "s"); + System.out.println("Sound duration (buffered): " + sound.getDuration() + "s"); - this.activeSource = this.bufferedSource; + activeSource = bufferedSource; } @Override public void render() { - if (!this.activeSource.isPlaying()) { - if (this.activeSource == this.bufferedSource) { - this.activeSource = this.streamedSource; + if (!activeSource.isPlaying()) { + if (activeSource == bufferedSource) { + activeSource = streamedSource; System.out.println("streamed sound playing"); } else { - this.activeSource = this.bufferedSource; + activeSource = bufferedSource; System.out.println("buffered sound playing"); } - this.activeSource.play(); + activeSource.play(); } } @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/AifcULawTest.java b/core/src/test/java/de/pottgames/tuningfork/test/AifcULawTest.java index 9eb7535..eb1c3cf 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/AifcULawTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/AifcULawTest.java @@ -34,37 +34,37 @@ public class AifcULawTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = AiffLoader.load(Gdx.files.internal(AifcULawTest.FILE_PATH)); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(AifcULawTest.FILE_PATH)); - this.bufferedSource = this.audio.obtainSource(this.sound); - System.out.println("Sound duration (streamed): " + this.streamedSource.getDuration() + "s"); - System.out.println("Sound duration (buffered): " + this.sound.getDuration() + "s"); + audio = Audio.init(); + sound = AiffLoader.load(Gdx.files.internal(AifcULawTest.FILE_PATH)); + streamedSource = new StreamedSoundSource(Gdx.files.internal(AifcULawTest.FILE_PATH)); + bufferedSource = audio.obtainSource(sound); + System.out.println("Sound duration (streamed): " + streamedSource.getDuration() + "s"); + System.out.println("Sound duration (buffered): " + sound.getDuration() + "s"); - this.activeSource = this.bufferedSource; + activeSource = bufferedSource; } @Override public void render() { - if (!this.activeSource.isPlaying()) { - if (this.activeSource == this.bufferedSource) { - this.activeSource = this.streamedSource; + if (!activeSource.isPlaying()) { + if (activeSource == bufferedSource) { + activeSource = streamedSource; System.out.println("streamed sound playing"); } else { - this.activeSource = this.bufferedSource; + activeSource = bufferedSource; System.out.println("buffered sound playing"); } - this.activeSource.play(); + activeSource.play(); } } @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/AsyncLoadTest.java b/core/src/test/java/de/pottgames/tuningfork/test/AsyncLoadTest.java index bb8212f..c419de1 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/AsyncLoadTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/AsyncLoadTest.java @@ -38,35 +38,35 @@ public class AsyncLoadTest extends ApplicationAdapter { @Override public void create() { - this.assetManager = new AssetManager(); + assetManager = new AssetManager(); final AudioConfig config = new AudioConfig(); - config.setAssetManager(this.assetManager); + config.setAssetManager(assetManager); config.setLogger(new ConsoleLogger(LogLevel.TRACE_DEBUG_INFO_WARN_ERROR)); - this.audio = Audio.init(config); + audio = Audio.init(config); // If you cannot provide an AssetManager in the AudioConfig, use this: // this.audio.registerAssetManagerLoaders(this.assetManager); - this.assetManager.load(AsyncLoadTest.FILE_1, SoundBuffer.class); + assetManager.load(AsyncLoadTest.FILE_1, SoundBuffer.class); final ReadableSoundBufferLoaderParameter parameter = new ReadableSoundBufferLoaderParameter(); parameter.reverse = true; - this.assetManager.load(AsyncLoadTest.FILE_2, ReadableSoundBuffer.class, parameter); + assetManager.load(AsyncLoadTest.FILE_2, ReadableSoundBuffer.class, parameter); } @Override public void render() { - if (this.assetManager.update(15)) { - if (!this.playedSoundBuffer) { - final SoundBuffer soundBuffer = this.assetManager.get(AsyncLoadTest.FILE_1, SoundBuffer.class); - this.source = this.audio.obtainSource(soundBuffer); - this.source.play(); - this.playedSoundBuffer = true; - } else if (this.source != null && !this.source.isPlaying() && !this.playedReadableSoundBuffer) { - final ReadableSoundBuffer buffer = this.assetManager.get(AsyncLoadTest.FILE_2, ReadableSoundBuffer.class); + if (assetManager.update(15)) { + if (!playedSoundBuffer) { + final SoundBuffer soundBuffer = assetManager.get(AsyncLoadTest.FILE_1, SoundBuffer.class); + source = audio.obtainSource(soundBuffer); + source.play(); + playedSoundBuffer = true; + } else if (source != null && !source.isPlaying() && !playedReadableSoundBuffer) { + final ReadableSoundBuffer buffer = assetManager.get(AsyncLoadTest.FILE_2, ReadableSoundBuffer.class); buffer.play(); - this.playedReadableSoundBuffer = true; + playedReadableSoundBuffer = true; } } @@ -75,8 +75,8 @@ public void render() { @Override public void dispose() { - this.assetManager.dispose(); - this.audio.dispose(); + assetManager.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/AuxSendsTest.java b/core/src/test/java/de/pottgames/tuningfork/test/AuxSendsTest.java index 4fe6325..746d805 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/AuxSendsTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/AuxSendsTest.java @@ -47,12 +47,12 @@ public void create() { deviceConfig.setEffectSlots(3); // INIT - this.audio = Audio.init(config); - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); - System.out.println("available effect slots: " + this.audio.getDevice().getNumberOfEffectSlots()); + audio = Audio.init(config); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + System.out.println("available effect slots: " + audio.getDevice().getNumberOfEffectSlots()); // PLAY - final SoundSource source = this.audio.obtainSource(this.sound); + final SoundSource source = audio.obtainSource(sound); source.setLooping(true); source.setFilter(0f, 0f); source.attachEffect(new SoundEffect(new PitchShifter())); // this effect should be kicked out because we configured only 3 effect slots @@ -71,8 +71,8 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/ClockTest.java b/core/src/test/java/de/pottgames/tuningfork/test/ClockTest.java index 346ab17..527e5df 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/ClockTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/ClockTest.java @@ -28,24 +28,24 @@ public class ClockTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); - this.sound.play(); + audio = Audio.init(); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + sound.play(); } @Override public void render() { - System.out.println("clock time: " + this.audio.getDevice().getClockTime()); - System.out.println("latency: " + this.audio.getDevice().getLatency()); + System.out.println("clock time: " + audio.getDevice().getClockTime()); + System.out.println("latency: " + audio.getDevice().getLatency()); System.out.println(); } @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/DirectChannelRemixTest.java b/core/src/test/java/de/pottgames/tuningfork/test/DirectChannelRemixTest.java index bb2b960..0e1eda5 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/DirectChannelRemixTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/DirectChannelRemixTest.java @@ -26,9 +26,9 @@ public class DirectChannelRemixTest extends ApplicationAdapter { public void create() { final AudioConfig config = new AudioConfig(); config.setVirtualization(Virtualization.ON); - this.audio = Audio.init(config); - this.sound = SoundLoader.load(Gdx.files.internal("quadrophonic.ogg")); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal("quadrophonic.ogg")); + audio = Audio.init(config); + sound = SoundLoader.load(Gdx.files.internal("quadrophonic.ogg")); + streamedSource = new StreamedSoundSource(Gdx.files.internal("quadrophonic.ogg")); System.out.println("Press space to switch through the different virtualization settings."); } @@ -36,20 +36,20 @@ public void create() { @Override public void render() { if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { - this.virtualizationIndex++; - if (this.virtualizationIndex >= DirectChannelRemixTest.virtualizations.length) { - this.virtualizationIndex = 0; - this.streamed = !this.streamed; + virtualizationIndex++; + if (virtualizationIndex >= DirectChannelRemixTest.virtualizations.length) { + virtualizationIndex = 0; + streamed = !streamed; } - final Virtualization virtualization = DirectChannelRemixTest.virtualizations[this.virtualizationIndex]; + final Virtualization virtualization = DirectChannelRemixTest.virtualizations[virtualizationIndex]; System.out.println("virtualization: " + virtualization); - this.audio.setDefaultVirtualization(virtualization); - if (this.streamed) { + audio.setDefaultVirtualization(virtualization); + if (streamed) { System.out.println("playing via StreamedSoundSource"); - this.streamedSource.play(); + streamedSource.play(); } else { System.out.println("playing via SoundBuffer"); - this.sound.play(); + sound.play(); } } } @@ -57,8 +57,8 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/EffectTest.java b/core/src/test/java/de/pottgames/tuningfork/test/EffectTest.java index 08ef7be..b638253 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/EffectTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/EffectTest.java @@ -36,28 +36,28 @@ public class EffectTest extends ApplicationAdapter { @Override public void create() { // before we can do anything, we need to initialize our Audio instance - this.audio = Audio.init(); + audio = Audio.init(); // load a sound - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); // obtain sound source - this.soundSource = this.audio.obtainSource(this.sound); - this.soundSource.setLooping(true); - this.soundSource.play(); + soundSource = audio.obtainSource(sound); + soundSource.setLooping(true); + soundSource.play(); // create effects - this.effect1 = new SoundEffect(EaxReverb.domeSaintPauls()); + effect1 = new SoundEffect(EaxReverb.domeSaintPauls()); final Flanger flanger = new Flanger(); flanger.rate = 7f; - this.effect2 = new SoundEffect(flanger); + effect2 = new SoundEffect(flanger); // attach the effects to the source - this.soundSource.attachEffect(this.effect1); - this.soundSource.attachEffect(this.effect2); + soundSource.attachEffect(effect1); + soundSource.attachEffect(effect2); // [optional] mute the original output if you want - this.soundSource.setFilter(0f, 0f); + soundSource.setFilter(0f, 0f); } @@ -69,13 +69,13 @@ public void render() { @Override public void dispose() { - this.effect1.dispose(); - this.effect2.dispose(); - this.soundSource.free(); - this.sound.dispose(); + effect1.dispose(); + effect2.dispose(); + soundSource.free(); + sound.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/EightBitTest.java b/core/src/test/java/de/pottgames/tuningfork/test/EightBitTest.java index b8ec86f..5e54566 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/EightBitTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/EightBitTest.java @@ -29,14 +29,14 @@ public class EightBitTest extends ApplicationAdapter { @Override public void create() { // before we can do anything, we need to initialize our Audio instance - this.audio = Audio.init(); + audio = Audio.init(); // load a sound - this.sound = SoundLoader.load(Gdx.files.internal("numbers_8bit_stereo.wav")); - System.out.println("Sound duration: " + this.sound.getDuration() + "s"); + sound = SoundLoader.load(Gdx.files.internal("numbers_8bit_stereo.wav")); + System.out.println("Sound duration: " + sound.getDuration() + "s"); // play the sound - this.sound.play(); + sound.play(); } @@ -48,10 +48,10 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); + sound.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/FilterTest.java b/core/src/test/java/de/pottgames/tuningfork/test/FilterTest.java index da22d5a..15de79c 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/FilterTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/FilterTest.java @@ -38,41 +38,41 @@ public void create() { // before we can do anything, we need to initialize our Audio instance final AudioConfig config = new AudioConfig(); config.setLogger(new ConsoleLogger(LogLevel.DEBUG_INFO_WARN_ERROR)); - this.audio = Audio.init(config); + audio = Audio.init(config); // load a sound - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); // obtain sound source - this.soundSource = this.audio.obtainSource(this.sound); + soundSource = audio.obtainSource(sound); // create filters // no effect - this.filters[0][0] = 1f; - this.filters[0][1] = 1f; + filters[0][0] = 1f; + filters[0][1] = 1f; // only high frequencies - this.filters[1][0] = 0.01f; - this.filters[1][1] = 1f; + filters[1][0] = 0.01f; + filters[1][1] = 1f; // only low frequencies - this.filters[2][0] = 1f; - this.filters[2][1] = 0.01f; + filters[2][0] = 1f; + filters[2][1] = 0.01f; } @Override public void render() { - if (!this.soundSource.isPlaying()) { - System.out.println("filter: " + this.filterIndex); - System.out.println("using low freq: " + this.filters[this.filterIndex][0]); - System.out.println("using low freq: " + this.filters[this.filterIndex][1]); + if (!soundSource.isPlaying()) { + System.out.println("filter: " + filterIndex); + System.out.println("using low freq: " + filters[filterIndex][0]); + System.out.println("using low freq: " + filters[filterIndex][1]); System.out.println(); - this.soundSource.setFilter(this.filters[this.filterIndex][0], this.filters[this.filterIndex][1]); - this.soundSource.play(); - this.filterIndex++; - if (this.filterIndex >= this.filters.length) { - this.filterIndex = 0; + soundSource.setFilter(filters[filterIndex][0], filters[filterIndex][1]); + soundSource.play(); + filterIndex++; + if (filterIndex >= filters.length) { + filterIndex = 0; } } } @@ -80,11 +80,11 @@ public void render() { @Override public void dispose() { - this.soundSource.free(); - this.sound.dispose(); + soundSource.free(); + sound.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/FlacTest.java b/core/src/test/java/de/pottgames/tuningfork/test/FlacTest.java index e4735f6..6645aef 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/FlacTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/FlacTest.java @@ -35,23 +35,23 @@ public class FlacTest extends ApplicationAdapter { @Override public void create() { // before we can do anything, we need to initialize our Audio instance - this.audio = Audio.init(); + audio = Audio.init(); // load and play SoundBuffer - this.sound = FlacLoader.load(Gdx.files.internal("numbers_8bit_mono.flac")); - System.out.println("Sound duration: " + this.sound.getDuration() + "s"); - this.sound.play(); + sound = FlacLoader.load(Gdx.files.internal("numbers_8bit_mono.flac")); + System.out.println("Sound duration: " + sound.getDuration() + "s"); + sound.play(); // load and play StreamedSoundSource delayed - this.streamedSound = new StreamedSoundSource(Gdx.files.internal("numbers_16bit_stereo.flac")); - System.out.println("Streamed sound duration: " + this.streamedSound.getDuration() + "s"); - this.streamedSound.setLooping(true); + streamedSound = new StreamedSoundSource(Gdx.files.internal("numbers_16bit_stereo.flac")); + System.out.println("Streamed sound duration: " + streamedSound.getDuration() + "s"); + streamedSound.setLooping(true); try { Thread.sleep(100); } catch (final InterruptedException e) { e.printStackTrace(); } - this.streamedSound.play(); + streamedSound.play(); } @@ -63,11 +63,11 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.streamedSound.dispose(); + sound.dispose(); + streamedSound.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/HrtfTest.java b/core/src/test/java/de/pottgames/tuningfork/test/HrtfTest.java index d78cc1f..484fad3 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/HrtfTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/HrtfTest.java @@ -76,27 +76,27 @@ public void create() { logger.setLogLevel(LogLevel.TRACE_DEBUG_INFO_WARN_ERROR); final AudioDeviceConfig audioDeviceConfig = new AudioDeviceConfig(); audioDeviceConfig.setDeviceSpecifier(deviceList.get(number)); - this.audio = Audio.init(new AudioConfig(audioDeviceConfig, DistanceAttenuationModel.NONE, 1, 0, logger)); + audio = Audio.init(new AudioConfig(audioDeviceConfig, DistanceAttenuationModel.NONE, 1, 0, logger)); Gdx.input.setInputProcessor(this); // ENABLE HRTF - final Array hrtfs = this.audio.getDevice().getAvailableHrtfs(); + final Array hrtfs = audio.getDevice().getAvailableHrtfs(); hrtfs.forEach(name -> System.out.println("available hrtf: " + name)); if (!hrtfs.isEmpty()) { - this.hrtfName = hrtfs.get(0); - this.audio.getDevice().enableHrtf(hrtfs.get(0)); + hrtfName = hrtfs.get(0); + audio.getDevice().enableHrtf(hrtfs.get(0)); } else { logger.error(this.getClass(), "no hrtf available"); } // LOAD SOUND - this.soundBuffer = SoundLoader.load(Gdx.files.internal("numbers.wav")); + soundBuffer = SoundLoader.load(Gdx.files.internal("numbers.wav")); // OBTAIN SOURCE & PLAY SOUND - this.soundSource = this.audio.obtainSource(this.soundBuffer); - this.soundSource.setLooping(true); - this.soundSource.setRelative(true); - this.soundSource.play(); + soundSource = audio.obtainSource(soundBuffer); + soundSource.setLooping(true); + soundSource.setRelative(true); + soundSource.play(); System.out.println("Focus the application window and press space to toggle HRTF"); } @@ -104,20 +104,20 @@ public void create() { @Override public void render() { - this.angle += Math.PI / 4f / 100f; - this.soundSource.setPosition(MathUtils.sin(this.angle), 0f, -MathUtils.cos(this.angle)); + angle += Math.PI / 4f / 100f; + soundSource.setPosition(MathUtils.sin(angle), 0f, -MathUtils.cos(angle)); } @Override public boolean keyDown(int button) { if (button == Input.Keys.SPACE) { - final AudioDevice device = this.audio.getDevice(); + final AudioDevice device = audio.getDevice(); if (device.isHrtfEnabled()) { device.disableHrtf(); System.out.println("hrtf disabled"); - } else if (this.hrtfName != null) { - device.enableHrtf(this.hrtfName); + } else if (hrtfName != null) { + device.enableHrtf(hrtfName); System.out.println("hrtf enabled"); } } @@ -127,9 +127,9 @@ public boolean keyDown(int button) { @Override public void dispose() { - this.soundSource.free(); - this.soundBuffer.dispose(); - this.audio.dispose(); + soundSource.free(); + soundBuffer.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/ImaAdpcmWavMonoTest.java b/core/src/test/java/de/pottgames/tuningfork/test/ImaAdpcmWavMonoTest.java index 39e7e8b..262e8b2 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/ImaAdpcmWavMonoTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/ImaAdpcmWavMonoTest.java @@ -32,21 +32,21 @@ public class ImaAdpcmWavMonoTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(ImaAdpcmWavMonoTest.SOUND_PATH)); - final SoundSource bufferedSource = this.audio.obtainSource(this.sound); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(ImaAdpcmWavMonoTest.SOUND_PATH)); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(ImaAdpcmWavMonoTest.SOUND_PATH)); + final SoundSource bufferedSource = audio.obtainSource(sound); + streamedSource = new StreamedSoundSource(Gdx.files.internal(ImaAdpcmWavMonoTest.SOUND_PATH)); bufferedSource.setLooping(true); - this.streamedSource.setLooping(true); + streamedSource.setLooping(true); bufferedSource.play(); try { Thread.sleep(50); } catch (final InterruptedException e) { // ignore } - this.streamedSource.play(); - System.out.println("buffered duration: " + this.sound.getDuration() + "s"); - System.out.println("streamed duration: " + this.streamedSource.getDuration() + "s"); + streamedSource.play(); + System.out.println("buffered duration: " + sound.getDuration() + "s"); + System.out.println("streamed duration: " + streamedSource.getDuration() + "s"); } @@ -58,11 +58,11 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.streamedSource.dispose(); + sound.dispose(); + streamedSource.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/ImaAdpcmWavStereoTest.java b/core/src/test/java/de/pottgames/tuningfork/test/ImaAdpcmWavStereoTest.java index af43493..fff71a9 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/ImaAdpcmWavStereoTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/ImaAdpcmWavStereoTest.java @@ -32,21 +32,21 @@ public class ImaAdpcmWavStereoTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(ImaAdpcmWavStereoTest.SOUND_PATH)); - final SoundSource bufferedSource = this.audio.obtainSource(this.sound); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(ImaAdpcmWavStereoTest.SOUND_PATH)); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(ImaAdpcmWavStereoTest.SOUND_PATH)); + final SoundSource bufferedSource = audio.obtainSource(sound); + streamedSource = new StreamedSoundSource(Gdx.files.internal(ImaAdpcmWavStereoTest.SOUND_PATH)); bufferedSource.setLooping(true); - this.streamedSource.setLooping(true); + streamedSource.setLooping(true); bufferedSource.play(); try { Thread.sleep(50); } catch (final InterruptedException e) { // ignore } - this.streamedSource.play(); - System.out.println("buffered duration: " + this.sound.getDuration() + "s"); - System.out.println("streamed duration: " + this.streamedSource.getDuration() + "s"); + streamedSource.play(); + System.out.println("buffered duration: " + sound.getDuration() + "s"); + System.out.println("streamed duration: " + streamedSource.getDuration() + "s"); } @@ -58,11 +58,11 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.streamedSource.dispose(); + sound.dispose(); + streamedSource.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/JniTest.java b/core/src/test/java/de/pottgames/tuningfork/test/JniTest.java index d7d1299..0efd976 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/JniTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/JniTest.java @@ -16,22 +16,22 @@ public class JniTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); // load via java decoder final long javaStartTime = System.nanoTime(); - this.sound = WaveLoader.load(Gdx.files.internal("ima_adpcm_stereo.wav"), true); + sound = WaveLoader.load(Gdx.files.internal("ima_adpcm_stereo.wav"), true); final long javaEndTime = System.nanoTime(); - this.sound.dispose(); + sound.dispose(); System.out.println("java decoder load time: " + (javaEndTime - javaStartTime) / 1000 / 1000 + " ms"); // load via rust decoder final long rustStartTime = System.nanoTime(); - this.sound = WaveLoader.load(Gdx.files.internal("ima_adpcm_stereo.wav"), false); + sound = WaveLoader.load(Gdx.files.internal("ima_adpcm_stereo.wav"), false); final long rustEndTime = System.nanoTime(); System.out.println("rust decoder load time: " + (rustEndTime - rustStartTime) / 1000 / 1000 + " ms"); - this.sound.play(); + sound.play(); } @@ -43,8 +43,8 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/JukeBoxTest.java b/core/src/test/java/de/pottgames/tuningfork/test/JukeBoxTest.java index 1e5d096..776ba04 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/JukeBoxTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/JukeBoxTest.java @@ -46,35 +46,35 @@ public class JukeBoxTest extends ApplicationAdapter implements JukeBoxObserver { @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); // LOAD SOUNDS - this.rhythm1 = new StreamedSoundSource(Gdx.files.internal("rhythm.wav")); - this.rhythm2 = SoundLoader.load(Gdx.files.internal("rhythm2.flac")); - this.rhythm3 = new StreamedSoundSource(Gdx.files.internal("rhythm3.flac")); - this.rhythm4 = SoundLoader.load(Gdx.files.internal("rhythm4.flac")); - this.rhythm5 = new StreamedSoundSource(Gdx.files.internal("short.flac")); + rhythm1 = new StreamedSoundSource(Gdx.files.internal("rhythm.wav")); + rhythm2 = SoundLoader.load(Gdx.files.internal("rhythm2.flac")); + rhythm3 = new StreamedSoundSource(Gdx.files.internal("rhythm3.flac")); + rhythm4 = SoundLoader.load(Gdx.files.internal("rhythm4.flac")); + rhythm5 = new StreamedSoundSource(Gdx.files.internal("short.flac")); // OBTAIN BUFFERED SOUND SOURCES - this.rhythm2Source = this.audio.obtainSource(this.rhythm2); - this.rhythm4Source = this.audio.obtainSource(this.rhythm4); + rhythm2Source = audio.obtainSource(rhythm2); + rhythm4Source = audio.obtainSource(rhythm4); // OPTIONAL: SET RELATIVE // if you want to play music globally and not in 3D space, make sure to only provide relative sources - this.rhythm1.setRelative(true); - this.rhythm3.setRelative(true); - this.rhythm5.setRelative(true); - this.rhythm2Source.setRelative(true); - this.rhythm4Source.setRelative(true); - this.rhythm5.setRelative(true); + rhythm1.setRelative(true); + rhythm3.setRelative(true); + rhythm5.setRelative(true); + rhythm2Source.setRelative(true); + rhythm4Source.setRelative(true); + rhythm5.setRelative(true); // CREATE SONGS final SongSettings settings = SongSettings.linear(1f, 2f, 2f); - final Song song1 = new Song(this.rhythm1, SongSettings.linear(1f, 0.5f, 1f), new SongMeta().setTitle("rhythm1")); - final Song song2 = new Song(this.rhythm2Source, settings, new SongMeta().setTitle("rhythm2")); - final Song song3 = new Song(this.rhythm3, settings, new SongMeta().setTitle("rhythm3")); - final Song song4 = new Song(this.rhythm4Source, settings, new SongMeta().setTitle("rhythm4")); - final Song song5 = new Song(this.rhythm5, settings, new SongMeta().setTitle("rhythm5")); + final Song song1 = new Song(rhythm1, SongSettings.linear(1f, 0.5f, 1f), new SongMeta().setTitle("rhythm1")); + final Song song2 = new Song(rhythm2Source, settings, new SongMeta().setTitle("rhythm2")); + final Song song3 = new Song(rhythm3, settings, new SongMeta().setTitle("rhythm3")); + final Song song4 = new Song(rhythm4Source, settings, new SongMeta().setTitle("rhythm4")); + final Song song5 = new Song(rhythm5, settings, new SongMeta().setTitle("rhythm5")); // CREATE PLAYLIST 1 final PlayList playList = new PlayList() { @@ -102,54 +102,54 @@ public String toString() { // CREATE PLAYLIST PROVIDER final DefaultPlayListProvider provider = new DefaultPlayListProvider().add(playList).add(playList2); - this.jukeBox = new JukeBox(provider); - this.jukeBox.addObserver(this); - this.jukeBox.play(); + jukeBox = new JukeBox(provider); + jukeBox.addObserver(this); + jukeBox.play(); } @Override public void render() { if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { - this.jukeBox.play(); + jukeBox.play(); } if (Gdx.input.isKeyJustPressed(Input.Keys.P)) { - this.jukeBox.pause(); + jukeBox.pause(); } if (Gdx.input.isKeyJustPressed(Input.Keys.S)) { - this.jukeBox.stop(); + jukeBox.stop(); } if (Gdx.input.isKeyJustPressed(Input.Keys.J)) { - this.jukeBox.softStop(Interpolation.linear, 1.5f); + jukeBox.softStop(Interpolation.linear, 1.5f); } if (Gdx.input.isKeyJustPressed(Input.Keys.K)) { - this.jukeBox.softStopAndResume(Interpolation.linear, 2f); + jukeBox.softStopAndResume(Interpolation.linear, 2f); } if (Gdx.input.isKeyJustPressed(Input.Keys.U)) { - this.audio.getListener().setPosition(100f, 0f, 0f); + audio.getListener().setPosition(100f, 0f, 0f); } if (Gdx.input.isKeyJustPressed(Input.Keys.I)) { - this.jukeBox.setVolume(this.jukeBox.getVolume() + 0.1f); + jukeBox.setVolume(jukeBox.getVolume() + 0.1f); } if (Gdx.input.isKeyJustPressed(Input.Keys.K)) { - this.jukeBox.setVolume(this.jukeBox.getVolume() - 0.1f); + jukeBox.setVolume(jukeBox.getVolume() - 0.1f); } - this.jukeBox.update(); + jukeBox.update(); } @Override public void dispose() { - this.jukeBox.clear(); - this.rhythm1.dispose(); - this.rhythm2.dispose(); - this.rhythm3.dispose(); - this.rhythm4.dispose(); - this.rhythm5.dispose(); + jukeBox.clear(); + rhythm1.dispose(); + rhythm2.dispose(); + rhythm3.dispose(); + rhythm4.dispose(); + rhythm5.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/LoaderInputStreamTest.java b/core/src/test/java/de/pottgames/tuningfork/test/LoaderInputStreamTest.java index 83dcdc5..e5902e2 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/LoaderInputStreamTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/LoaderInputStreamTest.java @@ -44,7 +44,7 @@ public class LoaderInputStreamTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); InputStream wavStream = null; InputStream flacStream = null; @@ -62,40 +62,40 @@ public void create() { System.exit(1); } - this.wav = WaveLoader.load(wavStream); - this.flac = FlacLoader.load(flacStream); - this.ogg = OggLoader.load(oggStream); - this.aiff = AiffLoader.load(aiffStream); - this.mp3 = Mp3Loader.load(mp3Stream); + wav = WaveLoader.load(wavStream); + flac = FlacLoader.load(flacStream); + ogg = OggLoader.load(oggStream); + aiff = AiffLoader.load(aiffStream); + mp3 = Mp3Loader.load(mp3Stream); } @Override public void render() { - if (System.currentTimeMillis() > this.startTime + (long) this.duration) { + if (System.currentTimeMillis() > startTime + (long) duration) { SoundBuffer toPlay; - if (this.playing == this.wav) { - toPlay = this.flac; + if (playing == wav) { + toPlay = flac; System.out.println("flac"); - } else if (this.playing == this.flac) { - toPlay = this.ogg; + } else if (playing == flac) { + toPlay = ogg; System.out.println("ogg"); - } else if (this.playing == this.ogg) { - toPlay = this.aiff; + } else if (playing == ogg) { + toPlay = aiff; System.out.println("aiff"); - } else if (this.playing == this.aiff) { - toPlay = this.mp3; + } else if (playing == aiff) { + toPlay = mp3; System.out.println("mp3"); - } else if (this.playing == this.mp3) { - toPlay = this.wav; + } else if (playing == mp3) { + toPlay = wav; System.out.println("wav"); } else { - toPlay = this.wav; + toPlay = wav; System.out.println("wav"); } - this.playing = toPlay; - this.startTime = System.currentTimeMillis(); - this.duration = toPlay.getDuration() * 1000f; + playing = toPlay; + startTime = System.currentTimeMillis(); + duration = toPlay.getDuration() * 1000f; toPlay.play(); } } @@ -103,13 +103,13 @@ public void render() { @Override public void dispose() { - this.wav.dispose(); - this.flac.dispose(); - this.ogg.dispose(); - this.aiff.dispose(); - this.mp3.dispose(); + wav.dispose(); + flac.dispose(); + ogg.dispose(); + aiff.dispose(); + mp3.dispose(); - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/LoopPointSoundBufferTest.java b/core/src/test/java/de/pottgames/tuningfork/test/LoopPointSoundBufferTest.java index 6b57d7c..143603c 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/LoopPointSoundBufferTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/LoopPointSoundBufferTest.java @@ -18,30 +18,30 @@ public class LoopPointSoundBufferTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); - this.sound.setLoopPoints(3f, 7f); - final float[] loopPoints = this.sound.getLoopPoints(); - System.out.println("Sound duration: " + this.sound.getDuration() + "s"); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + sound.setLoopPoints(3f, 7f); + final float[] loopPoints = sound.getLoopPoints(); + System.out.println("Sound duration: " + sound.getDuration() + "s"); System.out.println("loop points: " + loopPoints[0] + " | " + loopPoints[1]); - this.source = this.audio.obtainSource(this.sound); - this.source.setLooping(true); - this.source.play(); + source = audio.obtainSource(sound); + source.setLooping(true); + source.play(); } @Override public void render() { - System.out.println("playback position: " + this.source.getPlaybackPosition() + "s"); + System.out.println("playback position: " + source.getPlaybackPosition() + "s"); } @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/LoopPointStreamingTest.java b/core/src/test/java/de/pottgames/tuningfork/test/LoopPointStreamingTest.java index 07f016c..9c8fc0d 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/LoopPointStreamingTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/LoopPointStreamingTest.java @@ -16,13 +16,13 @@ public class LoopPointStreamingTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); - this.source = new StreamedSoundSource(Gdx.files.internal("numbers.wav")); - this.source.setLoopPoints(3f, 7f); - this.source.setLooping(true); - this.source.play(); - System.out.println("Sound duration: " + this.source.getDuration() + "s"); + source = new StreamedSoundSource(Gdx.files.internal("numbers.wav")); + source.setLoopPoints(3f, 7f); + source.setLooping(true); + source.play(); + System.out.println("Sound duration: " + source.getDuration() + "s"); } @@ -30,20 +30,20 @@ public void create() { @Override public void render() { if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { - this.source.setPlaybackPosition(9f); + source.setPlaybackPosition(9f); } else if (Gdx.input.isKeyJustPressed(Input.Keys.P)) { - this.source.play(); + source.play(); } else if (Gdx.input.isKeyJustPressed(Input.Keys.T)) { - this.source.setPlaybackPosition(1f); + source.setPlaybackPosition(1f); } - System.out.println("playback position: " + this.source.getPlaybackPosition() + "s"); + System.out.println("playback position: " + source.getPlaybackPosition() + "s"); } @Override public void dispose() { - this.source.dispose(); - this.audio.dispose(); + source.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/MiniExample.java b/core/src/test/java/de/pottgames/tuningfork/test/MiniExample.java index 6ec772e..9982eec 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/MiniExample.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/MiniExample.java @@ -29,13 +29,13 @@ public class MiniExample extends ApplicationAdapter { @Override public void create() { // before we can do anything, we need to initialize our Audio instance - this.audio = Audio.init(); + audio = Audio.init(); // load a sound - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); - System.out.println("Sound duration: " + this.sound.getDuration() + "s"); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + System.out.println("Sound duration: " + sound.getDuration() + "s"); - this.sound.play(); + sound.play(); } @@ -47,10 +47,10 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); + sound.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/MsAdpcmWavMonoTest.java b/core/src/test/java/de/pottgames/tuningfork/test/MsAdpcmWavMonoTest.java index f4588a1..7826917 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/MsAdpcmWavMonoTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/MsAdpcmWavMonoTest.java @@ -33,21 +33,21 @@ public class MsAdpcmWavMonoTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(MsAdpcmWavMonoTest.SOUND_PATH)); - this.bufferedSource = this.audio.obtainSource(this.sound); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(MsAdpcmWavMonoTest.SOUND_PATH)); - this.bufferedSource.setLooping(true); - this.streamedSource.setLooping(true); - this.bufferedSource.play(); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(MsAdpcmWavMonoTest.SOUND_PATH)); + bufferedSource = audio.obtainSource(sound); + streamedSource = new StreamedSoundSource(Gdx.files.internal(MsAdpcmWavMonoTest.SOUND_PATH)); + bufferedSource.setLooping(true); + streamedSource.setLooping(true); + bufferedSource.play(); try { Thread.sleep(50); } catch (final InterruptedException e) { // ignore } - this.streamedSource.play(); - System.out.println("buffered duration: " + this.sound.getDuration() + "s"); - System.out.println("streamed duration: " + this.streamedSource.getDuration() + "s"); + streamedSource.play(); + System.out.println("buffered duration: " + sound.getDuration() + "s"); + System.out.println("streamed duration: " + streamedSource.getDuration() + "s"); } @@ -59,8 +59,8 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/MsAdpcmWavStereoTest.java b/core/src/test/java/de/pottgames/tuningfork/test/MsAdpcmWavStereoTest.java index d30a788..9d1ee36 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/MsAdpcmWavStereoTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/MsAdpcmWavStereoTest.java @@ -33,21 +33,21 @@ public class MsAdpcmWavStereoTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(MsAdpcmWavStereoTest.SOUND_PATH)); - this.bufferedSource = this.audio.obtainSource(this.sound); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(MsAdpcmWavStereoTest.SOUND_PATH)); - this.bufferedSource.setLooping(true); - this.streamedSource.setLooping(true); - this.bufferedSource.play(); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(MsAdpcmWavStereoTest.SOUND_PATH)); + bufferedSource = audio.obtainSource(sound); + streamedSource = new StreamedSoundSource(Gdx.files.internal(MsAdpcmWavStereoTest.SOUND_PATH)); + bufferedSource.setLooping(true); + streamedSource.setLooping(true); + bufferedSource.play(); try { Thread.sleep(50); } catch (final InterruptedException e) { // ignore } - this.streamedSource.play(); - System.out.println("buffered duration: " + this.sound.getDuration() + "s"); - System.out.println("streamed duration: " + this.streamedSource.getDuration() + "s"); + streamedSource.play(); + System.out.println("buffered duration: " + sound.getDuration() + "s"); + System.out.println("streamed duration: " + streamedSource.getDuration() + "s"); } @@ -59,8 +59,8 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/Note.java b/core/src/test/java/de/pottgames/tuningfork/test/Note.java index c19ea84..9a642ad 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/Note.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/Note.java @@ -47,7 +47,7 @@ enum Note { float getFrequency() { - return this.frequency; + return frequency; } } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/PanningTest.java b/core/src/test/java/de/pottgames/tuningfork/test/PanningTest.java index 7046319..de9523f 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/PanningTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/PanningTest.java @@ -31,32 +31,32 @@ public class PanningTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = SoundLoader.load(Gdx.files.internal("rhythm.wav")); - this.soundDuration = this.sound.getDuration() * 1000f; + audio = Audio.init(); + sound = SoundLoader.load(Gdx.files.internal("rhythm.wav")); + soundDuration = sound.getDuration() * 1000f; } @Override public void render() { - if (System.currentTimeMillis() > this.soundPlayStartTime + (long) this.soundDuration) { - this.left = !this.left; - this.playSound(this.left ? -1f : 1f); - System.out.println(this.left ? "left" : "right"); + if (System.currentTimeMillis() > soundPlayStartTime + (long) soundDuration) { + left = !left; + playSound(left ? -1f : 1f); + System.out.println(left ? "left" : "right"); } } private void playSound(float pan) { - this.sound.play(1f, 1f, pan); - this.soundPlayStartTime = System.currentTimeMillis(); + sound.play(1f, 1f, pan); + soundPlayStartTime = System.currentTimeMillis(); } @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/PcmSoundSourceTest.java b/core/src/test/java/de/pottgames/tuningfork/test/PcmSoundSourceTest.java index 33432a1..ebe8653 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/PcmSoundSourceTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/PcmSoundSourceTest.java @@ -37,22 +37,22 @@ public class PcmSoundSourceTest extends ApplicationAdapter { @Override public void create() { final AudioConfig config = new AudioConfig().setLogger(new ConsoleLogger(LogLevel.DEBUG_INFO_WARN_ERROR)); - this.audio = Audio.init(config); - this.stream = new WavInputStream(Gdx.files.internal("numbers.wav")); - final PcmFormat format = PcmFormat.determineFormat(this.stream.getChannels(), this.stream.getBitsPerSample(), this.stream.getPcmDataType()); + audio = Audio.init(config); + stream = new WavInputStream(Gdx.files.internal("numbers.wav")); + final PcmFormat format = PcmFormat.determineFormat(stream.getChannels(), stream.getBitsPerSample(), stream.getPcmDataType()); assert format != null; - this.pcmSource = new PcmSoundSource(this.stream.getSampleRate(), format); + pcmSource = new PcmSoundSource(stream.getSampleRate(), format); } @Override public void render() { - if (System.currentTimeMillis() > this.lastPcmPush + 500) { - this.lastPcmPush = System.currentTimeMillis(); - final int readData = this.stream.read(this.pcm); + if (System.currentTimeMillis() > lastPcmPush + 500) { + lastPcmPush = System.currentTimeMillis(); + final int readData = stream.read(pcm); if (readData != -1) { - this.pcmSource.queueSamples(this.pcm, 0, readData); - this.pcmSource.play(); + pcmSource.queueSamples(pcm, 0, readData); + pcmSource.play(); } } } @@ -60,8 +60,8 @@ public void render() { @Override public void dispose() { - this.pcmSource.dispose(); - this.audio.dispose(); + pcmSource.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/PlayReverseExample.java b/core/src/test/java/de/pottgames/tuningfork/test/PlayReverseExample.java index 12efba8..7810389 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/PlayReverseExample.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/PlayReverseExample.java @@ -38,46 +38,46 @@ public class PlayReverseExample extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.setupAssetManager(); + audio = Audio.init(); + setupAssetManager(); // normal loading - this.sound = SoundLoader.loadReverse(Gdx.files.internal("numbers.wav")); + sound = SoundLoader.loadReverse(Gdx.files.internal("numbers.wav")); // async loading via AssetManager final SoundBufferLoaderParameter parameter = new SoundBufferLoaderParameter(); parameter.reverse = true; - this.assetManager.load("carnivalrides.ogg", SoundBuffer.class, parameter); + assetManager.load("carnivalrides.ogg", SoundBuffer.class, parameter); - this.source = this.audio.obtainSource(this.sound); - this.source.play(); + source = audio.obtainSource(sound); + source.play(); } public void setupAssetManager() { - this.assetManager = new AssetManager(); + assetManager = new AssetManager(); final FileHandleResolver resolver = new InternalFileHandleResolver(); - this.assetManager.setLoader(SoundBuffer.class, new SoundBufferLoader(resolver)); + assetManager.setLoader(SoundBuffer.class, new SoundBufferLoader(resolver)); } @Override public void render() { - if (!this.jobDone && this.assetManager.update() && !this.source.isPlaying()) { - this.asyncLoadedSound = this.assetManager.get("carnivalrides.ogg"); - this.asyncLoadedSound.play(); - this.jobDone = true; + if (!jobDone && assetManager.update() && !source.isPlaying()) { + asyncLoadedSound = assetManager.get("carnivalrides.ogg"); + asyncLoadedSound.play(); + jobDone = true; } } @Override public void dispose() { - this.sound.dispose(); - if (this.asyncLoadedSound != null) { - this.asyncLoadedSound.dispose(); + sound.dispose(); + if (asyncLoadedSound != null) { + asyncLoadedSound.dispose(); } - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/PlayStartDelayTest.java b/core/src/test/java/de/pottgames/tuningfork/test/PlayStartDelayTest.java index 2a657ba..09bb461 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/PlayStartDelayTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/PlayStartDelayTest.java @@ -18,23 +18,23 @@ public class PlayStartDelayTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); - final long currentTime = this.audio.getDevice().getClockTime(); + final long currentTime = audio.getDevice().getClockTime(); // load a sound - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); // play via fire & forget but delayed final long startTime = currentTime + PlayStartDelayTest.milliToNano(1000L); - this.sound.playAtTime(-5L); + sound.playAtTime(-5L); System.out.println("The error is expected. If no error is logged, this test failed."); - this.sound.playAtTime(startTime); + sound.playAtTime(startTime); // play via source right after - this.source = this.audio.obtainSource(this.sound); - this.source.playAtTime(startTime + PlayStartDelayTest.milliToNano((long) (this.source.getDuration() * 1000))); - this.source.play(); // this should have no effect + source = audio.obtainSource(sound); + source.playAtTime(startTime + PlayStartDelayTest.milliToNano((long) (source.getDuration() * 1000))); + source.play(); // this should have no effect System.out.println("The test will finish after counting to ten twice."); } @@ -42,7 +42,7 @@ public void create() { @Override public void render() { - if (!this.source.isPlaying()) { + if (!source.isPlaying()) { System.out.println("Test finished"); System.exit(0); } @@ -56,8 +56,8 @@ private static long milliToNano(long millis) { @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/PlaybackPositionBufferedSourceTest.java b/core/src/test/java/de/pottgames/tuningfork/test/PlaybackPositionBufferedSourceTest.java index 5c399ca..eb1cf45 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/PlaybackPositionBufferedSourceTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/PlaybackPositionBufferedSourceTest.java @@ -38,15 +38,15 @@ public void create() { // before we can do anything, we need to initialize our Audio instance final AudioConfig config = new AudioConfig(); config.setLogger(new ConsoleLogger(LogLevel.TRACE_DEBUG_INFO_WARN_ERROR)); - this.audio = Audio.init(config); + audio = Audio.init(config); // load a sound - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); // play the sound - this.soundSource = this.audio.obtainSource(this.sound); - this.soundSource.setLooping(true); - this.soundSource.play(); + soundSource = audio.obtainSource(sound); + soundSource.setLooping(true); + soundSource.play(); } @@ -54,23 +54,23 @@ public void create() { public boolean touchUp(int screenX, int screenY, int pointer, int button) { final float seconds = Rng.get(-20f, 20f); System.out.println("setting position to: " + seconds); - this.soundSource.setPlaybackPosition(seconds); + soundSource.setPlaybackPosition(seconds); return true; } @Override public void render() { - System.out.println("playback position: " + this.soundSource.getPlaybackPosition()); + System.out.println("playback position: " + soundSource.getPlaybackPosition()); } @Override public void dispose() { - this.sound.dispose(); + sound.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/ProceduralSoundTest.java b/core/src/test/java/de/pottgames/tuningfork/test/ProceduralSoundTest.java index 966477d..76a4252 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/ProceduralSoundTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/ProceduralSoundTest.java @@ -40,67 +40,67 @@ public class ProceduralSoundTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.pcmSource = new PcmSoundSource(ProceduralSoundTest.SAMPLE_RATE, PcmFormat.FLOAT_MONO_32_BIT); - this.pcmSource.setVolume(0.5f); - this.song = SongGenerator.createImperialMarch(); - this.queueNextNote(); - this.pcmSource.play(); + audio = Audio.init(); + pcmSource = new PcmSoundSource(ProceduralSoundTest.SAMPLE_RATE, PcmFormat.FLOAT_MONO_32_BIT); + pcmSource.setVolume(0.5f); + song = SongGenerator.createImperialMarch(); + queueNextNote(); + pcmSource.play(); } @Override public void render() { // this isn't necessary, just to demonstrate how to check for an underflow - if (!this.pcmSource.isPlaying()) { + if (!pcmSource.isPlaying()) { System.out.println("pcm underflow, resuming playback"); } // we're playing a song on repeat, so we want to make sure there's always some samples in the queue (prevent // underflow) - final int queuedBuffers = this.pcmSource.queuedBuffers(); + final int queuedBuffers = pcmSource.queuedBuffers(); for (int i = 0; i < 3 - queuedBuffers; i++) { - this.queueNextNote(); + queueNextNote(); // this is best practice: // if an underflow happened for some reason, the source is in stopped-state and won't continue playing // without this call - this.pcmSource.play(); + pcmSource.play(); } } private void queueNextNote() { // fetch the next note from the song - final SongNote songNote = this.song[this.noteIndex]; + final SongNote songNote = song[noteIndex]; // sample count for this note final int sampleCount = (int) (ProceduralSoundTest.SAMPLES_PER_BEAT * songNote.durationFactor); // fill the array with samples if (songNote.note == Note.SILENCE) { - Arrays.fill(this.pcm, 0f); + Arrays.fill(pcm, 0f); } else { switch (ProceduralSoundTest.WAVEFORM) { case SINE: - this.createSineTonePcm(songNote.note, this.pcm, sampleCount); + createSineTonePcm(songNote.note, pcm, sampleCount); break; case SQUARE: - this.createSquareTonePcm(songNote.note, this.pcm, sampleCount); + createSquareTonePcm(songNote.note, pcm, sampleCount); break; } // to prevent audio cracks, apply some fading at the beginning and the end - this.fadeInAndOut(this.pcm, sampleCount); + fadeInAndOut(pcm, sampleCount); } // finally queue the samples on the source - this.pcmSource.queueSamples(this.pcm, 0, sampleCount); + pcmSource.queueSamples(pcm, 0, sampleCount); // and prepare for the next call to this method - this.noteIndex++; - if (this.noteIndex >= this.song.length) { - this.noteIndex = 0; + noteIndex++; + if (noteIndex >= song.length) { + noteIndex = 0; } } @@ -160,8 +160,8 @@ private void fadeInAndOut(float[] target, int limit) { @Override public void dispose() { - this.pcmSource.dispose(); - this.audio.dispose(); + pcmSource.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/QoaTest.java b/core/src/test/java/de/pottgames/tuningfork/test/QoaTest.java index 174aa7d..f3bfb84 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/QoaTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/QoaTest.java @@ -26,40 +26,40 @@ public class QoaTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.assetManager = new AssetManager(); - this.assetManager.setLoader(SoundBuffer.class, new SoundBufferLoader(new InternalFileHandleResolver())); + audio = Audio.init(); + assetManager = new AssetManager(); + assetManager.setLoader(SoundBuffer.class, new SoundBufferLoader(new InternalFileHandleResolver())); // SoundBuffer - this.sound = SoundLoader.load(Gdx.files.internal(QoaTest.SOUND_FILE_PATH1)); - System.out.println("SoundBuffer duration: " + this.sound.getDuration() + "s"); - this.sound.play(); + sound = SoundLoader.load(Gdx.files.internal(QoaTest.SOUND_FILE_PATH1)); + System.out.println("SoundBuffer duration: " + sound.getDuration() + "s"); + sound.play(); // StreamedSoundSource - this.streamedSound = new StreamedSoundSource(Gdx.files.internal(QoaTest.SOUND_FILE_PATH2)); - System.out.println("Streamed sound duration: " + this.streamedSound.getDuration() + "s"); - this.streamedSound.play(); + streamedSound = new StreamedSoundSource(Gdx.files.internal(QoaTest.SOUND_FILE_PATH2)); + System.out.println("Streamed sound duration: " + streamedSound.getDuration() + "s"); + streamedSound.play(); // Async loading - this.assetManager.load(QoaTest.SOUND_FILE_PATH3, SoundBuffer.class); + assetManager.load(QoaTest.SOUND_FILE_PATH3, SoundBuffer.class); } @Override public void render() { - if (this.asyncSound == null && this.assetManager.update()) { - this.asyncSound = this.assetManager.get(QoaTest.SOUND_FILE_PATH3, SoundBuffer.class); - System.out.println("Async SoundBuffer duration: " + this.asyncSound.getDuration() + "s"); - this.asyncSound.play(); + if (asyncSound == null && assetManager.update()) { + asyncSound = assetManager.get(QoaTest.SOUND_FILE_PATH3, SoundBuffer.class); + System.out.println("Async SoundBuffer duration: " + asyncSound.getDuration() + "s"); + asyncSound.play(); } } @Override public void dispose() { - this.sound.dispose(); - this.streamedSound.dispose(); - this.audio.dispose(); + sound.dispose(); + streamedSound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/ResamplerTest.java b/core/src/test/java/de/pottgames/tuningfork/test/ResamplerTest.java index 2594487..2457514 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/ResamplerTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/ResamplerTest.java @@ -37,22 +37,22 @@ public class ResamplerTest extends ApplicationAdapter implements InputAdapter { @Override public void create() { Gdx.input.setInputProcessor(this); - this.audio = Audio.init(); - final AudioDevice device = this.audio.getDevice(); + audio = Audio.init(); + final AudioDevice device = audio.getDevice(); System.out.println("default resampler: " + device.getDefaultResampler()); - this.resamplers = device.getAvailableResamplers(); - for (int i = 0; i < this.resamplers.size; i++) { - System.out.println("Press " + i + " to set the " + this.resamplers.get(i) + " resampler"); + resamplers = device.getAvailableResamplers(); + for (int i = 0; i < resamplers.size; i++) { + System.out.println("Press " + i + " to set the " + resamplers.get(i) + " resampler"); } System.out.println("Press A to play the BufferedSoundSource"); System.out.println("Press B to play the StreamedSoundSource"); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal("numbers_8bit_mono_8kHz.wav")); - this.streamedSource.setLooping(true); + streamedSource = new StreamedSoundSource(Gdx.files.internal("numbers_8bit_mono_8kHz.wav")); + streamedSource.setLooping(true); - this.sound = SoundLoader.load(Gdx.files.internal("numbers_8bit_mono_8kHz.wav")); - this.soundSource = this.audio.obtainSource(this.sound); - this.soundSource.setLooping(true); + sound = SoundLoader.load(Gdx.files.internal("numbers_8bit_mono_8kHz.wav")); + soundSource = audio.obtainSource(sound); + soundSource.setLooping(true); } @@ -67,12 +67,12 @@ public boolean keyUp(int keycode) { int resamplerIndex = -1; switch (keycode) { case Input.Keys.A: - this.soundSource.play(); - this.streamedSource.stop(); + soundSource.play(); + streamedSource.stop(); break; case Input.Keys.B: - this.soundSource.stop(); - this.streamedSource.play(); + soundSource.stop(); + streamedSource.play(); break; case Input.Keys.NUM_0: case Input.Keys.NUMPAD_0: @@ -118,9 +118,9 @@ public boolean keyUp(int keycode) { return false; } - if (resamplerIndex >= 0 && resamplerIndex < this.resamplers.size) { - final String resampler = this.resamplers.get(resamplerIndex); - this.audio.setDefaultResampler(resampler); + if (resamplerIndex >= 0 && resamplerIndex < resamplers.size) { + final String resampler = resamplers.get(resamplerIndex); + audio.setDefaultResampler(resampler); System.out.println("resampler set to: " + resampler); } @@ -130,8 +130,8 @@ public boolean keyUp(int keycode) { @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/SmartDeviceRerouterTest.java b/core/src/test/java/de/pottgames/tuningfork/test/SmartDeviceRerouterTest.java index fd88ada..99482c3 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/SmartDeviceRerouterTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/SmartDeviceRerouterTest.java @@ -73,11 +73,11 @@ public void create() { final AudioDeviceConfig audioDeviceConfig = new AudioDeviceConfig(); audioDeviceConfig.setDeviceSpecifier(deviceList.get(number)); audioDeviceConfig.setRerouter(new SmartDeviceRerouter()); - this.audio = Audio.init(new AudioConfig(audioDeviceConfig, DistanceAttenuationModel.NONE, 1, 0, logger)); + audio = Audio.init(new AudioConfig(audioDeviceConfig, DistanceAttenuationModel.NONE, 1, 0, logger)); - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); - final SoundSource source = this.audio.obtainSource(this.sound); + final SoundSource source = audio.obtainSource(sound); source.setLooping(true); source.play(); } @@ -91,10 +91,10 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); + sound.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/SoundBufferLoaderParameterTest.java b/core/src/test/java/de/pottgames/tuningfork/test/SoundBufferLoaderParameterTest.java index 60cc576..b3df907 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/SoundBufferLoaderParameterTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/SoundBufferLoaderParameterTest.java @@ -36,48 +36,48 @@ public class SoundBufferLoaderParameterTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.assetManager = new AssetManager(); + audio = Audio.init(); + assetManager = new AssetManager(); final FileHandleResolver resolver = new InternalFileHandleResolver(); - this.assetManager.setLoader(SoundBuffer.class, new SoundBufferLoader(resolver)); + assetManager.setLoader(SoundBuffer.class, new SoundBufferLoader(resolver)); // queue fordward playback asset for loading as usual - this.assetManager.load("numbers.wav", SoundBuffer.class); + assetManager.load("numbers.wav", SoundBuffer.class); // queue reverse playback asset for loading // it's the same file so we need to trick the AssetManager into thinking it's a different file final SoundBufferLoaderParameter parameter = new SoundBufferLoaderParameter(); parameter.reverse = true; parameter.file = Gdx.files.internal("numbers.wav"); - this.assetManager.load("numerinos_wavus", SoundBuffer.class, parameter); + assetManager.load("numerinos_wavus", SoundBuffer.class, parameter); // we don't load asynchronously because it's just a test - this.assetManager.finishLoading(); + assetManager.finishLoading(); // fetch assets - this.sound = this.assetManager.get("numbers.wav", SoundBuffer.class); - this.soundReverse = this.assetManager.get("numerinos_wavus", SoundBuffer.class); + sound = assetManager.get("numbers.wav", SoundBuffer.class); + soundReverse = assetManager.get("numerinos_wavus", SoundBuffer.class); - this.source = this.audio.obtainSource(this.sound); - this.source.play(); + source = audio.obtainSource(sound); + source.play(); } @Override public void render() { - if (!this.source.isPlaying()) { - final SoundBuffer playedSound = this.source.getBuffer(); - this.source.free(); - this.source = this.audio.obtainSource(playedSound == this.sound ? this.soundReverse : this.sound); - this.source.play(); + if (!source.isPlaying()) { + final SoundBuffer playedSound = source.getBuffer(); + source.free(); + source = audio.obtainSource(playedSound == sound ? soundReverse : sound); + source.play(); } } @Override public void dispose() { - this.assetManager.dispose(); - this.audio.dispose(); + assetManager.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/SoundLoaderAudioStreamTest.java b/core/src/test/java/de/pottgames/tuningfork/test/SoundLoaderAudioStreamTest.java index 6105014..f914782 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/SoundLoaderAudioStreamTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/SoundLoaderAudioStreamTest.java @@ -18,17 +18,17 @@ public class SoundLoaderAudioStreamTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); final AudioStream stream = new WavInputStream(Gdx.files.internal("numbers.wav")); - this.sound = SoundLoader.load(stream); - this.sound.play(); + sound = SoundLoader.load(stream); + sound.play(); } @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/SpeedOnlyChangeTest.java b/core/src/test/java/de/pottgames/tuningfork/test/SpeedOnlyChangeTest.java index 3c8b219..c0d3b73 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/SpeedOnlyChangeTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/SpeedOnlyChangeTest.java @@ -32,18 +32,18 @@ public class SpeedOnlyChangeTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); - this.sound = SoundLoader.load(Gdx.files.absolute("src/test/resources/carnivalrides.ogg")); - final SoundSource source = this.audio.obtainSource(this.sound); + sound = SoundLoader.load(Gdx.files.absolute("src/test/resources/carnivalrides.ogg")); + final SoundSource source = audio.obtainSource(sound); // set source pitch to change the speed final float pitch = 1.2f; source.setPitch(pitch); // apply pitch correction - this.effect = new SoundEffect(new PitchShifter().correctPitch(pitch)); - source.attachEffect(this.effect); + effect = new SoundEffect(new PitchShifter().correctPitch(pitch)); + source.attachEffect(effect); // in order to only hear the pitch corrected sound, we must silence the original sound with a filter source.setFilter(0f, 0f); @@ -60,11 +60,11 @@ public void render() { @Override public void dispose() { - this.effect.dispose(); - this.sound.dispose(); + effect.dispose(); + sound.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/StbVorbisTest.java b/core/src/test/java/de/pottgames/tuningfork/test/StbVorbisTest.java index 577e044..4300289 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/StbVorbisTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/StbVorbisTest.java @@ -16,20 +16,20 @@ public class StbVorbisTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); - this.sound = OggLoader.loadNonPacked("src/test/resources/numbers2.ogg"); - this.sound2 = OggLoader.load(Gdx.files.internal("numbers2.ogg")); - System.out.println("Sound duration: " + this.sound.getDuration() + "s"); - System.out.println("Sound2 duration: " + this.sound.getDuration() + "s"); + sound = OggLoader.loadNonPacked("src/test/resources/numbers2.ogg"); + sound2 = OggLoader.load(Gdx.files.internal("numbers2.ogg")); + System.out.println("Sound duration: " + sound.getDuration() + "s"); + System.out.println("Sound2 duration: " + sound.getDuration() + "s"); - this.sound.play(); + sound.play(); try { Thread.sleep(100); } catch (final InterruptedException e) { e.printStackTrace(); } - this.sound2.play(); + sound2.play(); } @@ -41,9 +41,9 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.sound2.dispose(); - this.audio.dispose(); + sound.dispose(); + sound2.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/StreamedSoundSourceTest.java b/core/src/test/java/de/pottgames/tuningfork/test/StreamedSoundSourceTest.java index 1d7c909..4d1bc55 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/StreamedSoundSourceTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/StreamedSoundSourceTest.java @@ -28,35 +28,35 @@ public class StreamedSoundSourceTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.source = new StreamedSoundSource(Gdx.files.absolute("src/test/resources/numbers.wav")); - System.out.println("Sound duration: " + this.source.getDuration() + "s"); - this.source.setLooping(true); - this.source.play(); + audio = Audio.init(); + source = new StreamedSoundSource(Gdx.files.absolute("src/test/resources/numbers.wav")); + System.out.println("Sound duration: " + source.getDuration() + "s"); + source.setLooping(true); + source.play(); } @Override public void render() { - final float pos = this.source.getPlaybackPosition(); + final float pos = source.getPlaybackPosition(); System.out.println("current playback position: " + pos + "s"); // PRESS SPACE TO SKIP TO 5s if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { - this.source.setPlaybackPosition(5f); + source.setPlaybackPosition(5f); } if (Gdx.input.isKeyJustPressed(Input.Keys.P)) { - if (this.source.isPlaying()) { - this.source.pause(); + if (source.isPlaying()) { + source.pause(); } else { - this.source.play(); + source.play(); } } if (Gdx.input.isKeyJustPressed(Input.Keys.S)) { - if (this.source.isPlaying()) { - this.source.stop(); + if (source.isPlaying()) { + source.stop(); } else { - this.source.play(); + source.play(); } } } @@ -64,8 +64,8 @@ public void render() { @Override public void dispose() { - this.source.dispose(); - this.audio.dispose(); + source.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/ThemePlayListProviderTest.java b/core/src/test/java/de/pottgames/tuningfork/test/ThemePlayListProviderTest.java index 16a8fe5..a5b6e7a 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/ThemePlayListProviderTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/ThemePlayListProviderTest.java @@ -35,35 +35,35 @@ public class ThemePlayListProviderTest extends ApplicationAdapter implements Juk @Override public void create() { - this.audio = Audio.init(); + audio = Audio.init(); // LOAD SOUNDS - this.rhythm1 = new StreamedSoundSource(Gdx.files.internal("rhythm.wav")); - this.rhythm2 = SoundLoader.load(Gdx.files.internal("rhythm2.flac")); - this.rhythm3 = new StreamedSoundSource(Gdx.files.internal("rhythm3.flac")); - this.rhythm4 = SoundLoader.load(Gdx.files.internal("rhythm4.flac")); - this.rhythm5 = new StreamedSoundSource(Gdx.files.internal("short.flac")); + rhythm1 = new StreamedSoundSource(Gdx.files.internal("rhythm.wav")); + rhythm2 = SoundLoader.load(Gdx.files.internal("rhythm2.flac")); + rhythm3 = new StreamedSoundSource(Gdx.files.internal("rhythm3.flac")); + rhythm4 = SoundLoader.load(Gdx.files.internal("rhythm4.flac")); + rhythm5 = new StreamedSoundSource(Gdx.files.internal("short.flac")); // OBTAIN BUFFERED SOUND SOURCES - this.rhythm2Source = this.audio.obtainSource(this.rhythm2); - this.rhythm4Source = this.audio.obtainSource(this.rhythm4); + rhythm2Source = audio.obtainSource(rhythm2); + rhythm4Source = audio.obtainSource(rhythm4); // OPTIONAL: SET RELATIVE // if you want to play music globally and not in 3D space, make sure to only provide relative sources - this.rhythm1.setRelative(true); - this.rhythm3.setRelative(true); - this.rhythm5.setRelative(true); - this.rhythm2Source.setRelative(true); - this.rhythm4Source.setRelative(true); - this.rhythm5.setRelative(true); + rhythm1.setRelative(true); + rhythm3.setRelative(true); + rhythm5.setRelative(true); + rhythm2Source.setRelative(true); + rhythm4Source.setRelative(true); + rhythm5.setRelative(true); // CREATE SONGS final SongSettings settings = SongSettings.linear(1f, 2f, 2f); - final Song song1 = new Song(this.rhythm1, SongSettings.linear(1f, 0.5f, 1f), new SongMeta().setTitle("rhythm1")); - final Song song2 = new Song(this.rhythm2Source, settings, new SongMeta().setTitle("rhythm2")); - final Song song3 = new Song(this.rhythm3, settings, new SongMeta().setTitle("rhythm3")); - final Song song4 = new Song(this.rhythm4Source, settings, new SongMeta().setTitle("rhythm4")); - final Song song5 = new Song(this.rhythm5, settings, new SongMeta().setTitle("rhythm5")); + final Song song1 = new Song(rhythm1, SongSettings.linear(1f, 0.5f, 1f), new SongMeta().setTitle("rhythm1")); + final Song song2 = new Song(rhythm2Source, settings, new SongMeta().setTitle("rhythm2")); + final Song song3 = new Song(rhythm3, settings, new SongMeta().setTitle("rhythm3")); + final Song song4 = new Song(rhythm4Source, settings, new SongMeta().setTitle("rhythm4")); + final Song song5 = new Song(rhythm5, settings, new SongMeta().setTitle("rhythm5")); // CREATE PLAYLIST 1 final PlayList playList = new PlayList() { @@ -89,49 +89,49 @@ public String toString() { playList2.setLooping(true); // CREATE PLAYLIST PROVIDER - this.provider = new ThemePlayListProvider(); - this.provider.add(playList, 0); - this.provider.add(playList2, 1); - this.provider.setTheme(0); - - this.jukeBox = new JukeBox(this.provider); - this.jukeBox.addObserver(this); - this.jukeBox.play(); + provider = new ThemePlayListProvider(); + provider.add(playList, 0); + provider.add(playList2, 1); + provider.setTheme(0); + + jukeBox = new JukeBox(provider); + jukeBox.addObserver(this); + jukeBox.play(); } @Override public void render() { if (Gdx.input.isKeyJustPressed(Input.Keys.SPACE)) { - this.jukeBox.play(); + jukeBox.play(); } if (Gdx.input.isKeyJustPressed(Input.Keys.P)) { - this.jukeBox.pause(); + jukeBox.pause(); } if (Gdx.input.isKeyJustPressed(Input.Keys.S)) { - this.jukeBox.stop(); + jukeBox.stop(); } if (Gdx.input.isKeyJustPressed(Input.Keys.J)) { - this.jukeBox.softStop(Interpolation.linear, 1.5f); + jukeBox.softStop(Interpolation.linear, 1.5f); } if (Gdx.input.isKeyJustPressed(Input.Keys.T)) { - this.provider.setTheme(1 - this.provider.getTheme()); // toggle theme - this.jukeBox.softStopAndResume(Interpolation.linear, 2f); + provider.setTheme(1 - provider.getTheme()); // toggle theme + jukeBox.softStopAndResume(Interpolation.linear, 2f); } - this.jukeBox.update(); + jukeBox.update(); } @Override public void dispose() { - this.jukeBox.clear(); - this.rhythm1.dispose(); - this.rhythm2.dispose(); - this.rhythm3.dispose(); - this.rhythm4.dispose(); - this.rhythm5.dispose(); - this.audio.dispose(); + jukeBox.clear(); + rhythm1.dispose(); + rhythm2.dispose(); + rhythm3.dispose(); + rhythm4.dispose(); + rhythm5.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/UpdateSoundEffectTest.java b/core/src/test/java/de/pottgames/tuningfork/test/UpdateSoundEffectTest.java index e054b6c..42ceb39 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/UpdateSoundEffectTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/UpdateSoundEffectTest.java @@ -32,42 +32,42 @@ public class UpdateSoundEffectTest extends ApplicationAdapter { private SoundEffect effect; private long tick = System.currentTimeMillis(); - private SoundEffectData[] effectData = { AutoWah.funkyBeats(), Chorus.chore(), new Compressor(), Distortion.rattle(), EaxReverb.auditorium(), - Echo.farAway(), new Equalizer(), Flanger.robotMetallic(), new FrequencyShifter(), PitchShifter.chipmunk(), new Reverb(), RingModulator.tremolo(), - new VocalMorpher() }; - private int effectDataIndex = this.effectData.length; + private SoundEffectData[] effectData = + { AutoWah.funkyBeats(), Chorus.chore(), new Compressor(), Distortion.rattle(), EaxReverb.auditorium(), Echo.farAway(), new Equalizer(), + Flanger.robotMetallic(), new FrequencyShifter(), PitchShifter.chipmunk(), new Reverb(), RingModulator.tremolo(), new VocalMorpher() }; + private int effectDataIndex = effectData.length; @Override public void create() { - this.audio = Audio.init(); - this.sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); - this.source = this.audio.obtainSource(this.sound); - this.source.setFilter(0f, 0f); - this.source.setLooping(true); - this.source.play(); - - this.effect = new SoundEffect(this.getNextEffectData()); - this.source.attachEffect(this.effect); + audio = Audio.init(); + sound = SoundLoader.load(Gdx.files.internal("numbers.wav")); + source = audio.obtainSource(sound); + source.setFilter(0f, 0f); + source.setLooping(true); + source.play(); + + effect = new SoundEffect(getNextEffectData()); + source.attachEffect(effect); } @Override public void render() { - if (this.tick + 2000 < System.currentTimeMillis()) { - this.tick = System.currentTimeMillis(); - final SoundEffectData data = this.getNextEffectData(); - this.effect.updateEffect(data); + if (tick + 2000 < System.currentTimeMillis()) { + tick = System.currentTimeMillis(); + final SoundEffectData data = getNextEffectData(); + effect.updateEffect(data); } } private SoundEffectData getNextEffectData() { - this.effectDataIndex++; - if (this.effectDataIndex >= this.effectData.length) { - this.effectDataIndex = 0; + effectDataIndex++; + if (effectDataIndex >= effectData.length) { + effectDataIndex = 0; } - final SoundEffectData data = this.effectData[this.effectDataIndex]; + final SoundEffectData data = effectData[effectDataIndex]; System.out.println(data.getClass().toString()); return data; } @@ -75,9 +75,9 @@ private SoundEffectData getNextEffectData() { @Override public void dispose() { - this.effect.dispose(); - this.sound.dispose(); - this.audio.dispose(); + effect.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/WavALawTest.java b/core/src/test/java/de/pottgames/tuningfork/test/WavALawTest.java index 5daef5b..1b4fc14 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/WavALawTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/WavALawTest.java @@ -34,37 +34,37 @@ public class WavALawTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(WavALawTest.FILE_PATH)); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(WavALawTest.FILE_PATH)); - this.bufferedSource = this.audio.obtainSource(this.sound); - System.out.println("Sound duration (streamed): " + this.streamedSource.getDuration() + "s"); - System.out.println("Sound duration (buffered): " + this.sound.getDuration() + "s"); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(WavALawTest.FILE_PATH)); + streamedSource = new StreamedSoundSource(Gdx.files.internal(WavALawTest.FILE_PATH)); + bufferedSource = audio.obtainSource(sound); + System.out.println("Sound duration (streamed): " + streamedSource.getDuration() + "s"); + System.out.println("Sound duration (buffered): " + sound.getDuration() + "s"); - this.activeSource = this.bufferedSource; + activeSource = bufferedSource; } @Override public void render() { - if (!this.activeSource.isPlaying()) { - if (this.activeSource == this.bufferedSource) { - this.activeSource = this.streamedSource; + if (!activeSource.isPlaying()) { + if (activeSource == bufferedSource) { + activeSource = streamedSource; System.out.println("streamed sound playing"); } else { - this.activeSource = this.bufferedSource; + activeSource = bufferedSource; System.out.println("buffered sound playing"); } - this.activeSource.play(); + activeSource.play(); } } @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/WavExtensibleFormatTest.java b/core/src/test/java/de/pottgames/tuningfork/test/WavExtensibleFormatTest.java index 3e2a581..22560c3 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/WavExtensibleFormatTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/WavExtensibleFormatTest.java @@ -32,21 +32,21 @@ public class WavExtensibleFormatTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(WavExtensibleFormatTest.SOUND_PATH)); - final SoundSource bufferedSource = this.audio.obtainSource(this.sound); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(WavExtensibleFormatTest.SOUND_PATH)); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(WavExtensibleFormatTest.SOUND_PATH)); + final SoundSource bufferedSource = audio.obtainSource(sound); + streamedSource = new StreamedSoundSource(Gdx.files.internal(WavExtensibleFormatTest.SOUND_PATH)); bufferedSource.setLooping(true); - this.streamedSource.setLooping(true); + streamedSource.setLooping(true); bufferedSource.play(); try { Thread.sleep(50); } catch (final InterruptedException e) { // ignore } - this.streamedSource.play(); - System.out.println("buffered duration: " + this.sound.getDuration() + "s"); - System.out.println("streamed duration: " + this.streamedSource.getDuration() + "s"); + streamedSource.play(); + System.out.println("buffered duration: " + sound.getDuration() + "s"); + System.out.println("streamed duration: " + streamedSource.getDuration() + "s"); } @@ -58,11 +58,11 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.streamedSource.dispose(); + sound.dispose(); + streamedSource.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/WavFloat32PcmTest.java b/core/src/test/java/de/pottgames/tuningfork/test/WavFloat32PcmTest.java index 3cda0b8..47e86d2 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/WavFloat32PcmTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/WavFloat32PcmTest.java @@ -32,21 +32,21 @@ public class WavFloat32PcmTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(WavFloat32PcmTest.SOUND_PATH)); - final SoundSource bufferedSource = this.audio.obtainSource(this.sound); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(WavFloat32PcmTest.SOUND_PATH)); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(WavFloat32PcmTest.SOUND_PATH)); + final SoundSource bufferedSource = audio.obtainSource(sound); + streamedSource = new StreamedSoundSource(Gdx.files.internal(WavFloat32PcmTest.SOUND_PATH)); bufferedSource.setLooping(true); - this.streamedSource.setLooping(true); + streamedSource.setLooping(true); bufferedSource.play(); try { Thread.sleep(200); } catch (final InterruptedException e) { // ignore } - this.streamedSource.play(); - System.out.println("buffered duration: " + this.sound.getDuration() + "s"); - System.out.println("streamed duration: " + this.streamedSource.getDuration() + "s"); + streamedSource.play(); + System.out.println("buffered duration: " + sound.getDuration() + "s"); + System.out.println("streamed duration: " + streamedSource.getDuration() + "s"); } @@ -58,11 +58,11 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.streamedSource.dispose(); + sound.dispose(); + streamedSource.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/WavFloat64PcmTest.java b/core/src/test/java/de/pottgames/tuningfork/test/WavFloat64PcmTest.java index c08ad5f..9b598c2 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/WavFloat64PcmTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/WavFloat64PcmTest.java @@ -32,21 +32,21 @@ public class WavFloat64PcmTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(WavFloat64PcmTest.SOUND_PATH)); - final SoundSource bufferedSource = this.audio.obtainSource(this.sound); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(WavFloat64PcmTest.SOUND_PATH)); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(WavFloat64PcmTest.SOUND_PATH)); + final SoundSource bufferedSource = audio.obtainSource(sound); + streamedSource = new StreamedSoundSource(Gdx.files.internal(WavFloat64PcmTest.SOUND_PATH)); bufferedSource.setLooping(true); - this.streamedSource.setLooping(true); + streamedSource.setLooping(true); bufferedSource.play(); try { Thread.sleep(200); } catch (final InterruptedException e) { // ignore } - this.streamedSource.play(); - System.out.println("buffered duration: " + this.sound.getDuration() + "s"); - System.out.println("streamed duration: " + this.streamedSource.getDuration() + "s"); + streamedSource.play(); + System.out.println("buffered duration: " + sound.getDuration() + "s"); + System.out.println("streamed duration: " + streamedSource.getDuration() + "s"); } @@ -58,11 +58,11 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.streamedSource.dispose(); + sound.dispose(); + streamedSource.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/WavInt24PcmTest.java b/core/src/test/java/de/pottgames/tuningfork/test/WavInt24PcmTest.java index 2e6f671..2003a5c 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/WavInt24PcmTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/WavInt24PcmTest.java @@ -32,21 +32,21 @@ public class WavInt24PcmTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(WavInt24PcmTest.SOUND_PATH)); - final SoundSource bufferedSource = this.audio.obtainSource(this.sound); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(WavInt24PcmTest.SOUND_PATH)); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(WavInt24PcmTest.SOUND_PATH)); + final SoundSource bufferedSource = audio.obtainSource(sound); + streamedSource = new StreamedSoundSource(Gdx.files.internal(WavInt24PcmTest.SOUND_PATH)); bufferedSource.setLooping(true); - this.streamedSource.setLooping(true); + streamedSource.setLooping(true); bufferedSource.play(); try { Thread.sleep(200); } catch (final InterruptedException e) { // ignore } - this.streamedSource.play(); - System.out.println("buffered duration: " + this.sound.getDuration() + "s"); - System.out.println("streamed duration: " + this.streamedSource.getDuration() + "s"); + streamedSource.play(); + System.out.println("buffered duration: " + sound.getDuration() + "s"); + System.out.println("streamed duration: " + streamedSource.getDuration() + "s"); } @@ -58,11 +58,11 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.streamedSource.dispose(); + sound.dispose(); + streamedSource.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/WavInt32PcmTest.java b/core/src/test/java/de/pottgames/tuningfork/test/WavInt32PcmTest.java index 540247f..0d9b835 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/WavInt32PcmTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/WavInt32PcmTest.java @@ -32,21 +32,21 @@ public class WavInt32PcmTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(WavInt32PcmTest.SOUND_PATH)); - final SoundSource bufferedSource = this.audio.obtainSource(this.sound); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(WavInt32PcmTest.SOUND_PATH)); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(WavInt32PcmTest.SOUND_PATH)); + final SoundSource bufferedSource = audio.obtainSource(sound); + streamedSource = new StreamedSoundSource(Gdx.files.internal(WavInt32PcmTest.SOUND_PATH)); bufferedSource.setLooping(true); - this.streamedSource.setLooping(true); + streamedSource.setLooping(true); bufferedSource.play(); try { Thread.sleep(50); } catch (final InterruptedException e) { // ignore } - this.streamedSource.play(); - System.out.println("buffered duration: " + this.sound.getDuration() + "s"); - System.out.println("streamed duration: " + this.streamedSource.getDuration() + "s"); + streamedSource.play(); + System.out.println("buffered duration: " + sound.getDuration() + "s"); + System.out.println("streamed duration: " + streamedSource.getDuration() + "s"); } @@ -58,11 +58,11 @@ public void render() { @Override public void dispose() { - this.sound.dispose(); - this.streamedSource.dispose(); + sound.dispose(); + streamedSource.dispose(); // always dispose Audio last - this.audio.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/WavULawTest.java b/core/src/test/java/de/pottgames/tuningfork/test/WavULawTest.java index 3274383..0ee8d44 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/WavULawTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/WavULawTest.java @@ -34,37 +34,37 @@ public class WavULawTest extends ApplicationAdapter { @Override public void create() { - this.audio = Audio.init(); - this.sound = WaveLoader.load(Gdx.files.internal(WavULawTest.FILE_PATH)); - this.streamedSource = new StreamedSoundSource(Gdx.files.internal(WavULawTest.FILE_PATH)); - this.bufferedSource = this.audio.obtainSource(this.sound); - System.out.println("Sound duration (streamed): " + this.streamedSource.getDuration() + "s"); - System.out.println("Sound duration (buffered): " + this.sound.getDuration() + "s"); + audio = Audio.init(); + sound = WaveLoader.load(Gdx.files.internal(WavULawTest.FILE_PATH)); + streamedSource = new StreamedSoundSource(Gdx.files.internal(WavULawTest.FILE_PATH)); + bufferedSource = audio.obtainSource(sound); + System.out.println("Sound duration (streamed): " + streamedSource.getDuration() + "s"); + System.out.println("Sound duration (buffered): " + sound.getDuration() + "s"); - this.activeSource = this.bufferedSource; + activeSource = bufferedSource; } @Override public void render() { - if (!this.activeSource.isPlaying()) { - if (this.activeSource == this.bufferedSource) { - this.activeSource = this.streamedSource; + if (!activeSource.isPlaying()) { + if (activeSource == bufferedSource) { + activeSource = streamedSource; System.out.println("streamed sound playing"); } else { - this.activeSource = this.bufferedSource; + activeSource = bufferedSource; System.out.println("buffered sound playing"); } - this.activeSource.play(); + activeSource.play(); } } @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/WaveFormTest.java b/core/src/test/java/de/pottgames/tuningfork/test/WaveFormTest.java index 392fb9c..2402cf1 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/WaveFormTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/WaveFormTest.java @@ -57,31 +57,31 @@ public class WaveFormTest extends ApplicationAdapter { @Override public void create() { - this.camera = new OrthographicCamera(); - this.viewport = new FitViewport(WaveFormTest.VIEWPORT_WIDTH, WaveFormTest.VIEWPORT_HEIGHT, this.camera); - this.renderer = new ShapeRenderer(); - this.audio = Audio.init(); + camera = new OrthographicCamera(); + viewport = new FitViewport(WaveFormTest.VIEWPORT_WIDTH, WaveFormTest.VIEWPORT_HEIGHT, camera); + renderer = new ShapeRenderer(); + audio = Audio.init(); // Load a ReadableSoundBuffer instead of just a default SoundBuffer. // That will allow us to read the audio data later on. - this.sound = SoundLoader.loadReadable(Gdx.files.internal(WaveFormTest.TEST_FILES[8])); + sound = SoundLoader.loadReadable(Gdx.files.internal(WaveFormTest.TEST_FILES[8])); // Extract the data we need to create the waveform - final PcmFormat format = this.sound.getPcmFormat(); + final PcmFormat format = sound.getPcmFormat(); final int channels = format.getChannels(); // Create the waveform of each channel - this.waveform = new float[channels][0]; + waveform = new float[channels][0]; for (int channel = 0; channel < channels; channel++) { - this.waveform[channel] = this.analyzeWaveForm(this.sound.getAudioData(), format, channel + 1); + waveform[channel] = analyzeWaveForm(sound.getAudioData(), format, channel + 1); } // Totally optional but often desired: normalizing the wave form - this.normalizeWaveForm(this.waveform); + normalizeWaveForm(waveform); - this.soundSource = this.audio.obtainSource(this.sound); - this.soundSource.setLooping(true); - this.soundSource.play(); + soundSource = audio.obtainSource(sound); + soundSource.setLooping(true); + soundSource.play(); } @@ -126,45 +126,45 @@ private void normalizeWaveForm(float[][] waveform) { @Override public void render() { ScreenUtils.clear(Color.BLACK); - this.renderer.setProjectionMatrix(this.camera.combined); - this.renderer.begin(ShapeRenderer.ShapeType.Filled); + renderer.setProjectionMatrix(camera.combined); + renderer.begin(ShapeRenderer.ShapeType.Filled); - for (int channel = 0; channel < this.waveform.length; channel++) { - this.renderWaveForm(this.waveform[channel], 50 + channel * WaveFormTest.WAVEFORM_HEIGHT); + for (int channel = 0; channel < waveform.length; channel++) { + renderWaveForm(waveform[channel], 50 + channel * WaveFormTest.WAVEFORM_HEIGHT); } - this.renderCursor(); + renderCursor(); - this.renderer.end(); + renderer.end(); } private void renderWaveForm(float[] waveform, float centerY) { - this.renderer.setColor(Color.WHITE); + renderer.setColor(Color.WHITE); for (int i = 0; i < waveform.length; i++) { final float height = waveform[i] * WaveFormTest.WAVEFORM_HEIGHT; - this.renderer.rect(i, centerY - height / 2f, 1f, height); + renderer.rect(i, centerY - height / 2f, 1f, height); } } private void renderCursor() { - this.renderer.setColor(Color.RED); - final float progress = this.soundSource.getPlaybackPosition() / this.sound.getDuration(); - this.renderer.rect(progress * WaveFormTest.VIEWPORT_WIDTH - WaveFormTest.CURSOR_WIDTH_HALF, 0f, WaveFormTest.CURSOR_WIDTH, - WaveFormTest.WAVEFORM_HEIGHT * this.waveform.length); + renderer.setColor(Color.RED); + final float progress = soundSource.getPlaybackPosition() / sound.getDuration(); + renderer.rect(progress * WaveFormTest.VIEWPORT_WIDTH - WaveFormTest.CURSOR_WIDTH_HALF, 0f, WaveFormTest.CURSOR_WIDTH, + WaveFormTest.WAVEFORM_HEIGHT * waveform.length); } @Override public void resize(int width, int height) { - this.viewport.update(width, height, true); + viewport.update(width, height, true); } @Override public void dispose() { - this.sound.dispose(); - this.audio.dispose(); + sound.dispose(); + audio.dispose(); } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/unit/DurationTest.java b/core/src/test/java/de/pottgames/tuningfork/test/unit/DurationTest.java index 6214cc1..1f1f511 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/unit/DurationTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/unit/DurationTest.java @@ -47,194 +47,194 @@ public class DurationTest { @BeforeAll public void setup() { Gdx.files = new Lwjgl3Files(); // hack setup gdx because we only need Gdx.files in order to run properly - this.audio = Audio.init(new AudioConfig().setLogger(new ConsoleLogger(LogLevel.INFO_WARN_ERROR))); - this.errorChecker = new ErrorLogger(this.getClass(), new ConsoleLogger()); + audio = Audio.init(new AudioConfig().setLogger(new ConsoleLogger(LogLevel.INFO_WARN_ERROR))); + errorChecker = new ErrorLogger(this.getClass(), new ConsoleLogger()); } @Test public void test1() { - this.testWav("numbers.wav", 10.508f, DurationTest.TOLERANCE); + testWav("numbers.wav", 10.508f, DurationTest.TOLERANCE); } @Test public void test2() { - this.testWav("24bit_stereo.wav", 5.538f, DurationTest.TOLERANCE); + testWav("24bit_stereo.wav", 5.538f, DurationTest.TOLERANCE); } @Test public void test3() { - this.testWav("32bit_float_numbers.wav", 10.508f, DurationTest.TOLERANCE); + testWav("32bit_float_numbers.wav", 10.508f, DurationTest.TOLERANCE); } @Test public void test4() { - this.testWav("32bit_stereo.wav", 5.619f, DurationTest.TOLERANCE); + testWav("32bit_stereo.wav", 5.619f, DurationTest.TOLERANCE); } @Test public void test5() { - this.testWav("64bit_float_numbers.wav", 10.508f, DurationTest.TOLERANCE); + testWav("64bit_float_numbers.wav", 10.508f, DurationTest.TOLERANCE); } @Test public void test6() { - this.testOgg("carnivalrides.ogg", 25.498f, DurationTest.TOLERANCE); + testOgg("carnivalrides.ogg", 25.498f, DurationTest.TOLERANCE); } @Test public void test7() { - this.testWav("extensible_88200hertz.wav", 6.629f, DurationTest.TOLERANCE); + testWav("extensible_88200hertz.wav", 6.629f, DurationTest.TOLERANCE); } @Test public void test8() { - this.testWav("guitar.wav", 9.915f, DurationTest.TOLERANCE); + testWav("guitar.wav", 9.915f, DurationTest.TOLERANCE); } @Test public void test9() { - this.testAiff("guitar_32bit_float.aiff", 9.915f, DurationTest.TOLERANCE); + testAiff("guitar_32bit_float.aiff", 9.915f, DurationTest.TOLERANCE); } @Test public void test10() { - this.testWav("ima_adpcm_mono.wav", 5.563f, DurationTest.TOLERANCE); + testWav("ima_adpcm_mono.wav", 5.563f, DurationTest.TOLERANCE); } @Test public void test11() { - this.testWav("ima_adpcm_stereo.wav", 11.2f, DurationTest.TOLERANCE); + testWav("ima_adpcm_stereo.wav", 11.2f, DurationTest.TOLERANCE); } @Test public void test12() { - this.testAiff("M1F1-int8-AFsp.aif", 2.937f, DurationTest.TOLERANCE); + testAiff("M1F1-int8-AFsp.aif", 2.937f, DurationTest.TOLERANCE); } @Test public void test13() { - this.testAiff("M1F1-int12-AFsp.aif", 2.937f, DurationTest.TOLERANCE); + testAiff("M1F1-int12-AFsp.aif", 2.937f, DurationTest.TOLERANCE); } @Test public void test14() { - this.testAiff("M1F1-int32-AFsp.aif", 2.937f, DurationTest.TOLERANCE); + testAiff("M1F1-int32-AFsp.aif", 2.937f, DurationTest.TOLERANCE); } @Test public void test15() { - this.testWav("ms_adpcm_mono.wav", 4.63f, DurationTest.TOLERANCE); + testWav("ms_adpcm_mono.wav", 4.63f, DurationTest.TOLERANCE); } @Test public void test16() { - this.testWav("ms_adpcm_stereo.wav", 9.003f, DurationTest.TOLERANCE); + testWav("ms_adpcm_stereo.wav", 9.003f, DurationTest.TOLERANCE); } @Test public void test17() { - this.testAiff("numbers.aiff", 10.508f, DurationTest.TOLERANCE); + testAiff("numbers.aiff", 10.508f, DurationTest.TOLERANCE); } @Test public void test18() { - this.testMp3("numbers.mp3", 10.58f, DurationTest.HIGH_TOLERANCE); + testMp3("numbers.mp3", 10.58f, DurationTest.HIGH_TOLERANCE); } @Test public void test19() { - this.testFlac("numbers_8bit_mono.flac", 10.508f, DurationTest.TOLERANCE); + testFlac("numbers_8bit_mono.flac", 10.508f, DurationTest.TOLERANCE); } @Test public void test20() { - this.testWav("numbers_8bit_mono.wav", 10.508f, DurationTest.TOLERANCE); + testWav("numbers_8bit_mono.wav", 10.508f, DurationTest.TOLERANCE); } @Test public void test21() { - this.testWav("numbers_8bit_mono_8kHz.wav", 10.508f, DurationTest.TOLERANCE); + testWav("numbers_8bit_mono_8kHz.wav", 10.508f, DurationTest.TOLERANCE); } @Test public void test22() { - this.testWav("numbers_8bit_stereo.wav", 10.508f, DurationTest.TOLERANCE); + testWav("numbers_8bit_stereo.wav", 10.508f, DurationTest.TOLERANCE); } @Test public void test23() { - this.testFlac("numbers_16bit_mono.flac", 10.508f, DurationTest.TOLERANCE); + testFlac("numbers_16bit_mono.flac", 10.508f, DurationTest.TOLERANCE); } @Test public void test24() { - this.testFlac("numbers_16bit_stereo.flac", 10.508f, DurationTest.TOLERANCE); + testFlac("numbers_16bit_stereo.flac", 10.508f, DurationTest.TOLERANCE); } @Test public void test25() { - this.testMp3("numbers_stereo.mp3", 10.867f, DurationTest.HIGH_TOLERANCE); + testMp3("numbers_stereo.mp3", 10.867f, DurationTest.HIGH_TOLERANCE); } @Test public void test26() { - this.testOgg("numbers2.ogg", 5.542f, DurationTest.TOLERANCE); + testOgg("numbers2.ogg", 5.542f, DurationTest.TOLERANCE); } @Test public void test27() { - this.testOgg("numbers3.ogg", 1080.765f, DurationTest.TOLERANCE); + testOgg("numbers3.ogg", 1080.765f, DurationTest.TOLERANCE); } @Test public void test28() { - this.testAiff("numbers-alaw.aifc", 10.508f, DurationTest.TOLERANCE); + testAiff("numbers-alaw.aifc", 10.508f, DurationTest.TOLERANCE); } @Test public void test29() { - this.testWav("numbers-alaw.wav", 10.508f, DurationTest.TOLERANCE); + testWav("numbers-alaw.wav", 10.508f, DurationTest.TOLERANCE); } @Test public void test30() { - this.testAiff("numbers-ulaw.aifc", 10.508f, DurationTest.TOLERANCE); + testAiff("numbers-ulaw.aifc", 10.508f, DurationTest.TOLERANCE); } @Test public void test31() { - this.testWav("numbers-ulaw.wav", 10.508f, DurationTest.TOLERANCE); + testWav("numbers-ulaw.wav", 10.508f, DurationTest.TOLERANCE); } @@ -248,14 +248,14 @@ public void test32() { final FileHandle file = Gdx.files.absolute("src/test/resources/" + path); final SoundBuffer buffer = OggLoader.load(file); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); + Assertions.assertFalse(errorChecker.checkLogError(null)); final StreamedSoundSource source = new StreamedSoundSource(file); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); + Assertions.assertFalse(errorChecker.checkLogError(null)); final float bufferDuration = buffer.getDuration(); final float streamDuration = source.getDuration(); - final String failMessageBuffer = this.assertionFailureMessage(file.name(), duration, bufferDuration, false); - final String failMessageStream = this.assertionFailureMessage(file.name(), duration, streamDuration, true); + final String failMessageBuffer = assertionFailureMessage(file.name(), duration, bufferDuration, false); + final String failMessageStream = assertionFailureMessage(file.name(), duration, streamDuration, true); final boolean bufferDurationMatches = MathUtils.isEqual(duration, bufferDuration, tolerance); final boolean streamDurationMatches = MathUtils.isEqual(duration, streamDuration, tolerance); @@ -265,133 +265,133 @@ public void test32() { Assertions.assertTrue(streamDurationMatches || !isStreamDuration, failMessageStream); source.dispose(); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); + Assertions.assertFalse(errorChecker.checkLogError(null)); buffer.dispose(); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); + Assertions.assertFalse(errorChecker.checkLogError(null)); } @Test public void test33() { - this.testWav("quadrophonic.wav", 0.636f, DurationTest.TOLERANCE); + testWav("quadrophonic.wav", 0.636f, DurationTest.TOLERANCE); } @Test public void test34() { - this.testWav("rhythm.wav", 3.692f, DurationTest.TOLERANCE); + testWav("rhythm.wav", 3.692f, DurationTest.TOLERANCE); } @Test public void test35() { - this.testFlac("rhythm2.flac", 16.615f, DurationTest.TOLERANCE); + testFlac("rhythm2.flac", 16.615f, DurationTest.TOLERANCE); } @Test public void test36() { - this.testFlac("rhythm3.flac", 16.615f, DurationTest.TOLERANCE); + testFlac("rhythm3.flac", 16.615f, DurationTest.TOLERANCE); } @Test public void test37() { - this.testFlac("rhythm4.flac", 16.615f, DurationTest.TOLERANCE); + testFlac("rhythm4.flac", 16.615f, DurationTest.TOLERANCE); } @Test public void test38() { - this.testFlac("short.flac", 1.846f, DurationTest.TOLERANCE); + testFlac("short.flac", 1.846f, DurationTest.TOLERANCE); } @Test public void test39() { - this.testWav("test_mono_1s.wav", 1f, DurationTest.TOLERANCE); + testWav("test_mono_1s.wav", 1f, DurationTest.TOLERANCE); } @Test public void test40() { - this.testWav("test_stereo_1s.wav", 1f, DurationTest.TOLERANCE); + testWav("test_stereo_1s.wav", 1f, DurationTest.TOLERANCE); } @Test public void test41() { - this.testAiff("wood12.aiff", 0.037f, DurationTest.TOLERANCE); + testAiff("wood12.aiff", 0.037f, DurationTest.TOLERANCE); } @Test public void test42() { - this.testAiff("wood24.aiff", 0.037f, DurationTest.TOLERANCE); + testAiff("wood24.aiff", 0.037f, DurationTest.TOLERANCE); } @Test public void test43() { - this.testAiff("guitar_64bit_float.aiff", 9.915f, DurationTest.TOLERANCE); + testAiff("guitar_64bit_float.aiff", 9.915f, DurationTest.TOLERANCE); } private void testWav(String path, float duration, float tolerance) { final FileHandle file = Gdx.files.absolute("src/test/resources/" + path); final SoundBuffer buffer = WaveLoader.load(file); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); - this.test(buffer, file, duration, tolerance); + Assertions.assertFalse(errorChecker.checkLogError(null)); + test(buffer, file, duration, tolerance); } private void testOgg(String path, float duration, float tolerance) { final FileHandle file = Gdx.files.absolute("src/test/resources/" + path); final SoundBuffer buffer = OggLoader.load(file); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); - this.test(buffer, file, duration, tolerance); + Assertions.assertFalse(errorChecker.checkLogError(null)); + test(buffer, file, duration, tolerance); } private void testMp3(String path, float duration, float tolerance) { final FileHandle file = Gdx.files.absolute("src/test/resources/" + path); final SoundBuffer buffer = Mp3Loader.load(file); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); - this.test(buffer, file, duration, tolerance); + Assertions.assertFalse(errorChecker.checkLogError(null)); + test(buffer, file, duration, tolerance); } private void testFlac(String path, float duration, float tolerance) { final FileHandle file = Gdx.files.absolute("src/test/resources/" + path); final SoundBuffer buffer = FlacLoader.load(file); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); - this.test(buffer, file, duration, tolerance); + Assertions.assertFalse(errorChecker.checkLogError(null)); + test(buffer, file, duration, tolerance); } private void testAiff(String path, float duration, float tolerance) { final FileHandle file = Gdx.files.absolute("src/test/resources/" + path); final SoundBuffer buffer = AiffLoader.load(file); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); - this.test(buffer, file, duration, tolerance); + Assertions.assertFalse(errorChecker.checkLogError(null)); + test(buffer, file, duration, tolerance); } private void test(SoundBuffer buffer, FileHandle file, float duration, float tolerance) { final StreamedSoundSource source = new StreamedSoundSource(file); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); + Assertions.assertFalse(errorChecker.checkLogError(null)); final float bufferDuration = buffer.getDuration(); final float streamDuration = source.getDuration(); - final String failMessageBuffer = this.assertionFailureMessage(file.name(), duration, bufferDuration, false); - final String failMessageStream = this.assertionFailureMessage(file.name(), duration, streamDuration, true); + final String failMessageBuffer = assertionFailureMessage(file.name(), duration, bufferDuration, false); + final String failMessageStream = assertionFailureMessage(file.name(), duration, streamDuration, true); Assertions.assertTrue(MathUtils.isEqual(duration, bufferDuration, tolerance), failMessageBuffer); Assertions.assertTrue(MathUtils.isEqual(duration, streamDuration, tolerance), failMessageStream); source.dispose(); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); + Assertions.assertFalse(errorChecker.checkLogError(null)); buffer.dispose(); - Assertions.assertFalse(this.errorChecker.checkLogError(null)); + Assertions.assertFalse(errorChecker.checkLogError(null)); } @@ -402,7 +402,7 @@ private String assertionFailureMessage(String path, float expected, float result @AfterAll public void cleanup() { - this.audio.dispose(); + audio.dispose(); } } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/unit/SoundLoaderUnitTest.java b/core/src/test/java/de/pottgames/tuningfork/test/unit/SoundLoaderUnitTest.java index f188cc6..d87975e 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/unit/SoundLoaderUnitTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/unit/SoundLoaderUnitTest.java @@ -36,7 +36,7 @@ public class SoundLoaderUnitTest { @BeforeAll public void setup() { Gdx.files = new Lwjgl3Files(); // hack setup gdx because we only need Gdx.files in order to run properly - this.audio = Audio.init(new AudioConfig().setLogger(new ConsoleLogger(LogLevel.INFO_WARN_ERROR))); + audio = Audio.init(new AudioConfig().setLogger(new ConsoleLogger(LogLevel.INFO_WARN_ERROR))); } @@ -82,7 +82,7 @@ public void loadFlac() { @AfterAll public void cleanup() { - this.audio.dispose(); + audio.dispose(); } } diff --git a/core/src/test/java/de/pottgames/tuningfork/test/unit/SoundSourceUnitTest.java b/core/src/test/java/de/pottgames/tuningfork/test/unit/SoundSourceUnitTest.java index 9ba7f89..4c4f9a4 100644 --- a/core/src/test/java/de/pottgames/tuningfork/test/unit/SoundSourceUnitTest.java +++ b/core/src/test/java/de/pottgames/tuningfork/test/unit/SoundSourceUnitTest.java @@ -40,87 +40,87 @@ public class SoundSourceUnitTest { public void setup() { Gdx.files = new Lwjgl3Files(); // hack setup gdx because we only need Gdx.files in order to run properly - this.audio = Audio.init(new AudioConfig().setLogger(new ConsoleLogger(LogLevel.INFO_WARN_ERROR))); - this.sound = WaveLoader.load(Gdx.files.internal("numbers.wav")); - this.source = this.audio.obtainSource(this.sound); + audio = Audio.init(new AudioConfig().setLogger(new ConsoleLogger(LogLevel.INFO_WARN_ERROR))); + sound = WaveLoader.load(Gdx.files.internal("numbers.wav")); + source = audio.obtainSource(sound); } @Test public void testVolume() { - Assertions.assertEquals(this.source.getVolume(), 1f); + Assertions.assertEquals(source.getVolume(), 1f); - this.source.setVolume(0f); - Assertions.assertEquals(this.source.getVolume(), 0f); + source.setVolume(0f); + Assertions.assertEquals(source.getVolume(), 0f); - this.source.setVolume(2f); - Assertions.assertEquals(this.source.getVolume(), 1f); + source.setVolume(2f); + Assertions.assertEquals(source.getVolume(), 1f); - this.source.setVolume(-1f); - Assertions.assertEquals(this.source.getVolume(), 0f); + source.setVolume(-1f); + Assertions.assertEquals(source.getVolume(), 0f); - this.source.setVolume(0.5f); - Assertions.assertEquals(this.source.getVolume(), 0.5f); + source.setVolume(0.5f); + Assertions.assertEquals(source.getVolume(), 0.5f); - this.source.setVolume(0.133333333333333333f); - Assertions.assertEquals(this.source.getVolume(), 0.133333333333333333f); + source.setVolume(0.133333333333333333f); + Assertions.assertEquals(source.getVolume(), 0.133333333333333333f); - this.source.setVolume(1f); - Assertions.assertEquals(this.source.getVolume(), 1f); + source.setVolume(1f); + Assertions.assertEquals(source.getVolume(), 1f); } @Test public void testRelative() { - Assertions.assertEquals(this.source.isRelative(), false); - this.source.setRelative(true); - Assertions.assertEquals(this.source.isRelative(), true); - this.source.setRelative(false); - Assertions.assertEquals(this.source.isRelative(), false); + Assertions.assertEquals(source.isRelative(), false); + source.setRelative(true); + Assertions.assertEquals(source.isRelative(), true); + source.setRelative(false); + Assertions.assertEquals(source.isRelative(), false); } @Test public void testPitch() { - Assertions.assertEquals(this.source.getPitch(), 1f); - this.source.setPitch(0f); - Assertions.assertEquals(this.source.getPitch(), 0f); + Assertions.assertEquals(source.getPitch(), 1f); + source.setPitch(0f); + Assertions.assertEquals(source.getPitch(), 0f); - this.source.setPitch(2f); - Assertions.assertEquals(this.source.getPitch(), 2f); + source.setPitch(2f); + Assertions.assertEquals(source.getPitch(), 2f); - this.source.setPitch(3f); - Assertions.assertEquals(this.source.getPitch(), 3f); + source.setPitch(3f); + Assertions.assertEquals(source.getPitch(), 3f); - this.source.setPitch(-1f); - Assertions.assertEquals(this.source.getPitch(), 0f); + source.setPitch(-1f); + Assertions.assertEquals(source.getPitch(), 0f); - this.source.setPitch(0.5f); - Assertions.assertEquals(this.source.getPitch(), 0.5f); + source.setPitch(0.5f); + Assertions.assertEquals(source.getPitch(), 0.5f); - this.source.setPitch(0.533333333333333333f); - Assertions.assertEquals(this.source.getPitch(), 0.533333333333333333f); + source.setPitch(0.533333333333333333f); + Assertions.assertEquals(source.getPitch(), 0.533333333333333333f); - this.source.setPitch(1f); - Assertions.assertEquals(this.source.getPitch(), 1f); + source.setPitch(1f); + Assertions.assertEquals(source.getPitch(), 1f); } @Test public void testFilter() { - Assertions.assertEquals(this.source.hasFilter(), false); - this.source.setFilter(0f, 0.5f); - Assertions.assertEquals(this.source.hasFilter(), true); - this.source.setFilter(1f, 1f); - Assertions.assertEquals(this.source.hasFilter(), false); + Assertions.assertEquals(source.hasFilter(), false); + source.setFilter(0f, 0.5f); + Assertions.assertEquals(source.hasFilter(), true); + source.setFilter(1f, 1f); + Assertions.assertEquals(source.hasFilter(), false); } @AfterAll public void cleanup() { - this.source.free(); - this.sound.dispose(); - this.audio.dispose(); + source.free(); + sound.dispose(); + audio.dispose(); } }