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

📄 perf.cpp

📁 WINCE XAUDIO可播放各种音乐格式内附SOURCE CODE可以再不同CPU 平台编译测试
💻 CPP
字号:
/*****************************************************************
|
|      Xaudio Player for Windows CE
|      Performance Tests      
|
|      (c) 1996-1998 MpegTV, LLC
|      Author: Gilles Boccon-Gibod (gilles@mpegtv.com)
|
 ****************************************************************/

/*----------------------------------------------------------------------
|       includes
+---------------------------------------------------------------------*/
#ifndef STRICT
#define STRICT
#endif

#include "xaplayer.h"
#include "decoder.h"
#include "file_input.h"
#include "audio_output.h"
#include "mpeg_codec.h"
#include "control.h"
#include "ceutils.h"
#include <commdlg.h>
#include <tchar.h>

/*----------------------------------------------------------------------
|       Globals
+---------------------------------------------------------------------*/
static TCHAR *FileName;

/*----------------------------------------------------------------------
|       DoTest
+---------------------------------------------------------------------*/
static int
DoTest(HWND progress_bar, int quality, int channels, BOOL output_sound)
{
    USES_CONVERSION;
    XA_DecoderInfo *decoder;
    int             status; 
    DWORD           before;
    DWORD           after;
    int             result;
    int             counter = 0;

    /* create a decoder */
    if (decoder_new(&decoder) != XA_SUCCESS) {
        return 0;
    }
    
    /* set the codec quality */
    decoder_codec_set_quality(decoder, quality);

    /* set the channels */
    decoder_codec_set_channels(decoder, (XA_OutputChannelsMode)channels);

    /* register the file input module */
    {
        XA_InputModule module;

        file_input_module_register(&module);
        decoder_input_module_register(decoder, &module);
    }


    /* register the audio output module */
    if (output_sound) {
        XA_OutputModule module;

        audio_output_module_register(&module);
        decoder_output_module_register(decoder, &module);
    }

    /* register the codec modules */
    {
        XA_CodecModule module;
        mpeg_codec_module_register(&module);
        decoder_codec_module_register(decoder, &module);
    }

    /* create and open input object */
    status = decoder_input_new(decoder, W2A(FileName),
                               XA_DECODER_INPUT_AUTOSELECT);
    if (status != XA_SUCCESS) {
        return 0;
    }
    if (decoder_input_open(decoder) != XA_SUCCESS) {
        return 0;
    }

    if (output_sound) {
        /* create and open output object */
        status = decoder_output_new(decoder, "/dev/wave/0", XA_DECODER_OUTPUT_AUTOSELECT);
        if (status != XA_SUCCESS) {
            return 0;
        }
        if (decoder_output_open(decoder) != XA_SUCCESS) {
            return 0;
        }
    }

    /* loop until there is an error */
    before = GetTickCount();
    if (output_sound) {
        do {
            status = decoder_play(decoder);
            if ((counter++ % 40) == 0 && decoder->input->size) {
                SendMessage(progress_bar, PBM_SETPOS, 
                            (100*decoder->input->offset)/decoder->input->size, 0);
            }
        } while (status == XA_SUCCESS ||
                 status == XA_ERROR_INVALID_FRAME);
    } else {
        do {
            status = decoder_decode(decoder, NULL);
            if ((counter++ % 40) == 0 && decoder->input->size) {
                SendMessage(progress_bar, PBM_SETPOS, 
                            (100*decoder->input->offset)/decoder->input->size, 0);
            }
        } while (status == XA_SUCCESS ||
                 status == XA_ERROR_INVALID_FRAME);
    }

    if (output_sound) {
        decoder_output_set_control(decoder, NULL, XA_DECODER_CONTROL_DRAIN);
    }

    after = GetTickCount();
    result = (100*(after-before))/decoder->status->info.duration;
    {
        unsigned short s[128];
        if (output_sound) {
            swprintf(s, TEXT("Stream Duration = %d msecs\nPlay Time = %d"), 
                     decoder->status->info.duration, after-before);
        } else {
            swprintf(s, TEXT("Stream Duration = %d msecs\nDecode Time = %d millesconds\n%d%% CPU"),
                     decoder->status->info.duration, after-before, result);
        }
        MessageBox(NULL, s, TEXT("Results"), MB_OK | MB_APPLMODAL | MB_TOPMOST);
    }
    decoder_output_close(decoder);
    decoder_delete(decoder);

    return result;
}

