📄 main.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 - 2007 Intel Corporation. All Rights Reserved.
//
*/
#include "vm_mmap.h"
#include "vm_time.h"
#include <stdio.h>
#include "umc_structures.h"
#include "umc_audio_codec.h"
#include "audio_codec_object.h"
#include "factory.h"
#include "umc_dual_thread_codec.h"
#include "umc_cyclic_buffer.h"
#include "cipic_hrtf_parser.h"
#include "umc_sound3d_filter.h"
#include "directsound_render.h"
#include "umc_audio_render.h"
#include "umc_ac3_decoder.h"
#include "ac_5p1_audio_file.h"
#include "ac_5p1_wav_file.h"
#include "ippac.h"
using namespace UMC;
#define SIZE_OF_FRAME 2048
#define NUM_CODEC_CH 6
#define MAX_NUM_CH 12
typedef struct {
vm_char input_file[256];
vm_char output_file[256];
vm_char output_txt[256];
vm_char codec_name[256];
Ipp32s is_text_out;
Ipp32s bitrate;
Ipp32s enumerate;
} sProgramParameters;
struct sCommandLineParams {
Ipp8s input_file[256];
Ipp8s output_file[256];
Ipp32s bUsePluginDll;
};
typedef enum {
HRTF = 1,
HRTF_CTC = 2,
DOLBY_DWNMX = 3,
MULT_5p1 = 4,
UNKNOW = -1
} USER_MENU;
static void LoadPlugins(Factory & factory);
static USER_MENU ParserUserChoice(Ipp16s my_key, bool * flag_s3d, Ipp32s FlagAC3,
UMC::AudioRender * ac_render5p1,
UMC::AudioRender * ac_renderStereo,
UMC::AudioRender ** audioRender,
Sound3dFilterParams * s3d_params,
Sound3dFilter ** s3d_filter,
bool SoundCardSupport_5p1);
static Ipp32s params_parse_command_line(sProgramParameters * p_param, Ipp32s argc,
char *argv[]);
static void params_print_usage(void);
Ipp32s main(Ipp32s argc, char *argv[])
{
AudioFile *p_in_file;
WavFile wav_file_in;
Ipp32s err;
Status sts;
Status umcRes;
Ipp32s i;
Ipp32s FirstFrame = 1;
Ipp32s FlagAC3 = 1;
Ipp32s size = 0;
Ipp32u size_out = 0;
vm_tick t_freq, t_start, t_end;
Ipp64f t_encode_time = 0;
Ipp32s numFramesToProcess = 0;
MediaBuffer *pMediaBuffer;
MediaData inMediaBuffer;
MediaData *pOut;
MediaData *pInData;
MediaData *pOutData;
Ipp32f *buff_32f;
Ipp32f *buff_common;
Ipp16s *buff_16s;
Ipp32f *buff_ch_32f[6];
Ipp16s *buff_ch_16s[6];
// CORE STRUCTURES
AudioCodec *pAudioCodec;
DualThreadedCodec dual_treaded_codec;
// 3D POSITION EFFECT
cipic_hrtf_parser *hrtf_data;
Sound3dFilter *s3d_filter[6];
UMC::AudioRender *audioRender[6];
UMC::AudioRender *ac_renderStereo;
UMC::AudioRender *ac_render5p1;
// PARAMS
AudioCodecParams *audio_codec_params;
MediaReceiverParams *pMediaReceiverParams;
MediaBufferParams *media_buffer_params;
DualThreadCodecParams codec_init;
sProgramParameters params;
// 3D POSITION EFFECT
Sound3dFilterParams *s3d_params;
AudioRenderParams *audio_render_params;
AudioRenderParams *ac_render_params5p1;
AudioRenderParams *ac_render_paramsStereo;
// USER DEFAULT TUNE PARAMS
UMC::AC3DecoderParams AC3Settings5p1;
UMC::AC3DecoderParams AC3SettingsStereo;
USER_MENU user_choice = HRTF;
USER_MENU user_choice_prev = HRTF;
// FLAG QUALITY SOUND CARD
bool SoundCardSupport_5p1 = false;
Factory factory;
Factory::Iterator < AudioCodecObject > iterator;
// SET AC3 DEC PARAMS
AC3Settings5p1.out_acmod = 7;
AC3Settings5p1.outlfeon = 1;
AC3SettingsStereo.out_compmod = 3;
AC3SettingsStereo.out_acmod = 0;
AC3SettingsStereo.outlfeon = 0;
// SET NULL
pAudioCodec = NULL;
pMediaBuffer = NULL;
pOut = NULL;
pOutData = NULL;
pInData = NULL;
hrtf_data = NULL;
audio_codec_params = NULL;
media_buffer_params = NULL;
audio_render_params = NULL;
s3d_params = NULL;
ac_render_params5p1 = NULL;
ac_render_paramsStereo = NULL;
ac_renderStereo = NULL;
ac_render5p1 = NULL;
// // this code is needed for RENDER
UMC::HWNDModuleContext HWNDContext;
vm_char lpConsoleTitle[100];
SetConsoleTitle("IPP-AC DEMO: MULTI_CHANNEl AUDIO & 3D POSITION EFFECT");
GetConsoleTitle((LPTSTR) lpConsoleTitle, 100);
printf("%s\n", lpConsoleTitle);
printf("Copyright(c) 2005-2007 Intel Corporation. All Rights Reserved");
printf("\n");
HWND hwnd = FindWindow(NULL, lpConsoleTitle);
HWNDContext.m_hWnd = hwnd;
LoadPlugins(factory);
if (argc < 5) {
params_print_usage();
return -1;
}
ippsZero_8u((Ipp8u *)¶ms, sizeof(sProgramParameters));
params_parse_command_line(¶ms, argc, argv);
if (params.enumerate) {
iterator = factory;
printf("The following codecs are available:\n");
printf("%-25s %s\n------\n", "Codec name", "Version");
while (iterator != NULL) {
printf("%-25s %s\n", iterator->GetName(), iterator->GetVersion());
iterator++;
}
return 0;
}
p_in_file = &wav_file_in;
audio_codec_params = new UMC::AudioCodecParams;
err = p_in_file->Open(params.input_file, AudioFile::AFM_NO_CONTENT_WRN);
audio_codec_params->m_info_in.stream_type = UNDEF_AUDIO;
if (err < 0) {
printf("Can't open input file '%s'", params.input_file);
return -2;
}
iterator = factory;
if (((params.codec_name)[0] == 'a') && ((params.codec_name)[1] == 'c') &&
((params.codec_name)[2] == '3'))
FlagAC3 = 1;
else
FlagAC3 = 0;
if (false == iterator.Find(params.codec_name)) {
printf("The codec '%s'is not found.\n", params.codec_name);
return -4;
}
pAudioCodec = (UMC::AudioCodec *) iterator->Create();
if (pAudioCodec == NULL) {
printf("Can't create audio codec object '%s'\n", params.codec_name);
return -5;
}
// INITIALIZATION
hrtf_data = new cipic_hrtf_parser;
umcRes = hrtf_data->Init(argv[4]);
if (umcRes != UMC_OK) {
printf("\nthis HRTF database isn't CIPIC or there is other problem \n");
return -1;
}
pMediaBuffer = DynamicCast < MediaBuffer > (new LinearBuffer);
media_buffer_params =
DynamicCast < MediaBufferParams > (new MediaBufferParams);
pOut = new MediaData(SIZE_OF_FRAME * 2 * 6);
pInData = new MediaData;
pOutData = new MediaData(SIZE_OF_FRAME * 2 * 2);
media_buffer_params->m_numberOfFrames = 10;
media_buffer_params->m_prefInputBufferSize = 2304;
codec_init.m_pCodec = pAudioCodec;
codec_init.m_pMediaBuffer = pMediaBuffer;
codec_init.m_pCodecInitParams = audio_codec_params;
codec_init.m_pMediaBufferParams = media_buffer_params;
for (i = 0; i < 6; i++)
audioRender[i] = new UMC::DSoundAudioRender;
ac_render5p1 = new UMC::DSoundAudioRender;
ac_renderStereo = new UMC::DSoundAudioRender;
for (i = 0; i < 6; i++)
s3d_filter[i] = new UMC::Sound3dFilter;
s3d_params = new Sound3dFilterParams;
audio_render_params = new AudioRenderParams;
ac_render_params5p1 = new AudioRenderParams;
ac_render_paramsStereo = new AudioRenderParams;
// CHECK SOUND CARD
ac_render_params5p1->info.bitPerSample = 16;
ac_render_params5p1->info.channels = 6;
ac_render_params5p1->info.sample_frequency = 44100;
ac_render_params5p1->info.stream_type = (UMC::AudioStreamType) 1;
ac_render_params5p1->pModuleContext = &HWNDContext;
pMediaReceiverParams = DynamicCast < MediaReceiverParams, AudioRenderParams > (ac_render_params5p1);
umcRes = ac_render5p1->Init(pMediaReceiverParams);
if (umcRes != UMC_OK)
{
//printf("Your sound card doesn't support multichannel mode %s", GetErrString(umcRes));
printf("\nYour sound card doesn't support multichannel mode\n");
SoundCardSupport_5p1 = false;
}
else
{
SoundCardSupport_5p1 = true;
ac_render5p1->Close();
}
buff_32f = new Ipp32f[(SIZE_OF_FRAME * 6)];
buff_common = new Ipp32f[(SIZE_OF_FRAME * 6)];
buff_16s = new Ipp16s[(SIZE_OF_FRAME * 12)];
for (i = 0; i < 6; i++) {
buff_ch_32f[i] = &buff_32f[i * SIZE_OF_FRAME];
buff_ch_16s[i] = &buff_16s[i * SIZE_OF_FRAME * 2];
}
sts = dual_treaded_codec.InitCodec(&codec_init);
if (sts == UMC_OK) {
t_freq = vm_time_get_frequency();
t_end = 0;
if (FlagAC3)
{
if(SoundCardSupport_5p1)
{
printf
("AC3(5.1)stream\n\nkey <1> 5.1 -> HRTF\nkey <2> 5.1 -> HRTF + CrossTalkCancellation\nkey <3> 5.1 -> 2 (DOLBY)\nkey <4> 5.1 (realy 5.1 - enable)\n");
}
else
{
printf
("AC3(5.1)stream\n\nkey <1> 5.1 -> HRTF\nkey <2> 5.1 -> HRTF + CrossTalkCancellation\nkey <3> 5.1 -> 2 (DOLBY)\nkey <4> 5.1 (realy 5.1 - disenable)\n");
}
}
else
{
if(SoundCardSupport_5p1)
{
printf
("AAC(5.1)stream\n\nkey <1> 5.1 -> HRTF\nkey <2> 5.1 -> HRTF + CrossTalkCancellation\nkey <3> isn't used\nkey <4> 5.1 (realy 5.1 - enable)\n");
}
else
{
printf
("AAC(5.1)stream\n\nkey <1> 5.1 -> HRTF\nkey <2> 5.1 -> HRTF + CrossTalkCancellation\nkey <3> isn't used\nkey <4> 5.1 (realy 5.1 - disenable)\n");
}
}
Ipp16s my_key = 1;
bool flag_s3d = true;
do {
sts = dual_treaded_codec.LockInputBuffer(&inMediaBuffer);
if (sts == UMC::UMC_OK) {
size =
p_in_file->Read(inMediaBuffer.GetBufferPointer(),
inMediaBuffer.GetBufferSize());
inMediaBuffer.SetDataSize(size);
dual_treaded_codec.UnLockInputBuffer(&inMediaBuffer);
}
do {
t_start = vm_time_get_tick();
/*
* USER CHOICE
*/
user_choice_prev = user_choice;
user_choice =
ParserUserChoice(my_key, &flag_s3d, FlagAC3, ac_render5p1,
ac_renderStereo, audioRender, s3d_params,
s3d_filter, SoundCardSupport_5p1);
if (user_choice == UNKNOW)
user_choice = user_choice_prev;
if (user_choice == DOLBY_DWNMX){
pAudioCodec->SetParams(DynamicCast<BaseCodecParams>(&AC3SettingsStereo));
}
else{
pAudioCodec->SetParams(DynamicCast<BaseCodecParams>(&AC3Settings5p1) );
}
sts = dual_treaded_codec.GetFrame(pOut);
dual_treaded_codec.GetInfo(audio_codec_params);
if (FirstFrame) {
// reset flag init
FirstFrame = 0;
// check: stream has to be 5.1
if (audio_codec_params->m_info_in.channels < 5 + 1) {
printf
(" \n this stream isn't 5.1 \n demo plays multi-channel stream only \n");
return 2;
}
// init render and s3d_filter
s3d_params->FreqSamples =
audio_codec_params->m_info_out.sample_frequency;
s3d_params->LenFilter = 200;
s3d_params->MaxSamples = SIZE_OF_FRAME * 6 * 2 * 2;
s3d_params->user_hrtf = (base_hrtf_parser *) hrtf_data;
s3d_params->pos_speakers = -30;
s3d_params->flag_ctc = 0;
s3d_params->InvertFilter = FFTInvertFilter; // UMC::LMSInvertFilter;
s3d_params->Delay = 20;
s3d_params->LenInvFilter = 200;
// for(i=0; i<6; i++)
// {
// L-channel
s3d_params->Azimuth = -30;
s3d_params->Elevation = 0;
s3d_filter[0]->Init((UMC::BaseCodecParams *) s3d_params);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -