diff options
author | Christian Gmeiner <christian.gmeiner@gmail.com> | 2009-02-22 16:58:37 +0100 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2009-02-22 16:58:37 +0100 |
commit | c154d033633e41290b0d5231b94840762666dd76 (patch) | |
tree | 4c3d9ba870fd70c066a5e9f67b85edf634690bf5 | |
parent | 2d405ad8011283e20c50d63eb47741cd5dbcc5c7 (diff) | |
download | vdr-plugin-dxr3-c154d033633e41290b0d5231b94840762666dd76.tar.gz vdr-plugin-dxr3-c154d033633e41290b0d5231b94840762666dd76.tar.bz2 |
Use iAudio class to resample audio stream
With the help of iAudio class, we can factor out the resample
methode and clean up dxr3interface.[ch] a little bit.
-rw-r--r-- | dxr3interface.c | 140 | ||||
-rw-r--r-- | dxr3interface.h | 31 | ||||
-rw-r--r-- | dxr3output-audio.c | 5 |
3 files changed, 20 insertions, 156 deletions
diff --git a/dxr3interface.c b/dxr3interface.c index c69b8eb..9eedf5c 100644 --- a/dxr3interface.c +++ b/dxr3interface.c @@ -560,104 +560,24 @@ void cDxr3Interface::PlayVideoFrame(const uint8_t* pBuf, int length, int times) // ================================== void cDxr3Interface::PlayAudioFrame(cFixedLengthFrame* pFrame) { - // XXX: Call this only with we are not in external mode? - int written = 0; - - if (m_AudioActive) - { - Lock(); - - SetAudioSpeed(pFrame->GetDataRate()); - SetChannelCount(pFrame->GetChannelCount()); - - if (!m_ExternalReleased) - { - if (!cDxr3Interface::Instance().IsAudioModeAC3()) - ResampleVolume((short*)pFrame->GetData(), pFrame->GetCount()); + // TODO can this method get called, when external released? - written = write(m_fdAudio, pFrame->GetData(), pFrame->GetCount()); - if (written == -1) - { - esyslog("dxr3: unable to play audio frame: %m"); - // TODO: Resuscitation() ? - } - else if (written != pFrame->GetCount()) - { - esyslog("dxr3: unable to play whole audio frame, skipped" - " %d bytes", pFrame->GetCount() - written); - } - } - - Unlock(); - } -} + if (m_AudioActive && !m_ExternalReleased) { + Lock(); -// ================================== -void cDxr3Interface::PlayAudioFrame(uint8_t* pBuf, int length) -{ - int written = 0; - Lock(); + SetAudioSpeed(pFrame->GetDataRate()); + SetChannelCount(pFrame->GetChannelCount()); - if (!m_ExternalReleased) - { - if (!cDxr3Interface::Instance().IsAudioModeAC3()) - ResampleVolume((short*)pBuf, length); + int written = write(m_fdAudio, pFrame->GetData(), pFrame->GetCount()); + if (written == -1) { + esyslog("dxr3: unable to play audio frame: %m"); + // TODO: Resuscitation() ? + } else if (written != pFrame->GetCount()) { + esyslog("dxr3: unable to play whole audio frame, skipped" + " %d bytes", pFrame->GetCount() - written); + } - if ((written = write(m_fdAudio, pBuf, length)) == -1) - { - esyslog("dxr3: unable to play audio frame: %m"); - Resuscitation(); - } - else if (written != length) - { - esyslog("dxr3: unable to play whole audio frame, skipped %d bytes", - length - written); - } - } - - Unlock(); -} - -// ================================== -void cDxr3Interface::PlayAudioLpcmFrame(uint8_t* pBuf, int length) -{ - if (length > (LPCM_HEADER_LENGTH + 2)) - { - uint8_t* pFrame = new uint8_t[length - LPCM_HEADER_LENGTH]; - // only even number of bytes are allowed - assert(!((length - LPCM_HEADER_LENGTH) % 2)); - - for (int i = LPCM_HEADER_LENGTH; i < length; i += 2) - { - pFrame[i - LPCM_HEADER_LENGTH] = pBuf[i + 1]; - pFrame[i - LPCM_HEADER_LENGTH + 1] = pBuf[i]; - } - - int codedSpeed = (pBuf[5] >> 4) & 0x03; - int speed = 0; - - switch (codedSpeed) - { - case 1: - speed = 96000; - break; - - case 2: - speed = 44100; - break; - - case 3: - speed = 32000; - break; - - default: - speed = 48000; - break; - } - - SetAudioSpeed(speed); - PlayAudioFrame(pFrame, length - LPCM_HEADER_LENGTH); - delete[] pFrame; + Unlock(); } } @@ -701,8 +621,6 @@ void cDxr3Interface::ClaimDevices() m_AudioActive = false; m_VideoActive = false; m_ExternalReleased = false; - m_volume = 255; - m_audioChannel = AUDIO_STEREO; m_horizontal = 720; m_vertical = 576; m_audioChannelCount = UNKNOWN_CHANNEL_COUNT; @@ -1009,36 +927,6 @@ void cDxr3Interface::Resuscitation() } // ================================== -//! pcm resampling function -void cDxr3Interface::ResampleVolume(short* pcmbuf, int size) -{ - if (m_volume == 0) - { - memset(pcmbuf, 0, size); - } - if (m_volume < 255 || m_audioChannel != AUDIO_STEREO) - { - int factor = (int)pow (2.0, (double)m_volume/32 + 8.0) - 1; - //int factor = (int)pow (2.0, (double)m_volume/16) - 1; - for (int i = 0; i < size / (int)sizeof(short); i++) - { - if (m_audioChannel == AUDIO_MONO_RIGHT && !(i & 0x1)) - { - pcmbuf[i] = pcmbuf[i+1]; - } - if (m_audioChannel == AUDIO_MONO_LEFT && (i & 0x1)) - { - pcmbuf[i] = pcmbuf[i-1]; - } - else if (m_volume < 255) - { - pcmbuf[i] = (((int)pcmbuf[i]) * factor) / 65536; - } - } - } -} - -// ================================== void cDxr3Interface::ClearOsd() { encodedata ed; diff --git a/dxr3interface.h b/dxr3interface.h index 4f13bee..3124264 100644 --- a/dxr3interface.h +++ b/dxr3interface.h @@ -77,30 +77,8 @@ public: void SetAudioDigitalPCM(); void SetAudioDigitalAC3(); int GetAudioMode(); - int IsAudioModeAnalog() - { - return GetAudioMode() == EM8300_AUDIOMODE_ANALOG; - } - int IsAudioModePCM() - { - return GetAudioMode() == EM8300_AUDIOMODE_DIGITALPCM; - } - int IsAudioModeAC3() - { - return GetAudioMode() == EM8300_AUDIOMODE_DIGITALAC3; - } - void SetVolume(int volume) - { - m_volume = volume; - } - void SetAudioChannel(int audiochannel) - { - m_audioChannel = audiochannel; - } - int GetAudioChannel(void) - { - return m_audioChannel; - } + int IsAudioModeAC3() { return GetAudioMode() == EM8300_AUDIOMODE_DIGITALAC3; } + void SetAudioSpeed(uint32_t speed); void SetChannelCount(uint32_t count); void SetAudioSampleSize(uint32_t sampleSize); @@ -156,8 +134,6 @@ public: void PlayVideoFrame(cFixedLengthFrame* pFrame, int times = 1); void PlayVideoFrame(const uint8_t* pBuf, int length, int times = 1); void PlayAudioFrame(cFixedLengthFrame* pFrame); - void PlayAudioFrame(uint8_t* pBuf, int length); - void PlayAudioLpcmFrame(uint8_t* pBuf, int length); // external device access void ExternalReleaseDevices(); @@ -212,8 +188,6 @@ private: uint32_t m_audioMode; uint32_t m_spuMode; bool m_ExternalReleased; ///< is dxr3 used by e.g. mplayer? - int m_volume; ///< volumevalue (0...255) - int m_audioChannel; ///> 0=stereo, 1=left, 2=right audio channel bool m_AudioActive; ///< is audio active? bool m_VideoActive; ///< is video active? @@ -226,7 +200,6 @@ private: void UploadMicroCode(); void ConfigureDevice(); void ConfigureDeviceAudio(); - void ResampleVolume(short* pcmbuf, int size); void ClaimDevices(); void ReleaseDevices(); void Resuscitation(); diff --git a/dxr3output-audio.c b/dxr3output-audio.c index f267003..af1a879 100644 --- a/dxr3output-audio.c +++ b/dxr3output-audio.c @@ -106,7 +106,10 @@ void cDxr3AudioOutThread::Action() void cDxr3AudioOutThread::PlayFrame(cFixedLengthFrame *frame) { - audioOutput->changeVolume((short *)frame->GetData(), (size_t)frame->GetCount()); + if (!cDxr3Interface::Instance().IsAudioModeAC3()) { + audioOutput->changeVolume((short *)frame->GetData(), (size_t)frame->GetCount()); + } + m_dxr3Device.PlayAudioFrame(frame); } |