Compare commits
89 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1005619211 | |||
| af31ba91a4 | |||
| 0e9ae7cc91 | |||
| 702160c1df | |||
| b57c1b5753 | |||
| e22a1ce84a | |||
| 83c728e7c8 | |||
| ed75718d34 | |||
| 75873b9e8c | |||
| 1416f6d632 | |||
| 8a7e070f46 | |||
| 1c953dbf1f | |||
| da3b88e083 | |||
| 13d8dc4612 | |||
| 785a4f1b7b | |||
| 43b0ccd96d | |||
| f6af5ce2e7 | |||
| 577ff9c1eb | |||
| f0ae69d610 | |||
| 7e6a08d64b | |||
| 5f34c57b23 | |||
| 356d95191b | |||
| 903f8eaa91 | |||
| 1b7dd7dfb1 | |||
| ca0a15ba09 | |||
| c52422247c | |||
| c9b65cb315 | |||
| fc3365af62 | |||
| 7c7cd58963 | |||
| aea5a58691 | |||
| fab7f1a91c | |||
| 9b23eb56ce | |||
| 450e80ad21 | |||
| 21d7d9d597 | |||
| 746f47a5fa | |||
| c67e6d6abc | |||
| 1f722f5df3 | |||
| df4eae1d66 | |||
| 4d435b4fc1 | |||
| f95ae10d03 | |||
| 423d840d83 | |||
| 1997b0bf9b | |||
| b206fb33aa | |||
| 11b26e396c | |||
| 94139e6ac6 | |||
| c0cc2432ff | |||
| f86aaa3782 | |||
| 690a8f0c3b | |||
| 1de0ca8d60 | |||
| de149c5d85 | |||
| 7d2b11473b | |||
| 4c25fccc86 | |||
| 5e310b0224 | |||
| 169802ccaf | |||
| 28257e00c0 | |||
| 38c6af7090 | |||
| bdbf4c604d | |||
| 73bcba2c9a | |||
| 90ca84cfbf | |||
| a18ca1ce21 | |||
| b92babb5cd | |||
| e3231ec495 | |||
| 4896ee7a65 | |||
| ce3eb7165a | |||
| 4de00b8fac | |||
| ebe777bdc5 | |||
| 3b5cacb8ad | |||
| db7d297dbc | |||
| 2f9abf7629 | |||
| b6063d2fed | |||
| e1f566f0c8 | |||
| 9fa892a6fd | |||
| 1572e163ef | |||
| 2791691057 | |||
| 575537ae66 | |||
| fde4a597c7 | |||
| e69ae52f50 | |||
| 8bdb06749f | |||
| 0cfd066f4f | |||
| 217ccb915a | |||
| 1dd3e9d86f | |||
| d3d81d71fe | |||
| 80c110afa9 | |||
| 1c08b9a51d | |||
| 4ad30106b6 | |||
| 9100d0e35a | |||
| b8dea19c30 | |||
| 671f2b9270 | |||
| d619fb2f4d |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,3 +5,4 @@ AudiobookRecorder.jar
|
|||||||
AudiobookRecorder-linux
|
AudiobookRecorder-linux
|
||||||
AudiobookRecorder-osx.dmg
|
AudiobookRecorder-osx.dmg
|
||||||
AudiobookRecorder-win.exe
|
AudiobookRecorder-win.exe
|
||||||
|
.*.swp
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<effect name="Alien">
|
<effect name="Alien">
|
||||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
<!--biquad type="lowpass" fc="10000" q="1" gain="-10" /-->
|
||||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
<lfo frequency="50" depth="1.0" waveform="triangle" mode="replace"/>
|
||||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
|
||||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
|
||||||
<lfo frequency="100" depth="0.5" />
|
|
||||||
</effect>
|
</effect>
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<effect name="Big Echo">
|
<effect name="Big Echo">
|
||||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
|
||||||
<delayline>
|
<delayline>
|
||||||
<delay samples="22000" gain="0.2" pan="-0.3">
|
<delay samples="22000" gain="0.2" pan="-0.3">
|
||||||
<biquad type="highpass" fc="300" q="1" gain="0" />
|
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||||
|
|||||||
@@ -3,5 +3,5 @@
|
|||||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||||
<agc ceiling="0.666" limit="1" attack="0.1" decay="0.01" />
|
<agc ceiling="0.666" limit="1.5" attack="0.08" decay="0.01" />
|
||||||
</effect>
|
</effect>
|
||||||
|
|||||||
15
ExampleFilters/cuthumagcstereo.eff
Normal file
15
ExampleFilters/cuthumagcstereo.eff
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<effect name="Cut Computer Hum (with AGC and Stereo)">
|
||||||
|
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||||
|
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||||
|
<delayline wetonly="false">
|
||||||
|
<delay samples="-100" gain="0.1" pan="-1.0">
|
||||||
|
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||||
|
</delay>
|
||||||
|
<delay samples="100" gain="0.1" pan="1.0">
|
||||||
|
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||||
|
</delay>
|
||||||
|
</delayline>
|
||||||
|
<agc ceiling="0.666" limit="1.5" attack="0.1" decay="0.01" />
|
||||||
|
</effect>
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
<effect name="Ethereal Voice">
|
<effect name="Ethereal Voice">
|
||||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
|
||||||
<amplifier gain="0.1" />
|
<amplifier gain="0.1" />
|
||||||
<delayline>
|
<delayline>
|
||||||
<delay samples="2000" gain="1.0" pan="-0.3">
|
<delay samples="2000" gain="1.0" pan="-0.3">
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<effect name="Large Room (quiet)">
|
<effect name="Large Room (quiet)">
|
||||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
|
||||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||||
<delayline>
|
<delayline>
|
||||||
<delay samples="5500" gain="0.2" pan="-0.3">
|
<delay samples="5500" gain="0.2" pan="-0.3">
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<effect name="Large Room (loud)">
|
<effect name="Large Room (loud)">
|
||||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
|
||||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||||
<delayline>
|
<delayline>
|
||||||
<delay samples="5500" gain="0.2" pan="-0.3">
|
<delay samples="5500" gain="0.2" pan="-0.3">
|
||||||
|
|||||||
3
ExampleFilters/panleft.eff
Normal file
3
ExampleFilters/panleft.eff
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<effect name="Pan Left">
|
||||||
|
<pan pan="-0.4" />
|
||||||
|
</effect>
|
||||||
3
ExampleFilters/panright.eff
Normal file
3
ExampleFilters/panright.eff
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<effect name="Pan Right">
|
||||||
|
<pan pan="0.4" />
|
||||||
|
</effect>
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
<effect name="Telephone">
|
<effect name="Telephone">
|
||||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
|
||||||
<biquad type="lowshelf" fc="400" q="10" gain="-20" />
|
<biquad type="lowshelf" fc="400" q="10" gain="-20" />
|
||||||
<biquad type="highshelf" fc="8000" q="10" gain="-20" />
|
<biquad type="highshelf" fc="8000" q="10" gain="-20" />
|
||||||
<delayline>
|
<delayline>
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
<effect name="Radio">
|
<effect name="Radio">
|
||||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
<amplifier gain="0.5" />
|
||||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
<biquad type="peak" fc="1000" q="10" gain="25" />
|
||||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
<lfo frequency="3000" depth="0.3" waveform="sine" mode="add" />
|
||||||
<amplifier gain="0.1" />
|
<clipping clip="0.9" />
|
||||||
<biquad type="peak" fc="1000" q="10" gain="45" />
|
|
||||||
<lfo frequency="5000" depth="0.3" />
|
|
||||||
<clipping clip="0.3" />
|
|
||||||
<biquad type="highshelf" fc="8000" q="1" gain="-20" />
|
<biquad type="highshelf" fc="8000" q="1" gain="-20" />
|
||||||
<delayline>
|
<delayline>
|
||||||
<delay samples="100" gain="0.7" />
|
<delay samples="100" gain="0.7" />
|
||||||
<delay samples="200" gain="0.5" />
|
<delay samples="200" gain="0.5" />
|
||||||
</delayline>
|
</delayline>
|
||||||
|
<amplifier gain="0.3" />
|
||||||
</effect>
|
</effect>
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
<effect name="Robotic">
|
<effect name="Robotic">
|
||||||
<biquad type="notch" fc="28" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="91" q="20" gain="-50" />
|
|
||||||
<biquad type="notch" fc="120" q="20" gain="-50" />
|
|
||||||
<biquad type="lowshelf" fc="100" q="2" gain="-20" />
|
<biquad type="lowshelf" fc="100" q="2" gain="-20" />
|
||||||
<delayline>
|
<delayline>
|
||||||
<delay samples="400" gain="1" pan="-0.3" />
|
<delay samples="400" gain="1" pan="-0.3" />
|
||||||
|
|||||||
10
ExampleFilters/stereochorus.eff
Normal file
10
ExampleFilters/stereochorus.eff
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<effect name="Stereo Chorus">
|
||||||
|
<delayline>
|
||||||
|
<delay samples="2000" gain="0.1" pan="-0.3">
|
||||||
|
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||||
|
</delay>
|
||||||
|
<delay samples="4000" gain="0.1" pan="0.3">
|
||||||
|
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||||
|
</delay>
|
||||||
|
</delayline>
|
||||||
|
</effect>
|
||||||
40
README.md
40
README.md
@@ -10,6 +10,8 @@ A system for easing the task of recording and editing audiobooks.
|
|||||||
* Chapter management
|
* Chapter management
|
||||||
* Audio effect chains (biquad, delay line, etc)
|
* Audio effect chains (biquad, delay line, etc)
|
||||||
|
|
||||||
|
# [Manual and Tutorial](https://majenkoprojects.github.io/AudiobookRecorder)
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
@@ -29,12 +31,13 @@ From here on much is controlled by key presses.
|
|||||||
appended to the currently selected chapter, or to the last chapter if none is selected.
|
appended to the currently selected chapter, or to the last chapter if none is selected.
|
||||||
* Press and hold "T" to record a new phrase that is the start of a new paragraph. This adds the "post paragraph" gap to the previous sentence. Otherwise it does the same as "R".
|
* Press and hold "T" to record a new phrase that is the start of a new paragraph. This adds the "post paragraph" gap to the previous sentence. Otherwise it does the same as "R".
|
||||||
* Press and hold "F" to record a "continuation" phrase. This sets the previous phrase's post-gap to be the "short" gap instead of the normal length gap.
|
* Press and hold "F" to record a "continuation" phrase. This sets the previous phrase's post-gap to be the "short" gap instead of the normal length gap.
|
||||||
|
* Press and hold "Y" to record a new phrase that is the start of a new section. This add the "post section" gap to the previous sentence. Otherwise it does the same as "R".
|
||||||
* Press "D" to delete the last phrase you recorded.
|
* Press "D" to delete the last phrase you recorded.
|
||||||
* Press "E" to re-record the currently selected phrase.
|
* Press "E" to re-record the currently selected phrase.
|
||||||
|
|
||||||
Each phrase you record will be briefly analysed using FFT to find the start and end of the audio and set
|
Each phrase you record can be automatically analysed to find the start and end of the audio and set
|
||||||
crop marks appropriately. These can be adjusted in the waveform display when a phrase is selected. You can also
|
crop marks appropriately. These can be adjusted in the waveform display when a phrase is selected. You can also
|
||||||
re-run the analysis using either the default FFT method or using a peak detector method (finding the first and last points
|
re-run the analysis using either FFT or a peak detector method (finding the first and last points
|
||||||
where the audio amplitude rises above the backround noise).
|
where the audio amplitude rises above the backround noise).
|
||||||
|
|
||||||
The phrases also have a "post gap" associated with them. This is the amount of room noise (in milliseconds) to place between
|
The phrases also have a "post gap" associated with them. This is the amount of room noise (in milliseconds) to place between
|
||||||
@@ -53,18 +56,14 @@ edit the text of this ID to identify the recordings. You
|
|||||||
may, for instance, change it to have the same text as the
|
may, for instance, change it to have the same text as the
|
||||||
audio contains.
|
audio contains.
|
||||||
|
|
||||||
To help with this the Haven On-Demand online speech recognition
|
The audio can also be automatically converted to text if you have an suitable command-line
|
||||||
service is integrated with the system and can be used to try and convert the
|
executable that will work. One example is (on Linux) [DeepSpeech](https://github.com/mozilla/DeepSpeech) by Mozilla.
|
||||||
audio into text. Right clicking on a recording brings
|
|
||||||
up a menu which includes the option to try and convert
|
|
||||||
the audio into text. The detected text is then used to
|
|
||||||
replace the current recording ID / text.
|
|
||||||
|
|
||||||
File layout
|
File layout
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
All data is stored in your "storage" directory (specified in Options). Each book (which is a directory named after the
|
All data is stored in your "storage" directory (specified in Options). Each book (which is a directory named after the
|
||||||
title of the book) has an associated XML file (audiobook.abk) and a directory "files" where all the audio (stored as WAV
|
title of the book) has an associated XML file (audiobook.abx) and a directory "files" where all the audio (stored as WAV
|
||||||
files) is placed.
|
files) is placed.
|
||||||
|
|
||||||
When you export the book as MP3 a new folder "export" is created within the book's folder where the MP3 files are placed.
|
When you export the book as MP3 a new folder "export" is created within the book's folder where the MP3 files are placed.
|
||||||
@@ -81,3 +80,26 @@ Building
|
|||||||
5. Build with `ant build`
|
5. Build with `ant build`
|
||||||
6. Run with `java -jar ./AudiobookRecorder.jar`
|
6. Run with `java -jar ./AudiobookRecorder.jar`
|
||||||
|
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Extra Resources
|
||||||
|
===============
|
||||||
|
|
||||||
|
* DeepSpeech wrapper script
|
||||||
|
|
||||||
|
This is a small script that will convert the audio into a format DeepSpeech likes and call the `deepspeech` executable, removing any extra rubbish from the output. It
|
||||||
|
also requires `sox` to be installed for the audio conversion.
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
ID=$$
|
||||||
|
FILE=$1
|
||||||
|
BINPATH=${HOME}/local/bin
|
||||||
|
MODELS=${HOME}/ds/deepspeech-0.6.1-models
|
||||||
|
|
||||||
|
sox "$FILE" -r 16000 -c 1 -b 16 "/tmp/ds-${ID}.wav"
|
||||||
|
${BINPATH}/deepspeech --model ${MODELS}/output_graph.pbmm --lm ${MODELS}/lm.binary --trie ${MODELS}/trie --audio "/tmp/ds-${ID}.wav" 2>/dev/null
|
||||||
|
rm /tmp/ds-${ID}.wav
|
||||||
|
```
|
||||||
|
|||||||
BIN
deps/commons-lang3.jar
LFS
vendored
Normal file
BIN
deps/commons-lang3.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/commons-text.jar
LFS
vendored
Normal file
BIN
deps/commons-text.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/json-20190722.jar
LFS
vendored
Normal file
BIN
deps/json-20190722.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
Binary file not shown.
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
Binary file not shown.
133
iircoeff.c
133
iircoeff.c
@@ -1,133 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2002-2006 Felipe Rivera <liebremx at users.sourceforge.net>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* Coefficient stuff
|
|
||||||
*
|
|
||||||
* $Id: iir_cfs.c,v 1.2 2006/01/15 00:17:46 liebremx Exp $
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
static const double band_f031[] =
|
|
||||||
{ 20,25,31.5,40,50,63,80,100,125,160,200,250,315,400,500,630,800,
|
|
||||||
1000,1250,1600,2000,2500,3150,4000,5000,6300,8000,10000,12500,16000,20000
|
|
||||||
};
|
|
||||||
|
|
||||||
#define GAIN_F0 1.0
|
|
||||||
#define GAIN_F1 GAIN_F0 / M_SQRT2
|
|
||||||
|
|
||||||
#define SAMPLING_FREQ 44100.0
|
|
||||||
#define TETA(f) (2*M_PI*(double)f/sample_frequency)
|
|
||||||
#define TWOPOWER(value) (value * value)
|
|
||||||
|
|
||||||
#define BETA2(tf0, tf) \
|
|
||||||
(TWOPOWER(GAIN_F1)*TWOPOWER(cos(tf0)) \
|
|
||||||
- 2.0 * TWOPOWER(GAIN_F1) * cos(tf) * cos(tf0) \
|
|
||||||
+ TWOPOWER(GAIN_F1) \
|
|
||||||
- TWOPOWER(GAIN_F0) * TWOPOWER(sin(tf)))
|
|
||||||
#define BETA1(tf0, tf) \
|
|
||||||
(2.0 * TWOPOWER(GAIN_F1) * TWOPOWER(cos(tf)) \
|
|
||||||
+ TWOPOWER(GAIN_F1) * TWOPOWER(cos(tf0)) \
|
|
||||||
- 2.0 * TWOPOWER(GAIN_F1) * cos(tf) * cos(tf0) \
|
|
||||||
- TWOPOWER(GAIN_F1) + TWOPOWER(GAIN_F0) * TWOPOWER(sin(tf)))
|
|
||||||
#define BETA0(tf0, tf) \
|
|
||||||
(0.25 * TWOPOWER(GAIN_F1) * TWOPOWER(cos(tf0)) \
|
|
||||||
- 0.5 * TWOPOWER(GAIN_F1) * cos(tf) * cos(tf0) \
|
|
||||||
+ 0.25 * TWOPOWER(GAIN_F1) \
|
|
||||||
- 0.25 * TWOPOWER(GAIN_F0) * TWOPOWER(sin(tf)))
|
|
||||||
|
|
||||||
#define GAMMA(beta, tf0) ((0.5 + beta) * cos(tf0))
|
|
||||||
#define ALPHA(beta) ((0.5 - beta)/2.0)
|
|
||||||
|
|
||||||
/*************
|
|
||||||
* Functions *
|
|
||||||
*************/
|
|
||||||
|
|
||||||
/* Get the band_f031 at both sides of F0. These will be cut at -3dB */
|
|
||||||
static void find_f1_and_f2(double f0, double octave_percent, double *f1, double *f2)
|
|
||||||
{
|
|
||||||
double octave_factor = pow(2.0, octave_percent/2.0);
|
|
||||||
*f1 = f0/octave_factor;
|
|
||||||
*f2 = f0*octave_factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find the quadratic root
|
|
||||||
* Always return the smallest root */
|
|
||||||
static int find_root(double a, double b, double c, double *x0) {
|
|
||||||
double k = c-((b*b)/(4.*a));
|
|
||||||
double h = -(b/(2.*a));
|
|
||||||
double x1 = 0.;
|
|
||||||
if (-(k/a) < 0.)
|
|
||||||
return -1;
|
|
||||||
*x0 = h - sqrt(-(k/a));
|
|
||||||
x1 = h + sqrt(-(k/a));
|
|
||||||
if (x1 < *x0)
|
|
||||||
*x0 = x1;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void calc_coeffs(double sample_frequency)
|
|
||||||
{
|
|
||||||
int i, n;
|
|
||||||
double f1, f2;
|
|
||||||
double x0;
|
|
||||||
|
|
||||||
printf(" public final static IIRCoefficients iir_cf31_%d[] = {\n", (int)sample_frequency);
|
|
||||||
for (i = 0; i < 31; i++) {
|
|
||||||
|
|
||||||
/* Find -3dB frequencies for the center freq */
|
|
||||||
find_f1_and_f2(band_f031[i], 1.0/3.0, &f1, &f2);
|
|
||||||
/* Find Beta */
|
|
||||||
if ( find_root(
|
|
||||||
BETA2(TETA(band_f031[i]), TETA(f1)),
|
|
||||||
BETA1(TETA(band_f031[i]), TETA(f1)),
|
|
||||||
BETA0(TETA(band_f031[i]), TETA(f1)),
|
|
||||||
&x0) == 0)
|
|
||||||
{
|
|
||||||
/* Got a solution, now calculate the rest of the factors */
|
|
||||||
/* Take the smallest root always (find_root returns the smallest one)
|
|
||||||
*
|
|
||||||
* NOTE: The IIR equation is
|
|
||||||
* y[n] = 2 * (alpha*(x[n]-x[n-2]) + gamma*y[n-1] - beta*y[n-2])
|
|
||||||
* Now the 2 factor has been distributed in the coefficients
|
|
||||||
*/
|
|
||||||
/* Now store the coefficients */
|
|
||||||
printf(" /* %.1f Hz */\n", band_f031[i]);
|
|
||||||
printf(" new IIRCoefficients(%.10e, %010e, %.10e),\n",
|
|
||||||
(double)(2.0 * x0),
|
|
||||||
(double)(2.0 * ALPHA(x0)),
|
|
||||||
(double)(2.0 * GAMMA(x0, TETA(band_f031[i])))
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
printf(" **** Where are the roots?\n");
|
|
||||||
}
|
|
||||||
}// for i
|
|
||||||
printf(" };\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
if (argc != 2) {
|
|
||||||
printf("Usage: iircoeff <sample frequency>\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
double f = strtod(argv[1], NULL);
|
|
||||||
calc_coeffs(f);
|
|
||||||
}
|
|
||||||
76
iircoeff.pl
76
iircoeff.pl
@@ -1,76 +0,0 @@
|
|||||||
#!/usr/bin/perl
|
|
||||||
|
|
||||||
use Math::Trig;
|
|
||||||
|
|
||||||
my $fs = 48000;
|
|
||||||
my $q = 1.414;
|
|
||||||
|
|
||||||
printCo(20, $fs, $q);
|
|
||||||
printCo(25, $fs, $q);
|
|
||||||
printCo(31.5, $fs, $q);
|
|
||||||
printCo(40, $fs, $q);
|
|
||||||
printCo(50, $fs, $q);
|
|
||||||
printCo(63, $fs, $q);
|
|
||||||
printCo(80, $fs, $q);
|
|
||||||
printCo(100, $fs, $q);
|
|
||||||
printCo(125, $fs, $q);
|
|
||||||
printCo(160, $fs, $q);
|
|
||||||
printCo(200, $fs, $q);
|
|
||||||
printCo(250, $fs, $q);
|
|
||||||
printCo(315, $fs, $q);
|
|
||||||
printCo(400, $fs, $q);
|
|
||||||
printCo(500, $fs, $q);
|
|
||||||
printCo(630, $fs, $q);
|
|
||||||
printCo(800, $fs, $q);
|
|
||||||
printCo(1000, $fs, $q);
|
|
||||||
printCo(1250, $fs, $q);
|
|
||||||
printCo(1600, $fs, $q);
|
|
||||||
printCo(2000, $fs, $q);
|
|
||||||
printCo(2500, $fs, $q);
|
|
||||||
printCo(3150, $fs, $q);
|
|
||||||
printCo(4000, $fs, $q);
|
|
||||||
printCo(5000, $fs, $q);
|
|
||||||
printCo(6300, $fs, $q);
|
|
||||||
printCo(8000, $fs, $q);
|
|
||||||
printCo(10000, $fs, $q);
|
|
||||||
printCo(12500, $fs, $q);
|
|
||||||
printCo(16000, $fs, $q);
|
|
||||||
printCo(20000, $fs, $q);
|
|
||||||
|
|
||||||
sub printCo($$$$) {
|
|
||||||
my $f0 = shift;
|
|
||||||
my $fs = shift;
|
|
||||||
my $q = shift;
|
|
||||||
|
|
||||||
|
|
||||||
@coeff = coefficient($f0, $fs, $q);
|
|
||||||
print "/* $f0 Hz */\n";
|
|
||||||
printf("new IIRCoefficients(%.10e, %.10e, %.10e),\n" , $coeff[1] * 2, $coeff[0] * 2, $coeff[2] * 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub coefficient($$$$) {
|
|
||||||
my $f0 = shift;
|
|
||||||
my $fs = shift;
|
|
||||||
my $q = shift;
|
|
||||||
|
|
||||||
my $q2 = $q * $q;
|
|
||||||
|
|
||||||
my $f1 = $f0 * (sqrt(1 + (1 / (4 * $q2))) - (1 / (2 * $q)));
|
|
||||||
my $f2 = $f0 * (sqrt(1 + (1 / (4 * $q2))) + (1 / (2 * $q)));
|
|
||||||
|
|
||||||
my $pi = 3.141592653;
|
|
||||||
|
|
||||||
my $theta0 = 2 * $pi * ($f0 / $fs);
|
|
||||||
|
|
||||||
my $thetaOverTwoQ = $theta0 / (2 * $q);
|
|
||||||
|
|
||||||
my $beta = 0.5 * ((1 - tan($thetaOverTwoQ)) / (1 + tan($thetaOverTwoQ)));
|
|
||||||
|
|
||||||
my $gamma = (0.5 + $beta) * cos($theta0);
|
|
||||||
|
|
||||||
my $alpha = (0.5 - $beta) / 2;
|
|
||||||
|
|
||||||
return ($alpha, $beta, $gamma);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1 +1 @@
|
|||||||
version=0.2.0
|
version=0.4.1
|
||||||
|
|||||||
BIN
resources/uk/co/majenko/audiobookrecorder/icons/close.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/close.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/manuscript.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/manuscript.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/processing.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/processing.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 489 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/queued.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/queued.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 717 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/refresh.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/refresh.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/tooltip.png
Normal file
BIN
resources/uk/co/majenko/audiobookrecorder/icons/tooltip.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
@@ -10,6 +10,7 @@ public class AGC implements Effect {
|
|||||||
double attack;
|
double attack;
|
||||||
|
|
||||||
public AGC(double c, double a, double d, double l) {
|
public AGC(double c, double a, double d, double l) {
|
||||||
|
Debug.trace();
|
||||||
ceiling = c;
|
ceiling = c;
|
||||||
attack = a;
|
attack = a;
|
||||||
decay = d;
|
decay = d;
|
||||||
@@ -18,18 +19,21 @@ public class AGC implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit;
|
return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
|
Debug.trace();
|
||||||
gain = 1d;
|
gain = 1d;
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
double absSampleLeft = Math.abs(samples[i][Sentence.LEFT]) * gain;
|
double absSampleLeft = Math.abs(samples[Sentence.LEFT][i]) * gain;
|
||||||
double absSampleRight = Math.abs(samples[i][Sentence.RIGHT]) * gain;
|
double absSampleRight = Math.abs(samples[Sentence.RIGHT][i]) * gain;
|
||||||
|
|
||||||
double factor = 0.0d;
|
double factor = 0.0d;
|
||||||
|
|
||||||
@@ -47,21 +51,25 @@ public class AGC implements Effect {
|
|||||||
|
|
||||||
gain += factor;
|
gain += factor;
|
||||||
if (gain > limit) gain = limit;
|
if (gain > limit) gain = limit;
|
||||||
|
if (gain < 0) gain = 0;
|
||||||
|
|
||||||
samples[i][Sentence.LEFT] *= gain;
|
samples[Sentence.LEFT][i] *= gain;
|
||||||
samples[i][Sentence.RIGHT] *= gain;
|
samples[Sentence.RIGHT][i] *= gain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(double sr) {
|
public void init(double sr) {
|
||||||
|
Debug.trace();
|
||||||
gain = 1d;
|
gain = 1d;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump() {
|
public void dump() {
|
||||||
|
Debug.trace();
|
||||||
System.out.println(toString());
|
System.out.println(toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Effect> getChildEffects() {
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
Debug.trace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.*;
|
import javax.swing.Box;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
public class AboutPanel extends JPanel {
|
public class AboutPanel extends JPanel {
|
||||||
|
|
||||||
public AboutPanel() {
|
public AboutPanel() {
|
||||||
|
Debug.trace();
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
JLabel icon = new JLabel(Icons.appIcon);
|
JLabel icon = new JLabel(Icons.appIcon);
|
||||||
add(icon, BorderLayout.WEST);
|
add(icon, BorderLayout.WEST);
|
||||||
@@ -17,7 +22,7 @@ public class AboutPanel extends JPanel {
|
|||||||
|
|
||||||
JLabel l1 = new JLabel("AudiobookRecorder");
|
JLabel l1 = new JLabel("AudiobookRecorder");
|
||||||
JLabel l2 = new JLabel("Version " + AudiobookRecorder.config.getProperty("version"));
|
JLabel l2 = new JLabel("Version " + AudiobookRecorder.config.getProperty("version"));
|
||||||
JLabel l3 = new JLabel("(c) 2018 Majenko Technologies");
|
JLabel l3 = new JLabel("(c) 2020 Majenko Technologies");
|
||||||
|
|
||||||
l1.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
l1.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
||||||
l2.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
l2.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
||||||
|
|||||||
@@ -5,43 +5,53 @@ import java.util.ArrayList;
|
|||||||
public class Amplifier implements Effect {
|
public class Amplifier implements Effect {
|
||||||
double gain;
|
double gain;
|
||||||
public Amplifier() {
|
public Amplifier() {
|
||||||
|
Debug.trace();
|
||||||
gain = 1.0d;
|
gain = 1.0d;
|
||||||
}
|
}
|
||||||
public Amplifier(double g) {
|
public Amplifier(double g) {
|
||||||
|
Debug.trace();
|
||||||
gain = g;
|
gain = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
return "Amplifier (" + gain + ")";
|
return "Amplifier (" + gain + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Effect> getChildEffects() {
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
Debug.trace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
for (int i = 0; i < samples.length; i++) {
|
Debug.trace();
|
||||||
samples[i][Sentence.LEFT] *= gain;
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
samples[i][Sentence.RIGHT] *= gain;
|
samples[Sentence.LEFT][i] *= gain;
|
||||||
|
samples[Sentence.RIGHT][i] *= gain;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getGain() {
|
public double getGain() {
|
||||||
|
Debug.trace();
|
||||||
return gain;
|
return gain;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGain(double g) {
|
public void setGain(double g) {
|
||||||
|
Debug.trace();
|
||||||
gain = g;
|
gain = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump() {
|
public void dump() {
|
||||||
|
Debug.trace();
|
||||||
System.out.println(toString());
|
System.out.println(toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(double sf) {
|
public void init(double sf) {
|
||||||
|
Debug.trace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,23 +1,5 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
// Biquad.java
|
|
||||||
//
|
|
||||||
// Created by Nigel Redmon on 11/24/12
|
|
||||||
// EarLevel Engineering: earlevel.com
|
|
||||||
// Copyright 2012 Nigel Redmon
|
|
||||||
// Translated to Java 2019 Majenko Technologies
|
|
||||||
//
|
|
||||||
// For a complete explanation of the Biquad code:
|
|
||||||
// http://www.earlevel.com/main/2012/11/26/biquad-c-source-code/
|
|
||||||
//
|
|
||||||
// License:
|
|
||||||
//
|
|
||||||
// This source code is provided as is, without warranty.
|
|
||||||
// You may copy and distribute verbatim copies of this document.
|
|
||||||
// You may modify and use this source code to create binary code
|
|
||||||
// for your own purposes, free or commercial.
|
|
||||||
//
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Biquad implements Effect {
|
public class Biquad implements Effect {
|
||||||
@@ -37,6 +19,7 @@ public class Biquad implements Effect {
|
|||||||
double sampleFrequency;
|
double sampleFrequency;
|
||||||
|
|
||||||
public Biquad() {
|
public Biquad() {
|
||||||
|
Debug.trace();
|
||||||
type = Lowpass;
|
type = Lowpass;
|
||||||
a0 = 1.0d;
|
a0 = 1.0d;
|
||||||
a1 = 0.0d;
|
a1 = 0.0d;
|
||||||
@@ -54,6 +37,7 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Biquad(int type, double Fc, double Q, double peakGainDB) {
|
public Biquad(int type, double Fc, double Q, double peakGainDB) {
|
||||||
|
Debug.trace();
|
||||||
setBiquad(type, Fc, Q, peakGainDB);
|
setBiquad(type, Fc, Q, peakGainDB);
|
||||||
lz1 = 0.0;
|
lz1 = 0.0;
|
||||||
lz2 = 0.0;
|
lz2 = 0.0;
|
||||||
@@ -63,26 +47,31 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setType(int typei) {
|
public void setType(int typei) {
|
||||||
|
Debug.trace();
|
||||||
type = typei;
|
type = typei;
|
||||||
calcBiquad();
|
calcBiquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setQ(double Qi) {
|
public void setQ(double Qi) {
|
||||||
|
Debug.trace();
|
||||||
Q = Qi;
|
Q = Qi;
|
||||||
calcBiquad();
|
calcBiquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFc(double Fci) {
|
public void setFc(double Fci) {
|
||||||
|
Debug.trace();
|
||||||
Fc = Fci;
|
Fc = Fci;
|
||||||
calcBiquad();
|
calcBiquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPeakGain(double peakGainDB) {
|
public void setPeakGain(double peakGainDB) {
|
||||||
|
Debug.trace();
|
||||||
peakGain = peakGainDB;
|
peakGain = peakGainDB;
|
||||||
calcBiquad();
|
calcBiquad();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBiquad(int typei, double Fci, double Qi, double peakGainDB) {
|
public void setBiquad(int typei, double Fci, double Qi, double peakGainDB) {
|
||||||
|
Debug.trace();
|
||||||
type = typei;
|
type = typei;
|
||||||
Q = Qi;
|
Q = Qi;
|
||||||
Fc = Fci;
|
Fc = Fci;
|
||||||
@@ -90,27 +79,29 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
|
Debug.trace();
|
||||||
lz1 = 0d;
|
lz1 = 0d;
|
||||||
lz2 = 0d;
|
lz2 = 0d;
|
||||||
rz1 = 0d;
|
rz1 = 0d;
|
||||||
rz2 = 0d;
|
rz2 = 0d;
|
||||||
for (double[] in : samples) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
double lout = in[Sentence.LEFT] * a0 + lz1;
|
double lout = samples[Sentence.LEFT][i] * a0 + lz1;
|
||||||
|
|
||||||
lz1 = in[Sentence.LEFT] * a1 + lz2 - b1 * lout;
|
lz1 = samples[Sentence.LEFT][i] * a1 + lz2 - b1 * lout;
|
||||||
lz2 = in[Sentence.LEFT] * a2 - b2 * lout;
|
lz2 = samples[Sentence.LEFT][i] * a2 - b2 * lout;
|
||||||
|
|
||||||
double rout = in[Sentence.RIGHT] * a0 + rz1;
|
double rout = samples[Sentence.RIGHT][i] * a0 + rz1;
|
||||||
|
|
||||||
rz1 = in[Sentence.RIGHT] * a1 + rz2 - b1 * rout;
|
rz1 = samples[Sentence.RIGHT][i] * a1 + rz2 - b1 * rout;
|
||||||
rz2 = in[Sentence.RIGHT] * a2 - b2 * rout;
|
rz2 = samples[Sentence.RIGHT][i] * a2 - b2 * rout;
|
||||||
|
|
||||||
in[Sentence.LEFT] = lout;
|
samples[Sentence.LEFT][i] = lout;
|
||||||
in[Sentence.RIGHT] = rout;
|
samples[Sentence.RIGHT][i] = rout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(double sf) {
|
public void init(double sf) {
|
||||||
|
Debug.trace();
|
||||||
sampleFrequency = sf;
|
sampleFrequency = sf;
|
||||||
lz1 = 0d;
|
lz1 = 0d;
|
||||||
lz2 = 0d;
|
lz2 = 0d;
|
||||||
@@ -120,6 +111,7 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void calcBiquad() {
|
void calcBiquad() {
|
||||||
|
Debug.trace();
|
||||||
|
|
||||||
double norm;
|
double norm;
|
||||||
double V = Math.pow(10, Math.abs(peakGain) / 20.0);
|
double V = Math.pow(10, Math.abs(peakGain) / 20.0);
|
||||||
@@ -221,6 +213,7 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
String n = "Biquad Filter (";
|
String n = "Biquad Filter (";
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Lowpass: n += "Lowpass"; break;
|
case Lowpass: n += "Lowpass"; break;
|
||||||
@@ -242,14 +235,17 @@ public class Biquad implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<Effect> getChildEffects() {
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
Debug.trace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return getName();
|
return getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump() {
|
public void dump() {
|
||||||
|
Debug.trace();
|
||||||
System.out.println(toString());
|
System.out.println(toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,59 +1,198 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.io.File;
|
||||||
import javax.swing.event.*;
|
import java.io.IOException;
|
||||||
import java.awt.*;
|
import java.nio.file.Files;
|
||||||
import java.awt.event.*;
|
import java.util.Arrays;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
import java.io.*;
|
import java.util.Enumeration;
|
||||||
import java.nio.file.*;
|
import java.util.UUID;
|
||||||
import javax.swing.tree.*;
|
import java.util.Random;
|
||||||
import javax.sound.sampled.*;
|
import java.util.TimerTask;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
import java.awt.Image;
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.tree.TreeNode;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
import javax.xml.transform.TransformerConfigurationException;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import javax.xml.transform.OutputKeys;
|
||||||
|
import org.w3c.dom.Attr;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
public class Book extends DefaultMutableTreeNode {
|
public class Book extends BookTreeNode {
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
String author;
|
String author;
|
||||||
String genre;
|
String genre;
|
||||||
String comment;
|
String comment;
|
||||||
String ACX;
|
String ACX;
|
||||||
|
String manuscript;
|
||||||
int sampleRate;
|
String defaultEffect = "none";
|
||||||
int channels;
|
Sentence roomNoise = null;
|
||||||
int resolution;
|
String notes = null;
|
||||||
|
|
||||||
ImageIcon icon;
|
ImageIcon icon;
|
||||||
|
File location;
|
||||||
|
Random rng = new Random();
|
||||||
|
TreeMap<String, EffectGroup> effects;
|
||||||
|
AudioFormat cachedFormat = null;
|
||||||
|
|
||||||
Properties prefs;
|
public Book(String bookname) {
|
||||||
|
|
||||||
public Book(Properties p, String bookname) {
|
|
||||||
super(bookname);
|
super(bookname);
|
||||||
|
Debug.trace();
|
||||||
prefs = p;
|
|
||||||
name = bookname;
|
name = bookname;
|
||||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
location = new File(Options.get("path.storage"), sanitize(name));
|
||||||
|
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
||||||
|
setIcon(Icons.book);
|
||||||
|
roomNoise = new Sentence("room-noise", "Room Noise");
|
||||||
|
roomNoise.setParentBook(this);
|
||||||
|
loadEffects();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthor(String a) { author = a; }
|
public Book(File inputFile) throws SAXException, IOException, ParserConfigurationException {
|
||||||
public void setGenre(String g) { genre = g; }
|
Debug.trace();
|
||||||
public void setComment(String c) { comment = c; }
|
Debug.d("Loading book from", inputFile.getCanonicalPath());
|
||||||
public void setACX(String c) { ACX = c; }
|
if (inputFile.getName().endsWith(".abx")) {
|
||||||
|
location = inputFile.getParentFile();
|
||||||
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
|
Document doc = dBuilder.parse(inputFile);
|
||||||
|
doc.getDocumentElement().normalize();
|
||||||
|
Element root = doc.getDocumentElement();
|
||||||
|
|
||||||
public String getAuthor() { return author; }
|
name = getTextNode(root, "title");
|
||||||
public String getGenre() { return genre; }
|
author = getTextNode(root, "author");
|
||||||
public String getComment() { return comment; }
|
genre = getTextNode(root, "genre");
|
||||||
public String getACX() { if (ACX == null) return ""; return ACX; }
|
comment = getTextNode(root, "comment");
|
||||||
|
ACX = getTextNode(root, "acx");
|
||||||
|
manuscript = getTextNode(root, "manuscript");
|
||||||
|
notes = getTextNode(root, "notes");
|
||||||
|
|
||||||
public Chapter getClosingCredits() {
|
Element settings = getNode(root, "settings");
|
||||||
return getChapterById("close");
|
Element audioSettings = getNode(settings, "audio");
|
||||||
|
Element effectSettings = getNode(settings, "effects");
|
||||||
|
|
||||||
|
defaultEffect = getTextNode(settings, "default");
|
||||||
|
|
||||||
|
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
||||||
|
|
||||||
|
loadEffects();
|
||||||
|
|
||||||
|
File cf = new File(location, "coverart.png");
|
||||||
|
if (!cf.exists()) {
|
||||||
|
cf = new File(location, "coverart.jpg");
|
||||||
|
if (!cf.exists()) {
|
||||||
|
cf = new File(location, "coverart.gif");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cf.exists()) {
|
||||||
|
ImageIcon i = new ImageIcon(cf.getAbsolutePath());
|
||||||
|
Image ri = Utils.getScaledImage(i.getImage(), 22, 22);
|
||||||
|
setIcon(new ImageIcon(ri));
|
||||||
|
} else {
|
||||||
|
setIcon(Icons.book);
|
||||||
|
}
|
||||||
|
|
||||||
|
roomNoise = new Sentence("room-noise", "Room Noise");
|
||||||
|
roomNoise.setParentBook(this);
|
||||||
|
|
||||||
|
Element chapters = getNode(root, "chapters");
|
||||||
|
NodeList chapterList = chapters.getElementsByTagName("chapter");
|
||||||
|
for (int i = 0; i < chapterList.getLength(); i++) {
|
||||||
|
Element chapterElement = (Element)chapterList.item(i);
|
||||||
|
Chapter newChapter = new Chapter(chapterElement);
|
||||||
|
newChapter.setParentBook(this);
|
||||||
|
add(newChapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
AudiobookRecorder.window.updateEffectChains(effects);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chapter getOpeningCredits() {
|
public void loadBookXML(Element root, DefaultTreeModel model) {
|
||||||
return getChapterById("open");
|
Debug.trace();
|
||||||
|
name = getTextNode(root, "title");
|
||||||
|
author = getTextNode(root, "author");
|
||||||
|
genre = getTextNode(root, "genre");
|
||||||
|
comment = getTextNode(root, "comment");
|
||||||
|
ACX = getTextNode(root, "acx");
|
||||||
|
manuscript = getTextNode(root, "manuscript");
|
||||||
|
notes = getTextNode(root, "notes");
|
||||||
|
|
||||||
|
Element settings = getNode(root, "settings");
|
||||||
|
Element audioSettings = getNode(settings, "audio");
|
||||||
|
Element effectSettings = getNode(settings, "effects");
|
||||||
|
|
||||||
|
defaultEffect = getTextNode(settings, "default");
|
||||||
|
|
||||||
|
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
||||||
|
|
||||||
|
Element chapters = getNode(root, "chapters");
|
||||||
|
|
||||||
|
NodeList chapterList = chapters.getElementsByTagName("chapter");
|
||||||
|
|
||||||
|
roomNoise = new Sentence("room-noise", "Room Noise");
|
||||||
|
roomNoise.setParentBook(this);
|
||||||
|
|
||||||
|
for (int i = 0; i < chapterList.getLength(); i++) {
|
||||||
|
Element chapterElement = (Element)chapterList.item(i);
|
||||||
|
Chapter newChapter = new Chapter(chapterElement, model);
|
||||||
|
model.insertNodeInto(newChapter, this, getChildCount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Element getNode(Element r, String n) {
|
||||||
|
Debug.trace();
|
||||||
|
NodeList nl = r.getElementsByTagName(n);
|
||||||
|
if (nl == null) return null;
|
||||||
|
if (nl.getLength() == 0) return null;
|
||||||
|
return (Element)nl.item(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTextNode(Element r, String n) {
|
||||||
|
Debug.trace();
|
||||||
|
return getTextNode(r, n, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTextNode(Element r, String n, String d) {
|
||||||
|
Debug.trace();
|
||||||
|
Element node = getNode(r, n);
|
||||||
|
if (node == null) return d;
|
||||||
|
return node.getTextContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String n) { Debug.trace(); name = n; }
|
||||||
|
public void setAuthor(String a) { Debug.trace(); author = a; }
|
||||||
|
public void setGenre(String g) { Debug.trace(); genre = g; }
|
||||||
|
public void setComment(String c) { Debug.trace(); comment = c; }
|
||||||
|
public void setACX(String c) { Debug.trace(); ACX = c; }
|
||||||
|
|
||||||
|
public String getTitle() { Debug.trace(); return name; }
|
||||||
|
public String getAuthor() { Debug.trace(); return author; }
|
||||||
|
public String getGenre() { Debug.trace(); return genre; }
|
||||||
|
public String getComment() { Debug.trace(); return comment; }
|
||||||
|
public String getACX() { Debug.trace(); if (ACX == null) return ""; return ACX; }
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Chapter getChapterById(String id) {
|
public Chapter getChapterById(String id) {
|
||||||
|
Debug.trace();
|
||||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
Object ob = (Object)o.nextElement();
|
Object ob = (Object)o.nextElement();
|
||||||
if (ob instanceof Chapter) {
|
if (ob instanceof Chapter) {
|
||||||
@@ -66,48 +205,82 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Chapter getChapterByName(String name) {
|
||||||
|
Debug.trace();
|
||||||
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
|
Object ob = (Object)o.nextElement();
|
||||||
|
if (ob instanceof Chapter) {
|
||||||
|
Chapter c = (Chapter)ob;
|
||||||
|
if (c.getName().equals(name)) {
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public Chapter getLastChapter() {
|
public Chapter getLastChapter() {
|
||||||
Chapter cc = getClosingCredits();
|
Debug.trace();
|
||||||
if (cc == null) return null;
|
DefaultMutableTreeNode leaf = getLastLeaf();
|
||||||
Chapter c = (Chapter)getChildBefore(cc);
|
if (leaf instanceof Sentence) {
|
||||||
if (c == null) return null;
|
Sentence s = (Sentence)leaf;
|
||||||
if (c.getId().equals("open")) return null;
|
return (Chapter)s.getParent();
|
||||||
return c;
|
}
|
||||||
|
if (leaf instanceof Chapter) {
|
||||||
|
return (Chapter)getLastLeaf();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chapter getChapter(int n) {
|
public Chapter getChapter(int n) {
|
||||||
|
Debug.trace();
|
||||||
if (n == 0) return null;
|
if (n == 0) return null;
|
||||||
return (Chapter)getChildAt(n);
|
return (Chapter)getChildAt(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Chapter addChapter() {
|
public Chapter addChapter() {
|
||||||
Chapter lc = getLastChapter();
|
Debug.trace();
|
||||||
if (lc == null) return new Chapter("1", "Chapter 1");
|
String uuid = UUID.randomUUID().toString();
|
||||||
try {
|
Chapter c = new Chapter(uuid, uuid);
|
||||||
int lcid = Integer.parseInt(lc.getId());
|
add(c);
|
||||||
lcid++;
|
c.setParentBook(this);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
Chapter nc = new Chapter(String.format("%04d", lcid), "Chapter " + lcid);
|
public Chapter addChapter(String name) {
|
||||||
return nc;
|
Debug.trace();
|
||||||
} catch (Exception e) {
|
String uuid = UUID.randomUUID().toString();
|
||||||
e.printStackTrace();
|
Chapter c = new Chapter(uuid, name);
|
||||||
}
|
add(c);
|
||||||
return null;
|
c.setParentBook(this);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chapter addChapter(String id, String name) {
|
||||||
|
Debug.trace();
|
||||||
|
Chapter c = new Chapter(id, name);
|
||||||
|
add(c);
|
||||||
|
c.setParentBook(this);
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageIcon getIcon() {
|
public ImageIcon getIcon() {
|
||||||
|
Debug.trace();
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(ImageIcon i) {
|
public void setIcon(ImageIcon i) {
|
||||||
|
Debug.trace();
|
||||||
icon = i;
|
icon = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserObject(Object o) {
|
public void setUserObject(Object o) {
|
||||||
|
Debug.trace();
|
||||||
if (o instanceof String) {
|
if (o instanceof String) {
|
||||||
String newName = (String)o;
|
String newName = (String)o;
|
||||||
if (newName.equals(name)) return;
|
if (newName.equals(name)) return;
|
||||||
@@ -116,7 +289,8 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void renameBook(String newName) {
|
public void renameBook(String newName) {
|
||||||
File oldDir = new File(Options.get("path.storage"), name);
|
Debug.trace();
|
||||||
|
File oldDir = location;
|
||||||
File newDir = new File(Options.get("path.storage"), newName);
|
File newDir = new File(Options.get("path.storage"), newName);
|
||||||
|
|
||||||
if (newDir.exists()) {
|
if (newDir.exists()) {
|
||||||
@@ -127,8 +301,12 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
if (oldDir.exists() && oldDir.isDirectory()) {
|
if (oldDir.exists() && oldDir.isDirectory()) {
|
||||||
oldDir.renameTo(newDir);
|
oldDir.renameTo(newDir);
|
||||||
name = newName;
|
name = newName;
|
||||||
AudiobookRecorder.window.saveBookStructure();
|
try {
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(this);
|
save();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
reloadTree();
|
||||||
Options.set("path.last-book", name);
|
Options.set("path.last-book", name);
|
||||||
Options.savePreferences();
|
Options.savePreferences();
|
||||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
||||||
@@ -136,57 +314,25 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public void renumberChapters() {
|
|
||||||
int id = 1;
|
|
||||||
|
|
||||||
for (Enumeration c = children(); c.hasMoreElements();) {
|
|
||||||
Chapter chp = (Chapter)c.nextElement();
|
|
||||||
if (Utils.s2i(chp.getId()) > 0) {
|
|
||||||
chp.setId(String.format("%04d", id));
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSampleRate() { return sampleRate; }
|
|
||||||
public void setSampleRate(int sr) { sampleRate = sr; }
|
|
||||||
public int getChannels() { return channels; }
|
|
||||||
public void setChannels(int c) { channels = c; }
|
|
||||||
public int getResolution() { return resolution; }
|
|
||||||
public void setResolution(int r) { resolution = r; }
|
|
||||||
|
|
||||||
public AudioFormat getAudioFormat() {
|
public AudioFormat getAudioFormat() {
|
||||||
return new AudioFormat(getSampleRate(), getResolution(), getChannels(), true, false);
|
Debug.trace();
|
||||||
}
|
if (cachedFormat != null) {
|
||||||
|
return cachedFormat;
|
||||||
public String get(String key) {
|
}
|
||||||
if (prefs.getProperty(key) == null) { return Options.get(key); }
|
cachedFormat = roomNoise.getAudioFormat();
|
||||||
return prefs.getProperty(key);
|
return cachedFormat;
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getInteger(String key) {
|
|
||||||
if (prefs.getProperty(key) == null) { return Options.getInteger(key); }
|
|
||||||
return Utils.s2i(prefs.getProperty(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(String key, String value) {
|
|
||||||
prefs.setProperty(key, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void set(String key, Integer value) {
|
|
||||||
prefs.setProperty(key, "" + value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getBookFolder() {
|
public File getBookFolder() {
|
||||||
File dir = new File(Options.get("path.storage"), name);
|
return location;
|
||||||
return dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getUsedEffects() {
|
public ArrayList<String> getUsedEffects() {
|
||||||
|
Debug.trace();
|
||||||
|
|
||||||
ArrayList<String> out = new ArrayList<String>();
|
ArrayList<String> out = new ArrayList<String>();
|
||||||
|
|
||||||
@@ -206,4 +352,340 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void purgeBackups() {
|
||||||
|
Debug.trace();
|
||||||
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
|
Object ob = (Object)o.nextElement();
|
||||||
|
if (ob instanceof Chapter) {
|
||||||
|
Chapter c = (Chapter)ob;
|
||||||
|
c.purgeBackups();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Document buildDocument() throws ParserConfigurationException {
|
||||||
|
Debug.trace();
|
||||||
|
DocumentBuilderFactory dbFactory =
|
||||||
|
DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
|
Document doc = dBuilder.newDocument();
|
||||||
|
|
||||||
|
Element root = doc.createElement("book");
|
||||||
|
doc.appendChild(root);
|
||||||
|
|
||||||
|
root.appendChild(makeTextNode(doc, "title", name));
|
||||||
|
root.appendChild(makeTextNode(doc, "author", author));
|
||||||
|
root.appendChild(makeTextNode(doc, "comment", comment));
|
||||||
|
root.appendChild(makeTextNode(doc, "genre", genre));
|
||||||
|
root.appendChild(makeTextNode(doc, "acx", ACX));
|
||||||
|
root.appendChild(makeTextNode(doc, "manuscript", manuscript));
|
||||||
|
root.appendChild(makeTextNode(doc, "notes", notes));
|
||||||
|
|
||||||
|
Element settingsNode = doc.createElement("settings");
|
||||||
|
root.appendChild(settingsNode);
|
||||||
|
|
||||||
|
Element effectsNode = doc.createElement("effects");
|
||||||
|
settingsNode.appendChild(effectsNode);
|
||||||
|
|
||||||
|
effectsNode.appendChild(makeTextNode(doc, "default", defaultEffect));
|
||||||
|
|
||||||
|
Element chaptersNode = doc.createElement("chapters");
|
||||||
|
|
||||||
|
root.appendChild(chaptersNode);
|
||||||
|
|
||||||
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
|
Object ob = (Object)o.nextElement();
|
||||||
|
if (ob instanceof Chapter) {
|
||||||
|
Chapter c = (Chapter)ob;
|
||||||
|
chaptersNode.appendChild(c.getChapterXML(doc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Element makeTextNode(Document doc, String name, String text) {
|
||||||
|
Debug.trace();
|
||||||
|
Element node = doc.createElement(name);
|
||||||
|
Text tnode = doc.createTextNode(text == null ? "" : text);
|
||||||
|
node.appendChild(tnode);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Element makeTextNode(Document doc, String name, Integer text) {
|
||||||
|
Debug.trace();
|
||||||
|
Element node = doc.createElement(name);
|
||||||
|
Text tnode = doc.createTextNode(Integer.toString(text));
|
||||||
|
node.appendChild(tnode);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Element makeTextNode(Document doc, String name, Double text) {
|
||||||
|
Debug.trace();
|
||||||
|
Element node = doc.createElement(name);
|
||||||
|
Text tnode = doc.createTextNode(String.format("%.8f", text));
|
||||||
|
node.appendChild(tnode);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Element makeTextNode(Document doc, String name, Boolean text) {
|
||||||
|
Debug.trace();
|
||||||
|
Element node = doc.createElement(name);
|
||||||
|
Text tnode = doc.createTextNode(text ? "true" : "false");
|
||||||
|
node.appendChild(tnode);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultEffect() {
|
||||||
|
Debug.trace();
|
||||||
|
return defaultEffect;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultEffect(String eff) {
|
||||||
|
Debug.trace();
|
||||||
|
defaultEffect = eff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManuscript(File f) {
|
||||||
|
Debug.trace();
|
||||||
|
manuscript = f.getName();
|
||||||
|
File dst = new File(location, manuscript);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.copy(f.toPath(), dst.toPath());
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getManuscript() {
|
||||||
|
Debug.trace();
|
||||||
|
if (manuscript == null) return null;
|
||||||
|
if (manuscript.equals("")) return null;
|
||||||
|
File f = new File(location, manuscript);
|
||||||
|
if (f.exists()) {
|
||||||
|
return f;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSelect(BookTreeNode target) {
|
||||||
|
Debug.trace();
|
||||||
|
AudiobookRecorder.setSelectedBook(this);
|
||||||
|
if (target == this) {
|
||||||
|
AudiobookRecorder.setSelectedChapter(null);
|
||||||
|
AudiobookRecorder.setSelectedSentence(null);
|
||||||
|
}
|
||||||
|
AudiobookRecorder.window.setBookNotes(notes);
|
||||||
|
AudiobookRecorder.window.noiseFloorLabel.setNoiseFloor(getNoiseFloorDB());
|
||||||
|
// AudiobookRecorder.window.updateEffectChains(effects);
|
||||||
|
TreeNode p = getParent();
|
||||||
|
if (p instanceof BookTreeNode) {
|
||||||
|
BookTreeNode btn = (BookTreeNode)p;
|
||||||
|
btn.onSelect(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNotes() {
|
||||||
|
Debug.trace();
|
||||||
|
return notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotes(String n) {
|
||||||
|
Debug.trace();
|
||||||
|
notes = n;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getLocation() {
|
||||||
|
Debug.trace();
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(File l) {
|
||||||
|
Debug.trace();
|
||||||
|
location = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadTree() {
|
||||||
|
Debug.trace();
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
Debug.trace();
|
||||||
|
if (AudiobookRecorder.window == null) return;
|
||||||
|
if (AudiobookRecorder.window.bookTreeModel == null) return;
|
||||||
|
try {
|
||||||
|
AudiobookRecorder.window.bookTreeModel.reload(Book.this);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Book getBook() {
|
||||||
|
Debug.trace();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getRoomNoise(int ms) {
|
||||||
|
Debug.trace();
|
||||||
|
|
||||||
|
if (roomNoise == null) return null;
|
||||||
|
|
||||||
|
// roomNoise.setEffectChain(getDefaultEffect());
|
||||||
|
int len = roomNoise.getSampleSize();
|
||||||
|
if (len == 0) return null;
|
||||||
|
|
||||||
|
AudioFormat f = roomNoise.getAudioFormat();
|
||||||
|
|
||||||
|
float sr = f.getSampleRate();
|
||||||
|
|
||||||
|
int samples = (int)(ms * (sr / 1000f));
|
||||||
|
|
||||||
|
int start = rng.nextInt(len - samples);
|
||||||
|
int end = start + samples;
|
||||||
|
|
||||||
|
roomNoise.setStartOffset(start);
|
||||||
|
roomNoise.setEndOffset(end);
|
||||||
|
|
||||||
|
byte[] data = roomNoise.getPCMData();
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getNoiseFloor() {
|
||||||
|
Debug.trace();
|
||||||
|
if (roomNoise == null) return 0;
|
||||||
|
return roomNoise.getPeak();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNoiseFloorDB() {
|
||||||
|
Debug.trace();
|
||||||
|
if (roomNoise == null) return 0;
|
||||||
|
return roomNoise.getPeakDB();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sentence getRoomNoiseSentence() {
|
||||||
|
Debug.trace();
|
||||||
|
return roomNoise;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recordRoomNoise() {
|
||||||
|
Debug.trace();
|
||||||
|
if (roomNoise.startRecording()) {
|
||||||
|
|
||||||
|
java.util.Timer ticker = new java.util.Timer(true);
|
||||||
|
ticker.schedule(new TimerTask() {
|
||||||
|
public void run() {
|
||||||
|
Debug.trace();
|
||||||
|
roomNoise.stopRecording();
|
||||||
|
}
|
||||||
|
}, 5000); // 5 seconds of recording
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadEffects() {
|
||||||
|
Debug.trace();
|
||||||
|
effects = new TreeMap<String,EffectGroup>();
|
||||||
|
loadEffectsFromFolder(new File(Options.get("path.storage"), "System"));
|
||||||
|
if (location != null) {
|
||||||
|
loadEffectsFromFolder(location);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadEffectsFromFolder(File dir) {
|
||||||
|
Debug.trace();
|
||||||
|
if (dir == null) return;
|
||||||
|
if (!dir.exists()) return;
|
||||||
|
File[] files = dir.listFiles();
|
||||||
|
for (File f : files) {
|
||||||
|
if (f.getName().endsWith(".eff")) {
|
||||||
|
EffectGroup g = loadEffect(f);
|
||||||
|
if (g != null) {
|
||||||
|
String fn = f.getName().replace(".eff","");
|
||||||
|
effects.put(fn, g);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public EffectGroup loadEffect(File xml) {
|
||||||
|
Debug.trace();
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document document = builder.parse(xml);
|
||||||
|
|
||||||
|
Element root = document.getDocumentElement();
|
||||||
|
if (root.getTagName().equals("effect")) {
|
||||||
|
EffectGroup g = EffectGroup.loadEffectGroup(root);
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public void save() throws ParserConfigurationException, TransformerConfigurationException, TransformerException {
|
||||||
|
Debug.trace();
|
||||||
|
if (location == null) {
|
||||||
|
location = new File(Options.get("path.storage"), getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!location.exists()) {
|
||||||
|
location.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
File xml = new File(location, "audiobook.abx");
|
||||||
|
Document doc = buildDocument();
|
||||||
|
|
||||||
|
|
||||||
|
// write the content into xml file
|
||||||
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||||
|
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
|
||||||
|
DOMSource source = new DOMSource(doc);
|
||||||
|
StreamResult result = new StreamResult(xml);
|
||||||
|
transformer.transform(source, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getBookFile() {
|
||||||
|
return new File(location, "audiobook.abx");
|
||||||
|
}
|
||||||
|
|
||||||
|
final static int[] illegalChars = {34, 60, 62, 124, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 58, 42, 63, 92, 47};
|
||||||
|
|
||||||
|
static {
|
||||||
|
Arrays.sort(illegalChars);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String sanitize(String badFileName) {
|
||||||
|
StringBuilder cleanName = new StringBuilder();
|
||||||
|
int len = badFileName.codePointCount(0, badFileName.length());
|
||||||
|
for (int i=0; i<len; i++) {
|
||||||
|
int c = badFileName.codePointAt(i);
|
||||||
|
if (Arrays.binarySearch(illegalChars, c) < 0) {
|
||||||
|
cleanName.appendCodePoint(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cleanName.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getLength() {
|
||||||
|
Debug.trace();
|
||||||
|
double len = 0;
|
||||||
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
|
Object ob = (Object)o.nextElement();
|
||||||
|
if (ob instanceof Chapter) {
|
||||||
|
Chapter c = (Chapter)ob;
|
||||||
|
len += c.getLength();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.util.regex.Matcher;
|
||||||
import javax.swing.event.*;
|
import java.util.regex.Pattern;
|
||||||
import java.awt.*;
|
import java.awt.Dimension;
|
||||||
import java.awt.event.*;
|
import java.awt.GridBagLayout;
|
||||||
import java.util.regex.*;
|
import java.awt.GridBagConstraints;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
public class BookInfoPanel extends JPanel {
|
public class BookInfoPanel extends JPanel {
|
||||||
|
|
||||||
@@ -16,6 +19,7 @@ public class BookInfoPanel extends JPanel {
|
|||||||
|
|
||||||
public BookInfoPanel(String t, String a, String g, String c, String x) {
|
public BookInfoPanel(String t, String a, String g, String c, String x) {
|
||||||
super();
|
super();
|
||||||
|
Debug.trace();
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
GridBagConstraints con = new GridBagConstraints();
|
GridBagConstraints con = new GridBagConstraints();
|
||||||
|
|
||||||
@@ -69,25 +73,25 @@ public class BookInfoPanel extends JPanel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTitle() { return title.getText(); }
|
public String getTitle() { Debug.trace(); return title.getText(); }
|
||||||
public String getAuthor() { return author.getText(); }
|
public String getAuthor() { Debug.trace(); return author.getText(); }
|
||||||
public String getGenre() { return genre.getText(); }
|
public String getGenre() { Debug.trace(); return genre.getText(); }
|
||||||
public String getComment() { return comment.getText(); }
|
public String getComment() { Debug.trace(); return comment.getText(); }
|
||||||
|
|
||||||
public String getACX() {
|
public String getACX() {
|
||||||
|
Debug.trace();
|
||||||
Pattern p = Pattern.compile("\\/titleview\\/([A-Z0-9]{14})");
|
Pattern p = Pattern.compile("\\/titleview\\/([A-Z0-9]{14})");
|
||||||
Matcher m = p.matcher(acx.getText());
|
Matcher m = p.matcher(acx.getText());
|
||||||
if (m.find()) {
|
if (m.find()) {
|
||||||
System.err.println(m);
|
|
||||||
return m.group(1);
|
return m.group(1);
|
||||||
}
|
}
|
||||||
return acx.getText();
|
return acx.getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTitle(String t) { title.setText(t); }
|
public void setTitle(String t) { Debug.trace(); title.setText(t); }
|
||||||
public void setAuthor(String a) { author.setText(a); }
|
public void setAuthor(String a) { Debug.trace(); author.setText(a); }
|
||||||
public void setGenre(String g) { genre.setText(g); }
|
public void setGenre(String g) { Debug.trace(); genre.setText(g); }
|
||||||
public void setComment(String c) { comment.setText(c); }
|
public void setComment(String c) { Debug.trace(); comment.setText(c); }
|
||||||
public void setACX(String a) { acx.setText(a); }
|
public void setACX(String a) { Debug.trace(); acx.setText(a); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,30 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.io.File;
|
||||||
import javax.swing.event.*;
|
import java.io.FileInputStream;
|
||||||
import java.awt.*;
|
import java.util.Properties;
|
||||||
import java.awt.event.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.image.*;
|
import java.awt.Color;
|
||||||
import javax.swing.border.*;
|
import java.awt.Dimension;
|
||||||
import java.util.*;
|
import java.awt.Image;
|
||||||
import java.io.*;
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import org.w3c.dom.Attr;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
public class BookPanel extends JPanel {
|
public class BookPanel extends JPanel {
|
||||||
String name;
|
String name;
|
||||||
@@ -25,6 +42,7 @@ public class BookPanel extends JPanel {
|
|||||||
JPanel panel;
|
JPanel panel;
|
||||||
|
|
||||||
File root;
|
File root;
|
||||||
|
File configFile;
|
||||||
|
|
||||||
boolean highlight = false;
|
boolean highlight = false;
|
||||||
|
|
||||||
@@ -36,13 +54,78 @@ public class BookPanel extends JPanel {
|
|||||||
try {
|
try {
|
||||||
root = r;
|
root = r;
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.loadFromXML(new FileInputStream(new File(root, "audiobook.abk")));
|
|
||||||
loadBookData(props, null);
|
configFile = new File(root, "audiobook.abx");
|
||||||
|
|
||||||
|
if (configFile.exists()) {
|
||||||
|
loadXMLData(configFile);
|
||||||
|
} else {
|
||||||
|
configFile = new File(root, "audiobook.abk");
|
||||||
|
props.loadFromXML(new FileInputStream(configFile));
|
||||||
|
loadBookData(props, null);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BookPanel(String n, String a, String g, String c, ImageIcon i) {
|
||||||
|
name = n;
|
||||||
|
author = a;
|
||||||
|
genre = g;
|
||||||
|
comment = c;
|
||||||
|
cover = i;
|
||||||
|
if (i != null) {
|
||||||
|
cover = i;
|
||||||
|
resizedCover = Utils.getScaledImage(cover.getImage(), 75, 75);
|
||||||
|
iconLabel = new JLabel(new ImageIcon(resizedCover));
|
||||||
|
} else {
|
||||||
|
cover = null;
|
||||||
|
resizedCover = null;
|
||||||
|
iconLabel = new JLabel("");
|
||||||
|
}
|
||||||
|
populate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadXMLData(File inputFile) {
|
||||||
|
try {
|
||||||
|
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||||
|
Document doc = dBuilder.parse(inputFile);
|
||||||
|
doc.getDocumentElement().normalize();
|
||||||
|
|
||||||
|
Element rootnode = doc.getDocumentElement();
|
||||||
|
|
||||||
|
name = Book.getTextNode(rootnode, "title");
|
||||||
|
author = Book.getTextNode(rootnode, "author");
|
||||||
|
genre = Book.getTextNode(rootnode, "genre");
|
||||||
|
comment = Book.getTextNode(rootnode, "comment");
|
||||||
|
|
||||||
|
File icon = new File(root, "coverart.png");
|
||||||
|
if (!icon.exists()) {
|
||||||
|
icon = new File(root, "coverart.jpg");
|
||||||
|
}
|
||||||
|
if (!icon.exists()) {
|
||||||
|
icon = new File(root, "coverart.gif");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (icon.exists()) {
|
||||||
|
cover = new ImageIcon(icon.getAbsolutePath());
|
||||||
|
resizedCover = Utils.getScaledImage(cover.getImage(), 75, 75);
|
||||||
|
iconLabel = new JLabel(new ImageIcon(resizedCover));
|
||||||
|
} else {
|
||||||
|
cover = null;
|
||||||
|
resizedCover = null;
|
||||||
|
iconLabel = new JLabel("");
|
||||||
|
}
|
||||||
|
|
||||||
|
populate();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void loadBookData(Properties props, ImageIcon i) {
|
public void loadBookData(Properties props, ImageIcon i) {
|
||||||
try {
|
try {
|
||||||
name = props.getProperty("book.name");
|
name = props.getProperty("book.name");
|
||||||
@@ -71,41 +154,44 @@ public class BookPanel extends JPanel {
|
|||||||
resizedCover = Utils.getScaledImage(cover.getImage(), 75, 75);
|
resizedCover = Utils.getScaledImage(cover.getImage(), 75, 75);
|
||||||
iconLabel = new JLabel(new ImageIcon(resizedCover));
|
iconLabel = new JLabel(new ImageIcon(resizedCover));
|
||||||
}
|
}
|
||||||
|
populate();
|
||||||
iconLabel.setSize(new Dimension(75, 75));
|
|
||||||
iconLabel.setPreferredSize(new Dimension(75, 75));
|
|
||||||
|
|
||||||
titleLabel = new JLabel(name);
|
|
||||||
authorLabel = new JLabel(author);
|
|
||||||
otherLabel = new JLabel(genre + " :: " + comment);
|
|
||||||
|
|
||||||
authorLabel.setForeground(new Color(0x80, 0x80, 0x80));
|
|
||||||
otherLabel.setForeground(new Color(0x80, 0x80, 0x80));
|
|
||||||
|
|
||||||
setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
panel = new JPanel();
|
|
||||||
|
|
||||||
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
|
||||||
|
|
||||||
panel.setBorder(new EmptyBorder(10, 10, 10, 10));
|
|
||||||
|
|
||||||
panel.add(titleLabel);
|
|
||||||
panel.add(authorLabel);
|
|
||||||
panel.add(otherLabel);
|
|
||||||
|
|
||||||
add(iconLabel, BorderLayout.WEST);
|
|
||||||
add(panel, BorderLayout.CENTER);
|
|
||||||
panel.setBackground(new Color(0x20, 0x20, 0x20));
|
|
||||||
panel.setOpaque(true);
|
|
||||||
setBackground(new Color(0x20, 0x20, 0x20));
|
|
||||||
setOpaque(true);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void populate() {
|
||||||
|
iconLabel.setSize(new Dimension(75, 75));
|
||||||
|
iconLabel.setPreferredSize(new Dimension(75, 75));
|
||||||
|
|
||||||
|
titleLabel = new JLabel(name);
|
||||||
|
authorLabel = new JLabel(author);
|
||||||
|
otherLabel = new JLabel(genre + " :: " + comment);
|
||||||
|
|
||||||
|
authorLabel.setForeground(new Color(0x80, 0x80, 0x80));
|
||||||
|
otherLabel.setForeground(new Color(0x80, 0x80, 0x80));
|
||||||
|
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
panel = new JPanel();
|
||||||
|
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
panel.setBorder(new EmptyBorder(10, 10, 10, 10));
|
||||||
|
|
||||||
|
panel.add(titleLabel);
|
||||||
|
panel.add(authorLabel);
|
||||||
|
panel.add(otherLabel);
|
||||||
|
|
||||||
|
add(iconLabel, BorderLayout.WEST);
|
||||||
|
add(panel, BorderLayout.CENTER);
|
||||||
|
panel.setBackground(new Color(0x20, 0x20, 0x20));
|
||||||
|
panel.setOpaque(true);
|
||||||
|
setBackground(new Color(0x20, 0x20, 0x20));
|
||||||
|
setOpaque(true);
|
||||||
|
}
|
||||||
|
|
||||||
public File getConfigFile() {
|
public File getConfigFile() {
|
||||||
return new File(root, "audiobook.abk");
|
return configFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void highlight() {
|
public void highlight() {
|
||||||
|
|||||||
21
src/uk/co/majenko/audiobookrecorder/BookTreeNode.java
Normal file
21
src/uk/co/majenko/audiobookrecorder/BookTreeNode.java
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
|
||||||
|
public abstract class BookTreeNode extends DefaultMutableTreeNode {
|
||||||
|
|
||||||
|
public BookTreeNode(String t) {
|
||||||
|
super(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BookTreeNode() {
|
||||||
|
super("");
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void setNotes(String t);
|
||||||
|
public abstract String getNotes();
|
||||||
|
public abstract void onSelect(BookTreeNode target);
|
||||||
|
public abstract Book getBook();
|
||||||
|
public abstract double getLength();
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,32 +1,49 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.Component;
|
||||||
import javax.swing.tree.*;
|
import java.awt.Color;
|
||||||
import java.awt.*;
|
import java.awt.Dimension;
|
||||||
import javax.swing.border.*;
|
import java.awt.Font;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JTree;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.tree.DefaultTreeCellRenderer;
|
||||||
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
|
|
||||||
public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
||||||
|
|
||||||
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
|
||||||
JLabel ret = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
|
JLabel ret = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
|
||||||
ret.setIconTextGap(0);
|
ret.setIconTextGap(5);
|
||||||
ret.setBorder(new EmptyBorder(0, 0, 0, 0));
|
ret.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||||
if (value instanceof Sentence) {
|
if (value instanceof Sentence) {
|
||||||
Sentence s = (Sentence)value;
|
Sentence s = (Sentence)value;
|
||||||
|
|
||||||
|
JPanel p = new JPanel();
|
||||||
|
p.setLayout(new GridBagLayout());
|
||||||
|
GridBagConstraints ctx = new GridBagConstraints();
|
||||||
|
|
||||||
OverlayIcon icn = new OverlayIcon(Icons.sentence);
|
OverlayIcon icn = new OverlayIcon(Icons.sentence);
|
||||||
|
|
||||||
if (s.getOverrideText() != null) {
|
if (s.getOverrideText() != null) {
|
||||||
ret.setText(s.getOverrideText());
|
ret.setText(s.getOverrideText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!s.isProcessed()) {
|
||||||
|
ret.setForeground(new Color(0x88, 0x88, 0x88));
|
||||||
|
}
|
||||||
|
|
||||||
if (s.getAttentionFlag()) {
|
if (s.getAttentionFlag()) {
|
||||||
ret.setForeground(new Color(0xFF, 0xFF, 0x00));
|
ret.setForeground(new Color(0xFF, 0xFF, 0x00));
|
||||||
icn.add(Overlays.attention, OverlayIcon.TOP_LEFT);
|
icn.add(Overlays.attention, OverlayIcon.TOP_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s.isLocked()) {
|
if (s.isLocked()) {
|
||||||
ret.setForeground(new Color(0x00, 0x80, 0xFF));
|
ret.setForeground(new Color(0x30, 0xb0, 0xFF));
|
||||||
icn.add(Overlays.locked, OverlayIcon.BOTTOM_LEFT);
|
icn.add(Overlays.locked, OverlayIcon.BOTTOM_LEFT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,6 +51,10 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
|||||||
icn.add(Overlays.important, OverlayIcon.TOP_RIGHT);
|
icn.add(Overlays.important, OverlayIcon.TOP_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s.getEndOffset() == s.getSampleSize() - 1) {
|
||||||
|
icn.add(Overlays.important, OverlayIcon.TOP_RIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
if (s.getEffectChain() != null) {
|
if (s.getEffectChain() != null) {
|
||||||
if (!s.getEffectChain().equals("none")) {
|
if (!s.getEffectChain().equals("none")) {
|
||||||
icn.add(Overlays.filter, OverlayIcon.BOTTOM_RIGHT);
|
icn.add(Overlays.filter, OverlayIcon.BOTTOM_RIGHT);
|
||||||
@@ -55,19 +76,123 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gaptype.equals("sentence")) {
|
if (gaptype.equals("sentence")) {
|
||||||
ret.setBorder(new EmptyBorder(0, 0, 0, 0));
|
p.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||||
} else if (gaptype.equals("continuation")) {
|
} else if (gaptype.equals("continuation")) {
|
||||||
ret.setBorder(new EmptyBorder(0, 0, 0, 0));
|
p.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||||
} else if (gaptype.equals("paragraph")) {
|
} else if (gaptype.equals("paragraph")) {
|
||||||
ret.setBorder(new EmptyBorder(0, 0, 7, 0));
|
p.setBorder(new EmptyBorder(0, 0, 7, 0));
|
||||||
} else if (gaptype.equals("section")) {
|
} else if (gaptype.equals("section")) {
|
||||||
ret.setBorder(new EmptyBorder(0, 0, 15, 0));
|
p.setBorder(new EmptyBorder(0, 0, 15, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JLabel time = new JLabelFixedWidth(75, " " + Utils.secToTime(s.getStartTime(), "mm.ss.SSS") + " ");
|
||||||
|
time.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||||
|
|
||||||
|
ctx.gridx = 0;
|
||||||
|
ctx.gridy = 0;
|
||||||
|
ctx.weightx = 1.0d;
|
||||||
|
ctx.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
ctx.anchor = GridBagConstraints.LINE_START;
|
||||||
|
p.add(ret, ctx);
|
||||||
|
|
||||||
|
String effectChain = s.getEffectChain();
|
||||||
|
if ((effectChain != null) && (!effectChain.equals("none"))) {
|
||||||
|
Effect e = s.getBook().effects.get(effectChain);
|
||||||
|
if (e != null) {
|
||||||
|
JLabel eff = new JLabel(e.toString() + " ");
|
||||||
|
ctx.weightx = 0.0d;
|
||||||
|
ctx.gridx = 1;
|
||||||
|
p.add(eff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (s.isProcessing()) {
|
||||||
|
JLabel eff = new JLabel();
|
||||||
|
eff.setIcon(Icons.processing);
|
||||||
|
ctx.weightx = 0.0d;
|
||||||
|
ctx.gridx = 2;
|
||||||
|
p.add(eff);
|
||||||
|
} else if (s.isQueued()) {
|
||||||
|
JLabel eff = new JLabel();
|
||||||
|
eff.setIcon(Icons.queued);
|
||||||
|
ctx.weightx = 0.0d;
|
||||||
|
ctx.gridx = 2;
|
||||||
|
p.add(eff);
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.weightx = 0.0d;
|
||||||
|
ctx.gridx = 3;
|
||||||
|
ctx.anchor = GridBagConstraints.LINE_END;
|
||||||
|
int peak = s.getPeakDB();
|
||||||
|
JLabel peakLabel = new JLabelFixedWidth(50, peak + "dB ");
|
||||||
|
peakLabel.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||||
|
if (peak > 0) {
|
||||||
|
peakLabel.setForeground(new Color(0xCC, 0x00, 0x00));
|
||||||
|
}
|
||||||
|
p.add(peakLabel, ctx);
|
||||||
|
|
||||||
|
ctx.weightx = 0.0d;
|
||||||
|
ctx.gridx = 4;
|
||||||
|
ctx.anchor = GridBagConstraints.LINE_END;
|
||||||
|
p.add(time, ctx);
|
||||||
|
|
||||||
|
p.setOpaque(false);
|
||||||
|
|
||||||
|
return p;
|
||||||
|
|
||||||
} else if (value instanceof Chapter) {
|
} else if (value instanceof Chapter) {
|
||||||
|
Chapter c = (Chapter)value;
|
||||||
|
|
||||||
ret.setIcon(Icons.chapter);
|
ret.setIcon(Icons.chapter);
|
||||||
|
|
||||||
|
JPanel p = new JPanel();
|
||||||
|
p.setLayout(new GridBagLayout());
|
||||||
|
GridBagConstraints ctx = new GridBagConstraints();
|
||||||
|
|
||||||
|
JLabel time = new JLabel(Utils.secToTime(c.getLength(), "mm:ss") + " ");
|
||||||
|
|
||||||
|
ctx.gridx = 0;
|
||||||
|
ctx.gridy = 0;
|
||||||
|
ctx.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
ctx.anchor = GridBagConstraints.LINE_START;
|
||||||
|
ctx.weightx = 1.0d;
|
||||||
|
p.add(ret, ctx);
|
||||||
|
ctx.weightx = 0.0d;
|
||||||
|
ctx.gridx = 1;
|
||||||
|
ctx.anchor = GridBagConstraints.LINE_END;
|
||||||
|
p.add(time, ctx);
|
||||||
|
p.setOpaque(false);
|
||||||
|
return p;
|
||||||
} else if (value instanceof Book) {
|
} else if (value instanceof Book) {
|
||||||
ret.setIcon(((Book)value).getIcon());
|
Book b = (Book)value;
|
||||||
|
|
||||||
|
JPanel p = new JPanel();
|
||||||
|
p.setLayout(new GridBagLayout());
|
||||||
|
GridBagConstraints ctx = new GridBagConstraints();
|
||||||
|
|
||||||
|
ctx.gridx = 0;
|
||||||
|
ctx.gridy = 0;
|
||||||
|
ctx.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
ctx.anchor = GridBagConstraints.LINE_START;
|
||||||
|
ctx.weightx = 1.0d;
|
||||||
|
|
||||||
|
ret.setIcon(b.getIcon());
|
||||||
|
p.add(ret, ctx);
|
||||||
|
|
||||||
|
JLabel author = new JLabel(b.getAuthor() + " - " + Utils.secToTime(b.getLength(), "HH:mm:ss"));
|
||||||
|
ctx.gridy++;
|
||||||
|
author.setBorder(new EmptyBorder(0, 27, 0, 0));
|
||||||
|
Font f = author.getFont();
|
||||||
|
Font nf = f.deriveFont(Font.ITALIC, (int)(f.getSize() * 0.75));
|
||||||
|
author.setFont(nf);
|
||||||
|
author.setForeground(author.getForeground().darker());
|
||||||
|
p.add(author, ctx);
|
||||||
|
|
||||||
|
p.setOpaque(false);
|
||||||
|
return p;
|
||||||
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class CacheManager {
|
public class CacheManager {
|
||||||
static ArrayList<Cacheable> cache = new ArrayList<Cacheable>();
|
static ArrayList<Cacheable> cache = new ArrayList<Cacheable>();
|
||||||
@@ -34,4 +34,11 @@ public class CacheManager {
|
|||||||
cache.remove(c);
|
cache.remove(c);
|
||||||
c.clearCache();
|
c.clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void purgeCache() {
|
||||||
|
for (Cacheable c : cache) {
|
||||||
|
c.clearCache();
|
||||||
|
}
|
||||||
|
cache.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public class Chain implements Effect {
|
|||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
Effect t = AudiobookRecorder.window.effects.get(target);
|
Effect t = AudiobookRecorder.window.getBook().effects.get(target);
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
t.process(samples);
|
t.process(samples);
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ public class Chain implements Effect {
|
|||||||
|
|
||||||
public void init(double sf) {
|
public void init(double sf) {
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
Effect t = AudiobookRecorder.window.effects.get(target);
|
Effect t = AudiobookRecorder.window.getBook().effects.get(target);
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
t.init(sf);
|
t.init(sf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,50 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.io.File;
|
||||||
import javax.swing.event.*;
|
import java.io.FileInputStream;
|
||||||
import java.awt.*;
|
import java.io.FileOutputStream;
|
||||||
import java.awt.event.*;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.*;
|
import java.io.IOException;
|
||||||
import java.io.*;
|
import java.util.ArrayList;
|
||||||
import java.nio.file.*;
|
import java.util.Enumeration;
|
||||||
import javax.swing.tree.*;
|
import javax.swing.tree.DefaultTreeModel;
|
||||||
import it.sauronsoftware.jave.*;
|
import javax.swing.tree.DefaultMutableTreeNode;
|
||||||
import com.mpatric.mp3agic.*;
|
import javax.swing.tree.TreeNode;
|
||||||
import javax.sound.sampled.*;
|
|
||||||
|
|
||||||
|
import it.sauronsoftware.jave.FFMPEGLocator;
|
||||||
|
import it.sauronsoftware.jave.AudioAttributes;
|
||||||
|
import it.sauronsoftware.jave.EncodingAttributes;
|
||||||
|
import it.sauronsoftware.jave.Encoder;
|
||||||
|
import it.sauronsoftware.jave.EncoderException;
|
||||||
|
import it.sauronsoftware.jave.InputFormatException;
|
||||||
|
|
||||||
public class Chapter extends DefaultMutableTreeNode {
|
import com.mpatric.mp3agic.Mp3File;
|
||||||
|
import com.mpatric.mp3agic.ID3v2;
|
||||||
|
import com.mpatric.mp3agic.ID3v24Tag;
|
||||||
|
import com.mpatric.mp3agic.InvalidDataException;
|
||||||
|
import com.mpatric.mp3agic.NotSupportedException;
|
||||||
|
import com.mpatric.mp3agic.UnsupportedTagException;
|
||||||
|
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import javax.sound.sampled.AudioFileFormat;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
|
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import org.w3c.dom.Attr;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
import org.w3c.dom.Text;
|
||||||
|
|
||||||
|
public class Chapter extends BookTreeNode {
|
||||||
|
|
||||||
String name;
|
String name;
|
||||||
String id;
|
String id;
|
||||||
@@ -21,35 +52,80 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
int preGap;
|
int preGap;
|
||||||
int postGap;
|
int postGap;
|
||||||
|
|
||||||
|
String notes;
|
||||||
|
Book parentBook = null;
|
||||||
|
|
||||||
public Chapter(String i, String chaptername) {
|
public Chapter(String i, String chaptername) {
|
||||||
super(chaptername);
|
super(chaptername);
|
||||||
|
Debug.trace();
|
||||||
id = i;
|
id = i;
|
||||||
name = chaptername;
|
name = chaptername;
|
||||||
preGap = Options.getInteger("catenation.pre-chapter");
|
preGap = Options.getInteger("catenation.pre-chapter");
|
||||||
postGap = Options.getInteger("catenation.post-chapter");
|
postGap = Options.getInteger("catenation.post-chapter");
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chapter(Element root, DefaultTreeModel model) {
|
||||||
|
Debug.trace();
|
||||||
|
name = Book.getTextNode(root, "name");
|
||||||
|
id = root.getAttribute("id");
|
||||||
|
preGap = Utils.s2i(Book.getTextNode(root, "pre-gap"));
|
||||||
|
postGap = Utils.s2i(Book.getTextNode(root, "post-gap"));
|
||||||
|
|
||||||
|
notes = Book.getTextNode(root, "notes");
|
||||||
|
|
||||||
|
Element sentencesNode = Book.getNode(root, "sentences");
|
||||||
|
NodeList sentences = sentencesNode.getElementsByTagName("sentence");
|
||||||
|
|
||||||
|
for (int i = 0; i < sentences.getLength(); i++) {
|
||||||
|
Element sentenceElement = (Element)sentences.item(i);
|
||||||
|
Sentence newSentence = new Sentence(sentenceElement);
|
||||||
|
model.insertNodeInto(newSentence, this, getChildCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Chapter(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
name = Book.getTextNode(root, "name");
|
||||||
|
id = root.getAttribute("id");
|
||||||
|
preGap = Utils.s2i(Book.getTextNode(root, "pre-gap"));
|
||||||
|
postGap = Utils.s2i(Book.getTextNode(root, "post-gap"));
|
||||||
|
|
||||||
|
notes = Book.getTextNode(root, "notes");
|
||||||
|
|
||||||
|
Element sentencesNode = Book.getNode(root, "sentences");
|
||||||
|
NodeList sentences = sentencesNode.getElementsByTagName("sentence");
|
||||||
|
|
||||||
|
for (int i = 0; i < sentences.getLength(); i++) {
|
||||||
|
Element sentenceElement = (Element)sentences.item(i);
|
||||||
|
Sentence newSentence = new Sentence(sentenceElement);
|
||||||
|
add(newSentence);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
Debug.trace();
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String i) {
|
public void setId(String i) {
|
||||||
|
Debug.trace();
|
||||||
id = i;
|
id = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sentence getLastSentence() {
|
public Sentence getLastSentence() {
|
||||||
|
Debug.trace();
|
||||||
DefaultMutableTreeNode ls = getLastLeaf();
|
DefaultMutableTreeNode ls = getLastLeaf();
|
||||||
if (ls instanceof Sentence) return (Sentence)ls;
|
if (ls instanceof Sentence) return (Sentence)ls;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
Debug.trace();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserObject(Object o) {
|
public void setUserObject(Object o) {
|
||||||
|
Debug.trace();
|
||||||
if (o instanceof String) {
|
if (o instanceof String) {
|
||||||
String so = (String)o;
|
String so = (String)o;
|
||||||
name = so;
|
name = so;
|
||||||
@@ -57,26 +133,32 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
Debug.trace();
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String n) {
|
public void setName(String n) {
|
||||||
|
Debug.trace();
|
||||||
name = n;
|
name = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPreGap(int g) {
|
public void setPreGap(int g) {
|
||||||
|
Debug.trace();
|
||||||
preGap = g;
|
preGap = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPreGap() {
|
public int getPreGap() {
|
||||||
|
Debug.trace();
|
||||||
return preGap;
|
return preGap;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPostGap(int g) {
|
public void setPostGap(int g) {
|
||||||
|
Debug.trace();
|
||||||
postGap = g;
|
postGap = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPostGap() {
|
public int getPostGap() {
|
||||||
|
Debug.trace();
|
||||||
return postGap;
|
return postGap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,10 +166,11 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
public void exportChapter(ProgressDialog exportDialog) throws
|
public void exportChapter(ProgressDialog exportDialog) throws
|
||||||
FileNotFoundException, IOException, InputFormatException, NotSupportedException,
|
FileNotFoundException, IOException, InputFormatException, NotSupportedException,
|
||||||
EncoderException, UnsupportedTagException, InvalidDataException {
|
EncoderException, UnsupportedTagException, InvalidDataException {
|
||||||
|
Debug.trace();
|
||||||
|
|
||||||
if (getChildCount() == 0) return;
|
if (getChildCount() == 0) return;
|
||||||
|
|
||||||
Book book = AudiobookRecorder.window.book;
|
Book book = getBook();
|
||||||
|
|
||||||
File bookRoot = new File(Options.get("path.storage"), book.getName());
|
File bookRoot = new File(Options.get("path.storage"), book.getName());
|
||||||
if (!bookRoot.exists()) {
|
if (!bookRoot.exists()) {
|
||||||
@@ -116,12 +199,12 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
audioAttributes.setCodec("libmp3lame");
|
audioAttributes.setCodec("libmp3lame");
|
||||||
audioAttributes.setBitRate(Options.getInteger("audio.export.bitrate"));
|
audioAttributes.setBitRate(Options.getInteger("audio.export.bitrate"));
|
||||||
audioAttributes.setSamplingRate(Options.getInteger("audio.export.samplerate"));
|
audioAttributes.setSamplingRate(Options.getInteger("audio.export.samplerate"));
|
||||||
audioAttributes.setChannels(2); //new Integer(2));
|
audioAttributes.setChannels(Options.getInteger("audio.export.channels")); //new Integer(2));
|
||||||
attributes.setFormat("mp3");
|
attributes.setFormat("mp3");
|
||||||
attributes.setAudioAttributes(audioAttributes);
|
attributes.setAudioAttributes(audioAttributes);
|
||||||
|
|
||||||
|
|
||||||
AudioFormat sampleformat = AudiobookRecorder.window.roomNoise.getAudioFormat();
|
AudioFormat sampleformat = getBook().getRoomNoiseSentence().getAudioFormat();
|
||||||
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 2, true, false);
|
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 2, true, false);
|
||||||
byte[] data;
|
byte[] data;
|
||||||
|
|
||||||
@@ -139,7 +222,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
File taggedFile = new File(export, book.getName() + " - " + name + ".mp3");
|
File taggedFile = new File(export, book.getName() + " - " + name + ".mp3");
|
||||||
|
|
||||||
FileOutputStream fos = new FileOutputStream(exportFile);
|
FileOutputStream fos = new FileOutputStream(exportFile);
|
||||||
data = AudiobookRecorder.window.getRoomNoise(Utils.s2i(Options.get("catenation.pre-chapter")));
|
data = getBook().getRoomNoise(Utils.s2i(Options.get("catenation.pre-chapter")));
|
||||||
fullLength += data.length;
|
fullLength += data.length;
|
||||||
fos.write(data);
|
fos.write(data);
|
||||||
|
|
||||||
@@ -156,9 +239,9 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
fos.write(data);
|
fos.write(data);
|
||||||
|
|
||||||
if (s.hasMoreElements()) {
|
if (s.hasMoreElements()) {
|
||||||
data = AudiobookRecorder.window.getRoomNoise(snt.getPostGap());
|
data = getBook().getRoomNoise(snt.getPostGap());
|
||||||
} else {
|
} else {
|
||||||
data = AudiobookRecorder.window.getRoomNoise(Utils.s2i(Options.get("catenation.post-chapter")));
|
data = getBook().getRoomNoise(Utils.s2i(Options.get("catenation.post-chapter")));
|
||||||
}
|
}
|
||||||
fullLength += data.length;
|
fullLength += data.length;
|
||||||
fos.write(data);
|
fos.write(data);
|
||||||
@@ -202,6 +285,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public double getChapterLength() {
|
public double getChapterLength() {
|
||||||
|
Debug.trace();
|
||||||
double totalTime = Options.getInteger("audio.recording.pre-chapter") / 1000d;
|
double totalTime = Options.getInteger("audio.recording.pre-chapter") / 1000d;
|
||||||
for (Enumeration s = children(); s.hasMoreElements();) {
|
for (Enumeration s = children(); s.hasMoreElements();) {
|
||||||
Sentence sentence = (Sentence)s.nextElement();
|
Sentence sentence = (Sentence)s.nextElement();
|
||||||
@@ -216,6 +300,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getUsedEffects() {
|
public ArrayList<String> getUsedEffects() {
|
||||||
|
Debug.trace();
|
||||||
|
|
||||||
ArrayList<String> out = new ArrayList<String>();
|
ArrayList<String> out = new ArrayList<String>();
|
||||||
|
|
||||||
@@ -233,10 +318,106 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void resetPostGaps() {
|
public void resetPostGaps() {
|
||||||
|
Debug.trace();
|
||||||
for (Enumeration s = children(); s.hasMoreElements();) {
|
for (Enumeration s = children(); s.hasMoreElements();) {
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
snt.resetPostGap();
|
snt.resetPostGap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void purgeBackups() {
|
||||||
|
Debug.trace();
|
||||||
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
|
Object ob = (Object)o.nextElement();
|
||||||
|
if (ob instanceof Sentence) {
|
||||||
|
Sentence s = (Sentence)ob;
|
||||||
|
s.purgeBackups();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Element getChapterXML(Document doc) {
|
||||||
|
Debug.trace();
|
||||||
|
Element chapterNode = doc.createElement("chapter");
|
||||||
|
chapterNode.setAttribute("id", id);
|
||||||
|
chapterNode.appendChild(Book.makeTextNode(doc, "name", name));
|
||||||
|
chapterNode.appendChild(Book.makeTextNode(doc, "pre-gap", preGap));
|
||||||
|
chapterNode.appendChild(Book.makeTextNode(doc, "post-gap", postGap));
|
||||||
|
chapterNode.appendChild(Book.makeTextNode(doc, "notes", notes));
|
||||||
|
|
||||||
|
Element sentencesNode = doc.createElement("sentences");
|
||||||
|
chapterNode.appendChild(sentencesNode);
|
||||||
|
|
||||||
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
|
Object ob = (Object)o.nextElement();
|
||||||
|
if (ob instanceof Sentence) {
|
||||||
|
Sentence s = (Sentence)ob;
|
||||||
|
sentencesNode.appendChild(s.getSentenceXML(doc));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return chapterNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNotes() {
|
||||||
|
Debug.trace();
|
||||||
|
return notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotes(String t) {
|
||||||
|
Debug.trace();
|
||||||
|
notes = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onSelect(BookTreeNode target) {
|
||||||
|
Debug.trace();
|
||||||
|
AudiobookRecorder.setSelectedChapter(this);
|
||||||
|
if (target == this) {
|
||||||
|
AudiobookRecorder.setSelectedSentence(null);
|
||||||
|
}
|
||||||
|
AudiobookRecorder.window.setChapterNotes(notes);
|
||||||
|
TreeNode p = getParent();
|
||||||
|
if (p instanceof BookTreeNode) {
|
||||||
|
BookTreeNode btn = (BookTreeNode)p;
|
||||||
|
btn.onSelect(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getLength() {
|
||||||
|
Debug.trace();
|
||||||
|
double len = 0;
|
||||||
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
|
Object ob = (Object)o.nextElement();
|
||||||
|
if (ob instanceof Sentence) {
|
||||||
|
Sentence s = (Sentence)ob;
|
||||||
|
len += s.getLength();
|
||||||
|
len += (s.getPostGap() / 1000d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len > 0) {
|
||||||
|
len += (getPreGap() / 1000d);
|
||||||
|
len += (getPostGap() / 1000d);
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Book getBook() {
|
||||||
|
if (parentBook != null) return parentBook;
|
||||||
|
if (getParent() == null) return null;
|
||||||
|
return (Book)getParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentBook(Book me) {
|
||||||
|
parentBook = me;
|
||||||
|
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||||
|
Object ob = (Object)o.nextElement();
|
||||||
|
if (ob instanceof Sentence) {
|
||||||
|
Sentence s = (Sentence)ob;
|
||||||
|
s.setParentBook(me);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,11 @@ public class Clipping implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
for (double[] sample : samples) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
if (sample[Sentence.LEFT] > clip) sample[Sentence.LEFT] = clip;
|
if (samples[Sentence.LEFT][i] > clip) samples[Sentence.LEFT][i] = clip;
|
||||||
if (sample[Sentence.LEFT] < -clip) sample[Sentence.LEFT] = -clip;
|
if (samples[Sentence.LEFT][i] < -clip) samples[Sentence.LEFT][i] = -clip;
|
||||||
if (sample[Sentence.RIGHT] > clip) sample[Sentence.RIGHT] = clip;
|
if (samples[Sentence.RIGHT][i] > clip) samples[Sentence.RIGHT][i] = clip;
|
||||||
if (sample[Sentence.RIGHT] < -clip) sample[Sentence.RIGHT] = -clip;
|
if (samples[Sentence.RIGHT][i] < -clip) samples[Sentence.RIGHT][i] = -clip;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
192
src/uk/co/majenko/audiobookrecorder/CommandLine.java
Normal file
192
src/uk/co/majenko/audiobookrecorder/CommandLine.java
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class CommandLine {
|
||||||
|
HashMap<String, Class<?>> parameterTypes = new HashMap<String, Class<?>>();
|
||||||
|
HashMap<String, String> parameterComments = new HashMap<String, String>();
|
||||||
|
HashMap<String, Object> parameterValues = new HashMap<String, Object>();
|
||||||
|
HashMap<String, String> parameterNames = new HashMap<String, String>();
|
||||||
|
ArrayList<String> extraValues = new ArrayList<String>();
|
||||||
|
|
||||||
|
public CommandLine() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addParameter(String key, String name, Class<?> type, String comment) {
|
||||||
|
parameterNames.put(key, name);
|
||||||
|
parameterTypes.put(key, type);
|
||||||
|
parameterComments.put(key, comment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] process(String[] args) {
|
||||||
|
parameterValues = new HashMap<String, Object>();
|
||||||
|
extraValues = new ArrayList<String>();
|
||||||
|
|
||||||
|
for (String arg : args) {
|
||||||
|
if (arg.startsWith("--")) {
|
||||||
|
arg = arg.substring(2);
|
||||||
|
String value = "";
|
||||||
|
int equals = arg.indexOf("=");
|
||||||
|
if (equals > -1) {
|
||||||
|
value = arg.substring(equals + 1);
|
||||||
|
arg = arg.substring(0, equals);
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> aclass = parameterTypes.get(arg);
|
||||||
|
if (aclass == null) {
|
||||||
|
help();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
if (aclass == Boolean.class) {
|
||||||
|
Boolean b = true;
|
||||||
|
parameterValues.put(arg, b);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (value.equals("")) {
|
||||||
|
help();
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
if (aclass == Integer.class) {
|
||||||
|
Integer i = 0;
|
||||||
|
try {
|
||||||
|
i = Integer.parseInt(value);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
parameterValues.put(arg, i);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (aclass == Float.class) {
|
||||||
|
Float f = 0F;
|
||||||
|
try {
|
||||||
|
f = Float.parseFloat(value);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
parameterValues.put(arg, f);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (aclass == Double.class) {
|
||||||
|
Double d = 0D;
|
||||||
|
try {
|
||||||
|
d = Double.parseDouble(value);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
parameterValues.put(arg, d);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (aclass == String.class) {
|
||||||
|
parameterValues.put(arg, value);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
extraValues.add(arg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return extraValues.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void help() {
|
||||||
|
System.out.println("Available command line arguments:");
|
||||||
|
int maxlen = 0;
|
||||||
|
|
||||||
|
String[] arglist = parameterTypes.keySet().toArray(new String[0]);
|
||||||
|
Arrays.sort(arglist);
|
||||||
|
|
||||||
|
for (String s : arglist) {
|
||||||
|
int thislen = s.length();
|
||||||
|
if (parameterTypes.get(s) != Boolean.class) {
|
||||||
|
thislen++;
|
||||||
|
thislen += parameterNames.get(s).length();
|
||||||
|
}
|
||||||
|
if (thislen > maxlen) {
|
||||||
|
maxlen = thislen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String s : arglist) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
System.out.print(" --");
|
||||||
|
sb.append(s);
|
||||||
|
if (parameterTypes.get(s) != Boolean.class) {
|
||||||
|
sb.append("=");
|
||||||
|
sb.append(parameterNames.get(s));
|
||||||
|
}
|
||||||
|
while (sb.length() < maxlen) {
|
||||||
|
sb.append(" ");
|
||||||
|
}
|
||||||
|
System.out.print(sb.toString());
|
||||||
|
System.out.print(" ");
|
||||||
|
System.out.println(parameterComments.get(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSet(String key) {
|
||||||
|
Object value = parameterValues.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getString(String key) {
|
||||||
|
Class<?> type = parameterTypes.get(key);
|
||||||
|
if (type == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (type != String.class) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String value = (String)parameterValues.get(key);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getInteger(String key) {
|
||||||
|
Class<?> type = parameterTypes.get(key);
|
||||||
|
if (type == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (type != Integer.class) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Integer value = (Integer)parameterValues.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (int)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getFloat(String key) {
|
||||||
|
Class<?> type = parameterTypes.get(key);
|
||||||
|
if (type == null) {
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
if (type != Float.class) {
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
Float value = (Float)parameterValues.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
return (float)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getDouble(String key) {
|
||||||
|
Class<?> type = parameterTypes.get(key);
|
||||||
|
if (type == null) {
|
||||||
|
return 0d;
|
||||||
|
}
|
||||||
|
if (type != Double.class) {
|
||||||
|
return 0d;
|
||||||
|
}
|
||||||
|
Double value = (Double)parameterValues.get(key);
|
||||||
|
if (value == null) {
|
||||||
|
return 0d;
|
||||||
|
}
|
||||||
|
return (double)value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(String key, String value) {
|
||||||
|
parameterValues.put(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.tree.*;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.plaf.*;
|
import javax.swing.tree.AbstractLayoutCache;
|
||||||
import javax.swing.plaf.basic.*;
|
import javax.swing.tree.TreePath;
|
||||||
import java.awt.*;
|
import javax.swing.plaf.basic.BasicTreeUI;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
|
||||||
public class CustomTreeUI extends BasicTreeUI {
|
public class CustomTreeUI extends BasicTreeUI {
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,53 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
public class Debug {
|
public class Debug {
|
||||||
static long timestamp;
|
static long timestamp;
|
||||||
|
static public boolean debugEnabled = false;
|
||||||
|
static public boolean traceEnabled = false;
|
||||||
|
|
||||||
static void debug(String msg) {
|
static void debug(String msg) {
|
||||||
|
if (!debugEnabled) return;
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
long diff = now - timestamp;
|
long diff = now - timestamp;
|
||||||
timestamp = now;
|
timestamp = now;
|
||||||
System.err.println(String.format("%8d - %s", diff, msg));
|
System.err.println(String.format("%8d - %s", diff, msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void d(Object... args) {
|
||||||
|
if (!debugEnabled) return;
|
||||||
|
|
||||||
|
Thread t = Thread.currentThread();
|
||||||
|
StackTraceElement[] st = t.getStackTrace();
|
||||||
|
StackTraceElement caller = st[2];
|
||||||
|
|
||||||
|
String tag = "[" + getCurrentLocalDateTimeStamp() + "] " + caller.getFileName() + " " + caller.getLineNumber() + " (" + caller.getMethodName() + "):";
|
||||||
|
|
||||||
|
System.err.print(tag);
|
||||||
|
|
||||||
|
for (Object o : args) {
|
||||||
|
System.err.print(" ");
|
||||||
|
System.err.print(o);
|
||||||
|
}
|
||||||
|
System.err.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void trace() {
|
||||||
|
if (!traceEnabled) return;
|
||||||
|
Thread t = Thread.currentThread();
|
||||||
|
StackTraceElement[] st = t.getStackTrace();
|
||||||
|
StackTraceElement caller = st[3];
|
||||||
|
StackTraceElement callee = st[2];
|
||||||
|
|
||||||
|
String tag = "[" + getCurrentLocalDateTimeStamp() + "] " + t.getName() + " - " + caller.getFileName() + ":" + caller.getLineNumber() + " " + caller.getMethodName() + "(...) -> " + callee.getFileName() + ":" + callee.getLineNumber() + " " + callee.getMethodName() + "(...)";
|
||||||
|
|
||||||
|
System.err.println(tag);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getCurrentLocalDateTimeStamp() {
|
||||||
|
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,65 +17,41 @@ public class DelayLine implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
double[][] savedSamples = new double[samples.length][2];
|
double[][] savedSamples = new double[2][samples[Sentence.LEFT].length];
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
savedSamples[i][Sentence.LEFT] = samples[i][Sentence.LEFT];
|
savedSamples[Sentence.LEFT][i] = samples[Sentence.LEFT][i];
|
||||||
savedSamples[i][Sentence.RIGHT] = samples[i][Sentence.RIGHT];
|
savedSamples[Sentence.RIGHT][i] = samples[Sentence.RIGHT][i];
|
||||||
}
|
}
|
||||||
if (wetOnly) {
|
if (wetOnly) {
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
samples[i][Sentence.LEFT] = 0d;
|
samples[Sentence.LEFT][i] = 0d;
|
||||||
samples[i][Sentence.RIGHT] = 0d;
|
samples[Sentence.RIGHT][i] = 0d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double[][] subSamples = new double[samples.length][2];
|
double[][] subSamples = new double[2][samples[Sentence.LEFT].length];
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
subSamples[i][Sentence.LEFT] = savedSamples[i][Sentence.LEFT];
|
subSamples[Sentence.LEFT][i] = savedSamples[Sentence.LEFT][i];
|
||||||
subSamples[i][Sentence.RIGHT] = savedSamples[i][Sentence.RIGHT];
|
subSamples[Sentence.RIGHT][i] = savedSamples[Sentence.RIGHT][i];
|
||||||
}
|
}
|
||||||
for (DelayLineStore d : delayLines) {
|
for (DelayLineStore d : delayLines) {
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
subSamples[i][Sentence.LEFT] = savedSamples[i][Sentence.LEFT];
|
subSamples[Sentence.LEFT][i] = savedSamples[Sentence.LEFT][i];
|
||||||
subSamples[i][Sentence.RIGHT] = savedSamples[i][Sentence.RIGHT];
|
subSamples[Sentence.RIGHT][i] = savedSamples[Sentence.RIGHT][i];
|
||||||
}
|
}
|
||||||
|
|
||||||
d.process(subSamples);
|
d.process(subSamples);
|
||||||
|
|
||||||
for (int i = 0; i < subSamples.length; i++) {
|
for (int i = 0; i < subSamples[Sentence.LEFT].length; i++) {
|
||||||
int off = i + d.getSamples();
|
int off = i + d.getSamples();
|
||||||
if ((off < samples.length) && (off > 0)) {
|
if ((off < samples[Sentence.LEFT].length) && (off > 0)) {
|
||||||
|
samples[Sentence.LEFT][off] = Utils.mix(samples[Sentence.LEFT][off], subSamples[Sentence.LEFT][i]);
|
||||||
double[] ns = mix(samples[off], subSamples[i]);
|
samples[Sentence.RIGHT][off] = Utils.mix(samples[Sentence.RIGHT][off], subSamples[Sentence.RIGHT][i]);
|
||||||
samples[off][Sentence.LEFT] = ns[Sentence.LEFT];
|
|
||||||
samples[off][Sentence.RIGHT] = ns[Sentence.RIGHT];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double[] mix(double[] a, double[] b) {
|
|
||||||
double[] out = new double[2];
|
|
||||||
|
|
||||||
if ((a[Sentence.LEFT] < 0) && (b[Sentence.LEFT] < 0)) {
|
|
||||||
out[Sentence.LEFT] = (a[Sentence.LEFT] + b[Sentence.LEFT]) - (a[Sentence.LEFT] * b[Sentence.LEFT]);
|
|
||||||
} else if ((a[Sentence.LEFT] > 0) && (b[Sentence.LEFT] > 0)) {
|
|
||||||
out[Sentence.LEFT] = (a[Sentence.LEFT] + b[Sentence.LEFT]) - (a[Sentence.LEFT] * b[Sentence.LEFT]);
|
|
||||||
} else {
|
|
||||||
out[Sentence.LEFT] = a[Sentence.LEFT] + b[Sentence.LEFT];
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((a[Sentence.RIGHT] < 0) && (b[Sentence.RIGHT] < 0)) {
|
|
||||||
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
|
||||||
} else if ((a[Sentence.RIGHT] > 0) && (b[Sentence.RIGHT] > 0)) {
|
|
||||||
out[Sentence.RIGHT] = (a[Sentence.RIGHT] + b[Sentence.RIGHT]) - (a[Sentence.RIGHT] * b[Sentence.RIGHT]);
|
|
||||||
} else {
|
|
||||||
out[Sentence.RIGHT] = a[Sentence.RIGHT] + b[Sentence.RIGHT];
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DelayLineStore addDelayLine(int samples, double gain, double pan) {
|
public DelayLineStore addDelayLine(int samples, double gain, double pan) {
|
||||||
DelayLineStore s = new DelayLineStore(samples, gain, pan);
|
DelayLineStore s = new DelayLineStore(samples, gain, pan);
|
||||||
delayLines.add(s);
|
delayLines.add(s);
|
||||||
|
|||||||
@@ -29,16 +29,16 @@ public class DelayLineStore {
|
|||||||
e.process(samples);
|
e.process(samples);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (double[] sample : samples) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
sample[Sentence.LEFT] *= gain;
|
samples[Sentence.LEFT][i] *= gain;
|
||||||
sample[Sentence.RIGHT] *= gain;
|
samples[Sentence.RIGHT][i] *= gain;
|
||||||
|
|
||||||
if (pan < 0) {
|
if (pan < 0) {
|
||||||
double p = 1 + pan;
|
double p = 1 + pan;
|
||||||
sample[Sentence.RIGHT] *= p;
|
samples[Sentence.RIGHT][i] *= p;
|
||||||
} else {
|
} else {
|
||||||
double p = 1 - pan;
|
double p = 1 - pan;
|
||||||
sample[Sentence.LEFT] *= p;
|
samples[Sentence.LEFT][i] *= p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JButton;
|
||||||
import java.awt.*;
|
import javax.swing.JPanel;
|
||||||
import java.awt.event.*;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.border.*;
|
import javax.swing.JTextArea;
|
||||||
import java.net.*;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class DonationPanel extends JPanel {
|
public class DonationPanel extends JPanel {
|
||||||
public DonationPanel() {
|
public DonationPanel() {
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
|
|
||||||
public class EffectGroup implements Effect {
|
public class EffectGroup implements Effect {
|
||||||
String name;
|
String name;
|
||||||
@@ -66,4 +70,259 @@ public class EffectGroup implements Effect {
|
|||||||
e.init(sf);
|
e.init(sf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static EffectGroup loadEffectGroup(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
EffectGroup group = new EffectGroup(root.getAttribute("name"));
|
||||||
|
NodeList kids = root.getChildNodes();
|
||||||
|
for (int i = 0; i < kids.getLength(); i++) {
|
||||||
|
Node kid = kids.item(i);
|
||||||
|
if (kid instanceof Element) {
|
||||||
|
Element e = (Element)kid;
|
||||||
|
if (e.getTagName().equals("biquad")) {
|
||||||
|
Effect eff = (Effect)loadBiquad(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (e.getTagName().equals("delayline")) {
|
||||||
|
Effect eff = (Effect)loadDelayLine(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (e.getTagName().equals("pan")) {
|
||||||
|
Effect eff = (Effect)loadPan(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (e.getTagName().equals("amplifier")) {
|
||||||
|
Effect eff = (Effect)loadAmplifier(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (e.getTagName().equals("chain")) {
|
||||||
|
Effect eff = (Effect)loadChain(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (e.getTagName().equals("group")) {
|
||||||
|
Effect eff = (Effect)loadEffectGroup(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (e.getTagName().equals("lfo")) {
|
||||||
|
Effect eff = (Effect)loadLFO(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (e.getTagName().equals("agc")) {
|
||||||
|
Effect eff = (Effect)loadAGC(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (e.getTagName().equals("clipping")) {
|
||||||
|
Effect eff = (Effect)loadClipping(e);
|
||||||
|
if (eff != null) {
|
||||||
|
group.addEffect(eff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Biquad loadBiquad(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
String type = root.getAttribute("type").toLowerCase();
|
||||||
|
Biquad bq = new Biquad();
|
||||||
|
|
||||||
|
if (type.equals("lowpass")) {
|
||||||
|
bq.setType(Biquad.Lowpass);
|
||||||
|
} else if (type.equals("highpass")) {
|
||||||
|
bq.setType(Biquad.Highpass);
|
||||||
|
} else if (type.equals("bandpass")) {
|
||||||
|
bq.setType(Biquad.Bandpass);
|
||||||
|
} else if (type.equals("notch")) {
|
||||||
|
bq.setType(Biquad.Notch);
|
||||||
|
} else if (type.equals("peak")) {
|
||||||
|
bq.setType(Biquad.Peak);
|
||||||
|
} else if (type.equals("lowshelf")) {
|
||||||
|
bq.setType(Biquad.Lowshelf);
|
||||||
|
} else if (type.equals("highshelf")) {
|
||||||
|
bq.setType(Biquad.Highshelf);
|
||||||
|
} else {
|
||||||
|
Debug.d("Bad Biquad type:", type);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
bq.setQ(Utils.s2d(root.getAttribute("q")));
|
||||||
|
bq.setFc(Utils.s2d(root.getAttribute("fc")));
|
||||||
|
bq.setPeakGain(Utils.s2d(root.getAttribute("gain")));
|
||||||
|
return bq;
|
||||||
|
}
|
||||||
|
public static DelayLine loadDelayLine(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
DelayLine line = new DelayLine();
|
||||||
|
|
||||||
|
NodeList list = root.getChildNodes();
|
||||||
|
if (Utils.s2b(root.getAttribute("wetonly"))) {
|
||||||
|
line.setWetOnly(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < list.getLength(); i++) {
|
||||||
|
Node n = list.item(i);
|
||||||
|
if (n instanceof Element) {
|
||||||
|
Element e = (Element)n;
|
||||||
|
if (e.getTagName().equals("delay")) {
|
||||||
|
int samples = Utils.s2i(e.getAttribute("samples"));
|
||||||
|
double gain = Utils.s2d(e.getAttribute("gain"));
|
||||||
|
double pan = Utils.s2d(e.getAttribute("pan"));
|
||||||
|
DelayLineStore store = line.addDelayLine(samples, gain, pan);
|
||||||
|
|
||||||
|
|
||||||
|
NodeList inner = e.getChildNodes();
|
||||||
|
for (int j = 0; j < inner.getLength(); j++) {
|
||||||
|
Node in = inner.item(j);
|
||||||
|
if (in instanceof Element) {
|
||||||
|
Element ie = (Element)in;
|
||||||
|
|
||||||
|
if (ie.getTagName().equals("biquad")) {
|
||||||
|
Effect eff = (Effect)loadBiquad(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (ie.getTagName().equals("delayline")) {
|
||||||
|
Effect eff = (Effect)loadDelayLine(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (ie.getTagName().equals("pan")) {
|
||||||
|
Effect eff = (Effect)loadPan(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (ie.getTagName().equals("amplifier")) {
|
||||||
|
Effect eff = (Effect)loadAmplifier(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (ie.getTagName().equals("chain")) {
|
||||||
|
Effect eff = (Effect)loadChain(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (ie.getTagName().equals("group")) {
|
||||||
|
Effect eff = (Effect)loadEffectGroup(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (ie.getTagName().equals("lfo")) {
|
||||||
|
Effect eff = (Effect)loadLFO(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (ie.getTagName().equals("agc")) {
|
||||||
|
Effect eff = (Effect)loadAGC(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
|
} else if (ie.getTagName().equals("clipping")) {
|
||||||
|
Effect eff = (Effect)loadClipping(ie);
|
||||||
|
if (eff != null) {
|
||||||
|
store.addEffect(eff);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Amplifier loadAmplifier(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
Amplifier a = new Amplifier(Utils.s2d(root.getAttribute("gain")));
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Chain loadChain(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
Chain c = new Chain(root.getAttribute("src"));
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Pan loadPan(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
Pan p = new Pan(Utils.s2d(root.getAttribute("pan")));
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Clipping loadClipping(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
Clipping c = new Clipping(Utils.s2d(root.getAttribute("clip")));
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LFO loadLFO(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
double f = Utils.s2d(root.getAttribute("frequency"));
|
||||||
|
double d = Utils.s2d(root.getAttribute("depth"));
|
||||||
|
double p = Utils.s2d(root.getAttribute("phase"));
|
||||||
|
double dty = Math.PI;
|
||||||
|
String waveform = root.getAttribute("waveform");
|
||||||
|
if (waveform == null) {
|
||||||
|
waveform = "sine";
|
||||||
|
}
|
||||||
|
|
||||||
|
int w = LFO.SINE;
|
||||||
|
|
||||||
|
switch (waveform.toLowerCase()) {
|
||||||
|
case "sine": w = LFO.SINE; break;
|
||||||
|
case "cosine": w = LFO.COSINE; break;
|
||||||
|
case "square": w = LFO.SQUARE; break;
|
||||||
|
case "triangle": w = LFO.TRIANGLE; break;
|
||||||
|
case "sawtooth": w = LFO.SAWTOOTH; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
int m = LFO.ADD;
|
||||||
|
|
||||||
|
String mode = root.getAttribute("mode");
|
||||||
|
|
||||||
|
if (mode == null) {
|
||||||
|
mode = "add";
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (mode.toLowerCase()) {
|
||||||
|
case "add": m = LFO.ADD; break;
|
||||||
|
case "replace": m = LFO.REPLACE; break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root.getAttribute("duty") != null) {
|
||||||
|
int di = Utils.s2i(root.getAttribute("duty")); // 0-100;
|
||||||
|
dty = (Math.PI * 2) * ((double)di / 100d);
|
||||||
|
}
|
||||||
|
return new LFO(f, d, p, w, dty, m);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AGC loadAGC(Element root) {
|
||||||
|
Debug.trace();
|
||||||
|
double ceiling = Utils.s2d(root.getAttribute("ceiling"));
|
||||||
|
double limit = Utils.s2d(root.getAttribute("limit"));
|
||||||
|
double attack = Utils.s2d(root.getAttribute("attack"));
|
||||||
|
double decay = Utils.s2d(root.getAttribute("decay"));
|
||||||
|
if (ceiling < 0.0001d) {
|
||||||
|
ceiling = 0.708d; // -3dB
|
||||||
|
}
|
||||||
|
if (limit < 0.0001d) {
|
||||||
|
limit = 1d; // No gain
|
||||||
|
}
|
||||||
|
AGC agc = new AGC(ceiling, attack, decay, limit);
|
||||||
|
return agc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,130 +1,93 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Orlando Selenu
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class FFT {
|
public class FFT {
|
||||||
/**
|
public static double[] fft(final double[] inputReal, double[] inputImag, boolean DIRECT) {
|
||||||
* The Fast Fourier Transform (generic version, with NO optimizations).
|
int n = inputReal.length;
|
||||||
*
|
|
||||||
* @param inputReal
|
|
||||||
* an array of length n, the real part
|
|
||||||
* @param inputImag
|
|
||||||
* an array of length n, the imaginary part
|
|
||||||
* @param DIRECT
|
|
||||||
* TRUE = direct transform, FALSE = inverse transform
|
|
||||||
* @return a new array of length 2n
|
|
||||||
*/
|
|
||||||
public static double[] fft(final double[] inputReal, double[] inputImag,
|
|
||||||
boolean DIRECT) {
|
|
||||||
// - n is the dimension of the problem
|
|
||||||
// - nu is its logarithm in base e
|
|
||||||
int n = inputReal.length;
|
|
||||||
|
|
||||||
// If n is a power of 2, then ld is an integer (_without_ decimals)
|
double ld = Math.log(n) / Math.log(2.0);
|
||||||
double ld = Math.log(n) / Math.log(2.0);
|
|
||||||
|
|
||||||
// Here I check if n is a power of 2. If exist decimals in ld, I quit
|
if (((int) ld) - ld != 0) {
|
||||||
// from the function returning null.
|
System.out.println("The number of elements is not a power of 2.");
|
||||||
if (((int) ld) - ld != 0) {
|
return null;
|
||||||
System.out.println("The number of elements is not a power of 2.");
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Declaration and initialization of the variables
|
int nu = (int) ld;
|
||||||
// ld should be an integer, actually, so I don't lose any information in
|
int n2 = n / 2;
|
||||||
// the cast
|
int nu1 = nu - 1;
|
||||||
int nu = (int) ld;
|
double[] xReal = new double[n];
|
||||||
int n2 = n / 2;
|
double[] xImag = new double[n];
|
||||||
int nu1 = nu - 1;
|
double tReal, tImag, p, arg, c, s;
|
||||||
double[] xReal = new double[n];
|
|
||||||
double[] xImag = new double[n];
|
|
||||||
double tReal, tImag, p, arg, c, s;
|
|
||||||
|
|
||||||
// Here I check if I'm going to do the direct transform or the inverse
|
double constant;
|
||||||
// transform.
|
if (DIRECT) {
|
||||||
double constant;
|
constant = -2 * Math.PI;
|
||||||
if (DIRECT)
|
} else {
|
||||||
constant = -2 * Math.PI;
|
constant = 2 * Math.PI;
|
||||||
else
|
}
|
||||||
constant = 2 * Math.PI;
|
|
||||||
|
|
||||||
// I don't want to overwrite the input arrays, so here I copy them. This
|
for (int i = 0; i < n; i++) {
|
||||||
// choice adds \Theta(2n) to the complexity.
|
xReal[i] = inputReal[i];
|
||||||
for (int i = 0; i < n; i++) {
|
xImag[i] = inputImag[i];
|
||||||
xReal[i] = inputReal[i];
|
}
|
||||||
xImag[i] = inputImag[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// First phase - calculation
|
int k = 0;
|
||||||
int k = 0;
|
for (int l = 1; l <= nu; l++) {
|
||||||
for (int l = 1; l <= nu; l++) {
|
while (k < n) {
|
||||||
while (k < n) {
|
for (int i = 1; i <= n2; i++) {
|
||||||
for (int i = 1; i <= n2; i++) {
|
p = bitreverseReference(k >> nu1, nu);
|
||||||
p = bitreverseReference(k >> nu1, nu);
|
// direct FFT or inverse FFT
|
||||||
// direct FFT or inverse FFT
|
arg = constant * p / n;
|
||||||
arg = constant * p / n;
|
c = Math.cos(arg);
|
||||||
c = Math.cos(arg);
|
s = Math.sin(arg);
|
||||||
s = Math.sin(arg);
|
tReal = xReal[k + n2] * c + xImag[k + n2] * s;
|
||||||
tReal = xReal[k + n2] * c + xImag[k + n2] * s;
|
tImag = xImag[k + n2] * c - xReal[k + n2] * s;
|
||||||
tImag = xImag[k + n2] * c - xReal[k + n2] * s;
|
xReal[k + n2] = xReal[k] - tReal;
|
||||||
xReal[k + n2] = xReal[k] - tReal;
|
xImag[k + n2] = xImag[k] - tImag;
|
||||||
xImag[k + n2] = xImag[k] - tImag;
|
xReal[k] += tReal;
|
||||||
xReal[k] += tReal;
|
xImag[k] += tImag;
|
||||||
xImag[k] += tImag;
|
k++;
|
||||||
k++;
|
}
|
||||||
|
k += n2;
|
||||||
}
|
}
|
||||||
k += n2;
|
k = 0;
|
||||||
|
nu1--;
|
||||||
|
n2 /= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
k = 0;
|
k = 0;
|
||||||
nu1--;
|
int r;
|
||||||
n2 /= 2;
|
while (k < n) {
|
||||||
}
|
r = bitreverseReference(k, nu);
|
||||||
|
if (r > k) {
|
||||||
// Second phase - recombination
|
tReal = xReal[k];
|
||||||
k = 0;
|
tImag = xImag[k];
|
||||||
int r;
|
xReal[k] = xReal[r];
|
||||||
while (k < n) {
|
xImag[k] = xImag[r];
|
||||||
r = bitreverseReference(k, nu);
|
xReal[r] = tReal;
|
||||||
if (r > k) {
|
xImag[r] = tImag;
|
||||||
tReal = xReal[k];
|
}
|
||||||
tImag = xImag[k];
|
k++;
|
||||||
xReal[k] = xReal[r];
|
|
||||||
xImag[k] = xImag[r];
|
|
||||||
xReal[r] = tReal;
|
|
||||||
xImag[r] = tImag;
|
|
||||||
}
|
}
|
||||||
k++;
|
|
||||||
|
double[] newArray = new double[xReal.length * 2];
|
||||||
|
double radice = 1 / Math.sqrt(n);
|
||||||
|
for (int i = 0; i < newArray.length; i += 2) {
|
||||||
|
int i2 = i / 2;
|
||||||
|
newArray[i] = xReal[i2] * radice;
|
||||||
|
newArray[i + 1] = xImag[i2] * radice;
|
||||||
|
}
|
||||||
|
return newArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Here I have to mix xReal and xImag to have an array (yes, it should
|
private static int bitreverseReference(int j, int nu) {
|
||||||
// be possible to do this stuff in the earlier parts of the code, but
|
int j2;
|
||||||
// it's here to readibility).
|
int j1 = j;
|
||||||
double[] newArray = new double[xReal.length * 2];
|
int k = 0;
|
||||||
double radice = 1 / Math.sqrt(n);
|
for (int i = 1; i <= nu; i++) {
|
||||||
for (int i = 0; i < newArray.length; i += 2) {
|
j2 = j1 / 2;
|
||||||
int i2 = i / 2;
|
k = 2 * k + j1 - 2 * j2;
|
||||||
// I used Stephen Wolfram's Mathematica as a reference so I'm going
|
j1 = j2;
|
||||||
// to normalize the output while I'm copying the elements.
|
}
|
||||||
newArray[i] = xReal[i2] * radice;
|
return k;
|
||||||
newArray[i + 1] = xImag[i2] * radice;
|
|
||||||
}
|
}
|
||||||
return newArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The reference bitreverse function.
|
|
||||||
*/
|
|
||||||
private static int bitreverseReference(int j, int nu) {
|
|
||||||
int j2;
|
|
||||||
int j1 = j;
|
|
||||||
int k = 0;
|
|
||||||
for (int i = 1; i <= nu; i++) {
|
|
||||||
j2 = j1 / 2;
|
|
||||||
k = 2 * k + j1 - 2 * j2;
|
|
||||||
j1 = j2;
|
|
||||||
}
|
|
||||||
return k;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.util.TimerTask;
|
||||||
import java.awt.*;
|
import java.util.Timer;
|
||||||
import java.util.*;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
public class FlashPanel extends JPanel {
|
public class FlashPanel extends JPanel {
|
||||||
|
|
||||||
boolean flash = false;
|
boolean flash = false;
|
||||||
boolean col = false;
|
boolean col = false;
|
||||||
|
|
||||||
java.util.Timer ticker;
|
Timer ticker;
|
||||||
|
|
||||||
public FlashPanel() {
|
public FlashPanel() {
|
||||||
super();
|
super();
|
||||||
ticker = new java.util.Timer(true);
|
ticker = new Timer(true);
|
||||||
ticker.scheduleAtFixedRate(new TimerTask() {
|
ticker.scheduleAtFixedRate(new TimerTask() {
|
||||||
public void run() {
|
public void run() {
|
||||||
if (flash) {
|
if (flash) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
public class Icons {
|
public class Icons {
|
||||||
static public final ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png"));
|
static public final ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png"));
|
||||||
@@ -38,4 +38,10 @@ public class Icons {
|
|||||||
static public final ImageIcon docut = new ImageIcon(Icons.class.getResource("icons/do-cut.png"));
|
static public final ImageIcon docut = new ImageIcon(Icons.class.getResource("icons/do-cut.png"));
|
||||||
static public final ImageIcon playto = new ImageIcon(Icons.class.getResource("icons/play-to.png"));
|
static public final ImageIcon playto = new ImageIcon(Icons.class.getResource("icons/play-to.png"));
|
||||||
static public final ImageIcon disable = new ImageIcon(Icons.class.getResource("icons/disable-effects.png"));
|
static public final ImageIcon disable = new ImageIcon(Icons.class.getResource("icons/disable-effects.png"));
|
||||||
|
static public final ImageIcon manuscript = new ImageIcon(Icons.class.getResource("icons/manuscript.png"));
|
||||||
|
static public final ImageIcon tooltip = new ImageIcon(Icons.class.getResource("icons/tooltip.png"));
|
||||||
|
static public final ImageIcon queued = new ImageIcon(Icons.class.getResource("icons/queued.png"));
|
||||||
|
static public final ImageIcon processing = new ImageIcon(Icons.class.getResource("icons/processing.png"));
|
||||||
|
static public final ImageIcon close = new ImageIcon(Icons.class.getResource("icons/close.png"));
|
||||||
|
static public final ImageIcon refresh = new ImageIcon(Icons.class.getResource("icons/refresh.png"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JButton;
|
||||||
import javax.swing.event.*;
|
import javax.swing.ImageIcon;
|
||||||
import java.awt.*;
|
import javax.swing.JComponent;
|
||||||
import java.awt.event.*;
|
import javax.swing.KeyStroke;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
public class JButtonSpacePlay extends JButton {
|
public class JButtonSpacePlay extends JButton {
|
||||||
public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||||
|
|||||||
38
src/uk/co/majenko/audiobookrecorder/JLabelFixedWidth.java
Normal file
38
src/uk/co/majenko/audiobookrecorder/JLabelFixedWidth.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
|
||||||
|
public class JLabelFixedWidth extends JLabel {
|
||||||
|
int width = 0;
|
||||||
|
int height = 0;
|
||||||
|
Dimension size;
|
||||||
|
public JLabelFixedWidth(int w, String txt) {
|
||||||
|
super(txt);
|
||||||
|
JLabel t = new JLabel(txt);
|
||||||
|
size = t.getPreferredSize();
|
||||||
|
size.width = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JLabelFixedWidth(int w) {
|
||||||
|
super();
|
||||||
|
JLabel t = new JLabel("nothing");
|
||||||
|
size = t.getPreferredSize();
|
||||||
|
size.width = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMaximumSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMinimumSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JSlider;
|
||||||
|
|
||||||
public class JSliderOb extends JSlider {
|
public class JSliderOb extends JSlider {
|
||||||
Object object;
|
Object object;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
import javax.swing.*;
|
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
public class JTextFieldOb extends JTextField {
|
public class JTextFieldOb extends JTextField {
|
||||||
Object object;
|
Object object;
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.event.ActionListener;
|
||||||
import javax.swing.event.*;
|
import java.awt.event.KeyEvent;
|
||||||
import java.awt.*;
|
import javax.swing.JToggleButton;
|
||||||
import java.awt.event.*;
|
import javax.swing.JComponent;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
public class JToggleButtonSpacePlay extends JToggleButton {
|
public class JToggleButtonSpacePlay extends JToggleButton {
|
||||||
public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||||
|
|||||||
@@ -14,10 +14,6 @@ public class KVPair<K,V> implements Comparable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int compareTo(Object o) {
|
public int compareTo(Object o) {
|
||||||
// if (o instanceof KVPair) {
|
|
||||||
// KVPair ko = (KVPair)o;
|
|
||||||
// return key.compareTo(ko.key);
|
|
||||||
// }
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,37 +9,73 @@ public class LFO implements Effect {
|
|||||||
double depth;
|
double depth;
|
||||||
double sampleRate;
|
double sampleRate;
|
||||||
double sampleStep;
|
double sampleStep;
|
||||||
|
int waveform;
|
||||||
|
double duty;
|
||||||
|
int mode;
|
||||||
|
|
||||||
|
public static final int SINE = 0;
|
||||||
|
public static final int COSINE = 1;
|
||||||
|
public static final int SQUARE = 2;
|
||||||
|
public static final int TRIANGLE = 3;
|
||||||
|
public static final int SAWTOOTH = 4;
|
||||||
|
|
||||||
|
public static final int ADD = 0;
|
||||||
|
public static final int REPLACE = 1;
|
||||||
|
|
||||||
public LFO(double f, double d) {
|
public LFO(double f, double d) {
|
||||||
frequency = f;
|
this(f, d, 0, SINE, Math.PI, REPLACE);
|
||||||
depth = d;
|
|
||||||
phase = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public LFO(double f, double d, double p) {
|
public LFO(double f, double d, double p) {
|
||||||
|
this(f, d, p, SINE, Math.PI, REPLACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LFO(double f, double d, double p, int w) {
|
||||||
|
this(f, d, p, w, Math.PI, REPLACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LFO(double f, double d, double p, int w, double dty) {
|
||||||
|
this(f, d, p, w, dty, REPLACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LFO(double f, double d, double p, int w, double dty, int m) {
|
||||||
frequency = f;
|
frequency = f;
|
||||||
depth = d;
|
depth = d;
|
||||||
phase = p;
|
phase = p;
|
||||||
|
waveform = w;
|
||||||
|
duty = dty;
|
||||||
|
mode = m;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
for (double[] sample : samples) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
double v = Math.sin(phase);
|
double v = 0;
|
||||||
|
switch (waveform) {
|
||||||
|
case SINE: v = Math.sin(phase); break;
|
||||||
|
case COSINE: v = Math.cos(phase); break;
|
||||||
|
case SQUARE: v = (phase > duty) ? 1d : 0d; break;
|
||||||
|
case TRIANGLE: v = (phase < Math.PI) ? (phase / Math.PI) : (1d - ((phase - Math.PI) / Math.PI)); break;
|
||||||
|
case SAWTOOTH: v = (phase / (Math.PI*2d)); break;
|
||||||
|
}
|
||||||
phase += sampleStep;
|
phase += sampleStep;
|
||||||
if (phase > (Math.PI * 2d)) {
|
if (phase > (Math.PI * 2d)) {
|
||||||
phase -= (Math.PI * 2d);
|
phase -= (Math.PI * 2d);
|
||||||
}
|
}
|
||||||
|
|
||||||
// // Make it between 0 and 1.
|
|
||||||
// v = 1d + v;
|
|
||||||
// v /= 2d;
|
|
||||||
|
|
||||||
// Multiply it by the gain factor
|
// Multiply it by the gain factor
|
||||||
v *= depth;
|
v *= depth;
|
||||||
|
|
||||||
// Apply it to the sample
|
// Apply it to the sample
|
||||||
sample[Sentence.LEFT] += (sample[Sentence.LEFT] * v);
|
switch (mode) {
|
||||||
sample[Sentence.RIGHT] += (sample[Sentence.RIGHT] * v);
|
case REPLACE:
|
||||||
|
samples[Sentence.LEFT][i] = (samples[Sentence.LEFT][i] * v);
|
||||||
|
samples[Sentence.RIGHT][i] = (samples[Sentence.RIGHT][i] * v);
|
||||||
|
break;
|
||||||
|
case ADD:
|
||||||
|
samples[Sentence.LEFT][i] += (samples[Sentence.LEFT][i] * v);
|
||||||
|
samples[Sentence.RIGHT][i] += (samples[Sentence.RIGHT][i] * v);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.event.ActionEvent;
|
||||||
import javax.swing.event.*;
|
import java.awt.event.ActionListener;
|
||||||
import java.awt.*;
|
import java.awt.Color;
|
||||||
import java.awt.event.*;
|
import javax.swing.JToggleButton;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JToolBar;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
public class MainToolBar extends JToolBar {
|
public class MainToolBar extends JToolBar {
|
||||||
|
|
||||||
@@ -16,9 +19,11 @@ public class MainToolBar extends JToolBar {
|
|||||||
JButtonSpacePlay playonSentence;
|
JButtonSpacePlay playonSentence;
|
||||||
JButtonSpacePlay playtoSentence;
|
JButtonSpacePlay playtoSentence;
|
||||||
JButtonSpacePlay stopPlaying;
|
JButtonSpacePlay stopPlaying;
|
||||||
JButtonSpacePlay eq;
|
JButtonSpacePlay openManuscript;
|
||||||
JToggleButtonSpacePlay mic;
|
JToggleButtonSpacePlay mic;
|
||||||
|
|
||||||
|
JComboBox<String> playbackSpeed;
|
||||||
|
|
||||||
JToggleButtonSpacePlay disableEffects;
|
JToggleButtonSpacePlay disableEffects;
|
||||||
|
|
||||||
AudiobookRecorder root;
|
AudiobookRecorder root;
|
||||||
@@ -44,7 +49,7 @@ public class MainToolBar extends JToolBar {
|
|||||||
|
|
||||||
saveBook = new JButtonSpacePlay(Icons.save, "Save Book", new ActionListener() {
|
saveBook = new JButtonSpacePlay(Icons.save, "Save Book", new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.saveBookStructure();
|
root.saveAllBooks();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(saveBook);
|
add(saveBook);
|
||||||
@@ -60,7 +65,7 @@ public class MainToolBar extends JToolBar {
|
|||||||
|
|
||||||
recordRoomNoise = new JButtonSpacePlay(Icons.recordRoom, "Record Room Noise", new ActionListener() {
|
recordRoomNoise = new JButtonSpacePlay(Icons.recordRoom, "Record Room Noise", new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.recordRoomNoise();
|
root.getBook().recordRoomNoise();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
add(recordRoomNoise);
|
add(recordRoomNoise);
|
||||||
@@ -96,15 +101,6 @@ public class MainToolBar extends JToolBar {
|
|||||||
});
|
});
|
||||||
add(stopPlaying);
|
add(stopPlaying);
|
||||||
|
|
||||||
addSeparator();
|
|
||||||
eq = new JButtonSpacePlay(Icons.eq, "Reload Effects", new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
root.loadEffects();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
add(eq);
|
|
||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
mic = new JToggleButtonSpacePlay(Icons.mic, "Enable / disable microphone", new ActionListener() {
|
mic = new JToggleButtonSpacePlay(Icons.mic, "Enable / disable microphone", new ActionListener() {
|
||||||
@@ -112,7 +108,7 @@ public class MainToolBar extends JToolBar {
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JToggleButton b = (JToggleButton)e.getSource();
|
JToggleButton b = (JToggleButton)e.getSource();
|
||||||
if (b.isSelected()) {
|
if (b.isSelected()) {
|
||||||
if (!root.enableMicrophone()) {
|
if (!Microphone.start()) {
|
||||||
b.setSelected(false);
|
b.setSelected(false);
|
||||||
} else {
|
} else {
|
||||||
if (bgCol == null) {
|
if (bgCol == null) {
|
||||||
@@ -121,7 +117,7 @@ public class MainToolBar extends JToolBar {
|
|||||||
b.setBackground(Color.RED);
|
b.setBackground(Color.RED);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
root.disableMicrophone();
|
Microphone.stop();
|
||||||
if (bgCol != null) {
|
if (bgCol != null) {
|
||||||
b.setBackground(bgCol);
|
b.setBackground(bgCol);
|
||||||
}
|
}
|
||||||
@@ -129,6 +125,7 @@ public class MainToolBar extends JToolBar {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
add(mic);
|
add(mic);
|
||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
@@ -152,6 +149,28 @@ public class MainToolBar extends JToolBar {
|
|||||||
|
|
||||||
add(disableEffects);
|
add(disableEffects);
|
||||||
|
|
||||||
|
addSeparator();
|
||||||
|
|
||||||
|
add(new JLabel("Playback speed: "));
|
||||||
|
playbackSpeed = new JComboBox<String>(new String[] {
|
||||||
|
"0.75x",
|
||||||
|
"1.00x",
|
||||||
|
"1.25x",
|
||||||
|
"1.50x",
|
||||||
|
"1.75x"
|
||||||
|
});
|
||||||
|
playbackSpeed.setFocusable(false);
|
||||||
|
|
||||||
|
playbackSpeed.setSelectedIndex(1);
|
||||||
|
add(playbackSpeed);
|
||||||
|
|
||||||
|
addSeparator();
|
||||||
|
openManuscript = new JButtonSpacePlay(Icons.manuscript, "Open Manuscript", new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
root.openManuscript();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(openManuscript);
|
||||||
|
|
||||||
|
|
||||||
setFloatable(false);
|
setFloatable(false);
|
||||||
@@ -161,4 +180,9 @@ public class MainToolBar extends JToolBar {
|
|||||||
playtoSentence.setEnabled(b);
|
playtoSentence.setEnabled(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getPlaybackSpeed() {
|
||||||
|
int v = playbackSpeed.getSelectedIndex();
|
||||||
|
return 0.75f + (0.25f * v);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import java.awt.event.*;
|
|
||||||
|
|
||||||
public class MarkerDragEvent {
|
public class MarkerDragEvent {
|
||||||
|
|
||||||
Object src;
|
Object src;
|
||||||
|
|||||||
77
src/uk/co/majenko/audiobookrecorder/Microphone.java
Normal file
77
src/uk/co/majenko/audiobookrecorder/Microphone.java
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.Mixer;
|
||||||
|
import javax.sound.sampled.SourceDataLine;
|
||||||
|
import javax.sound.sampled.TargetDataLine;
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
public class Microphone {
|
||||||
|
|
||||||
|
public static TargetDataLine device = null;
|
||||||
|
public static AudioInputStream stream = null;
|
||||||
|
|
||||||
|
public static boolean start() {
|
||||||
|
Debug.trace();
|
||||||
|
AudioFormat format = Options.getAudioFormat();
|
||||||
|
Mixer.Info mixer = Options.getRecordingMixer();
|
||||||
|
|
||||||
|
device = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
device = AudioSystem.getTargetDataLine(format, mixer);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
device = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device == null) {
|
||||||
|
JOptionPane.showMessageDialog(AudiobookRecorder.window, "Sample format not supported", "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream = new AudioInputStream(device);
|
||||||
|
|
||||||
|
try {
|
||||||
|
device.open();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
device = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
device.start();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stop() {
|
||||||
|
Debug.trace();
|
||||||
|
try {
|
||||||
|
stream.close();
|
||||||
|
device.stop();
|
||||||
|
device.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
device = null;
|
||||||
|
stream = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AudioInputStream getStream() {
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TargetDataLine getDevice() {
|
||||||
|
return device;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void flush() {
|
||||||
|
if (device != null) {
|
||||||
|
device.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
src/uk/co/majenko/audiobookrecorder/NoiseFloor.java
Normal file
51
src/uk/co/majenko/audiobookrecorder/NoiseFloor.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
|
public class NoiseFloor extends JPanel {
|
||||||
|
|
||||||
|
int noiseFloor = 0;
|
||||||
|
|
||||||
|
public NoiseFloor() {
|
||||||
|
super();
|
||||||
|
noiseFloor = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNoiseFloor(int n) {
|
||||||
|
noiseFloor = n;
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return new Dimension(128, 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMinimumSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMaximumSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
Rectangle size = g.getClipBounds();
|
||||||
|
g.setColor(getBackground());
|
||||||
|
g.fillRect(0, 0, size.width - 1, size.height - 1);
|
||||||
|
g.setColor(new Color(10, 10, 10));
|
||||||
|
g.drawRect(0, 0, size.width - 1, size.height - 1);
|
||||||
|
g.setFont(getFont());
|
||||||
|
|
||||||
|
g.setColor(getForeground());
|
||||||
|
g.drawString("Noise Floor: " + noiseFloor + "dB", 6, 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.table.*;
|
import javax.swing.table.TableCellRenderer;
|
||||||
import javax.swing.event.*;
|
import javax.swing.JTable;
|
||||||
import java.awt.*;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import java.awt.event.*;
|
import java.util.ArrayList;
|
||||||
import java.io.*;
|
import javax.swing.JScrollPane;
|
||||||
import java.util.*;
|
import java.io.File;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Component;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
public class OpenBookPanel extends JPanel {
|
public class OpenBookPanel extends JPanel {
|
||||||
|
|
||||||
@@ -86,10 +92,16 @@ public class OpenBookPanel extends JPanel {
|
|||||||
for (File b : dir.listFiles()) {
|
for (File b : dir.listFiles()) {
|
||||||
if (b == null) continue;
|
if (b == null) continue;
|
||||||
if (!b.isDirectory()) continue;
|
if (!b.isDirectory()) continue;
|
||||||
File xml = new File(b, "audiobook.abk");
|
File xml = new File(b, "audiobook.abx");
|
||||||
if (xml.exists()) {
|
if (xml.exists()) {
|
||||||
BookPanel book = new BookPanel(b);
|
BookPanel book = new BookPanel(b);
|
||||||
model.addBook(book);
|
model.addBook(book);
|
||||||
|
} else {
|
||||||
|
xml = new File(b, "audiobook.abk");
|
||||||
|
if (xml.exists()) {
|
||||||
|
BookPanel book = new BookPanel(b);
|
||||||
|
model.addBook(book);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,7 +121,7 @@ public class OpenBookPanel extends JPanel {
|
|||||||
c = c.getParent();
|
c = c.getParent();
|
||||||
}
|
}
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
System.err.println("Could not get option pane!");
|
Debug.d("Could not get option pane!");
|
||||||
} else {
|
} else {
|
||||||
JOptionPane op = (JOptionPane)c;
|
JOptionPane op = (JOptionPane)c;
|
||||||
op.setValue(JOptionPane.OK_OPTION);
|
op.setValue(JOptionPane.OK_OPTION);
|
||||||
|
|||||||
@@ -1,14 +1,42 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.sound.sampled.*;
|
import java.io.File;
|
||||||
import javax.swing.*;
|
import java.util.TreeSet;
|
||||||
import javax.swing.event.*;
|
import java.util.ArrayList;
|
||||||
import java.awt.*;
|
import java.util.HashMap;
|
||||||
import java.awt.event.*;
|
import java.util.prefs.Preferences;
|
||||||
import java.util.*;
|
import java.awt.GridBagConstraints;
|
||||||
import java.util.prefs.*;
|
import java.awt.GridBagLayout;
|
||||||
import java.io.*;
|
import java.awt.BorderLayout;
|
||||||
import javax.swing.tree.*;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Dialog;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import javax.swing.JDialog;
|
||||||
|
import javax.swing.JTabbedPane;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JSpinner;
|
||||||
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import javax.sound.sampled.Mixer;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
import javax.swing.JScrollPane;
|
||||||
|
import javax.sound.sampled.DataLine;
|
||||||
|
import javax.sound.sampled.TargetDataLine;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.SourceDataLine;
|
||||||
|
|
||||||
public class Options extends JDialog {
|
public class Options extends JDialog {
|
||||||
|
|
||||||
@@ -16,14 +44,14 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
GridBagConstraints constraint;
|
GridBagConstraints constraint;
|
||||||
|
|
||||||
public static ArrayList<EffectGroup> effectChains;
|
|
||||||
|
|
||||||
JComboBox<KVPair> mixerList;
|
JComboBox<KVPair> mixerList;
|
||||||
JComboBox<KVPair> playbackList;
|
JComboBox<KVPair> playbackList;
|
||||||
JComboBox<KVPair> channelList;
|
JComboBox<KVPair> channelList;
|
||||||
JComboBox<KVPair> rateList;
|
JComboBox<KVPair> rateList;
|
||||||
JComboBox<KVPair> bitDepth;
|
JComboBox<KVPair> bitDepth;
|
||||||
JComboBox<KVPair> trimMethod;
|
JComboBox<KVPair> trimMethod;
|
||||||
|
JComboBox<KVPair> fftBlockSize;
|
||||||
|
JComboBox<KVPair> playbackBlockSize;
|
||||||
JTextField storageFolder;
|
JTextField storageFolder;
|
||||||
JTextField archiveFolder;
|
JTextField archiveFolder;
|
||||||
JSpinner preChapterGap;
|
JSpinner preChapterGap;
|
||||||
@@ -32,8 +60,10 @@ public class Options extends JDialog {
|
|||||||
JSpinner shortSentenceGap;
|
JSpinner shortSentenceGap;
|
||||||
JSpinner postParagraphGap;
|
JSpinner postParagraphGap;
|
||||||
JSpinner postSectionGap;
|
JSpinner postSectionGap;
|
||||||
|
JSpinner maxGainVariance;
|
||||||
JTextField ffmpegLocation;
|
JTextField ffmpegLocation;
|
||||||
JComboBox<KVPair> bitRate;
|
JComboBox<KVPair> bitRate;
|
||||||
|
JComboBox<KVPair> channels;
|
||||||
JComboBox<KVPair> exportRate;
|
JComboBox<KVPair> exportRate;
|
||||||
JCheckBox enableParsing;
|
JCheckBox enableParsing;
|
||||||
JSpinner cacheSize;
|
JSpinner cacheSize;
|
||||||
@@ -46,6 +76,9 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
JTextField externalEditor;
|
JTextField externalEditor;
|
||||||
|
|
||||||
|
JTextField speechCommand;
|
||||||
|
JSpinner workerThreads;
|
||||||
|
|
||||||
JTextArea startupScript;
|
JTextArea startupScript;
|
||||||
|
|
||||||
ArrayList<JTextField[]> processorList;
|
ArrayList<JTextField[]> processorList;
|
||||||
@@ -65,7 +98,7 @@ public class Options extends JDialog {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
JComboBox<KVPair> addDropdown(JPanel panel, String label, KVPair[] options, String def) {
|
JComboBox<KVPair> addDropdown(JPanel panel, String label, KVPair[] options, String def, String tip) {
|
||||||
JLabel l = new JLabel(label);
|
JLabel l = new JLabel(label);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.gridwidth = 1;
|
constraint.gridwidth = 1;
|
||||||
@@ -76,8 +109,12 @@ public class Options extends JDialog {
|
|||||||
JComboBox<KVPair> o = new JComboBox<KVPair>(options);
|
JComboBox<KVPair> o = new JComboBox<KVPair>(options);
|
||||||
constraint.gridx = 1;
|
constraint.gridx = 1;
|
||||||
panel.add(o, constraint);
|
panel.add(o, constraint);
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
for (KVPair p : options) {
|
for (KVPair p : options) {
|
||||||
|
if (p == null) continue;
|
||||||
if (p.key.equals(def)) {
|
if (p.key.equals(def)) {
|
||||||
o.setSelectedItem(p);
|
o.setSelectedItem(p);
|
||||||
}
|
}
|
||||||
@@ -106,7 +143,7 @@ public class Options extends JDialog {
|
|||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
}
|
}
|
||||||
|
|
||||||
JTextField addTextField(JPanel panel, String label, String def) {
|
JTextField addTextField(JPanel panel, String label, String def, String tip) {
|
||||||
JLabel l = new JLabel(label);
|
JLabel l = new JLabel(label);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.gridwidth = 1;
|
constraint.gridwidth = 1;
|
||||||
@@ -120,13 +157,18 @@ public class Options extends JDialog {
|
|||||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||||
panel.add(a, constraint);
|
panel.add(a, constraint);
|
||||||
|
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
|
|
||||||
constraint.fill = GridBagConstraints.NONE;
|
constraint.fill = GridBagConstraints.NONE;
|
||||||
|
|
||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
JTextField[] addTwoField(JPanel panel, String def1, String def2) {
|
JTextField[] addTwoField(JPanel panel, String def1, String def2, String tip) {
|
||||||
JTextField a = new JTextField(def1);
|
JTextField a = new JTextField(def1);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||||
@@ -137,13 +179,18 @@ public class Options extends JDialog {
|
|||||||
panel.add(b, constraint);
|
panel.add(b, constraint);
|
||||||
constraint.fill = GridBagConstraints.NONE;
|
constraint.fill = GridBagConstraints.NONE;
|
||||||
|
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
|
|
||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
return new JTextField[] { a, b };
|
return new JTextField[] { a, b };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JTextField addFilePath(JPanel panel, String label, String path, boolean dironly) {
|
JTextField addFilePath(JPanel panel, String label, String path, boolean dironly, String tip) {
|
||||||
JLabel l = new JLabel(label);
|
JLabel l = new JLabel(label);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.gridwidth = 1;
|
constraint.gridwidth = 1;
|
||||||
@@ -205,6 +252,10 @@ public class Options extends JDialog {
|
|||||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||||
panel.add(p, constraint);
|
panel.add(p, constraint);
|
||||||
|
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
constraint.fill = GridBagConstraints.NONE;
|
constraint.fill = GridBagConstraints.NONE;
|
||||||
|
|
||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
@@ -231,7 +282,7 @@ public class Options extends JDialog {
|
|||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSpinner addSpinner(JPanel panel, String label, int min, int max, int step, int value, String suffix) {
|
JSpinner addSpinner(JPanel panel, String label, int min, int max, int step, int value, String suffix, String tip) {
|
||||||
JLabel l = new JLabel(label);
|
JLabel l = new JLabel(label);
|
||||||
constraint.gridx = 0;
|
constraint.gridx = 0;
|
||||||
constraint.gridwidth = 1;
|
constraint.gridwidth = 1;
|
||||||
@@ -251,6 +302,10 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||||
panel.add(p, constraint);
|
panel.add(p, constraint);
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
|
|
||||||
constraint.fill = GridBagConstraints.NONE;
|
constraint.fill = GridBagConstraints.NONE;
|
||||||
|
|
||||||
@@ -259,11 +314,16 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JCheckBox addCheckBox(JPanel panel, String label, boolean state) {
|
JCheckBox addCheckBox(JPanel panel, String label, boolean state, String tip) {
|
||||||
constraint.gridx = 1;
|
constraint.gridx = 1;
|
||||||
JCheckBox cb = new JCheckBox(label);
|
JCheckBox cb = new JCheckBox(label);
|
||||||
cb.setSelected(state);
|
cb.setSelected(state);
|
||||||
panel.add(cb, constraint);
|
panel.add(cb, constraint);
|
||||||
|
Tip t = new Tip(tip);
|
||||||
|
constraint.gridx = 2;
|
||||||
|
panel.add(t, constraint);
|
||||||
|
|
||||||
|
|
||||||
constraint.gridy++;
|
constraint.gridy++;
|
||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
@@ -291,89 +351,71 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
mixerList = addDropdown(optionsPanel, "Recording device:", getRecordingMixerList(), get("audio.recording.device"));
|
mixerList = addDropdown(optionsPanel, "Recording device:", getRecordingMixerList(), get("audio.recording.device"), "This is the system device to record through");
|
||||||
channelList = addDropdown(optionsPanel, "Channels:", getChannelCountList(), get("audio.recording.channels"));
|
channelList = addDropdown(optionsPanel, "Channels:", getChannelCountList(), get("audio.recording.channels"), "How many channels do you want to record - stereo or mono?");
|
||||||
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"));
|
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"), "The higher the sample rate the better the quality, but the bigger the files.");
|
||||||
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"));
|
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"), "The higher the resolution the better the quality, but the bigger the files.");
|
||||||
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"));
|
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"), "None: don't auto-trim. FFT: Compare the FFT profile of blocks to the room noise profile and trim silent blocks, Peak: Look for the start and end rise and fall points");
|
||||||
fftThreshold = addSpinner(optionsPanel, "FFT threshold:", 0, 100, 1, getInteger("audio.recording.trim.fft"), "");
|
fftThreshold = addSpinner(optionsPanel, "FFT threshold:", 0, 100, 1, getInteger("audio.recording.trim.fft"), "", "This specifies the difference (in hundredths) between the power of FFT buckets in a sample block compared to the overall power of the same FFT bucket in the room noise. Raising this number makes the FFT trimming less sensitive.");
|
||||||
|
fftBlockSize = addDropdown(optionsPanel, "FFT Block size:", getFFTBlockSizes(), get("audio.recording.trim.blocksize"), "How large an FFT block should be when processing. Larger values increase sensitivity but at the epxense of resolution.");
|
||||||
|
maxGainVariance = addSpinner(optionsPanel, "Maximum gain variance:", 0, 100, 1, getInteger("audio.recording.variance"), "", "This is how much the gain is allowed to vary by from phrase to phrase when normalizing an entire chapter.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device"));
|
playbackList = addDropdown(optionsPanel, "Playback device:", getPlaybackMixerList(), get("audio.playback.device"), "Which device to play back through");
|
||||||
|
playbackBlockSize = addDropdown(optionsPanel, "Playback Block size:", getPlaybackBlockSizes(), get("audio.playback.blocksize"), "How big the playback buffer should be. Larger is smoother playback but the playback marker in the waveform becomes more out of sync");
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true);
|
storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true, "This is where all your working audiobooks are stored.");
|
||||||
archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), true);
|
archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), true, "This is where audiobooks are archived to.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
preChapterGap = addSpinner(optionsPanel, "Default pre-chapter gap:", 0, 5000, 100, getInteger("catenation.pre-chapter"), "ms");
|
preChapterGap = addSpinner(optionsPanel, "Default pre-chapter gap:", 0, 5000, 100, getInteger("catenation.pre-chapter"), "ms", "How much room noise to add at the beginning of a chapter.");
|
||||||
postChapterGap = addSpinner(optionsPanel, "Default post-chapter gap:", 0, 5000, 100, getInteger("catenation.post-chapter"), "ms");
|
postChapterGap = addSpinner(optionsPanel, "Default post-chapter gap:", 0, 5000, 100, getInteger("catenation.post-chapter"), "ms", "How much room noise to add to the end of a chapter.");
|
||||||
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms");
|
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms", "How much room noise to add between normal sentences.");
|
||||||
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms");
|
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms", "How much room noise to add between 'continuations'.");
|
||||||
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms");
|
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms", "How much room noise to add between paragraphs.");
|
||||||
postSectionGap = addSpinner(optionsPanel, "Default post-section gap:", 0, 5000, 100, getInteger("catenation.post-section"), "ms");
|
postSectionGap = addSpinner(optionsPanel, "Default post-section gap:", 0, 5000, 100, getInteger("catenation.post-section"), "ms", "How much room noise to add between sections.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false);
|
ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false, "Path to your ffmpeg executable.");
|
||||||
bitRate = addDropdown(optionsPanel, "Export bitrate:", getBitrates(), get("audio.export.bitrate"));
|
bitRate = addDropdown(optionsPanel, "Export bitrate:", getBitrates(), get("audio.export.bitrate"), "The MP3 bitrate to produce");
|
||||||
exportRate = addDropdown(optionsPanel, "Export sample rate:", getSampleRateList(), get("audio.export.samplerate"));
|
channels = addDropdown(optionsPanel, "Export channels:", getChannelCountList(), get("audio.export.channels"), "Mono or stereo MP3 production");
|
||||||
|
exportRate = addDropdown(optionsPanel, "Export sample rate:", getSampleRateList(), get("audio.export.samplerate"), "Sample frequency of the produced MP3");
|
||||||
|
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
enableParsing = addCheckBox(optionsPanel, "Enable automatic sphinx speech-to-text (**SLOW**)", getBoolean("process.sphinx"));
|
enableParsing = addCheckBox(optionsPanel, "Enable automatic speech-to-text (**SLOW**)", getBoolean("process.sphinx"), "This will automatically start recognising the speech in every sentence you record. This can really slow down recording though so it's recommended to leave it turned off and do your recognition afterwards as a batch operation.");
|
||||||
|
speechCommand = addTextField(optionsPanel, "Speech to text command (must take 1 filename parameter):", get("process.command"), "This specifies what command to run to recognize the speech. This command must take only one parameter, which is the full path of the WAV file. It should return (on standard output) the recognised speech.");
|
||||||
|
workerThreads = addSpinner(optionsPanel, "Worker threads:", 1, 100, 1, getInteger("process.threads"), "", "How many concurrent threads to run when processing speech. This should ideally be no more than the number of CPU cores you have in your computer minus one.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
externalEditor = addTextField(optionsPanel, "External Editor Command", get("editor.external"));
|
externalEditor = addTextField(optionsPanel, "External Editor Command", get("editor.external"), "The program to run when you select 'Open in external editor'.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
cacheSize = addSpinner(optionsPanel, "Cache size:", 2, 100, 1, getInteger("cache.size"), "");
|
cacheSize = addSpinner(optionsPanel, "Cache size:", 2, 100, 1, getInteger("cache.size"), "", "How many phrases to keep cached in memory at once. More gives a smoother editing experience, but you can easily run out of memory if you are not careful.");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
tabs.add("Options", new JScrollPane(optionsPanel));
|
tabs.add("Options", new JScrollPane(optionsPanel));
|
||||||
|
|
||||||
JPanel effectChains = new JPanel();
|
|
||||||
effectChains.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
JPanel effectDetails = new JPanel() {
|
|
||||||
public Dimension getPreferredSize() {
|
|
||||||
return new Dimension(200, 400);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
DefaultTreeModel m = new DefaultTreeModel(new DefaultMutableTreeNode("Effect Chains"));
|
|
||||||
|
|
||||||
JTree effectChainTree = new JTree(m);
|
|
||||||
effectChains.add(effectChainTree, BorderLayout.CENTER);
|
|
||||||
effectChains.add(effectDetails, BorderLayout.EAST);
|
|
||||||
|
|
||||||
tabs.add("Effects Chains", new JScrollPane(effectChains));
|
|
||||||
|
|
||||||
JPanel startScript = new JPanel();
|
JPanel startScript = new JPanel();
|
||||||
startScript.setLayout(new BorderLayout());
|
startScript.setLayout(new BorderLayout());
|
||||||
|
startScript.setBorder(new EmptyBorder(15, 15, 15, 15));
|
||||||
startupScript = new JTextArea(get("scripts.startup"));
|
startupScript = new JTextArea(get("scripts.startup"));
|
||||||
|
startupScript.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
startupScript.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
|
||||||
startScript.add(startupScript, BorderLayout.CENTER);
|
startScript.add(startupScript, BorderLayout.CENTER);
|
||||||
tabs.add("Startup Script", startScript);
|
tabs.add("Startup Script", startScript);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
JPanel effects = new JPanel();
|
|
||||||
effects.setLayout(new GridBagLayout());
|
|
||||||
constraint.gridx = 0;
|
|
||||||
constraint.gridy = 0;
|
|
||||||
constraint.gridwidth = 1;
|
|
||||||
constraint.gridheight = 1;
|
|
||||||
|
|
||||||
etherealOffset = addSpinner(effects, "Ethereal Voice Offset", 0, 2000, 10, getInteger("effects.ethereal.offset"), "ms");
|
|
||||||
etherealIterations = addSpinner(effects, "Ethereal Voice Iterations", 1, 10, 1, getInteger("effects.ethereal.iterations"), "");
|
|
||||||
etherealAttenuation = addSpinner(effects, "Ethereal Voice Attenuation", 0, 100, 1, getInteger("effects.ethereal.attenuation"), "%");
|
|
||||||
|
|
||||||
tabs.add("Effects", effects);
|
|
||||||
|
|
||||||
|
|
||||||
JPanel processors = new JPanel();
|
JPanel processors = new JPanel();
|
||||||
processors.setLayout(new BorderLayout());
|
processors.setLayout(new BorderLayout());
|
||||||
@@ -398,19 +440,16 @@ public class Options extends JDialog {
|
|||||||
String command = get("editor.processor." + i + ".command");
|
String command = get("editor.processor." + i + ".command");
|
||||||
if (name == null || command == null) break;
|
if (name == null || command == null) break;
|
||||||
if (name.equals("") || command.equals("")) break;
|
if (name.equals("") || command.equals("")) break;
|
||||||
JTextField[] f = addTwoField(processorListPanel, name, command);
|
JTextField[] f = addTwoField(processorListPanel, name, command, "Specify the name of the operation (which will appear in context menus) and the command to run for that operation. The command should have parameters separated with :: and %f for the input filename and %o for the output filename.");
|
||||||
processorList.add(f);
|
processorList.add(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
JTextField[] f = addTwoField(processorListPanel, "", "");
|
JTextField[] f = addTwoField(processorListPanel, "", "", "Specify the name of the operation (which will appear in context menus) and the command to run for that operation. The command should have parameters separated with :: and %f for the input filename and %o for the output filename.");
|
||||||
processorList.add(f);
|
processorList.add(f);
|
||||||
|
|
||||||
tabs.add("Processors", processors);
|
tabs.add("Processors", processors);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add(tabs, BorderLayout.CENTER);
|
add(tabs, BorderLayout.CENTER);
|
||||||
|
|
||||||
setTitle("Options");
|
setTitle("Options");
|
||||||
@@ -457,49 +496,37 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static KVPair<String, String>[] getRecordingMixerList() {
|
static KVPair<String, String>[] getRecordingMixerList() {
|
||||||
TreeSet<KVPair<String, String>> list = new TreeSet<KVPair<String, String>>();
|
return getMixerList(TargetDataLine.class);
|
||||||
|
|
||||||
AudioFormat stereoFormat = new AudioFormat(44100f, 16, 2, true, false);
|
|
||||||
AudioFormat monoFormat = new AudioFormat(44100f, 16, 1, true, false);
|
|
||||||
|
|
||||||
DataLine.Info stereoDIF = new DataLine.Info(TargetDataLine.class, stereoFormat);
|
|
||||||
DataLine.Info monoDIF = new DataLine.Info(TargetDataLine.class, monoFormat);
|
|
||||||
|
|
||||||
Mixer.Info[] info = AudioSystem.getMixerInfo();
|
|
||||||
for (Mixer.Info i : info) {
|
|
||||||
Mixer m = AudioSystem.getMixer(i);
|
|
||||||
|
|
||||||
boolean supported = false;
|
|
||||||
|
|
||||||
try {
|
|
||||||
m.getLine(stereoDIF);
|
|
||||||
supported = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
m.getLine(monoDIF);
|
|
||||||
supported = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
if (supported) {
|
|
||||||
KVPair<String, String> p = new KVPair<String, String>(i.getName(), i.getName()); //i.getDescription());
|
|
||||||
list.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return list.toArray(new KVPair[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static KVPair[] getPlaybackMixerList() {
|
static KVPair[] getPlaybackMixerList() {
|
||||||
TreeSet<KVPair<String, String>> list = new TreeSet<KVPair<String, String>>();
|
return getMixerList(SourceDataLine.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
static KVPair[] getMixerList(Class<?> cl) {
|
||||||
|
ArrayList<KVPair<String, String>> list = new ArrayList<KVPair<String, String>>();
|
||||||
|
|
||||||
AudioFormat stereoFormat = new AudioFormat(44100f, 16, 2, true, false);
|
AudioFormat stereoFormat = new AudioFormat(44100f, 16, 2, true, false);
|
||||||
AudioFormat monoFormat = new AudioFormat(44100f, 16, 1, true, false);
|
AudioFormat monoFormat = new AudioFormat(44100f, 16, 1, true, false);
|
||||||
|
|
||||||
DataLine.Info stereoDIF = new DataLine.Info(SourceDataLine.class, stereoFormat);
|
ArrayList<AudioFormat> validFormats = new ArrayList<AudioFormat>();
|
||||||
DataLine.Info monoDIF = new DataLine.Info(SourceDataLine.class, monoFormat);
|
|
||||||
|
validFormats.add(new AudioFormat(44100f, 16, 1, true, false));
|
||||||
|
validFormats.add(new AudioFormat(44100f, 16, 2, true, false));
|
||||||
|
validFormats.add(new AudioFormat(44100f, 24, 1, true, false));
|
||||||
|
validFormats.add(new AudioFormat(44100f, 24, 2, true, false));
|
||||||
|
validFormats.add(new AudioFormat(48000f, 16, 1, true, false));
|
||||||
|
validFormats.add(new AudioFormat(48000f, 16, 2, true, false));
|
||||||
|
validFormats.add(new AudioFormat(48000f, 24, 1, true, false));
|
||||||
|
validFormats.add(new AudioFormat(48000f, 24, 2, true, false));
|
||||||
|
validFormats.add(new AudioFormat(96000f, 16, 1, true, false));
|
||||||
|
validFormats.add(new AudioFormat(96000f, 16, 2, true, false));
|
||||||
|
validFormats.add(new AudioFormat(96000f, 24, 1, true, false));
|
||||||
|
validFormats.add(new AudioFormat(96000f, 24, 2, true, false));
|
||||||
|
validFormats.add(new AudioFormat(192000f, 16, 1, true, false));
|
||||||
|
validFormats.add(new AudioFormat(192000f, 16, 2, true, false));
|
||||||
|
validFormats.add(new AudioFormat(192000f, 24, 1, true, false));
|
||||||
|
validFormats.add(new AudioFormat(192000f, 24, 2, true, false));
|
||||||
|
|
||||||
Mixer.Info[] info = AudioSystem.getMixerInfo();
|
Mixer.Info[] info = AudioSystem.getMixerInfo();
|
||||||
for (Mixer.Info i : info) {
|
for (Mixer.Info i : info) {
|
||||||
@@ -507,19 +534,14 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
boolean supported = false;
|
boolean supported = false;
|
||||||
|
|
||||||
try {
|
for (AudioFormat valid : validFormats) {
|
||||||
m.getLine(stereoDIF);
|
try {
|
||||||
supported = true;
|
m.getLine(new DataLine.Info(cl, valid));
|
||||||
} catch (Exception e) {
|
supported = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
m.getLine(monoDIF);
|
|
||||||
supported = true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (supported) {
|
if (supported) {
|
||||||
KVPair<String, String> p = new KVPair<String, String>(i.getName(), i.getName()); //i.getDescription());
|
KVPair<String, String> p = new KVPair<String, String>(i.getName(), i.getName()); //i.getDescription());
|
||||||
list.add(p);
|
list.add(p);
|
||||||
@@ -537,10 +559,11 @@ public class Options extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static KVPair[] getSampleRateList() {
|
static KVPair[] getSampleRateList() {
|
||||||
KVPair[] l = new KVPair[3];
|
KVPair[] l = new KVPair[4];
|
||||||
l[0] = new KVPair<String, String>("44100", "44100");
|
l[0] = new KVPair<String, String>("44100", "44100");
|
||||||
l[1] = new KVPair<String, String>("48000", "48000");
|
l[1] = new KVPair<String, String>("48000", "48000");
|
||||||
l[2] = new KVPair<String, String>("96000", "96000");
|
l[2] = new KVPair<String, String>("96000", "96000");
|
||||||
|
l[3] = new KVPair<String, String>("192000", "192000");
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,6 +588,8 @@ public class Options extends JDialog {
|
|||||||
} else {
|
} else {
|
||||||
defaultPrefs.put("audio.playback.device", "");
|
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.pre-chapter", "1000");
|
||||||
defaultPrefs.put("catenation.post-chapter", "1500");
|
defaultPrefs.put("catenation.post-chapter", "1500");
|
||||||
@@ -574,14 +599,18 @@ public class Options extends JDialog {
|
|||||||
defaultPrefs.put("catenation.post-section", "3000");
|
defaultPrefs.put("catenation.post-section", "3000");
|
||||||
|
|
||||||
defaultPrefs.put("audio.recording.trim.fft", "10");
|
defaultPrefs.put("audio.recording.trim.fft", "10");
|
||||||
|
defaultPrefs.put("audio.recording.variance", "10");
|
||||||
|
|
||||||
defaultPrefs.put("path.storage", (new File(System.getProperty("user.home"), "Recordings")).toString());
|
defaultPrefs.put("path.storage", (new File(System.getProperty("user.home"), "Recordings")).toString());
|
||||||
defaultPrefs.put("path.archive", (new File(new File(System.getProperty("user.home"), "Recordings"),"archive")).toString());
|
defaultPrefs.put("path.archive", (new File(new File(System.getProperty("user.home"), "Recordings"),"archive")).toString());
|
||||||
defaultPrefs.put("path.ffmpeg", "");
|
defaultPrefs.put("path.ffmpeg", "");
|
||||||
|
|
||||||
defaultPrefs.put("audio.export.bitrate", "256000");
|
defaultPrefs.put("audio.export.bitrate", "256000");
|
||||||
|
defaultPrefs.put("audio.export.channels", "2");
|
||||||
defaultPrefs.put("audio.export.samplerate", "44100");
|
defaultPrefs.put("audio.export.samplerate", "44100");
|
||||||
defaultPrefs.put("process.sphinx", "false");
|
defaultPrefs.put("process.sphinx", "false");
|
||||||
|
defaultPrefs.put("process.command", "speech-to-text \"%f\"");
|
||||||
|
defaultPrefs.put("process.threads", "10");
|
||||||
|
|
||||||
defaultPrefs.put("editor.external", "");
|
defaultPrefs.put("editor.external", "");
|
||||||
|
|
||||||
@@ -589,10 +618,6 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
defaultPrefs.put("scripts.startup", "");
|
defaultPrefs.put("scripts.startup", "");
|
||||||
|
|
||||||
defaultPrefs.put("effects.ethereal.offset", "50");
|
|
||||||
defaultPrefs.put("effects.ethereal.iterations", "3");
|
|
||||||
defaultPrefs.put("effects.ethereal.attenuation", "50");
|
|
||||||
|
|
||||||
if (prefs == null) {
|
if (prefs == null) {
|
||||||
prefs = Preferences.userNodeForPackage(AudiobookRecorder.class);
|
prefs = Preferences.userNodeForPackage(AudiobookRecorder.class);
|
||||||
}
|
}
|
||||||
@@ -682,17 +707,17 @@ public class Options extends JDialog {
|
|||||||
} else if (value instanceof Boolean) {
|
} else if (value instanceof Boolean) {
|
||||||
set(key, (Boolean)value);
|
set(key, (Boolean)value);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("Bad type for key " + key);
|
Debug.d("Bad type for key", key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void storePreferences() {
|
void storePreferences() {
|
||||||
set("audio.recording.device", ((KVPair)mixerList.getSelectedItem()).key);
|
if (mixerList.getSelectedItem() != null) set("audio.recording.device", ((KVPair)mixerList.getSelectedItem()).key);
|
||||||
set("audio.recording.channels", ((KVPair)channelList.getSelectedItem()).key);
|
if (channelList.getSelectedItem() != null) set("audio.recording.channels", ((KVPair)channelList.getSelectedItem()).key);
|
||||||
set("audio.recording.samplerate", ((KVPair)rateList.getSelectedItem()).key);
|
if (rateList.getSelectedItem() != null) set("audio.recording.samplerate", ((KVPair)rateList.getSelectedItem()).key);
|
||||||
set("audio.recording.resolution", ((KVPair)bitDepth.getSelectedItem()).key);
|
if (bitDepth.getSelectedItem() != null) set("audio.recording.resolution", ((KVPair)bitDepth.getSelectedItem()).key);
|
||||||
set("audio.recording.trim", ((KVPair)trimMethod.getSelectedItem()).key);
|
if (trimMethod.getSelectedItem() != null) set("audio.recording.trim", ((KVPair)trimMethod.getSelectedItem()).key);
|
||||||
set("audio.playback.device", ((KVPair)playbackList.getSelectedItem()).key);
|
if (playbackList.getSelectedItem() != null) set("audio.playback.device", ((KVPair)playbackList.getSelectedItem()).key);
|
||||||
set("path.storage", storageFolder.getText());
|
set("path.storage", storageFolder.getText());
|
||||||
set("path.archive", archiveFolder.getText());
|
set("path.archive", archiveFolder.getText());
|
||||||
set("path.ffmpeg", ffmpegLocation.getText());
|
set("path.ffmpeg", ffmpegLocation.getText());
|
||||||
@@ -702,16 +727,18 @@ public class Options extends JDialog {
|
|||||||
set("catenation.short-sentence", shortSentenceGap.getValue());
|
set("catenation.short-sentence", shortSentenceGap.getValue());
|
||||||
set("catenation.post-paragraph", postParagraphGap.getValue());
|
set("catenation.post-paragraph", postParagraphGap.getValue());
|
||||||
set("catenation.post-section", postSectionGap.getValue());
|
set("catenation.post-section", postSectionGap.getValue());
|
||||||
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
if (bitRate.getSelectedItem() != null) set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
||||||
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
if (channels.getSelectedItem() != null) set("audio.export.channels", ((KVPair)channels.getSelectedItem()).key);
|
||||||
|
if (exportRate.getSelectedItem() != null) set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
||||||
set("process.sphinx", enableParsing.isSelected());
|
set("process.sphinx", enableParsing.isSelected());
|
||||||
|
set("process.command", speechCommand.getText());
|
||||||
|
set("process.threads", workerThreads.getValue());
|
||||||
set("editor.external", externalEditor.getText());
|
set("editor.external", externalEditor.getText());
|
||||||
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.variance", maxGainVariance.getValue());
|
||||||
set("effects.ethereal.offset", etherealOffset.getValue());
|
if (fftBlockSize.getSelectedItem() != null) set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.getSelectedItem()).key);
|
||||||
set("effects.ethereal.iterations", etherealIterations.getValue());
|
if (playbackBlockSize.getSelectedItem() != null) set("audio.playback.blocksize", ((KVPair)playbackBlockSize.getSelectedItem()).key);
|
||||||
set("effects.ethereal.attenuation", etherealAttenuation.getValue());
|
|
||||||
|
|
||||||
set("scripts.startup", startupScript.getText());
|
set("scripts.startup", startupScript.getText());
|
||||||
|
|
||||||
@@ -768,9 +795,10 @@ public class Options extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static KVPair[] getResolutionList() {
|
public static KVPair[] getResolutionList() {
|
||||||
KVPair[] pairs = new KVPair[2];
|
KVPair[] pairs = new KVPair[3];
|
||||||
pairs[0] = new KVPair<String, String>("16", "16 Bit");
|
pairs[0] = new KVPair<String, String>("16", "16 Bit");
|
||||||
pairs[1] = new KVPair<String, String>("24", "24 Bit");
|
pairs[1] = new KVPair<String, String>("24", "24 Bit");
|
||||||
|
pairs[2] = new KVPair<String, String>("32", "32 Bit");
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -782,51 +810,29 @@ public class Options extends JDialog {
|
|||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static KVPair[] getFFTBlockSizes() {
|
||||||
|
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 KVPair[] getPlaybackBlockSizes() {
|
||||||
effectChains = new ArrayList<EffectGroup>();
|
KVPair[] pairs = new KVPair[8];
|
||||||
|
pairs[0] = new KVPair<String, String>("1024", "1024");
|
||||||
for (int i = 0; i < 999999; i++) {
|
pairs[1] = new KVPair<String, String>("2048", "2048");
|
||||||
if (get("effects." + i + ".name") == null) {
|
pairs[2] = new KVPair<String, String>("4096", "4096");
|
||||||
EffectGroup e = new EffectGroup(get("effects." + i + ".name"));
|
pairs[3] = new KVPair<String, String>("8192", "8192");
|
||||||
for (int j = 0; i < 999999; j++) {
|
pairs[4] = new KVPair<String, String>("16384", "16384");
|
||||||
String type = get("effects." + i + ".children." + j + ".type");
|
pairs[5] = new KVPair<String, String>("32768", "32768");
|
||||||
if (type == null) break;
|
pairs[6] = new KVPair<String, String>("65536", "65537");
|
||||||
|
pairs[7] = new KVPair<String, String>("131072", "131072");
|
||||||
if (type.equals("biquad")) {
|
return pairs;
|
||||||
int bqt = getInteger("effects." + i + ".children." + j + ".filtertype");
|
|
||||||
double fc = getDouble("effects." + i + ".children." + j + ".fc");
|
|
||||||
double q = getDouble("effects." + i + ".children." + j + ".q");
|
|
||||||
double gain = getDouble("effects." + i + ".children." + j + ".gain");
|
|
||||||
Biquad b = new Biquad(bqt, fc, q, gain);
|
|
||||||
e.addEffect(b);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.equals("amplifier")) {
|
|
||||||
double gain = getDouble("effects." + i + ".children." + j + ".gain");
|
|
||||||
Amplifier a = new Amplifier(gain);
|
|
||||||
e.addEffect(a);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (type.equals("delayline")) {
|
|
||||||
DelayLine l = new DelayLine();
|
|
||||||
for (int c = 0; c < 999999; c++) {
|
|
||||||
if (get("effects." + i + ".children." + j + ".lines." + c + ".samples") == null) break;
|
|
||||||
int samples = getInteger("effects." + i + ".children." + j + ".lines." + c + ".samples");
|
|
||||||
double gain = getDouble("effects." + i + ".children." + j + ".lines." + c + ".gain");
|
|
||||||
l.addDelayLine(samples, gain);
|
|
||||||
}
|
|
||||||
e.addEffect(l);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
effectChains.add(e);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,3 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2015, Majenko Technologies
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
|
||||||
* are permitted provided that the following conditions are met:
|
|
||||||
*
|
|
||||||
* * Redistributions of source code must retain the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer.
|
|
||||||
*
|
|
||||||
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
||||||
* list of conditions and the following disclaimer in the documentation and/or
|
|
||||||
* other materials provided with the distribution.
|
|
||||||
*
|
|
||||||
* * Neither the name of Majenko Technologies nor the names of its
|
|
||||||
* contributors may be used to endorse or promote products derived from
|
|
||||||
* this software without specific prior written permission.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
||||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
||||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
||||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
||||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
||||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.ImageIcon;
|
||||||
|
|
||||||
public class Overlays {
|
public class Overlays {
|
||||||
static public final ImageIcon locked = new ImageIcon(Overlays.class.getResource("overlays/locked.png"));
|
static public final ImageIcon locked = new ImageIcon(Overlays.class.getResource("overlays/locked.png"));
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ public class Pan implements Effect {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process(double[][] samples) {
|
public void process(double[][] samples) {
|
||||||
for (double[] sample : samples) {
|
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||||
if (pan < 0) {
|
if (pan < 0) {
|
||||||
double p = 1 + pan;
|
double p = 1 + pan;
|
||||||
sample[Sentence.RIGHT] *= p;
|
samples[Sentence.RIGHT][i] *= p;
|
||||||
} else {
|
} else {
|
||||||
double p = 1 - pan;
|
double p = 1 - pan;
|
||||||
sample[Sentence.LEFT] *= p;
|
samples[Sentence.LEFT][i] *= p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.JDialog;
|
||||||
import javax.swing.event.*;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.border.*;
|
import javax.swing.JProgressBar;
|
||||||
import java.awt.*;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.event.*;
|
import it.sauronsoftware.jave.MultimediaInfo;
|
||||||
import java.util.*;
|
import it.sauronsoftware.jave.EncoderProgressListener;
|
||||||
import it.sauronsoftware.jave.*;
|
import java.awt.Dialog;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
public class ProgressDialog extends JDialog implements EncoderProgressListener {
|
public class ProgressDialog extends JDialog implements EncoderProgressListener {
|
||||||
JLabel message;
|
JLabel message;
|
||||||
|
|||||||
110
src/uk/co/majenko/audiobookrecorder/QueueMonitor.java
Normal file
110
src/uk/co/majenko/audiobookrecorder/QueueMonitor.java
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
|
||||||
|
public class QueueMonitor extends JPanel implements MouseListener {
|
||||||
|
|
||||||
|
ArrayList<WorkerThread> threadList = new ArrayList<WorkerThread>();
|
||||||
|
Queue<Runnable> queue;
|
||||||
|
|
||||||
|
public QueueMonitor(Queue<Runnable> q) {
|
||||||
|
super();
|
||||||
|
queue = q;
|
||||||
|
addMouseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addThread(WorkerThread t) {
|
||||||
|
threadList.add(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void purgeQueue() {
|
||||||
|
Runnable work;
|
||||||
|
synchronized (queue) {
|
||||||
|
while (queue.size() > 0) {
|
||||||
|
work = queue.remove();
|
||||||
|
if (work instanceof SentenceJob) {
|
||||||
|
SentenceJob sj = (SentenceJob)work;
|
||||||
|
sj.setDequeued();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return new Dimension(150 + (24 * threadList.size()), 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMinimumSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dimension getMaximumSize() {
|
||||||
|
return getPreferredSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
Rectangle size = g.getClipBounds();
|
||||||
|
g.setColor(getBackground());
|
||||||
|
g.fillRect(0, 0, size.width - 1, size.height - 1);
|
||||||
|
g.setColor(new Color(10, 10, 10));
|
||||||
|
g.drawRect(0, 0, size.width - 1, size.height - 1);
|
||||||
|
g.setFont(getFont());
|
||||||
|
|
||||||
|
for (int i = 0; i < threadList.size(); i++) {
|
||||||
|
WorkerThread t = threadList.get(i);
|
||||||
|
if (t.isRunning()) {
|
||||||
|
g.setColor(new Color(50, 200, 0));
|
||||||
|
} else {
|
||||||
|
g.setColor(new Color(80, 0, 0));
|
||||||
|
}
|
||||||
|
g.fillOval(i * 24 + 4, 4, 22 - 8, 22 - 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
g.setColor(getForeground());
|
||||||
|
g.drawString("Queued: " + queue.size(), threadList.size() * 24 + 4, 16);
|
||||||
|
|
||||||
|
if (queue.size() > 0) {
|
||||||
|
Icons.close.paintIcon(this, g, size.width - 23, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseEntered(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mousePressed(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseReleased(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent evt) {
|
||||||
|
if (queue.size() == 0) return; // No button - ignore it
|
||||||
|
Dimension size = getPreferredSize();
|
||||||
|
if (evt.getX() > (size.width - 24)) {
|
||||||
|
purgeQueue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
File diff suppressed because it is too large
Load Diff
17
src/uk/co/majenko/audiobookrecorder/SentenceExternalJob.java
Normal file
17
src/uk/co/majenko/audiobookrecorder/SentenceExternalJob.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.lang.Runnable;
|
||||||
|
|
||||||
|
public class SentenceExternalJob extends SentenceJob {
|
||||||
|
protected int command;
|
||||||
|
|
||||||
|
public SentenceExternalJob(Sentence s, int c) {
|
||||||
|
super(s);
|
||||||
|
command = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
sentence.runExternalProcessor(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/uk/co/majenko/audiobookrecorder/SentenceJob.java
Normal file
25
src/uk/co/majenko/audiobookrecorder/SentenceJob.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.lang.Runnable;
|
||||||
|
|
||||||
|
public abstract class SentenceJob implements Runnable {
|
||||||
|
protected Sentence sentence;
|
||||||
|
|
||||||
|
public SentenceJob(Sentence s) {
|
||||||
|
sentence = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQueued() {
|
||||||
|
sentence.setQueued();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDequeued() {
|
||||||
|
sentence.setDequeued();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProcessing() {
|
||||||
|
sentence.setProcessing();
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void run();
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import java.util.*;
|
import javax.swing.SpinnerModel;
|
||||||
import javax.swing.*;
|
import java.util.ArrayList;
|
||||||
import javax.swing.event.*;
|
import javax.swing.event.ChangeListener;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
|
||||||
public class SteppedNumericSpinnerModel implements SpinnerModel {
|
public class SteppedNumericSpinnerModel implements SpinnerModel {
|
||||||
int min;
|
int min;
|
||||||
|
|||||||
115
src/uk/co/majenko/audiobookrecorder/Tip.java
Normal file
115
src/uk/co/majenko/audiobookrecorder/Tip.java
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JToolTip;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Rectangle2D;
|
||||||
|
import java.awt.font.FontRenderContext;
|
||||||
|
import java.awt.FontMetrics;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import org.apache.commons.text.WordUtils;
|
||||||
|
|
||||||
|
public class Tip extends JLabel implements MouseListener {
|
||||||
|
String tip = null;
|
||||||
|
|
||||||
|
public Tip(String text) {
|
||||||
|
tip = WordUtils.wrap(text, 50);
|
||||||
|
|
||||||
|
setToolTipText(text);
|
||||||
|
setIcon(Icons.tooltip);
|
||||||
|
addMouseListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JToolTip createToolTip() {
|
||||||
|
JToolTip tt = new JToolTip() {
|
||||||
|
public String getTipText() {
|
||||||
|
return "*" + tip + "*";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
|
||||||
|
Rectangle r = g.getClipBounds();
|
||||||
|
|
||||||
|
JLabel l = new JLabel();
|
||||||
|
|
||||||
|
AffineTransform affinetransform = new AffineTransform();
|
||||||
|
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);
|
||||||
|
Font f = l.getFont().deriveFont(14f);
|
||||||
|
|
||||||
|
g.setColor(new Color(200, 200, 180));
|
||||||
|
g.fillRect(0, 0, r.width, r.height);
|
||||||
|
|
||||||
|
g.setColor(new Color(10, 10, 10));
|
||||||
|
g.setFont(f);
|
||||||
|
int y = 3;
|
||||||
|
String[] lines = tip.split("\n");
|
||||||
|
for (String line : lines) {
|
||||||
|
Rectangle2D bounds = f.getStringBounds(line, frc);
|
||||||
|
y += bounds.getHeight();
|
||||||
|
g.drawString(line, 5, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
|
||||||
|
JLabel l = new JLabel();
|
||||||
|
AffineTransform affinetransform = new AffineTransform();
|
||||||
|
FontRenderContext frc = new FontRenderContext(affinetransform,true,true);
|
||||||
|
Font f = l.getFont().deriveFont(14f);
|
||||||
|
|
||||||
|
String[] lines = tip.split("\n");
|
||||||
|
int w = 0;
|
||||||
|
int h = 0;
|
||||||
|
for (String line : lines) {
|
||||||
|
Rectangle2D bounds = f.getStringBounds(line, frc);
|
||||||
|
double fw = bounds.getWidth();
|
||||||
|
if (fw > w) w = (int)fw;
|
||||||
|
h += bounds.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
Dimension s = new Dimension(w + 10, h + 10);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
tt.removeAll();
|
||||||
|
JPanel p = new JPanel();
|
||||||
|
tt.add(p);
|
||||||
|
JLabel l = new JLabel(tip);
|
||||||
|
l.setBackground(new Color(200, 200, 180));
|
||||||
|
l.setForeground(new Color(0, 0, 0));
|
||||||
|
p.add(l);
|
||||||
|
return tt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseEntered(MouseEvent evt) {
|
||||||
|
// showTipWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseExited(MouseEvent evt) {
|
||||||
|
// hideTipWindow();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mousePressed(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseClicked(MouseEvent evt) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.text.SimpleDateFormat;
|
||||||
import javax.swing.event.*;
|
import java.awt.Image;
|
||||||
import java.awt.*;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.event.*;
|
import java.awt.RenderingHints;
|
||||||
import java.awt.image.*;
|
import java.net.URI;
|
||||||
import javax.swing.border.*;
|
import java.awt.Graphics2D;
|
||||||
import java.util.*;
|
import java.awt.Desktop;
|
||||||
import java.io.*;
|
import java.util.Date;
|
||||||
import java.net.*;
|
import java.util.TimeZone;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static Image getScaledImage(Image srcImg, int w, int h){
|
public static Image getScaledImage(Image srcImg, int w, int h){
|
||||||
@@ -70,10 +73,63 @@ public class Utils {
|
|||||||
long t = System.currentTimeMillis();
|
long t = System.currentTimeMillis();
|
||||||
long d = t - millis;
|
long d = t - millis;
|
||||||
millis = t;
|
millis = t;
|
||||||
System.err.println(String.format("%10d - %10s : %8d | %8d | %8d", d, tag,
|
Debug.d(String.format("%10d - %10s : %8d | %8d | %8d", d, tag,
|
||||||
Runtime.getRuntime().totalMemory(),
|
Runtime.getRuntime().totalMemory(),
|
||||||
Runtime.getRuntime().maxMemory(),
|
Runtime.getRuntime().maxMemory(),
|
||||||
Runtime.getRuntime().freeMemory()
|
Runtime.getRuntime().freeMemory()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String secToTime(double sec, String fmt) {
|
||||||
|
Date d = new Date((long)(sec * 1000d));
|
||||||
|
SimpleDateFormat df = new SimpleDateFormat(fmt);
|
||||||
|
df.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
|
String time = df.format(d);
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double[] stereoToMono(double[][] in) {
|
||||||
|
double[] out = new double[in[Sentence.LEFT].length];
|
||||||
|
|
||||||
|
for (int i = 0; i < in[Sentence.LEFT].length; i++) {
|
||||||
|
out[i] = mix(in[Sentence.LEFT][i], in[Sentence.RIGHT][i]);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double mix(double a, double b) {
|
||||||
|
double out;
|
||||||
|
|
||||||
|
if ((a < 0) && (b < 0)) {
|
||||||
|
out = (a + b) - (a * b);
|
||||||
|
} else if ((a > 0) && (b > 0)) {
|
||||||
|
out = (a + b) - (a * b);
|
||||||
|
} else {
|
||||||
|
out = a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void copyFolder(File from, File to) throws IOException {
|
||||||
|
File[] files = from.listFiles();
|
||||||
|
|
||||||
|
for (File source : files) {
|
||||||
|
File destination = new File(to, source.getName());
|
||||||
|
if (destination.exists()) {
|
||||||
|
if (!destination.isDirectory()) {
|
||||||
|
destination.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (source.isDirectory()) {
|
||||||
|
if (!destination.exists()) {
|
||||||
|
destination.mkdirs();
|
||||||
|
}
|
||||||
|
copyFolder(source, destination);
|
||||||
|
} else {
|
||||||
|
Files.copy(source.toPath(), destination.toPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
73
src/uk/co/majenko/audiobookrecorder/VersionChecker.java
Normal file
73
src/uk/co/majenko/audiobookrecorder/VersionChecker.java
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.lang.Runnable;
|
||||||
|
import java.net.URL;
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import javax.swing.JButton;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
|
public class VersionChecker implements Runnable {
|
||||||
|
public VersionChecker() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
URL url = new URL("https://api.github.com/repos/MajenkoProjects/AudiobookRecorder/releases/latest");
|
||||||
|
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
|
||||||
|
InputStream is = conn.getInputStream();
|
||||||
|
InputStreamReader isr = new InputStreamReader(is);
|
||||||
|
BufferedReader br = new BufferedReader(isr);
|
||||||
|
|
||||||
|
String inputLine;
|
||||||
|
StringBuilder jsonData = new StringBuilder();
|
||||||
|
|
||||||
|
while ((inputLine = br.readLine()) != null) {
|
||||||
|
jsonData.append(inputLine);
|
||||||
|
}
|
||||||
|
|
||||||
|
br.close();
|
||||||
|
|
||||||
|
JSONObject job = new JSONObject(jsonData.toString());
|
||||||
|
|
||||||
|
String installed = AudiobookRecorder.config.getProperty("version");
|
||||||
|
String available = job.getString("tag_name");
|
||||||
|
if (available.startsWith("v")) {
|
||||||
|
available = available.substring(1);
|
||||||
|
}
|
||||||
|
String website = job.getString("html_url");
|
||||||
|
|
||||||
|
|
||||||
|
String[] installedParts = installed.split("\\.");
|
||||||
|
String[] availableParts = available.split("\\.");
|
||||||
|
// Must be x.y.z
|
||||||
|
|
||||||
|
if (installedParts.length != 3) return;
|
||||||
|
if (availableParts.length != 3) return;
|
||||||
|
|
||||||
|
// Convert to xxxyyyzzz
|
||||||
|
String installedVersion = String.format("%03d%03d%03d", Utils.s2i(installedParts[0]), Utils.s2i(installedParts[1]), Utils.s2i(installedParts[2]));
|
||||||
|
String availableVersion = String.format("%03d%03d%03d", Utils.s2i(availableParts[0]), Utils.s2i(availableParts[1]), Utils.s2i(availableParts[2]));
|
||||||
|
|
||||||
|
if (Utils.s2i(installedVersion) >= Utils.s2i(availableVersion)) return;
|
||||||
|
|
||||||
|
JButton upgrade = new JButton("A new version is available.");
|
||||||
|
upgrade.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
Utils.browse(website);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AudiobookRecorder.window.statusBar.add(upgrade);
|
||||||
|
AudiobookRecorder.window.statusBar.revalidate();
|
||||||
|
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
ignored.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +1,21 @@
|
|||||||
package uk.co.majenko.audiobookrecorder;
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.awt.event.MouseListener;
|
||||||
import java.awt.*;
|
import java.awt.event.MouseMotionListener;
|
||||||
import java.awt.event.*;
|
import java.awt.event.MouseWheelListener;
|
||||||
import java.util.*;
|
import javax.swing.JPanel;
|
||||||
import java.io.*;
|
import java.util.TreeMap;
|
||||||
import javax.sound.sampled.*;
|
import java.util.ArrayList;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseWheelEvent;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Cursor;
|
||||||
|
|
||||||
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
public class Waveform extends JPanel implements MouseListener, MouseMotionListener, MouseWheelListener {
|
||||||
|
|
||||||
double[][] samples = null;
|
Sentence sentence = null;
|
||||||
|
|
||||||
int leftMarker = 0;
|
int leftMarker = 0;
|
||||||
int rightMarker = 0;
|
int rightMarker = 0;
|
||||||
@@ -26,6 +32,8 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
boolean displayCut = false;
|
boolean displayCut = false;
|
||||||
boolean displaySplit = false;
|
boolean displaySplit = false;
|
||||||
|
|
||||||
|
boolean displayGainCurve = false;
|
||||||
|
|
||||||
int dragging = 0;
|
int dragging = 0;
|
||||||
|
|
||||||
int step = 1;
|
int step = 1;
|
||||||
@@ -34,19 +42,31 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
int offsetFactor = 0;
|
int offsetFactor = 0;
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
|
|
||||||
ArrayList<MarkerDragListener> markerDragListeners;
|
String loadedId = null;
|
||||||
|
|
||||||
public Waveform() {
|
public Waveform() {
|
||||||
super();
|
super();
|
||||||
addMouseListener(this);
|
addMouseListener(this);
|
||||||
addMouseMotionListener(this);
|
addMouseMotionListener(this);
|
||||||
markerDragListeners = new ArrayList<MarkerDragListener>();
|
addMouseWheelListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMarkerDragListener(MarkerDragListener l) {
|
public void setSentence(Sentence s) {
|
||||||
if (markerDragListeners.indexOf(l) == -1) {
|
sentence = s;
|
||||||
markerDragListeners.add(l);
|
playMarker = 0;
|
||||||
|
displayCut = false;
|
||||||
|
displaySplit = false;
|
||||||
|
updateMarkers();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateMarkers() {
|
||||||
|
if (sentence != null) {
|
||||||
|
leftMarker = sentence.getStartOffset();
|
||||||
|
rightMarker = sentence.getEndOffset();
|
||||||
|
leftAltMarker = sentence.getStartCrossing();
|
||||||
|
rightAltMarker = sentence.getEndCrossing();
|
||||||
}
|
}
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
@@ -77,9 +97,10 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
|
|
||||||
double scale = (h/2);
|
double scale = (h/2);
|
||||||
|
|
||||||
if (samples != null) {
|
if (sentence != null) {
|
||||||
|
double[][] samples = sentence.getDoubleAudioData(true);
|
||||||
|
|
||||||
int num = samples.length;
|
int num = samples[Sentence.LEFT].length;
|
||||||
step = num / zoomFactor / w;
|
step = num / zoomFactor / w;
|
||||||
if (step == 0) return;
|
if (step == 0) return;
|
||||||
|
|
||||||
@@ -97,7 +118,8 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
double lmax = 0;
|
double lmax = 0;
|
||||||
|
|
||||||
for (int o = 0; o < step; o++) {
|
for (int o = 0; o < step; o++) {
|
||||||
double sample = (samples[offset + (n * step) + o][Sentence.LEFT] + samples[offset + (n * step) + o][Sentence.RIGHT]) / 2d;
|
if (offset + (n * step) + o >= samples[Sentence.LEFT].length) break;
|
||||||
|
double sample = (samples[Sentence.LEFT][offset + (n * step) + o] + samples[Sentence.RIGHT][offset + (n * step) + o]) / 2d;
|
||||||
if (sample >= 0) {
|
if (sample >= 0) {
|
||||||
have += sample;
|
have += sample;
|
||||||
hcnt++;
|
hcnt++;
|
||||||
@@ -167,51 +189,30 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
for (int i = 0; i < h; i += 2) {
|
for (int i = 0; i < h; i += 2) {
|
||||||
g.drawLine((playMarker - offset) / step, i, (playMarker - offset) / step, i);
|
g.drawLine((playMarker - offset) / step, i, (playMarker - offset) / step, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (displayGainCurve) {
|
||||||
|
int x1 = 0;
|
||||||
|
double y1 = 1.0;
|
||||||
|
g.setColor(new Color(200, 200, 200));
|
||||||
|
TreeMap<Integer, Double> points = sentence.getGainPoints();
|
||||||
|
for (Integer loc : points.keySet()) {
|
||||||
|
int x2 = loc;
|
||||||
|
double y2 = points.get(loc);
|
||||||
|
|
||||||
|
g.fillRect((x1 - offset) / step - 1, h - (int)((double)h / 2.0 * y1) - 1, 3, 3);
|
||||||
|
|
||||||
|
g.drawLine((x1 - offset) / step, h - (int)((double)h / 2.0 * y1), (x2 - offset) / step, h - (int)((double)h / 2.0 * y2));
|
||||||
|
x1 = x2;
|
||||||
|
y1 = y2;
|
||||||
|
}
|
||||||
|
g.fillRect((x1 - offset) / step - 1, h - (int)((double)h / 2.0 * y1) - 1, 3, 3);
|
||||||
|
g.drawLine((x1 - offset) / step, h - (int)((double)h / 2.0 * y1), (num - offset) / step, h - (int)((double)h / 2.0 * y1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAltMarkers(int l, int r) {
|
public void setDisplayGainCurve(boolean b) {
|
||||||
leftAltMarker = l;
|
displayGainCurve = b;
|
||||||
rightAltMarker = r;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setMarkers(int l, int r) {
|
|
||||||
leftMarker = l;
|
|
||||||
rightMarker = r;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLeftAltMarker(int l) {
|
|
||||||
leftAltMarker = l;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRightAltMarker(int r) {
|
|
||||||
rightAltMarker = r;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLeftMarker(int l) {
|
|
||||||
leftMarker = l;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRightMarker(int r) {
|
|
||||||
rightMarker = r;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clearData() {
|
|
||||||
samples = null;
|
|
||||||
repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(double[][] s) {
|
|
||||||
samples = s;
|
|
||||||
playMarker = 0;
|
|
||||||
displayCut = false;
|
|
||||||
displaySplit = false;
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,46 +259,118 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
|
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
if (dragging == 1) {
|
if (dragging == 1) {
|
||||||
MarkerDragEvent evt = new MarkerDragEvent(this, leftMarker);
|
sentence.setStartOffset(leftMarker);
|
||||||
for (MarkerDragListener l : markerDragListeners) {
|
sentence.updateCrossings();
|
||||||
l.leftMarkerMoved(evt);
|
updateMarkers();
|
||||||
}
|
|
||||||
} else if (dragging == 2) {
|
} else if (dragging == 2) {
|
||||||
MarkerDragEvent evt = new MarkerDragEvent(this, rightMarker);
|
sentence.setEndOffset(rightMarker);
|
||||||
for (MarkerDragListener l : markerDragListeners) {
|
sentence.updateCrossings();
|
||||||
l.rightMarkerMoved(evt);
|
updateMarkers();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dragging = 0;
|
dragging = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||||
|
if (sentence == null) return;
|
||||||
|
if (sentence.isLocked()) return;
|
||||||
|
|
||||||
|
if (displayGainCurve) {
|
||||||
|
int x = e.getX() * step + offset;
|
||||||
|
int f = -1;
|
||||||
|
int diff = Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
TreeMap<Integer, Double> gc = sentence.getGainPoints();
|
||||||
|
for (Integer loc : gc.keySet()) {
|
||||||
|
int d = Math.abs(loc - x);
|
||||||
|
if (d < diff) {
|
||||||
|
diff = d;
|
||||||
|
f = loc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (diff / step < 5) {
|
||||||
|
sentence.adjustGainPoint(f, (0 - e.getWheelRotation()) / 100d);
|
||||||
|
repaint();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int val = ((int)AudiobookRecorder.window.gainPercent.getValue()) - e.getWheelRotation();
|
||||||
|
if (val < 1) val = 1;
|
||||||
|
AudiobookRecorder.window.gainPercent.setValue(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
if (displayGainCurve) {
|
||||||
|
if (e.getButton() == MouseEvent.BUTTON1) {
|
||||||
|
Dimension size = getSize();
|
||||||
|
|
||||||
|
int w = size.width;
|
||||||
|
int h = size.height;
|
||||||
|
|
||||||
|
int x = e.getX() * step + offset;
|
||||||
|
double y = (double)(h - e.getY()) / (double)h * 2.0;
|
||||||
|
|
||||||
|
sentence.addGainPoint(x, y);
|
||||||
|
repaint();
|
||||||
|
} else if (e.getButton() == MouseEvent.BUTTON2) {
|
||||||
|
Dimension size = getSize();
|
||||||
|
|
||||||
|
int w = size.width;
|
||||||
|
int h = size.height;
|
||||||
|
|
||||||
|
int x = e.getX() * step + offset;
|
||||||
|
double y = 1.0d;
|
||||||
|
|
||||||
|
sentence.addGainPoint(x, y);
|
||||||
|
repaint();
|
||||||
|
} else if (e.getButton() == MouseEvent.BUTTON3) {
|
||||||
|
int x = e.getX() * step + offset;
|
||||||
|
int f = -1;
|
||||||
|
int diff = Integer.MAX_VALUE;
|
||||||
|
|
||||||
|
TreeMap<Integer, Double> gc = sentence.getGainPoints();
|
||||||
|
for (Integer loc : gc.keySet()) {
|
||||||
|
int d = Math.abs(loc - x);
|
||||||
|
if (d < diff) {
|
||||||
|
diff = d;
|
||||||
|
f = loc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sentence.removeGainPoint(f);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void mouseMoved(MouseEvent e) {
|
public void mouseMoved(MouseEvent e) {
|
||||||
int x = e.getX();
|
int x = e.getX();
|
||||||
if ((x >= ((leftMarker - offset)/step) - 10) && (x <= ((leftMarker - offset)/step) + 10)) {
|
int y = e.getY();
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ((x >= ((rightMarker - offset)/step) - 10) && (x <= ((rightMarker - offset)/step) + 10)) {
|
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (displayCut || displaySplit) {
|
|
||||||
if ((x >= ((cutEntry - offset)/step) - 10) && (x <= ((cutEntry - offset)/step) + 10)) {
|
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (displayCut) {
|
if (displayGainCurve) {
|
||||||
|
|
||||||
|
} else if (displayCut) {
|
||||||
if ((x >= ((cutExit - offset)/step) - 10) && (x <= ((cutExit - offset)/step) + 10)) {
|
if ((x >= ((cutExit - offset)/step) - 10) && (x <= ((cutExit - offset)/step) + 10)) {
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if ((x >= ((leftMarker - offset)/step) - 10) && (x <= ((leftMarker - offset)/step) + 10)) {
|
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ((x >= ((rightMarker - offset)/step) - 10) && (x <= ((rightMarker - offset)/step) + 10)) {
|
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (displayCut || displaySplit) {
|
||||||
|
if ((x >= ((cutEntry - offset)/step) - 10) && (x <= ((cutEntry - offset)/step) + 10)) {
|
||||||
|
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -386,4 +459,12 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
public int getCutEnd() {
|
public int getCutEnd() {
|
||||||
return cutExit;
|
return cutExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
loadedId = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return loadedId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
src/uk/co/majenko/audiobookrecorder/WorkerThread.java
Normal file
62
src/uk/co/majenko/audiobookrecorder/WorkerThread.java
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
|
public class WorkerThread extends Thread {
|
||||||
|
private static int instance = 0;
|
||||||
|
private final Queue<Runnable> queue;
|
||||||
|
private final QueueMonitor monitor;
|
||||||
|
|
||||||
|
private boolean running = false;
|
||||||
|
|
||||||
|
public WorkerThread(Queue<Runnable> queue, QueueMonitor mon) {
|
||||||
|
this.queue = queue;
|
||||||
|
monitor = mon;
|
||||||
|
setName("Worker Thread " + (instance++));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Debug.d(getName(), "started");
|
||||||
|
while ( true ) {
|
||||||
|
try {
|
||||||
|
Runnable work = null;
|
||||||
|
|
||||||
|
synchronized ( queue ) {
|
||||||
|
while ( queue.isEmpty() ) {
|
||||||
|
Debug.d(getName(), "waiting on work");
|
||||||
|
queue.wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
Debug.d(getName(), "got work");
|
||||||
|
|
||||||
|
// Get the next work item off of the queue
|
||||||
|
work = queue.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
running = true;
|
||||||
|
monitor.repaint();
|
||||||
|
if (work instanceof SentenceJob) {
|
||||||
|
SentenceJob sj = (SentenceJob)work;
|
||||||
|
sj.setProcessing();
|
||||||
|
}
|
||||||
|
work.run();
|
||||||
|
if (work instanceof SentenceJob) {
|
||||||
|
SentenceJob sj = (SentenceJob)work;
|
||||||
|
sj.setDequeued();
|
||||||
|
}
|
||||||
|
running = false;
|
||||||
|
monitor.repaint();
|
||||||
|
}
|
||||||
|
catch ( InterruptedException ie ) {
|
||||||
|
ie.printStackTrace();
|
||||||
|
break; // Terminate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Debug.d(getName(), "died");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user