Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianscar committed May 18, 2023
1 parent 0772ba9 commit 2cfc3f8
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
```groovy
dependencies {
...
implementation 'com.tianscar.javasound:javasound-alac:0.2.2'
implementation 'com.tianscar.javasound:javasound-alac:0.2.3'
}
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ ext {
libraryGroupName = 'com.tianscar.javasound'
libraryVendorName = 'Tianscar'

libraryVersionCode = 2
libraryVersionName = '0.2.2'
libraryVersionCode = 3
libraryVersionName = '0.2.3'

librarySourceCompatibility = JavaVersion.VERSION_1_8
libraryTargetCompatibility = JavaVersion.VERSION_1_8
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/beatofthedrum/alacdecoder/AlacDebug.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.beatofthedrum.alacdecoder;

class AlacDebug {

private static final boolean DEBUG = Boolean.parseBoolean(System.getProperty("com.beatofthedrom.alacdecoder.debug", "false"));

static void println(String msg) {
if (DEBUG) System.err.println(msg);
}

}
10 changes: 5 additions & 5 deletions src/main/java/com/beatofthedrum/alacdecoder/AlacDecodeUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ public static int decode_frame(AlacFile alac, byte[] inbuffer, int[] outbuffer,
}
else
{
System.err.println("FIXME: unhandled predicition type: " +prediction_type);
AlacDebug.println("FIXME: unhandled predicition type: " +prediction_type);

/* i think the only other prediction type (or perhaps this is just a
* boolean?) runs adaptive fir twice.. like:
Expand Down Expand Up @@ -794,7 +794,7 @@ public static int decode_frame(AlacFile alac, byte[] inbuffer, int[] outbuffer,
}
case 20:
case 32:
System.err.println("FIXME: unimplemented sample size " + alac.setinfo_sample_size);
AlacDebug.println("FIXME: unimplemented sample size " + alac.setinfo_sample_size);
default:

}
Expand Down Expand Up @@ -914,7 +914,7 @@ else if(channels == 1) // 2 channels
}
else
{ // see mono case
System.err.println("FIXME: unhandled predicition type: " + prediction_type_a);
AlacDebug.println("FIXME: unhandled predicition type: " + prediction_type_a);
}

/* channel 2 */
Expand All @@ -926,7 +926,7 @@ else if(channels == 1) // 2 channels
}
else
{
System.err.println("FIXME: unhandled predicition type: " + prediction_type_b);
AlacDebug.println("FIXME: unhandled predicition type: " + prediction_type_b);
}
}
else
Expand Down Expand Up @@ -997,7 +997,7 @@ else if(channels == 1) // 2 channels
}
case 20:
case 32:
System.err.println("FIXME: unimplemented sample size " + alac.setinfo_sample_size);
AlacDebug.println("FIXME: unimplemented sample size " + alac.setinfo_sample_size);

default:

Expand Down
46 changes: 25 additions & 21 deletions src/main/java/com/beatofthedrum/alacdecoder/AlacUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,15 @@ public static int AlacUnpackSamples(AlacContext ac, int[] pDestBuffer)
{
return 0;
}

if (get_sample_info(ac.demux_res, ac.current_sample_block , sampleinfo) == 0)
{

try {
get_sample_info(ac.demux_res, ac.current_sample_block , sampleinfo);
}
catch (AlacException e) {
ac.error = true;
ac.error_message = e;
// getting sample failed
return 0;
return 0;
}

sample_byte_size = sampleinfo.sample_byte_size;
Expand Down Expand Up @@ -253,19 +257,22 @@ public static int AlacGetNumSamples(AlacContext ac)
SampleDuration sampleinfo = new SampleDuration();
int i;
boolean error_found = false;
int retval = 0;

for (i = 0; i < ac.demux_res.sample_byte_size.length; i++)
{
thissample_duration = 0;
thissample_bytesize = 0;

retval = get_sample_info(ac.demux_res, i, sampleinfo);

if(retval == 0)
{
try {
get_sample_info(ac.demux_res, ac.current_sample_block , sampleinfo);
}
catch (AlacException e) {
ac.error = true;
ac.error_message = e;
// getting sample failed
return (-1);
}

thissample_duration = sampleinfo.sample_duration;
thissample_bytesize = sampleinfo.sample_byte_size;

Expand All @@ -276,37 +283,32 @@ public static int AlacGetNumSamples(AlacContext ac)
}


static int get_sample_info(DemuxResT demux_res, int samplenum, SampleDuration sampleinfo)
{
static void get_sample_info(DemuxResT demux_res, int samplenum, SampleDuration sampleinfo) throws AlacException {
int duration_index_accum = 0;
int duration_cur_index = 0;

if (samplenum >= demux_res.sample_byte_size.length)
{
System.err.println("sample " + samplenum + " does not exist ");
return 0;
throw new AlacException("sample " + samplenum + " does not exist ");
}

if (demux_res.num_time_to_samples == 0) // was null
{
System.err.println("no time to samples");
return 0;
throw new AlacException("no time to samples");
}
while ((demux_res.time_to_sample[duration_cur_index].sample_count + duration_index_accum) <= samplenum)
{
duration_index_accum += demux_res.time_to_sample[duration_cur_index].sample_count;
duration_cur_index++;
if (duration_cur_index >= demux_res.num_time_to_samples)
{
System.err.println("sample " + samplenum + " does not have a duration");
return 0;
throw new AlacException("sample " + samplenum + " does not have a duration");
}
}

sampleinfo.sample_duration = demux_res.time_to_sample[duration_cur_index].sample_duration;
sampleinfo.sample_byte_size = demux_res.sample_byte_size[samplenum];

return 1;
}

/**
Expand Down Expand Up @@ -335,10 +337,12 @@ public static AlacContext AlacSetPosition(AlacContext ac, long position) {
int pos = res.stco[chunk - 1];
int sample_count = chunkInfo.samples_per_chunk;
while (sample_count > 0) {
int ret = get_sample_info(res, current_sample, sample_info);
if (ret == 0) {
ac.error_message = new IOException("Error while reading sample info");
try {
get_sample_info(res, current_sample, sample_info);
}
catch (AlacException e) {
ac.error = true;
ac.error_message = new IOException("Error while reading sample info");
return ac;
}
current_position += sample_info.sample_duration;
Expand Down

0 comments on commit 2cfc3f8

Please sign in to comment.