Skip to content

Kyrixen/KyrixenAudio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hi! This is Kyrixen, if you choosed this lib thank you very much! The description below is AI generated (ChatGPT) because im not a good writer :D

KyrixenAudio

A lightweight, cross-platform audio library for Java 8+ with IcedTea compatibility.

Features

  • Pure Java 8 - no native dependencies
  • IcedTea fix - works on default Linux OpenJDK
  • Cross-platform - Windows, Linux, macOS
  • Multiple sources - Files, classpath resources, InputStreams
  • Automatic format conversion - handles 8-bit, mono, unsigned PCM
  • Volume control - linear 0.0 to 1.0
  • Memory safe - proper cleanup methods

Installation

Drop KyrixenAudio.jar into your project and add to classpath.

IntelliJ IDEA

File → Project Structure → Libraries → + → Java → Select KyrixenAudio.jar

Maven/Gradle (Local)

mvn install:install-file -Dfile=KyrixenAudio.jar -DgroupId=org.kyrixen -DartifactId=dreg-audio -Dversion=1.0 -Dpackaging=jar

Quick Start

import org.kyrixen.audio.Sound;

public class MyGame {
    public static void main(String[] args) {
        // Load from file
        Sound music = new Sound(new File("music/background.wav"));
        music.loop();
        music.setVolume(0.5f);
        
        // Load from JAR resource
        Sound jump = new Sound("/assets/sounds/jump.wav");
        jump.play();
        
        // Cleanup on exit
        Sound.cleanup();
    }
}

Usage

Loading Sounds

// From file system
Sound sfx = new Sound(new File("sounds/explosion.wav"));

// From classpath (inside JAR)
Sound sfx = new Sound("/assets/sounds/explosion.wav");

// From InputStream
Sound sfx = new Sound(stream, "soundName");

Playback Control

sound.play();      // Play once
sound.loop();      // Loop continuously
sound.stop();      // Stop playback
sound.reset();     // Reset to beginning
sound.close();     // Release resources

Volume

sound.setVolume(1.0f);  // 100% (max)
sound.setVolume(0.5f);  // 50%
sound.setVolume(0.0f);  // 0% (mute)

Cleanup

// Close all loaded sounds
Sound.cleanup();

Supported Formats

Format Support Notes
WAV PCM 16-bit signed ✅ Native Best performance
WAV PCM 8-bit ✅ Converted Auto-converted to 16-bit
WAV PCM unsigned ✅ Converted Auto-converted to signed
WAV Mono ✅ Converted Auto-converted to stereo
MP3 ❌ No Convert to WAV first

Troubleshooting

No sound on Linux (IcedTea/OpenJDK)

This library automatically detects and works around IcedTea PulseAudio bugs. No action needed.

"Invalid format" error

Your audio file uses an unsupported encoding. Convert it:

ffmpeg -i input.wav -acodec pcm_s16le -ar 44100 -ac 2 output.wav

Memory issues

Call Sound.cleanup() when switching levels or exiting.

Building from Source

git clone https://github.com/Kyrixen/KyrixenAudio.git
cd KyrixenAudio

# IntelliJ
# Open project, Build → Build Artifacts

# Or command line
javac -d out src/io/kyrixen/audio/*.java
jar cvf KyrixenAudio.jar -C out org

License

MIT License - free for personal and commercial use.

Credits

Created for the DREG game project.

About

Fixes default openjdk 8 sound api issue

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages