# v_pcma2lin

## PURPOSE

V_PCMU2LIN Convert A-law PCM to linear X=(P,M,S)

## SYNOPSIS

function x=v_pcma2lin(p,m,s)

## DESCRIPTION

    V_PCMU2LIN Convert A-law PCM to linear X=(P,M,S)
        lin = v_pcma2lin(pcma,m,s) where pcma contains a vector or matrix
        of A-law values in the range 0 to 255.
        No checking is performed to see that numbers are in this range.

        Input values are exclusive ored with m (default=85)

        Output values are divided by the scale factor s:

               s        Output Range

               1        +-4032    (integer values)
            2017.396342    +-1.998616 (default)
            4032        +-1
            4096        +-0.984375 (+-1 nominal full scale)

        The default value of s is 2017.396342 which equals
        sqrt((1120^2 + 2624^2)/2). This factor follows ITU standard G.711 and
        the sine wave with PCM-A values [225 244 244 225 97 116 116 97]
        has a mean square value of unity corresponding to 0 dBm0.

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- v_readsph V_READSPH Read a SPHERE/TIMIT format sound file [Y,FS,WRD,PHN,FFX]=(FILENAME,MODE,NMAX,NSKIP)
- v_readwav V_READWAV Read a .WAV format sound file [Y,FS,WMODE,FIDX]=(FILENAME,MODE,NMAX,NSKIP)

## SOURCE CODE

    0001 function x=v_pcma2lin(p,m,s)
    0002 %V_PCMU2LIN Convert A-law PCM to linear X=(P,M,S)
    0003 %    lin = v_pcma2lin(pcma,m,s) where pcma contains a vector or matrix
    0004 %    of A-law values in the range 0 to 255.
    0005 %    No checking is performed to see that numbers are in this range.
    0006 %
    0007 %    Input values are exclusive ored with m (default=85)
    0008 %
    0009 %    Output values are divided by the scale factor s:
    0010 %
    0011 %           s        Output Range
    0012 %
    0013 %           1        +-4032    (integer values)
    0014 %        2017.396342    +-1.998616 (default)
    0015 %        4032        +-1
    0016 %        4096        +-0.984375 (+-1 nominal full scale)
    0017 %
    0018 %    The default value of s is 2017.396342 which equals
    0019 %    sqrt((1120^2 + 2624^2)/2). This factor follows ITU standard G.711 and
    0020 %    the sine wave with PCM-A values [225 244 244 225 97 116 116 97]
    0021 %    has a mean square value of unity corresponding to 0 dBm0.
    0022
    0023
    0024
    0025 %      Copyright (C) Mike Brookes 1998
    0026 %      Version: $Id: v_pcma2lin.m 10865 2018-09-21 17:22:45Z dmb $
    0027 %
    0028 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0029 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0030 %
    0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0032 %   This program is free software; you can redistribute it and/or modify
    0033 %   it under the terms of the GNU Lesser General Public License as published by
    0034 %   the Free Software Foundation; either version 3 of the License, or
    0035 %   (at your option) any later version.
    0036 %
    0037 %   This program is distributed in the hope that it will be useful,
    0038 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0039 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0040 %   GNU Lesser General Public License for more details.
    0041 %
    0042 %   You can obtain a copy of the GNU Lesser General Public License from
    0043 %   https://www.gnu.org/licenses/ .
    0044 %
    0045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0046
    0047 if nargin<3
    0048   t=4.95688418E-4;
    0049   if nargin<2 m=85; end
    0050 else
    0051   t=1/s;
    0052 end
    0053
    0054 if m q=bitxor(p,m); else q=p; end;
    0055 k=rem(q,16);
    0056 g=floor(q/128);
    0057 e=(q-k-128*g)/16;
    0058 f=(abs(e-1)-e+1)/2;
    0059 x=(2*g-1).*(pow2(k+16.5,e)+f.*(k-15.5))*t;