kwave  18.07.70
SampleEncoderLinear.cpp File Reference
#include "config.h"
#include <stdio.h>
#include <sys/types.h>
#include <QtGlobal>
#include "libkwave/Sample.h"
#include "libkwave/SampleEncoderLinear.h"
#include "libkwave/SampleFormat.h"
#include "libkwave/Utils.h"
Include dependency graph for SampleEncoderLinear.cpp:

Go to the source code of this file.

Macros

#define MAKE_ENCODER(bits)
 

Functions

static void encode_NULL (const sample_t *src, quint8 *dst, unsigned int count)
 
template<const unsigned int bits, const bool is_signed, const bool is_little_endian>
void encode_linear (const sample_t *src, quint8 *dst, unsigned int count)
 

Macro Definition Documentation

◆ MAKE_ENCODER

#define MAKE_ENCODER (   bits)
Value:
if (sample_format != Kwave::SampleFormat::Unsigned) { \
if (endianness != Kwave::BigEndian) { \
m_encoder = encode_linear<bits, true, true>; \
} else { \
m_encoder = encode_linear<bits, true, false>; \
} \
} else { \
if (endianness != Kwave::BigEndian) { \
m_encoder = encode_linear<bits, false, true>; \
} else { \
m_encoder = encode_linear<bits, false, false>; \
} \
}

Definition at line 92 of file SampleEncoderLinear.cpp.

Referenced by Kwave::SampleEncoderLinear::SampleEncoderLinear().

Function Documentation

◆ encode_linear()

template<const unsigned int bits, const bool is_signed, const bool is_little_endian>
void encode_linear ( const sample_t src,
quint8 *  dst,
unsigned int  count 
)

Template for encoding a buffer with linear samples. The tricky part is done in the compiler which optimizes away all unused parts of current variant and does nice loop optimizing!

Parameters
srcarray with samples in Kwave's format
dstarray that receives the raw data
countthe number of samples to be encoded

Definition at line 50 of file SampleEncoderLinear.cpp.

References SAMPLE_BITS.

51 {
52  for ( ; count; --count) {
53  // read from source buffer
54  sample_t s = *(src++);
55 
56  // convert to unsigned if necessary
57  if (!is_signed)
58  s += 1 << (SAMPLE_BITS-1);
59 
60  // shrink 18/20 bits and similar down, otherwise it does not work
61  // with ALSA for some dubious reason !?
62  if (bits == 20)
63  s >>= 4;
64  if (bits == 18) // don't ask me why... !!!???
65  s >>= 6;
66 
67  if (is_little_endian) {
68  // little endian
69  if (bits > 24)
70  *(dst++) = 0x00;
71  if (bits > 16)
72  *(dst++) = static_cast<quint8>(s & 0xFF);
73  if (bits > 8)
74  *(dst++) = static_cast<quint8>(s >> 8);
75  if (bits >= 8)
76  *(dst++) = static_cast<quint8>(s >> 16);
77  } else {
78  // big endian
79  if (bits >= 8)
80  *(dst++) = static_cast<quint8>(s >> 16);
81  if (bits > 8)
82  *(dst++) = static_cast<quint8>(s >> 8);
83  if (bits > 16)
84  *(dst++) = static_cast<quint8>(s & 0xFF);
85  if (bits > 24)
86  *(dst++) = 0x00;
87  }
88  }
89 }
#define SAMPLE_BITS
Definition: Sample.h:43
qint32 sample_t
Definition: Sample.h:37

◆ encode_NULL()

static void encode_NULL ( const sample_t src,
quint8 *  dst,
unsigned int  count 
)
static

Definition at line 31 of file SampleEncoderLinear.cpp.

Referenced by Kwave::SampleEncoderLinear::SampleEncoderLinear().

32 {
33  (void)src;
34  (void)dst;
35  (void)count;
36 // qWarning("call to encode_NULL");
37 }
Here is the caller graph for this function: