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

📄 g723.cpp

📁 windows环境下利用IPP库的例子代码
💻 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) 2001-03 Intel Corporation. All Rights Reserved.
//
//	Filename:
//		g723.cpp 
//
//	Description:
//		Codec sample application
//		PocketPC 2002
//		Intel Integrated Performance Primitives (IPP)
//		ITU-T G.723.1, ITU-T G.723.1 Annex A
//      Uses the following building blocks:
//			Intel(R) IPP ITU G.723.1 performance library
//			Intel(R) IPP ITU G.723.1 sample code		
//
//	Revision:
//		1.0
//
//	References:
//		[1]	ITU-T Rec. G.723.1, "Dual Rate Speech Coder for Multimedia
//          Communications Transmitting at 5.3 and 6.3 kbit/s,"  
//          Telecommunications Standardization Sector of ITU,
//          March, 1996.                                
//      [2] ITU-T Rec. G.723.1 fixed-point C reference code ("96_03"),
//          March, 1996.
//		[3]	ITU-T Rec. G.723.1 Annex A, "Annex A: Silence Compression Scheme,"
//          Telecommunications Standardization Sector of ITU,
//          November, 1996.                      
//
//  The following functions are defined in this file:
//
//		Name									Purpose
//      ---------------------------------------------------------------------------------
//		WinMain()								main entry point
//		MyRegisterClass()						window registration
//		InitInstance()							app initialization
//		WndProc()								main window message handler
//		TestDialog()							test vector dialog message handler
//		About()									about dialog message handler
//		createMenus()							command menu initialization
//				
******************************************************************************************/

#include "stdafx.h"
#include "g723.h"
#include <commctrl.h>
#include <aygshell.h>
#include <sipapi.h>

/* IPP definitions */
#include "ippdefs.h"
#include "ippSC.h"

/* codec API and OS adaptation layer */
#include "g723_codec.h"
#include <g723_oal_win32.h>

// application globals
#include <g723_globals.h>

// max string length
#define MAX_LOADSTRING 100

// user interface globals
HINSTANCE				g_hInst;		// The current instance
HWND					g_hwndCB;		// The command bar handle
static SHACTIVATEINFO	s_sai;

// Forward declarations of functions included in this code module:
ATOM				MyRegisterClass		(HINSTANCE, LPTSTR);
BOOL				InitInstance		(HINSTANCE, int);
LRESULT CALLBACK	WndProc				(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK	About				(HWND, UINT, WPARAM, LPARAM);
//HWND				CreateRpCommandBar	(HWND);
int					createMenus			(HINSTANCE hi, HWND hw);
LRESULT CALLBACK	TestDialog			(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
HWND				CreateRpCommandBar(HWND);

// main entry point
int WINAPI WinMain(	HINSTANCE hInstance,
					HINSTANCE hPrevInstance,
					LPTSTR    lpCmdLine,
					int       nCmdShow)
{
	MSG msg;
	HACCEL hAccelTable;

	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}

	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_G723);

	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	return msg.wParam;
}

//
//  FUNCTION: MyRegisterClass()
//  PURPOSE: Registers the window class.
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
	WNDCLASS	wc;

    wc.style			= CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc		= (WNDPROC) WndProc;
    wc.cbClsExtra		= 0;
    wc.cbWndExtra		= 0;
    wc.hInstance		= hInstance;
    wc.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_G723));
    wc.hCursor			= 0;
    wc.hbrBackground	= (HBRUSH) GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName		= 0;
    wc.lpszClassName	= szWindowClass;

	return RegisterClass(&wc);
}

//
//  FUNCTION: InitInstance(HANDLE, int)
//
//  PURPOSE: Saves instance handle and creates main window
//
//  COMMENTS:
//
//    In this function, we save the instance handle in a global variable and
//    create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	HWND	hWnd = NULL;
	TCHAR	szTitle[MAX_LOADSTRING];			
	TCHAR	szWindowClass[MAX_LOADSTRING];		

	/* init main window */
	g_hInst = hInstance;		
	LoadString(hInstance, IDC_G723, szWindowClass, MAX_LOADSTRING);
	LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

	hWnd = FindWindow(szWindowClass, szTitle);	
	if (hWnd) 
	{
		SetForegroundWindow((HWND)((ULONG) hWnd | 0x00000001));
		return 0;
	} 

	MyRegisterClass(hInstance, szWindowClass);
	
	g_hwnd = hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
								 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 
								 CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
	if (!hWnd)
	{	
		return FALSE;
	}
	{
		RECT rc;
		GetWindowRect(hWnd, &rc);
		rc.bottom -= MENU_HEIGHT;
		if (g_hwndCB)
			MoveWindow(hWnd, rc.left, rc.top, rc.right, rc.bottom, FALSE);
	}

	/* establish default settings */
	g_bitrate=IPP_SPCHBR_5300;
	g_dtxEnable=0;

	/* display window */
	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);

	/* display startup prompt */
	ClearStreamProperties();

	return TRUE;
}

//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//  PURPOSE:  Processes messages for the main window.
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	HDC hdc;
	HWND hDlg;
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	TCHAR inputStreamName[MAXFN];
	unsigned int i;

	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			switch (wmId)
			{	
				case IDM_HELP_ABOUT:
					DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				    break;				
				case IDM_FILE_EXIT1:					
					SendMessage(hWnd, WM_ACTIVATE, MAKEWPARAM(WA_INACTIVE, 0), (LPARAM)hWnd);
					SendMessage (hWnd, WM_CLOSE, 0, 0);
					break;
				case IDOK:
					DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
					SendMessage (hWnd, WM_CLOSE, 0, 0);
					SendMessage (hWnd, WM_CLOSE, 0, 0);
					break;
				case IDM_SETTINGS_DTXON1:
					g_dtxEnable=1;										
					//MessageBox(hWnd, _T("DTX Turned On"), _T("DTX Setting"), MB_OK);
					ClearStreamProperties();
					break;
				case IDM_SETTINGS_DTXOFF1:					
					g_dtxEnable=0;
					//MessageBox(hWnd, _T("DTX Turned Off"), _T("DTX Setting"), MB_OK);
					ClearStreamProperties();
					break;
				case IDM_SETTINGS_53KBPS1:										
					g_bitrate=IPP_SPCHBR_5300;
					//MessageBox(hWnd, _T("Bitrate Set to 5.3kbps"), _T("Bitrate Setting"), MB_OK);
					ClearStreamProperties();
					break;
				case IDM_SETTINGS_63KBPS1:					
					g_bitrate=IPP_SPCHBR_6300;
					//MessageBox(hWnd, _T("Bitrate Set to 6.3kbps"), _T("Bitrate Setting"), MB_OK);
					ClearStreamProperties();
					break;
				case IDM_FILE_OPEN1:
					if (!g_busy)
					{
						g_busy=1;

						/* Init codec and streams */
						initCodec_G723( IPP_G723_FRAME_LEN, 
                                        IPP_G723_BITSTREAM_LEN_6300, 
                                        FRAMES_PER_WAVEBUF,
										&g_inputPcmStream, 
										&g_outputBitstream, 
										&g_G723encState, 
										&g_G723decState );

						if ( GetFilePath(hWnd,inputStreamName,_T("pcm stream"),_T("*.in")) )
						{
							/* convert from 16-bit string for PocketPC */
							for(i=0;i<strlen(inputStreamName);i++)
								g_inputPcmStream.pId[i]=(char)inputStreamName[i];
							g_inputPcmStream.pId[i]='\0';
							strcpy(g_filename,inputStreamName);

							/* start encode-decode-playback procedure */
							startCodec_G723(&g_inputPcmStream,
											&g_outputBitstream,
                                            &g_G723encState, 
											&g_G723decState); 				
						}
						else 
						{
							g_busy=0;
						}
					}
					break;
				case IDM_TEST1:
					if (!g_busy)
					{
						/* run test vector compliance tests */
						g_busy=1;
						if (GetTVPath_G723(g_hwnd,g_tvPath))
						{
							hDlg=CreateDialog(g_hInst,(LPCTSTR)IDD_ENCTESTBOX, hWnd, (DLGPROC)TestDialog);
							TestCodecCompliance_G723(ENCODER_TEST,g_tvPath,hDlg);
							TestCodecCompliance_G723(DECODER_TEST,g_tvPath,hDlg);
						}
						g_busy=0;
					}
					break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_CREATE:
			g_hwndCB = CreateRpCommandBar(hWnd);
            // Initialize the shell activate info structure
            memset (&s_sai, 0, sizeof (s_sai));
            s_sai.cbSize = sizeof (s_sai);
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			EndPaint(hWnd, &ps);
			break; 
		case WM_DESTROY:
			CommandBar_Destroy(g_hwndCB);
			PostQuitMessage(0);
			break;
		case WM_ACTIVATE:
			SHHandleWMActivate(hWnd, wParam, lParam, &s_sai, FALSE);
     		break;
		case WM_SETTINGCHANGE:
			SHHandleWMSettingChange(hWnd, wParam, lParam, &s_sai);
     		break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}

