Skip to content

Commit

Permalink
Updates in response to pull request 1132
Browse files Browse the repository at this point in the history
Signed-off-by: Kelly Davis <kdavis@mozilla.com>
  • Loading branch information
kdavis-mozilla committed Mar 7, 2016
1 parent 4f5743b commit 404a2f5
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ Bundle-Version: 0.8.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ClassPath: .
Import-Package: org.slf4j
Service-Component: OSGI-INF/*,
OSGI-INF/audioContext.xml
Service-Component: OSGI-INF/*.xml,
Export-Package: org.eclipse.smarthome.io.audio
Bundle-ActivationPolicy: lazy

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Copyright (c) 2015-2016 Harald Kuhn
*
* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -11,7 +10,7 @@
/**
* A collection of constants for commonly used audio codecs
*
* @author Harald Kuhn (hkuhn42) initial api
* @author Harald Kuhn - Initial API
*
*/
public class AudioCodec {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Copyright (c) 2015-2016 Harald Kuhn
*
* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -11,13 +10,12 @@
/**
* A collection of constants for container formats
*
* @author Harald Kuhn (hkuhn42) initial api
* @author Harald Kuhn - Initial API
*/
public class AudioContainer {
/**
* {@link AudioCodec} encoded data without any container header or footer,
* e.g. MP3 is a non-container format
*
*/
public static final String NONE = "NONE";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Copyright (c) 2015-2016 Harald Kuhn
*
* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -11,7 +10,7 @@
/**
* General purpose audio exception
*
* @author Harald Kuhn (hkuhn42) initial api
* @author Harald Kuhn - Initial API
*/
public class AudioException extends Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Copyright (c) 2015-2016 Harald Kuhn
*
* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -9,39 +8,75 @@
package org.eclipse.smarthome.io.audio;

/**
* An audio format definition
* An audio format definition
*
* @author Harald Kuhn (hkuhn42) initial api
* @author Harald Kuhn - Initial API
*/
public class AudioFormat {

/**
* Codec
*/
private String codec;
private final String codec;

/**
* Container
*/
private String container;
private final String container;

/**
* Big endian or little endian
*/
private boolean bigEndian;
private final Boolean bigEndian;

/**
* Bit depth or bit rate depending on codec
* Bit depth
*
* @see <a href="http://bit.ly/1OTydad">Bit Depth</a>
*/
private final Integer bitDepth;

/**
* Bit rate
*
* @see <a href="http://bit.ly/1OTy5rk">Bit Rate</a>
*/
private int bits;
private final Integer bitRate;

/**
* Sample frequency
*/
private long frequency;
private final Long frequency;

/**
* Constructs an instance with the specified peoperties.
*
* Note that any properties that are null indicate that
* the corresponding AudioFormat allows any value for
* the property.
*
* Concretely this implies that if, for example, one
* passed null for the value of frequency, this would
* mean the created AudioFormat allowed for any valid
* frequency.
*
* @param container The container for the audio
* @param codec The audio codec
* @param bigEndian If the audo data is big endian
* @param bitDepth The bit depth of the audo data
* @param bitRate The bit rate of the audio
* @param frequency The frequency at which the audio was sampled
*/
public AudioFormat(String container, String codec, Boolean bigEndian,
Integer bitDepth, Integer bitRate, Long frequency) {
super();
this.container = container;
this.codec = codec;
this.bigEndian = bigEndian;
this.bitDepth = bitDepth;
this.bitRate = bitRate;
this.frequency = frequency;
}

/**
* Gets codec
Expand All @@ -52,15 +87,6 @@ public String getCodec() {
return codec;
}

/**
* Sets codec
*
* @param codec The codec
*/
public void setCodec(String codec) {
this.codec = codec;
}

/**
* Gets container
*
Expand All @@ -70,71 +96,70 @@ public String getContainer() {
return container;
}

/**
* Sets container
*
* @param container The container
*/
public void setContainer(String container) {
this.container = container;
}

/**
* Is big endian?
*
* @return If format is big endian
* @return If format is big endian
*/
public boolean isBigEndian() {
public Boolean isBigEndian() {
return bigEndian;
}

/**
* Sets big endian
*
* @param bigEndian Sets if is big endian
*/
public void setBigEndian(boolean bigEndian) {
this.bigEndian = bigEndian;
}

/**
* Gets bit depth or bit rate depending on codec.
* Gets bit depth
*
* @see <a href="http://bit.ly/1OTydad">Bit Depth</a>
* @see <a href="http://bit.ly/1OTy5rk">Bit Rate</a>
* @return Bit depth or bit rate depending on codec
* @return Bit depth
*/
public int getBits() {
return bits;
public Integer getBitDepth() {
return bitDepth;
}

/**
* Sets bit depth or bit rate depending on codec.
* Gets bit rate
*
* @see <a href="http://bit.ly/1OTydad">Bit Depth</a>
* @see <a href="http://bit.ly/1OTy5rk">Bit Rate</a>
* @param bits Bit depth or bit rate depending on codec
* @return Bit rate
*/
public void setBits(int bits) {
this.bits = bits;
public Integer getBitRate() {
return bitRate;
}

/**
* Gets frequency
*
* @return The frequency
*/
public long getFrequency() {
public Long getFrequency() {
return frequency;
}

/**
* Sets frequency
*
* @param frequency The frequency
*/
public void setFrequency(long frequency) {
this.frequency = frequency;
/**
* Determines if the passed AudioFormat is compatable with this AudioFormat.
*
* This AudioFormat is compatible with the passed AudioFormat if both have
* the same value for all non-null members of this instance.
*/
boolean isCompatible(AudioFormat audioFormat) {
if (getContainer() && (getContainer() != audioFormat.getContainer())) {
return false;
}
if (getCodec() && (getCodec() != audioFormat.getCodec())) {
return false;
}
if (getBigEndian() && (getBigEndian() != audioFormat.getBigEndian())) {
return false;
}
if (getBitDepth() && (getBitDepth() != audioFormat.getBitDepth())) {
return false;
}
if (getBitRate() && (getBitRate() != audioFormat.getBitRate())) {
return false;
}
if (getFrequency() && (getFrequency() != audioFormat.getFrequency())) {
return false;
}
return true;
}

@Override
Expand All @@ -150,7 +175,10 @@ public boolean equals(Object obj) {
if (format.isBigEndian() != isBigEndian()) {
return false;
}
if (format.getBits() != getBits()) {
if (format.getBitDepth() != getBitDepth()) {
return false;
}
if (format.getBitRate() != getBitRate()) {
return false;
}
if (format.getFrequency() != getFrequency()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Copyright (c) 2015-2016 Harald Kuhn
*
* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -14,7 +13,7 @@
* Definition of an audio output like headphones, a speaker or for writing to
* a file / clip. Also used by TTS service.
*
* @author Harald Kuhn (hkuhn42) initial api
* @author Harald Kuhn - Initial API
*/
public interface AudioSink {
/**
Expand All @@ -23,10 +22,9 @@ public interface AudioSink {
* If the passed {@link AudioSource} has a {@link AudioFormat} not supported by this instance,
* an {@link UnsupportedAudioFormatException} is thrown.
*
* @return A boolean indicating processing started
* @throws UnsupportedAudioFormatException If audioSource format is not supported
*/
boolean process(AudioSource audioSource) throws UnsupportedAudioFormatException;
void process(AudioSource audioSource) throws UnsupportedAudioFormatException;

/**
* Gets a set containing all supported audio formats
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Copyright (c) 2015-2016 Harald Kuhn
*
* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -13,7 +12,7 @@
/**
* Wrapper for a source of audio data
*
* @author Harald Kuhn (hkuhn42) initial api
* @author Harald Kuhn - Initial API
*/
public interface AudioSource {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Copyright (c) 2015-2016 Harald Kuhn
*
* Copyright (c) 2014-2015 openHAB UG (haftungsbeschraenkt) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -12,7 +11,7 @@
* Thrown when a requested format is not supported by an {@link AudioSource}
* or {@link AudioSink} implementation
*
* @author Harald Kuhn (hkuhn42) initial api
* @author Harald Kuhn - Initial API
*/
public class UnsupportedAudioFormatException extends AudioException {

Expand Down

0 comments on commit 404a2f5

Please sign in to comment.