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

📄 umc_reverb_demodlg.cpp

📁 audio-video-codecs.rar语音编解码器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*//////////////////////////////////////////////////////////////////////////////
//
//                  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.
//
//  Note: umc_reverb_demoDlg.cpp - implementation revereration algorithm
*/

#include "stdafx.h"
#include "umc_reverb_demo.h"
#include "umc_reverb_demoDlg.h"
#include "reverb_data.h"
//#include "winmm_render.h"
#include "directsound_render.h"

using namespace UMC;

#include "umc_audio_render.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

static FileInfoStruct fileInfo;

class CAboutDlg : public CDialog
{
public:
  CAboutDlg();

// Dialog Data
  //{{AFX_DATA(CAboutDlg)
  enum { IDD = IDD_ABOUTBOX };
  //}}AFX_DATA

  // ClassWizard generated virtual function overrides
  //{{AFX_VIRTUAL(CAboutDlg)
  protected:
  virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  //}}AFX_VIRTUAL

// Implementation
protected:
  //{{AFX_MSG(CAboutDlg)
  //}}AFX_MSG
  DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
  //{{AFX_DATA_INIT(CAboutDlg)
  //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CAboutDlg)
  //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  //{{AFX_MSG_MAP(CAboutDlg)
    // No message handlers
  //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUmc_reverb_demoDlg dialog

CUmc_reverb_demoDlg::CUmc_reverb_demoDlg(CWnd* pParent /*=NULL*/)
  : CDialog(CUmc_reverb_demoDlg::IDD, pParent)
{
  //{{AFX_DATA_INIT(CUmc_reverb_demoDlg)
  //}}AFX_DATA_INIT
  // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CUmc_reverb_demoDlg::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CUmc_reverb_demoDlg)
  DDX_Control(pDX, IDC_BUTTON_PLAY, m_PlayButton);
  DDX_Control(pDX, IDC_LIST, m_FileFromList);
  //}}AFX_DATA_MAP
  DDX_Control(pDX, IDC_CHECK_REVERB, m_ReverbEnable);
  DDX_Control(pDX, IDC_CHECK_ROOMSIZE, m_RoomSizeEnable);
  DDX_Control(pDX, IDC_CHECK_FINISHING, m_FinishingEnable);
  DDX_Control(pDX, IDC_ROOMSIZE_SLIDER, m_RSSliderValue);
  DDX_Control(pDX, IDC_FINISHING_SLIDER, m_FSliderValue);
  DDX_Control(pDX, IDC_TEXT_MIN, m_TextMin);
  DDX_Control(pDX, IDC_TEXT_MAX, m_TextMax);
  DDX_Control(pDX, IDC_TEXT_SOFT, m_TextSoft);
  DDX_Control(pDX, IDC_TEXT_HARD, m_TextHard);
  DDX_Control(pDX, IDC_BUTTON_RSDEF, m_RSDef);
  DDX_Control(pDX, IDC_BUTTON_FDEF, m_FDef);
  DDX_Control(pDX, IDC_RSL_TEXT, m_TextRSLevel);
  DDX_Control(pDX, IDC_RSL_MAX, m_TextRSLMax);
  DDX_Control(pDX, IDC_RSL_MIN, m_TextRSLMin);
  DDX_Control(pDX, IDC_RSL_SLIDER, m_RSLSliderValue);
}

BEGIN_MESSAGE_MAP(CUmc_reverb_demoDlg, CDialog)
  //{{AFX_MSG_MAP(CUmc_reverb_demoDlg)
  ON_WM_SYSCOMMAND()
  ON_WM_PAINT()
  ON_WM_QUERYDRAGICON()
  ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
  ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
  ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
  ON_BN_CLICKED(IDC_BUTTON_PLAY, OnButtonPlay)
  ON_LBN_DBLCLK(IDC_LIST, OnDblclkList)
  //}}AFX_MSG_MAP
  ON_BN_CLICKED(IDC_CHECK_REVERB, OnBnClickedCheckReverb)
  ON_BN_CLICKED(IDC_CHECK_ROOMSIZE, OnBnClickedCheckRoomsize)
  ON_BN_CLICKED(IDC_CHECK_FINISHING, OnBnClickedCheckFinishing)
  ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_ROOMSIZE_SLIDER, OnNMReleasedcaptureRoomsizeSlider)
  ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_FINISHING_SLIDER, OnNMReleasedcaptureFinishingSlider)
  ON_BN_CLICKED(IDC_BUTTON_RSDEF, OnBnClickedButtonRsdef)
  ON_BN_CLICKED(IDC_BUTTON_FDEF, OnBnClickedButtonFdef)
  ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_RSL_SLIDER, OnNMReleasedcaptureRslSlider)
  END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CUmc_reverb_demoDlg message handlers

