Example usage for java.lang Short SIZE

List of usage examples for java.lang Short SIZE

Introduction

In this page you can find the example usage for java.lang Short SIZE.

Prototype

int SIZE

To view the source code for java.lang Short SIZE.

Click Source Link

Document

The number of bits used to represent a short value in two's complement binary form.

Usage

From source file:org.cellprofiler.subimager.ImageWriterHandler.java

private byte[] convertImage(NDImage ndimage, PixelType pixelType, boolean toBigEndian) {
    double[] inputDouble = ndimage.getBuffer();
    switch (pixelType) {
    case INT8://w  w w  .  j a va2  s  .c o  m
        return convertToIntegerType(inputDouble, Byte.MIN_VALUE, Byte.MAX_VALUE, Byte.SIZE / 8, toBigEndian);
    case UINT8:
        return convertToIntegerType(inputDouble, 0, (1L << Byte.SIZE) - 1, Byte.SIZE / 8, toBigEndian);
    case INT16:
        return convertToIntegerType(inputDouble, Short.MIN_VALUE, Short.MAX_VALUE, Short.SIZE / 8, toBigEndian);
    case UINT16:
        return convertToIntegerType(inputDouble, 0, (1L << Short.SIZE) - 1, Short.SIZE / 8, toBigEndian);
    case INT32:
        return convertToIntegerType(inputDouble, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.SIZE / 8,
                toBigEndian);
    case UINT32:
        return convertToIntegerType(inputDouble, 0, (1L << Integer.SIZE) - 1, Integer.SIZE / 8, toBigEndian);
    case FLOAT: {
        int bpp = Float.SIZE / 8;
        byte[] buffer = new byte[inputDouble.length * bpp];
        for (int i = 0; i < inputDouble.length; i++) {
            DataTools.unpackBytes(Float.floatToIntBits((float) inputDouble[i]), buffer, i * bpp, bpp,
                    !toBigEndian);
        }
        return buffer;
    }
    case DOUBLE: {
        int bpp = Double.SIZE / 8;
        byte[] buffer = new byte[inputDouble.length * bpp];
        for (int i = 0; i < inputDouble.length; i++) {
            DataTools.unpackBytes(Double.doubleToLongBits(inputDouble[i]), buffer, i * bpp, bpp, !toBigEndian);
        }
        return buffer;
    }
    default:
        throw new UnsupportedOperationException("The pixel type, " + pixelType.getValue()
                + ", should have been explicitly handled by the caller and an error should have been reported to the web client.");
    }
}

From source file:org.noise_planet.noisecapture.CalibrationLinearityActivity.java

private void playNewTrack() {

    double rms = dbToRms(99 - (splLoop++) * DB_STEP);
    short[] data = makeWhiteNoiseSignal(44100, rms);
    double[] fftCenterFreq = FFTSignalProcessing
            .computeFFTCenterFrequency(AudioProcess.REALTIME_SAMPLE_RATE_LIMITATION);
    FFTSignalProcessing fftSignalProcessing = new FFTSignalProcessing(44100, fftCenterFreq, 44100);
    fftSignalProcessing.addSample(data);
    whiteNoisedB = fftSignalProcessing.computeGlobalLeq();
    freqLeqStats.add(new LinearCalibrationResult(fftSignalProcessing.processSample(true, false, false)));
    LOGGER.info("Emit white noise of " + whiteNoisedB + " dB");
    if (audioTrack == null) {
        audioTrack = new AudioTrack(getAudioOutput(), 44100, AudioFormat.CHANNEL_OUT_MONO,
                AudioFormat.ENCODING_PCM_16BIT, data.length * (Short.SIZE / 8), AudioTrack.MODE_STATIC);
    } else {//from   w  ww . j  a v a  2  s  .c  om
        try {
            audioTrack.pause();
            audioTrack.flush();
        } catch (IllegalStateException ex) {
            // Ignore
        }
    }
    audioTrack.setLoopPoints(0, audioTrack.write(data, 0, data.length), -1);
    audioTrack.play();
}

From source file:org.eclipse.dataset.AbstractDataset.java

/**
 * @param dtype//from www.j a  v  a 2s .  co  m
 * @param isize
 *            number of elements in an item
 * @return length of single item in bytes
 */
public static int getItemsize(final int dtype, final int isize) {
    int size;

    switch (dtype) {
    case BOOL:
        size = 1; // How is this defined?
        break;
    case INT8:
    case ARRAYINT8:
        size = Byte.SIZE / 8;
        break;
    case INT16:
    case ARRAYINT16:
    case RGB:
        size = Short.SIZE / 8;
        break;
    case INT32:
    case ARRAYINT32:
        size = Integer.SIZE / 8;
        break;
    case INT64:
    case ARRAYINT64:
        size = Long.SIZE / 8;
        break;
    case FLOAT32:
    case ARRAYFLOAT32:
    case COMPLEX64:
        size = Float.SIZE / 8;
        break;
    case FLOAT64:
    case ARRAYFLOAT64:
    case COMPLEX128:
        size = Double.SIZE / 8;
        break;
    default:
        size = 0;
        break;
    }

    return size * isize;
}