You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 6, 2023. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+47-25Lines changed: 47 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,15 @@
1
1
# JavaMP3
2
2
3
-
**Currently only supports MP1 and MP2, see Status below. Support for MP3 is planned.**
3
+
**Currently supports MPEG-1 Layer I/II/III (that is, most MP1, MP2, and MP3 files)**
4
4
5
5
## Introduction
6
6
7
-
JavaMP3 is a lightweight and fast API for decoding MP1, MP2, and MP3 files.
7
+
JavaMP3 is a lightweight (minimalist) and fast API for decoding MP1, MP2, and MP3 files.
8
8
9
9
This API lets you:
10
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
11
+
- Get a javax.sound.sampled.AudioFormat to easily use the javax.sound.sampled API and play back the decoded data.
12
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
13
15
14
## Install
16
15
@@ -29,39 +28,60 @@ JavaMP3 requires Java >= 8 to run. You can get this library using Maven by addin
29
28
30
29
## Quick example
31
30
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.
31
+
The only public class in this library is the Sound class. It is simply an InputStream that return decoded PCM sound samples as you read from the stream, decoded from the specified underlying stream.
33
32
34
-
35
-
There are several ways to get a Sound object (ie decoding MPEG data) :
33
+
There are also several metadata-related methods to be able to get the sound sampling frequency, stereo mode, ...
36
34
37
35
```java
38
-
// Getting and decoding a sound from a file
36
+
// Getting a Sound from a file
39
37
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
// You can also decode a sound from a byte array, see the library Javadoc
47
56
```
48
57
49
-
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:
58
+
As expected from an InputStream, the creation of the stream will **not block**, and it is only when reading bytes from the stream, that the processing will take place (for the Sound class, that is the MPEG decoding process). You may get metadata about the sound as soon as you have instantiated it.
50
59
60
+
Let's have a look at some examples on how to use the decoded raw PCM sound data samples:
51
61
52
62
```java
53
63
// Creating a Clip from the sound and play it using the plain javax.sound.sampled API
54
64
Sound sound =/* ... */;
65
+
// We use an array to store the produced sound data (bad code style, but is okay for short sounds)
66
+
// (We have to store the data in order to get the number of samples in it, because of the (dumb) Java sound API)
67
+
ByteArrayOutputStream os =newByteArrayOutputStream();
68
+
// Read and decode the encoded sound data into the byte array output stream (blocking)
The javadoc for the API is located at: https://mpeg.delthas.fr/
93
+
The javadoc for the API is located at: http://www.javadoc.io/doc/fr.delthas/javamp3/
74
94
75
-
This API fully supports multithreaded 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.
95
+
You are encouraged to read the decoded data stream in a streaming way, and/or make use of multithreaded calls (i.e. decode the sound data in a background thread if your application needs to react in real-time to user input).
76
96
77
97
## Building
78
98
79
-
Simply run ```maven package```.
99
+
Simply run ```mvn install```.
80
100
81
101
82
102
## Status
83
103
84
104
-[X] MPEG-1 Audio Layer I Support
85
105
-[X] MPEG-1 Audio Layer II Support
86
-
-[] MPEG-1 Audio Layer III Support
106
+
-[X] MPEG-1 Audio Layer III Support
87
107
-[ ] MPEG-2 Audio Layer I Support
88
108
-[ ] MPEG-2 Audio Layer II Support
89
109
-[ ] MPEG-2 Audio Layer II Support
90
110
-[ ] MPEG-2.5 Audio Layer I Support
91
111
-[ ] MPEG-2.5 Audio Layer II Support
92
112
-[ ] MPEG-2.5 Audio Layer III Support
93
-
-[ ] Tests
113
+
-[X] Tests
114
+
-[ ] Fast seeking support
115
+
-[ ] Fast samples count fetching support
94
116
95
117
## Misceallenous
96
118
97
119
### Tech
98
120
99
-
JavaMP3 uses no library except the standard Java library.
121
+
JavaMP3 uses no library except the standard Java library, except for the compile-time JUnit dependency, for testing.
0 commit comments