Package org.asteriskjava.iax.util

Examples of org.asteriskjava.iax.util.ByteBuffer


    @Override
    public void convertFromLin(byte[] in, byte[] out) {

        short[] sbuff = new short[160];

        ByteBuffer bb = ByteBuffer.wrap(in);
        for (int i = 0; i < in.length / 2; i++) {
            short s = bb.getShort();
            sbuff[i] = s;
        }

        encoder.encode(sbuff, out);
View Full Code Here


     * @param in  Description of Parameter
     * @param out Description of Parameter
     */
    @Override
    public void convertFromLin(byte[] in, byte[] out) {
        ByteBuffer bb = ByteBuffer.wrap(in);
        for (int i = 0; i < in.length / 2; i++) {
            short s = bb.getShort();
            out[i] = linear2alaw(s);
        }
    }
View Full Code Here

     *
     * @param in  byte[]
     * @param out byte[]
     */
    public static void convert(byte[] in, byte[] out) {
        ByteBuffer bb = ByteBuffer.wrap(out);
        for (int i = 0; i < in.length; i++) {
            short s = alaw2linear(in[i]);
            bb.putShort(s);
        }
    }
View Full Code Here

        convert(in, out);
    }

    @Override
    public void convertFromLin(byte[] in, byte[] out) {
        ByteBuffer bb = ByteBuffer.wrap(in);
        for (int i = 0; i < out.length; i++) {
            short s = bb.getShort();
            out[i] = linear2ulaw(s);
        }
    }
View Full Code Here

     *
     * @param in  byte[]
     * @param out byte[]
     */
    public static void convert(byte[] in, byte[] out) {
        ByteBuffer bb = ByteBuffer.wrap(out);
        for (int i = 0; i < in.length; i++) {
            short s = ulaw2linear(in[i]);
            bb.putShort(s);
        }
    }
View Full Code Here

    private void initRingback() {
        // from indications.conf 440+480/2000,0/4000
        double rat2 = 420.0 / 8000.0;
        double rat1 = 25.0 / 8000.0;
        int num = this.getSampSz();
        ByteBuffer rbb = ByteBuffer.allocate(num);

        for (int i = 0; i < 160; i++) {

            short s = (short) ((Short.MAX_VALUE / 16) * (Math.sin(2.0 * Math.PI * rat1 * i) * Math.sin(4.0 * Math.PI * rat2 * i)));
            rbb.putShort(s);
        }
        _ring = rbb.array();
        _silence = new byte[num];
    }
View Full Code Here

            }
        } else {
            // we assume that it is 44k1 stereo 16 bit and down sample
            // nothing clever - no anti alias etc....

            ByteBuffer bbs = ByteBuffer.wrap(s);
            ByteBuffer bbd = ByteBuffer.wrap(d);
            // iterate over the values we have,
            // add them to the taget bucket they fall into
            // and count the drops....
            int drange = d.length / 2;
            double v[] = new double[drange];
            double w[] = new double[drange];

            double rat = 8000.0 / 44100.0;
            int top = s.length / 2;
            for (int eo = 0; eo < top; eo++) {
                int samp = (int) Math.floor(eo * rat);
                if (samp >= drange) {
                    samp = drange - 1;
                }
                v[samp] += bbs.getShort(eo * 2);
                w[samp]++;
            }
            // now reweight the samples to ensure
            // no volume quirks
            // and move to short
            short vw = 0;
            for (int ei = 0; ei < drange; ei++) {
                if (w[ei] != 0) {
                    vw = (short) (v[ei] / w[ei]);
                }
                bbd.putShort(ei * 2, vw);
            }
        }
    }
View Full Code Here

    public void SendHold() {


        _subclass = ControlFrame.HOLD;
        _data = new ByteBuffer();


        sendMe(ControlFrame.EMPTY);

        Log.debug("Sending Hold");
View Full Code Here

     * @throws IllegalArgumentException The bytes do not represent a
     *                                  fullframe
     */
    public FullFrame(Call call, byte[] bs)
            throws IllegalArgumentException {
        ByteBuffer buf = ByteBuffer.wrap(bs);
        _sCall = buf.getShort();
        if (_sCall < 0) {
            _sCall = 0x7fff & _sCall;
            _fullBit = true;
        } else {
            _fullBit = false;
            throw new IllegalArgumentException("Not a fullframe, but miniframe.");
        }
        _dCall = buf.getShort();
        if (_dCall < 0) {
            _dCall = 0x7fff & _dCall;
            _retry = true;
        }
        long tst = buf.getInt();
        tst = (tst < 1) ? tst + 0x100000000L : tst;
        setTimestampVal(tst);
        _oseq = tint(buf.get());
        _iseq = tint(buf.get());
        _frametype = buf.get();
        _subclass = buf.get();
        if (_subclass < 0) {
            _subclass = 1 << (_subclass & 0x7f);
            _cbit = true;
        }
        _data = buf.slice();
        _call = call;
    }
View Full Code Here

     * Sends this object with the specified IE.
     *
     * @param ie The IE
     */
    void sendMe(InfoElement ie) {
        ByteBuffer buff = ByteBuffer.allocate(2048);
        buff.putChar((char) (0x8000 | _sCall));
        int rd = _dCall;
        if (_retry) {
            rd |= 0x8000;
        }
        buff.putChar((char) rd);
        long tst = this.getTimestampVal();
        tst = ((0x100000000L & tst) > 0) ? tst - 0x100000000L : tst;
        buff.putInt((int) tst);
        buff.put((byte) _oseq);
        buff.put((byte) _iseq);
        buff.put((byte) _frametype);
        int sc = _subclass;
        if (_cbit) {
            sc |= 0x80;
        }
        buff.put((byte) sc);
        if (ie != null) {
            ie.update(buff);
        }
        sendAndStore(buff);
    }
View Full Code Here

TOP

Related Classes of org.asteriskjava.iax.util.ByteBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.