Counter Strike : Global Offensive Source Code
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.

134 lines
3.1 KiB

  1. //========== Copyright � Valve Corporation, All rights reserved. ========
  2. #if !defined( JOB_SNDUPSAMPLER_SHARED_HDR ) && defined( _PS3 )
  3. #define JOB_SNDUPSAMPLER_SHARED_HDR
  4. #include "ps3/spu_job_shared.h"
  5. // the PS3 audio buffer can have either 8 or 16 blocks of 256 samples each.
  6. // The only sample frequency allowed is 48khz, so that's around 23 or 46 milliseconds.
  7. #define CELLAUDIO_PORT_BUFFER_BLOCKS 16
  8. #define SURROUND_HEADPHONES 0
  9. #define SURROUND_STEREO 2
  10. #define SURROUND_DIGITAL5DOT1 5
  11. #define SURROUND_DIGITAL7DOT1 7
  12. // 7.1 means there are a max of 6 channels
  13. #define MAX_DEVICE_CHANNELS 8
  14. /// the libaudio buffers are simply large arrays of float samples.
  15. /// there's only two configurations: two-channel and eight-channel.
  16. /*
  17. * This is disabled as now we are only outputting surround.
  18. * The stereo is pushed in the left and right of the surround structure.
  19. *
  20. struct libaudio_sample_stereo_t
  21. {
  22. float left;
  23. float right;
  24. };
  25. */
  26. struct libaudio_sample_surround_t
  27. {
  28. float left;
  29. float right;
  30. float center;
  31. float subwoofer;
  32. float leftsurround;
  33. float rightsurround;
  34. float leftextend;
  35. float rightextend;
  36. };
  37. namespace job_sndupsampler
  38. {
  39. typedef CellSpursJob256 JobDescriptor_t;
  40. enum ConstEnum_t
  41. {
  42. INPUTFREQ = 44100,
  43. OUTPUTFREQ = 48000,
  44. BUFFERSIZE = 256 * 16, // < input samples, should be a power of two
  45. OUTBUFFERSAMPLES
  46. };
  47. struct BlockTrace_t
  48. {
  49. float m_fractionalSamplesBefore;
  50. uint32 m_n44kSamplesConsumed;
  51. };
  52. struct ALIGN16 JobOutput_t
  53. {
  54. uint32 m_nBlockWritten;
  55. float m_fractionalSamples;
  56. int32 m_ringHead;
  57. int32 m_n44kSamplesConsumed;
  58. BlockTrace_t m_trace[0x10];
  59. }
  60. ALIGN16_POST;
  61. /// ring buffers: one interleaved pair for stereo, or five channels for surround.
  62. /// I compress them back to signed shorts to conserve memory bandwidth.
  63. struct stereosample_t
  64. {
  65. int16 left, right;
  66. };
  67. struct surroundsample_t
  68. {
  69. int16 left, right, center, surleft, surright;
  70. };
  71. struct JobParams_t
  72. {
  73. sys_addr_t m_eaPortBufferAddr; // may change when user switches surround <-> stereo
  74. int32 m_availableInputBlocks;
  75. int32 m_nextBlockIdxToWrite;
  76. float m_volumeFactor;
  77. float m_fractionalSamples;
  78. int32 m_ringHead;
  79. int32 m_ringCount;
  80. float m_flMaxSumStereo;
  81. float m_flBackChannelMultipler;
  82. uint8 m_eaInputSamplesBegin0xF;
  83. uint8 m_nDebuggerBreak;
  84. int8 m_deviceChannels;
  85. int8 m_nCellAudioBlockSamplesLog2;
  86. int8 m_bIsSurround;
  87. public:
  88. inline float *GetEffectiveAddressForBlockIdx( unsigned nBlock )const
  89. {
  90. nBlock %= CELLAUDIO_PORT_BUFFER_BLOCKS;
  91. return reinterpret_cast<float *>( m_eaPortBufferAddr + ( ( nBlock * sizeof(float) * m_deviceChannels ) << m_nCellAudioBlockSamplesLog2 ) );
  92. }
  93. inline bool IsSurround() const
  94. {
  95. return m_bIsSurround;
  96. }
  97. inline int OutputSamplesAvailable()
  98. {
  99. // returns the number of output samples we can generate (notice this rounds down, ie we may leave some fractional samples for next time)
  100. return ( ( m_ringCount - 1 ) * OUTPUTFREQ ) / INPUTFREQ;
  101. }
  102. };
  103. inline JobParams_t * GetJobParams( void *pJob )
  104. {
  105. return VjobGetJobParams< JobParams_t, JobDescriptor_t >( pJob );
  106. }
  107. }
  108. #endif