BOOL CUmc_reverb_demoDlg::OnInitDialog()
{
  CDialog::OnInitDialog();

  // Add "About..." menu item to system menu.

  // IDM_ABOUTBOX must be in the system command range.
  ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  ASSERT(IDM_ABOUTBOX < 0xF000);

  CMenu* pSysMenu = GetSystemMenu(FALSE);
  if (pSysMenu != NULL)
  {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
    {
      pSysMenu->AppendMenu(MF_SEPARATOR);
      pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
    }
  }

  // Set the icon for this dialog.  The framework does this automatically
  //  when the application's main window is not a dialog
  SetIcon(m_hIcon, TRUE);      // Set big icon
  SetIcon(m_hIcon, FALSE);    // Set small icon

  // TODO: Add extra initialization here
  fileInfo.isPlaying = -1;
  fileInfo.handler = CUmc_reverb_demoDlg::m_hWnd;
  revInfo.reverb = FALSE;
  revInfo.eReflect = FALSE;
  revInfo.lReflect = FALSE;
  m_RSSliderValue.SetPos(10);
  m_FSliderValue.SetPos(20);
  revInfo.RSSliderPos = 10;
  revInfo.FSliderPos = 20;

  m_RoomSizeEnable.EnableWindow(FALSE);
  m_FinishingEnable.EnableWindow(FALSE);
  m_RSSliderValue.EnableWindow(FALSE);
  m_FSliderValue.EnableWindow(FALSE);
  m_TextMin.EnableWindow(FALSE);
  m_TextMax.EnableWindow(FALSE);
  m_TextSoft.EnableWindow(FALSE);
  m_TextHard.EnableWindow(FALSE);
  m_RSDef.EnableWindow(FALSE);
  m_FDef.EnableWindow(FALSE);
  m_TextRSLevel.EnableWindow(FALSE);
  m_RSLSliderValue.EnableWindow(FALSE);
  m_TextRSLMax.EnableWindow(FALSE);
  m_TextRSLMin.EnableWindow(FALSE);
  m_RSLSliderValue.SetPos(10);
  revInfo.LevelSliderPos = 10;

  return TRUE;  // return TRUE  unless you set the focus to a control
}

