Python Code Clones

This page shows the identified clones for Python. These clones may also be downloaded in .xlsx, html and .csv format here.
The source code of each clone may be viewed on by clicking each method group.

  • 
    static PyObject *
    audioop_alaw2lin(PyObject *self, PyObject *args)
    {
            unsigned char *cp;
            unsigned char cval;
            signed char *ncp;
            int len, size, val;
            PyObject *rv;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#i:alaw2lin"",
                                   &cp, &len, &size) )
                    return 0;
    
            if ( size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len*size);
            if ( rv == 0 )
                    return 0;
            ncp = (signed char *)PyString_AsString(rv);
        
            for ( i=0; i < len*size; i += size ) {
                    cval = *cp++;
                    val = st_alaw2linear16(cval);
            
                    if ( size == 1 )      *CHARP(ncp, i) = (signed char)(val >> 8);
                    else if ( size == 2 ) *SHORTP(ncp, i) = (short)(val);
                    else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)(val<<16);
            }
            return rv;
    }
    
    
    static PyObject *
    audioop_reverse(PyObject *self, PyObject *args)
    {
            signed char *cp;
            unsigned char *ncp;
            int len, size, val = 0;
            PyObject *rv;
            int i, j;
    
            if ( !PyArg_ParseTuple(args, ""s#i:reverse"",
                              &cp, &len, &size) )
                    return 0;
    
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len);
            if ( rv == 0 )
                    return 0;
            ncp = (unsigned char *)PyString_AsString(rv);
        
            for ( i=0; i < len; i += size ) {
                    if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16;
    
                    j = len - i - size;
            
                    if ( size == 1 )      *CHARP(ncp, j) = (signed char)(val >> 8);
                    else if ( size == 2 ) *SHORTP(ncp, j) = (short)(val);
                    else if ( size == 4 ) *LONGP(ncp, j) = (Py_Int32)(val<<16);
            }
            return rv;
    }
    
  • 
    static PyObject *
    audioop_rms(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
            double sum_squares = 0.0;
    
            if ( !PyArg_ParseTuple(args, ""s#i:rms"", &cp, &len, &size) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            for ( i=0; i
    
    static PyObject *
    audioop_max(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
            int max = 0;
    
            if ( !PyArg_ParseTuple(args, ""s#i:max"", &cp, &len, &size) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            for ( i=0; i max ) max = val;
            }
            return PyInt_FromLong(max);
    }
    
  • 
    static PyObject *
    audioop_maxpp(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0, prevval = 0, prevextremevalid = 0,
                    prevextreme = 0;
            int i;
            int max = 0;
            int diff, prevdiff, extremediff;
    
            if ( !PyArg_ParseTuple(args, ""s#i:maxpp"", &cp, &len, &size) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            /* Compute first delta value ahead. Also automatically makes us
            ** skip the first extreme value
            */
            if ( size == 1 )      prevval = (int)*CHARP(cp, 0);
            else if ( size == 2 ) prevval = (int)*SHORTP(cp, 0);
            else if ( size == 4 ) prevval = (int)*LONGP(cp, 0);
            if ( size == 1 )      val = (int)*CHARP(cp, size);
            else if ( size == 2 ) val = (int)*SHORTP(cp, size);
            else if ( size == 4 ) val = (int)*LONGP(cp, size);
            prevdiff = val - prevval;
    
            for ( i=size; i max )
                                            max = extremediff;
                            }
                            prevextremevalid = 1;
                            prevextreme = prevval;
                    }
                    prevval = val;
                    if ( diff != 0 )
                            prevdiff = diff;
            }
            return PyInt_FromLong(max);
    }
    
    
    
    
    static PyObject *
    audioop_avgpp(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0, prevval = 0, prevextremevalid = 0,
                    prevextreme = 0;
            int i;
            double avg = 0.0;
            int diff, prevdiff, extremediff, nextreme = 0;
    
            if ( !PyArg_ParseTuple(args, ""s#i:avgpp"", &cp, &len, &size) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            /* Compute first delta value ahead. Also automatically makes us
            ** skip the first extreme value
            */
            if ( size == 1 )      prevval = (int)*CHARP(cp, 0);
            else if ( size == 2 ) prevval = (int)*SHORTP(cp, 0);
            else if ( size == 4 ) prevval = (int)*LONGP(cp, 0);
            if ( size == 1 )      val = (int)*CHARP(cp, size);
            else if ( size == 2 ) val = (int)*SHORTP(cp, size);
            else if ( size == 4 ) val = (int)*LONGP(cp, size);
            prevdiff = val - prevval;
        
            for ( i=size; i
  • 
    static PyObject *
    audioop_avg(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
            double avg = 0.0;
    
            if ( !PyArg_ParseTuple(args, ""s#i:avg"", &cp, &len, &size) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            for ( i=0; i
    
    static PyObject *
    audioop_minmax(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
            int min = 0x7fffffff, max = -0x7fffffff;
    
            if (!PyArg_ParseTuple(args, ""s#i:minmax"", &cp, &len, &size))
                    return NULL;
            if (size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return NULL;
            }
            for (i = 0; i < len; i += size) {
                    if (size == 1) val = (int) *CHARP(cp, i);
                    else if (size == 2) val = (int) *SHORTP(cp, i);
                    else if (size == 4) val = (int) *LONGP(cp, i);
                    if (val > max) max = val;
                    if (val < min) min = val;
            }
            return Py_BuildValue(""(ii)"", min, max);
    }
    
  • 
    static PyObject *
    audioop_avg(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
            double avg = 0.0;
    
            if ( !PyArg_ParseTuple(args, ""s#i:avg"", &cp, &len, &size) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            for ( i=0; i
    
    static PyObject *
    audioop_max(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
            int max = 0;
    
            if ( !PyArg_ParseTuple(args, ""s#i:max"", &cp, &len, &size) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            for ( i=0; i max ) max = val;
            }
            return PyInt_FromLong(max);
    }
    
  • 
    static Py_complex
    c_acosh(Py_complex x)
    {
     Py_complex z;
     z = c_sqrt(c_half);
     z = c_log(c_prod(z, c_sum(c_sqrt(c_sum(x,c_one)),
          c_sqrt(c_diff(x,c_one)))));
     return c_sum(z, z);
    }
    
    PyDoc_STRVAR(c_acosh_doc,
    ""acosh(x)\n""
    ""\n""
    ""Return the hyperbolic arccosine of x."");
    
    
    static Py_complex
    c_atanh(Py_complex x)
    {
     return c_prod(c_half,c_log(c_quot(c_sum(c_one,x),c_diff(c_one,x))));
    }
    
    PyDoc_STRVAR(c_atanh_doc,
    ""atanh(x)\n""
    ""\n""
    ""Return the hyperbolic arc tangent of x."");
    
    
  • 
    static PyObject *
    audioop_bias(PyObject *self, PyObject *args)
    {
            signed char *cp, *ncp;
            int len, size, val = 0;
            PyObject *rv;
            int i;
            int bias;
    
            if ( !PyArg_ParseTuple(args, ""s#ii:bias"",
                              &cp, &len, &size , &bias) )
                    return 0;
    
            if ( size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len);
            if ( rv == 0 )
                    return 0;
            ncp = (signed char *)PyString_AsString(rv);
        
        
            for ( i=0; i < len; i += size ) {
                    if ( size == 1 )      val = (int)*CHARP(cp, i);
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = (int)*LONGP(cp, i);
            
                    if ( size == 1 )      *CHARP(ncp, i) = (signed char)(val+bias);
                    else if ( size == 2 ) *SHORTP(ncp, i) = (short)(val+bias);
                    else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)(val+bias);
            }
            return rv;
    }
    
    
    static PyObject *
    audioop_ulaw2lin(PyObject *self, PyObject *args)
    {
            unsigned char *cp;
            unsigned char cval;
            signed char *ncp;
            int len, size, val;
            PyObject *rv;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#i:ulaw2lin"",
                                   &cp, &len, &size) )
                    return 0;
    
            if ( size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len*size);
            if ( rv == 0 )
                    return 0;
            ncp = (signed char *)PyString_AsString(rv);
        
            for ( i=0; i < len*size; i += size ) {
                    cval = *cp++;
                    val = st_ulaw2linear16(cval);
            
                    if ( size == 1 )      *CHARP(ncp, i) = (signed char)(val >> 8);
                    else if ( size == 2 ) *SHORTP(ncp, i) = (short)(val);
                    else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)(val<<16);
            }
            return rv;
    }
    
  • 
    static PyObject *
    audioop_mul(PyObject *self, PyObject *args)
    {
            signed char *cp, *ncp;
            int len, size, val = 0;
            double factor, fval, maxval;
            PyObject *rv;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#id:mul"", &cp, &len, &size, &factor ) )
                    return 0;
        
            if ( size == 1 ) maxval = (double) 0x7f;
            else if ( size == 2 ) maxval = (double) 0x7fff;
            else if ( size == 4 ) maxval = (double) 0x7fffffff;
            else {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len);
            if ( rv == 0 )
                    return 0;
            ncp = (signed char *)PyString_AsString(rv);
        
        
            for ( i=0; i < len; i += size ) {
                    if ( size == 1 )      val = (int)*CHARP(cp, i);
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = (int)*LONGP(cp, i);
                    fval = (double)val*factor;
                    if ( fval > maxval ) fval = maxval;
                    else if ( fval < -maxval ) fval = -maxval;
                    val = (int)fval;
                    if ( size == 1 )      *CHARP(ncp, i) = (signed char)val;
                    else if ( size == 2 ) *SHORTP(ncp, i) = (short)val;
                    else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)val;
            }
            return rv;
    }
    
    
    
    
    static PyObject *
    audioop_reverse(PyObject *self, PyObject *args)
    {
            signed char *cp;
            unsigned char *ncp;
            int len, size, val = 0;
            PyObject *rv;
            int i, j;
    
            if ( !PyArg_ParseTuple(args, ""s#i:reverse"",
                              &cp, &len, &size) )
                    return 0;
    
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len);
            if ( rv == 0 )
                    return 0;
            ncp = (unsigned char *)PyString_AsString(rv);
        
            for ( i=0; i < len; i += size ) {
                    if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16;
    
                    j = len - i - size;
            
                    if ( size == 1 )      *CHARP(ncp, j) = (signed char)(val >> 8);
                    else if ( size == 2 ) *SHORTP(ncp, j) = (short)(val);
                    else if ( size == 4 ) *LONGP(ncp, j) = (Py_Int32)(val<<16);
            }
            return rv;
    }
    
  • 
    static PyObject *
    audioop_lin2alaw(PyObject *self, PyObject *args)
    {
            signed char *cp;
            unsigned char *ncp;
            int len, size, val = 0;
            PyObject *rv;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#i:lin2alaw"",
                                   &cp, &len, &size) )
                    return 0;
    
            if ( size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len/size);
            if ( rv == 0 )
                    return 0;
            ncp = (unsigned char *)PyString_AsString(rv);
        
            for ( i=0; i < len; i += size ) {
                    if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16;
    
                    *ncp++ = st_linear2alaw(val);
            }
            return rv;
    }
    
    
    static PyObject *
    audioop_reverse(PyObject *self, PyObject *args)
    {
            signed char *cp;
            unsigned char *ncp;
            int len, size, val = 0;
            PyObject *rv;
            int i, j;
    
            if ( !PyArg_ParseTuple(args, ""s#i:reverse"",
                              &cp, &len, &size) )
                    return 0;
    
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len);
            if ( rv == 0 )
                    return 0;
            ncp = (unsigned char *)PyString_AsString(rv);
        
            for ( i=0; i < len; i += size ) {
                    if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16;
    
                    j = len - i - size;
            
                    if ( size == 1 )      *CHARP(ncp, j) = (signed char)(val >> 8);
                    else if ( size == 2 ) *SHORTP(ncp, j) = (short)(val);
                    else if ( size == 4 ) *LONGP(ncp, j) = (Py_Int32)(val<<16);
            }
            return rv;
    }
    
  • 
    static PyObject *
    audioop_tomono(PyObject *self, PyObject *args)
    {
            signed char *cp, *ncp;
            int len, size, val1 = 0, val2 = 0;
            double fac1, fac2, fval, maxval;
            PyObject *rv;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#idd:tomono"",
                            &cp, &len, &size, &fac1, &fac2 ) )
                    return 0;
        
            if ( size == 1 ) maxval = (double) 0x7f;
            else if ( size == 2 ) maxval = (double) 0x7fff;
            else if ( size == 4 ) maxval = (double) 0x7fffffff;
            else {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len/2);
            if ( rv == 0 )
                    return 0;
            ncp = (signed char *)PyString_AsString(rv);
        
        
            for ( i=0; i < len; i += size*2 ) {
                    if ( size == 1 )      val1 = (int)*CHARP(cp, i);
                    else if ( size == 2 ) val1 = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val1 = (int)*LONGP(cp, i);
                    if ( size == 1 )      val2 = (int)*CHARP(cp, i+1);
                    else if ( size == 2 ) val2 = (int)*SHORTP(cp, i+2);
                    else if ( size == 4 ) val2 = (int)*LONGP(cp, i+4);
                    fval = (double)val1*fac1 + (double)val2*fac2;
                    if ( fval > maxval ) fval = maxval;
                    else if ( fval < -maxval ) fval = -maxval;
                    val1 = (int)fval;
                    if ( size == 1 )      *CHARP(ncp, i/2) = (signed char)val1;
                    else if ( size == 2 ) *SHORTP(ncp, i/2) = (short)val1;
                    else if ( size == 4 ) *LONGP(ncp, i/2)= (Py_Int32)val1;
            }
            return rv;
    }
    
    
    static PyObject *
    audioop_mul(PyObject *self, PyObject *args)
    {
            signed char *cp, *ncp;
            int len, size, val = 0;
            double factor, fval, maxval;
            PyObject *rv;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#id:mul"", &cp, &len, &size, &factor ) )
                    return 0;
        
            if ( size == 1 ) maxval = (double) 0x7f;
            else if ( size == 2 ) maxval = (double) 0x7fff;
            else if ( size == 4 ) maxval = (double) 0x7fffffff;
            else {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len);
            if ( rv == 0 )
                    return 0;
            ncp = (signed char *)PyString_AsString(rv);
        
        
            for ( i=0; i < len; i += size ) {
                    if ( size == 1 )      val = (int)*CHARP(cp, i);
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = (int)*LONGP(cp, i);
                    fval = (double)val*factor;
                    if ( fval > maxval ) fval = maxval;
                    else if ( fval < -maxval ) fval = -maxval;
                    val = (int)fval;
                    if ( size == 1 )      *CHARP(ncp, i) = (signed char)val;
                    else if ( size == 2 ) *SHORTP(ncp, i) = (short)val;
                    else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)val;
            }
            return rv;
    }
    
    
    
    
  • 
    static PyObject *
    audioop_lin2ulaw(PyObject *self, PyObject *args)
    {
            signed char *cp;
            unsigned char *ncp;
            int len, size, val = 0;
            PyObject *rv;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#i:lin2ulaw"",
                                   &cp, &len, &size) )
                    return 0 ;
    
            if ( size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len/size);
            if ( rv == 0 )
                    return 0;
            ncp = (unsigned char *)PyString_AsString(rv);
        
            for ( i=0; i < len; i += size ) {
                    if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16;
    
                    *ncp++ = st_14linear2ulaw(val);
            }
            return rv;
    }
    
    
    static PyObject *
    audioop_lin2lin(PyObject *self, PyObject *args)
    {
            signed char *cp;
            unsigned char *ncp;
            int len, size, size2, val = 0;
            PyObject *rv;
            int i, j;
    
            if ( !PyArg_ParseTuple(args, ""s#ii:lin2lin"",
                              &cp, &len, &size, &size2) )
                    return 0;
    
            if ( (size != 1 && size != 2 && size != 4) ||
                 (size2 != 1 && size2 != 2 && size2 != 4)) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, (len/size)*size2);
            if ( rv == 0 )
                    return 0;
            ncp = (unsigned char *)PyString_AsString(rv);
        
            for ( i=0, j=0; i < len; i += size, j += size2 ) {
                    if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16;
    
                    if ( size2 == 1 )  *CHARP(ncp, j) = (signed char)(val >> 8);
                    else if ( size2 == 2 ) *SHORTP(ncp, j) = (short)(val);
                    else if ( size2 == 4 ) *LONGP(ncp, j) = (Py_Int32)(val<<16);
            }
            return rv;
    }
    
    
  • 
    static PyObject *
    audioop_lin2ulaw(PyObject *self, PyObject *args)
    {
            signed char *cp;
            unsigned char *ncp;
            int len, size, val = 0;
            PyObject *rv;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#i:lin2ulaw"",
                                   &cp, &len, &size) )
                    return 0 ;
    
            if ( size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len/size);
            if ( rv == 0 )
                    return 0;
            ncp = (unsigned char *)PyString_AsString(rv);
        
            for ( i=0; i < len; i += size ) {
                    if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16;
    
                    *ncp++ = st_14linear2ulaw(val);
            }
            return rv;
    }
    
    
    static PyObject *
    audioop_minmax(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
            int min = 0x7fffffff, max = -0x7fffffff;
    
            if (!PyArg_ParseTuple(args, ""s#i:minmax"", &cp, &len, &size))
                    return NULL;
            if (size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return NULL;
            }
            for (i = 0; i < len; i += size) {
                    if (size == 1) val = (int) *CHARP(cp, i);
                    else if (size == 2) val = (int) *SHORTP(cp, i);
                    else if (size == 4) val = (int) *LONGP(cp, i);
                    if (val > max) max = val;
                    if (val < min) min = val;
            }
            return Py_BuildValue(""(ii)"", min, max);
    }
    
  • 
    static PyObject *
    audioop_getsample(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#ii:getsample"", &cp, &len, &size, &i) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            if ( i < 0 || i >= len/size ) {
                    PyErr_SetString(AudioopError, ""Index out of range"");
                    return 0;
            }
            if ( size == 1 )      val = (int)*CHARP(cp, i);
            else if ( size == 2 ) val = (int)*SHORTP(cp, i*2);
            else if ( size == 4 ) val = (int)*LONGP(cp, i*4);
            return PyInt_FromLong(val);
    }
    
    
    static PyObject *
    audioop_minmax(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
            int min = 0x7fffffff, max = -0x7fffffff;
    
            if (!PyArg_ParseTuple(args, ""s#i:minmax"", &cp, &len, &size))
                    return NULL;
            if (size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return NULL;
            }
            for (i = 0; i < len; i += size) {
                    if (size == 1) val = (int) *CHARP(cp, i);
                    else if (size == 2) val = (int) *SHORTP(cp, i);
                    else if (size == 4) val = (int) *LONGP(cp, i);
                    if (val > max) max = val;
                    if (val < min) min = val;
            }
            return Py_BuildValue(""(ii)"", min, max);
    }
    
  • 
    static PyObject *
    audioop_ulaw2lin(PyObject *self, PyObject *args)
    {
            unsigned char *cp;
            unsigned char cval;
            signed char *ncp;
            int len, size, val;
            PyObject *rv;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#i:ulaw2lin"",
                                   &cp, &len, &size) )
                    return 0;
    
            if ( size != 1 && size != 2 && size != 4) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, len*size);
            if ( rv == 0 )
                    return 0;
            ncp = (signed char *)PyString_AsString(rv);
        
            for ( i=0; i < len*size; i += size ) {
                    cval = *cp++;
                    val = st_ulaw2linear16(cval);
            
                    if ( size == 1 )      *CHARP(ncp, i) = (signed char)(val >> 8);
                    else if ( size == 2 ) *SHORTP(ncp, i) = (short)(val);
                    else if ( size == 4 ) *LONGP(ncp, i) = (Py_Int32)(val<<16);
            }
            return rv;
    }
    
    
    static PyObject *
    audioop_lin2lin(PyObject *self, PyObject *args)
    {
            signed char *cp;
            unsigned char *ncp;
            int len, size, size2, val = 0;
            PyObject *rv;
            int i, j;
    
            if ( !PyArg_ParseTuple(args, ""s#ii:lin2lin"",
                              &cp, &len, &size, &size2) )
                    return 0;
    
            if ( (size != 1 && size != 2 && size != 4) ||
                 (size2 != 1 && size2 != 2 && size2 != 4)) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
        
            rv = PyString_FromStringAndSize(NULL, (len/size)*size2);
            if ( rv == 0 )
                    return 0;
            ncp = (unsigned char *)PyString_AsString(rv);
        
            for ( i=0, j=0; i < len; i += size, j += size2 ) {
                    if ( size == 1 )      val = ((int)*CHARP(cp, i)) << 8;
                    else if ( size == 2 ) val = (int)*SHORTP(cp, i);
                    else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16;
    
                    if ( size2 == 1 )  *CHARP(ncp, j) = (signed char)(val >> 8);
                    else if ( size2 == 2 ) *SHORTP(ncp, j) = (short)(val);
                    else if ( size2 == 4 ) *LONGP(ncp, j) = (Py_Int32)(val<<16);
            }
            return rv;
    }
    
  • 
    static PyObject *
    audioop_avg(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
            double avg = 0.0;
    
            if ( !PyArg_ParseTuple(args, ""s#i:avg"", &cp, &len, &size) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            for ( i=0; i
    
    static PyObject *
    audioop_getsample(PyObject *self, PyObject *args)
    {
            signed char *cp;
            int len, size, val = 0;
            int i;
    
            if ( !PyArg_ParseTuple(args, ""s#ii:getsample"", &cp, &len, &size, &i) )
                    return 0;
            if ( size != 1 && size != 2 && size != 4 ) {
                    PyErr_SetString(AudioopError, ""Size should be 1, 2 or 4"");
                    return 0;
            }
            if ( i < 0 || i >= len/size ) {
                    PyErr_SetString(AudioopError, ""Index out of range"");
                    return 0;
            }
            if ( size == 1 )      val = (int)*CHARP(cp, i);
            else if ( size == 2 ) val = (int)*SHORTP(cp, i*2);
            else if ( size == 4 ) val = (int)*LONGP(cp, i*4);
            return PyInt_FromLong(val);
    }