external/the-forge/Common_3/ThirdParty/OpenSource/soloud20181119/src/audiosource/wav/dr_flac.h
static drflac_bool32 drflac__decode_samples_with_residual__rice__reference(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 order, drflac_int32 shift, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
{
    drflac_assert(bs != NULL);
    drflac_assert(count > 0);
    drflac_assert(pSamplesOut != NULL);

    for (drflac_uint32 i = 0; i < count; ++i) {
        drflac_uint32 zeroCounter = 0;
        for (;;) {
            drflac_uint8 bit;
            if (!drflac__read_uint8(bs, 1, &bit)) {
                return DRFLAC_FALSE;
            }

            if (bit == 0) {
                zeroCounter += 1;
            } else {
                break;
            }
        }

        drflac_uint32 decodedRice;
        if (riceParam > 0) {
            if (!drflac__read_uint32(bs, riceParam, &decodedRice)) {
                return DRFLAC_FALSE;
            }
        } else {
            decodedRice = 0;
        }

        decodedRice |= (zeroCounter << riceParam);
        if ((decodedRice & 0x01)) {
            decodedRice = ~(decodedRice >> 1);
        } else {
            decodedRice =  (decodedRice >> 1);
        }


        if (bitsPerSample > 16) {
            pSamplesOut[i] = decodedRice + drflac__calculate_prediction_64(order, shift, coefficients, pSamplesOut + i);
        } else {
            pSamplesOut[i] = decodedRice + drflac__calculate_prediction_32(order, shift, coefficients, pSamplesOut + i);
        }
    }

    return DRFLAC_TRUE;
}
// Reference implementation for reading and decoding samples with residual. This is intentionally left unoptimized for the
// sake of readability and should only be used as a reference.
Reference implementation for reading and decoding samples with residual. This is intentionally left unoptimized for the
sake of readability and should only be used as a reference.
Reference implementation for reading and decoding samples with residual . This is intentionally left unoptimized for the sake of readability and should only be used as a reference .
static drflac_bool32 drflac__decode_samples_with_residual__rice__reference(drflac_bs* bs, drflac_uint32 bitsPerSample, drflac_uint32 count, drflac_uint8 riceParam, drflac_uint32 order, drflac_int32 shift, const drflac_int32* coefficients, drflac_int32* pSamplesOut)
{
    drflac_assert(bs != NULL);
    drflac_assert(count > 0);
    drflac_assert(pSamplesOut != NULL);
    for (drflac_uint32 i = 0; i < count; ++i) {
        drflac_uint32 zeroCounter = 0;
        for (;;) {
            drflac_uint8 bit;
            if (!drflac__read_uint8(bs, 1, &bit)) {
                return DRFLAC_FALSE;
            }
            if (bit == 0) {
                zeroCounter += 1;
            } else {
                break;
            }
        }
        drflac_uint32 decodedRice;
        if (riceParam > 0) {
            if (!drflac__read_uint32(bs, riceParam, &decodedRice)) {
                return DRFLAC_FALSE;
            }
        } else {
            decodedRice = 0;
        }
        decodedRice |= (zeroCounter << riceParam);
        if ((decodedRice & 0x01)) {
            decodedRice = ~(decodedRice >> 1);
        } else {
            decodedRice =  (decodedRice >> 1);
        }
        if (bitsPerSample > 16) {
            pSamplesOut[i] = decodedRice + drflac__calculate_prediction_64(order, shift, coefficients, pSamplesOut + i);
        } else {
            pSamplesOut[i] = decodedRice + drflac__calculate_prediction_32(order, shift, coefficients, pSamplesOut + i);
        }
    }
    return DRFLAC_TRUE;
}
static drflac_bool32 drflac__decode_samples_with_residual__rice__reference ( drflac_bs * bs , drflac_uint32 bitsPerSample , drflac_uint32 count , drflac_uint8 riceParam , drflac_uint32 order , drflac_int32 shift , const drflac_int32 * coefficients , drflac_int32 * pSamplesOut ) { drflac_assert ( bs != NULL ) ; drflac_assert ( count > 0 ) ; drflac_assert ( pSamplesOut != NULL ) ; for ( drflac_uint32 i = 0 ; i < count ; ++ i ) { drflac_uint32 zeroCounter = 0 ; for ( ; ; ) { drflac_uint8 bit ; if ( ! drflac__read_uint8 ( bs , 1 , & bit ) ) { return DRFLAC_FALSE ; } if ( bit == 0 ) { zeroCounter += 1 ; } else { break ; } } drflac_uint32 decodedRice ; if ( riceParam > 0 ) { if ( ! drflac__read_uint32 ( bs , riceParam , & decodedRice ) ) { return DRFLAC_FALSE ; } } else { decodedRice = 0 ; } decodedRice |= ( zeroCounter << riceParam ) ; if ( ( decodedRice & 0x01 ) ) { decodedRice = ~ ( decodedRice >> 1 ) ; } else { decodedRice = ( decodedRice >> 1 ) ; } if ( bitsPerSample > 16 ) { pSamplesOut [ i ] = decodedRice + drflac__calculate_prediction_64 ( order , shift , coefficients , pSamplesOut + i ) ; } else { pSamplesOut [ i ] = decodedRice + drflac__calculate_prediction_32 ( order , shift , coefficients , pSamplesOut + i ) ; } } return DRFLAC_TRUE ; }
Reference implementation for reading and decoding samples with residual.
Reference implementation for reading and decoding samples with residual .