Fixed exception on empty gainpoints after recording

This commit is contained in:
2024-04-07 15:50:58 +01:00
parent 09436a17d8
commit 89e83f978b
6 changed files with 51 additions and 16 deletions

View File

@@ -0,0 +1,21 @@
<profile>
<code>librivox-noinit</code>
<name>LibriVox.org (Without initials)</name>
<export>
<bitrate>128000</bitrate>
<channels>1</channels>
<samples>44100</samples>
<format>{chapter.name:lower}_{book.author.short:lower}_{file.bitrate.kb}kb</format>
</export>
<gaps>
<pre-chapter>500</pre-chapter>
<post-chapter>5000</post-chapter>
<post-sentence>400</post-sentence>
<followon>100</followon>
<post-paragraph>1000</post-paragraph>
<post-section>1200</post-section>
</gaps>
<audio>
<rms>-19</rms>
</audio>
</profile>

View File

@@ -0,0 +1,21 @@
<profile>
<code>librivox-spc</code>
<name>LibriVox.org Short Poetry Collection</name>
<export>
<bitrate>128000</bitrate>
<channels>1</channels>
<samples>44100</samples>
<format>{book.title:lower}_{chapter.name:lower}_{narrator.initials:lower}_{file.bitrate.kb}kb</format>
</export>
<gaps>
<pre-chapter>500</pre-chapter>
<post-chapter>5000</post-chapter>
<post-sentence>400</post-sentence>
<followon>100</followon>
<post-paragraph>1000</post-paragraph>
<post-section>1200</post-section>
</gaps>
<audio>
<rms>-19</rms>
</audio>
</profile>

View File

@@ -252,8 +252,11 @@ public class Book extends BookTreeNode {
public Chapter getChapter(int n) {
Debug.trace();
if (n == 0) return null;
return (Chapter)getChildAt(n);
Object o = getChildAt(n);
if (o instanceof Chapter) {
return (Chapter)o;
}
return null;
}
public Chapter addChapter() {

View File

@@ -100,7 +100,7 @@ public class Chapter extends BookTreeNode {
public int getSequenceNumber() {
Book book = getBook();
int i = 1;
int i = 0;
while (true) {
Chapter c = book.getChapter(i);
if (c == null) {

View File

@@ -106,7 +106,7 @@ public class Sentence extends BookTreeNode implements Cacheable {
double[] waveProfile = null;
TreeMap<Integer, Double> gainPoints = null;
TreeMap<Integer, Double> gainPoints = new TreeMap<Integer, Double>();
RecordingThread recordingThread;
@@ -241,7 +241,6 @@ public class Sentence extends BookTreeNode implements Cacheable {
autoTrimSample();
}
gainPoints = new TreeMap<Integer, Double>();
Element gp = Book.getNode(root, "gainpoints");
if (gp != null) {
NodeList points = gp.getElementsByTagName("gainpoint");
@@ -1901,16 +1900,10 @@ public class Sentence extends BookTreeNode implements Cacheable {
public TreeMap<Integer, Double> getGainPoints() {
Debug.trace();
if (gainPoints == null) {
gainPoints = new TreeMap<Integer, Double>();
}
return gainPoints;
}
public void addGainPoint(Integer loc, Double g) {
if (gainPoints == null) {
gainPoints = new TreeMap<Integer, Double>();
}
gainPoints.put(loc, g);
refreshAllData();
}
@@ -1925,10 +1918,6 @@ public class Sentence extends BookTreeNode implements Cacheable {
}
public void adjustGainPoint(Integer loc, Double adj, boolean reload) {
if (gainPoints == null) {
gainPoints = new TreeMap<Integer, Double>();
return;
}
Double gp = gainPoints.get(loc);
if (gp == null) return;
gp += adj;
@@ -2048,10 +2037,11 @@ public class Sentence extends BookTreeNode implements Cacheable {
final int window = 500;
public double[] getWaveProfile() {
public synchronized double[] getWaveProfile() {
if (waveProfile != null) return waveProfile;
double[][] samples = getProcessedAudioData();
if (samples[LEFT].length == 0) return null;
System.out.println(String.format("Sample length: %d", samples[LEFT].length));
waveProfile = new double[samples[LEFT].length];
double rt = 0;