Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jkiddo committed Aug 17, 2016
2 parents 7625274 + cb45d15 commit 3e0abf2
Show file tree
Hide file tree
Showing 49 changed files with 251 additions and 247 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ public static void alac_set_info(AlacFile alac, int[] inputbuffer)

ptrIndex += 4; // 0 ?

alac.setinfo_max_samples_per_frame = ((inputbuffer[ptrIndex] << 24) + (inputbuffer[ptrIndex + 1] << 16) + (inputbuffer[ptrIndex + 2] << 8) + inputbuffer[ptrIndex + 3]); // buffer size / 2 ?
alac.setinfo_max_samples_per_frame = (inputbuffer[ptrIndex] << 24) + (inputbuffer[ptrIndex + 1] << 16) + (inputbuffer[ptrIndex + 2] << 8) + inputbuffer[ptrIndex + 3]; // buffer size / 2 ?
ptrIndex += 4;
alac.setinfo_7a = inputbuffer[ptrIndex];
ptrIndex += 1;
alac.setinfo_sample_size = inputbuffer[ptrIndex];
ptrIndex += 1;
alac.setinfo_rice_historymult = (inputbuffer[ptrIndex] & 0xff);
alac.setinfo_rice_historymult = inputbuffer[ptrIndex] & 0xff;
ptrIndex += 1;
alac.setinfo_rice_initialhistory = (inputbuffer[ptrIndex] & 0xff);
alac.setinfo_rice_initialhistory = inputbuffer[ptrIndex] & 0xff;
ptrIndex += 1;
alac.setinfo_rice_kmodifier = (inputbuffer[ptrIndex] & 0xff);
alac.setinfo_rice_kmodifier = inputbuffer[ptrIndex] & 0xff;
ptrIndex += 1;
alac.setinfo_7f = inputbuffer[ptrIndex];
ptrIndex += 1;
alac.setinfo_80 = (inputbuffer[ptrIndex] << 8) + inputbuffer[ptrIndex + 1];
ptrIndex += 2;
alac.setinfo_82 = ((inputbuffer[ptrIndex] << 24) + (inputbuffer[ptrIndex + 1] << 16) + (inputbuffer[ptrIndex + 2] << 8) + inputbuffer[ptrIndex + 3]);
alac.setinfo_82 = (inputbuffer[ptrIndex] << 24) + (inputbuffer[ptrIndex + 1] << 16) + (inputbuffer[ptrIndex + 2] << 8) + inputbuffer[ptrIndex + 3];
ptrIndex += 4;
alac.setinfo_86 = ((inputbuffer[ptrIndex] << 24) + (inputbuffer[ptrIndex + 1] << 16) + (inputbuffer[ptrIndex + 2] << 8) + inputbuffer[ptrIndex + 3]);
alac.setinfo_86 = (inputbuffer[ptrIndex] << 24) + (inputbuffer[ptrIndex + 1] << 16) + (inputbuffer[ptrIndex + 2] << 8) + inputbuffer[ptrIndex + 3];
ptrIndex += 4;
alac.setinfo_8a_rate = ((inputbuffer[ptrIndex] << 24) + (inputbuffer[ptrIndex + 1] << 16) + (inputbuffer[ptrIndex + 2] << 8) + inputbuffer[ptrIndex + 3]);
alac.setinfo_8a_rate = (inputbuffer[ptrIndex] << 24) + (inputbuffer[ptrIndex + 1] << 16) + (inputbuffer[ptrIndex + 2] << 8) + inputbuffer[ptrIndex + 3];
ptrIndex += 4;

}
Expand All @@ -64,11 +64,11 @@ static int readbits_16(AlacFile alac, int bits)
int part2;
int part3;

part1 = (alac.input_buffer[alac.ibIdx] & 0xff);
part2 = (alac.input_buffer[alac.ibIdx + 1] & 0xff);
part3 = (alac.input_buffer[alac.ibIdx + 2] & 0xff);
part1 = alac.input_buffer[alac.ibIdx] & 0xff;
part2 = alac.input_buffer[alac.ibIdx + 1] & 0xff;
part3 = alac.input_buffer[alac.ibIdx + 2] & 0xff;

result = ((part1 << 16) | (part2 << 8) | part3);
result = (part1 << 16) | (part2 << 8) | part3;

/*
* shift left by the number of bits we've already read, so that the top 'n' bits of the 24 bits we read will be the return bits
Expand All @@ -82,13 +82,13 @@ static int readbits_16(AlacFile alac, int bits)
*/
result = result >> (24 - bits);

new_accumulator = (alac.input_buffer_bitaccumulator + bits);
new_accumulator = alac.input_buffer_bitaccumulator + bits;

/* increase the buffer pointer if we've read over n bytes. */
alac.ibIdx += (new_accumulator >> 3);

/* and the remainder goes back into the bit accumulator */
alac.input_buffer_bitaccumulator = (new_accumulator & 7);
alac.input_buffer_bitaccumulator = new_accumulator & 7;

return result;
}
Expand All @@ -115,30 +115,30 @@ static int readbit(AlacFile alac)
{
int result;
int new_accumulator;
int part1 = (alac.input_buffer[alac.ibIdx] & 0xff);
int part1 = alac.input_buffer[alac.ibIdx] & 0xff;

result = part1;

result = result << alac.input_buffer_bitaccumulator;

result = result >> 7 & 1;

new_accumulator = (alac.input_buffer_bitaccumulator + 1);
new_accumulator = alac.input_buffer_bitaccumulator + 1;

alac.ibIdx += new_accumulator / 8;

alac.input_buffer_bitaccumulator = (new_accumulator % 8);
alac.input_buffer_bitaccumulator = new_accumulator % 8;

return result;
}

