mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
add support for synthesis to big-endian in plugins
This commit is contained in:
@@ -103,6 +103,87 @@ static FLAC__INLINE FLAC__int32 linear_dither(unsigned source_bps, unsigned targ
|
||||
return output >> scalebits;
|
||||
}
|
||||
|
||||
unsigned FLAC__plugin_common__pack_pcm_signed_big_endian(FLAC__byte *data, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps)
|
||||
{
|
||||
static dither_state dither[FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS];
|
||||
FLAC__byte * const start = data;
|
||||
FLAC__int32 sample;
|
||||
const FLAC__int32 *input_;
|
||||
unsigned samples, channel;
|
||||
const unsigned bytes_per_sample = target_bps / 8;
|
||||
unsigned inc = bytes_per_sample * channels;
|
||||
|
||||
FLAC__ASSERT(channels > 0 && channels <= FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS);
|
||||
FLAC__ASSERT(source_bps < 32);
|
||||
FLAC__ASSERT(target_bps <= 24);
|
||||
FLAC__ASSERT(target_bps <= source_bps);
|
||||
FLAC__ASSERT((source_bps & 7) == 0);
|
||||
FLAC__ASSERT((target_bps & 7) == 0);
|
||||
|
||||
if(source_bps != target_bps) {
|
||||
const FLAC__int32 MIN = -(1L << (source_bps - 1));
|
||||
const FLAC__int32 MAX = ~MIN; /*(1L << (source_bps-1)) - 1 */
|
||||
|
||||
for(channel = 0; channel < channels; channel++) {
|
||||
|
||||
samples = wide_samples;
|
||||
data = start + bytes_per_sample * channel;
|
||||
input_ = input[channel];
|
||||
|
||||
while(samples--) {
|
||||
sample = linear_dither(source_bps, target_bps, *input_++, &dither[channel], MIN, MAX);
|
||||
|
||||
switch(target_bps) {
|
||||
case 8:
|
||||
data[0] = sample ^ 0x80;
|
||||
break;
|
||||
case 16:
|
||||
data[0] = (FLAC__byte)(sample >> 8);
|
||||
data[1] = (FLAC__byte)sample;
|
||||
break;
|
||||
case 24:
|
||||
data[0] = (FLAC__byte)(sample >> 16);
|
||||
data[1] = (FLAC__byte)(sample >> 8);
|
||||
data[2] = (FLAC__byte)sample;
|
||||
break;
|
||||
}
|
||||
|
||||
data += inc;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(channel = 0; channel < channels; channel++) {
|
||||
samples = wide_samples;
|
||||
data = start + bytes_per_sample * channel;
|
||||
input_ = input[channel];
|
||||
|
||||
while(samples--) {
|
||||
sample = *input_++;
|
||||
|
||||
switch(target_bps) {
|
||||
case 8:
|
||||
data[0] = sample ^ 0x80;
|
||||
break;
|
||||
case 16:
|
||||
data[0] = (FLAC__byte)(sample >> 8);
|
||||
data[1] = (FLAC__byte)sample;
|
||||
break;
|
||||
case 24:
|
||||
data[0] = (FLAC__byte)(sample >> 16);
|
||||
data[1] = (FLAC__byte)(sample >> 8);
|
||||
data[2] = (FLAC__byte)sample;
|
||||
break;
|
||||
}
|
||||
|
||||
data += inc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return data - start;
|
||||
}
|
||||
|
||||
unsigned FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps)
|
||||
{
|
||||
static dither_state dither[FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS];
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "defs.h" /* buy FLAC_PLUGIN__MAX_SUPPORTED_CHANNELS for the caller */
|
||||
#include "FLAC/ordinals.h"
|
||||
|
||||
unsigned FLAC__plugin_common__pack_pcm_signed_big_endian(FLAC__byte *data, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps);
|
||||
unsigned FLAC__plugin_common__pack_pcm_signed_little_endian(FLAC__byte *data, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, unsigned source_bps, unsigned target_bps);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -288,7 +288,7 @@ static FLAC__INLINE FLAC__int64 dither_output_(DitherContext *d, FLAC__bool do_d
|
||||
#endif
|
||||
|
||||
|
||||
int FLAC__plugin_common__apply_gain(FLAC__byte *data_out, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const float scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context)
|
||||
int FLAC__plugin_common__apply_gain(FLAC__byte *data_out, FLAC__bool little_endian_data_out, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const float scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context)
|
||||
{
|
||||
static const FLAC__int32 conv_factors_[33] = {
|
||||
-1, /* 0 bits-per-sample (not supported) */
|
||||
@@ -410,16 +410,35 @@ int FLAC__plugin_common__apply_gain(FLAC__byte *data_out, const FLAC__int32 * co
|
||||
else if(val64 < hard_clip_factor)
|
||||
val32 = (FLAC__int32)hard_clip_factor;
|
||||
|
||||
switch(target_bps) {
|
||||
case 8:
|
||||
data_out[0] = val32 ^ 0x80;
|
||||
break;
|
||||
case 24:
|
||||
data_out[2] = (FLAC__byte)(val32 >> 16);
|
||||
/* fall through */
|
||||
case 16:
|
||||
data_out[1] = (FLAC__byte)(val32 >> 8);
|
||||
data_out[0] = (FLAC__byte)val32;
|
||||
if (little_endian_data_out) {
|
||||
switch(target_bps) {
|
||||
case 8:
|
||||
data_out[0] = val32 ^ 0x80;
|
||||
break;
|
||||
case 24:
|
||||
data_out[2] = (FLAC__byte)(val32 >> 16);
|
||||
/* fall through */
|
||||
case 16:
|
||||
data_out[1] = (FLAC__byte)(val32 >> 8);
|
||||
data_out[0] = (FLAC__byte)val32;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
switch(target_bps) {
|
||||
case 8:
|
||||
data_out[0] = val32 ^ 0x80;
|
||||
break;
|
||||
case 16:
|
||||
data_out[0] = (FLAC__byte)(val32 >> 8);
|
||||
data_out[1] = (FLAC__byte)val32;
|
||||
break;
|
||||
case 24:
|
||||
data_out[0] = (FLAC__byte)(val32 >> 16);
|
||||
data_out[1] = (FLAC__byte)(val32 >> 8);
|
||||
data_out[2] = (FLAC__byte)val32;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,6 @@ typedef struct {
|
||||
void FLAC__plugin_common__init_dither_context(DitherContext *dither, int bits, int shapingtype);
|
||||
|
||||
/* scale = (float) pow(10., (double)replaygain * 0.05); */
|
||||
int FLAC__plugin_common__apply_gain(FLAC__byte *data_out, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const float scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context);
|
||||
int FLAC__plugin_common__apply_gain(FLAC__byte *data_out, FLAC__bool little_endian_data_out, const FLAC__int32 * const input[], unsigned wide_samples, unsigned channels, const unsigned source_bps, const unsigned target_bps, const float scale, const FLAC__bool hard_limit, FLAC__bool do_dithering, DitherContext *dither_context);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user