Skip to content

Commit

Permalink
tidy: Tweak the allocation of the OutputAudioLoop buffer.
Browse files Browse the repository at this point in the history
Replace over-allocation and manipulation of the buffer starting address
with the C++17 placement new function.
  • Loading branch information
linuxdude42 committed Jul 10, 2022
1 parent ca29373 commit c777f26
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions mythtv/libs/libmyth/audio/audiooutputbase.cpp
Expand Up @@ -38,7 +38,6 @@
#define RPOS (&m_audioBuffer[m_raud])
#define ABUF (m_audioBuffer.data())
#define STST soundtouch::SAMPLETYPE
#define AOALIGN(x) (((long)&(x) + 15) & ~0xf);

// 1,2,5 and 7 channels are currently valid for upmixing if required
static constexpr int UPMIX_CHANNEL_MASK { (1<<1)|(1<<2)|(1<<5)|(1<<7) };
Expand Down Expand Up @@ -1647,9 +1646,8 @@ void AudioOutputBase::GetBufferStatus(uint &fill, uint &total)
*/
void AudioOutputBase::OutputAudioLoop(void)
{
auto *zeros = new uchar[m_fragmentSize];
auto *fragment_buf = new uchar[m_fragmentSize + 16];
auto *fragment = (uchar *)AOALIGN(fragment_buf[0]);
auto *zeros = new(std::align_val_t(16)) uchar[m_fragmentSize];
auto *fragment = new(std::align_val_t(16)) uchar[m_fragmentSize];
memset(zeros, 0, m_fragmentSize);

// to reduce startup latency, write silence in 8ms chunks
Expand Down Expand Up @@ -1727,7 +1725,7 @@ void AudioOutputBase::OutputAudioLoop(void)
}

delete[] zeros;
delete[] fragment_buf;
delete[] fragment;
VBAUDIO("OutputAudioLoop: Stop Event");
OutputEvent e(OutputEvent::Stopped);
dispatch(e);
Expand Down

0 comments on commit c777f26

Please sign in to comment.