Example #1
0
    // Initializes FMOD Studio and loads all sound banks.
    Audio() :
      Listener(system)
    {
      // Create the FMOD Studio system.
      FmodCall(fmod::System::create(&system));
      // Initialize the system.
      FmodCall(system->initialize(
        maxChannels,               // max channels capable of playing audio
        FMOD_STUDIO_INIT_NORMAL,   // studio-specific flags
        FMOD_INIT_3D_RIGHTHANDED,  // regular flags
        nullptr));                 // extra driver data

      vector<fmod::Bank*> banks;

      // For each file in the Sounds directory with a *.bank extension:
      for (const string& file : PathInfo(config::Sounds).FilesWithExtension("bank"))
      {
        // Load the sound bank from file.
        fmod::Bank* bank = nullptr;
        FmodCall(system->loadBankFile(file.c_str(), FMOD_STUDIO_LOAD_BANK_NORMAL, &bank));

        banks.push_back(bank);
      }

      for (fmod::Bank* bank : banks)
      {
        // Get the number of events in the bank.
        int eventCount = 0;
        FmodCall(bank->getEventCount(&eventCount));
        if (eventCount == 0) continue;

        // Get the list of event descriptions from the bank.
        auto eventArray = vector<fmod::EventDescription*>(static_cast<size_t>(eventCount), nullptr);
        FmodCall(bank->getEventList(eventArray.data(), eventArray.size(), nullptr));

        // For each event description:
        for (fmod::EventDescription* eventDescription : eventArray)
        {
          // Get the path to the event, e.g. "event:/Ambience/Country"
          auto path = string(512, ' ');
          int retrieved = 0;
          FmodCall(eventDescription->getPath(&path[0], path.size(), &retrieved));
          path.resize(static_cast<size_t>(retrieved - 1)); // - 1 to account for null character

          // Save the event description in the event map.
          eventDescriptionMap.emplace(path, EventDescription(eventDescription, path));
        }
      }

      Note(*this);
    }