/*----------------------------------------------------------------------
|       PerforamceTestsDialogProc
+---------------------------------------------------------------------*/
static BOOL CALLBACK 
PerforamceTestsDialogProc(HWND window, UINT message, 
                          WPARAM wparam, LPARAM lparam)
{
    static HWND quality_radios[3];
    static HWND channels_radios[3];
    int    play_sound = 0;

    switch (message) {
      case WM_INITDIALOG: {
          quality_radios[0] = GetDlgItem(window, IDC_RADIO_QUALITY_HIGH);
          quality_radios[1] = GetDlgItem(window, IDC_RADIO_QUALITY_MEDIUM);
          quality_radios[2] = GetDlgItem(window, IDC_RADIO_QUALITY_LOW);
          channels_radios[0] = GetDlgItem(window, IDC_RADIO_STEREO);
          channels_radios[1] = GetDlgItem(window, IDC_RADIO_MIX);
          channels_radios[2] = GetDlgItem(window, IDC_RADIO_MONO);

          SendMessage(quality_radios[0], BM_SETCHECK, 1, 0);
          SendMessage(channels_radios[0], BM_SETCHECK, 1, 0);
      }
      break;

      case WM_COMMAND:
        switch (LOWORD(wparam)) {
          case IDOK:
          case IDCANCEL:
            EndDialog(window, 0);
            break;
          case IDC_PLAY_SOUND_BUTTON:
              play_sound = 1;
              /* fallthrough */
          case IDC_START_BUTTON: {
            int result;
            int quality;
            int channels;

            if (SendMessage(channels_radios[0], BM_GETCHECK, 0, 0)) {
                channels = XA_OUTPUT_STEREO;
            } else if (SendMessage(channels_radios[1], BM_GETCHECK, 0, 0)) {
                channels = XA_OUTPUT_MONO_MIX;
            } else {
                channels = XA_OUTPUT_MONO_LEFT;
            }

            if (SendMessage(quality_radios[0], BM_GETCHECK, 0, 0)) {
                quality = XA_DECODER_CODEC_QUALITY_HIGH;
            } else if (SendMessage(quality_radios[1], BM_GETCHECK, 0, 0)) {
                quality = XA_DECODER_CODEC_QUALITY_MEDIUM;
            } else {
                quality = XA_DECODER_CODEC_QUALITY_LOW;
            }

            result = DoTest(GetDlgItem(window, IDC_PROGRESS_BAR), quality, channels, play_sound);
            break;
            }
        }
        break;
    }

    return FALSE;
}

/*----------------------------------------------------------------------
|       DoPerformanceTests
+---------------------------------------------------------------------*/
void
DoPerformanceTests(HINSTANCE instance, HWND parent)
{
    BOOL         result;
	TCHAR        file[MAX_PATH] = TEXT("\0");
	OPENFILENAME ofn;
	
	memset(&(ofn), 0, sizeof(ofn));
	ofn.lStructSize	= sizeof(ofn);
	ofn.hwndOwner   = parent;
    ofn.lpstrFile   = file;
    ofn.nMaxFile    = MAX_PATH;	
    ofn.lpstrFilter = TEXT("MP3 Files (*.mp3)\0*.mp3\0MP2 Files (*.mp2)\0*.mp2\0MP1 Files (*.mp1)\0*.mp1\0All (*.*)\0*.*\0\0");	
    ofn.lpstrTitle  = TEXT("Open File");
    ofn.Flags       = OFN_EXPLORER;

    result = GetOpenFileName(&ofn);
    if (result == 0) return;

    FileName = ofn.lpstrFile;
    DialogBox(instance, 
              ID(IDD_OPTIONS_PERF_TESTS_DIALOG), 
              parent, 
              PerforamceTestsDialogProc);
}

⌨️ 快捷键说明

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