You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

OpusConverter.cs 1.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. namespace Discord.Audio
  3. {
  4. internal abstract class OpusConverter : IDisposable
  5. {
  6. protected IntPtr _ptr;
  7. public const int SamplingRate = 48000;
  8. public const int Channels = 2;
  9. public const int FrameMillis = 20;
  10. public const int SampleBytes = sizeof(short) * Channels;
  11. public const int FrameSamples = SamplingRate / 1000 * FrameMillis;
  12. public const int FrameSamplesPerChannel = SamplingRate / 1000 * FrameMillis;
  13. public const int FrameBytes = FrameSamples * SampleBytes;
  14. protected bool _isDisposed = false;
  15. protected virtual void Dispose(bool disposing)
  16. {
  17. if (!_isDisposed)
  18. _isDisposed = true;
  19. }
  20. ~OpusConverter()
  21. {
  22. Dispose(false);
  23. }
  24. public void Dispose()
  25. {
  26. Dispose(true);
  27. GC.SuppressFinalize(this);
  28. }
  29. protected static void CheckError(int result)
  30. {
  31. if (result < 0)
  32. throw new Exception($"Opus Error: {(OpusError)result}");
  33. }
  34. protected static void CheckError(OpusError error)
  35. {
  36. if ((int)error < 0)
  37. throw new Exception($"Opus Error: {error}");
  38. }
  39. }
  40. }