⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cipic_hrtf_parser.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
字号:
/*//////////////////////////////////////////////////////////////////////////////
//
//                  INTEL CORPORATION PROPRIETARY INFORMATION
//     This software is supplied under the terms of a license agreement or
//     nondisclosure agreement with Intel Corporation and may not be copied
//     or disclosed except in accordance with the terms of that agreement.
//          Copyright(c) 2005-2006 Intel Corporation. All Rights Reserved.
//
*/

#include "cipic_hrtf_parser.h"

namespace UMC {

  static Ipp32s id_of_azimuth[25] =
    { -80, -65, -55, -45, -40, -35, -30, -25, -20, -15, -10, -5, 0, 5, 10, 15,
       20, 25, 30, 35, 40, 45, 55, 65, 80 };

  static Ipp32u ChkCopressed(Ipp32u *in_data)
  {
    Ipp32u array[4];

// Ipp32u _0 = 0x000000ff;
    Ipp32u _1 = 0x0000ff00;
    Ipp32u _2 = 0x00ff0000;
    Ipp32u _3 = 0xff000000;
    Ipp32u temp;

    temp = *in_data;
    array[0] = temp;
    array[1] = (temp & _1) >> 8;
    array[2] = (temp & _2) >> 16;
    array[3] = (temp & _3) >> 24;

    if ((array[2] == 0) && (array[3] == 0)) {
      return 0;
    } else {
      *in_data = 0;
      *in_data = (array[1] << 8) + (array[0]);
      return (array[3] << 8) + (array[2]);
    }
  }

  cipic_hrtf_parser::cipic_hrtf_parser()
  {
  }

  cipic_hrtf_parser::~cipic_hrtf_parser()
  {
    Close();
  }

  Status  cipic_hrtf_parser::Parser(FileReader * hrtf_base, sHRIR * thrir)
  {
    Ipp32u i;
    Ipp32u data_type;
    Ipp32u size;
    Ipp32u data_size;
    Ipp8u array_flags[8];
    Ipp32u array_dimension[3];
    vm_char *array_name;
    Ipp32u temp;
    Status  status = UMC_OK;

// skip header
    status = hrtf_base->MovePosition(128);
    if (status != UMC_OK)
      return status;

    while (hrtf_base->GetSize() > hrtf_base->GetPosition())     // read data
                                                                // elements
    {
// Read of data element
      size = 4;
      status = hrtf_base->GetData(&data_type, &size);
      if (status != UMC_OK)
        return status;

      status = hrtf_base->GetData(&data_size, &size);   // number of bytes
      temp = data_size + (Ipp32u)hrtf_base->GetPosition();
      if (data_type == 14)      // if miMatrix
      {
// Read Tag Flag
        status = hrtf_base->GetData(&data_type, &size);
        status = hrtf_base->GetData(&data_size, &size);
        status = hrtf_base->GetData(array_flags, &data_size);
// Read Tag Dimensions
        status = hrtf_base->GetData(&data_type, &size);
        status = hrtf_base->GetData(&data_size, &size);
        for (i = 0; i < data_size / 4; i++)
          hrtf_base->GetData(&array_dimension[i], &size);
        if ((data_size % 8) != 0) {
          size = 8 - (data_size % 8);
          status = hrtf_base->GetData(&data_type, &size);
        }
// Read Tag Array Name (compressed!)
        size = 4;
        status = hrtf_base->GetData(&data_type, &size);
        data_size = ChkCopressed(&data_type);
        if (data_size == 0) {
          status = hrtf_base->GetData(&data_size, &size);
          array_name = (vm_char *)malloc(data_size * sizeof(vm_char));
          status = hrtf_base->GetData(array_name, &data_size);
          if ((data_size % 4) != 0) {
            size = 4 - (data_size % 4);
            status = hrtf_base->GetData(&data_type, &size);
          }
        } else {
          array_name = (vm_char *)malloc(data_size * sizeof(vm_char));
          status = hrtf_base->GetData(array_name, &data_size);
          if ((data_size % 4) != 0) {
            size = 4 - (data_size % 4);
            status = hrtf_base->GetData(&data_type, &size);
          }
        }
// Read ITD
        if (strncmp(array_name, "ITD", 3) == 0) {
          size = 4;
          status = hrtf_base->GetData(&data_type, &size);
          status = hrtf_base->GetData(&data_size, &size);
          size = sizeof(Ipp64f) * data_size / 8;
          status = hrtf_base->GetData(thrir->itd, &size);
          free(array_name);
        }
// Read HRIR left
        else if ((strncmp(array_name, "hrir_l", 6) == 0)) {
          size = 4;
          status = hrtf_base->GetData(&data_type, &size);
          status = hrtf_base->GetData(&data_size, &size);
          size = sizeof(Ipp64f) * data_size / 8;
          hrtf_base->GetData(thrir->hrir_left, &size);
          free(array_name);
        }
// Read HRIR right
        else if ((strncmp(array_name, "hrir_r", 6) == 0)) {
          size = 4;
          status = hrtf_base->GetData(&data_type, &size);
          status = hrtf_base->GetData(&data_size, &size);
          size = sizeof(Ipp64f) * data_size / 8;
          status = hrtf_base->GetData(thrir->hrir_right, &size);
          free(array_name);
        } else {
          status = hrtf_base->MovePosition(temp - hrtf_base->GetPosition());
          free(array_name);
        }
      } else
        status = hrtf_base->MovePosition(data_size);
    }
    return status;
  }

