Exemple #1
0
// Overload function to set coefficients from the given data array.
//
// Parameters:
//   coeffs        buffers of coefficients
//   n_coeffs      the number of coefficient buffers
//   length        the length of each buffer
//   coeff_blocks  the number of coefficient blocks
//   scale         the scaling factor
//
// Returns:
//    0 if successful
//   -1 if coefficients could not be loaded
int
brutefir::set_coeff(void **coeffs,
                    int n_coeffs,
                    int length,
                    int coeff_blocks,
                    double scale)
{
    int n;

    // free existing coefficient memory
    free_coeff();

    if (n_coeffs > bfconf->n_channels)
    {
        n_coeffs = bfconf->n_channels;
    }

    for (n = 0; n < n_coeffs; n++)
    {
        // preprocess coefficients
        bfconf->coeffs[n].data = coeff::preprocess_coeff(m_convolver,
                                                        coeffs[n],
                                                        bfconf->filter_length,
                                                        coeff_blocks,
                                                        length,
                                                        bfconf->realsize,
                                                        scale);

        if (bfconf->coeffs[n].data == NULL)
        {
            pinfo("Error preprocessing coefficient %u", n);
            break;
        }

        bfconf->coeffs[n].n_blocks = coeff_blocks;
        bfconf->coeffs[n].intname = n;
        bfconf->coeffs[n].n_channels = 1;
        bfconf->coeffs[n].channels[0] = n;
    }

    if (n < n_coeffs)
    {
        // Free coefficient memory on error
        free_coeff();
        return -2;
    }

    m_initialized = true;
    return 0;
}
Exemple #2
0
// Destructor for the class.
brutefir::~brutefir()
{
    free_buffers();
    free_coeff();

    // free objects
    delete m_convolver;
    delete m_dither;

    // free configuration structure
    if (bfconf != NULL)
    {
        free(bfconf);
        bfconf = NULL;
    }
}
Exemple #3
0
void free_stages(struct stage *stage_ptr) {
  struct blkt *this_blkt, *next_blkt;

  if(stage_ptr != (struct stage *)NULL) {
    free_stages(stage_ptr->next_stage);
    this_blkt = stage_ptr->first_blkt;
    while(this_blkt != (struct blkt *)NULL) {
      next_blkt = this_blkt->next_blkt;
      switch (this_blkt->type) {
      case LAPLACE_PZ:
      case ANALOG_PZ:
      case IIR_PZ:
        free_pz(this_blkt);
        break;
      case FIR_SYM_1:
      case FIR_SYM_2:
      case FIR_ASYM:
        free_fir(this_blkt);
        break;
      case FIR_COEFFS:
        free_coeff(this_blkt);
        break;
      case LIST:
        free_list(this_blkt);
        break;
      case GENERIC:
        free_generic(this_blkt);
        break;
      case DECIMATION:
        free_deci(this_blkt);
        break;
      case GAIN:
        free_gain(this_blkt);
        break;
      case REFERENCE:
        free_ref(this_blkt);
        break;
      default:
        break;
      }
      this_blkt = next_blkt;
    }
    free(stage_ptr);
  }
}
Exemple #4
0
// Sets coefficients from the specified sound file.
//
// Supported formats are any that the libsndfile library
// can process.
//
// Parameters:
//   filename      the coefficient filename
//   coeff_blocks  the number of coefficient blocks
//   scale         the scaling factor
//
// Returns:
//   the number of channels extracted
//    -1 if incompatible file
//    -2 if coefficients could not be loaded
int
brutefir::set_coeff(const wchar_t *filename,
                    int coeff_blocks,
                    double scale)
{
    int n;
    int n_coeffs;
    int length;
    void **coeffs;

    // check compatibility of sound file
    if (!buffer::check_snd_file(filename, bfconf->n_channels, bfconf->sampling_rate))
    {
        pinfo("Incompatible file %s: format %u channels %u Hz.",
              filename,
              bfconf->n_channels,
              bfconf->sampling_rate);

        return -1;
    }

    // load the coefficients
    coeffs = coeff::load_snd_coeff(filename,
                                   &length,
                                   bfconf->realsize,
                                   coeff_blocks * bfconf->filter_length,
                                   &n_coeffs);

    if (coeffs == NULL)
    {
        pinfo("Error loading coefficients from sound file %s.", filename);
        return -2;
    }

    // free existing coefficient memory
    free_coeff();

    if (n_coeffs > bfconf->n_channels)
    {
        n_coeffs = bfconf->n_channels;
    }

    for (n = 0; n < n_coeffs; n++)
    {
        // preprocess coefficients
        bfconf->coeffs[n].data = coeff::preprocess_coeff(m_convolver,
                                                         coeffs[n],
                                                         bfconf->filter_length,
                                                         coeff_blocks,
                                                         length,
                                                         bfconf->realsize,
                                                         scale);

        _aligned_free(coeffs[n]);
        coeffs[n] = NULL;

        if (bfconf->coeffs[n].data == NULL)
        {
            pinfo("Error preprocessing coefficient %u from sound file %s.", n, filename);
            break;
        }

        bfconf->coeffs[n].n_blocks = coeff_blocks;
        bfconf->coeffs[n].intname = n;
        bfconf->coeffs[n].n_channels = 1;
        bfconf->coeffs[n].channels[0] = n;
    }

    if (n < n_coeffs)
    {
        // Free coefficient memory on error
        free_coeff();
        return -2;
    }

    m_initialized = true;
    return n_coeffs;
}