* reading or pre- processing.
*/
private double[] preProcessRecording(File recordingFile) throws Exception {
// Get the original audio and its format
AudioInputStream originalStream = AudioSystem.getAudioInputStream(recordingFile);
AudioFormat originalFormat = originalStream.getFormat();
// Set the bit depth
int bitDepth = originalFormat.getSampleSizeInBits();
if (bitDepth != 8 && bitDepth != 16) {
bitDepth = 16;
}
// If the audio is not PCM signed big endian, then convert it to PCM
// signed
// This is particularly necessary when dealing with MP3s
AudioInputStream secondStream = originalStream;
if (originalFormat.getEncoding() != AudioFormat.Encoding.PCM_SIGNED || !originalFormat.isBigEndian()) {
AudioFormat newFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
originalFormat.getSampleRate(),
bitDepth,
originalFormat.getChannels(),
originalFormat.getChannels() * (bitDepth / 8),
originalFormat.getSampleRate(),
true);
secondStream = AudioSystem.getAudioInputStream(newFormat, originalStream);
}
// Convert to the set sampling rate, if it is not already at this
// sampling rate.
// Also, convert to an appropriate bit depth if necessary.
AudioInputStream newStream = secondStream;
if (originalFormat.getSampleRate() != settings.getSamplingRate().floatValue()
|| bitDepth != originalFormat.getSampleSizeInBits() ) {
AudioFormat newFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
settings.getSamplingRate().floatValue(),
bitDepth,
originalFormat.getChannels(),
originalFormat.getChannels() * (bitDepth / 8),