2014-08-23 14:42:23 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2009, 2011 Sebastian Gesemann. All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
conditions and the following disclaimer.
|
|
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer in the documentation and/or other materials
|
|
|
|
provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY SEBASTIAN GESEMANN ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SEBASTIAN GESEMANN OR
|
|
|
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those of the
|
|
|
|
authors and should not be interpreted as representing official policies, either expressed
|
|
|
|
or implied, of Sebastian Gesemann.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2011-10-03 12:03:37 +02:00
|
|
|
#ifndef DSD2PCM_H_INCLUDED
|
|
|
|
#define DSD2PCM_H_INCLUDED
|
|
|
|
|
2020-01-14 23:29:03 +01:00
|
|
|
#include "ChannelDefs.hxx"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
2011-10-03 12:03:37 +02:00
|
|
|
#include <stddef.h>
|
2020-01-14 22:36:50 +01:00
|
|
|
#include <stdint.h>
|
2011-10-03 12:03:37 +02:00
|
|
|
|
|
|
|
/**
|
2020-01-14 22:16:02 +01:00
|
|
|
* A "dsd2pcm engine" for one channel.
|
2011-10-03 12:03:37 +02:00
|
|
|
*/
|
2020-01-14 22:16:02 +01:00
|
|
|
class Dsd2Pcm {
|
|
|
|
public:
|
|
|
|
/* must be a power of two */
|
2020-01-14 22:39:12 +01:00
|
|
|
static constexpr size_t FIFOSIZE = 16;
|
2020-01-14 22:16:02 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/** bit mask for FIFO offsets */
|
|
|
|
static constexpr size_t FIFOMASK = FIFOSIZE - 1;
|
|
|
|
|
2020-01-14 22:36:50 +01:00
|
|
|
uint8_t fifo[FIFOSIZE];
|
2020-01-14 22:37:30 +01:00
|
|
|
size_t fifopos;
|
2020-01-14 22:16:02 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
Dsd2Pcm() noexcept {
|
|
|
|
Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* resets the internal state for a fresh new stream
|
|
|
|
*/
|
|
|
|
void Reset() noexcept;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "translates" a stream of octets to a stream of floats
|
|
|
|
* (8:1 decimation)
|
|
|
|
* @param ctx -- pointer to abstract context (buffers)
|
|
|
|
* @param samples -- number of octets/samples to "translate"
|
|
|
|
* @param src -- pointer to first octet (input)
|
|
|
|
* @param src_stride -- src pointer increment
|
|
|
|
* @param dst -- pointer to first float (output)
|
|
|
|
* @param dst_stride -- dst pointer increment
|
|
|
|
*/
|
|
|
|
void Translate(size_t samples,
|
2020-01-14 22:36:50 +01:00
|
|
|
const uint8_t *src, ptrdiff_t src_stride,
|
2020-01-14 22:16:02 +01:00
|
|
|
float *dst, ptrdiff_t dst_stride) noexcept;
|
2020-01-14 22:25:54 +01:00
|
|
|
|
|
|
|
private:
|
2020-01-14 22:43:11 +01:00
|
|
|
void ApplySample(size_t ffp, uint8_t src) noexcept;
|
2020-01-14 22:37:30 +01:00
|
|
|
float CalcOutputSample(size_t ffp) const noexcept;
|
2020-01-14 22:47:30 +01:00
|
|
|
float TranslateSample(size_t ffp, uint8_t src) noexcept;
|
2020-01-14 22:16:02 +01:00
|
|
|
};
|
2011-10-03 12:03:37 +02:00
|
|
|
|
2020-01-14 23:29:03 +01:00
|
|
|
class MultiDsd2Pcm {
|
|
|
|
std::array<Dsd2Pcm, MAX_CHANNELS> per_channel;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Reset() noexcept {
|
|
|
|
for (auto &i : per_channel)
|
|
|
|
i.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Translate(unsigned channels, size_t n_frames,
|
|
|
|
const uint8_t *src, float *dest) noexcept;
|
|
|
|
};
|
|
|
|
|
2011-10-03 12:03:37 +02:00
|
|
|
#endif /* include guard DSD2PCM_H_INCLUDED */
|
|
|
|
|