Add check for processor endianness. Fix a small warning.

This commit is contained in:
Mke Brady
2015-11-29 20:59:11 +00:00
parent 5d646e795b
commit 73c3744e4c
3 changed files with 38 additions and 32 deletions
+2
View File
@@ -2,6 +2,7 @@
#define _COMMON_H
#include <stdint.h>
#include <endian.h>
#include <sys/socket.h>
#include <libconfig.h>
@@ -116,6 +117,7 @@ uint64_t get_absolute_time_in_fp(void);
// this is for reading an unsigned 32 bit number, such as an RTP timestamp
long endianness;
uint32_t uatoi(const char *nptr);
shairport_cfg config;
+3 -32
View File
@@ -384,9 +384,9 @@ int32_t rand_in_range(int32_t exclusive_range_limit) {
}
static inline short dithered_vol(short sample) {
int32_t out;
long out;
out = (int32_t)sample * fix_volume;
out = (long)sample * fix_volume;
if (fix_volume < 0x10000) {
// add a TPDF dither -- see http://www.users.qwest.net/%7Evolt42/cadenzarecording/DitherExplained.pdf
@@ -398,7 +398,7 @@ static inline short dithered_vol(short sample) {
// See the original paper at http://www.ece.rochester.edu/courses/ECE472/resources/Papers/Lipshitz_1992.pdf
// by Lipshitz, Wannamaker and Vanderkooy, 1992.
int32_t tpdf = rand_in_range(65536+1) - rand_in_range(65536+1);
long tpdf = rand_in_range(65536+1) - rand_in_range(65536+1);
// Check there's no clipping -- if there is,
if (tpdf>=0) {
if (LONG_MAX-tpdf>=out)
@@ -415,35 +415,6 @@ static inline short dithered_vol(short sample) {
return out >> 16;
}
/*
static inline short lcg_rand(void) {
static unsigned long lcg_prev = 12345;
lcg_prev = lcg_prev * 69069 + 3;
return lcg_prev & 0xffff;
}
static inline short dithered_vol(short sample) {
static short rand_a;
short rand_b;
long out;
out = (long)sample * fix_volume;
if (fix_volume < 0x10000) {
// add a TPDF dither -- see http://www.users.qwest.net/%7Evolt42/cadenzarecording/DitherExplained.pdf
// and the discussion around https://www.hydrogenaud.io/forums/index.php?showtopic=16963&st=25
// I think it's wrong. I think, for a 32 --> 16 bits, the range of
// random numbers needs to be from 0 to 2^16, i.e. from 0 to 65536, not from -32768bto +32767
rand_b = rand_a;
rand_a = lcg_rand();
out += rand_a;
out -= rand_b;
}
return out >> 16;
}
*/
// get the next frame, when available. return 0 if underrun/stream reset.
static abuf_t *buffer_get_frame(void) {
int16_t buf_fill;
+33
View File
@@ -641,6 +641,27 @@ int main(int argc, char **argv) {
free(basec);
// set defaults
// get thje endianness
union {
uint32_t u32;
uint8_t arr[4];
} xn;
xn.arr[0] = 0x44; /* Lowest-address byte */
xn.arr[1] = 0x33;
xn.arr[2] = 0x22;
xn.arr[3] = 0x11; /* Highest-address byte */
if (xn.u32==0x11223344)
endianness = __LITTLE_ENDIAN;
else if (xn.u32==0x33441122)
endianness = __PDP_ENDIAN;
else if (xn.u32==0x44332211)
endianness = __BIG_ENDIAN;
else die("Can not recognise the endianness of the processor.");
strcpy(configuration_file_path, "/etc/");
strcat(configuration_file_path, appName);
strcat(configuration_file_path, ".conf");
@@ -832,6 +853,18 @@ int main(int argc, char **argv) {
daemon_log(LOG_NOTICE, "startup");
switch (endianness) {
case __LITTLE_ENDIAN:
debug(2,"The processor is running little-endian.");
break;
case __BIG_ENDIAN:
debug(2,"The processor is running big-endian.");
break;
case __PDP_ENDIAN:
debug(2,"The processor is running pdp-endian.");
break;
}
/* Mess around with the latency options */
// Basically, we used to rely on static latencies -- 99400 for iTunes 10 or later and forkedDaapd, 88200 for everything else
// Nowadays we allow the source to set the latency, which works out at 99651 for iTunes 10 and forkedDaapd and 88220 for everything else