diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /engine/audio/private/snd_wave_mixer_mp3.h | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'engine/audio/private/snd_wave_mixer_mp3.h')
| -rw-r--r-- | engine/audio/private/snd_wave_mixer_mp3.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/engine/audio/private/snd_wave_mixer_mp3.h b/engine/audio/private/snd_wave_mixer_mp3.h new file mode 100644 index 0000000..1138c25 --- /dev/null +++ b/engine/audio/private/snd_wave_mixer_mp3.h @@ -0,0 +1,59 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: Mixer for ADPCM encoded audio +// +//=============================================================================// + +#ifndef SND_WAVE_MIXER_MP3_H +#define SND_WAVE_MIXER_MP3_H +#pragma once + +#include "vaudio/ivaudio.h" + +static const int MP3_BUFFER_SIZE = 16384; + +class CAudioMixerWaveMP3 : public CAudioMixerWave, public IAudioStreamEvent +{ +public: + CAudioMixerWaveMP3( IWaveData *data ); + ~CAudioMixerWaveMP3( void ); + + virtual void Mix( IAudioDevice *pDevice, channel_t *pChannel, void *pData, int outputOffset, int inputOffset, fixedint fracRate, int outCount, int timecompress ); + virtual int GetOutputData( void **pData, int sampleCount, char copyBuf[AUDIOSOURCE_COPYBUF_SIZE] ); + + // need to override this to fixup blocks + // UNDONE: This doesn't quite work with MP3 - we need a MP3 position, not a sample position + void SetSampleStart( int newPosition ); + + int GetPositionForSave() { return GetStream() ? GetStream()->GetPosition() : 0; } + void SetPositionFromSaved(int position) { if ( GetStream() ) GetStream()->SetPosition(position); } + + // IAudioStreamEvent + virtual int StreamRequestData( void *pBuffer, int bytesRequested, int offset ); + + virtual void SetStartupDelaySamples( int delaySamples ); + virtual int GetMixSampleSize() { return CalcSampleSize( 16, m_channelCount ); } + + virtual int GetStreamOutputRate() { return GetStream() ? GetStream()->GetOutputRate() : 0; } + +private: + IAudioStream *GetStream(); + bool DecodeBlock( void ); + void GetID3HeaderOffset(); + + // Lazily initialized, use GetStream + IAudioStream *m_pStream; + bool m_bStreamInit; + + char m_samples[MP3_BUFFER_SIZE]; + int m_sampleCount; + int m_samplePosition; + int m_channelCount; + int m_offset; + int m_delaySamples; + int m_headerOffset; +}; + +CAudioMixerWaveMP3 *CreateMP3Mixer( IWaveData *data ); + +#endif // SND_WAVE_MIXER_MP3_H |