annotate at/ofai/music/audio/Convert.java @ 5:bcb4c9697967 tip

Add README and CITATION files
author Chris Cannam
date Tue, 03 Dec 2013 12:58:05 +0000
parents 4c3f5bc01c97
children
rev   line source
Chris@2 1 /*
Chris@2 2 Copyright (C) 2001, 2006 by Simon Dixon
Chris@2 3
Chris@2 4 This program is free software; you can redistribute it and/or modify
Chris@2 5 it under the terms of the GNU General Public License as published by
Chris@2 6 the Free Software Foundation; either version 2 of the License, or
Chris@2 7 (at your option) any later version.
Chris@2 8
Chris@2 9 This program is distributed in the hope that it will be useful,
Chris@2 10 but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@2 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@2 12 GNU General Public License for more details.
Chris@2 13
Chris@2 14 You should have received a copy of the GNU General Public License along
Chris@2 15 with this program (the file gpl.txt); if not, download it from
Chris@2 16 http://www.gnu.org/licenses/gpl.txt or write to the
Chris@2 17 Free Software Foundation, Inc.,
Chris@2 18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Chris@2 19 */
Chris@2 20
Chris@2 21 package at.ofai.music.audio;
Chris@2 22
Chris@2 23 public class Convert {
Chris@2 24
Chris@2 25 public static void monoShortToInt(byte[] in, int[] out,boolean isBigEndian){
Chris@2 26 monoShortToInt(in, 0, in.length, out, 0, isBigEndian);
Chris@2 27 } // monoShortToInt()/3
Chris@2 28
Chris@2 29 public static void monoShortToInt(byte[] in, int inIndex, int bytes,
Chris@2 30 int[] out, int outIndex, boolean isBigEndian){
Chris@2 31 if (isBigEndian)
Chris@2 32 for ( ; inIndex < bytes; inIndex += 2)
Chris@2 33 out[outIndex++] = (in[inIndex+1] & 0xff) | (in[inIndex] << 8);
Chris@2 34 else
Chris@2 35 for ( ; inIndex < bytes; inIndex += 2)
Chris@2 36 out[outIndex++] = (in[inIndex] & 0xff) | (in[inIndex+1] << 8);
Chris@2 37 } // monoShortToInt()
Chris@2 38
Chris@2 39 public static void monoShortToDouble(byte[] in, double[] out,
Chris@2 40 boolean isBigEndian) {
Chris@2 41 int j = 0;
Chris@2 42 if (isBigEndian)
Chris@2 43 for (int i = 0; i < in.length; i += 2)
Chris@2 44 out[j++] = ((in[i+1] & 0xff) | (in[i] << 8)) / 32768.0;
Chris@2 45 else
Chris@2 46 for (int i = 0; i < in.length; i += 2)
Chris@2 47 out[j++] = ((in[i] & 0xff) | (in[i+1] << 8)) / 32768.0;
Chris@2 48 } // monoShortToDouble()
Chris@2 49
Chris@2 50 } // class Convert