Декодирование аудио с использованием CVSD Decoder (GnuRadio) - PullRequest
0 голосов
/ 02 ноября 2019

Я использовал код декодера CVSD в файле: cvsd_decode_bs_impl.cc .

Функция:

int cvsd_decode_bs_impl::work(int noutput_items,
                          gr_vector_const_void_star& input_items,
                          gr_vector_void_star& output_items)
{
const unsigned char* in = (const unsigned char*)input_items[0];
short* out = (short*)output_items[0];

int i = 0;
short output_short = 0;       // 2 bytes 0 .. 65,535
unsigned char bit_count = 0;  // 1 byte, 0 .. 255
unsigned int mask = 0;        // 4 bytes, 0 .. 4,294,967,295
unsigned char input_byte = 0; //  1 bytes
unsigned char input_bit = 0;  // 1 byte, 0 .. 255

// Loop through each input data point
for (i = 0; i < noutput_items / 8.0; i++) {
    input_byte = in[i];
    // Initialize bit counter
    bit_count = 0;

    while (bit_count < 8) {
        // Compute the Appropriate Mask
        mask = cvsd_pow(2, 7 - bit_count);

        // Pull off the corresponding bit
        input_bit = input_byte & mask;

        // Update the bit counter
        bit_count++;

        // Update runner with the next input bit
        // Runner is a shift-register; shift left, add on newest output bit
        //d_runner = (d_runner<<1) | ((unsigned int) input_bit);
        d_runner <<= 1;
        if (input_bit)
            d_runner |= 1;    // always add it to the LSbit

        // Run this only if you have >= J bits in your shift register
        if (d_loop_counter >= d_J) {
            // Update Step Size
            d_runner_mask = (cvsd_pow(2, d_J) - 1);
            if ((cvsd_bitwise_sum(d_runner & d_runner_mask) >= d_J) ||
                (cvsd_bitwise_sum((~d_runner) & d_runner_mask) >= d_J)) {
                // Runs of 1s and 0s
                d_stepsize = std::min((short)(d_stepsize + d_min_step), d_max_step);
            } else {
                // No runs of 1s and 0s
                d_stepsize = std::max((short)cvsd_round(d_stepsize * d_step_decay),
                                      d_min_step);
            }
        }

        // Update Accum (i.e. the reference value)
        if (input_bit) {
            d_accum = d_accum + d_stepsize;
        } else {
            d_accum = d_accum - d_stepsize;
        }

        // Multiply by Accum_Decay
        d_accum = (cvsd_round(d_accum * d_accum_decay));

        // Check for overflow
        if (d_accum >= ((int)d_pos_accum_max)) {
            d_accum = (int)d_pos_accum_max;
        } else if (d_accum <= ((int)d_neg_accum_max)) {
            d_accum = (int)d_neg_accum_max;
        }

        // Find the output short to write to the file
        output_short = ((short)d_accum);

        if (d_loop_counter <= d_K) {
            d_loop_counter++;
        }

        *(out++) = output_short;
    } // while ()

} // for()

return noutput_items;
}

Но звук был шумом после декодирования.

Ввод: чтение байтов из файла RAW.

Вывод: запись байтов в файл RAW. Я использую Audacity для чтения файла RAW.

Кто-нибудь здесь экспериментировал с этим? Как лучше всего уменьшить шум?

Спасибо за помощь.

...