// --------------------------------------------------------------------------- // Project Name : Nook // File Name : Audio.c // Author : Mary Khuu // Creation Date : 15 Mar 2021 // Purpose : add audio to the game // All content © 2021 DigiPen (USA) Corporation, all rights reserved. // --------------------------------------------------------------------------- #include "fmod.h" #include <stdio.h> // printf() #include <stdbool.h> // FALSE #include "AEEngine.h" #include "Audio.h" FMOD_SYSTEM* soundSystem; FMOD_SOUND* sound; FMOD_CHANNEL* channel; FMOD_RESULT result; // Initialize the Audio System void AudioInit() { channel = 0; // Create and Initialize the FMOD System result = FMOD_System_Create(&soundSystem); void* extradriverdata = 0; result = FMOD_System_Init(soundSystem, 32, FMOD_INIT_NORMAL, extradriverdata); } void playSound(bool trigger, const char* file) { // Create and Play the sound // Note: this should be generalized for multiple sounds and // be placed in a function to be used outside of init. result = FMOD_System_CreateStream(soundSystem, file, FMOD_LOOP_OFF | FMOD_2D, 0, &sound); result = FMOD_System_PlaySound(soundSystem, sound, 0, trigger, &channel); } void playSoundAdvanced(const char* file, float volume) { FMOD_CHANNEL* channel; result = FMOD_System_CreateStream(soundSystem, file, FMOD_LOOP_OFF | FMOD_2D, 0, &sound); result = FMOD_System_PlaySound(soundSystem, sound, 0, true, &channel); result = FMOD_Channel_SetVolume(channel, volume); result = FMOD_Channel_SetPaused(channel, false); } // Update the Audio System // Note: this should be called frequently such as every game loop or // every time a user enters a command depending on the engine void AudioUpdate() { result = FMOD_System_Update(soundSystem); } // Cleanup the Audio System void AudioCleanup() { // Release all sounds that have been created result = FMOD_Sound_Release(sound); // Close and Release the FMOD system result = FMOD_System_Close(soundSystem); result = FMOD_System_Release(soundSystem); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter