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 /** The number of channels of this format. */
29 private final int channels;
31 /** The sampling frequency of this format. */
32 private final int frequency;
34 /** The encoding of this format. */
35 private final String encoding;
38 * Creates a new format.
41 * The number of channels of this format
43 * The sampling frequency of this format
45 * The encoding of this format
47 public Format(int channels, int frequency, String encoding) {
48 this.channels = channels;
49 this.frequency = frequency;
50 this.encoding = encoding;
58 * Returns the number of channels of this format.
60 * @return The number of channels of this format
62 public int channels() {
67 * Returns the sampling frequency of this format.
69 * @return The sampling frequency of this format
71 public int frequency() {
76 * Returns the encoding of this format
78 * @return The encoding of this format
80 public String encoding() {
89 public int hashCode() {
90 return (channels << 16) ^ frequency ^ encoding.hashCode();
94 public boolean equals(Object object) {
95 if ((object == null) || (getClass() != object.getClass())) {
98 Format format = (Format) object;
99 return (format.channels == channels) && (format.frequency == frequency) && format.encoding.equals(encoding());
103 public String toString() {
104 return String.format("%d Channels, %d Hz, %s", channels, frequency, encoding);