diff --git a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java index 7c6a7ce..246bcde 100644 --- a/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java +++ b/src/uk/co/majenko/audiobookrecorder/AudiobookRecorder.java @@ -30,8 +30,6 @@ public class AudiobookRecorder extends JFrame { // 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"; static Properties config = new Properties(); @@ -2178,6 +2176,8 @@ public class AudiobookRecorder extends JFrame { try { + int blockSize = Options.getInteger("audio.playback.blocksize"); + AudioFormat sampleformat = s.getAudioFormat(); float sampleRate = sampleformat.getSampleRate(); // sampleRate *= toolBar.getPlaybackSpeed(); @@ -2190,10 +2190,10 @@ public class AudiobookRecorder extends JFrame { bookTree.scrollPathToVisible(new TreePath(s.getPath())); 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()); int l = data.length - pos; - if (l > PLAYBACK_CHUNK_SIZE) l = PLAYBACK_CHUNK_SIZE; + if (l > blockSize) l = blockSize; play.write(data, pos, l); } @@ -2342,6 +2342,8 @@ public class AudiobookRecorder extends JFrame { try { + int blockSize = Options.getInteger("audio.playback.blocksize"); + AudioFormat sampleformat = s.getAudioFormat(); 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 (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()); int l = data.length - pos; - if (l > PLAYBACK_CHUNK_SIZE) l = PLAYBACK_CHUNK_SIZE; + if (l > blockSize) l = blockSize; play.write(data, pos, l); } @@ -2418,6 +2420,8 @@ public class AudiobookRecorder extends JFrame { try { + int blockSize = Options.getInteger("audio.playback.blocksize"); + AudioFormat sampleformat = s.getAudioFormat(); float sampleRate = sampleformat.getSampleRate(); sampleRate *= toolBar.getPlaybackSpeed(); @@ -2451,10 +2455,10 @@ public class AudiobookRecorder extends JFrame { }); 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()); int l = data.length - pos; - if (l > PLAYBACK_CHUNK_SIZE) l = PLAYBACK_CHUNK_SIZE; + if (l > blockSize) l = blockSize; play.write(data, pos, l); } diff --git a/src/uk/co/majenko/audiobookrecorder/Options.java b/src/uk/co/majenko/audiobookrecorder/Options.java index 0f6c4fc..2418267 100644 --- a/src/uk/co/majenko/audiobookrecorder/Options.java +++ b/src/uk/co/majenko/audiobookrecorder/Options.java @@ -25,6 +25,7 @@ public class Options extends JDialog { JComboBox bitDepth; JComboBox trimMethod; JComboBox fftBlockSize; + JComboBox playbackBlockSize; JTextField storageFolder; JTextField archiveFolder; JSpinner preChapterGap; @@ -303,6 +304,7 @@ public class Options extends JDialog { addSeparator(optionsPanel); playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device")); + playbackBlockSize = addDropdown(optionsPanel, "Playback Block size:", getPlaybackBlockSizes(), get("audio.playback.blocksize")); addSeparator(optionsPanel); storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), 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.recording.trim.blocksize", "4096"); + defaultPrefs.put("audio.playback.blocksize", "4096"); defaultPrefs.put("catenation.pre-chapter", "1000"); defaultPrefs.put("catenation.post-chapter", "1500"); @@ -712,6 +715,7 @@ public class Options extends JDialog { set("cache.size", cacheSize.getValue()); set("audio.recording.trim.fft", fftThreshold.getValue()); 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.iterations", etherealIterations.getValue()); @@ -799,6 +803,18 @@ public class Options extends JDialog { return pairs; } + public static KVPair[] getPlaybackBlockSizes() { + KVPair[] pairs = new KVPair[8]; + pairs[0] = new KVPair("1024", "1024"); + pairs[1] = new KVPair("2048", "2048"); + pairs[2] = new KVPair("4096", "4096"); + pairs[3] = new KVPair("8192", "8192"); + pairs[4] = new KVPair("16384", "16384"); + pairs[5] = new KVPair("32768", "32768"); + pairs[6] = new KVPair("65536", "65537"); + pairs[7] = new KVPair("131072", "131072"); + return pairs; + } public static void createEffectChains() { effectChains = new ArrayList();