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

📄 ch11p1_dynamicmusic.cpp

📁 游戏音频程序设计-Beginning.Game.Audio.Programming
💻 CPP
字号:
// Ch11p1_DynamicMusic.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <sstream>
#include <string>
#include <math.h>
#include <conio.h>
#include <windows.h>
#include <mmreg.h>

#include "dsound.h"
#include "dxerr8.h"
#include "AudioEngine/dxutil.h"
#include "AudioEngine/AudioEngine.h"

using namespace std;
using namespace AudioEngine;

CAudioManager g_AudioMgr;
CAudioManager *AudioEngine::GetAudioManager() { return(&g_AudioMgr); }

void Exit(int errorcode)
{
  #ifdef _DEBUG
  cout << endl << endl << "(Program ended, press a key to exit.)";
  // so that the console window doesn't disappear before we have
  // a chance to look at it.
  getch(); 
#endif

  exit(errorcode);
}

HWND GetConsoleWindowHandle()
{
  char title[512];
  HWND hWnd;
 
  GetConsoleTitle(title, sizeof(title));
  hWnd = FindWindow(NULL, title);
  return(hWnd);
}

void main(int argc, char* argv[])
{
  
  try {

    // initialize audio manager
    cout << "Initializing Audio Manager..." << endl;
    g_AudioMgr.Init(GetConsoleWindowHandle());

    // load a file
    cout << "Loading Dynamic Music..." << endl;
    CSoundPtr snd = g_AudioMgr.LoadDynamicMusic("HappySegment.sgt");
  
    // full volume on performance
    GetAudioManager()->SetVolume(CVolume(0));

    cout << "Playing..." << endl;
    snd->Play();

    Sleep(500); // let the sound start playing

    bool done=false;
    CDynamicMusic *dynmusic = dynamic_cast<CDynamicMusic *>(snd.Get());

    while (!done) {
      cout << endl;
      cout << "Groove Level is now: " << GetAudioManager()->GetPerformanceGrooveLevelModifier() << endl << "(be patient if you just changed the groove level!)" << endl;
      cout << "1) Change to low groove level" << endl;
      cout << "2) Change to high groove level" << endl;
      cout << "3) Play Motif" << endl;
      cout << "4) Exit" << endl; 
      char choice = getch();
      switch(choice) {
      case '1':
        GetAudioManager()->SetPerformanceGrooveLevelModifier(0);
        break;

      case '2':
        GetAudioManager()->SetPerformanceGrooveLevelModifier(10);
        break;

      case '3': // play motif
        if (dynmusic) dynmusic->PlayMotif("Motif1");
        break;

      case '4':
        done=true;
        break;
      }

    }
    
    if (kbhit()) getch();
  
    // uninit audio manager
    cout << endl << "UnIniting audio manager..." << endl;
    g_AudioMgr.UnInit();

  } 
  catch(CError &e) {
    MessageBox(GetConsoleWindowHandle(), e.GetMessageBoxString().c_str(), "Ch11p1_DynamicMusic", MB_ICONSTOP);
    Exit(-1);
  }
  catch(...) {
    MessageBox(GetConsoleWindowHandle(), "This sample program has encountered an error and must close.", "Ch11p1_DynamicMusic", MB_ICONSTOP);
    Exit(-1);
  }
  Exit(0);
}

⌨️ 快捷键说明

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