Add parser for FLAC metadata.
[sonitus.git] / src / main / java / net / pterodactylus / sonitus / io / flac / StreamInfo.java
1 /*
2  * Sonitus - StreamInfo.java - Copyright © 2013 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sonitus.io.flac;
19
20 /**
21  * Parser for a {@link BlockType#STREAMINFO} metadata block.
22  *
23  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
24  */
25 public class StreamInfo extends Data {
26
27         /**
28          * Creates a new STREAMINFO block from the given buffer.
29          *
30          * @param content
31          *              The contents of the metadata block
32          */
33         public StreamInfo(byte[] content) {
34                 super(content);
35         }
36
37         //
38         // ACCESSORS
39         //
40
41         /**
42          * Returns the minimum block size.
43          *
44          * @return The minimum block size (in samples)
45          */
46         public int minimumBlockSize() {
47                 return (int) parseBits(0, 0, 16);
48         }
49
50         /**
51          * Returns the maximum block size.
52          *
53          * @return The maximum block size (in samples)
54          */
55         public int maximumBlockSize() {
56                 return (int) parseBits(2, 0, 16);
57         }
58
59         /**
60          * Returns the minimum frame size.
61          *
62          * @return The minimum frame size (in bytes)
63          */
64         public int minimumFrameSize() {
65                 return (int) parseBits(4, 0, 24);
66         }
67
68         /**
69          * Returns the maximum frame size.
70          *
71          * @return The maximum frame size (in bytes)
72          */
73         public int maximumFrameSize() {
74                 return (int) parseBits(7, 0, 24);
75         }
76
77         /**
78          * Returns the sample rate.
79          *
80          * @return The sample rate (in Hertz)
81          */
82         public int sampleRate() {
83                 return (int) parseBits(10, 0, 20);
84         }
85
86         /**
87          * Returns the number of channels.
88          *
89          * @return The number of channels
90          */
91         public int numberOfChannels() {
92                 return (int) (parseBits(12, 4, 3) + 1);
93         }
94
95         /**
96          * Returns the number of bits per sample.
97          *
98          * @return The number of bits per sample
99          */
100         public int bitsPerSample() {
101                 return (int) (parseBits(12, 7, 5) + 1);
102         }
103
104         /**
105          * Returns the total number of samples.
106          *
107          * @return The total number of samples
108          */
109         public long totalSamples() {
110                 return parseBits(13, 4, 36);
111         }
112
113 }