BackendHelper.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // Copyright (c) 2019-2021 Ryujinx
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. //
  17. using Ryujinx.Audio.Common;
  18. using System;
  19. namespace Ryujinx.Audio.Backends.Common
  20. {
  21. public static class BackendHelper
  22. {
  23. public static int GetSampleSize(SampleFormat format)
  24. {
  25. return format switch
  26. {
  27. SampleFormat.PcmInt8 => sizeof(byte),
  28. SampleFormat.PcmInt16 => sizeof(ushort),
  29. SampleFormat.PcmInt24 => 3,
  30. SampleFormat.PcmInt32 => sizeof(int),
  31. SampleFormat.PcmFloat => sizeof(float),
  32. _ => throw new ArgumentException($"{format}"),
  33. };
  34. }
  35. public static int GetSampleCount(SampleFormat format, int channelCount, int bufferSize)
  36. {
  37. return bufferSize / GetSampleSize(format) / channelCount;
  38. }
  39. }
  40. }