Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit 102791d

Browse files
committed
Initial commit
1 parent 84df9c9 commit 102791d

5 files changed

Lines changed: 768 additions & 6 deletions

File tree

README.md

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,104 @@
11
# JavaMP3
2-
A fast and lightweight library to decode MP3 data into raw samples (supports MPEG 1/2/2.5 Layer I/II/III)
2+
3+
**Currently only supports MP1 and MP2, see Status below. Support for MP3 is planned.**
4+
5+
## Introduction
6+
7+
JavaMP3 is a lightweight and fast API for decoding MP1, MP2, and MP3 files.
8+
9+
This API lets you:
10+
- Decode MPEG-1/2/2.5 Layer I/II/III data (that is MP1, MP2, and MP3)
11+
- Get a javax.sound.sampled.AudioInputStream to easily create a Clip from the decoded data and use the javax.sound.sampled API
12+
- Get the decoded raw bytes in the format OpenAL takes so you can directly feed an OpenAL buffer with the decoded data
13+
- Decode the data from several types of input such as InputStream, Path, byte[], byte[] with length and offset
14+
15+
## Install
16+
17+
JavaSkype requires Java >= 8 to run. You can get this library using Maven by adding this to your ```pom.xml```:
18+
19+
```xml
20+
<dependencies>
21+
<dependency>
22+
<groupId>fr.delthas</groupId>
23+
<artifactId>javamp3</artifactId>
24+
<version>1.0.0</version>
25+
</dependency>
26+
</dependencies>
27+
```
28+
29+
30+
## Quick example
31+
32+
This library is Object-oriented: you can use one of the several static functions in the Sound class to get a Sound object, and then call methods on it to get data and metadata. Let's have a look at how to interact with the library.
33+
34+
35+
There are several ways to get a Sound object (ie decoding MPEG data) :
36+
37+
```java
38+
// Getting and decoding a sound from a file
39+
Path path = Paths.get("res","crazy_dnb.mp3");
40+
Sound sound = Sound.createSound(path); // throws IOException if an error occured while reading the file or decoding its data
41+
42+
// Getting and decoding a sound from a resource file in your JAR
43+
InputStream in = MyClass.class.getResourceAsStream("/mp3/rick_astley.mp3");
44+
Sound sound = Sound.createSound(in) // throws IOException if an error occured while reading the resource file or decoding its data
45+
}
46+
47+
// You can also decode a sound from a byte array, see the library Javadoc
48+
```
49+
50+
Once you've got a Sound object, you may get the raw decoded PCM samples, or directly use the sound with the javax.sound.sampled API:
51+
52+
53+
```java
54+
// Creating a Clip from the sound and play it using the plain javax.sound.sampled API
55+
Sound sound = /* ... */;
56+
Clip clip = AudioSystem.getClip();
57+
AudioInputStream stream = sound.newAudioInputStream();
58+
clip.open(stream);
59+
clip.start();
60+
61+
// Getting the raw decoded PCM samples to fill an OpenAL buffer (using LWJGL)
62+
Sound sound = /* ... */;
63+
int buffer = alGenBuffers();
64+
ByteBuffer data = BufferUtils.createByteBuffer(sound.getBytes().length);
65+
data.put(sound.getBytes()).flip(); // LWJGL needs a direct buffer, cannot simply wrap the array
66+
alBufferData(buffer, sound.isStereo() ? AL_FORMAT_STEREO16 : AL_FORMAT_MONO16, data, sound.getSamplingFrequency());
67+
68+
```
69+
70+
## Documentation
71+
72+
The only public class is the Sound class.
73+
74+
The javadoc for the API is located at: https://mpeg.delthas.fr/
75+
76+
This API full supports multithread calls, there is no shared static state. For example, if trying to decode multiple MPEG files from a music folder, you are encouraged to use multiple threads.
77+
78+
## Building
79+
80+
Simply run ```maven package```.
81+
82+
83+
## Status
84+
85+
- [X] MPEG-1 Audio Layer I Support
86+
- [X] MPEG-1 Audio Layer II Support
87+
- [ ] MPEG-1 Audio Layer III Support
88+
- [ ] MPEG-2 Audio Layer I Support
89+
- [ ] MPEG-2 Audio Layer II Support
90+
- [ ] MPEG-2 Audio Layer II Support
91+
- [ ] MPEG-2.5 Audio Layer I Support
92+
- [ ] MPEG-2.5 Audio Layer II Support
93+
- [ ] MPEG-2.5 Audio Layer III Support
94+
- [ ] Tests
95+
96+
## Misceallenous
97+
98+
### Tech
99+
100+
JavaSkype uses no library except the standard Java library.:
101+
102+
### License
103+
104+
MIT

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>fr.delthas</groupId>
55
<artifactId>javamp3</artifactId>
6-
<version>0.0.1-SNAPSHOT</version>
6+
<version>1.0.0</version>
77

88
<name>JavaMP3</name>
99
<url>https://github.com/delthas/javamp3</url>

0 commit comments

Comments
 (0)