Added playback block size option

This commit is contained in:
2019-10-13 20:11:07 +01:00
parent 1c08b9a51d
commit 80c110afa9
2 changed files with 28 additions and 8 deletions

View File

@@ -30,8 +30,6 @@ public class AudiobookRecorder extends JFrame {
// Settings - tweakable // Settings - tweakable
public static final int PLAYBACK_CHUNK_SIZE = 1024;
public static final String SPHINX_MODEL = "resource:/edu/cmu/sphinx/models/en-us/en-us"; public static final String SPHINX_MODEL = "resource:/edu/cmu/sphinx/models/en-us/en-us";
static Properties config = new Properties(); static Properties config = new Properties();
@@ -2178,6 +2176,8 @@ public class AudiobookRecorder extends JFrame {
try { try {
int blockSize = Options.getInteger("audio.playback.blocksize");
AudioFormat sampleformat = s.getAudioFormat(); AudioFormat sampleformat = s.getAudioFormat();
float sampleRate = sampleformat.getSampleRate(); float sampleRate = sampleformat.getSampleRate();
// sampleRate *= toolBar.getPlaybackSpeed(); // sampleRate *= toolBar.getPlaybackSpeed();
@@ -2190,10 +2190,10 @@ public class AudiobookRecorder extends JFrame {
bookTree.scrollPathToVisible(new TreePath(s.getPath())); bookTree.scrollPathToVisible(new TreePath(s.getPath()));
data = s.getPCMData(effectsEnabled); data = s.getPCMData(effectsEnabled);
for (int pos = 0; pos < data.length; pos += PLAYBACK_CHUNK_SIZE) { for (int pos = 0; pos < data.length; pos += blockSize) {
sampleWaveform.setPlayMarker(pos / format.getFrameSize()); sampleWaveform.setPlayMarker(pos / format.getFrameSize());
int l = data.length - pos; int l = data.length - pos;
if (l > PLAYBACK_CHUNK_SIZE) l = PLAYBACK_CHUNK_SIZE; if (l > blockSize) l = blockSize;
play.write(data, pos, l); play.write(data, pos, l);
} }
@@ -2342,6 +2342,8 @@ public class AudiobookRecorder extends JFrame {
try { try {
int blockSize = Options.getInteger("audio.playback.blocksize");
AudioFormat sampleformat = s.getAudioFormat(); AudioFormat sampleformat = s.getAudioFormat();
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 2, true, false); AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 2, true, false);
@@ -2373,10 +2375,10 @@ public class AudiobookRecorder extends JFrame {
if (startPos > data.length) startPos = data.length; if (startPos > data.length) startPos = data.length;
if (endPos > data.length) endPos = data.length; if (endPos > data.length) endPos = data.length;
for (int pos = startPos; pos < endPos; pos += PLAYBACK_CHUNK_SIZE) { for (int pos = startPos; pos < endPos; pos += blockSize) {
sampleWaveform.setPlayMarker(pos / format.getFrameSize()); sampleWaveform.setPlayMarker(pos / format.getFrameSize());
int l = data.length - pos; int l = data.length - pos;
if (l > PLAYBACK_CHUNK_SIZE) l = PLAYBACK_CHUNK_SIZE; if (l > blockSize) l = blockSize;
play.write(data, pos, l); play.write(data, pos, l);
} }
@@ -2418,6 +2420,8 @@ public class AudiobookRecorder extends JFrame {
try { try {
int blockSize = Options.getInteger("audio.playback.blocksize");
AudioFormat sampleformat = s.getAudioFormat(); AudioFormat sampleformat = s.getAudioFormat();
float sampleRate = sampleformat.getSampleRate(); float sampleRate = sampleformat.getSampleRate();
sampleRate *= toolBar.getPlaybackSpeed(); sampleRate *= toolBar.getPlaybackSpeed();
@@ -2451,10 +2455,10 @@ public class AudiobookRecorder extends JFrame {
}); });
t.start(); t.start();
} }
for (int pos = 0; pos < data.length; pos += PLAYBACK_CHUNK_SIZE) { for (int pos = 0; pos < data.length; pos += blockSize) {
sampleWaveform.setPlayMarker(pos / format.getFrameSize()); sampleWaveform.setPlayMarker(pos / format.getFrameSize());
int l = data.length - pos; int l = data.length - pos;
if (l > PLAYBACK_CHUNK_SIZE) l = PLAYBACK_CHUNK_SIZE; if (l > blockSize) l = blockSize;
play.write(data, pos, l); play.write(data, pos, l);
} }

View File

@@ -25,6 +25,7 @@ public class Options extends JDialog {
JComboBox<KVPair> bitDepth; JComboBox<KVPair> bitDepth;
JComboBox<KVPair> trimMethod; JComboBox<KVPair> trimMethod;
JComboBox<KVPair> fftBlockSize; JComboBox<KVPair> fftBlockSize;
JComboBox<KVPair> playbackBlockSize;
JTextField storageFolder; JTextField storageFolder;
JTextField archiveFolder; JTextField archiveFolder;
JSpinner preChapterGap; JSpinner preChapterGap;
@@ -303,6 +304,7 @@ public class Options extends JDialog {
addSeparator(optionsPanel); addSeparator(optionsPanel);
playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device")); playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device"));
playbackBlockSize = addDropdown(optionsPanel, "Playback Block size:", getPlaybackBlockSizes(), get("audio.playback.blocksize"));
addSeparator(optionsPanel); addSeparator(optionsPanel);
storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true); storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true);
archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), true); archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), true);
@@ -568,6 +570,7 @@ public class Options extends JDialog {
defaultPrefs.put("audio.playback.device", ""); defaultPrefs.put("audio.playback.device", "");
} }
defaultPrefs.put("audio.recording.trim.blocksize", "4096"); defaultPrefs.put("audio.recording.trim.blocksize", "4096");
defaultPrefs.put("audio.playback.blocksize", "4096");
defaultPrefs.put("catenation.pre-chapter", "1000"); defaultPrefs.put("catenation.pre-chapter", "1000");
defaultPrefs.put("catenation.post-chapter", "1500"); defaultPrefs.put("catenation.post-chapter", "1500");
@@ -712,6 +715,7 @@ public class Options extends JDialog {
set("cache.size", cacheSize.getValue()); set("cache.size", cacheSize.getValue());
set("audio.recording.trim.fft", fftThreshold.getValue()); set("audio.recording.trim.fft", fftThreshold.getValue());
set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.getSelectedItem()).key); set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.getSelectedItem()).key);
set("audio.playback.blocksize", ((KVPair)playbackBlockSize.getSelectedItem()).key);
set("effects.ethereal.offset", etherealOffset.getValue()); set("effects.ethereal.offset", etherealOffset.getValue());
set("effects.ethereal.iterations", etherealIterations.getValue()); set("effects.ethereal.iterations", etherealIterations.getValue());
@@ -799,6 +803,18 @@ public class Options extends JDialog {
return pairs; return pairs;
} }
public static KVPair[] getPlaybackBlockSizes() {
KVPair[] pairs = new KVPair[8];
pairs[0] = new KVPair<String, String>("1024", "1024");
pairs[1] = new KVPair<String, String>("2048", "2048");
pairs[2] = new KVPair<String, String>("4096", "4096");
pairs[3] = new KVPair<String, String>("8192", "8192");
pairs[4] = new KVPair<String, String>("16384", "16384");
pairs[5] = new KVPair<String, String>("32768", "32768");
pairs[6] = new KVPair<String, String>("65536", "65537");
pairs[7] = new KVPair<String, String>("131072", "131072");
return pairs;
}
public static void createEffectChains() { public static void createEffectChains() {
effectChains = new ArrayList<EffectGroup>(); effectChains = new ArrayList<EffectGroup>();