PcmExport: use class ConstBuffer
This commit is contained in:
parent
ee7282ce0d
commit
0e756e4377
@ -25,6 +25,7 @@
|
|||||||
#include "util/Manual.hxx"
|
#include "util/Manual.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
|
#include "util/ConstBuffer.hxx"
|
||||||
#include "Log.hxx"
|
#include "Log.hxx"
|
||||||
|
|
||||||
#include <alsa/asoundlib.h>
|
#include <alsa/asoundlib.h>
|
||||||
@ -809,7 +810,9 @@ alsa_play(AudioOutput *ao, const void *chunk, size_t size,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chunk = ad->pcm_export->Export(chunk, size, size);
|
const auto e = ad->pcm_export->Export({chunk, size});
|
||||||
|
chunk = e.data;
|
||||||
|
size = e.size;
|
||||||
|
|
||||||
assert(size % ad->out_frame_size == 0);
|
assert(size % ad->out_frame_size == 0);
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "../OutputAPI.hxx"
|
#include "../OutputAPI.hxx"
|
||||||
#include "mixer/MixerList.hxx"
|
#include "mixer/MixerList.hxx"
|
||||||
#include "system/fd_util.h"
|
#include "system/fd_util.h"
|
||||||
|
#include "util/ConstBuffer.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
#include "util/Macros.hxx"
|
#include "util/Macros.hxx"
|
||||||
@ -728,7 +729,9 @@ oss_output_play(AudioOutput *ao, const void *chunk, size_t size,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
#ifdef AFMT_S24_PACKED
|
#ifdef AFMT_S24_PACKED
|
||||||
chunk = od->pcm_export->Export(chunk, size, size);
|
const auto e = od->pcm_export->Export({chunk, size});
|
||||||
|
chunk = e.data;
|
||||||
|
size = e.size;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "PcmDsdUsb.hxx"
|
#include "PcmDsdUsb.hxx"
|
||||||
#include "PcmPack.hxx"
|
#include "PcmPack.hxx"
|
||||||
#include "util/ByteReverse.hxx"
|
#include "util/ByteReverse.hxx"
|
||||||
|
#include "util/ConstBuffer.hxx"
|
||||||
|
|
||||||
void
|
void
|
||||||
PcmExport::Open(SampleFormat sample_format, unsigned _channels,
|
PcmExport::Open(SampleFormat sample_format, unsigned _channels,
|
||||||
@ -71,59 +72,47 @@ PcmExport::GetFrameSize(const AudioFormat &audio_format) const
|
|||||||
return audio_format.GetFrameSize();
|
return audio_format.GetFrameSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *
|
ConstBuffer<void>
|
||||||
PcmExport::Export(const void *data, size_t size, size_t &dest_size_r)
|
PcmExport::Export(ConstBuffer<void> data)
|
||||||
{
|
{
|
||||||
if (dsd_usb)
|
if (dsd_usb)
|
||||||
data = pcm_dsd_to_usb(dsd_buffer, channels,
|
data.data = pcm_dsd_to_usb(dsd_buffer, channels,
|
||||||
(const uint8_t *)data, size, &size);
|
(const uint8_t *)data.data,
|
||||||
|
data.size, &data.size);
|
||||||
|
|
||||||
if (pack24) {
|
if (pack24) {
|
||||||
assert(size % 4 == 0);
|
const auto src = ConstBuffer<int32_t>::FromVoid(data);
|
||||||
|
const size_t num_samples = src.size;
|
||||||
const size_t num_samples = size / 4;
|
|
||||||
const size_t dest_size = num_samples * 3;
|
const size_t dest_size = num_samples * 3;
|
||||||
|
|
||||||
const uint8_t *src8 = (const uint8_t *)data;
|
|
||||||
const uint8_t *src_end8 = src8 + size;
|
|
||||||
uint8_t *dest = (uint8_t *)pack_buffer.Get(dest_size);
|
uint8_t *dest = (uint8_t *)pack_buffer.Get(dest_size);
|
||||||
assert(dest != nullptr);
|
assert(dest != nullptr);
|
||||||
|
|
||||||
pcm_pack_24(dest, (const int32_t *)src8,
|
pcm_pack_24(dest, src.begin(), src.end());
|
||||||
(const int32_t *)src_end8);
|
|
||||||
|
|
||||||
data = dest;
|
data.data = dest;
|
||||||
size = dest_size;
|
data.size = dest_size;
|
||||||
} else if (shift8) {
|
} else if (shift8) {
|
||||||
assert(size % 4 == 0);
|
const auto src = ConstBuffer<int32_t>::FromVoid(data);
|
||||||
|
|
||||||
const uint8_t *src8 = (const uint8_t *)data;
|
uint32_t *dest = (uint32_t *)pack_buffer.Get(data.size);
|
||||||
const uint8_t *src_end8 = src8 + size;
|
data.data = dest;
|
||||||
const uint32_t *src = (const uint32_t *)src8;
|
|
||||||
const uint32_t *const src_end = (const uint32_t *)src_end8;
|
|
||||||
|
|
||||||
uint32_t *dest = (uint32_t *)pack_buffer.Get(size);
|
for (auto i : src)
|
||||||
data = dest;
|
*dest++ = i << 8;
|
||||||
|
|
||||||
while (src < src_end)
|
|
||||||
*dest++ = *src++ << 8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (reverse_endian > 0) {
|
if (reverse_endian > 0) {
|
||||||
assert(reverse_endian >= 2);
|
assert(reverse_endian >= 2);
|
||||||
|
|
||||||
uint8_t *dest = (uint8_t *)reverse_buffer.Get(size);
|
const auto src = ConstBuffer<uint8_t>::FromVoid(data);
|
||||||
|
|
||||||
|
uint8_t *dest = (uint8_t *)reverse_buffer.Get(data.size);
|
||||||
assert(dest != nullptr);
|
assert(dest != nullptr);
|
||||||
|
data.data = dest;
|
||||||
|
|
||||||
const uint8_t *src = (const uint8_t *)data;
|
reverse_bytes(dest, src.begin(), src.end(), reverse_endian);
|
||||||
const uint8_t *src_end = src + size;
|
|
||||||
reverse_bytes(dest, src, src_end, reverse_endian);
|
|
||||||
|
|
||||||
data = dest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dest_size_r = size;
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
|
|
||||||
struct AudioFormat;
|
struct AudioFormat;
|
||||||
|
template<typename T> struct ConstBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An object that handles export of PCM samples to some instance
|
* An object that handles export of PCM samples to some instance
|
||||||
@ -108,12 +109,9 @@ struct PcmExport {
|
|||||||
*
|
*
|
||||||
* @param state an initialized and open pcm_export_state object
|
* @param state an initialized and open pcm_export_state object
|
||||||
* @param src the source PCM buffer
|
* @param src the source PCM buffer
|
||||||
* @param src_size the size of #src in bytes
|
|
||||||
* @param dest_size_r returns the number of bytes of the destination buffer
|
|
||||||
* @return the destination buffer (may be a pointer to the source buffer)
|
* @return the destination buffer (may be a pointer to the source buffer)
|
||||||
*/
|
*/
|
||||||
const void *Export(const void *src, size_t src_size,
|
ConstBuffer<void> Export(ConstBuffer<void> src);
|
||||||
size_t &dest_size_r);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the number of consumed bytes from the pcm_export()
|
* Converts the number of consumed bytes from the pcm_export()
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include "test_pcm_all.hxx"
|
#include "test_pcm_all.hxx"
|
||||||
#include "pcm/PcmExport.hxx"
|
#include "pcm/PcmExport.hxx"
|
||||||
#include "system/ByteOrder.hxx"
|
#include "system/ByteOrder.hxx"
|
||||||
|
#include "util/ConstBuffer.hxx"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -33,10 +34,9 @@ PcmExportTest::TestShift8()
|
|||||||
PcmExport e;
|
PcmExport e;
|
||||||
e.Open(SampleFormat::S24_P32, 2, false, true, false, false);
|
e.Open(SampleFormat::S24_P32, 2, false, true, false, false);
|
||||||
|
|
||||||
size_t dest_size;
|
auto dest = e.Export({src, sizeof(src)});
|
||||||
auto dest = e.Export(src, sizeof(src), dest_size);
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected), dest.size);
|
||||||
CPPUNIT_ASSERT_EQUAL(sizeof(expected), dest_size);
|
CPPUNIT_ASSERT(memcmp(dest.data, expected, dest.size) == 0);
|
||||||
CPPUNIT_ASSERT(memcmp(dest, expected, dest_size) == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -67,10 +67,9 @@ PcmExportTest::TestPack24()
|
|||||||
PcmExport e;
|
PcmExport e;
|
||||||
e.Open(SampleFormat::S24_P32, 2, false, false, true, false);
|
e.Open(SampleFormat::S24_P32, 2, false, false, true, false);
|
||||||
|
|
||||||
size_t dest_size;
|
auto dest = e.Export({src, sizeof(src)});
|
||||||
auto dest = e.Export(src, sizeof(src), dest_size);
|
CPPUNIT_ASSERT_EQUAL(expected_size, dest.size);
|
||||||
CPPUNIT_ASSERT_EQUAL(expected_size, dest_size);
|
CPPUNIT_ASSERT(memcmp(dest.data, expected, dest.size) == 0);
|
||||||
CPPUNIT_ASSERT(memcmp(dest, expected, dest_size) == 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -91,20 +90,19 @@ PcmExportTest::TestReverseEndian()
|
|||||||
PcmExport e;
|
PcmExport e;
|
||||||
e.Open(SampleFormat::S8, 2, false, false, false, true);
|
e.Open(SampleFormat::S8, 2, false, false, false, true);
|
||||||
|
|
||||||
size_t dest_size;
|
auto dest = e.Export({src, sizeof(src)});
|
||||||
auto dest = e.Export(src, sizeof(src), dest_size);
|
CPPUNIT_ASSERT_EQUAL(sizeof(src), dest.size);
|
||||||
CPPUNIT_ASSERT_EQUAL(sizeof(src), dest_size);
|
CPPUNIT_ASSERT(memcmp(dest.data, src, dest.size) == 0);
|
||||||
CPPUNIT_ASSERT(memcmp(dest, src, dest_size) == 0);
|
|
||||||
|
|
||||||
e.Open(SampleFormat::S16, 2, false, false, false, true);
|
e.Open(SampleFormat::S16, 2, false, false, false, true);
|
||||||
dest = e.Export(src, sizeof(src), dest_size);
|
dest = e.Export({src, sizeof(src)});
|
||||||
CPPUNIT_ASSERT_EQUAL(sizeof(expected2), dest_size);
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected2), dest.size);
|
||||||
CPPUNIT_ASSERT(memcmp(dest, expected2, dest_size) == 0);
|
CPPUNIT_ASSERT(memcmp(dest.data, expected2, dest.size) == 0);
|
||||||
|
|
||||||
e.Open(SampleFormat::S32, 2, false, false, false, true);
|
e.Open(SampleFormat::S32, 2, false, false, false, true);
|
||||||
dest = e.Export(src, sizeof(src), dest_size);
|
dest = e.Export({src, sizeof(src)});
|
||||||
CPPUNIT_ASSERT_EQUAL(sizeof(expected4), dest_size);
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected4), dest.size);
|
||||||
CPPUNIT_ASSERT(memcmp(dest, expected4, dest_size) == 0);
|
CPPUNIT_ASSERT(memcmp(dest.data, expected4, dest.size) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -125,8 +123,7 @@ PcmExportTest::TestDsdUsb()
|
|||||||
PcmExport e;
|
PcmExport e;
|
||||||
e.Open(SampleFormat::DSD, 2, true, false, false, false);
|
e.Open(SampleFormat::DSD, 2, true, false, false, false);
|
||||||
|
|
||||||
size_t dest_size;
|
auto dest = e.Export({src, sizeof(src)});
|
||||||
auto dest = e.Export(src, sizeof(src), dest_size);
|
CPPUNIT_ASSERT_EQUAL(sizeof(expected), dest.size);
|
||||||
CPPUNIT_ASSERT_EQUAL(sizeof(expected), dest_size);
|
CPPUNIT_ASSERT(memcmp(dest.data, expected, dest.size) == 0);
|
||||||
CPPUNIT_ASSERT(memcmp(dest, expected, dest_size) == 0);
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user