  Status  cipic_hrtf_parser::Init(vm_char * NameDataBase)
  {
    Status  status = UMC_OK;

    DataBaseStatus = UMC_ERR_NOT_INITIALIZED;

    m_DataBaseFileReaderParams = new UMC::FileReaderParams;
    m_DataBaseFileReader = new UMC::FileReader;
    if (m_DataBaseFileReader == NULL)
      return UMC_ERR_ALLOC;

    strcpy(m_DataBaseFileReaderParams->m_file_name, NameDataBase);

    DataBaseStatus = status =
      m_DataBaseFileReader->
      Init((DataReaderParams *) m_DataBaseFileReaderParams);
    if (status == UMC_OK) {
      HRIR_DataBase.hrir_left = ippsMalloc_64f(25 * 50 * 200);
      HRIR_DataBase.hrir_right = ippsMalloc_64f(25 * 50 * 200);
      HRIR_DataBase.itd = ippsMalloc_64f(25 * 50);

      status = Parser(m_DataBaseFileReader, &HRIR_DataBase);
    }
    return status;
  }

  Status  cipic_hrtf_parser::Close()
  {
    Status  status = UMC_OK;

    if (DataBaseStatus == UMC_ERR_NOT_INITIALIZED)
      return DataBaseStatus;

    if (m_DataBaseFileReaderParams)
      delete  m_DataBaseFileReaderParams;

    status = ((FileReader *) m_DataBaseFileReader)->Close();
    ippsFree(HRIR_DataBase.hrir_left);
    ippsFree(HRIR_DataBase.hrir_right);
    ippsFree(HRIR_DataBase.itd);

    return status;
  }

  Ipp32s  cipic_hrtf_parser::GetFilterFromDataBase(Ipp32f *filter_left,
                                                   Ipp32f *filter_right,
                                                   Ipp32f azimuth,
                                                   Ipp32f elevation)
  {
    Ipp32s  i;
    Ipp32s  id_az = 0;
    Ipp32s  id_el = 0;

    for (i = 0; i < 25; i++)
      if (id_of_azimuth[i] >= (Ipp32s)azimuth) {
        id_az = i;
        break;
      }
    for (i = 0; i < 50; i++)
      if (-45 + 5.625f * i >= elevation) {
        id_el = i;
        break;
      }
// extract HRIR for users' request
    for (i = 0; i < 200; i++) {
      filter_left[i] =
        (Ipp32f)(HRIR_DataBase.hrir_left[50 * 25 * i + 25 * id_el + id_az]);
      filter_right[i] =
        (Ipp32f)(HRIR_DataBase.hrir_right[50 * 25 * i + 25 * id_el + id_az]);
    }
    return 1;
  }

  Status  cipic_hrtf_parser::GetInfo(BaseCodecParams * info) {
    info->m_SuggestedInputSize = 200;

    return UMC_OK;
  }

}       // namespace UMC

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -