split Audio Bytes - Java javax.sound.sampled

Java examples for javax.sound.sampled:Audio

Description

split Audio Bytes

Demo Code


//package com.java2s;

import java.util.Arrays;

public class Main {

    public static byte[] splitAudioBytes(byte[] source,
            int audioSampleSizeInBits, double fromTimeMillis,
            double toTimeMillis, double totalLengthMillis) {
        int sampleSizeInBytes = audioSampleSizeInBits / 8;
        int divisionPointFrom = (int) Math
                .floor((fromTimeMillis * source.length) / totalLengthMillis);
        int divisionPointTo = (int) Math
                .floor((toTimeMillis * source.length) / totalLengthMillis);
        divisionPointFrom += divisionPointFrom % sampleSizeInBytes;
        divisionPointTo += divisionPointTo % sampleSizeInBytes;
        return Arrays.copyOfRange(source, divisionPointFrom,
                divisionPointTo);//from ww  w.j  a va2  s  . co m
    }
}

Related Tutorials