Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
4.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef VOICE_H
  8. #define VOICE_H
  9. #pragma once
  10. #include "ivoicetweak.h"
  11. /*! @defgroup Voice Voice
  12. Defines the engine's interface to the voice code.
  13. @{
  14. */
  15. // Voice_Init will pick a sample rate, it must be within RATE_MAX
  16. #define VOICE_OUTPUT_SAMPLE_RATE_LOW 11025 // Sample rate that we feed to the mixer.
  17. #define VOICE_OUTPUT_SAMPLE_RATE_HIGH 22050 // Sample rate that we feed to the mixer.
  18. #define VOICE_OUTPUT_SAMPLE_RATE_MAX 22050 // Sample rate that we feed to the mixer.
  19. //! Returned on error from certain voice functions.
  20. #define VOICE_CHANNEL_ERROR -1
  21. #define VOICE_CHANNEL_IN_TWEAK_MODE -2 // Returned by AssignChannel if currently in tweak mode (not an error).
  22. //! Initialize the voice code.
  23. bool Voice_Init( const char *pCodec, int nSampleRate );
  24. //! Inits voice with defaults if it is not initialized normally, e.g. for local mixer use.
  25. void Voice_ForceInit();
  26. //! Get the default sample rate to use for this codec
  27. inline int Voice_GetDefaultSampleRate( const char *pCodec ) // Inline for DEDICATED builds
  28. {
  29. // Use legacy lower rate for speex
  30. if ( Q_stricmp( pCodec, "vaudio_speex" ) == 0 )
  31. {
  32. return VOICE_OUTPUT_SAMPLE_RATE_LOW;
  33. }
  34. else if ( Q_stricmp( pCodec, "steam" ) == 0 )
  35. {
  36. return 0; // For the steam codec, 0 passed to voice_init means "use optimal steam voice rate"
  37. }
  38. // Use high sample rate by default for other codecs.
  39. return VOICE_OUTPUT_SAMPLE_RATE_HIGH;
  40. }
  41. //! Shutdown the voice code.
  42. void Voice_Deinit();
  43. //! Returns true if the client has voice enabled
  44. bool Voice_Enabled( void );
  45. //! The codec voice was initialized with. Empty string if voice is not initialized.
  46. const char *Voice_ConfiguredCodec();
  47. //! The sample rate voice was initialized with. -1 if voice is not initialized.
  48. int Voice_ConfiguredSampleRate();
  49. //! Returns true if the user can hear themself speak.
  50. bool Voice_GetLoopback();
  51. //! This is called periodically by the engine when the server acks the local player talking.
  52. //! This tells the client DLL that the local player is talking and fades after about 200ms.
  53. void Voice_LocalPlayerTalkingAck();
  54. //! Call every frame to update the voice stuff.
  55. void Voice_Idle(float frametime);
  56. //! Returns true if mic input is currently being recorded.
  57. bool Voice_IsRecording();
  58. //! Begin recording input from the mic.
  59. bool Voice_RecordStart(
  60. //! Filename to store incoming mic data, or NULL if none.
  61. const char *pUncompressedFile,
  62. //! Filename to store the output of compression and decompressiong with the codec, or NULL if none.
  63. const char *pDecompressedFile,
  64. //! If this is non-null, the voice manager will use this file for input instead of the mic.
  65. const char *pMicInputFile
  66. );
  67. // User wants to stop recording
  68. void Voice_UserDesiresStop();
  69. //! Stop recording from the mic.
  70. bool Voice_RecordStop();
  71. //! Get the most recent N bytes of compressed data. If nCount is less than the number of
  72. //! available bytes, it discards the first bytes and gives you the last ones.
  73. //! Set bFinal to true on the last call to this (it will flush out any stored voice data).
  74. int Voice_GetCompressedData(char *pchData, int nCount, bool bFinal);
  75. //! Pass incoming data from the server into here.
  76. //! The data should have been compressed and gotten through a Voice_GetCompressedData call.
  77. int Voice_AddIncomingData(
  78. //! Channel index.
  79. int nChannel,
  80. //! Compressed data to add to the channel.
  81. const char *pchData,
  82. //! Number of bytes in pchData.
  83. int nCount,
  84. //! Sequence number. If a packet is missed, it adds padding so the time isn't squashed.
  85. int iSequenceNumber
  86. );
  87. //! Call this to reserve a voice channel for the specified entity to talk into.
  88. //! \return A channel index for use with Voice_AddIncomingData or VOICE_CHANNEL_ERROR on error.
  89. int Voice_AssignChannel(int nEntity, bool bProximity );
  90. //! Call this to get the channel index that the specified entity is talking into.
  91. //! \return A channel index for use with Voice_AddIncomingData or VOICE_CHANNEL_ERROR if the entity isn't talking.
  92. int Voice_GetChannel(int nEntity);
  93. #if !defined( NO_VOICE )
  94. extern IVoiceTweak g_VoiceTweakAPI;
  95. extern bool g_bUsingSteamVoice;
  96. #endif
  97. /*! @} */
  98. #endif // VOICE_H