2021-09-12
This commit is contained in:
@@ -15,5 +15,5 @@ include(
|
|||||||
"xml", "jackson", "jsoup", "markdown", "network", "httpd",
|
"xml", "jackson", "jsoup", "markdown", "network", "httpd",
|
||||||
"properties", "serial-io",
|
"properties", "serial-io",
|
||||||
"mustache", "thymeleaf", "locale", "quartz", "sysinfo",
|
"mustache", "thymeleaf", "locale", "quartz", "sysinfo",
|
||||||
"imaging", "stream"
|
"imaging", "stream", "sound"
|
||||||
)
|
)
|
||||||
|
|||||||
14
sound/build.gradle.kts
Normal file
14
sound/build.gradle.kts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("elex-java")
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
|
||||||
|
}
|
||||||
56
sound/src/main/java/kr/pe/elex/examples/Example.java
Normal file
56
sound/src/main/java/kr/pe/elex/examples/Example.java
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.elex_project.abraxas.Console;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.sound.sampled.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class Example {
|
||||||
|
public static void main(String... args) throws LineUnavailableException {
|
||||||
|
Console.writeLine("# Audio file formats");
|
||||||
|
for (AudioFileFormat.Type type : AudioSystem.getAudioFileTypes()) {
|
||||||
|
Console.writeLine("{} / {}", type.toString(), type.getExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.writeLine("# Audio mixers");
|
||||||
|
for (Mixer.Info info : AudioSystem.getMixerInfo()) {
|
||||||
|
Console.writeLine("{} / {} / {}", info.getName(), info.getDescription(), info.getVendor());
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.writeLine("# Getting a Line from mixer");
|
||||||
|
Mixer mixer = AudioSystem.getMixer(AudioSystem.getMixerInfo()[1]);
|
||||||
|
//mixer.sy
|
||||||
|
for (Line.Info info : mixer.getSourceLineInfo()) {
|
||||||
|
Console.writeLine("{}", info);
|
||||||
|
if (mixer.isLineSupported(info)) {
|
||||||
|
Line line = mixer.getLine(info);
|
||||||
|
//line.open();
|
||||||
|
//line.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Console.writeLine("# Getting a Line from Audio System");
|
||||||
|
AudioFormat audioFormat = new AudioFormat(441000,16,2, false,true);
|
||||||
|
TargetDataLine line;
|
||||||
|
DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
|
||||||
|
if (AudioSystem.isLineSupported(info)) {
|
||||||
|
line = (TargetDataLine) AudioSystem.getLine(info);
|
||||||
|
line.open(audioFormat);
|
||||||
|
line.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.writeLine("# Getting a Port from Audio System");
|
||||||
|
if (AudioSystem.isLineSupported(Port.Info.SPEAKER)) {
|
||||||
|
Port speakerPort = (Port) AudioSystem.getLine(Port.Info.SPEAKER);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
sound/src/main/java/kr/pe/elex/examples/Playback.java
Normal file
65
sound/src/main/java/kr/pe/elex/examples/Playback.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import javax.sound.sampled.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class Playback {
|
||||||
|
|
||||||
|
public static void main(String... args) throws UnsupportedAudioFileException, LineUnavailableException, IOException {
|
||||||
|
playback();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void playback() throws LineUnavailableException, UnsupportedAudioFileException, IOException {
|
||||||
|
AudioInputStream inputStream = AudioSystem.getAudioInputStream(Objects.requireNonNull(ClassLoader.
|
||||||
|
getSystemResourceAsStream("alarm_gentle.wav")));
|
||||||
|
|
||||||
|
SourceDataLine line = AudioSystem.getSourceDataLine(inputStream.getFormat());
|
||||||
|
line.open();
|
||||||
|
line.start();
|
||||||
|
line.addLineListener(event -> {
|
||||||
|
if (event.getType().equals(LineEvent.Type.OPEN)){
|
||||||
|
|
||||||
|
} else if (event.getType().equals(LineEvent.Type.START)) {
|
||||||
|
|
||||||
|
}else if (event.getType().equals(LineEvent.Type.STOP)) {
|
||||||
|
|
||||||
|
}else if (event.getType().equals(LineEvent.Type.CLOSE)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
byte[] buffer = new byte[32];
|
||||||
|
int numRead = 0;
|
||||||
|
while ((numRead = inputStream.read(buffer, 0, buffer.length)) > 0) {
|
||||||
|
log.debug("read: {}", numRead);
|
||||||
|
line.write(buffer, 0, numRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
inputStream.close();
|
||||||
|
line.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void playbackClip() throws LineUnavailableException, UnsupportedAudioFileException, IOException {
|
||||||
|
Clip clip = AudioSystem.getClip();
|
||||||
|
clip.open(AudioSystem.getAudioInputStream(Objects.requireNonNull(ClassLoader.
|
||||||
|
getSystemResourceAsStream("alarm_gentle.wav"))));
|
||||||
|
//clip.loop(3);
|
||||||
|
clip.start();
|
||||||
|
|
||||||
|
//clip.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Examples for Java
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
BIN
sound/src/main/resources/alarm_gentle.wav
Executable file
BIN
sound/src/main/resources/alarm_gentle.wav
Executable file
Binary file not shown.
BIN
sound/src/main/resources/ringtone_minimal.wav
Executable file
BIN
sound/src/main/resources/ringtone_minimal.wav
Executable file
Binary file not shown.
Reference in New Issue
Block a user