void CUmc_reverb_demoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
  if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
  }
  else
  {
    CDialog::OnSysCommand(nID, lParam);
  }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CUmc_reverb_demoDlg::OnPaint()
{
  if (IsIconic())
  {
    CPaintDC dc(this); // device context for painting

    SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

    // Center icon in client rectangle
    Ipp32s cxIcon = GetSystemMetrics(SM_CXICON);
    Ipp32s cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    Ipp32s x = (rect.Width() - cxIcon + 1) / 2;
    Ipp32s y = (rect.Height() - cyIcon + 1) / 2;

    // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
  }
  else
  {
    CDialog::OnPaint();
  }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CUmc_reverb_demoDlg::OnQueryDragIcon()
{
  return (HCURSOR) m_hIcon;
}

void CUmc_reverb_demoDlg::OnButtonAdd()
{
  OPENFILENAME    ofn;

  memset(&ofn, 0, sizeof(OPENFILENAME));

  vm_char szFile[MAX_PATH_LEN] = "\0";
  vm_char szFileTitle[MAX_TITLE_LEN] = "";
  vm_char szFilter[]       = "WAV Files (*.wav)\0*.wav\0";

  ofn.lStructSize     = sizeof(OPENFILENAME);
  ofn.hwndOwner       = this->m_hWnd;
  ofn.hInstance       = ::AfxGetInstanceHandle();
  ofn.lpstrFile       = szFile;
  ofn.lpstrFileTitle  = szFileTitle;
  ofn.nMaxFile        = MAX_PATH_LEN;
  ofn.nMaxFileTitle   = MAX_TITLE_LEN;
  ofn.lpstrFilter     = szFilter;
  ofn.nFilterIndex    = 1;
  ofn.lpstrInitialDir = "%HOMEDIR%";
  ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_EXPLORER;// | OFN_ALLOWMULTISELECT;

  if(::GetOpenFileName(&ofn))
  {
    UpdateData();
    m_FileFromList.AddString(ofn.lpstrFile);
  }
}

void CUmc_reverb_demoDlg::OnButtonExit()
{
  CDialog::OnCancel();
}

void CUmc_reverb_demoDlg::OnButtonDelete()
{
  if (m_FileFromList.GetCurSel() != LB_ERR)
  {
    m_FileFromList.DeleteString(m_FileFromList.GetCurSel());
  }
  UpdateData();
}

void CUmc_reverb_demoDlg::OnButtonStop()
{
  m_PlayButton.SetWindowText("Play");
  fileInfo.isPlaying = -1;
//  vm_thread_close(&(fileInfo.play_thread));
}

static Ipp32s FillInFileStruct()
{
  FILE    *file_wav;
  chunk_info  cur_chunk;

  file_wav = fopen(fileInfo.file_name, "rb");
    if (file_wav == NULL) {
        fileInfo.dlg->MessageBox("Failed to open file!!!", "Error", MB_ICONERROR);
        return 1;
    }
  fread(&cur_chunk, 1, sizeof(cur_chunk), file_wav);
  if (vm_string_strncmp(cur_chunk.ChunkName, "RIFF", 4) != 0) {
    return 1;
  }
  fread(&cur_chunk.ChunkName, 1, sizeof(cur_chunk.ChunkName), file_wav);
  if (vm_string_strncmp(cur_chunk.ChunkName, "WAVE", 4) != 0) {
    return 1;
  }
  fread(&cur_chunk, 1, sizeof(cur_chunk), file_wav);
  if (vm_string_strncmp(cur_chunk.ChunkName, "fmt ", 4) != 0) {
    return 1;
  }

  fread(&(fileInfo.streamtype), 1, 2, file_wav);
  if (fileInfo.streamtype != UMC::PCM_AUDIO) {
    return 1;
  }
  fread(&(fileInfo.nchan), 1, 2, file_wav);
  if ((fileInfo.nchan != 0x1) && (fileInfo.nchan != 0x2)) { //mono or stereo
        fileInfo.dlg->MessageBox("This file is not a MONO one", "Error", MB_ICONERROR);
    return 1;
  }
  fread(&(fileInfo.sRate), 1, 4, file_wav);
  fseek(file_wav, 6, SEEK_CUR); //Bytes Per Second (16-19)& Bytes Per Sample (20-21)
  fread(&(fileInfo.bitspersample), 1, 2, file_wav);

  fseek(file_wav, cur_chunk.chunk_len - 16, SEEK_CUR);

  fread(&cur_chunk, 1, sizeof(cur_chunk), file_wav);
  if (vm_string_strncmp(cur_chunk.ChunkName, "fact", 4) == 0) { //fact chunk is present
    fseek(file_wav, cur_chunk.chunk_len, SEEK_CUR); //length of fact
    fread(&cur_chunk, 1, sizeof(cur_chunk), file_wav);
  }
  if (vm_string_strncmp(cur_chunk.ChunkName, "data", 4) != 0) {
    return 1;
  }
  fileInfo.data_chunk = cur_chunk;
  fileInfo.data = file_wav;

  return 0;
}

static Ipp32u VM_THREAD_CALLCONVENTION playback_thread(void *ptr)
{
  UMC::AudioRender*         pRender       = new UMC::DSoundAudioRender;
//  UMC::AudioRender*         pRender       = new UMC::WinMMAudioRender;
//  UMC::AudioRender*         pRender       = new UMC::FWAudioRender;
  UMC::AudioRenderParams*   pRenderParams = new UMC::AudioRenderParams;
//  UMC::FWAudioRenderParams*   pRenderParams = new UMC::FWAudioRenderParams;
  UMC::ReverbFilter*        pRevFilter    = new UMC::ReverbFilter;
  UMC::ReverbFilterParams*  pRevParams    = new UMC::ReverbFilterParams;
  UMC::MediaReceiverParams* pMediaReceiverParams;
  UMC::HWNDModuleContext    HWNDContext;
  UMC::Status               umc_stat;
  IppStatus                 ippStat;
  Ipp32s maxRead;

  pRenderParams->info.stream_type = (UMC::AudioStreamType)fileInfo.streamtype;
  pRenderParams->info.channels = fileInfo.nchan;
  pRenderParams->info.sample_frequency = fileInfo.sRate;
  pRenderParams->info.bitPerSample = fileInfo.bitspersample;

  /* passing the handler */
  HWNDContext.m_hWnd = fileInfo.handler;
  pRenderParams->pModuleContext  = &HWNDContext;
//  pRenderParams->pOutFile = "myfile.wav";

  /* patch */
  pMediaReceiverParams = DynamicCast<MediaReceiverParams, AudioRenderParams>(pRenderParams);
  umc_stat = pRender->Init(pMediaReceiverParams);
  if (umc_stat != UMC::UMC_OK) {
    fileInfo.dlg->MessageBox("Failed to Init render", "Error", MB_ICONERROR);
    delete pRenderParams;
    delete pRender;
    delete pRevFilter;
    delete pRevParams;
    return 0;
  }

  Ipp16s *inBuf = ippsMalloc_16s(REVERB_BUF_SIZE * fileInfo.nchan);
  if (inBuf == NULL) {
    fileInfo.dlg->MessageBox("Failed on malloc inBuf!!!", "", MB_ICONERROR);
    delete pRenderParams;
    delete pRender;
    delete pRevFilter;
    delete pRevParams;
    return 0;
  }

  UMC::MediaData* inData = new UMC::MediaData;
  UMC::MediaData outData;

  inData->SetBufferPointer((Ipp8u *)inBuf, REVERB_BUF_SIZE * fileInfo.nchan * sizeof(Ipp16s));
  inData->SetDataSize(REVERB_BUF_SIZE * fileInfo.nchan * sizeof(Ipp16s));

  /***** REVERBERATOR INIT *****/
  pRevParams->fileSampleRate = fileInfo.sRate;
  pRevParams->fileChannels = fileInfo.nchan;
  pRevParams->maxFrameLen = REVERB_BUF_SIZE;

⌨️ 快捷键说明

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