static void unreadbits(AlacFile alac, int bits)
{
int new_accumulator = (alac.input_buffer_bitaccumulator - bits);
int new_accumulator = alac.input_buffer_bitaccumulator - bits;

alac.ibIdx += (new_accumulator >> 3);

alac.input_buffer_bitaccumulator = (new_accumulator & 7);
alac.input_buffer_bitaccumulator = new_accumulator & 7;
if(alac.input_buffer_bitaccumulator < 0)
alac.input_buffer_bitaccumulator *= -1;
}
Expand Down Expand Up @@ -294,7 +294,7 @@ public static void entropy_rice_decode(AlacFile alac, int[] outputBuffer, int ou
decodedValue = entropy_decode_value(alac, readSampleSize, k, 0xFFFFFFFF);

decodedValue += signModifier;
finalValue = ((decodedValue + 1) / 2); // inc by 1 and shift out sign bit
finalValue = (decodedValue + 1) / 2; // inc by 1 and shift out sign bit
if((decodedValue & 1) != 0) // the sign is stored in the low bit
finalValue *= -1;

Expand Down Expand Up @@ -354,10 +354,10 @@ static int[] predictor_decompress_fir_adapt(int[] error_buffer, int output_size,
if(predictor_coef_num == 0)
{
if(output_size <= 1)
return(buffer_out);
return buffer_out;
int sizeToCopy = (output_size - 1) * 4;
System.arraycopy(error_buffer, 1, buffer_out, 1, sizeToCopy);
return(buffer_out);
return buffer_out;
}

if(predictor_coef_num == 0x1f) // 11111 - max value of predictor_coef_num
Expand All @@ -366,17 +366,17 @@ static int[] predictor_decompress_fir_adapt(int[] error_buffer, int output_size,
* second-best case scenario for fir decompression, error describes a small difference from the previous sample only
*/
if(output_size <= 1)
return(buffer_out);
return buffer_out;

for(int i = 0; i < (output_size - 1); i++)
{
int prev_value = buffer_out[i];
int error_value = error_buffer[i + 1];;

bitsmove = 32 - readsamplesize;
buffer_out[i + 1] = (((prev_value + error_value) << bitsmove) >> bitsmove);
buffer_out[i + 1] = ((prev_value + error_value) << bitsmove) >> bitsmove;
}
return(buffer_out);
return buffer_out;
}

/* read warm-up samples */
Expand All @@ -388,7 +388,7 @@ static int[] predictor_decompress_fir_adapt(int[] error_buffer, int output_size,

bitsmove = 32 - readsamplesize;

val = ((val << bitsmove) >> bitsmove);
val = (val << bitsmove) >> bitsmove;

buffer_out[i + 1] = val;
}
Expand All @@ -415,7 +415,7 @@ static int[] predictor_decompress_fir_adapt(int[] error_buffer, int output_size,
outval = outval + buffer_out[buffer_out_idx] + error_val;
bitsmove = 32 - readsamplesize;

outval = ((outval << bitsmove) >> bitsmove);
outval = (outval << bitsmove) >> bitsmove;

buffer_out[buffer_out_idx + predictor_coef_num + 1] = outval;

Expand All @@ -426,7 +426,7 @@ static int[] predictor_decompress_fir_adapt(int[] error_buffer, int output_size,
while(predictor_num >= 0 && error_val > 0)
{
int val = buffer_out[buffer_out_idx] - buffer_out[buffer_out_idx + predictor_coef_num - predictor_num];
int sign = ((val < 0) ? (-1) : ((val > 0) ? (1) : (0)));
int sign = (val < 0) ? -1 : ((val > 0) ? 1 : 0);

predictor_coef_table[predictor_num] -= sign;

Expand All @@ -444,7 +444,7 @@ else if(error_val < 0)
while(predictor_num >= 0 && error_val < 0)
{
int val = buffer_out[buffer_out_idx] - buffer_out[buffer_out_idx + predictor_coef_num - predictor_num];
int sign = -((val < 0) ? (-1) : ((val > 0) ? (1) : (0)));
int sign = -((val < 0) ? -1 : ((val > 0) ? 1 : 0));

predictor_coef_table[predictor_num] -= sign;

Expand All @@ -459,7 +459,7 @@ else if(error_val < 0)
buffer_out_idx++;
}
}
return(buffer_out);
return buffer_out;
}

public static void deinterlace_16(int[] buffer_a, int[] buffer_b, int[] buffer_out, int numchannels, int numsamples, int interlacing_shift, int interlacing_leftweight)
Expand All @@ -481,8 +481,8 @@ public static void deinterlace_16(int[] buffer_a, int[] buffer_b, int[] buffer_o
midright = buffer_a[i];
difference = buffer_b[i];

right = (midright - ((difference * interlacing_leftweight) >> interlacing_shift));
left = (right + difference);
right = midright - ((difference * interlacing_leftweight) >> interlacing_shift);
left = right + difference;

/* output is always little endian */

Expand Down Expand Up @@ -540,13 +540,13 @@ public static void deinterlace_24(int[] buffer_a, int[] buffer_b, int uncompress
right = right | (uncompressed_bytes_buffer_b[i] & mask);
}

buffer_out[i * numchannels * 3] = (left & 0xFF);
buffer_out[i * numchannels * 3 + 1] = ((left >> 8) & 0xFF);
buffer_out[i * numchannels * 3 + 2] = ((left >> 16) & 0xFF);
buffer_out[i * numchannels * 3] = left & 0xFF;
buffer_out[i * numchannels * 3 + 1] = (left >> 8) & 0xFF;
buffer_out[i * numchannels * 3 + 2] = (left >> 16) & 0xFF;

buffer_out[i * numchannels * 3 + 3] = (right & 0xFF);
buffer_out[i * numchannels * 3 + 4] = ((right >> 8) & 0xFF);
buffer_out[i * numchannels * 3 + 5] = ((right >> 16) & 0xFF);
buffer_out[i * numchannels * 3 + 3] = right & 0xFF;
buffer_out[i * numchannels * 3 + 4] = (right >> 8) & 0xFF;
buffer_out[i * numchannels * 3 + 5] = (right >> 16) & 0xFF;
}

return;
Expand All @@ -571,13 +571,13 @@ public static void deinterlace_24(int[] buffer_a, int[] buffer_b, int uncompress
right = right | (uncompressed_bytes_buffer_b[i] & mask);
}

buffer_out[i * numchannels * 3] = (left & 0xFF);
buffer_out[i * numchannels * 3 + 1] = ((left >> 8) & 0xFF);
buffer_out[i * numchannels * 3 + 2] = ((left >> 16) & 0xFF);
buffer_out[i * numchannels * 3] = left & 0xFF;
buffer_out[i * numchannels * 3 + 1] = (left >> 8) & 0xFF;
buffer_out[i * numchannels * 3 + 2] = (left >> 16) & 0xFF;

buffer_out[i * numchannels * 3 + 3] = (right & 0xFF);
buffer_out[i * numchannels * 3 + 4] = ((right >> 8) & 0xFF);
buffer_out[i * numchannels * 3 + 5] = ((right >> 16) & 0xFF);
buffer_out[i * numchannels * 3 + 3] = right & 0xFF;
buffer_out[i * numchannels * 3 + 4] = (right >> 8) & 0xFF;
buffer_out[i * numchannels * 3 + 5] = (right >> 16) & 0xFF;

}

Expand Down Expand Up @@ -700,7 +700,7 @@ public static int decode_frame(AlacFile alac, byte[] inbuffer, int[] outbuffer,
int audiobits = readbits(alac, alac.setinfo_sample_size);
bitsmove = 32 - alac.setinfo_sample_size;

audiobits = ((audiobits << bitsmove) >> bitsmove);
audiobits = (audiobits << bitsmove) >> bitsmove;

alac.outputsamples_buffer_a[i] = audiobits;
}
Expand Down Expand Up @@ -760,9 +760,9 @@ public static int decode_frame(AlacFile alac, byte[] inbuffer, int[] outbuffer,
sample = sample | (alac.uncompressed_bytes_buffer_a[i] & mask);
}

outbuffer[i * alac.numchannels * 3] = ((sample) & 0xFF);
outbuffer[i * alac.numchannels * 3 + 1] = ((sample >> 8) & 0xFF);
outbuffer[i * alac.numchannels * 3 + 2] = ((sample >> 16) & 0xFF);
outbuffer[i * alac.numchannels * 3] = (sample) & 0xFF;
outbuffer[i * alac.numchannels * 3 + 1] = (sample >> 8) & 0xFF;
outbuffer[i * alac.numchannels * 3 + 2] = (sample >> 16) & 0xFF;

/*
* * We have to handle the case where the data is actually mono, but the stsd atom says it has 2 channels* in this case we create a stereo file where one of the channels is silent. If mono and 1 channel this value* will be overwritten in the next iteration
Expand Down Expand Up @@ -929,8 +929,8 @@ else if(channels == 1) // 2 channels

bitsmove = 32 - alac.setinfo_sample_size;

audiobits_a = ((audiobits_a << bitsmove) >> bitsmove);
audiobits_b = ((audiobits_b << bitsmove) >> bitsmove);
audiobits_a = (audiobits_a << bitsmove) >> bitsmove;
audiobits_b = (audiobits_b << bitsmove) >> bitsmove;

alac.outputsamples_buffer_a[i] = audiobits_a;
alac.outputsamples_buffer_b[i] = audiobits_b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class JettyCommandService extends AbstractHandler
{
private static Logger logger = Logger.getLogger(JettyCommandService.class.getName());
private static final Logger LOGGER = Logger.getLogger(JettyCommandService.class.getName());

private static Map<String, Device> deviceMap = new HashMap<>();

Expand Down Expand Up @@ -87,7 +87,7 @@ public void handle(String target, Request baseRequest, HttpServletRequest reques
}
catch(RuntimeException e)
{
logger.log(Level.SEVERE, e.getMessage(), e);
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
}
}
Expand Down Expand Up @@ -126,7 +126,7 @@ private void handleCommandRequest(Request baseRequest, HttpServletRequest reques
Device device = deviceMap.get(deviceId);
if(device == null)
{
logger.log(Level.SEVERE, "Device ID is not valid: " + deviceId);
LOGGER.log(Level.SEVERE, "Device ID is not valid: " + deviceId);
sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Device ID is not valid: " + deviceId, baseRequest, response);
}
else
Expand Down Expand Up @@ -186,7 +186,7 @@ private void handleCommandRequest(Request baseRequest, HttpServletRequest reques
}
else
{
logger.log(Level.INFO, "Error response: code=" + deviceResponse.getResponseCode() + " message=" + deviceResponse.getResponseMessage());
LOGGER.log(Level.INFO, "Error response: code=" + deviceResponse.getResponseCode() + " message=" + deviceResponse.getResponseMessage());
sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, deviceResponse.getResponseMessage(), baseRequest, response);
}
}
Expand All @@ -203,7 +203,7 @@ private void handleCommandRequest(Request baseRequest, HttpServletRequest reques
}
catch(NumberFormatException e)
{
logger.log(Level.INFO, "Could not parse rate parameter: " + request.getParameter("r"));
LOGGER.log(Level.INFO, "Could not parse rate parameter: " + request.getParameter("r"));
sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Rate is not valid.", baseRequest, response);
}

Expand Down Expand Up @@ -238,7 +238,7 @@ private void handleCommandRequest(Request baseRequest, HttpServletRequest reques
}
catch(NumberFormatException e)
{
logger.log(Level.INFO, "Could not parse position parameter: " + request.getParameter("p"));
LOGGER.log(Level.INFO, "Could not parse position parameter: " + request.getParameter("p"));
sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Position is not valid.", baseRequest, response);
}

Expand All @@ -261,15 +261,15 @@ private void handleCommandRequest(Request baseRequest, HttpServletRequest reques
}
else
{
logger.log(Level.INFO, "Error response: code=" + deviceResponse.getResponseCode() + " message=" + deviceResponse.getResponseMessage());
LOGGER.log(Level.INFO, "Error response: code=" + deviceResponse.getResponseCode() + " message=" + deviceResponse.getResponseMessage());
sendErrorResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, deviceResponse.getResponseMessage(), baseRequest, response);
}
}
}
break;
default:
{
logger.info("Command not understood: " + request.getParameter("t"));
LOGGER.info("Command not understood: " + request.getParameter("t"));
sendErrorResponse(HttpServletResponse.SC_NOT_ACCEPTABLE, "Command not understood.", baseRequest, response);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@Singleton
public class RemoteSpeakerDiscoverer implements IDiscoverer
{
public static final Logger logger = LoggerFactory.getLogger(RemoteSpeakerDiscoverer.class);
private static final Logger LOGGER = LoggerFactory.getLogger(RemoteSpeakerDiscoverer.class);

private final JmmDNS mDNS;
private final Map<JmDNS, InetAddress> interfaces = new HashMap<JmDNS, InetAddress>();
Expand All @@ -48,21 +48,21 @@ public RemoteSpeakerDiscoverer(JmmDNS mDNS, ISpeakerListener speakerListener)
@Override
public void serviceAdded(ServiceEvent event)
{
logger.info("ADD: " + event.getDNS().getServiceInfo(event.getType(), event.getName()));
LOGGER.info("ADD: " + event.getDNS().getServiceInfo(event.getType(), event.getName()));
}

@Override
public void serviceRemoved(ServiceEvent event)
{
logger.debug("REMOVE: " + event.getName());
LOGGER.debug("REMOVE: " + event.getName());
this.speakerListener.removeAvailableSpeaker(event.getInfo().getServer(), event.getInfo().getPort());
}

@SuppressWarnings("deprecation")
@Override
public void serviceResolved(ServiceEvent event)
{
logger.info("ADD: " + event.getDNS().getServiceInfo(event.getType(), event.getName()));
LOGGER.info("ADD: " + event.getDNS().getServiceInfo(event.getType(), event.getName()));
speakerListener.registerAvailableSpeaker(DeviceConnectionService.getConnection(new Device(event.getName(), event.getInfo().getInetAddress(), event.getInfo().getPort())));
}

Expand All @@ -71,7 +71,7 @@ public void inetAddressAdded(NetworkTopologyEvent event)
{
JmDNS mdns = event.getDNS();
InetAddress address = event.getInetAddress();
logger.info("Registered RemoteSpeakerDiscoverer @ " + address.getHostAddress());
LOGGER.info("Registered RemoteSpeakerDiscoverer @ " + address.getHostAddress());
mdns.addServiceListener(ISpeakerListener.RAOP_TYPE, this);
interfaces.put(mdns, address);
}
Expand Down
Loading

0 comments on commit 3e0abf2

Please sign in to comment.