FMODVoiceAdapter.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. /// \file
  11. /// \brief Connection between FMOD and RakVoice
  12. ///
  13. #ifndef __FMODVOICEBRIDGE_H
  14. #define __FMODVOICEBRIDGE_H
  15. #include "RakVoice.h"
  16. // If you get:
  17. // Error 1 fatal error C1083: Cannot open include file: 'fmod.hpp': No such file or directory c:\raknet\samples\rakvoicefmod\fmodvoiceadapter.h 9
  18. // It is because this project depends on Fmod. If you don't have FMOD you can't use it.
  19. #include "fmod.hpp"
  20. namespace RakNet {
  21. /// \brief Connects FMOD with RakVoice.
  22. class RAK_DLL_EXPORT FMODVoiceAdapter {
  23. public:
  24. // --------------------------------------------------------------------------------------------
  25. // User functions
  26. // --------------------------------------------------------------------------------------------
  27. /// Returns the singleton
  28. static FMODVoiceAdapter* Instance();
  29. /// \brief Setups the connection between FMOD and RakVoice
  30. /// You must call this method to create the connection between FMOD and RakVoice.
  31. /// \param[in] fmodSystem FMOD system object to use.
  32. /// \param[in] rakVoice RakVoice object to use, fully Initialized AND attached to a RakPeerInterface.
  33. /// \pre IMPORTANT : Don't forget to initialized and attach rakVoice, before calling this method.
  34. /// \sa \link FMODVoiceAdapter::Update \endlink
  35. /// \return true on success, false if an error occurred.
  36. bool SetupAdapter(FMOD::System *fmodSystem, RakVoice *rakVoice);
  37. /// Release any resources used.
  38. void Release();
  39. /// You need to call this once in a while, depending on the parameters used. Ex: call once every 20-30 milliseconds
  40. void Update();
  41. /// Turns on/off outgoing traffic
  42. /// \param[in] true to mute, false to allow outgoing traffic.
  43. void SetMute(bool mute);
  44. private:
  45. void UpdateSound(bool isRec);
  46. void BroadcastFrame(void *ptr);
  47. static FMODVoiceAdapter instance;
  48. // As required by the Singleton Pattern, make those ones private,
  49. // to keep the user from creating objects of this class.
  50. FMODVoiceAdapter();
  51. FMODVoiceAdapter(const FMODVoiceAdapter &obj) {};
  52. // FMOD releases all his resources at shutdown, so we don't need to do anything, which
  53. // cames in handy, as we don't need to worry about when to destroy the singleton.
  54. ~FMODVoiceAdapter() {};
  55. RakVoice *rakVoice;
  56. FMOD::System *fmodSystem;
  57. FMOD::Sound *recSound; // sound used for recording
  58. FMOD::Sound *sound; // sound used to play what we hear
  59. FMOD::Channel *channel;
  60. bool mute;
  61. unsigned int lastPlayPos;
  62. unsigned int lastRecordingPos;
  63. };
  64. } // namespace RakNet
  65. #endif
粤ICP备19079148号