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

📄 ch12p1_audioscripts.cpp

📁 游戏音频程序设计-Beginning.Game.Audio.Programming
💻 CPP
字号:
// Ch12p1_AudioScripts.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);
}

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

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

    // load a file
    cout << "Loading Audio Script..." << endl;
    CAudioScriptPtr script = g_AudioMgr.LoadScript("catsfx.spt");
  
    cout << "Routines in this audio script: " << endl;
    vector<string> routines = script->EnumRoutines();
    for (vector<string>::iterator i = routines.begin(); i != routines.end(); ++i) {
      cout << (*i) << endl;
    }
    cout << endl;

    cout << "Variables in this audio script: " << endl;
    vector<string> variables = script->EnumVariables();
    for (vector<string>::iterator z = variables.begin(); z != variables.end(); ++z) {
      cout << (*z) << endl;
    }
    cout << endl;

    // full volume on performance
    GetAudioManager()->SetVolume(CVolume(0));

    bool done=false;
    int catsize = 1;
    
    while (!done) {
      cout << "Select a function to call in the script: " << endl;
      cout << "1) Set cat size (currently " << script->GetVariable("CatSize") << ")" << endl;
      cout << "2) Make cat meow" << endl;
      cout << "3) Exit" << endl;           
      char choice = getch();
      switch(choice) {
      case '1': // set aggression level
        cout << "Enter new cat size: ";
        cin >> catsize;
        script->SetVariable("CatSize", catsize);
        break;

      case '2': // play growl sfx
        cout << "Growling..." << endl;
        script->CallRoutine("sfxCatMeow");
        break;

      case '3': // exit
        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(), "Ch12p1_AudioScripts", MB_ICONSTOP);
    Exit(-1);
  }
  catch(...) {
    MessageBox(GetConsoleWindowHandle(), "This sample program has encountered an error and must close.", "Ch12p1_AudioScripts", MB_ICONSTOP);
    Exit(-1);
  }
  Exit(0);
  return(0); // to avoid warning C4508
}

⌨️ 快捷键说明

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