-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAiffCodec.java
More file actions
35 lines (27 loc) · 1.08 KB
/
AiffCodec.java
File metadata and controls
35 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package me.tamkungz.codecmedia.internal.audio.aiff;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import me.tamkungz.codecmedia.CodecMediaException;
public final class AiffCodec {
private AiffCodec() {
}
public static AiffProbeInfo decode(Path input) throws CodecMediaException {
try {
byte[] bytes = Files.readAllBytes(input);
return decode(bytes, input);
} catch (IOException e) {
throw new CodecMediaException("Failed to decode AIFF: " + input, e);
}
}
public static AiffProbeInfo decode(byte[] bytes, Path sourceRef) throws CodecMediaException {
AiffProbeInfo info = AiffParser.parse(bytes);
validateDecodedProbe(info, sourceRef);
return info;
}
private static void validateDecodedProbe(AiffProbeInfo info, Path input) throws CodecMediaException {
if (info.sampleRate() <= 0 || info.channels() <= 0 || info.bitrateKbps() <= 0) {
throw new CodecMediaException("Decoded AIFF has invalid stream values: " + input);
}
}
}