// Mesage handler for the test vector compliance testing dialogs
LRESULT CALLBACK TestDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	SHINITDLGINFO shidi;
	switch (message)
	{
		case WM_INITDIALOG:
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_FULLSCREENNOMENUBAR;
			shidi.hDlg = hDlg;
			SHInitDialog(&shidi);
			return TRUE; 
		case WM_PAINT:
			break; 
		case WM_APP:
			break;
		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK)
			{
				DestroyWindow(hDlg);
				return TRUE;
			}
			break;
	}
    return FALSE;
}

// Mesage handler for the About box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	SHINITDLGINFO shidi;

	switch (message)
	{
		case WM_INITDIALOG:
			shidi.dwMask = SHIDIM_FLAGS;
			shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN | SHIDIF_SIZEDLGFULLSCREEN;
			shidi.hDlg = hDlg;
			SHInitDialog(&shidi);
			return TRUE; 

		case WM_COMMAND:
			if (LOWORD(wParam) == IDOK)
			{
				EndDialog(hDlg, LOWORD(wParam));
				g_propertiesDisplayed=0;
				return TRUE;
			}
			break;
	}
    return FALSE;
}

// Command menu initialization
int createMenus(HINSTANCE hi, HWND hw)
{
	HWND h;
	HMENU hMenu;
	HMENU hSubMenu;

	/* Add menu to the top of the screen */
	h=CommandBar_Create(hi,hw,0); 
	hMenu=CreateMenu();

	/* File menu */
	hSubMenu=CreatePopupMenu();
	AppendMenu(hSubMenu,MF_STRING,IDM_FILE_OPEN,_T("&Open"));
	AppendMenu(hSubMenu,MF_STRING,IDM_FILE_EXIT,_T("E&xit"));
	AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT)hSubMenu,_T("&File"));
	
	/* Settings menu */
	hSubMenu = CreatePopupMenu();
	AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT)hSubMenu,_T("&Settings"));

	/* Settings/Bitrate */
	g_hBitrateMenu=CreatePopupMenu();
	AppendMenu(g_hBitrateMenu,MF_STRING,IDM_SETTINGS_53KBPS,_T("5.3 kbps"));
	AppendMenu(g_hBitrateMenu,MF_STRING,IDM_SETTINGS_63KBPS,_T("6.3 kbps"));
	AppendMenu(hSubMenu,MF_STRING|MF_POPUP,(UINT)g_hBitrateMenu,_T("&Bitrate"));

	/* Settings/DTX */
	g_hDtxMenu=CreatePopupMenu();
	AppendMenu(g_hDtxMenu,MF_STRING,IDM_SETTINGS_DTXOFF,_T("Off"));
	AppendMenu(g_hDtxMenu,MF_STRING,IDM_SETTINGS_DTXON,_T("On"));
	AppendMenu(hSubMenu,MF_STRING|MF_POPUP,(UINT)g_hDtxMenu,_T("&DTX"));

	/* Test menu */
	hSubMenu=CreatePopupMenu();
	AppendMenu(hMenu,MF_STRING,IDM_TEST,_T("Test"));

	/* Help menu */
	hSubMenu=CreatePopupMenu();
	AppendMenu(hSubMenu,MF_STRING,IDM_HELP_ABOUT,_T("About..."));
	AppendMenu(hMenu,MF_STRING|MF_POPUP,(UINT)hSubMenu,_T("Help"));

	/* Update menus */
	CommandBar_InsertMenubarEx(h,NULL,(LPTSTR)hMenu,0);
	
	return(1);
}

HWND CreateRpCommandBar(HWND hwnd)
{
	SHMENUBARINFO mbi;

	memset(&mbi, 0, sizeof(SHMENUBARINFO));
	mbi.cbSize     = sizeof(SHMENUBARINFO);
	mbi.hwndParent = hwnd;
	mbi.nToolBarId = IDM_MENU;
	mbi.hInstRes   = g_hInst;
	mbi.nBmpId     = 0;
	mbi.cBmpImages = 0;

	if (!SHCreateMenuBar(&mbi)) 
		return NULL;

	return mbi.hwndMB;
}

⌨️ 快捷键说明

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