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.

111 lines
3.6 KiB

  1. //========= Copyright � Valve Corporation, All rights reserved. ============//
  2. #ifndef ENGINE_AUDIO_PRIVATE_SND_PS3_MP3DEC_HDR
  3. #define ENGINE_AUDIO_PRIVATE_SND_PS3_MP3DEC_HDR
  4. #ifndef _PS3
  5. #error "This header is for PS/3 target only"
  6. #endif
  7. #include "vjobs_interface.h"
  8. #include "vjobs/mp3dec_shared.h"
  9. #include "sys/timer.h"
  10. #include "tier1/checksum_crc.h"
  11. typedef job_mp3dec::Joblet_t Mp3DecJoblet;
  12. typedef job_mp3dec::Context_t Mp3DecContext;
  13. struct Mp3DecMgr: public VJobInstance
  14. {
  15. void Init();
  16. void Shutdown();
  17. void OnVjobsInit(); // gets called after m_pRoot was created and assigned
  18. void OnVjobsShutdown(); // gets called before m_pRoot is about to be destructed and NULL'ed
  19. Mp3DecJoblet * NewDecode( uint nFlags = Mp3DecJoblet::FLAGS_MONO_OR_STEREO );
  20. void KickPending();
  21. void DeleteDecode( Mp3DecJoblet *pJoblet );
  22. void Wait( Mp3DecJoblet * pJoblet ){ while( !pJoblet->IsComplete() ) sys_timer_usleep( 60 ); }
  23. // wait for all pending jobslets to finish
  24. void Finish(){ while( GetWorkerJobParams()->m_nPut != GetWorkerJobParams()->m_nGet ) sys_timer_usleep( 60 ); }
  25. void EnterWorkerLock(){ cellAtomicIncr32( &GetWorkerJobParams()->m_nWorkerLock ); }
  26. void LeaveWorkerLock(){ cellAtomicDecr32( &GetWorkerJobParams()->m_nWorkerLock ); }
  27. int GetNumberOfJobletsForDebugging() const { return JOBLET_COUNT; }
  28. const Mp3DecJoblet & GetJobletForDebugging( int nJobLetIndex ) const { return m_joblets[ nJobLetIndex ]; }
  29. protected:
  30. job_mp3dec::JobParams_t *GetWorkerJobParams(){ return job_mp3dec::GetJobParams( &m_jobWorker ); }
  31. void StartMsfTest( const char * pInputFile, const char * pOutputExtension, int nMode );
  32. protected:
  33. CRC32_t m_nDecoderCrc;
  34. uint m_nAllocatedNotKicked;
  35. int m_nDecoderSize;
  36. uint m_nMaxSpuWorkers;
  37. job_mp3dec::JobParams_t *m_pWorkerParams;
  38. job_mp3dec::JobDescriptor_t m_jobWorker;
  39. enum ConstEnum_t{ JOBLET_COUNT = job_mp3dec::JobParams_t::JOBLET_COUNT };
  40. Mp3DecJoblet m_joblets[JOBLET_COUNT];
  41. };
  42. const int NUMBER_OF_MP3_DECODER_SLOTS = 4; // We will allow for 4 decoding at a time (using up to 4 SPUs)
  43. extern Mp3DecMgr g_mp3dec[NUMBER_OF_MP3_DECODER_SLOTS];
  44. struct RiffWavHeader
  45. {
  46. uint32 m_nRiff; // 'RIFF'
  47. uint32 m_nChunkSizeLE;
  48. uint32 m_nFormat; // 'WAVE'
  49. uint32 m_nSubchunk1ID; // 'fmt '
  50. uint32 m_nSubchunk1SizeLE;
  51. uint16 m_nAudioFormat; // 1
  52. uint16 m_nNumChannels;
  53. uint32 m_nSampleRate;
  54. uint32 m_nByteRate;
  55. uint16 m_nBlockAlign;
  56. uint16 m_nBitsPerSample;
  57. uint32 m_nSubchankData;
  58. uint32 m_nSubchunk2Size;
  59. static uint32 Swap32( uint32 a )
  60. {
  61. return ( a >> 24 ) | ( ( a >> 8 ) & 0xFF00 ) | ( ( a << 8 ) & 0xFF0000 ) | ( a << 24 );
  62. }
  63. static uint16 Swap16( uint16 a )
  64. {
  65. return ( ( a & 0xFF ) << 8 ) | ( ( a >> 8 ) & 0xFF );
  66. }
  67. void Init( uint nNumSamples, uint nNumChannels, uint nBitsPerSample, uint nSampleRate ) // == NumSamples * NumChannels * BitsPerSample/8
  68. {
  69. m_nRiff = 0x52494646;
  70. uint nDataSize = nNumSamples * nNumChannels * nBitsPerSample/8;
  71. m_nChunkSizeLE = Swap32( 36 + nDataSize );
  72. m_nFormat = 0x57415645;
  73. m_nSubchunk1ID = 0x666d7420;
  74. m_nSubchunk1SizeLE = Swap32( 16 );
  75. m_nAudioFormat = 0x0100; // PCM
  76. m_nNumChannels = Swap16( nNumChannels );
  77. m_nSampleRate = Swap32( nSampleRate );
  78. m_nByteRate = Swap32( nSampleRate * nNumChannels * nBitsPerSample / 8 );
  79. m_nBlockAlign = Swap16( nNumChannels * nBitsPerSample / 8 );
  80. m_nBitsPerSample = Swap16( nBitsPerSample );
  81. m_nSubchankData = 0x64617461; // 'data'
  82. m_nSubchunk2Size = Swap32( nNumSamples * nNumChannels * nBitsPerSample / 8 );
  83. COMPILE_TIME_ASSERT( sizeof( *this ) == 44 );
  84. }
  85. };
  86. // This function skips ID3 tag version2.x
  87. uint8* SkipId3Tag( uint8 * pMp3header );
  88. #endif