2 * Sonitus - Format.java - Copyright © 2013 David Roden
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.
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.
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/>.
18 package net.pterodactylus.sonitus.data;
21 * A format is a combination of a number of channels, a sampling frequency, and
24 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
28 /** Constant for an unknown number of channels. */
29 public static final int UNKNOWN_CHANNELS = -1;
31 /** Constant for an unknown frequency. */
32 public static final int UNKNOWN_FREQUENCY = -1;
34 /** Constant for an unknown format. */
35 public static final String UNKNOWN_ENCODING = "UNKNOWN";
37 /** The number of channels of this format. */
38 private final int channels;
40 /** The sampling frequency of this format. */
41 private final int frequency;
43 /** The encoding of this format. */
44 private final String encoding;
47 * Creates a new format.
50 * The number of channels of this format
52 * The sampling frequency of this format
54 * The encoding of this format
56 public Format(int channels, int frequency, String encoding) {
57 this.channels = channels;
58 this.frequency = frequency;
59 this.encoding = encoding;
67 * Returns the number of channels of this format.
69 * @return The number of channels of this format
71 public int channels() {
76 * Returns the sampling frequency of this format.
78 * @return The sampling frequency of this format
80 public int frequency() {
85 * Returns the encoding of this format
87 * @return The encoding of this format
89 public String encoding() {
98 public int hashCode() {
99 return (channels << 16) ^ frequency ^ encoding.hashCode();
103 public boolean equals(Object object) {
104 if ((object == null) || (getClass() != object.getClass())) {
107 Format format = (Format) object;
108 return (format.channels == channels) && (format.frequency == frequency) && format.encoding.equals(encoding());
112 public String toString() {
113 return String.format("%d Channel%s, %d Hz, %s", channels, channels != 1 ? "s" : "", frequency, encoding);