Compare commits
104 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 3eb6704f2f | |||
| cd24beb8a6 | |||
| fa287305eb | |||
| 3fb656b693 | |||
| f514993525 | |||
| 81787260c9 | |||
| f9ad396228 | |||
| 8976f2e359 | |||
| 187c3edaf6 | |||
| 02e85fb354 | |||
| 289834021f | |||
| 04fea4acb2 | |||
| 54739b0a75 | |||
| ea5520a729 | |||
| 0a19d8d308 | |||
| 4dbe3e23b7 | |||
| c43cfc3b69 | |||
| babd3d2052 | |||
| 9464839b4d | |||
| bcf7875414 | |||
| 732894a0fb | |||
| 146bf5a3c2 | |||
| b05bfde094 | |||
| 37d372b8f5 | |||
| c01fee3b73 | |||
| c907e735c6 | |||
| 7545e33d2f | |||
| ebf961449a | |||
| 45d6882527 | |||
| 2ec370ad61 | |||
| 63d5c4af8e | |||
| 9619fd574e | |||
| adeb42070d | |||
| d207d246bf | |||
| 4dd3a3b874 | |||
| 52b04a754c | |||
| c0efd152e8 | |||
| 9bda80d40d | |||
| 0e12995063 | |||
| 424ebafab5 | |||
| 73d4feb679 | |||
| 887b2a9205 | |||
| 927eb3e1ff | |||
| fd19f5befe | |||
| 382775d6ab | |||
| c41ee27069 | |||
| e5b395ffa5 | |||
| b55f76c855 |
77
ExampleFilters/README.md
Normal file
@@ -0,0 +1,77 @@
|
||||
Filters are simply XML files with the extension ".eff"
|
||||
|
||||
Place them in a folder called `System` within your recordings folder.
|
||||
|
||||
The format is:
|
||||
|
||||
<effect name="Filter Name">
|
||||
<filter....>
|
||||
[optional sub-components or filters]
|
||||
</filter>
|
||||
[<filter...>]
|
||||
</effect>
|
||||
|
||||
Currently implemented filters:
|
||||
|
||||
<amplifier gain="1.0" />
|
||||
|
||||
Amplify (or attenuate) the sample by the given factor (1 = unity gain, 0 = silence, 2 = double, etc)
|
||||
|
||||
<lfo frequency="10" depth="0.2" />
|
||||
|
||||
Modulate the audio with a low-frequency oscillator. Specify the frequency and a factor of how much to modulate the audio signal. You can also specify an optional `phase="..."` (specified in radians) as an initial phase offset for the modulation.
|
||||
|
||||
<biquad type="..." fc="..." q="..." gain="..." />
|
||||
|
||||
A Biquad filter of the given type with a center frequency `fc` in Hz, a Q `q` and gain in Decibals of `gain`.
|
||||
Valid types are:
|
||||
|
||||
* lowpass
|
||||
* highpass
|
||||
* bandpass
|
||||
* notch
|
||||
* peak
|
||||
* lowshelf
|
||||
* highshelf
|
||||
|
||||
<delay>
|
||||
<delayline samples="..." gain="...">
|
||||
[optional effects to apply to the delay line]
|
||||
</delayline>
|
||||
</delay>
|
||||
|
||||
A multi-tap delay line where each tap can have its own additional filters applied. The delay is given in samples and the gain as
|
||||
a factor where 1.0 is unity gain.
|
||||
|
||||
<group name="Name">
|
||||
effects in the group
|
||||
</group>
|
||||
|
||||
Allows you to group effects together within a chain. Not of any real use yet (except that the outer wrapper of an effect chain is
|
||||
actually an effect group) but may be used in the future.
|
||||
|
||||
|
||||
An example: the "Ethereal Voice" - echoes starting off quiet and getting louder with a variable high-pass filter on the pre-echoes. Also
|
||||
includes a notch filter at 140Hz to cut out a specific annoying hum generated by my computer fans.
|
||||
|
||||
<effect name="Ethereal Voice">
|
||||
<biquad type="notch" fc="140" q="20" gain="-50" />
|
||||
<amplifier gain="0.1" />
|
||||
<delayline>
|
||||
<delay samples="4000" gain="1.0">
|
||||
<biquad type="highpass" fc="400" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="8000" gain="1.5">
|
||||
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="12000" gain="2.0">
|
||||
<biquad type="highpass" fc="200" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="16000" gain="3.0">
|
||||
<biquad type="highpass" fc="100" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="20000" gain="15.0" />
|
||||
</delayline>
|
||||
<biquad type="lowshelf" fc="1000" q="2.2" gain="-10" />
|
||||
<amplifier gain="1.5" />
|
||||
</effect>
|
||||
4
ExampleFilters/alien.eff
Normal file
@@ -0,0 +1,4 @@
|
||||
<effect name="Alien">
|
||||
<!--biquad type="lowpass" fc="10000" q="1" gain="-10" /-->
|
||||
<lfo frequency="50" depth="1.0" waveform="triangle" mode="replace"/>
|
||||
</effect>
|
||||
10
ExampleFilters/bigecho.eff
Normal file
@@ -0,0 +1,10 @@
|
||||
<effect name="Big Echo">
|
||||
<delayline>
|
||||
<delay samples="22000" gain="0.2" pan="-0.3">
|
||||
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="44000" gain="0.05" pan="0.3">
|
||||
<biquad type="highpass" fc="600" q="1" gain="0" />
|
||||
</delay>
|
||||
</delayline>
|
||||
</effect>
|
||||
6
ExampleFilters/cuthum.eff
Normal file
@@ -0,0 +1,6 @@
|
||||
<effect name="Cut Computer Hum">
|
||||
<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" />
|
||||
</effect>
|
||||
7
ExampleFilters/cuthumagc.eff
Normal file
@@ -0,0 +1,7 @@
|
||||
<effect name="Cut Computer Hum (with AGC)">
|
||||
<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" />
|
||||
<agc ceiling="0.666" limit="1.5" attack="0.08" decay="0.01" />
|
||||
</effect>
|
||||
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>
|
||||
20
ExampleFilters/ethereal.eff
Normal file
@@ -0,0 +1,20 @@
|
||||
<effect name="Ethereal Voice">
|
||||
<amplifier gain="0.1" />
|
||||
<delayline>
|
||||
<delay samples="2000" gain="1.0" pan="-0.3">
|
||||
<biquad type="highpass" fc="400" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="4000" gain="1.1" pan="0.3">
|
||||
<biquad type="highpass" fc="800" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="8000" gain="1.2" pan="-0.5">
|
||||
<biquad type="highpass" fc="1000" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="10000" gain="1.3" pan="0.5">
|
||||
<biquad type="highpass" fc="1500" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="12000" gain="15.0" pan="0" />
|
||||
</delayline>
|
||||
<biquad type="lowshelf" fc="2000" q="2.2" gain="-10" />
|
||||
<amplifier gain="1.5" />
|
||||
</effect>
|
||||
2
ExampleFilters/flat.eff
Normal file
@@ -0,0 +1,2 @@
|
||||
<effect name="Flat">
|
||||
</effect>
|
||||
15
ExampleFilters/largeroom.eff
Normal file
@@ -0,0 +1,15 @@
|
||||
<effect name="Large Room (quiet)">
|
||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||
<delayline>
|
||||
<delay samples="5500" gain="0.2" pan="-0.3">
|
||||
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="11000" gain="0.05" pan="0.3">
|
||||
<biquad type="highpass" fc="600" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="16500" gain="0.01" pan="0.0">
|
||||
<biquad type="highpass" fc="600" q="1" gain="0" />
|
||||
</delay>
|
||||
</delayline>
|
||||
<amplifier gain="0.3" />
|
||||
</effect>
|
||||
15
ExampleFilters/largeroomloud.eff
Normal file
@@ -0,0 +1,15 @@
|
||||
<effect name="Large Room (loud)">
|
||||
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||
<delayline>
|
||||
<delay samples="5500" gain="0.2" pan="-0.3">
|
||||
<biquad type="highpass" fc="300" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="11000" gain="0.05" pan="0.3">
|
||||
<biquad type="highpass" fc="600" q="1" gain="0" />
|
||||
</delay>
|
||||
<delay samples="16500" gain="0.01" pan="0.0">
|
||||
<biquad type="highpass" fc="600" q="1" gain="0" />
|
||||
</delay>
|
||||
</delayline>
|
||||
<amplifier gain="0.9" />
|
||||
</effect>
|
||||
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
@@ -0,0 +1,3 @@
|
||||
<effect name="Pan Right">
|
||||
<pan pan="0.4" />
|
||||
</effect>
|
||||
8
ExampleFilters/phone.eff
Normal file
@@ -0,0 +1,8 @@
|
||||
<effect name="Telephone">
|
||||
<biquad type="lowshelf" fc="400" q="10" gain="-20" />
|
||||
<biquad type="highshelf" fc="8000" q="10" gain="-20" />
|
||||
<delayline>
|
||||
<delay samples="100" gain="0.5" />
|
||||
</delayline>
|
||||
<amplifier gain="1.4" />
|
||||
</effect>
|
||||
12
ExampleFilters/radio.eff
Normal file
@@ -0,0 +1,12 @@
|
||||
<effect name="Radio">
|
||||
<amplifier gain="0.5" />
|
||||
<biquad type="peak" fc="1000" q="10" gain="25" />
|
||||
<lfo frequency="3000" depth="0.3" waveform="sine" mode="add" />
|
||||
<clipping clip="0.9" />
|
||||
<biquad type="highshelf" fc="8000" q="1" gain="-20" />
|
||||
<delayline>
|
||||
<delay samples="100" gain="0.7" />
|
||||
<delay samples="200" gain="0.5" />
|
||||
</delayline>
|
||||
<amplifier gain="0.3" />
|
||||
</effect>
|
||||
10
ExampleFilters/robotic.eff
Normal file
@@ -0,0 +1,10 @@
|
||||
<effect name="Robotic">
|
||||
<biquad type="lowshelf" fc="100" q="2" gain="-20" />
|
||||
<delayline>
|
||||
<delay samples="400" gain="1" pan="-0.3" />
|
||||
<delay samples="800" gain="1" pan="-0.3" />
|
||||
<delay samples="1200" gain="1" pan="-0.3" />
|
||||
<delay samples="1600" gain="1" pan="-0.3" />
|
||||
<delay samples="2000" gain="1" pan="-0.3" />
|
||||
</delayline>
|
||||
</effect>
|
||||
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>
|
||||
43
README.md
@@ -8,6 +8,7 @@ A system for easing the task of recording and editing audiobooks.
|
||||
* Zero editing
|
||||
* MP3 export
|
||||
* Chapter management
|
||||
* Audio effect chains (biquad, delay line, etc)
|
||||
|
||||
Usage
|
||||
-----
|
||||
@@ -28,12 +29,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.
|
||||
* 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 "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 "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
|
||||
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).
|
||||
|
||||
The phrases also have a "post gap" associated with them. This is the amount of room noise (in milliseconds) to place between
|
||||
@@ -52,22 +54,14 @@ edit the text of this ID to identify the recordings. You
|
||||
may, for instance, change it to have the same text as the
|
||||
audio contains.
|
||||
|
||||
To help with this CMU Sphinx (US EN dictionary) is bundled
|
||||
with the system and can be used to try and convert the
|
||||
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.
|
||||
|
||||
It's far from perfect (especially for a British English
|
||||
speaker), but it can help you to navigate your way around
|
||||
a chapter.
|
||||
The audio can also be automatically converted to text if you have an suitable command-line
|
||||
executable that will work. One example is (on Linux) [DeepSpeech](https://github.com/mozilla/DeepSpeech) by Mozilla.
|
||||
|
||||
File layout
|
||||
-----------
|
||||
|
||||
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.
|
||||
|
||||
When you export the book as MP3 a new folder "export" is created within the book's folder where the MP3 files are placed.
|
||||
@@ -84,3 +78,26 @@ Building
|
||||
5. Build with `ant build`
|
||||
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
|
||||
```
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
debug="true"
|
||||
debuglevel="lines,vars,source"
|
||||
encoding="UTF-8"
|
||||
bootclasspath="${bootclass.path}"
|
||||
bootclasspath="/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar"
|
||||
includeAntRuntime="false"
|
||||
deprecation="true"
|
||||
srcdir="src"
|
||||
|
||||
BIN
deps/commons-lang3.jar
LFS
vendored
Normal file
BIN
deps/commons-text.jar
LFS
vendored
Normal file
BIN
deps/json-20190722.jar
LFS
vendored
Normal file
@@ -1 +1 @@
|
||||
version=0.1.3
|
||||
version=0.3.9
|
||||
|
||||
BIN
resources/uk/co/majenko/audiobookrecorder/icons/close.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/cut.png
Normal file
|
After Width: | Height: | Size: 674 B |
|
After Width: | Height: | Size: 1.1 KiB |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/do-cut.png
Normal file
|
After Width: | Height: | Size: 576 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/manuscript.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/play-to.png
Normal file
|
After Width: | Height: | Size: 752 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/processing.png
Normal file
|
After Width: | Height: | Size: 489 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/queued.png
Normal file
|
After Width: | Height: | Size: 717 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/split.png
Normal file
|
After Width: | Height: | Size: 409 B |
BIN
resources/uk/co/majenko/audiobookrecorder/icons/tooltip.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
@@ -795,7 +795,7 @@ public abstract class AbstractTheme extends MetalTheme {
|
||||
public FontUIResource getControlTextFont() {
|
||||
if (controlFont == null) {
|
||||
if (JTattooUtilities.isLinux() && JTattooUtilities.isHiresScreen()) {
|
||||
controlFont = new FontUIResource(DIALOG, Font.BOLD, 14);
|
||||
controlFont = new FontUIResource(DIALOG, Font.PLAIN, 14); // bold
|
||||
} else {
|
||||
controlFont = new FontUIResource(DIALOG, Font.PLAIN, 12);
|
||||
}
|
||||
@@ -806,7 +806,7 @@ public abstract class AbstractTheme extends MetalTheme {
|
||||
public FontUIResource getSystemTextFont() {
|
||||
if (systemFont == null) {
|
||||
if (JTattooUtilities.isLinux() && JTattooUtilities.isHiresScreen()) {
|
||||
systemFont = new FontUIResource(DIALOG, Font.BOLD, 14);
|
||||
systemFont = new FontUIResource(DIALOG, Font.PLAIN, 14); // bold
|
||||
} else {
|
||||
systemFont = new FontUIResource(DIALOG, Font.PLAIN, 12);
|
||||
}
|
||||
@@ -817,7 +817,7 @@ public abstract class AbstractTheme extends MetalTheme {
|
||||
public FontUIResource getUserTextFont() {
|
||||
if (userFont == null) {
|
||||
if (JTattooUtilities.isLinux() && JTattooUtilities.isHiresScreen()) {
|
||||
userFont = new FontUIResource(DIALOG, Font.BOLD, 14);
|
||||
userFont = new FontUIResource(DIALOG, Font.PLAIN, 14); // bold
|
||||
} else {
|
||||
userFont = new FontUIResource(DIALOG, Font.PLAIN, 12);
|
||||
}
|
||||
@@ -828,7 +828,7 @@ public abstract class AbstractTheme extends MetalTheme {
|
||||
public FontUIResource getMenuTextFont() {
|
||||
if (menuFont == null) {
|
||||
if (JTattooUtilities.isLinux() && JTattooUtilities.isHiresScreen()) {
|
||||
menuFont = new FontUIResource(DIALOG, Font.BOLD, 14);
|
||||
menuFont = new FontUIResource(DIALOG, Font.PLAIN, 14); // bold
|
||||
} else {
|
||||
menuFont = new FontUIResource(DIALOG, Font.PLAIN, 12);
|
||||
}
|
||||
@@ -839,9 +839,9 @@ public abstract class AbstractTheme extends MetalTheme {
|
||||
public FontUIResource getWindowTitleFont() {
|
||||
if (windowTitleFont == null) {
|
||||
if (JTattooUtilities.isLinux() && JTattooUtilities.isHiresScreen()) {
|
||||
windowTitleFont = new FontUIResource(DIALOG, Font.BOLD, 14);
|
||||
windowTitleFont = new FontUIResource(DIALOG, Font.PLAIN, 14); // bold
|
||||
} else {
|
||||
windowTitleFont = new FontUIResource(DIALOG, Font.BOLD, 12);
|
||||
windowTitleFont = new FontUIResource(DIALOG, Font.PLAIN, 12); // bold
|
||||
}
|
||||
}
|
||||
return windowTitleFont;
|
||||
@@ -850,7 +850,7 @@ public abstract class AbstractTheme extends MetalTheme {
|
||||
public FontUIResource getSubTextFont() {
|
||||
if (smallFont == null) {
|
||||
if (JTattooUtilities.isLinux() && JTattooUtilities.isHiresScreen()) {
|
||||
smallFont = new FontUIResource(DIALOG, Font.BOLD, 12);
|
||||
smallFont = new FontUIResource(DIALOG, Font.PLAIN, 12); // bold
|
||||
} else {
|
||||
smallFont = new FontUIResource(DIALOG, Font.PLAIN, 10);
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ public class HiFiDefaultTheme extends AbstractTheme {
|
||||
tooltipForegroundColor = white;
|
||||
tooltipBackgroundColor = new ColorUIResource(24, 24, 24);
|
||||
|
||||
controlFont = new FontUIResource("Dialog", Font.BOLD, 12);
|
||||
systemFont = new FontUIResource("Dialog", Font.BOLD, 12);
|
||||
userFont = new FontUIResource("Dialog", Font.BOLD, 12);
|
||||
menuFont = new FontUIResource("Dialog", Font.BOLD, 12);
|
||||
windowTitleFont = new FontUIResource("Dialog", Font.BOLD, 12);
|
||||
controlFont = new FontUIResource("Dialog", Font.PLAIN, 12); // bold
|
||||
systemFont = new FontUIResource("Dialog", Font.PLAIN, 12); // bold
|
||||
userFont = new FontUIResource("Dialog", Font.PLAIN, 12); // bold
|
||||
menuFont = new FontUIResource("Dialog", Font.PLAIN, 12); // bold
|
||||
windowTitleFont = new FontUIResource("Dialog", Font.PLAIN, 12); // bold
|
||||
smallFont = new FontUIResource("Dialog", Font.PLAIN, 10);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,18 +42,18 @@ public class HiFiLookAndFeel extends AbstractLookAndFeel {
|
||||
private static final Properties giantFontProps = new Properties();
|
||||
|
||||
static {
|
||||
smallFontProps.setProperty("controlTextFont", "Dialog bold 10");
|
||||
smallFontProps.setProperty("systemTextFont", "Dialog bold 10");
|
||||
smallFontProps.setProperty("controlTextFont", "Dialog 10"); // bold
|
||||
smallFontProps.setProperty("systemTextFont", "Dialog 10"); // bold
|
||||
smallFontProps.setProperty("userTextFont", "Dialog 10");
|
||||
smallFontProps.setProperty("menuTextFont", "Dialog bold 10");
|
||||
smallFontProps.setProperty("windowTitleFont", "Dialog bold 10");
|
||||
smallFontProps.setProperty("menuTextFont", "Dialog 10"); // bold
|
||||
smallFontProps.setProperty("windowTitleFont", "Dialog 10"); // bold
|
||||
smallFontProps.setProperty("subTextFont", "Dialog 8");
|
||||
|
||||
largeFontProps.setProperty("controlTextFont", "Dialog bold 14");
|
||||
largeFontProps.setProperty("systemTextFont", "Dialog bold 14");
|
||||
largeFontProps.setProperty("userTextFont", "Dialog bold 14");
|
||||
largeFontProps.setProperty("menuTextFont", "Dialog bold 14");
|
||||
largeFontProps.setProperty("windowTitleFont", "Dialog bold 14");
|
||||
largeFontProps.setProperty("controlTextFont", "Dialog 14"); // bold
|
||||
largeFontProps.setProperty("systemTextFont", "Dialog 14"); // bold
|
||||
largeFontProps.setProperty("userTextFont", "Dialog 14"); // bold
|
||||
largeFontProps.setProperty("menuTextFont", "Dialog 14"); // bold
|
||||
largeFontProps.setProperty("windowTitleFont", "Dialog 14"); // bold
|
||||
largeFontProps.setProperty("subTextFont", "Dialog 12");
|
||||
|
||||
giantFontProps.setProperty("controlTextFont", "Dialog 18");
|
||||
|
||||
@@ -1,484 +0,0 @@
|
||||
/*
|
||||
* 21.04.2004 Original verion. davagin@udm.ru.
|
||||
*-----------------------------------------------------------------------
|
||||
* 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.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
package davaguine.jeq.core;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* The EqualizerInputStream class
|
||||
* Author: Dmitry Vaguine
|
||||
* Date: 02.05.2004
|
||||
* Time: 12:00:29
|
||||
*/
|
||||
public class EqualizerInputStream extends InputStream {
|
||||
private InputStream stream;
|
||||
private IIR iir;
|
||||
|
||||
private final static int BUFFER_SIZE = 65536;
|
||||
private byte[] inbuf = new byte[BUFFER_SIZE];
|
||||
private int[] workbuf = new int[BUFFER_SIZE];
|
||||
private byte[] outbuf = new byte[BUFFER_SIZE];
|
||||
private int inpos = 0;
|
||||
private int inlen = 0;
|
||||
private int outpos = 0;
|
||||
private int outlen = 0;
|
||||
|
||||
private boolean signed;
|
||||
private int samplesize;
|
||||
private boolean bigendian;
|
||||
|
||||
/**
|
||||
* Constructs new EqualizerInputStream object
|
||||
*
|
||||
* @param stream is an input stream for pcm data
|
||||
* @param samplerate is a sample rate of input data
|
||||
* @param channels is the number of channels
|
||||
* @param signed indicates that the data is signed
|
||||
* @param samplesize is the sample bit size of data
|
||||
* @param bigendian indicates that the dat is in "big endian" encoding
|
||||
* @param bands is the number of bands
|
||||
*/
|
||||
public EqualizerInputStream(InputStream stream, float samplerate, int channels, boolean signed, int samplesize, boolean bigendian, int bands) {
|
||||
this.stream = stream;
|
||||
this.iir = new IIR(bands, samplerate, channels);
|
||||
this.signed = signed;
|
||||
this.samplesize = samplesize;
|
||||
this.bigendian = bigendian;
|
||||
|
||||
if (!isParamsSupported(samplerate, channels, samplesize, bands))
|
||||
throw new IllegalArgumentException("Unsupported sample bit size");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Controls of equalizer
|
||||
*
|
||||
* @return Controls of equalizer
|
||||
*/
|
||||
public IIRControls getControls() {
|
||||
return iir.getControls();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is special method for checking of supported parameters of equalizer
|
||||
*
|
||||
* @param bands is the number of bands
|
||||
* @param samplerate is the sample rate of data
|
||||
* @param channels is the number of channels
|
||||
* @param samplesize is the size of sample in bits
|
||||
* @return true if parameters are supported
|
||||
*/
|
||||
public static boolean isParamsSupported(float samplerate, int channels, int samplesize, int bands) {
|
||||
switch (samplesize) {
|
||||
case 8:
|
||||
case 16:
|
||||
case 24:
|
||||
case 32:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return IIR.isParamsSupported(bands, samplerate, channels);
|
||||
}
|
||||
|
||||
private boolean fillInBuffer() throws IOException {
|
||||
if (inpos != 0 && inlen > 0)
|
||||
System.arraycopy(inbuf, inpos, inbuf, 0, inlen);
|
||||
inpos = 0;
|
||||
int num;
|
||||
boolean eof = false;
|
||||
while (inlen != inbuf.length) {
|
||||
num = stream.read(inbuf, inlen, inbuf.length - inlen);
|
||||
if (num < 0) {
|
||||
eof = true;
|
||||
break;
|
||||
}
|
||||
inlen += num;
|
||||
}
|
||||
return eof;
|
||||
}
|
||||
|
||||
private void fillOutBuffer() {
|
||||
if (outpos != 0 && outlen > 0)
|
||||
System.arraycopy(outbuf, outpos, outbuf, 0, outlen);
|
||||
outpos = 0;
|
||||
int len = outbuf.length - outlen;
|
||||
len = inlen < len ? inlen : len;
|
||||
len = convertToInt(len);
|
||||
if (len > 0) {
|
||||
iir.iir(workbuf, len);
|
||||
len = convertToByte(outbuf, outlen, len);
|
||||
outlen += len;
|
||||
}
|
||||
}
|
||||
|
||||
private int convertToInt(int length) {
|
||||
int l = length;
|
||||
int temp;
|
||||
byte a1[];
|
||||
switch (samplesize) {
|
||||
case 8: {
|
||||
if (length > 0) {
|
||||
System.arraycopy(inbuf, 0, workbuf, 0, length);
|
||||
inpos += length;
|
||||
inlen -= length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 16: {
|
||||
l = length >> 1;
|
||||
if (l > 0) {
|
||||
if (bigendian)
|
||||
for (int i = 0; i < l; i++) {
|
||||
temp = (((a1 = inbuf)[inpos++] & 0xff) << 8) | (a1[inpos++] & 0xff);
|
||||
workbuf[i] = signed && temp > 32767 ? temp - 65536 : temp;
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < l; i++) {
|
||||
temp = ((a1 = inbuf)[inpos++] & 0xff) | ((a1[inpos++] & 0xff) << 8);
|
||||
workbuf[i] = signed && temp > 32767 ? temp - 65536 : temp;
|
||||
}
|
||||
inlen -= inpos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 24: {
|
||||
l = length / 3;
|
||||
if (l > 0) {
|
||||
if (bigendian)
|
||||
for (int i = 0; i < l; i++) {
|
||||
temp = ((a1 = inbuf)[inpos++] & 0xff) | ((a1[inpos++] & 0xff) << 8) | ((a1[inpos++] & 0xff) << 16);
|
||||
workbuf[i] = signed && temp > 8388607 ? temp - 16777216 : temp;
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < l; i++) {
|
||||
temp = (((a1 = inbuf)[inpos++] & 0xff) << 16) | ((a1[inpos++] & 0xff) << 8) | (a1[inpos++] & 0xff);
|
||||
workbuf[i] = signed && temp > 8388607 ? temp - 16777216 : temp;
|
||||
}
|
||||
inlen -= inpos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 32: {
|
||||
l = length / 4;
|
||||
if (l > 0) {
|
||||
if (bigendian)
|
||||
for (int i = 0; i < l; i++) {
|
||||
temp = ((a1 = inbuf)[inpos++] & 0xff) | ((a1[inpos++] & 0xff) << 8) | ((a1[inpos++] & 0xff) << 16) | ((a1[inpos++] & 0xff) << 24);
|
||||
workbuf[i] = temp; //signed && temp > 8388607 ? temp - 16777216 : temp;
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < l; i++) {
|
||||
temp = (((a1 = inbuf)[inpos++] & 0xff) << 24) | ((a1[inpos++] & 0xff) << 16) | ((a1[inpos++] & 0xff) << 8) | (a1[inpos++] & 0xff);
|
||||
workbuf[i] = temp; //signed && temp > 8388607 ? temp - 16777216 : temp;
|
||||
}
|
||||
inlen -= inpos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private int wrap8Bit(int data) {
|
||||
if (data > 127)
|
||||
data = 127;
|
||||
else if (data < -128)
|
||||
data = -128;
|
||||
if (data < 0)
|
||||
data += 256;
|
||||
return data;
|
||||
}
|
||||
|
||||
private int wrap16Bit(int data) {
|
||||
if (data > 32767)
|
||||
data = 32767;
|
||||
else if (data < -32768)
|
||||
data = -32768;
|
||||
if (data < 0)
|
||||
data += 65536;
|
||||
return data;
|
||||
}
|
||||
|
||||
private int wrap24Bit(int data) {
|
||||
if (data > 8388607)
|
||||
data = 8388607;
|
||||
else if (data < -8388608)
|
||||
data = -8388608;
|
||||
if (data < 0)
|
||||
data += 16777216;
|
||||
return data;
|
||||
}
|
||||
|
||||
private int convertToByte(byte[] b, int off, int length) {
|
||||
int p = off;
|
||||
int d;
|
||||
switch (samplesize) {
|
||||
case 8: {
|
||||
for (int i = 0; i < length; i++)
|
||||
b[p++] = (byte) (wrap8Bit(workbuf[i]) & 0xff);
|
||||
break;
|
||||
}
|
||||
case 16: {
|
||||
if (bigendian) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
d = wrap16Bit(workbuf[i]);
|
||||
b[p++] = (byte) ((d & 0xff00) >> 8);
|
||||
b[p++] = (byte) (d & 0xff);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
d = wrap16Bit(workbuf[i]);
|
||||
b[p++] = (byte) (d & 0xff);
|
||||
b[p++] = (byte) ((d & 0xff00) >> 8);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 24: {
|
||||
if (bigendian) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
d = wrap24Bit(workbuf[i]);
|
||||
b[p++] = (byte) (d & 0xff);
|
||||
b[p++] = (byte) ((d & 0xff00) >> 8);
|
||||
b[p++] = (byte) ((d & 0xff0000) >> 16);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
d = wrap24Bit(workbuf[i]);
|
||||
b[p++] = (byte) ((d & 0xff0000) >> 16);
|
||||
b[p++] = (byte) ((d & 0xff00) >> 8);
|
||||
b[p++] = (byte) (d & 0xff);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 32: {
|
||||
if (bigendian) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
d = workbuf[i];
|
||||
b[p++] = (byte) (d & 0xff);
|
||||
b[p++] = (byte) ((d & 0xff00) >> 8);
|
||||
b[p++] = (byte) ((d & 0xff0000) >> 16);
|
||||
b[p++] = (byte) ((d & 0xff000000) >> 24);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < length; i++) {
|
||||
d = wrap24Bit(workbuf[i]);
|
||||
b[p++] = (byte) ((d & 0xff000000) >> 24);
|
||||
b[p++] = (byte) ((d & 0xff0000) >> 16);
|
||||
b[p++] = (byte) ((d & 0xff00) >> 8);
|
||||
b[p++] = (byte) (d & 0xff);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return p - off;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes that can be read (or skipped over) from
|
||||
* this input stream without blocking by the next caller of a method for
|
||||
* this input stream. The next caller might be the same thread or
|
||||
* another thread.
|
||||
*
|
||||
* @return the number of bytes that can be read from this input stream
|
||||
* without blocking.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public int available() throws IOException {
|
||||
return outlen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes this input stream and releases any system resources associated
|
||||
* with the stream.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
stream.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> The <code>mark</code> method of <code>EqualizerInputStream</code> does
|
||||
* nothing.
|
||||
*
|
||||
* @param readlimit the maximum limit of bytes that can be read before
|
||||
* the mark position becomes invalid.
|
||||
*/
|
||||
public synchronized void mark(int readlimit) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if this input stream supports the <code>mark</code> and
|
||||
* <code>reset</code> methods. Whether or not <code>mark</code> and
|
||||
* <code>reset</code> are supported is an invariant property of a
|
||||
* particular input stream instance. The <code>markSupported</code> method
|
||||
* of <code>EqualizerInputStream</code> returns <code>false</code>.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public boolean markSupported() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next byte of data from the input stream. The value byte is
|
||||
* returned as an <code>int</code> in the range <code>0</code> to
|
||||
* <code>255</code>. If no byte is available because the end of the stream
|
||||
* has been reached, the value <code>-1</code> is returned. This method
|
||||
* blocks until input data is available, the end of the stream is detected,
|
||||
* or an exception is thrown.
|
||||
*
|
||||
* @return the next byte of data, or <code>-1</code> if the end of the
|
||||
* stream is reached.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public int read() throws IOException {
|
||||
if (outlen == 0) {
|
||||
boolean eof = fillInBuffer();
|
||||
fillOutBuffer();
|
||||
if (outlen == 0 && eof)
|
||||
return -1;
|
||||
if (outlen == 0 && !eof)
|
||||
throw new IOException("Impossible state");
|
||||
}
|
||||
int b = outbuf[outpos++];
|
||||
outlen--;
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads up to <code>len</code> bytes of data from the input stream into
|
||||
* an array of bytes. An attempt is made to read as many as
|
||||
* <code>len</code> bytes, but a smaller number may be read.
|
||||
* The number of bytes actually read is returned as an integer.
|
||||
* <p/>
|
||||
* <p> This method blocks until input data is available, end of file is
|
||||
* detected, or an exception is thrown.
|
||||
* <p/>
|
||||
* <p> If <code>b</code> is <code>null</code>, a
|
||||
* <code>NullPointerException</code> is thrown.
|
||||
* <p/>
|
||||
* <p> If <code>off</code> is negative, or <code>len</code> is negative, or
|
||||
* <code>off+len</code> is greater than the length of the array
|
||||
* <code>b</code>, then an <code>IndexOutOfBoundsException</code> is
|
||||
* thrown.
|
||||
* <p/>
|
||||
* <p> If <code>len</code> is zero, then no bytes are read and
|
||||
* <code>0</code> is returned; otherwise, there is an attempt to read at
|
||||
* least one byte. If no byte is available because the stream is at end of
|
||||
* file, the value <code>-1</code> is returned; otherwise, at least one
|
||||
* byte is read and stored into <code>b</code>.
|
||||
* <p/>
|
||||
* <p> The first byte read is stored into element <code>b[off]</code>, the
|
||||
* next one into <code>b[off+1]</code>, and so on. The number of bytes read
|
||||
* is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
|
||||
* bytes actually read; these bytes will be stored in elements
|
||||
* <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
|
||||
* leaving elements <code>b[off+</code><i>k</i><code>]</code> through
|
||||
* <code>b[off+len-1]</code> unaffected.
|
||||
* <p/>
|
||||
* <p> In every case, elements <code>b[0]</code> through
|
||||
* <code>b[off]</code> and elements <code>b[off+len]</code> through
|
||||
* <code>b[b.length-1]</code> are unaffected.
|
||||
* <p/>
|
||||
* <p> If the first byte cannot be read for any reason other than end of
|
||||
* file, then an <code>IOException</code> is thrown. In particular, an
|
||||
* <code>IOException</code> is thrown if the input stream has been closed.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @param off the start offset in array <code>b</code>
|
||||
* at which the data is written.
|
||||
* @param len the maximum number of bytes to read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* <code>-1</code> if there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws NullPointerException if <code>b</code> is <code>null</code>.
|
||||
*/
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
if (outlen < len) {
|
||||
boolean eof = fillInBuffer();
|
||||
fillOutBuffer();
|
||||
if (outlen == 0 && eof)
|
||||
return -1;
|
||||
if (outlen == 0 && !eof)
|
||||
throw new IOException("Impossible state");
|
||||
}
|
||||
len = outlen < len ? outlen : len;
|
||||
if (len > 0) {
|
||||
System.arraycopy(outbuf, outpos, b, off, len);
|
||||
outpos += len;
|
||||
outlen -= len;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>The method <code>reset</code> for class <code>EqualizerInputStream</code>
|
||||
* does nothing except throw an <code>IOException</code>.
|
||||
*
|
||||
* @throws IOException as an indication that the mark feature doesn't supported by EqualizerInputStream.
|
||||
*/
|
||||
public void reset() throws IOException {
|
||||
throw new IOException("mark/reset not supported");
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips over and discards <code>n</code> bytes of data from this input
|
||||
* stream. The <code>skip</code> method may, for a variety of reasons, end
|
||||
* up skipping over some smaller number of bytes, possibly <code>0</code>.
|
||||
* This may result from any of a number of conditions; reaching end of file
|
||||
* before <code>n</code> bytes have been skipped is only one possibility.
|
||||
* The actual number of bytes skipped is returned. If <code>n</code> is
|
||||
* negative, no bytes are skipped.
|
||||
*
|
||||
* @param n the number of bytes to be skipped.
|
||||
* @return the actual number of bytes skipped.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public long skip(long n) throws IOException {
|
||||
int l;
|
||||
if (n <= outlen) {
|
||||
outpos += n;
|
||||
outlen -= n;
|
||||
return n;
|
||||
}
|
||||
n -= outlen;
|
||||
l = outlen;
|
||||
outlen = 0;
|
||||
outpos = 0;
|
||||
if (n <= inlen) {
|
||||
inpos += n;
|
||||
inlen -= n;
|
||||
return l + n;
|
||||
}
|
||||
n -= inlen;
|
||||
l += inlen;
|
||||
inlen = 0;
|
||||
inpos = 0;
|
||||
return stream.skip(n) + l;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,292 +0,0 @@
|
||||
/*
|
||||
* 21.04.2004 Original verion. davagin@udm.ru.
|
||||
*-----------------------------------------------------------------------
|
||||
* 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.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
package davaguine.jeq.core;
|
||||
|
||||
/**
|
||||
* Generic wrapper around IIR algorithm.
|
||||
* Author: Dmitry Vaguine
|
||||
* Date: 02.05.2004
|
||||
* Time: 12:00:29
|
||||
*/
|
||||
public class IIR extends IIRBase {
|
||||
/**
|
||||
* Max number of channels supported
|
||||
*/
|
||||
public final static int EQ_MAX_CHANNELS = 2;
|
||||
/**
|
||||
* Max bands supported by the code
|
||||
*/
|
||||
public final static int EQ_MAX_BANDS = 31;
|
||||
/**
|
||||
* Supported sample rates
|
||||
*/
|
||||
public final static float EQ_11025_RATE = 11025;
|
||||
public final static float EQ_22050_RATE = 22050;
|
||||
public final static float EQ_44100_RATE = 44100;
|
||||
public final static float EQ_48000_RATE = 48000;
|
||||
public final static float EQ_96000_RATE = 96000;
|
||||
/**
|
||||
* Supported number of bands
|
||||
*/
|
||||
public final static int EQ_10_BANDS = 10;
|
||||
public final static int EQ_15_BANDS = 15;
|
||||
public final static int EQ_25_BANDS = 25;
|
||||
public final static int EQ_31_BANDS = 31;
|
||||
|
||||
/* Indexes for the history arrays
|
||||
* These have to be kept between calls to this function
|
||||
* hence they are static */
|
||||
private int i;
|
||||
private int j;
|
||||
private int k;
|
||||
|
||||
/* History for two filters */
|
||||
private XYData[][] dataHistory = new XYData[EQ_MAX_BANDS][EQ_MAX_CHANNELS];
|
||||
private XYData[][] dataHistory2 = new XYData[EQ_MAX_BANDS][EQ_MAX_CHANNELS];
|
||||
|
||||
/* Coefficients */
|
||||
private IIRCoefficients[] iircf;
|
||||
|
||||
/* Equalizer config */
|
||||
private IIRControls eqcfg;
|
||||
/* rate */
|
||||
private float rate;
|
||||
/* channels */
|
||||
private int channels;
|
||||
/* bands */
|
||||
private int bands;
|
||||
|
||||
/**
|
||||
* Constructs equalizer with given config
|
||||
*
|
||||
* @param bands is the number of bands to be used
|
||||
* @param rate is the sample rate of equalizer
|
||||
* @param channels is the number of channels
|
||||
*/
|
||||
public IIR(int bands, float rate, int channels) {
|
||||
this.rate = rate;
|
||||
this.channels = channels;
|
||||
this.bands = bands;
|
||||
this.eqcfg = new IIRControls(bands, channels);
|
||||
|
||||
if (!isParamsSupported(bands, rate, channels))
|
||||
throw new IllegalArgumentException("Unsupported parameters");
|
||||
|
||||
initIIR();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Controls of equalizer
|
||||
*
|
||||
* @return Controls of equalizer
|
||||
*/
|
||||
public IIRControls getControls() {
|
||||
return eqcfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is special method for checking of supported parameters of equalizer
|
||||
*
|
||||
* @param bands is the number of bands
|
||||
* @param rate is the sample rate of data
|
||||
* @param channels is the number of channels
|
||||
* @return true if parameters are supported
|
||||
*/
|
||||
public static boolean isParamsSupported(int bands, float rate, int channels) {
|
||||
if (rate != EQ_11025_RATE && rate != EQ_22050_RATE && rate != EQ_44100_RATE && rate != EQ_48000_RATE && rate != EQ_96000_RATE)
|
||||
return false;
|
||||
|
||||
switch (bands) {
|
||||
case EQ_10_BANDS:
|
||||
case EQ_15_BANDS:
|
||||
case EQ_25_BANDS:
|
||||
case EQ_31_BANDS:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (channels) {
|
||||
case 1:
|
||||
case 2:
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return (rate != EQ_11025_RATE && rate != EQ_22050_RATE) || bands == EQ_10_BANDS;
|
||||
}
|
||||
|
||||
/* Init the filters */
|
||||
private void initIIR() {
|
||||
setFilters();
|
||||
for (int ii = 0; ii < EQ_MAX_BANDS; ii++)
|
||||
for (int jj = 0; jj < EQ_MAX_CHANNELS; jj++) {
|
||||
dataHistory[ii][jj] = new XYData();
|
||||
dataHistory2[ii][jj] = new XYData();
|
||||
}
|
||||
i = 0;
|
||||
j = 2;
|
||||
k = 1;
|
||||
}
|
||||
|
||||
private void setFilters() {
|
||||
if (rate == EQ_11025_RATE)
|
||||
iircf = iir_cf10_11k_11025;
|
||||
else if (rate == EQ_22050_RATE)
|
||||
iircf = iir_cf10_22k_22050;
|
||||
else if (rate == EQ_44100_RATE) {
|
||||
switch (bands) {
|
||||
case 31:
|
||||
iircf = iir_cf31_44100;
|
||||
break;
|
||||
case 25:
|
||||
iircf = iir_cf25_44100;
|
||||
break;
|
||||
case 15:
|
||||
iircf = iir_cf15_44100;
|
||||
break;
|
||||
default:
|
||||
iircf = iir_cf10_44100;
|
||||
break;
|
||||
}
|
||||
} else if (rate == EQ_48000_RATE) {
|
||||
switch (bands) {
|
||||
case 31:
|
||||
iircf = iir_cf31_48000;
|
||||
break;
|
||||
case 25:
|
||||
iircf = iir_cf25_48000;
|
||||
break;
|
||||
case 15:
|
||||
iircf = iir_cf15_48000;
|
||||
break;
|
||||
default:
|
||||
iircf = iir_cf10_48000;
|
||||
break;
|
||||
}
|
||||
} else if (rate == EQ_96000_RATE) {
|
||||
switch (bands) {
|
||||
case 31:
|
||||
iircf = iir_cf31_96000;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear filter history.
|
||||
*/
|
||||
public void cleanHistory() {
|
||||
/* Zero the history arrays */
|
||||
for (int ii = 0; ii < EQ_MAX_BANDS; ii++)
|
||||
for (int jj = 0; jj < EQ_MAX_CHANNELS; jj++) {
|
||||
dataHistory[ii][jj].zero();
|
||||
dataHistory2[ii][jj].zero();
|
||||
}
|
||||
i = 0;
|
||||
j = 2;
|
||||
k = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main filtering method.
|
||||
*
|
||||
* @param data - data to be filtered
|
||||
* @param length - length of data in buffer
|
||||
*/
|
||||
public void iir(int[] data, int length) {
|
||||
int index, band, channel;
|
||||
float eqpreamp[] = eqcfg.getPreamp();
|
||||
float eqbands[][] = eqcfg.getBands();
|
||||
double pcm, out;
|
||||
|
||||
/**
|
||||
* IIR filter equation is
|
||||
* y[n] = 2 * (alpha*(x[n]-x[n-2]) + gamma*y[n-1] - beta*y[n-2])
|
||||
*
|
||||
* NOTE: The 2 factor was introduced in the coefficients to save
|
||||
* a multiplication
|
||||
*
|
||||
* This algorithm cascades two filters to get nice filtering
|
||||
* at the expense of extra CPU cycles
|
||||
*/
|
||||
IIRCoefficients tempcf;
|
||||
XYData tempd;
|
||||
for (index = 0; index < length; index += channels) {
|
||||
/* For each channel */
|
||||
for (channel = 0; channel < channels; channel++) {
|
||||
/* Preamp gain */
|
||||
pcm = data[index + channel] * eqpreamp[channel];
|
||||
|
||||
out = 0f;
|
||||
/* For each band */
|
||||
for (band = 0; band < bands; band++) {
|
||||
/* Store Xi(n) */
|
||||
tempd = dataHistory[band][channel];
|
||||
tempd.x[i] = pcm;
|
||||
/* Calculate and store Yi(n) */
|
||||
tempcf = iircf[band];
|
||||
tempd.y[i] =
|
||||
(
|
||||
/* = alpha * [x(n)-x(n-2)] */
|
||||
tempcf.alpha * (pcm - tempd.x[k])
|
||||
/* + gamma * y(n-1) */
|
||||
+ tempcf.gamma * tempd.y[j]
|
||||
/* - beta * y(n-2) */
|
||||
- tempcf.beta * tempd.y[k]
|
||||
);
|
||||
/*
|
||||
* The multiplication by 2.0 was 'moved' into the coefficients to save
|
||||
* CPU cycles here */
|
||||
/* Apply the gain */
|
||||
out += (tempd.y[i] * eqbands[band][channel]); // * 2.0;
|
||||
} /* For each band */
|
||||
|
||||
/* Volume stuff
|
||||
Scale down original PCM sample and add it to the filters
|
||||
output. This substitutes the multiplication by 0.25
|
||||
Go back to use the floating point multiplication before the
|
||||
conversion to give more dynamic range
|
||||
*/
|
||||
out += (pcm * 0.25);
|
||||
|
||||
/* Normalize the output */
|
||||
out *= 4;
|
||||
|
||||
/* Round and convert to integer */
|
||||
data[index + channel] = (int) out;
|
||||
} /* For each channel */
|
||||
|
||||
i++;
|
||||
j++;
|
||||
k++;
|
||||
|
||||
/* Wrap around the indexes */
|
||||
if (i == 3)
|
||||
i = 0;
|
||||
else if (j == 3)
|
||||
j = 0;
|
||||
else
|
||||
k = 0;
|
||||
|
||||
|
||||
}/* For each pair of samples */
|
||||
}
|
||||
}
|
||||
@@ -1,486 +0,0 @@
|
||||
/*
|
||||
* 21.04.2004 Original verion. davagin@udm.ru.
|
||||
*-----------------------------------------------------------------------
|
||||
* 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.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
package davaguine.jeq.core;
|
||||
|
||||
/**
|
||||
* Author: Dmitry Vaguine
|
||||
* Date: 02.05.2004
|
||||
* Time: 12:00:29
|
||||
*/
|
||||
public class IIRBase {
|
||||
/* BETA, ALPHA, GAMMA */
|
||||
public final static IIRCoefficients iir_cf10_11k_11025[] = {
|
||||
/* 31 Hz*/
|
||||
new IIRCoefficients(9.8758524689e-01, 6.2073765555e-03, 1.9872750693e+00),
|
||||
/* 62 Hz*/
|
||||
new IIRCoefficients(9.7532461998e-01, 1.2337690008e-02, 1.9740916593e+00),
|
||||
/* 125 Hz*/
|
||||
new IIRCoefficients(9.5087485437e-01, 2.4562572817e-02, 1.9459267562e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.0416308662e-01, 4.7918456688e-02, 1.8848691023e+00),
|
||||
/* 500 Hz*/
|
||||
new IIRCoefficients(8.1751373987e-01, 9.1243130064e-02, 1.7442229115e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(6.6840529852e-01, 1.6579735074e-01, 1.4047189863e+00),
|
||||
/* 2k Hz*/
|
||||
new IIRCoefficients(4.4858358977e-01, 2.7570820511e-01, 6.0517475334e-01),
|
||||
/* 3k Hz*/
|
||||
new IIRCoefficients(3.1012671838e-01, 3.4493664081e-01, -1.8141012760e-01),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(2.4198119087e-01, 3.7900940457e-01, -8.0845085113e-01),
|
||||
/* 5.5k Hz*/
|
||||
new IIRCoefficients(3.3453245058e-01, 3.3273377471e-01, -1.3344985880e+00)
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf10_22k_22050[] = {
|
||||
/* 31 Hz*/
|
||||
new IIRCoefficients(9.9377323686e-01, 3.1133815717e-03, 1.9936954495e+00),
|
||||
/* 62 Hz*/
|
||||
new IIRCoefficients(9.8758524689e-01, 6.2073765555e-03, 1.9872750693e+00),
|
||||
/* 125 Hz*/
|
||||
new IIRCoefficients(9.7512812040e-01, 1.2435939802e-02, 1.9738753198e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.5087485437e-01, 2.4562572817e-02, 1.9459267562e+00),
|
||||
/* 500 Hz*/
|
||||
new IIRCoefficients(9.0416308662e-01, 4.7918456688e-02, 1.8848691023e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(8.1751373987e-01, 9.1243130064e-02, 1.7442229115e+00),
|
||||
/* 2k Hz*/
|
||||
new IIRCoefficients(6.6840529852e-01, 1.6579735074e-01, 1.4047189863e+00),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(4.4858358977e-01, 2.7570820511e-01, 6.0517475334e-01),
|
||||
/* 8k Hz*/
|
||||
new IIRCoefficients(2.4198119087e-01, 3.7900940457e-01, -8.0845085113e-01),
|
||||
/* 11k Hz*/
|
||||
new IIRCoefficients(3.3453245058e-01, 3.3273377471e-01, -1.3344985880e+00)
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf10_44100[] = {
|
||||
/* 31 Hz*/
|
||||
new IIRCoefficients(9.9688176273e-01, 1.5591186337e-03, 1.9968622855e+00),
|
||||
/* 62 Hz*/
|
||||
new IIRCoefficients(9.9377323686e-01, 3.1133815717e-03, 1.9936954495e+00),
|
||||
/* 125 Hz*/
|
||||
new IIRCoefficients(9.8748575691e-01, 6.2571215431e-03, 1.9871705722e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.7512812040e-01, 1.2435939802e-02, 1.9738753198e+00),
|
||||
/* 500 Hz*/
|
||||
new IIRCoefficients(9.5087485437e-01, 2.4562572817e-02, 1.9459267562e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(9.0416308662e-01, 4.7918456688e-02, 1.8848691023e+00),
|
||||
/* 2k Hz*/
|
||||
new IIRCoefficients(8.1751373987e-01, 9.1243130064e-02, 1.7442229115e+00),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(6.6840529852e-01, 1.6579735074e-01, 1.4047189863e+00),
|
||||
/* 8k Hz*/
|
||||
new IIRCoefficients(4.4858358977e-01, 2.7570820511e-01, 6.0517475334e-01),
|
||||
/* 16k Hz*/
|
||||
new IIRCoefficients(2.4198119087e-01, 3.7900940457e-01, -8.0845085113e-01)
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf10_48000[] = {
|
||||
/* 31 Hz*/
|
||||
new IIRCoefficients(9.9713475915e-01, 1.4326204244e-03, 1.9971183163e+00),
|
||||
/* 62 Hz*/
|
||||
new IIRCoefficients(9.9427771143e-01, 2.8611442874e-03, 1.9942120343e+00),
|
||||
/* 125 Hz*/
|
||||
new IIRCoefficients(9.8849666727e-01, 5.7516663664e-03, 1.9882304829e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.7712566171e-01, 1.1437169144e-02, 1.9760670839e+00),
|
||||
/* 500 Hz*/
|
||||
new IIRCoefficients(9.5477456091e-01, 2.2612719547e-02, 1.9505892385e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(9.1159452679e-01, 4.4202736607e-02, 1.8952405706e+00),
|
||||
/* 2k Hz*/
|
||||
new IIRCoefficients(8.3100647694e-01, 8.4496761532e-02, 1.7686164442e+00),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(6.9062328809e-01, 1.5468835596e-01, 1.4641227157e+00),
|
||||
/* 8k Hz*/
|
||||
new IIRCoefficients(4.7820368352e-01, 2.6089815824e-01, 7.3910184176e-01),
|
||||
/* 16k Hz*/
|
||||
new IIRCoefficients(2.5620076154e-01, 3.7189961923e-01, -6.2810038077e-01)
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf15_44100[] = {
|
||||
/* 25 Hz*/
|
||||
new IIRCoefficients(9.9834072702e-01, 8.2963648917e-04, 1.9983280505e+00),
|
||||
/* 40 Hz*/
|
||||
new IIRCoefficients(9.9734652663e-01, 1.3267366865e-03, 1.9973140908e+00),
|
||||
/* 63 Hz*/
|
||||
new IIRCoefficients(9.9582396353e-01, 2.0880182333e-03, 1.9957435641e+00),
|
||||
/* 100 Hz*/
|
||||
new IIRCoefficients(9.9337951306e-01, 3.3102434709e-03, 1.9931771947e+00),
|
||||
/* 160 Hz*/
|
||||
new IIRCoefficients(9.8942832039e-01, 5.2858398053e-03, 1.9889114258e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.8353109588e-01, 8.2344520610e-03, 1.9822729654e+00),
|
||||
/* 400 Hz*/
|
||||
new IIRCoefficients(9.7378088082e-01, 1.3109559588e-02, 1.9705764276e+00),
|
||||
/* 630 Hz*/
|
||||
new IIRCoefficients(9.5901979676e-01, 2.0490101620e-02, 1.9511333590e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(9.3574903986e-01, 3.2125480071e-02, 1.9161350100e+00),
|
||||
/* 1.6k Hz*/
|
||||
new IIRCoefficients(8.9923630641e-01, 5.0381846793e-02, 1.8501014162e+00),
|
||||
/* 2.5k Hz*/
|
||||
new IIRCoefficients(8.4722457681e-01, 7.6387711593e-02, 1.7312785699e+00),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(7.6755471307e-01, 1.1622264346e-01, 1.4881981417e+00),
|
||||
/* 6.3k Hz*/
|
||||
new IIRCoefficients(6.6125377473e-01, 1.6937311263e-01, 1.0357747868e+00),
|
||||
/* 10k Hz*/
|
||||
new IIRCoefficients(5.2683267950e-01, 2.3658366025e-01, 2.2218349322e-01),
|
||||
/* 16k Hz*/
|
||||
new IIRCoefficients(4.0179628792e-01, 2.9910185604e-01, -9.1248032613e-01)
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf15_48000[] = {
|
||||
/* 25 Hz*/
|
||||
new IIRCoefficients(9.9847546664e-01, 7.6226668143e-04, 1.9984647656e+00),
|
||||
/* 40 Hz*/
|
||||
new IIRCoefficients(9.9756184654e-01, 1.2190767289e-03, 1.9975344645e+00),
|
||||
/* 63 Hz*/
|
||||
new IIRCoefficients(9.9616261379e-01, 1.9186931041e-03, 1.9960947369e+00),
|
||||
/* 100 Hz*/
|
||||
new IIRCoefficients(9.9391578543e-01, 3.0421072865e-03, 1.9937449618e+00),
|
||||
/* 160 Hz*/
|
||||
new IIRCoefficients(9.9028307215e-01, 4.8584639242e-03, 1.9898465702e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.8485897264e-01, 7.5705136795e-03, 1.9837962543e+00),
|
||||
/* 400 Hz*/
|
||||
new IIRCoefficients(9.7588512657e-01, 1.2057436715e-02, 1.9731772447e+00),
|
||||
/* 630 Hz*/
|
||||
new IIRCoefficients(9.6228521814e-01, 1.8857390928e-02, 1.9556164694e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(9.4080933132e-01, 2.9595334338e-02, 1.9242054384e+00),
|
||||
/* 1.6k Hz*/
|
||||
new IIRCoefficients(9.0702059196e-01, 4.6489704022e-02, 1.8653476166e+00),
|
||||
/* 2.5k Hz*/
|
||||
new IIRCoefficients(8.5868004289e-01, 7.0659978553e-02, 1.7600401337e+00),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(7.8409610788e-01, 1.0795194606e-01, 1.5450725522e+00),
|
||||
/* 6.3k Hz*/
|
||||
new IIRCoefficients(6.8332861002e-01, 1.5833569499e-01, 1.1426447155e+00),
|
||||
/* 10k Hz*/
|
||||
new IIRCoefficients(5.5267518228e-01, 2.2366240886e-01, 4.0186190803e-01),
|
||||
/* 16k Hz*/
|
||||
new IIRCoefficients(4.1811888447e-01, 2.9094055777e-01, -7.0905944223e-01)
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf25_44100[] = {
|
||||
/* 20 Hz*/
|
||||
new IIRCoefficients(9.9934037157e-01, 3.2981421662e-04, 1.9993322545e+00),
|
||||
/* 31.5 Hz*/
|
||||
new IIRCoefficients(9.9896129025e-01, 5.1935487310e-04, 1.9989411587e+00),
|
||||
/* 40 Hz*/
|
||||
new IIRCoefficients(9.9868118265e-01, 6.5940867495e-04, 1.9986487252e+00),
|
||||
/* 50 Hz*/
|
||||
new IIRCoefficients(9.9835175161e-01, 8.2412419683e-04, 1.9983010452e+00),
|
||||
/* 80 Hz*/
|
||||
new IIRCoefficients(9.9736411067e-01, 1.3179446674e-03, 1.9972343673e+00),
|
||||
/* 100 Hz*/
|
||||
new IIRCoefficients(9.9670622662e-01, 1.6468866919e-03, 1.9965035707e+00),
|
||||
/* 125 Hz*/
|
||||
new IIRCoefficients(9.9588448566e-01, 2.0577571681e-03, 1.9955679690e+00),
|
||||
/* 160 Hz*/
|
||||
new IIRCoefficients(9.9473519326e-01, 2.6324033689e-03, 1.9942169198e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.9178600786e-01, 4.1069960678e-03, 1.9905226414e+00),
|
||||
/* 315 Hz*/
|
||||
new IIRCoefficients(9.8966154150e-01, 5.1692292513e-03, 1.9876580847e+00),
|
||||
/* 400 Hz*/
|
||||
new IIRCoefficients(9.8689036168e-01, 6.5548191616e-03, 1.9836646251e+00),
|
||||
/* 500 Hz*/
|
||||
new IIRCoefficients(9.8364027156e-01, 8.1798642207e-03, 1.9786090689e+00),
|
||||
/* 800 Hz*/
|
||||
new IIRCoefficients(9.7395577681e-01, 1.3022111597e-02, 1.9611472340e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(9.6755437936e-01, 1.6222810321e-02, 1.9476180811e+00),
|
||||
/* 1.25k Hz*/
|
||||
new IIRCoefficients(9.5961458750e-01, 2.0192706249e-02, 1.9286193446e+00),
|
||||
/* 1.6k Hz*/
|
||||
new IIRCoefficients(9.4861481164e-01, 2.5692594182e-02, 1.8982024567e+00),
|
||||
/* 2.5k Hz*/
|
||||
new IIRCoefficients(9.2095325455e-01, 3.9523372724e-02, 1.8003794694e+00),
|
||||
/* 3.15k Hz*/
|
||||
new IIRCoefficients(9.0153642498e-01, 4.9231787512e-02, 1.7132251201e+00),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(8.7685876255e-01, 6.1570618727e-02, 1.5802270232e+00),
|
||||
/* 5k Hz*/
|
||||
new IIRCoefficients(8.4886734822e-01, 7.5566325889e-02, 1.3992391376e+00),
|
||||
/* 8k Hz*/
|
||||
new IIRCoefficients(7.7175298860e-01, 1.1412350570e-01, 7.4018523020e-01),
|
||||
/* 10k Hz*/
|
||||
new IIRCoefficients(7.2627049462e-01, 1.3686475269e-01, 2.5120552756e-01),
|
||||
/* 12.5k Hz*/
|
||||
new IIRCoefficients(6.7674787974e-01, 1.6162606013e-01, -3.4978377639e-01),
|
||||
/* 16k Hz*/
|
||||
new IIRCoefficients(6.2482197550e-01, 1.8758901225e-01, -1.0576558797e+00),
|
||||
/* 20k Hz*/
|
||||
new IIRCoefficients(6.1776148240e-01, 1.9111925880e-01, -1.5492465594e+00)
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf25_48000[] = {
|
||||
/* 20 Hz*/
|
||||
new IIRCoefficients(9.9939388451e-01, 3.0305774630e-04, 1.9993870327e+00),
|
||||
/* 31.5 Hz*/
|
||||
new IIRCoefficients(9.9904564663e-01, 4.7717668529e-04, 1.9990286528e+00),
|
||||
/* 40 Hz*/
|
||||
new IIRCoefficients(9.9878827195e-01, 6.0586402557e-04, 1.9987608731e+00),
|
||||
/* 50 Hz*/
|
||||
new IIRCoefficients(9.9848556942e-01, 7.5721528829e-04, 1.9984427652e+00),
|
||||
/* 80 Hz*/
|
||||
new IIRCoefficients(9.9757801538e-01, 1.2109923088e-03, 1.9974684869e+00),
|
||||
/* 100 Hz*/
|
||||
new IIRCoefficients(9.9697343933e-01, 1.5132803374e-03, 1.9968023538e+00),
|
||||
/* 125 Hz*/
|
||||
new IIRCoefficients(9.9621823598e-01, 1.8908820086e-03, 1.9959510180e+00),
|
||||
/* 160 Hz*/
|
||||
new IIRCoefficients(9.9516191728e-01, 2.4190413595e-03, 1.9947243453e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.9245085008e-01, 3.7745749576e-03, 1.9913840669e+00),
|
||||
/* 315 Hz*/
|
||||
new IIRCoefficients(9.9049749914e-01, 4.7512504310e-03, 1.9888056233e+00),
|
||||
/* 400 Hz*/
|
||||
new IIRCoefficients(9.8794899744e-01, 6.0255012789e-03, 1.9852245824e+00),
|
||||
/* 500 Hz*/
|
||||
new IIRCoefficients(9.8495930023e-01, 7.5203498850e-03, 1.9807093500e+00),
|
||||
/* 800 Hz*/
|
||||
new IIRCoefficients(9.7604570090e-01, 1.1977149551e-02, 1.9652207158e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(9.7014963927e-01, 1.4925180364e-02, 1.9532947360e+00),
|
||||
/* 1.25k Hz*/
|
||||
new IIRCoefficients(9.6283181641e-01, 1.8584091793e-02, 1.9366149237e+00),
|
||||
/* 1.6k Hz*/
|
||||
new IIRCoefficients(9.5268463224e-01, 2.3657683878e-02, 1.9100137880e+00),
|
||||
/* 2.5k Hz*/
|
||||
new IIRCoefficients(9.2711765003e-01, 3.6441174983e-02, 1.8248457659e+00),
|
||||
/* 3.15k Hz*/
|
||||
new IIRCoefficients(9.0912548757e-01, 4.5437256213e-02, 1.7491177803e+00),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(8.8619860800e-01, 5.6900696000e-02, 1.6334959111e+00),
|
||||
/* 5k Hz*/
|
||||
new IIRCoefficients(8.6010264114e-01, 6.9948679430e-02, 1.4757186436e+00),
|
||||
/* 8k Hz*/
|
||||
new IIRCoefficients(7.8757448309e-01, 1.0621275845e-01, 8.9378724155e-01),
|
||||
/* 10k Hz*/
|
||||
new IIRCoefficients(7.4415362476e-01, 1.2792318762e-01, 4.5142017567e-01),
|
||||
/* 12.5k Hz*/
|
||||
new IIRCoefficients(6.9581428034e-01, 1.5209285983e-01, -1.1091156053e-01),
|
||||
/* 16k Hz*/
|
||||
new IIRCoefficients(6.4120506488e-01, 1.7939746756e-01, -8.2060253244e-01),
|
||||
/* 20k Hz*/
|
||||
new IIRCoefficients(6.0884213704e-01, 1.9557893148e-01, -1.3932981614e+00)
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf31_44100[] = {
|
||||
/* 20 Hz*/
|
||||
new IIRCoefficients(9.9934037157e-01, 3.2981421662e-04, 1.9993322545e+00),
|
||||
/* 25 Hz*/
|
||||
new IIRCoefficients(9.9917555233e-01, 4.1222383516e-04, 1.9991628705e+00),
|
||||
/* 31.5 Hz*/
|
||||
new IIRCoefficients(9.9896129025e-01, 5.1935487310e-04, 1.9989411587e+00),
|
||||
/* 40 Hz*/
|
||||
new IIRCoefficients(9.9868118265e-01, 6.5940867495e-04, 1.9986487252e+00),
|
||||
/* 50 Hz*/
|
||||
new IIRCoefficients(9.9835175161e-01, 8.2412419683e-04, 1.9983010452e+00),
|
||||
/* 63 Hz*/
|
||||
new IIRCoefficients(9.9792365217e-01, 1.0381739160e-03, 1.9978431682e+00),
|
||||
/* 80 Hz*/
|
||||
new IIRCoefficients(9.9736411067e-01, 1.3179446674e-03, 1.9972343673e+00),
|
||||
/* 100 Hz*/
|
||||
new IIRCoefficients(9.9670622662e-01, 1.6468866919e-03, 1.9965035707e+00),
|
||||
/* 125 Hz*/
|
||||
new IIRCoefficients(9.9588448566e-01, 2.0577571681e-03, 1.9955679690e+00),
|
||||
/* 160 Hz*/
|
||||
new IIRCoefficients(9.9473519326e-01, 2.6324033689e-03, 1.9942169198e+00),
|
||||
/* 200 Hz*/
|
||||
new IIRCoefficients(9.9342335280e-01, 3.2883236020e-03, 1.9926141028e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.9178600786e-01, 4.1069960678e-03, 1.9905226414e+00),
|
||||
/* 315 Hz*/
|
||||
new IIRCoefficients(9.8966154150e-01, 5.1692292513e-03, 1.9876580847e+00),
|
||||
/* 400 Hz*/
|
||||
new IIRCoefficients(9.8689036168e-01, 6.5548191616e-03, 1.9836646251e+00),
|
||||
/* 500 Hz*/
|
||||
new IIRCoefficients(9.8364027156e-01, 8.1798642207e-03, 1.9786090689e+00),
|
||||
/* 630 Hz*/
|
||||
new IIRCoefficients(9.7943153305e-01, 1.0284233476e-02, 1.9714629236e+00),
|
||||
/* 800 Hz*/
|
||||
new IIRCoefficients(9.7395577681e-01, 1.3022111597e-02, 1.9611472340e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(9.6755437936e-01, 1.6222810321e-02, 1.9476180811e+00),
|
||||
/* 1.25k Hz*/
|
||||
new IIRCoefficients(9.5961458750e-01, 2.0192706249e-02, 1.9286193446e+00),
|
||||
/* 1.6k Hz*/
|
||||
new IIRCoefficients(9.4861481164e-01, 2.5692594182e-02, 1.8982024567e+00),
|
||||
/* 2k Hz*/
|
||||
new IIRCoefficients(9.3620971896e-01, 3.1895140519e-02, 1.8581325022e+00),
|
||||
/* 2.5k Hz*/
|
||||
new IIRCoefficients(9.2095325455e-01, 3.9523372724e-02, 1.8003794694e+00),
|
||||
/* 3.15k Hz*/
|
||||
new IIRCoefficients(9.0153642498e-01, 4.9231787512e-02, 1.7132251201e+00),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(8.7685876255e-01, 6.1570618727e-02, 1.5802270232e+00),
|
||||
/* 5k Hz*/
|
||||
new IIRCoefficients(8.4886734822e-01, 7.5566325889e-02, 1.3992391376e+00),
|
||||
/* 6.3k Hz*/
|
||||
new IIRCoefficients(8.1417575446e-01, 9.2912122771e-02, 1.1311200817e+00),
|
||||
/* 8k Hz*/
|
||||
new IIRCoefficients(7.7175298860e-01, 1.1412350570e-01, 7.4018523020e-01),
|
||||
/* 10k Hz*/
|
||||
new IIRCoefficients(7.2627049462e-01, 1.3686475269e-01, 2.5120552756e-01),
|
||||
/* 12.5k Hz*/
|
||||
new IIRCoefficients(6.7674787974e-01, 1.6162606013e-01, -3.4978377639e-01),
|
||||
/* 16k Hz*/
|
||||
new IIRCoefficients(6.2482197550e-01, 1.8758901225e-01, -1.0576558797e+00),
|
||||
/* 20k Hz*/
|
||||
new IIRCoefficients(6.1776148240e-01, 1.9111925880e-01, -1.5492465594e+00)
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf31_48000[] = {
|
||||
/* 20 Hz*/
|
||||
new IIRCoefficients(9.9939388451e-01, 3.0305774630e-04, 1.9993870327e+00),
|
||||
/* 25 Hz*/
|
||||
new IIRCoefficients(9.9924247917e-01, 3.7876041632e-04, 1.9992317740e+00),
|
||||
/* 31.5 Hz*/
|
||||
new IIRCoefficients(9.9904564663e-01, 4.7717668529e-04, 1.9990286528e+00),
|
||||
/* 40 Hz*/
|
||||
new IIRCoefficients(9.9878827195e-01, 6.0586402557e-04, 1.9987608731e+00),
|
||||
/* 50 Hz*/
|
||||
new IIRCoefficients(9.9848556942e-01, 7.5721528829e-04, 1.9984427652e+00),
|
||||
/* 63 Hz*/
|
||||
new IIRCoefficients(9.9809219264e-01, 9.5390367779e-04, 1.9980242502e+00),
|
||||
/* 80 Hz*/
|
||||
new IIRCoefficients(9.9757801538e-01, 1.2109923088e-03, 1.9974684869e+00),
|
||||
/* 100 Hz*/
|
||||
new IIRCoefficients(9.9697343933e-01, 1.5132803374e-03, 1.9968023538e+00),
|
||||
/* 125 Hz*/
|
||||
new IIRCoefficients(9.9621823598e-01, 1.8908820086e-03, 1.9959510180e+00),
|
||||
/* 160 Hz*/
|
||||
new IIRCoefficients(9.9516191728e-01, 2.4190413595e-03, 1.9947243453e+00),
|
||||
/* 200 Hz*/
|
||||
new IIRCoefficients(9.9395607757e-01, 3.0219612131e-03, 1.9932727986e+00),
|
||||
/* 250 Hz*/
|
||||
new IIRCoefficients(9.9245085008e-01, 3.7745749576e-03, 1.9913840669e+00),
|
||||
/* 315 Hz*/
|
||||
new IIRCoefficients(9.9049749914e-01, 4.7512504310e-03, 1.9888056233e+00),
|
||||
/* 400 Hz*/
|
||||
new IIRCoefficients(9.8794899744e-01, 6.0255012789e-03, 1.9852245824e+00),
|
||||
/* 500 Hz*/
|
||||
new IIRCoefficients(9.8495930023e-01, 7.5203498850e-03, 1.9807093500e+00),
|
||||
/* 630 Hz*/
|
||||
new IIRCoefficients(9.8108651246e-01, 9.4567437704e-03, 1.9743538683e+00),
|
||||
/* 800 Hz*/
|
||||
new IIRCoefficients(9.7604570090e-01, 1.1977149551e-02, 1.9652207158e+00),
|
||||
/* 1k Hz*/
|
||||
new IIRCoefficients(9.7014963927e-01, 1.4925180364e-02, 1.9532947360e+00),
|
||||
/* 1.25k Hz*/
|
||||
new IIRCoefficients(9.6283181641e-01, 1.8584091793e-02, 1.9366149237e+00),
|
||||
/* 1.6k Hz*/
|
||||
new IIRCoefficients(9.5268463224e-01, 2.3657683878e-02, 1.9100137880e+00),
|
||||
/* 2k Hz*/
|
||||
new IIRCoefficients(9.4122788957e-01, 2.9386055213e-02, 1.8750821533e+00),
|
||||
/* 2.5k Hz*/
|
||||
new IIRCoefficients(9.2711765003e-01, 3.6441174983e-02, 1.8248457659e+00),
|
||||
/* 3.15k Hz*/
|
||||
new IIRCoefficients(9.0912548757e-01, 4.5437256213e-02, 1.7491177803e+00),
|
||||
/* 4k Hz*/
|
||||
new IIRCoefficients(8.8619860800e-01, 5.6900696000e-02, 1.6334959111e+00),
|
||||
/* 5k Hz*/
|
||||
new IIRCoefficients(8.6010264114e-01, 6.9948679430e-02, 1.4757186436e+00),
|
||||
/* 6.3k Hz*/
|
||||
new IIRCoefficients(8.2760520925e-01, 8.6197395374e-02, 1.2405797786e+00),
|
||||
/* 8k Hz*/
|
||||
new IIRCoefficients(7.8757448309e-01, 1.0621275845e-01, 8.9378724155e-01),
|
||||
/* 10k Hz*/
|
||||
new IIRCoefficients(7.4415362476e-01, 1.2792318762e-01, 4.5142017567e-01),
|
||||
/* 12.5k Hz*/
|
||||
new IIRCoefficients(6.9581428034e-01, 1.5209285983e-01, -1.1091156053e-01),
|
||||
/* 16k Hz*/
|
||||
new IIRCoefficients(6.4120506488e-01, 1.7939746756e-01, -8.2060253244e-01),
|
||||
/* 20k Hz*/
|
||||
new IIRCoefficients(6.0884213704e-01, 1.9557893148e-01, -1.3932981614e+00),
|
||||
};
|
||||
|
||||
public final static IIRCoefficients iir_cf31_96000[] = {
|
||||
/* 20.0 Hz */
|
||||
new IIRCoefficients(9.9969659208e-01, 1.517040e-04, 1.9996948789e+00),
|
||||
/* 25.0 Hz */
|
||||
new IIRCoefficients(9.9962116126e-01, 1.894194e-04, 1.9996184845e+00),
|
||||
/* 31.5 Hz */
|
||||
new IIRCoefficients(9.9952283343e-01, 2.385833e-04, 1.9995185840e+00),
|
||||
/* 40.0 Hz */
|
||||
new IIRCoefficients(9.9939398196e-01, 3.030090e-04, 1.9993871301e+00),
|
||||
/* 50.0 Hz */
|
||||
new IIRCoefficients(9.9924251688e-01, 3.787416e-04, 1.9992318117e+00),
|
||||
/* 63.0 Hz */
|
||||
new IIRCoefficients(9.9904565182e-01, 4.771741e-04, 1.9990286580e+00),
|
||||
/* 80.0 Hz */
|
||||
new IIRCoefficients(9.9878828573e-01, 6.058571e-04, 1.9987608868e+00),
|
||||
/* 100.0 Hz */
|
||||
new IIRCoefficients(9.9848557077e-01, 7.572146e-04, 1.9984427665e+00),
|
||||
/* 125.0 Hz */
|
||||
new IIRCoefficients(9.9810732562e-01, 9.463372e-04, 1.9980404568e+00),
|
||||
/* 160.0 Hz */
|
||||
new IIRCoefficients(9.9757801618e-01, 1.210992e-03, 1.9974684877e+00),
|
||||
/* 200.0 Hz */
|
||||
new IIRCoefficients(9.9697343858e-01, 1.513281e-03, 1.9968023530e+00),
|
||||
/* 250.0 Hz */
|
||||
new IIRCoefficients(9.9621823615e-01, 1.890882e-03, 1.9959510182e+00),
|
||||
/* 315.0 Hz */
|
||||
new IIRCoefficients(9.9523733132e-01, 2.381334e-03, 1.9948133101e+00),
|
||||
/* 400.0 Hz */
|
||||
new IIRCoefficients(9.9395607744e-01, 3.021961e-03, 1.9932727985e+00),
|
||||
/* 500.0 Hz */
|
||||
new IIRCoefficients(9.9245084999e-01, 3.774575e-03, 1.9913840669e+00),
|
||||
/* 630.0 Hz */
|
||||
new IIRCoefficients(9.9049749915e-01, 4.751250e-03, 1.9888056234e+00),
|
||||
/* 800.0 Hz */
|
||||
new IIRCoefficients(9.8794899744e-01, 6.025501e-03, 1.9852245824e+00),
|
||||
/* 1000.0 Hz */
|
||||
new IIRCoefficients(9.8495930024e-01, 7.520350e-03, 1.9807093500e+00),
|
||||
/* 1250.0 Hz */
|
||||
new IIRCoefficients(9.8123517675e-01, 9.382412e-03, 1.9746084192e+00),
|
||||
/* 1600.0 Hz */
|
||||
new IIRCoefficients(9.7604570090e-01, 1.197715e-02, 1.9652207158e+00),
|
||||
/* 2000.0 Hz */
|
||||
new IIRCoefficients(9.7014963927e-01, 1.492518e-02, 1.9532947360e+00),
|
||||
/* 2500.0 Hz */
|
||||
new IIRCoefficients(9.6283181641e-01, 1.858409e-02, 1.9366149237e+00),
|
||||
/* 3150.0 Hz */
|
||||
new IIRCoefficients(9.5340564248e-01, 2.329718e-02, 1.9120378855e+00),
|
||||
/* 4000.0 Hz */
|
||||
new IIRCoefficients(9.4122788957e-01, 2.938606e-02, 1.8750821533e+00),
|
||||
/* 5000.0 Hz */
|
||||
new IIRCoefficients(9.2711765003e-01, 3.644117e-02, 1.8248457659e+00),
|
||||
/* 6300.0 Hz */
|
||||
new IIRCoefficients(9.0912548757e-01, 4.543726e-02, 1.7491177803e+00),
|
||||
/* 8000.0 Hz */
|
||||
new IIRCoefficients(8.8619860800e-01, 5.690070e-02, 1.6334959111e+00),
|
||||
/* 10000.0 Hz */
|
||||
new IIRCoefficients(8.6010264114e-01, 6.994868e-02, 1.4757186436e+00),
|
||||
/* 12500.0 Hz */
|
||||
new IIRCoefficients(8.2882509035e-01, 8.558745e-02, 1.2501707535e+00),
|
||||
/* 16000.0 Hz */
|
||||
new IIRCoefficients(7.8757448309e-01, 1.062128e-01, 8.9378724155e-01),
|
||||
/* 20000.0 Hz */
|
||||
new IIRCoefficients(7.4415362476e-01, 1.279232e-01, 4.5142017567e-01),
|
||||
};
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 21.04.2004 Original verion. davagin@udm.ru.
|
||||
*-----------------------------------------------------------------------
|
||||
* 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.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
package davaguine.jeq.core;
|
||||
|
||||
/**
|
||||
* Author: Dmitry Vaguine
|
||||
* Date: 02.05.2004
|
||||
* Time: 12:00:29
|
||||
*/
|
||||
public class IIRCoefficients {
|
||||
public double beta;
|
||||
public double alpha;
|
||||
public double gamma;
|
||||
|
||||
public IIRCoefficients(double beta, double alpha, double gamma) {
|
||||
this.beta = beta;
|
||||
this.alpha = alpha;
|
||||
this.gamma = gamma;
|
||||
}
|
||||
}
|
||||
@@ -1,214 +0,0 @@
|
||||
/*
|
||||
* 21.04.2004 Original verion. davagin@udm.ru.
|
||||
*-----------------------------------------------------------------------
|
||||
* 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.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
package davaguine.jeq.core;
|
||||
|
||||
/**
|
||||
* Constols of equalizer
|
||||
* Author: Dmitry Vaguine
|
||||
* Date: 02.05.2004
|
||||
* Time: 12:00:29
|
||||
*/
|
||||
public class IIRControls {
|
||||
/**
|
||||
* Volume gain
|
||||
* values should be between 0.0 and 1.0
|
||||
*/
|
||||
private float preamp[];
|
||||
/**
|
||||
* Gain for each band
|
||||
* values should be between -0.2 and 1.0
|
||||
*/
|
||||
private float bands[][];
|
||||
|
||||
/**
|
||||
* Creates new IIRControls object for given number of bands
|
||||
*
|
||||
* @param bandsnum is the number of bands
|
||||
* @param channels is the number of channels
|
||||
*/
|
||||
public IIRControls(int bandsnum, int channels) {
|
||||
preamp = new float[channels];
|
||||
bands = new float[bandsnum][channels];
|
||||
for (int j = 0; j < channels; j++) {
|
||||
preamp[j] = 1.0f;
|
||||
for (int i = 0; i < bandsnum; i++)
|
||||
bands[i][j] = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum value for band control
|
||||
*
|
||||
* @return the maximum value for band control
|
||||
*/
|
||||
public float getMaximumBandValue() {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum value for band control
|
||||
*
|
||||
* @return the minimum value for band control
|
||||
*/
|
||||
public float getMinimumBandValue() {
|
||||
return -0.2f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum value for band control (in Db)
|
||||
*
|
||||
* @return the maximum value for band control
|
||||
*/
|
||||
public float getMaximumBandDbValue() {
|
||||
return 12;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum value for band control (in Db)
|
||||
*
|
||||
* @return the minimum value for band control
|
||||
*/
|
||||
public float getMinimumBandDbValue() {
|
||||
return -12f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum value for preamp control
|
||||
*
|
||||
* @return the maximum value for preamp control
|
||||
*/
|
||||
public float getMaximumPreampValue() {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum value for preamp control
|
||||
*
|
||||
* @return the minimum value for preamp control
|
||||
*/
|
||||
public float getMinimumPreampValue() {
|
||||
return 0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum value for preamp control (in Db)
|
||||
*
|
||||
* @return the maximum value for preamp control
|
||||
*/
|
||||
public float getMaximumPreampDbValue() {
|
||||
return 12f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum value for preamp control (in Db)
|
||||
*
|
||||
* @return the minimum value for preamp control
|
||||
*/
|
||||
public float getMinimumPreampDbValue() {
|
||||
return -12f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns bands array
|
||||
*
|
||||
* @return bands array
|
||||
*/
|
||||
float[][] getBands() {
|
||||
return bands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns preamp array
|
||||
*
|
||||
* @return preamp array
|
||||
*/
|
||||
float[] getPreamp() {
|
||||
return preamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of control for given band and channel
|
||||
*
|
||||
* @param band is the index of band
|
||||
* @param channel is the index of channel
|
||||
* @return the value
|
||||
*/
|
||||
public float getBandValue(int band, int channel) {
|
||||
return bands[band][channel];
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for value of control for given band and channel
|
||||
*
|
||||
* @param band is the index of band
|
||||
* @param channel is the index of channel
|
||||
* @param value is the new value
|
||||
*/
|
||||
public void setBandValue(int band, int channel, float value) {
|
||||
bands[band][channel] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for value of control for given band and channel (in Db)
|
||||
*
|
||||
* @param band is the index of band
|
||||
* @param channel is the index of channel
|
||||
* @param value is the new value
|
||||
*/
|
||||
public void setBandDbValue(int band, int channel, float value) {
|
||||
/* Map the gain and preamp values */
|
||||
/* -12dB .. 12dB mapping */
|
||||
bands[band][channel] = (float) (2.5220207857061455181125E-01 *
|
||||
Math.exp(8.0178361802353992349168E-02 * value)
|
||||
- 2.5220207852836562523180E-01);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns value of preamp control for given channel
|
||||
*
|
||||
* @param channel is the index of channel
|
||||
* @return the value
|
||||
*/
|
||||
public float getPreampValue(int channel) {
|
||||
return preamp[channel];
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for value of preamp control for given channel
|
||||
*
|
||||
* @param channel is the index of channel
|
||||
* @param value is the new value
|
||||
*/
|
||||
public void setPreampValue(int channel, float value) {
|
||||
preamp[channel] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for value of preamp control for given channel (in Db)
|
||||
*
|
||||
* @param channel is the index of channel
|
||||
* @param value is the new value
|
||||
*/
|
||||
public void setPreampDbValue(int channel, float value) {
|
||||
/* -12dB .. 12dB mapping */
|
||||
preamp[channel] = (float) (9.9999946497217584440165E-01 *
|
||||
Math.exp(6.9314738656671842642609E-02 * value)
|
||||
+ 3.7119444716771825623636E-07);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* 21.04.2004 Original verion. davagin@udm.ru.
|
||||
*-----------------------------------------------------------------------
|
||||
* 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.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
package davaguine.jeq.core;
|
||||
|
||||
/**
|
||||
* Structure for storing XYData of equalizer.
|
||||
* Author: Dmitry Vaguine
|
||||
* Date: 02.05.2004
|
||||
* Time: 12:00:29
|
||||
*/
|
||||
public class XYData {
|
||||
/**
|
||||
* X data
|
||||
*/
|
||||
public double x[] = new double[3]; /* x[n], x[n-1], x[n-2] */
|
||||
/**
|
||||
* Y data
|
||||
*/
|
||||
public double y[] = new double[3]; /* y[n], y[n-1], y[n-2] */
|
||||
|
||||
/**
|
||||
* Constructs new XYData object
|
||||
*/
|
||||
public XYData() {
|
||||
zero();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills all content with zero
|
||||
*/
|
||||
public void zero() {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
x[i] = 0;
|
||||
y[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,265 +0,0 @@
|
||||
/*
|
||||
* 21.04.2004 Original verion. davagin@udm.ru.
|
||||
*-----------------------------------------------------------------------
|
||||
* 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.
|
||||
*----------------------------------------------------------------------
|
||||
*/
|
||||
package davaguine.jeq.spi;
|
||||
|
||||
import davaguine.jeq.core.IIRControls;
|
||||
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.sound.sampled.AudioInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* The EqualizerInputStream input stream
|
||||
* Author: Dmitry Vaguine
|
||||
* Date: 02.05.2004
|
||||
* Time: 12:00:29
|
||||
*/
|
||||
public class EqualizerInputStream extends AudioInputStream {
|
||||
private davaguine.jeq.core.EqualizerInputStream eq;
|
||||
|
||||
/**
|
||||
* Constructs new audio stream
|
||||
*
|
||||
* @param stream input stream with audio data
|
||||
* @param bands is the number of bands
|
||||
*/
|
||||
public EqualizerInputStream(AudioInputStream stream, int bands) {
|
||||
super(stream, stream.getFormat(), stream.getFrameLength());
|
||||
AudioFormat format = stream.getFormat();
|
||||
if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED) && !!format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED))
|
||||
throw new IllegalArgumentException("Unsupported encoding");
|
||||
eq = new davaguine.jeq.core.EqualizerInputStream(stream,
|
||||
format.getSampleRate(),
|
||||
format.getChannels(),
|
||||
format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED),
|
||||
format.getSampleSizeInBits(),
|
||||
format.isBigEndian(),
|
||||
bands);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Controls of equalizer
|
||||
*
|
||||
* @return Controls of equalizer
|
||||
*/
|
||||
public IIRControls getControls() {
|
||||
return eq.getControls();
|
||||
}
|
||||
|
||||
/**
|
||||
* This is special method helps to determine supported audio format
|
||||
*
|
||||
* @param format is an audio format
|
||||
* @param bands is the number of bands
|
||||
* @return true if params supported
|
||||
*/
|
||||
public static boolean isParamsSupported(AudioFormat format, int bands) {
|
||||
if (!format.getEncoding().equals(AudioFormat.Encoding.PCM_SIGNED) && !!format.getEncoding().equals(AudioFormat.Encoding.PCM_UNSIGNED))
|
||||
return false;
|
||||
return davaguine.jeq.core.EqualizerInputStream.isParamsSupported(
|
||||
format.getSampleRate(),
|
||||
format.getChannels(),
|
||||
format.getSampleSizeInBits(),
|
||||
bands);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of bytes that can be read (or skipped over) from
|
||||
* this input stream without blocking by the next caller of a method for
|
||||
* this input stream. The next caller might be the same thread or
|
||||
* another thread.
|
||||
*
|
||||
* @return the number of bytes that can be read from this input stream
|
||||
* without blocking.
|
||||
* @throws java.io.IOException if an I/O error occurs.
|
||||
*/
|
||||
public int available() throws IOException {
|
||||
return eq.available();
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes this input stream and releases any system resources associated
|
||||
* with the stream.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public void close() throws IOException {
|
||||
eq.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p> The <code>mark</code> method of <code>EqualizerInputStream</code> does
|
||||
* nothing.
|
||||
*
|
||||
* @param readlimit the maximum limit of bytes that can be read before
|
||||
* the mark position becomes invalid.
|
||||
*/
|
||||
public synchronized void mark(int readlimit) {
|
||||
eq.mark(readlimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if this input stream supports the <code>mark</code> and
|
||||
* <code>reset</code> methods. Whether or not <code>mark</code> and
|
||||
* <code>reset</code> are supported is an invariant property of a
|
||||
* particular input stream instance. The <code>markSupported</code> method
|
||||
* of <code>EqualizerInputStream</code> returns <code>false</code>.
|
||||
*
|
||||
* @return false
|
||||
*/
|
||||
public boolean markSupported() {
|
||||
return eq.markSupported();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the next byte of data from the input stream. The value byte is
|
||||
* returned as an <code>int</code> in the range <code>0</code> to
|
||||
* <code>255</code>. If no byte is available because the end of the stream
|
||||
* has been reached, the value <code>-1</code> is returned. This method
|
||||
* blocks until input data is available, the end of the stream is detected,
|
||||
* or an exception is thrown.
|
||||
*
|
||||
* @return the next byte of data, or <code>-1</code> if the end of the
|
||||
* stream is reached.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public int read() throws IOException {
|
||||
return eq.read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads some number of bytes from the input stream and stores them into
|
||||
* the buffer array <code>b</code>. The number of bytes actually read is
|
||||
* returned as an integer. This method blocks until input data is
|
||||
* available, end of file is detected, or an exception is thrown.
|
||||
* <p/>
|
||||
* <p> If <code>b</code> is <code>null</code>, a
|
||||
* <code>NullPointerException</code> is thrown. If the length of
|
||||
* <code>b</code> is zero, then no bytes are read and <code>0</code> is
|
||||
* returned; otherwise, there is an attempt to read at least one byte. If
|
||||
* no byte is available because the stream is at end of file, the value
|
||||
* <code>-1</code> is returned; otherwise, at least one byte is read and
|
||||
* stored into <code>b</code>.
|
||||
* <p/>
|
||||
* <p> The first byte read is stored into element <code>b[0]</code>, the
|
||||
* next one into <code>b[1]</code>, and so on. The number of bytes read is,
|
||||
* at most, equal to the length of <code>b</code>. Let <i>k</i> be the
|
||||
* number of bytes actually read; these bytes will be stored in elements
|
||||
* <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
|
||||
* leaving elements <code>b[</code><i>k</i><code>]</code> through
|
||||
* <code>b[b.length-1]</code> unaffected.
|
||||
* <p/>
|
||||
* <p> If the first byte cannot be read for any reason other than end of
|
||||
* file, then an <code>IOException</code> is thrown. In particular, an
|
||||
* <code>IOException</code> is thrown if the input stream has been closed.
|
||||
* <p/>
|
||||
* <p> The <code>read(b)</code> method for class <code>EqualizerInputStream</code>
|
||||
* has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* <code>-1</code> is there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws NullPointerException if <code>b</code> is <code>null</code>.
|
||||
*/
|
||||
public int read(byte b[]) throws IOException {
|
||||
return read(b, 0, b.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads up to <code>len</code> bytes of data from the input stream into
|
||||
* an array of bytes. An attempt is made to read as many as
|
||||
* <code>len</code> bytes, but a smaller number may be read.
|
||||
* The number of bytes actually read is returned as an integer.
|
||||
* <p/>
|
||||
* <p> This method blocks until input data is available, end of file is
|
||||
* detected, or an exception is thrown.
|
||||
* <p/>
|
||||
* <p> If <code>b</code> is <code>null</code>, a
|
||||
* <code>NullPointerException</code> is thrown.
|
||||
* <p/>
|
||||
* <p> If <code>off</code> is negative, or <code>len</code> is negative, or
|
||||
* <code>off+len</code> is greater than the length of the array
|
||||
* <code>b</code>, then an <code>IndexOutOfBoundsException</code> is
|
||||
* thrown.
|
||||
* <p/>
|
||||
* <p> If <code>len</code> is zero, then no bytes are read and
|
||||
* <code>0</code> is returned; otherwise, there is an attempt to read at
|
||||
* least one byte. If no byte is available because the stream is at end of
|
||||
* file, the value <code>-1</code> is returned; otherwise, at least one
|
||||
* byte is read and stored into <code>b</code>.
|
||||
* <p/>
|
||||
* <p> The first byte read is stored into element <code>b[off]</code>, the
|
||||
* next one into <code>b[off+1]</code>, and so on. The number of bytes read
|
||||
* is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
|
||||
* bytes actually read; these bytes will be stored in elements
|
||||
* <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
|
||||
* leaving elements <code>b[off+</code><i>k</i><code>]</code> through
|
||||
* <code>b[off+len-1]</code> unaffected.
|
||||
* <p/>
|
||||
* <p> In every case, elements <code>b[0]</code> through
|
||||
* <code>b[off]</code> and elements <code>b[off+len]</code> through
|
||||
* <code>b[b.length-1]</code> are unaffected.
|
||||
* <p/>
|
||||
* <p> If the first byte cannot be read for any reason other than end of
|
||||
* file, then an <code>IOException</code> is thrown. In particular, an
|
||||
* <code>IOException</code> is thrown if the input stream has been closed.
|
||||
*
|
||||
* @param b the buffer into which the data is read.
|
||||
* @param off the start offset in array <code>b</code>
|
||||
* at which the data is written.
|
||||
* @param len the maximum number of bytes to read.
|
||||
* @return the total number of bytes read into the buffer, or
|
||||
* <code>-1</code> if there is no more data because the end of
|
||||
* the stream has been reached.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
* @throws NullPointerException if <code>b</code> is <code>null</code>.
|
||||
*/
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
return eq.read(b, off, len);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>The method <code>reset</code> for class <code>EqualizerInputStream</code>
|
||||
* does nothing except throw an <code>IOException</code>.
|
||||
*
|
||||
* @throws IOException as an indication that the mark feature doesn't supported by EqualizerInputStream.
|
||||
*/
|
||||
public void reset() throws IOException {
|
||||
eq.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips over and discards <code>n</code> bytes of data from this input
|
||||
* stream. The <code>skip</code> method may, for a variety of reasons, end
|
||||
* up skipping over some smaller number of bytes, possibly <code>0</code>.
|
||||
* This may result from any of a number of conditions; reaching end of file
|
||||
* before <code>n</code> bytes have been skipped is only one possibility.
|
||||
* The actual number of bytes skipped is returned. If <code>n</code> is
|
||||
* negative, no bytes are skipped.
|
||||
*
|
||||
* @param n the number of bytes to be skipped.
|
||||
* @return the actual number of bytes skipped.
|
||||
* @throws IOException if an I/O error occurs.
|
||||
*/
|
||||
public long skip(long n) throws IOException {
|
||||
return eq.skip(n);
|
||||
}
|
||||
}
|
||||
75
src/uk/co/majenko/audiobookrecorder/AGC.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AGC implements Effect {
|
||||
double limit;
|
||||
double gain;
|
||||
double ceiling;
|
||||
double decay;
|
||||
double attack;
|
||||
|
||||
public AGC(double c, double a, double d, double l) {
|
||||
Debug.trace();
|
||||
ceiling = c;
|
||||
attack = a;
|
||||
decay = d;
|
||||
limit = l;
|
||||
gain = 1d;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
Debug.trace();
|
||||
gain = 1d;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
double absSampleLeft = Math.abs(samples[Sentence.LEFT][i]) * gain;
|
||||
double absSampleRight = Math.abs(samples[Sentence.RIGHT][i]) * gain;
|
||||
|
||||
double factor = 0.0d;
|
||||
|
||||
if (absSampleLeft > ceiling) {
|
||||
factor = -attack;
|
||||
}
|
||||
|
||||
if (absSampleRight > ceiling) {
|
||||
factor = -attack;
|
||||
}
|
||||
|
||||
if ((absSampleLeft < ceiling) && (absSampleRight < ceiling)) {
|
||||
factor = decay;
|
||||
}
|
||||
|
||||
gain += factor;
|
||||
if (gain > limit) gain = limit;
|
||||
if (gain < 0) gain = 0;
|
||||
|
||||
samples[Sentence.LEFT][i] *= gain;
|
||||
samples[Sentence.RIGHT][i] *= gain;
|
||||
}
|
||||
}
|
||||
|
||||
public void init(double sr) {
|
||||
Debug.trace();
|
||||
gain = 1d;
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
Debug.trace();
|
||||
System.out.println(toString());
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
Debug.trace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.BorderLayout;
|
||||
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 AboutPanel() {
|
||||
Debug.trace();
|
||||
setLayout(new BorderLayout());
|
||||
JLabel icon = new JLabel(Icons.appIcon);
|
||||
add(icon, BorderLayout.WEST);
|
||||
@@ -17,7 +22,7 @@ public class AboutPanel extends JPanel {
|
||||
|
||||
JLabel l1 = new JLabel("AudiobookRecorder");
|
||||
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);
|
||||
l2.setAlignmentX(JComponent.CENTER_ALIGNMENT);
|
||||
|
||||
57
src/uk/co/majenko/audiobookrecorder/Amplifier.java
Normal file
@@ -0,0 +1,57 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Amplifier implements Effect {
|
||||
double gain;
|
||||
public Amplifier() {
|
||||
Debug.trace();
|
||||
gain = 1.0d;
|
||||
}
|
||||
public Amplifier(double g) {
|
||||
Debug.trace();
|
||||
gain = g;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
return "Amplifier (" + gain + ")";
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
Debug.trace();
|
||||
return null;
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
Debug.trace();
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
samples[Sentence.LEFT][i] *= gain;
|
||||
samples[Sentence.RIGHT][i] *= gain;
|
||||
}
|
||||
}
|
||||
|
||||
public double getGain() {
|
||||
Debug.trace();
|
||||
return gain;
|
||||
}
|
||||
|
||||
public void setGain(double g) {
|
||||
Debug.trace();
|
||||
gain = g;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
Debug.trace();
|
||||
System.out.println(toString());
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
Debug.trace();
|
||||
}
|
||||
}
|
||||
251
src/uk/co/majenko/audiobookrecorder/Biquad.java
Normal file
@@ -0,0 +1,251 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Biquad implements Effect {
|
||||
public static final int Lowpass = 0;
|
||||
public static final int Highpass = 1;
|
||||
public static final int Bandpass = 2;
|
||||
public static final int Notch = 3;
|
||||
public static final int Peak = 4;
|
||||
public static final int Lowshelf = 5;
|
||||
public static final int Highshelf = 6;
|
||||
|
||||
int type;
|
||||
double a0, a1, a2, b1, b2;
|
||||
double Fc, Q, peakGain;
|
||||
double lz1, lz2;
|
||||
double rz1, rz2;
|
||||
double sampleFrequency;
|
||||
|
||||
public Biquad() {
|
||||
Debug.trace();
|
||||
type = Lowpass;
|
||||
a0 = 1.0d;
|
||||
a1 = 0.0d;
|
||||
a2 = 0.0d;
|
||||
b1 = 0.0d;
|
||||
b2 = 0.0d;
|
||||
Fc = 440d;
|
||||
Q = 0.707d;
|
||||
peakGain = 0.0d;
|
||||
lz1 = 0.0d;
|
||||
lz2 = 0.0d;
|
||||
rz1 = 0.0d;
|
||||
rz2 = 0.0d;
|
||||
sampleFrequency = 44100d;
|
||||
}
|
||||
|
||||
public Biquad(int type, double Fc, double Q, double peakGainDB) {
|
||||
Debug.trace();
|
||||
setBiquad(type, Fc, Q, peakGainDB);
|
||||
lz1 = 0.0;
|
||||
lz2 = 0.0;
|
||||
rz1 = 0.0;
|
||||
rz2 = 0.0;
|
||||
sampleFrequency = 44100d;
|
||||
}
|
||||
|
||||
public void setType(int typei) {
|
||||
Debug.trace();
|
||||
type = typei;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
public void setQ(double Qi) {
|
||||
Debug.trace();
|
||||
Q = Qi;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
public void setFc(double Fci) {
|
||||
Debug.trace();
|
||||
Fc = Fci;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
public void setPeakGain(double peakGainDB) {
|
||||
Debug.trace();
|
||||
peakGain = peakGainDB;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
public void setBiquad(int typei, double Fci, double Qi, double peakGainDB) {
|
||||
Debug.trace();
|
||||
type = typei;
|
||||
Q = Qi;
|
||||
Fc = Fci;
|
||||
setPeakGain(peakGainDB);
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
Debug.trace();
|
||||
lz1 = 0d;
|
||||
lz2 = 0d;
|
||||
rz1 = 0d;
|
||||
rz2 = 0d;
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
double lout = samples[Sentence.LEFT][i] * a0 + lz1;
|
||||
|
||||
lz1 = samples[Sentence.LEFT][i] * a1 + lz2 - b1 * lout;
|
||||
lz2 = samples[Sentence.LEFT][i] * a2 - b2 * lout;
|
||||
|
||||
double rout = samples[Sentence.RIGHT][i] * a0 + rz1;
|
||||
|
||||
rz1 = samples[Sentence.RIGHT][i] * a1 + rz2 - b1 * rout;
|
||||
rz2 = samples[Sentence.RIGHT][i] * a2 - b2 * rout;
|
||||
|
||||
samples[Sentence.LEFT][i] = lout;
|
||||
samples[Sentence.RIGHT][i] = rout;
|
||||
}
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
Debug.trace();
|
||||
sampleFrequency = sf;
|
||||
lz1 = 0d;
|
||||
lz2 = 0d;
|
||||
rz1 = 0d;
|
||||
rz2 = 0d;
|
||||
calcBiquad();
|
||||
}
|
||||
|
||||
void calcBiquad() {
|
||||
Debug.trace();
|
||||
|
||||
double norm;
|
||||
double V = Math.pow(10, Math.abs(peakGain) / 20.0);
|
||||
double K = Math.tan(Math.PI * (Fc/sampleFrequency));
|
||||
switch (type) {
|
||||
case Lowpass:
|
||||
norm = 1d / (1d + K / Q + K * K);
|
||||
a0 = K * K * norm;
|
||||
a1 = 2d * a0;
|
||||
a2 = a0;
|
||||
b1 = 2d * (K * K - 1d) * norm;
|
||||
b2 = (1d - K / Q + K * K) * norm;
|
||||
break;
|
||||
|
||||
case Highpass:
|
||||
norm = 1d / (1d + K / Q + K * K);
|
||||
a0 = 1d * norm;
|
||||
a1 = -2d * a0;
|
||||
a2 = a0;
|
||||
b1 = 2d * (K * K - 1d) * norm;
|
||||
b2 = (1d - K / Q + K * K) * norm;
|
||||
break;
|
||||
|
||||
case Bandpass:
|
||||
norm = 1d / (1d + K / Q + K * K);
|
||||
a0 = K / Q * norm;
|
||||
a1 = 0d;
|
||||
a2 = -a0;
|
||||
b1 = 2d * (K * K - 1d) * norm;
|
||||
b2 = (1d - K / Q + K * K) * norm;
|
||||
break;
|
||||
|
||||
case Notch:
|
||||
norm = 1d / (1d + K / Q + K * K);
|
||||
a0 = (1d + K * K) * norm;
|
||||
a1 = 2d * (K * K - 1d) * norm;
|
||||
a2 = a0;
|
||||
b1 = a1;
|
||||
b2 = (1d - K / Q + K * K) * norm;
|
||||
break;
|
||||
|
||||
case Peak:
|
||||
if (peakGain >= 0d) { // boost
|
||||
norm = 1d / (1d + 1d/Q * K + K * K);
|
||||
a0 = (1d + V/Q * K + K * K) * norm;
|
||||
a1 = 2d * (K * K - 1d) * norm;
|
||||
a2 = (1d - V/Q * K + K * K) * norm;
|
||||
b1 = a1;
|
||||
b2 = (1d - 1d/Q * K + K * K) * norm;
|
||||
}
|
||||
else { // cut
|
||||
norm = 1d / (1d + V/Q * K + K * K);
|
||||
a0 = (1d + 1d/Q * K + K * K) * norm;
|
||||
a1 = 2d * (K * K - 1d) * norm;
|
||||
a2 = (1d - 1d/Q * K + K * K) * norm;
|
||||
b1 = a1;
|
||||
b2 = (1d - V/Q * K + K * K) * norm;
|
||||
}
|
||||
break;
|
||||
case Lowshelf:
|
||||
if (peakGain >= 0) { // boost
|
||||
norm = 1d / (1 + Math.sqrt(2d) * K + K * K);
|
||||
a0 = (1d + Math.sqrt(2d*V) * K + V * K * K) * norm;
|
||||
a1 = 2d * (V * K * K - 1d) * norm;
|
||||
a2 = (1d - Math.sqrt(2d*V) * K + V * K * K) * norm;
|
||||
b1 = 2d * (K * K - 1d) * norm;
|
||||
b2 = (1d - Math.sqrt(2d) * K + K * K) * norm;
|
||||
}
|
||||
else { // cut
|
||||
norm = 1d / (1 + Math.sqrt(2d*V) * K + V * K * K);
|
||||
a0 = (1d + Math.sqrt(2d) * K + K * K) * norm;
|
||||
a1 = 2d * (K * K - 1d) * norm;
|
||||
a2 = (1d - Math.sqrt(2d) * K + K * K) * norm;
|
||||
b1 = 2d * (V * K * K - 1d) * norm;
|
||||
b2 = (1d - Math.sqrt(2d*V) * K + V * K * K) * norm;
|
||||
}
|
||||
break;
|
||||
case Highshelf:
|
||||
if (peakGain >= 0d) { // boost
|
||||
norm = 1d / (1d + Math.sqrt(2d) * K + K * K);
|
||||
a0 = (V + Math.sqrt(2d*V) * K + K * K) * norm;
|
||||
a1 = 2d * (K * K - V) * norm;
|
||||
a2 = (V - Math.sqrt(2d*V) * K + K * K) * norm;
|
||||
b1 = 2d * (K * K - 1d) * norm;
|
||||
b2 = (1d - Math.sqrt(2d) * K + K * K) * norm;
|
||||
}
|
||||
else { // cut
|
||||
norm = 1d / (V + Math.sqrt(2d*V) * K + K * K);
|
||||
a0 = (1d + Math.sqrt(2d) * K + K * K) * norm;
|
||||
a1 = 2d * (K * K - 1d) * norm;
|
||||
a2 = (1d - Math.sqrt(2d) * K + K * K) * norm;
|
||||
b1 = 2d * (K * K - V) * norm;
|
||||
b2 = (V - Math.sqrt(2d*V) * K + K * K) * norm;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
String n = "Biquad Filter (";
|
||||
switch (type) {
|
||||
case Lowpass: n += "Lowpass"; break;
|
||||
case Highpass: n += "Highpass"; break;
|
||||
case Bandpass: n += "Bandpass"; break;
|
||||
case Notch: n += "Notch"; break;
|
||||
case Peak: n += "Peak"; break;
|
||||
case Lowshelf: n += "Lowshelf"; break;
|
||||
case Highshelf: n += "Highshelf"; break;
|
||||
}
|
||||
n += ", Fc=";
|
||||
n += Fc;
|
||||
n += ", Q=";
|
||||
n += Q;
|
||||
n += ", Gain=";
|
||||
n += peakGain;
|
||||
n += "dB)";
|
||||
return n;
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
Debug.trace();
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
Debug.trace();
|
||||
System.out.println(toString());
|
||||
}
|
||||
}
|
||||
@@ -1,66 +1,146 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import javax.swing.tree.*;
|
||||
import davaguine.jeq.core.IIRControls;
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.UUID;
|
||||
import java.util.Properties;
|
||||
import javax.sound.sampled.AudioFormat;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.ImageIcon;
|
||||
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.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 Book extends DefaultMutableTreeNode {
|
||||
public class Book extends BookTreeNode {
|
||||
|
||||
String name;
|
||||
String author;
|
||||
String genre;
|
||||
String comment;
|
||||
String ACX;
|
||||
String manuscript;
|
||||
|
||||
String defaultEffect = "none";
|
||||
|
||||
int sampleRate;
|
||||
int channels;
|
||||
int resolution;
|
||||
|
||||
String notes = null;
|
||||
|
||||
ImageIcon icon;
|
||||
|
||||
public Equaliser[] equaliser = new Equaliser[2];
|
||||
|
||||
float[] eqChannels = new float[31];
|
||||
|
||||
Properties prefs;
|
||||
|
||||
File location;
|
||||
|
||||
public Book(Properties p, String bookname) {
|
||||
super(bookname);
|
||||
|
||||
Debug.trace();
|
||||
prefs = p;
|
||||
name = bookname;
|
||||
equaliser[0] = new Equaliser("Default");
|
||||
equaliser[1] = new Equaliser("Phone");
|
||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
||||
}
|
||||
|
||||
public void setAuthor(String a) { author = a; }
|
||||
public void setGenre(String g) { genre = g; }
|
||||
public void setComment(String c) { comment = c; }
|
||||
public void setACX(String c) { ACX = c; }
|
||||
public Book(Element root) {
|
||||
super(getTextNode(root, "title"));
|
||||
Debug.trace();
|
||||
name = getTextNode(root, "title");
|
||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name); // This should be in the load routine!!!!
|
||||
}
|
||||
|
||||
public String getAuthor() { return author; }
|
||||
public String getGenre() { return genre; }
|
||||
public String getComment() { return comment; }
|
||||
public String getACX() { if (ACX == null) return ""; return ACX; }
|
||||
public void loadBookXML(Element root, DefaultTreeModel model) {
|
||||
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");
|
||||
|
||||
AudiobookRecorder.window.setBookNotes(getTextNode(root, "notes"));
|
||||
notes = getTextNode(root, "notes");
|
||||
|
||||
Element settings = getNode(root, "settings");
|
||||
Element audioSettings = getNode(settings, "audio");
|
||||
Element effectSettings = getNode(settings, "effects");
|
||||
|
||||
sampleRate = Utils.s2i(getTextNode(audioSettings, "samplerate"));
|
||||
channels = Utils.s2i(getTextNode(audioSettings, "channels"));
|
||||
resolution = Utils.s2i(getTextNode(audioSettings, "resolution"));
|
||||
|
||||
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");
|
||||
|
||||
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 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 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; }
|
||||
|
||||
public Chapter getClosingCredits() {
|
||||
Debug.trace();
|
||||
return getChapterById("close");
|
||||
}
|
||||
|
||||
public Chapter getOpeningCredits() {
|
||||
Debug.trace();
|
||||
return getChapterById("open");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Chapter getChapterById(String id) {
|
||||
Debug.trace();
|
||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||
Object ob = (Object)o.nextElement();
|
||||
if (ob instanceof Chapter) {
|
||||
@@ -74,47 +154,39 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public Chapter getLastChapter() {
|
||||
Chapter cc = getClosingCredits();
|
||||
if (cc == null) return null;
|
||||
Chapter c = (Chapter)getChildBefore(cc);
|
||||
if (c == null) return null;
|
||||
if (c.getId().equals("open")) return null;
|
||||
return c;
|
||||
Debug.trace();
|
||||
return (Chapter)getLastLeaf();
|
||||
}
|
||||
|
||||
public Chapter getChapter(int n) {
|
||||
Debug.trace();
|
||||
if (n == 0) return null;
|
||||
return (Chapter)getChildAt(n);
|
||||
}
|
||||
|
||||
public Chapter addChapter() {
|
||||
Chapter lc = getLastChapter();
|
||||
if (lc == null) return new Chapter("1", "Chapter 1");
|
||||
try {
|
||||
int lcid = Integer.parseInt(lc.getId());
|
||||
lcid++;
|
||||
|
||||
Chapter nc = new Chapter(String.format("%04d", lcid), "Chapter " + lcid);
|
||||
return nc;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
Debug.trace();
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
return new Chapter(uuid, uuid);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
return name;
|
||||
}
|
||||
|
||||
public ImageIcon getIcon() {
|
||||
Debug.trace();
|
||||
return icon;
|
||||
}
|
||||
|
||||
public void setIcon(ImageIcon i) {
|
||||
Debug.trace();
|
||||
icon = i;
|
||||
}
|
||||
|
||||
public void setUserObject(Object o) {
|
||||
Debug.trace();
|
||||
if (o instanceof String) {
|
||||
String newName = (String)o;
|
||||
if (newName.equals(name)) return;
|
||||
@@ -122,8 +194,14 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
public File getBookPath() {
|
||||
Debug.trace();
|
||||
return new File(Options.get("path.storage"), name);
|
||||
}
|
||||
|
||||
public void renameBook(String newName) {
|
||||
File oldDir = new File(Options.get("path.storage"), name);
|
||||
Debug.trace();
|
||||
File oldDir = getBookPath();
|
||||
File newDir = new File(Options.get("path.storage"), newName);
|
||||
|
||||
if (newDir.exists()) {
|
||||
@@ -135,7 +213,7 @@ public class Book extends DefaultMutableTreeNode {
|
||||
oldDir.renameTo(newDir);
|
||||
name = newName;
|
||||
AudiobookRecorder.window.saveBookStructure();
|
||||
AudiobookRecorder.window.bookTreeModel.reload(this);
|
||||
reloadTree();
|
||||
Options.set("path.last-book", name);
|
||||
Options.savePreferences();
|
||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
||||
@@ -143,11 +221,13 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return name;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void renumberChapters() {
|
||||
Debug.trace();
|
||||
int id = 1;
|
||||
|
||||
for (Enumeration c = children(); c.hasMoreElements();) {
|
||||
@@ -159,32 +239,222 @@ public class Book extends DefaultMutableTreeNode {
|
||||
}
|
||||
}
|
||||
|
||||
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 int getSampleRate() { Debug.trace(); return sampleRate; }
|
||||
public void setSampleRate(int sr) { Debug.trace(); sampleRate = sr; }
|
||||
public int getChannels() { Debug.trace(); return channels; }
|
||||
public void setChannels(int c) { Debug.trace(); channels = c; }
|
||||
public int getResolution() { Debug.trace(); return resolution; }
|
||||
public void setResolution(int r) { Debug.trace(); resolution = r; }
|
||||
|
||||
public AudioFormat getAudioFormat() {
|
||||
Debug.trace();
|
||||
return new AudioFormat(getSampleRate(), getResolution(), getChannels(), true, false);
|
||||
}
|
||||
|
||||
public String get(String key) {
|
||||
Debug.trace();
|
||||
if (prefs.getProperty(key) == null) { return Options.get(key); }
|
||||
return prefs.getProperty(key);
|
||||
}
|
||||
|
||||
public Integer getInteger(String key) {
|
||||
Debug.trace();
|
||||
if (prefs.getProperty(key) == null) { return Options.getInteger(key); }
|
||||
return Utils.s2i(prefs.getProperty(key));
|
||||
}
|
||||
|
||||
public void set(String key, String value) {
|
||||
Debug.trace();
|
||||
prefs.setProperty(key, value);
|
||||
}
|
||||
|
||||
public void set(String key, Integer value) {
|
||||
Debug.trace();
|
||||
prefs.setProperty(key, "" + value);
|
||||
}
|
||||
|
||||
public File getBookFolder() {
|
||||
Debug.trace();
|
||||
File dir = new File(Options.get("path.storage"), name);
|
||||
return dir;
|
||||
}
|
||||
|
||||
public ArrayList<String> getUsedEffects() {
|
||||
Debug.trace();
|
||||
|
||||
ArrayList<String> out = new ArrayList<String>();
|
||||
|
||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||
Object ob = (Object)o.nextElement();
|
||||
if (ob instanceof Chapter) {
|
||||
Chapter c = (Chapter)ob;
|
||||
ArrayList<String> effs = c.getUsedEffects();
|
||||
for (String ef : effs) {
|
||||
if (out.indexOf(ef) == -1) {
|
||||
out.add(ef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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", AudiobookRecorder.window.getBookNotes()));
|
||||
|
||||
Element settingsNode = doc.createElement("settings");
|
||||
root.appendChild(settingsNode);
|
||||
|
||||
Element audioSettingsNode = doc.createElement("audio");
|
||||
settingsNode.appendChild(audioSettingsNode);
|
||||
|
||||
audioSettingsNode.appendChild(makeTextNode(doc, "channels", channels));
|
||||
audioSettingsNode.appendChild(makeTextNode(doc, "resolution", resolution));
|
||||
audioSettingsNode.appendChild(makeTextNode(doc, "samplerate", sampleRate));
|
||||
|
||||
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(getBookPath(), 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(getBookPath(), manuscript);
|
||||
if (f.exists()) {
|
||||
return f;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void onSelect() {
|
||||
}
|
||||
|
||||
public String getNotes() {
|
||||
return notes;
|
||||
}
|
||||
|
||||
public void setNotes(String n) {
|
||||
notes = n;
|
||||
}
|
||||
|
||||
public File getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(File l) {
|
||||
location = l;
|
||||
}
|
||||
|
||||
public void reloadTree() {
|
||||
Debug.trace();
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (AudiobookRecorder.window == null) return;
|
||||
if (AudiobookRecorder.window.bookTreeModel == null) return;
|
||||
try {
|
||||
AudiobookRecorder.window.bookTreeModel.reload(Book.this);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.regex.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.GridBagConstraints;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.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) {
|
||||
super();
|
||||
Debug.trace();
|
||||
setLayout(new GridBagLayout());
|
||||
GridBagConstraints con = new GridBagConstraints();
|
||||
|
||||
@@ -69,12 +73,13 @@ public class BookInfoPanel extends JPanel {
|
||||
|
||||
}
|
||||
|
||||
public String getTitle() { return title.getText(); }
|
||||
public String getAuthor() { return author.getText(); }
|
||||
public String getGenre() { return genre.getText(); }
|
||||
public String getComment() { return comment.getText(); }
|
||||
public String getTitle() { Debug.trace(); return title.getText(); }
|
||||
public String getAuthor() { Debug.trace(); return author.getText(); }
|
||||
public String getGenre() { Debug.trace(); return genre.getText(); }
|
||||
public String getComment() { Debug.trace(); return comment.getText(); }
|
||||
|
||||
public String getACX() {
|
||||
Debug.trace();
|
||||
Pattern p = Pattern.compile("\\/titleview\\/([A-Z0-9]{14})");
|
||||
Matcher m = p.matcher(acx.getText());
|
||||
if (m.find()) {
|
||||
@@ -84,10 +89,10 @@ public class BookInfoPanel extends JPanel {
|
||||
return acx.getText();
|
||||
}
|
||||
|
||||
public void setTitle(String t) { title.setText(t); }
|
||||
public void setAuthor(String a) { author.setText(a); }
|
||||
public void setGenre(String g) { genre.setText(g); }
|
||||
public void setComment(String c) { comment.setText(c); }
|
||||
public void setACX(String a) { acx.setText(a); }
|
||||
public void setTitle(String t) { Debug.trace(); title.setText(t); }
|
||||
public void setAuthor(String a) { Debug.trace(); author.setText(a); }
|
||||
public void setGenre(String g) { Debug.trace(); genre.setText(g); }
|
||||
public void setComment(String c) { Debug.trace(); comment.setText(c); }
|
||||
public void setACX(String a) { Debug.trace(); acx.setText(a); }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,30 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.*;
|
||||
import javax.swing.border.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.Properties;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Image;
|
||||
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 {
|
||||
String name;
|
||||
@@ -25,6 +42,7 @@ public class BookPanel extends JPanel {
|
||||
JPanel panel;
|
||||
|
||||
File root;
|
||||
File configFile;
|
||||
|
||||
boolean highlight = false;
|
||||
|
||||
@@ -36,13 +54,78 @@ public class BookPanel extends JPanel {
|
||||
try {
|
||||
root = r;
|
||||
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) {
|
||||
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) {
|
||||
try {
|
||||
name = props.getProperty("book.name");
|
||||
@@ -71,41 +154,44 @@ public class BookPanel extends JPanel {
|
||||
resizedCover = Utils.getScaledImage(cover.getImage(), 75, 75);
|
||||
iconLabel = new JLabel(new ImageIcon(resizedCover));
|
||||
}
|
||||
|
||||
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);
|
||||
populate();
|
||||
} 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() {
|
||||
return new File(root, "audiobook.abk");
|
||||
return configFile;
|
||||
}
|
||||
|
||||
public void highlight() {
|
||||
|
||||
20
src/uk/co/majenko/audiobookrecorder/BookTreeNode.java
Normal file
@@ -0,0 +1,20 @@
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -1,29 +1,49 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.*;
|
||||
import java.awt.*;
|
||||
import java.awt.Component;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
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 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);
|
||||
ret.setIconTextGap(5);
|
||||
ret.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
if (value instanceof Sentence) {
|
||||
Sentence s = (Sentence)value;
|
||||
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new GridBagLayout());
|
||||
GridBagConstraints ctx = new GridBagConstraints();
|
||||
|
||||
OverlayIcon icn = new OverlayIcon(Icons.sentence);
|
||||
|
||||
if (s.getOverrideText() != null) {
|
||||
ret.setText(s.getOverrideText());
|
||||
}
|
||||
|
||||
if (!s.isProcessed()) {
|
||||
ret.setForeground(new Color(0x88, 0x88, 0x88));
|
||||
}
|
||||
|
||||
if (s.getAttentionFlag()) {
|
||||
ret.setForeground(new Color(0xFF, 0xFF, 0x00));
|
||||
icn.add(Overlays.attention, OverlayIcon.TOP_LEFT);
|
||||
}
|
||||
|
||||
if (s.isLocked()) {
|
||||
ret.setForeground(new Color(0x00, 0x80, 0xFF));
|
||||
ret.setForeground(new Color(0x30, 0xb0, 0xFF));
|
||||
icn.add(Overlays.locked, OverlayIcon.BOTTOM_LEFT);
|
||||
}
|
||||
|
||||
@@ -31,16 +51,147 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
||||
icn.add(Overlays.important, OverlayIcon.TOP_RIGHT);
|
||||
}
|
||||
|
||||
if (s.getEthereal()) {
|
||||
icn.add(Overlays.filter, OverlayIcon.BOTTOM_RIGHT);
|
||||
if (s.getEndOffset() == s.getSampleSize() - 1) {
|
||||
icn.add(Overlays.important, OverlayIcon.TOP_RIGHT);
|
||||
}
|
||||
|
||||
if (s.getEffectChain() != null) {
|
||||
if (!s.getEffectChain().equals("none")) {
|
||||
icn.add(Overlays.filter, OverlayIcon.BOTTOM_RIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
ret.setIcon(icn);
|
||||
|
||||
String gaptype = s.getPostGapType();
|
||||
DefaultMutableTreeNode prev = s.getPreviousSibling();
|
||||
String prevtype = "sentence";
|
||||
if (prev instanceof Sentence) {
|
||||
Sentence s2 = (Sentence)prev;
|
||||
prevtype = s2.getPostGapType();
|
||||
}
|
||||
|
||||
if (prevtype.equals("continuation")) {
|
||||
ret.setIconTextGap(20);
|
||||
}
|
||||
|
||||
if (gaptype.equals("sentence")) {
|
||||
p.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
} else if (gaptype.equals("continuation")) {
|
||||
p.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
} else if (gaptype.equals("paragraph")) {
|
||||
p.setBorder(new EmptyBorder(0, 0, 7, 0));
|
||||
} else if (gaptype.equals("section")) {
|
||||
p.setBorder(new EmptyBorder(0, 0, 15, 0));
|
||||
}
|
||||
|
||||
|
||||
JLabel time = new JLabelFixedWidth(75, " " + Utils.secToTime(s.getLength(), "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);
|
||||
|
||||
if (s.isProcessing()) {
|
||||
JLabel eff = new JLabel();
|
||||
eff.setIcon(Icons.processing);
|
||||
ctx.weightx = 0.0d;
|
||||
ctx.gridx = 1;
|
||||
p.add(eff);
|
||||
} else if (s.isQueued()) {
|
||||
JLabel eff = new JLabel();
|
||||
eff.setIcon(Icons.queued);
|
||||
ctx.weightx = 0.0d;
|
||||
ctx.gridx = 1;
|
||||
p.add(eff);
|
||||
}
|
||||
|
||||
String effectChain = s.getEffectChain();
|
||||
if ((effectChain != null) && (!effectChain.equals("none"))) {
|
||||
Effect e = AudiobookRecorder.window.effects.get(effectChain);
|
||||
if (e != null) {
|
||||
JLabel eff = new JLabel(e.toString() + " ");
|
||||
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) {
|
||||
Chapter c = (Chapter)value;
|
||||
|
||||
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) {
|
||||
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());
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CacheManager {
|
||||
static ArrayList<Cacheable> cache = new ArrayList<Cacheable>();
|
||||
@@ -13,6 +13,9 @@ public class CacheManager {
|
||||
if (ob.lockedInCache()) {
|
||||
cache.add(ob);
|
||||
} else {
|
||||
if (ob instanceof Sentence) {
|
||||
Sentence s = (Sentence)ob;
|
||||
}
|
||||
ob.clearCache();
|
||||
}
|
||||
}
|
||||
@@ -23,4 +26,19 @@ public class CacheManager {
|
||||
public static void setCacheSize(int c) {
|
||||
cacheSize = c;
|
||||
}
|
||||
|
||||
public static void removeFromCache(Cacheable c) {
|
||||
if (c instanceof Sentence) {
|
||||
Sentence s = (Sentence)c;
|
||||
}
|
||||
cache.remove(c);
|
||||
c.clearCache();
|
||||
}
|
||||
|
||||
public static void purgeCache() {
|
||||
for (Cacheable c : cache) {
|
||||
c.clearCache();
|
||||
}
|
||||
cache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
58
src/uk/co/majenko/audiobookrecorder/Chain.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Chain implements Effect {
|
||||
String target;
|
||||
|
||||
public Chain(String t) {
|
||||
target = t;
|
||||
}
|
||||
|
||||
public Chain() {
|
||||
target = null;
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
if (target != null) {
|
||||
Effect t = AudiobookRecorder.window.effects.get(target);
|
||||
if (t != null) {
|
||||
t.process(samples);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setTarget(String t) {
|
||||
target = t;
|
||||
}
|
||||
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Chain to " + target;
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
System.out.println(toString());
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
if (target != null) {
|
||||
Effect t = AudiobookRecorder.window.effects.get(target);
|
||||
if (t != null) {
|
||||
t.init(sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +1,49 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import javax.swing.tree.*;
|
||||
import it.sauronsoftware.jave.*;
|
||||
import com.mpatric.mp3agic.*;
|
||||
import javax.sound.sampled.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
|
||||
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 id;
|
||||
@@ -21,35 +51,60 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
int preGap;
|
||||
int postGap;
|
||||
|
||||
String notes;
|
||||
|
||||
public Chapter(String i, String chaptername) {
|
||||
super(chaptername);
|
||||
|
||||
Debug.trace();
|
||||
id = i;
|
||||
name = chaptername;
|
||||
preGap = Options.getInteger("catenation.pre-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 String getId() {
|
||||
Debug.trace();
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String i) {
|
||||
Debug.trace();
|
||||
id = i;
|
||||
}
|
||||
|
||||
public Sentence getLastSentence() {
|
||||
Debug.trace();
|
||||
DefaultMutableTreeNode ls = getLastLeaf();
|
||||
if (ls instanceof Sentence) return (Sentence)ls;
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
Debug.trace();
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setUserObject(Object o) {
|
||||
Debug.trace();
|
||||
if (o instanceof String) {
|
||||
String so = (String)o;
|
||||
name = so;
|
||||
@@ -57,26 +112,32 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
Debug.trace();
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String n) {
|
||||
Debug.trace();
|
||||
name = n;
|
||||
}
|
||||
|
||||
public void setPreGap(int g) {
|
||||
Debug.trace();
|
||||
preGap = g;
|
||||
}
|
||||
|
||||
public int getPreGap() {
|
||||
Debug.trace();
|
||||
return preGap;
|
||||
}
|
||||
|
||||
public void setPostGap(int g) {
|
||||
Debug.trace();
|
||||
postGap = g;
|
||||
}
|
||||
|
||||
public int getPostGap() {
|
||||
Debug.trace();
|
||||
return postGap;
|
||||
}
|
||||
|
||||
@@ -84,6 +145,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
public void exportChapter(ProgressDialog exportDialog) throws
|
||||
FileNotFoundException, IOException, InputFormatException, NotSupportedException,
|
||||
EncoderException, UnsupportedTagException, InvalidDataException {
|
||||
Debug.trace();
|
||||
|
||||
if (getChildCount() == 0) return;
|
||||
|
||||
@@ -116,12 +178,13 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
audioAttributes.setCodec("libmp3lame");
|
||||
audioAttributes.setBitRate(Options.getInteger("audio.export.bitrate"));
|
||||
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.setAudioAttributes(audioAttributes);
|
||||
|
||||
|
||||
AudioFormat format = AudiobookRecorder.window.roomNoise.getAudioFormat();
|
||||
AudioFormat sampleformat = AudiobookRecorder.window.roomNoise.getAudioFormat();
|
||||
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 2, true, false);
|
||||
byte[] data;
|
||||
|
||||
int fullLength = 0;
|
||||
@@ -149,7 +212,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
kidno++;
|
||||
if (exportDialog != null) exportDialog.setProgress(kidno * 1000 / kids);
|
||||
Sentence snt = (Sentence)s.nextElement();
|
||||
data = snt.getRawAudioData();
|
||||
data = snt.getPCMData();
|
||||
|
||||
fullLength += data.length;
|
||||
fos.write(data);
|
||||
@@ -201,6 +264,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
}
|
||||
|
||||
public double getChapterLength() {
|
||||
Debug.trace();
|
||||
double totalTime = Options.getInteger("audio.recording.pre-chapter") / 1000d;
|
||||
for (Enumeration s = children(); s.hasMoreElements();) {
|
||||
Sentence sentence = (Sentence)s.nextElement();
|
||||
@@ -214,4 +278,92 @@ public class Chapter extends DefaultMutableTreeNode {
|
||||
return totalTime;
|
||||
}
|
||||
|
||||
public ArrayList<String> getUsedEffects() {
|
||||
Debug.trace();
|
||||
|
||||
ArrayList<String> out = new ArrayList<String>();
|
||||
|
||||
for (Enumeration o = children(); o.hasMoreElements();) {
|
||||
Object ob = (Object)o.nextElement();
|
||||
if (ob instanceof Sentence) {
|
||||
Sentence s = (Sentence)ob;
|
||||
String ec = s.getEffectChain();
|
||||
if (out.indexOf(ec) == -1) {
|
||||
out.add(ec);
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public void resetPostGaps() {
|
||||
Debug.trace();
|
||||
for (Enumeration s = children(); s.hasMoreElements();) {
|
||||
Sentence snt = (Sentence)s.nextElement();
|
||||
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() {
|
||||
Debug.trace();
|
||||
AudiobookRecorder.window.setChapterNotes(notes);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
49
src/uk/co/majenko/audiobookrecorder/Clipping.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Clipping implements Effect {
|
||||
double clip;
|
||||
public Clipping() {
|
||||
clip = 1.0d;
|
||||
}
|
||||
public Clipping(double g) {
|
||||
clip = g;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Clipping (" + clip + ")";
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
if (samples[Sentence.LEFT][i] > clip) samples[Sentence.LEFT][i] = clip;
|
||||
if (samples[Sentence.LEFT][i] < -clip) samples[Sentence.LEFT][i] = -clip;
|
||||
if (samples[Sentence.RIGHT][i] > clip) samples[Sentence.RIGHT][i] = clip;
|
||||
if (samples[Sentence.RIGHT][i] < -clip) samples[Sentence.RIGHT][i] = -clip;
|
||||
}
|
||||
}
|
||||
|
||||
public double getClip() {
|
||||
return clip;
|
||||
}
|
||||
|
||||
public void setClip(double g) {
|
||||
clip = g;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
System.out.println(toString());
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.*;
|
||||
import javax.swing.plaf.*;
|
||||
import javax.swing.plaf.basic.*;
|
||||
import java.awt.*;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.tree.AbstractLayoutCache;
|
||||
import javax.swing.tree.TreePath;
|
||||
import javax.swing.plaf.basic.BasicTreeUI;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Graphics;
|
||||
|
||||
public class CustomTreeUI extends BasicTreeUI {
|
||||
|
||||
|
||||
53
src/uk/co/majenko/audiobookrecorder/Debug.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.Date;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
public class Debug {
|
||||
static long timestamp;
|
||||
static public boolean debugEnabled = false;
|
||||
static public boolean traceEnabled = false;
|
||||
|
||||
static void debug(String msg) {
|
||||
if (!debugEnabled) return;
|
||||
long now = System.currentTimeMillis();
|
||||
long diff = now - timestamp;
|
||||
timestamp = now;
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
105
src/uk/co/majenko/audiobookrecorder/DelayLine.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DelayLine implements Effect {
|
||||
|
||||
ArrayList<DelayLineStore> delayLines;
|
||||
|
||||
boolean wetOnly = false;
|
||||
|
||||
public DelayLine() {
|
||||
delayLines = new ArrayList<DelayLineStore>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Delay Line (" + delayLines.size() + " lines)";
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
double[][] savedSamples = new double[2][samples[Sentence.LEFT].length];
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
savedSamples[Sentence.LEFT][i] = samples[Sentence.LEFT][i];
|
||||
savedSamples[Sentence.RIGHT][i] = samples[Sentence.RIGHT][i];
|
||||
}
|
||||
if (wetOnly) {
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
samples[Sentence.LEFT][i] = 0d;
|
||||
samples[Sentence.RIGHT][i] = 0d;
|
||||
}
|
||||
}
|
||||
|
||||
double[][] subSamples = new double[2][samples[Sentence.LEFT].length];
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
subSamples[Sentence.LEFT][i] = savedSamples[Sentence.LEFT][i];
|
||||
subSamples[Sentence.RIGHT][i] = savedSamples[Sentence.RIGHT][i];
|
||||
}
|
||||
for (DelayLineStore d : delayLines) {
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
subSamples[Sentence.LEFT][i] = savedSamples[Sentence.LEFT][i];
|
||||
subSamples[Sentence.RIGHT][i] = savedSamples[Sentence.RIGHT][i];
|
||||
}
|
||||
|
||||
d.process(subSamples);
|
||||
|
||||
for (int i = 0; i < subSamples[Sentence.LEFT].length; i++) {
|
||||
int off = i + d.getSamples();
|
||||
if ((off < samples[Sentence.LEFT].length) && (off > 0)) {
|
||||
samples[Sentence.LEFT][off] = mix(samples[Sentence.LEFT][off], subSamples[Sentence.LEFT][i]);
|
||||
samples[Sentence.RIGHT][off] = mix(samples[Sentence.RIGHT][off], subSamples[Sentence.RIGHT][i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 DelayLineStore addDelayLine(int samples, double gain, double pan) {
|
||||
DelayLineStore s = new DelayLineStore(samples, gain, pan);
|
||||
delayLines.add(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
public DelayLineStore addDelayLine(int samples, double gain) {
|
||||
DelayLineStore s = new DelayLineStore(samples, gain);
|
||||
delayLines.add(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
System.out.println(toString());
|
||||
for (DelayLineStore s : delayLines) {
|
||||
s.dump();
|
||||
}
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
for (DelayLineStore s : delayLines) {
|
||||
s.init(sf);
|
||||
}
|
||||
}
|
||||
|
||||
public void setWetOnly(boolean b) {
|
||||
wetOnly = b;
|
||||
}
|
||||
}
|
||||
78
src/uk/co/majenko/audiobookrecorder/DelayLineStore.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class DelayLineStore {
|
||||
double gain;
|
||||
int numSamples;
|
||||
double pan;
|
||||
|
||||
ArrayList<Effect> effects;
|
||||
|
||||
public DelayLineStore(int s, double g, double p) {
|
||||
numSamples = s;
|
||||
gain = g;
|
||||
pan = p;
|
||||
effects = new ArrayList<Effect>();
|
||||
}
|
||||
|
||||
public DelayLineStore(int s, double g) {
|
||||
numSamples = s;
|
||||
gain = g;
|
||||
pan = 0d;
|
||||
effects = new ArrayList<Effect>();
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (Effect e : effects) {
|
||||
e.process(samples);
|
||||
}
|
||||
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
samples[Sentence.LEFT][i] *= gain;
|
||||
samples[Sentence.RIGHT][i] *= gain;
|
||||
|
||||
if (pan < 0) {
|
||||
double p = 1 + pan;
|
||||
samples[Sentence.RIGHT][i] *= p;
|
||||
} else {
|
||||
double p = 1 - pan;
|
||||
samples[Sentence.LEFT][i] *= p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setSamples(int s) {
|
||||
numSamples = s;
|
||||
}
|
||||
|
||||
public void setGain(double g) {
|
||||
gain = g;
|
||||
}
|
||||
|
||||
public int getSamples() {
|
||||
return numSamples;
|
||||
}
|
||||
|
||||
public double getGain() {
|
||||
return gain;
|
||||
}
|
||||
|
||||
public void addEffect(Effect e) {
|
||||
effects.add(e);
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
for (Effect e : effects) {
|
||||
e.init(sf);
|
||||
}
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
System.out.println(" Samples: " + numSamples + ", gain: " + gain);
|
||||
for (Effect e : effects) {
|
||||
e.dump();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.border.*;
|
||||
import java.net.*;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JTextArea;
|
||||
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 DonationPanel() {
|
||||
|
||||
12
src/uk/co/majenko/audiobookrecorder/Effect.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface Effect {
|
||||
public void process(double[][] samples);
|
||||
public String getName();
|
||||
public ArrayList<Effect> getChildEffects();
|
||||
public void dump();
|
||||
public void init(double sr);
|
||||
public String toString();
|
||||
}
|
||||
69
src/uk/co/majenko/audiobookrecorder/EffectGroup.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class EffectGroup implements Effect {
|
||||
String name;
|
||||
ArrayList<Effect> effects;
|
||||
|
||||
public EffectGroup(String n) {
|
||||
name = n;
|
||||
effects = new ArrayList<Effect>();
|
||||
}
|
||||
|
||||
public EffectGroup() {
|
||||
name = "Unnamed Group";
|
||||
effects = new ArrayList<Effect>();
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (Effect e : effects) {
|
||||
e.process(samples);
|
||||
}
|
||||
}
|
||||
|
||||
public void setName(String n) {
|
||||
name = n;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void addEffect(Effect e) {
|
||||
effects.add(e);
|
||||
}
|
||||
|
||||
public void clearEffects() {
|
||||
effects.clear();
|
||||
}
|
||||
|
||||
public void removeEffect(Effect e) {
|
||||
effects.remove(e);
|
||||
}
|
||||
|
||||
public void removeEffect(int n) {
|
||||
effects.remove(n);
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
System.out.println(toString() + " >> ");
|
||||
for (Effect e : effects) {
|
||||
e.dump();
|
||||
}
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
for (Effect e : effects) {
|
||||
e.init(sf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import javax.swing.tree.*;
|
||||
import javax.sound.sampled.*;
|
||||
import davaguine.jeq.core.IIRControls;
|
||||
|
||||
public class Equaliser extends JPanel {
|
||||
|
||||
EqualiserChannel channels[];
|
||||
String name;
|
||||
|
||||
static final double[] frequencies = {
|
||||
20d, 25d, 31.5d, 40d, 50d, 63d, 80d, 100d, 125d, 160d, 200d,
|
||||
250d, 315d, 400d, 500d, 630d, 800d, 1000d, 1250d, 1600d, 2000d,
|
||||
2500d, 3150d, 4000d, 5000d, 6300d, 8000d, 10000d, 12500d, 16000d,
|
||||
20000d
|
||||
};
|
||||
|
||||
public Equaliser(String n) {
|
||||
super();
|
||||
|
||||
name = n;
|
||||
|
||||
channels = new EqualiserChannel[31];
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
JPanel inner = new JPanel();
|
||||
|
||||
inner.setLayout(new FlowLayout());
|
||||
|
||||
for (int i = 0; i < 31; i++) {
|
||||
channels[i] = new EqualiserChannel(frequencies[i]);
|
||||
inner.add(channels[i]);
|
||||
}
|
||||
|
||||
add(inner, BorderLayout.CENTER);
|
||||
|
||||
|
||||
JButton smooth = new JButton("Smooth curve");
|
||||
smooth.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Float ave[] = new Float[31];
|
||||
for (int i = 1; i < 30; i++) {
|
||||
ave[i] = (channels[i-1].getValue() + channels[i].getValue() + channels[i+1].getValue()) / 3.0f;
|
||||
}
|
||||
|
||||
for (int i = 1; i < 30; i++) {
|
||||
channels[i].setValue(ave[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
JButton def = new JButton("Set as default");
|
||||
def.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (int i = 0; i < 31; i++) {
|
||||
Options.set("audio.eq." + i, channels[i].getValue());
|
||||
}
|
||||
}
|
||||
});
|
||||
JButton load = new JButton("Load from default");
|
||||
load.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
for (int i = 0; i < 31; i++) {
|
||||
channels[i].setValue(Options.getFloat("audio.eq." + i));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JPanel buttons = new JPanel();
|
||||
buttons.setLayout(new FlowLayout());
|
||||
buttons.add(smooth);
|
||||
buttons.add(def);
|
||||
buttons.add(load);
|
||||
|
||||
add(buttons, BorderLayout.SOUTH);
|
||||
}
|
||||
|
||||
public float getChannel(int c) {
|
||||
return channels[c].getValue();
|
||||
}
|
||||
|
||||
public void setChannel(int c, float v) {
|
||||
channels[c].setValue(v);
|
||||
}
|
||||
|
||||
public void apply(IIRControls c, int chans) {
|
||||
for (int i = 0; i < 31; i++) {
|
||||
c.setBandDbValue(i, 0, channels[i].getValue());
|
||||
if (chans == 2) {
|
||||
c.setBandDbValue(i, 1, channels[i].getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import javax.swing.tree.*;
|
||||
import javax.sound.sampled.*;
|
||||
|
||||
public class EqualiserChannel extends JPanel {
|
||||
|
||||
float value;
|
||||
JSlider slider;
|
||||
JTextField textbox;
|
||||
JLabel frequency;
|
||||
|
||||
public EqualiserChannel(double freq) {
|
||||
super();
|
||||
|
||||
|
||||
value = 0;
|
||||
|
||||
slider = new JSlider(-120, 120, 0);
|
||||
textbox = new JTextField();
|
||||
|
||||
String suffix = "Hz";
|
||||
if (freq > 1000) {
|
||||
freq /= 1000;
|
||||
suffix = "kHz";
|
||||
}
|
||||
|
||||
String ftxt = String.format("%.4f", freq);
|
||||
while (ftxt.endsWith("0")) {
|
||||
ftxt = ftxt.substring(0, ftxt.length() - 1);
|
||||
}
|
||||
if (ftxt.endsWith(".")) {
|
||||
ftxt = ftxt.substring(0, ftxt.length() - 1);
|
||||
}
|
||||
frequency = new JLabel(ftxt + suffix);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
add(frequency, BorderLayout.NORTH);
|
||||
slider.setOrientation(SwingConstants.VERTICAL);
|
||||
add(slider, BorderLayout.CENTER);
|
||||
textbox = new JTextField("0.0");
|
||||
add(textbox, BorderLayout.SOUTH);
|
||||
|
||||
textbox.setPreferredSize(new Dimension(40, 20));
|
||||
slider.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
value = (float)slider.getValue() / 10.0f;
|
||||
textbox.setText(String.format("%.1f", value));
|
||||
}
|
||||
});
|
||||
|
||||
textbox.addFocusListener(new FocusListener() {
|
||||
public void focusGained(FocusEvent e) {
|
||||
textbox.selectAll();
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
value = Utils.s2f(textbox.getText());
|
||||
if (value < -12f) value = -12f;
|
||||
if (value > 12f) value = 12f;
|
||||
|
||||
slider.setValue((int)(value * 10));
|
||||
textbox.setText(String.format("%.1f", value));
|
||||
}
|
||||
});
|
||||
|
||||
textbox.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
value = Utils.s2f(textbox.getText());
|
||||
if (value < -12f) value = -12f;
|
||||
if (value > 12f) value = 12f;
|
||||
|
||||
slider.setValue((int)(value * 10));
|
||||
textbox.setText(String.format("%.1f", value));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public float getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(float v) {
|
||||
value = v;
|
||||
slider.setValue((int)(value * 10));
|
||||
textbox.setText(String.format("%.1f", value));
|
||||
}
|
||||
}
|
||||
@@ -1,130 +1,93 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
/**
|
||||
* @author Orlando Selenu
|
||||
*
|
||||
*/
|
||||
public class FFT {
|
||||
/**
|
||||
* The Fast Fourier Transform (generic version, with NO optimizations).
|
||||
*
|
||||
* @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;
|
||||
public static double[] fft(final double[] inputReal, double[] inputImag, boolean DIRECT) {
|
||||
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
|
||||
// from the function returning null.
|
||||
if (((int) ld) - ld != 0) {
|
||||
System.out.println("The number of elements is not a power of 2.");
|
||||
return null;
|
||||
}
|
||||
if (((int) ld) - ld != 0) {
|
||||
System.out.println("The number of elements is not a power of 2.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Declaration and initialization of the variables
|
||||
// ld should be an integer, actually, so I don't lose any information in
|
||||
// the cast
|
||||
int nu = (int) ld;
|
||||
int n2 = n / 2;
|
||||
int nu1 = nu - 1;
|
||||
double[] xReal = new double[n];
|
||||
double[] xImag = new double[n];
|
||||
double tReal, tImag, p, arg, c, s;
|
||||
int nu = (int) ld;
|
||||
int n2 = n / 2;
|
||||
int nu1 = nu - 1;
|
||||
double[] xReal = new double[n];
|
||||
double[] xImag = new double[n];
|
||||
double tReal, tImag, p, arg, c, s;
|
||||
|
||||
double constant;
|
||||
if (DIRECT) {
|
||||
constant = -2 * Math.PI;
|
||||
} else {
|
||||
constant = 2 * Math.PI;
|
||||
}
|
||||
|
||||
// Here I check if I'm going to do the direct transform or the inverse
|
||||
// transform.
|
||||
double constant;
|
||||
if (DIRECT)
|
||||
constant = -2 * Math.PI;
|
||||
else
|
||||
constant = 2 * Math.PI;
|
||||
for (int i = 0; i < n; i++) {
|
||||
xReal[i] = inputReal[i];
|
||||
xImag[i] = inputImag[i];
|
||||
}
|
||||
|
||||
// I don't want to overwrite the input arrays, so here I copy them. This
|
||||
// choice adds \Theta(2n) to the complexity.
|
||||
for (int i = 0; i < n; i++) {
|
||||
xReal[i] = inputReal[i];
|
||||
xImag[i] = inputImag[i];
|
||||
}
|
||||
|
||||
// First phase - calculation
|
||||
int k = 0;
|
||||
for (int l = 1; l <= nu; l++) {
|
||||
while (k < n) {
|
||||
for (int i = 1; i <= n2; i++) {
|
||||
p = bitreverseReference(k >> nu1, nu);
|
||||
// direct FFT or inverse FFT
|
||||
arg = constant * p / n;
|
||||
c = Math.cos(arg);
|
||||
s = Math.sin(arg);
|
||||
tReal = xReal[k + n2] * c + xImag[k + n2] * s;
|
||||
tImag = xImag[k + n2] * c - xReal[k + n2] * s;
|
||||
xReal[k + n2] = xReal[k] - tReal;
|
||||
xImag[k + n2] = xImag[k] - tImag;
|
||||
xReal[k] += tReal;
|
||||
xImag[k] += tImag;
|
||||
k++;
|
||||
int k = 0;
|
||||
for (int l = 1; l <= nu; l++) {
|
||||
while (k < n) {
|
||||
for (int i = 1; i <= n2; i++) {
|
||||
p = bitreverseReference(k >> nu1, nu);
|
||||
// direct FFT or inverse FFT
|
||||
arg = constant * p / n;
|
||||
c = Math.cos(arg);
|
||||
s = Math.sin(arg);
|
||||
tReal = xReal[k + n2] * c + xImag[k + n2] * s;
|
||||
tImag = xImag[k + n2] * c - xReal[k + n2] * s;
|
||||
xReal[k + n2] = xReal[k] - tReal;
|
||||
xImag[k + n2] = xImag[k] - tImag;
|
||||
xReal[k] += tReal;
|
||||
xImag[k] += tImag;
|
||||
k++;
|
||||
}
|
||||
k += n2;
|
||||
}
|
||||
k += n2;
|
||||
k = 0;
|
||||
nu1--;
|
||||
n2 /= 2;
|
||||
}
|
||||
|
||||
k = 0;
|
||||
nu1--;
|
||||
n2 /= 2;
|
||||
}
|
||||
|
||||
// Second phase - recombination
|
||||
k = 0;
|
||||
int r;
|
||||
while (k < n) {
|
||||
r = bitreverseReference(k, nu);
|
||||
if (r > k) {
|
||||
tReal = xReal[k];
|
||||
tImag = xImag[k];
|
||||
xReal[k] = xReal[r];
|
||||
xImag[k] = xImag[r];
|
||||
xReal[r] = tReal;
|
||||
xImag[r] = tImag;
|
||||
int r;
|
||||
while (k < n) {
|
||||
r = bitreverseReference(k, nu);
|
||||
if (r > k) {
|
||||
tReal = xReal[k];
|
||||
tImag = xImag[k];
|
||||
xReal[k] = xReal[r];
|
||||
xImag[k] = xImag[r];
|
||||
xReal[r] = tReal;
|
||||
xImag[r] = tImag;
|
||||
}
|
||||
k++;
|
||||
}
|
||||
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
|
||||
// be possible to do this stuff in the earlier parts of the code, but
|
||||
// it's here to readibility).
|
||||
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;
|
||||
// I used Stephen Wolfram's Mathematica as a reference so I'm going
|
||||
// to normalize the output while I'm copying the elements.
|
||||
newArray[i] = xReal[i2] * radice;
|
||||
newArray[i + 1] = xImag[i2] * radice;
|
||||
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;
|
||||
}
|
||||
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;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.TimerTask;
|
||||
import java.util.Timer;
|
||||
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 {
|
||||
|
||||
boolean flash = false;
|
||||
boolean col = false;
|
||||
|
||||
java.util.Timer ticker;
|
||||
Timer ticker;
|
||||
|
||||
public FlashPanel() {
|
||||
super();
|
||||
ticker = new java.util.Timer(true);
|
||||
ticker = new Timer(true);
|
||||
ticker.scheduleAtFixedRate(new TimerTask() {
|
||||
public void run() {
|
||||
if (flash) {
|
||||
@@ -27,6 +32,8 @@ public class FlashPanel extends JPanel {
|
||||
public void setFlash(boolean f) {
|
||||
flash = f;
|
||||
|
||||
col = true;
|
||||
|
||||
for (Component o : getComponents()) {
|
||||
((JComponent)o).setVisible(!f);
|
||||
}
|
||||
@@ -42,7 +49,7 @@ public class FlashPanel extends JPanel {
|
||||
if (col) {
|
||||
g.setColor(Color.RED);
|
||||
} else {
|
||||
g.setColor(Color.BLACK);
|
||||
g.setColor(Color.GREEN);
|
||||
}
|
||||
Dimension d = getSize();
|
||||
g.fillRect(0, 0, d.width, d.height);
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Timer;
|
||||
|
||||
public class HavenQueue extends JPanel {
|
||||
ConcurrentLinkedQueue<Sentence> sentenceList = new ConcurrentLinkedQueue<Sentence>();
|
||||
|
||||
Timer timer = new Timer();
|
||||
|
||||
Sentence currentSentence = null;
|
||||
|
||||
JLabel count;
|
||||
|
||||
public HavenQueue() {
|
||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
||||
count = new JLabel("Haven queue: 0");
|
||||
setLayout(new BorderLayout());
|
||||
add(count, BorderLayout.CENTER);
|
||||
|
||||
count.setOpaque(false);
|
||||
setOpaque(false);
|
||||
count.setForeground(Color.WHITE);
|
||||
}
|
||||
|
||||
public void processQueue() {
|
||||
|
||||
count.setText("Haven queue: " + sentenceList.size());
|
||||
|
||||
if (currentSentence == null) {
|
||||
// Grab a new sentence to process.
|
||||
currentSentence = sentenceList.poll();
|
||||
|
||||
if (currentSentence != null) {
|
||||
if (!currentSentence.postHavenData()) { // Failed. Add to the end of the queue and wait a bit
|
||||
submit(currentSentence);
|
||||
currentSentence = null;
|
||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
||||
return;
|
||||
}
|
||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentSentence != null) {
|
||||
currentSentence.processPendingHaven();
|
||||
int status = currentSentence.getHavenStatus();
|
||||
switch (status) {
|
||||
case 0: // Um... not running...?
|
||||
currentSentence = null;
|
||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
||||
return;
|
||||
case 1: // Still processing...
|
||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 5000);
|
||||
return;
|
||||
case 2: // Finished
|
||||
currentSentence = null;
|
||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
||||
return;
|
||||
case 3: // Failed
|
||||
currentSentence = null;
|
||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
timer.schedule(new TimerTask() { public void run() { processQueue(); }}, 30000);
|
||||
}
|
||||
|
||||
public void submit(Sentence s) {
|
||||
s.setOverrideText("[queued...]");
|
||||
AudiobookRecorder.window.bookTreeModel.reload(s);
|
||||
sentenceList.add(s);
|
||||
count.setText("Haven queue: " + sentenceList.size());
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class Icons {
|
||||
static public final ImageIcon book = new ImageIcon(Icons.class.getResource("icons/book.png"));
|
||||
@@ -33,4 +33,14 @@ public class Icons {
|
||||
static public final ImageIcon dollar = new ImageIcon(Icons.class.getResource("icons/dollar.png"));
|
||||
static public final ImageIcon attention = new ImageIcon(Icons.class.getResource("icons/attention.png"));
|
||||
static public final ImageIcon normalize = new ImageIcon(Icons.class.getResource("icons/normalize.png"));
|
||||
static public final ImageIcon split = new ImageIcon(Icons.class.getResource("icons/split.png"));
|
||||
static public final ImageIcon cut = new ImageIcon(Icons.class.getResource("icons/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 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"));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.KeyStroke;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class JButtonSpacePlay extends JButton {
|
||||
public JButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||
|
||||
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;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.JSlider;
|
||||
|
||||
public class JSliderOb extends JSlider {
|
||||
Object object;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
import javax.swing.*;
|
||||
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class JTextFieldOb extends JTextField {
|
||||
Object object;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class JToggleButtonSpacePlay extends JToggleButton {
|
||||
public JToggleButtonSpacePlay(ImageIcon i, String tt, ActionListener al) {
|
||||
|
||||
@@ -14,10 +14,6 @@ public class KVPair<K,V> implements Comparable {
|
||||
}
|
||||
|
||||
public int compareTo(Object o) {
|
||||
// if (o instanceof KVPair) {
|
||||
// KVPair ko = (KVPair)o;
|
||||
// return key.compareTo(ko.key);
|
||||
// }
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
103
src/uk/co/majenko/audiobookrecorder/LFO.java
Normal file
@@ -0,0 +1,103 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LFO implements Effect {
|
||||
|
||||
double phase;
|
||||
double frequency;
|
||||
double depth;
|
||||
double sampleRate;
|
||||
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) {
|
||||
this(f, d, 0, SINE, Math.PI, REPLACE);
|
||||
}
|
||||
|
||||
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;
|
||||
depth = d;
|
||||
phase = p;
|
||||
waveform = w;
|
||||
duty = dty;
|
||||
mode = m;
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
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;
|
||||
if (phase > (Math.PI * 2d)) {
|
||||
phase -= (Math.PI * 2d);
|
||||
}
|
||||
|
||||
// Multiply it by the gain factor
|
||||
v *= depth;
|
||||
|
||||
// Apply it to the sample
|
||||
switch (mode) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getName() { return "Low Frequency Oscillator (" + frequency + " Hz, " + (depth * 100d) + "%)"; }
|
||||
|
||||
public ArrayList<Effect> getChildEffects() { return null; }
|
||||
|
||||
public void dump() {
|
||||
System.out.println(getName());
|
||||
}
|
||||
|
||||
public void init(double sr) {
|
||||
sampleRate = sr;
|
||||
|
||||
// Number of samples that make up one cycle of the LFO
|
||||
double oneCycle = sampleRate / frequency;
|
||||
|
||||
// Amount to increase each step
|
||||
sampleStep = (Math.PI * 2d) / oneCycle;
|
||||
|
||||
}
|
||||
|
||||
public String toString() { return getName(); }
|
||||
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.Color;
|
||||
import javax.swing.JToggleButton;
|
||||
import javax.swing.JComboBox;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
public class MainToolBar extends JToolBar {
|
||||
|
||||
@@ -14,9 +17,14 @@ public class MainToolBar extends JToolBar {
|
||||
JButtonSpacePlay recordRoomNoise;
|
||||
JButtonSpacePlay playSentence;
|
||||
JButtonSpacePlay playonSentence;
|
||||
JButtonSpacePlay playtoSentence;
|
||||
JButtonSpacePlay stopPlaying;
|
||||
JButtonSpacePlay eq;
|
||||
JToggleButton mic;
|
||||
JButtonSpacePlay openManuscript;
|
||||
JToggleButtonSpacePlay mic;
|
||||
|
||||
JComboBox<String> playbackSpeed;
|
||||
|
||||
JToggleButtonSpacePlay disableEffects;
|
||||
|
||||
AudiobookRecorder root;
|
||||
|
||||
@@ -78,6 +86,14 @@ public class MainToolBar extends JToolBar {
|
||||
});
|
||||
add(playonSentence);
|
||||
|
||||
playtoSentence = new JButtonSpacePlay(Icons.playto, "Play sentence to cut", new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
root.playToSelectedSentence();
|
||||
}
|
||||
});
|
||||
add(playtoSentence);
|
||||
playtoSentence.setEnabled(false);
|
||||
|
||||
stopPlaying = new JButtonSpacePlay(Icons.stop, "Stop playing", new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
root.stopPlaying();
|
||||
@@ -85,15 +101,6 @@ public class MainToolBar extends JToolBar {
|
||||
});
|
||||
add(stopPlaying);
|
||||
|
||||
addSeparator();
|
||||
eq = new JButtonSpacePlay(Icons.eq, "Equaliser", new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
root.showEqualiser();
|
||||
}
|
||||
});
|
||||
|
||||
add(eq);
|
||||
|
||||
addSeparator();
|
||||
|
||||
mic = new JToggleButtonSpacePlay(Icons.mic, "Enable / disable microphone", new ActionListener() {
|
||||
@@ -117,11 +124,65 @@ public class MainToolBar extends JToolBar {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
add(mic);
|
||||
|
||||
addSeparator();
|
||||
|
||||
disableEffects = new JToggleButtonSpacePlay(Icons.disable, "Disable effects", new ActionListener() {
|
||||
Color bgCol = null;
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JToggleButton b = (JToggleButton)e.getSource();
|
||||
if (b.isSelected()) {
|
||||
root.setEffectsEnabled(false);
|
||||
bgCol = b.getBackground();
|
||||
b.setBackground(Color.RED);
|
||||
} else {
|
||||
root.setEffectsEnabled(true);
|
||||
if (bgCol != null) {
|
||||
b.setBackground(bgCol);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void enablePlayTo(boolean 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;
|
||||
|
||||
import java.awt.event.*;
|
||||
|
||||
public class MarkerDragEvent {
|
||||
|
||||
Object src;
|
||||
|
||||
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;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.table.TableCellRenderer;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.JScrollPane;
|
||||
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 {
|
||||
|
||||
@@ -86,10 +92,16 @@ public class OpenBookPanel extends JPanel {
|
||||
for (File b : dir.listFiles()) {
|
||||
if (b == null) continue;
|
||||
if (!b.isDirectory()) continue;
|
||||
File xml = new File(b, "audiobook.abk");
|
||||
File xml = new File(b, "audiobook.abx");
|
||||
if (xml.exists()) {
|
||||
BookPanel book = new BookPanel(b);
|
||||
model.addBook(book);
|
||||
} else {
|
||||
xml = new File(b, "audiobook.abk");
|
||||
if (xml.exists()) {
|
||||
BookPanel book = new BookPanel(b);
|
||||
model.addBook(book);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,42 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.sound.sampled.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.util.prefs.*;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.util.TreeSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.prefs.Preferences;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.BorderLayout;
|
||||
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 {
|
||||
|
||||
@@ -21,6 +50,8 @@ public class Options extends JDialog {
|
||||
JComboBox<KVPair> rateList;
|
||||
JComboBox<KVPair> bitDepth;
|
||||
JComboBox<KVPair> trimMethod;
|
||||
JComboBox<KVPair> fftBlockSize;
|
||||
JComboBox<KVPair> playbackBlockSize;
|
||||
JTextField storageFolder;
|
||||
JTextField archiveFolder;
|
||||
JSpinner preChapterGap;
|
||||
@@ -28,22 +59,30 @@ public class Options extends JDialog {
|
||||
JSpinner postSentenceGap;
|
||||
JSpinner shortSentenceGap;
|
||||
JSpinner postParagraphGap;
|
||||
JSpinner postSectionGap;
|
||||
JSpinner maxGainVariance;
|
||||
JTextField ffmpegLocation;
|
||||
JComboBox<KVPair> bitRate;
|
||||
JComboBox<KVPair> channels;
|
||||
JComboBox<KVPair> exportRate;
|
||||
JCheckBox enableParsing;
|
||||
JSpinner cacheSize;
|
||||
|
||||
JSpinner fftThreshold;
|
||||
|
||||
JSpinner etherealIterations;
|
||||
JSpinner etherealAttenuation;
|
||||
JSpinner etherealOffset;
|
||||
|
||||
JTextField havenApiKey;
|
||||
JTextField externalEditor;
|
||||
|
||||
Equaliser equaliser;
|
||||
JTextField speechCommand;
|
||||
JSpinner workerThreads;
|
||||
|
||||
JTextArea startupScript;
|
||||
|
||||
ArrayList<JTextField[]> processorList;
|
||||
|
||||
static HashMap<String, String> defaultPrefs;
|
||||
static Preferences prefs = null;
|
||||
|
||||
@@ -59,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);
|
||||
constraint.gridx = 0;
|
||||
constraint.gridwidth = 1;
|
||||
@@ -70,6 +109,9 @@ public class Options extends JDialog {
|
||||
JComboBox<KVPair> o = new JComboBox<KVPair>(options);
|
||||
constraint.gridx = 1;
|
||||
panel.add(o, constraint);
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
for (KVPair p : options) {
|
||||
if (p.key.equals(def)) {
|
||||
@@ -82,7 +124,25 @@ public class Options extends JDialog {
|
||||
return o;
|
||||
}
|
||||
|
||||
JTextField addTextField(JPanel panel, String label, String def) {
|
||||
void addTwoLabel(JPanel panel, String label1, String label2) {
|
||||
JLabel l1 = new JLabel(label1);
|
||||
constraint.gridx = 0;
|
||||
constraint.gridwidth = 1;
|
||||
constraint.gridheight = 1;
|
||||
constraint.anchor = GridBagConstraints.LINE_START;
|
||||
panel.add(l1, constraint);
|
||||
|
||||
JLabel l2 = new JLabel(label2);
|
||||
constraint.gridx = 1;
|
||||
constraint.gridwidth = 1;
|
||||
constraint.gridheight = 1;
|
||||
constraint.anchor = GridBagConstraints.LINE_START;
|
||||
panel.add(l2, constraint);
|
||||
|
||||
constraint.gridy++;
|
||||
}
|
||||
|
||||
JTextField addTextField(JPanel panel, String label, String def, String tip) {
|
||||
JLabel l = new JLabel(label);
|
||||
constraint.gridx = 0;
|
||||
constraint.gridwidth = 1;
|
||||
@@ -96,14 +156,40 @@ public class Options extends JDialog {
|
||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||
panel.add(a, constraint);
|
||||
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
|
||||
constraint.fill = GridBagConstraints.NONE;
|
||||
|
||||
constraint.gridy++;
|
||||
return a;
|
||||
}
|
||||
|
||||
JTextField[] addTwoField(JPanel panel, String def1, String def2, String tip) {
|
||||
JTextField a = new JTextField(def1);
|
||||
constraint.gridx = 0;
|
||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||
panel.add(a, constraint);
|
||||
|
||||
JTextField b = new JTextField(def2);
|
||||
constraint.gridx = 1;
|
||||
panel.add(b, constraint);
|
||||
constraint.fill = GridBagConstraints.NONE;
|
||||
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
|
||||
constraint.gridy++;
|
||||
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);
|
||||
constraint.gridx = 0;
|
||||
constraint.gridwidth = 1;
|
||||
@@ -165,6 +251,10 @@ public class Options extends JDialog {
|
||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||
panel.add(p, constraint);
|
||||
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
constraint.fill = GridBagConstraints.NONE;
|
||||
|
||||
constraint.gridy++;
|
||||
@@ -191,7 +281,7 @@ public class Options extends JDialog {
|
||||
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);
|
||||
constraint.gridx = 0;
|
||||
constraint.gridwidth = 1;
|
||||
@@ -211,6 +301,10 @@ public class Options extends JDialog {
|
||||
|
||||
constraint.fill = GridBagConstraints.HORIZONTAL;
|
||||
panel.add(p, constraint);
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
|
||||
constraint.fill = GridBagConstraints.NONE;
|
||||
|
||||
@@ -219,11 +313,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;
|
||||
JCheckBox cb = new JCheckBox(label);
|
||||
cb.setSelected(state);
|
||||
panel.add(cb, constraint);
|
||||
Tip t = new Tip(tip);
|
||||
constraint.gridx = 2;
|
||||
panel.add(t, constraint);
|
||||
|
||||
|
||||
constraint.gridy++;
|
||||
return cb;
|
||||
}
|
||||
@@ -251,75 +350,104 @@ public class Options extends JDialog {
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
|
||||
mixerList = addDropdown(optionsPanel, "Recording device:", getRecordingMixerList(), get("audio.recording.device"));
|
||||
channelList = addDropdown(optionsPanel, "Channels:", getChannelCountList(), get("audio.recording.channels"));
|
||||
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"));
|
||||
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"));
|
||||
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"));
|
||||
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"), "How many channels do you want to record - stereo or mono?");
|
||||
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"), "The higher the resolution the better the quality, but the bigger the files.");
|
||||
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"), "", "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);
|
||||
|
||||
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);
|
||||
storageFolder = addFilePath(optionsPanel, "Storage folder:", get("path.storage"), true);
|
||||
archiveFolder = addFilePath(optionsPanel, "Archive folder:", get("path.archive"), 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, "This is where audiobooks are archived to.");
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
|
||||
preChapterGap = addSpinner(optionsPanel, "Default pre-chapter gap:", 0, 5000, 100, getInteger("catenation.pre-chapter"), "ms");
|
||||
postChapterGap = addSpinner(optionsPanel, "Default post-chapter gap:", 0, 5000, 100, getInteger("catenation.post-chapter"), "ms");
|
||||
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms");
|
||||
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms");
|
||||
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "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", "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", "How much room noise to add between normal sentences.");
|
||||
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", "How much room noise to add between paragraphs.");
|
||||
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);
|
||||
|
||||
ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false);
|
||||
bitRate = addDropdown(optionsPanel, "Export bitrate:", getBitrates(), get("audio.export.bitrate"));
|
||||
exportRate = addDropdown(optionsPanel, "Export sample rate:", getSampleRateList(), get("audio.export.samplerate"));
|
||||
ffmpegLocation = addFilePath(optionsPanel, "FFMPEG location:", get("path.ffmpeg"), false, "Path to your ffmpeg executable.");
|
||||
bitRate = addDropdown(optionsPanel, "Export bitrate:", getBitrates(), get("audio.export.bitrate"), "The MP3 bitrate to produce");
|
||||
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);
|
||||
|
||||
enableParsing = addCheckBox(optionsPanel, "Enable automatic speech-to-text submission", getBoolean("process.haven.auto"));
|
||||
havenApiKey = addTextField(optionsPanel, "Haven OnDemand API Key", get("process.haven.apikey"));
|
||||
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);
|
||||
|
||||
externalEditor = addTextField(optionsPanel, "External Editor Command", get("editor.external"), "The program to run when you select 'Open in external editor'.");
|
||||
|
||||
addSeparator(optionsPanel);
|
||||
|
||||
cacheSize = addSpinner(optionsPanel, "Cache size:", 0, 5000, 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);
|
||||
tabs.add("Options", new JScrollPane(optionsPanel));
|
||||
equaliser = new Equaliser("Default");
|
||||
for (int i = 0; i < 31; i++) {
|
||||
equaliser.setChannel(i, Options.getFloat("audio.eq." + i));
|
||||
}
|
||||
tabs.add("Default EQ", new JScrollPane(equaliser));
|
||||
|
||||
|
||||
|
||||
|
||||
JPanel startScript = new JPanel();
|
||||
startScript.setLayout(new BorderLayout());
|
||||
startScript.setBorder(new EmptyBorder(15, 15, 15, 15));
|
||||
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);
|
||||
tabs.add("Startup Script", startScript);
|
||||
|
||||
|
||||
|
||||
JPanel effects = new JPanel();
|
||||
effects.setLayout(new GridBagLayout());
|
||||
|
||||
JPanel processors = new JPanel();
|
||||
processors.setLayout(new BorderLayout());
|
||||
JPanel processorListPanel = new JPanel();
|
||||
|
||||
JScrollPane psp = new JScrollPane(processorListPanel);
|
||||
|
||||
processors.add(psp, BorderLayout.CENTER);
|
||||
processorListPanel.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);
|
||||
addTwoLabel(processorListPanel, "Name", "Command");
|
||||
|
||||
processorList = new ArrayList<JTextField[]>();
|
||||
|
||||
for (int i = 0; i < 999; i++) {
|
||||
String name = get("editor.processor." + i + ".name");
|
||||
String command = get("editor.processor." + i + ".command");
|
||||
if (name == null || command == null) break;
|
||||
if (name.equals("") || command.equals("")) break;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
tabs.add("Processors", processors);
|
||||
|
||||
|
||||
add(tabs, BorderLayout.CENTER);
|
||||
|
||||
@@ -365,6 +493,7 @@ public class Options extends JDialog {
|
||||
setVisible(true);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static KVPair<String, String>[] getRecordingMixerList() {
|
||||
TreeSet<KVPair<String, String>> list = new TreeSet<KVPair<String, String>>();
|
||||
|
||||
@@ -474,63 +603,36 @@ public class Options extends JDialog {
|
||||
} else {
|
||||
defaultPrefs.put("audio.playback.device", "");
|
||||
}
|
||||
defaultPrefs.put("audio.recording.trim.blocksize", "4096");
|
||||
defaultPrefs.put("audio.playback.blocksize", "4096");
|
||||
|
||||
defaultPrefs.put("catenation.pre-chapter", "1000");
|
||||
defaultPrefs.put("catenation.post-chapter", "1500");
|
||||
defaultPrefs.put("catenation.post-sentence", "1000");
|
||||
defaultPrefs.put("catenation.short-sentence", "100");
|
||||
defaultPrefs.put("catenation.post-paragraph", "2000");
|
||||
defaultPrefs.put("catenation.post-section", "3000");
|
||||
|
||||
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.archive", (new File(new File(System.getProperty("user.home"), "Recordings"),"archive")).toString());
|
||||
defaultPrefs.put("path.ffmpeg", "");
|
||||
|
||||
defaultPrefs.put("audio.export.bitrate", "256000");
|
||||
defaultPrefs.put("audio.export.channels", "2");
|
||||
defaultPrefs.put("audio.export.samplerate", "44100");
|
||||
|
||||
defaultPrefs.put("process.sphinx", "false");
|
||||
defaultPrefs.put("process.haven.apikey", "");
|
||||
defaultPrefs.put("process.command", "speech-to-text \"%f\"");
|
||||
defaultPrefs.put("process.threads", "10");
|
||||
|
||||
defaultPrefs.put("editor.external", "");
|
||||
|
||||
defaultPrefs.put("cache.size", "100");
|
||||
|
||||
defaultPrefs.put("audio.eq.0", "0.00");
|
||||
defaultPrefs.put("audio.eq.1", "0.00");
|
||||
defaultPrefs.put("audio.eq.2", "0.00");
|
||||
defaultPrefs.put("audio.eq.3", "0.00");
|
||||
defaultPrefs.put("audio.eq.4", "0.00");
|
||||
defaultPrefs.put("audio.eq.5", "0.00");
|
||||
defaultPrefs.put("audio.eq.6", "0.00");
|
||||
defaultPrefs.put("audio.eq.7", "0.00");
|
||||
defaultPrefs.put("audio.eq.8", "0.00");
|
||||
defaultPrefs.put("audio.eq.9", "0.00");
|
||||
defaultPrefs.put("audio.eq.10", "0.00");
|
||||
defaultPrefs.put("audio.eq.11", "0.00");
|
||||
defaultPrefs.put("audio.eq.12", "0.00");
|
||||
defaultPrefs.put("audio.eq.13", "0.00");
|
||||
defaultPrefs.put("audio.eq.14", "0.00");
|
||||
defaultPrefs.put("audio.eq.15", "0.00");
|
||||
defaultPrefs.put("audio.eq.16", "0.00");
|
||||
defaultPrefs.put("audio.eq.17", "0.00");
|
||||
defaultPrefs.put("audio.eq.18", "0.00");
|
||||
defaultPrefs.put("audio.eq.19", "-1.00");
|
||||
defaultPrefs.put("audio.eq.20", "-2.00");
|
||||
defaultPrefs.put("audio.eq.21", "-3.00");
|
||||
defaultPrefs.put("audio.eq.22", "-4.00");
|
||||
defaultPrefs.put("audio.eq.23", "-5.00");
|
||||
defaultPrefs.put("audio.eq.24", "-6.00");
|
||||
defaultPrefs.put("audio.eq.25", "-7.00");
|
||||
defaultPrefs.put("audio.eq.26", "-8.00");
|
||||
defaultPrefs.put("audio.eq.27", "-9.00");
|
||||
defaultPrefs.put("audio.eq.28", "-10.00");
|
||||
defaultPrefs.put("audio.eq.29", "-11.00");
|
||||
defaultPrefs.put("audio.eq.30", "-12.00");
|
||||
|
||||
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) {
|
||||
prefs = Preferences.userNodeForPackage(AudiobookRecorder.class);
|
||||
}
|
||||
@@ -562,6 +664,14 @@ public class Options extends JDialog {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static Double getDouble(String key) {
|
||||
try {
|
||||
Double f = Double.parseDouble(get(key));
|
||||
return f;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return 0.0d;
|
||||
}
|
||||
public static Float getFloat(String key) {
|
||||
try {
|
||||
Float f = Float.parseFloat(get(key));
|
||||
@@ -631,22 +741,34 @@ public class Options extends JDialog {
|
||||
set("catenation.post-sentence", postSentenceGap.getValue());
|
||||
set("catenation.short-sentence", shortSentenceGap.getValue());
|
||||
set("catenation.post-paragraph", postParagraphGap.getValue());
|
||||
set("catenation.post-section", postSectionGap.getValue());
|
||||
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
||||
set("audio.export.channels", ((KVPair)channels.getSelectedItem()).key);
|
||||
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
||||
set("process.sphinx", enableParsing.isSelected());
|
||||
set("process.haven.apikey", havenApiKey.getText());
|
||||
set("process.command", speechCommand.getText());
|
||||
set("process.threads", workerThreads.getValue());
|
||||
set("editor.external", externalEditor.getText());
|
||||
set("cache.size", cacheSize.getValue());
|
||||
|
||||
set("effects.ethereal.offset", etherealOffset.getValue());
|
||||
set("effects.ethereal.iterations", etherealIterations.getValue());
|
||||
set("effects.ethereal.attenuation", etherealAttenuation.getValue());
|
||||
|
||||
for (int i = 0; i < 31; i++) {
|
||||
set("audio.eq." + i, equaliser.getChannel(i));
|
||||
}
|
||||
set("audio.recording.trim.fft", fftThreshold.getValue());
|
||||
set("audio.recording.variance", maxGainVariance.getValue());
|
||||
set("audio.recording.trim.blocksize", ((KVPair)fftBlockSize.getSelectedItem()).key);
|
||||
set("audio.playback.blocksize", ((KVPair)playbackBlockSize.getSelectedItem()).key);
|
||||
|
||||
set("scripts.startup", startupScript.getText());
|
||||
|
||||
int procNo = 0;
|
||||
for (JTextField[] proc : processorList) {
|
||||
String name = proc[0].getText();
|
||||
String command = proc[1].getText();
|
||||
if (name.equals("") || command.equals("")) {
|
||||
continue;
|
||||
}
|
||||
set("editor.processor." + procNo + ".name", name);
|
||||
set("editor.processor." + procNo + ".command", command);
|
||||
procNo++;
|
||||
}
|
||||
|
||||
savePreferences();
|
||||
}
|
||||
|
||||
@@ -688,15 +810,43 @@ public class Options extends JDialog {
|
||||
}
|
||||
|
||||
public static KVPair[] getResolutionList() {
|
||||
KVPair[] pairs = new KVPair[1];
|
||||
KVPair[] pairs = new KVPair[2];
|
||||
pairs[0] = new KVPair<String, String>("16", "16 Bit");
|
||||
pairs[1] = new KVPair<String, String>("24", "24 Bit");
|
||||
return pairs;
|
||||
}
|
||||
|
||||
public static KVPair[] getTrimMethods() {
|
||||
KVPair[] pairs = new KVPair[2];
|
||||
pairs[0] = new KVPair<String, String>("peak", "Peak Amplitude");
|
||||
pairs[1] = new KVPair<String, String>("fft", "FFT Analysis");
|
||||
KVPair[] pairs = new KVPair[3];
|
||||
pairs[0] = new KVPair<String, String>("none", "None");
|
||||
pairs[1] = new KVPair<String, String>("peak", "Peak Amplitude");
|
||||
pairs[2] = new KVPair<String, String>("fft", "FFT Analysis");
|
||||
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 KVPair[] getPlaybackBlockSizes() {
|
||||
KVPair[] pairs = new KVPair[8];
|
||||
pairs[0] = new KVPair<String, String>("1024", "1024");
|
||||
pairs[1] = new KVPair<String, String>("2048", "2048");
|
||||
pairs[2] = new KVPair<String, String>("4096", "4096");
|
||||
pairs[3] = new KVPair<String, String>("8192", "8192");
|
||||
pairs[4] = new KVPair<String, String>("16384", "16384");
|
||||
pairs[5] = new KVPair<String, String>("32768", "32768");
|
||||
pairs[6] = new KVPair<String, String>("65536", "65537");
|
||||
pairs[7] = new KVPair<String, String>("131072", "131072");
|
||||
return pairs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
public class Overlays {
|
||||
static public final ImageIcon locked = new ImageIcon(Overlays.class.getResource("overlays/locked.png"));
|
||||
|
||||
52
src/uk/co/majenko/audiobookrecorder/Pan.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Pan implements Effect {
|
||||
double pan;
|
||||
public Pan() {
|
||||
pan = 0.0d;
|
||||
}
|
||||
public Pan(double p) {
|
||||
pan = p;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "Pan (" + pan + ")";
|
||||
}
|
||||
|
||||
public ArrayList<Effect> getChildEffects() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void process(double[][] samples) {
|
||||
for (int i = 0; i < samples[Sentence.LEFT].length; i++) {
|
||||
if (pan < 0) {
|
||||
double p = 1 + pan;
|
||||
samples[Sentence.RIGHT][i] *= p;
|
||||
} else {
|
||||
double p = 1 - pan;
|
||||
samples[Sentence.LEFT][i] *= p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double getPan() {
|
||||
return pan;
|
||||
}
|
||||
|
||||
public void setPan(double p) {
|
||||
pan = p;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void dump() {
|
||||
System.out.println(toString());
|
||||
}
|
||||
|
||||
public void init(double sf) {
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,15 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.border.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import it.sauronsoftware.jave.*;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JProgressBar;
|
||||
import java.awt.BorderLayout;
|
||||
import it.sauronsoftware.jave.MultimediaInfo;
|
||||
import it.sauronsoftware.jave.EncoderProgressListener;
|
||||
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 {
|
||||
JLabel message;
|
||||
@@ -44,6 +47,7 @@ public class ProgressDialog extends JDialog implements EncoderProgressListener {
|
||||
pack();
|
||||
|
||||
setSize(new Dimension(300, 100));
|
||||
setResizable(false);
|
||||
|
||||
// setVisible(true);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
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
@@ -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;
|
||||
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import javax.swing.SpinnerModel;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
|
||||
public class SteppedNumericSpinnerModel implements SpinnerModel {
|
||||
int min;
|
||||
|
||||
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,14 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.*;
|
||||
import javax.swing.border.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.RenderingHints;
|
||||
import java.net.URI;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Desktop;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class Utils {
|
||||
public static Image getScaledImage(Image srcImg, int w, int h){
|
||||
@@ -63,4 +63,25 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static long millis = System.currentTimeMillis();
|
||||
|
||||
public static void report(String tag) {
|
||||
long t = System.currentTimeMillis();
|
||||
long d = t - millis;
|
||||
millis = t;
|
||||
System.err.println(String.format("%10d - %10s : %8d | %8d | %8d", d, tag,
|
||||
Runtime.getRuntime().totalMemory(),
|
||||
Runtime.getRuntime().maxMemory(),
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
77
src/uk/co/majenko/audiobookrecorder/VersionChecker.java
Normal file
@@ -0,0 +1,77 @@
|
||||
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;
|
||||
|
||||
System.err.println("Version installed: " + installed);
|
||||
System.err.println("Version available: " + available);
|
||||
System.err.println("URL: " + website);
|
||||
|
||||
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,18 @@
|
||||
package uk.co.majenko.audiobookrecorder;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
import javax.sound.sampled.*;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import javax.swing.JPanel;
|
||||
import java.util.ArrayList;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
|
||||
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
||||
|
||||
int[] samples = null;
|
||||
double[][] samples = null;
|
||||
|
||||
int leftMarker = 0;
|
||||
int rightMarker = 0;
|
||||
@@ -21,6 +24,11 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
int leftAltMarker = 0;
|
||||
int rightAltMarker = 0;
|
||||
|
||||
int cutEntry = 0;
|
||||
int cutExit = 0;
|
||||
boolean displayCut = false;
|
||||
boolean displaySplit = false;
|
||||
|
||||
int dragging = 0;
|
||||
|
||||
int step = 1;
|
||||
@@ -29,6 +37,8 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
int offsetFactor = 0;
|
||||
int offset = 0;
|
||||
|
||||
String loadedId = null;
|
||||
|
||||
ArrayList<MarkerDragListener> markerDragListeners;
|
||||
|
||||
public Waveform() {
|
||||
@@ -62,16 +72,19 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
g.drawLine(x, 0, x, h);
|
||||
}
|
||||
|
||||
int h2 = h/2;
|
||||
int db3 = (int) (h2 * 0.708);
|
||||
|
||||
for (int x = 0; x < w; x += 4) {
|
||||
g.drawLine(x, h/4, x, h/4);
|
||||
g.drawLine(x, h/4*3, x, h/4*3);
|
||||
g.drawLine(x, h2 + db3, x, h2 + db3);
|
||||
g.drawLine(x, h2 - db3, x, h2 - db3);
|
||||
}
|
||||
|
||||
int scale = 32768/(h/2);
|
||||
double scale = (h/2);
|
||||
|
||||
if (samples != null) {
|
||||
|
||||
int num = samples.length;
|
||||
int num = samples[Sentence.LEFT].length;
|
||||
step = num / zoomFactor / w;
|
||||
if (step == 0) return;
|
||||
|
||||
@@ -81,15 +94,16 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
|
||||
for (int n = 0; n < w; n++) {
|
||||
int hcnt = 0;
|
||||
long have = 0;
|
||||
int hmax = 0;
|
||||
double have = 0;
|
||||
double hmax = 0;
|
||||
|
||||
int lcnt = 0;
|
||||
int lave = 0;
|
||||
int lmax = 0;
|
||||
double lave = 0;
|
||||
double lmax = 0;
|
||||
|
||||
for (int o = 0; o < step; o++) {
|
||||
int sample = samples[offset + (n * step) + o];
|
||||
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) {
|
||||
have += sample;
|
||||
hcnt++;
|
||||
@@ -107,30 +121,30 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
|
||||
boolean clip = false;
|
||||
|
||||
if (lmax > 32000) { // -3dB == 23198?
|
||||
if (lmax > 0.708) { // -3dB == 23198?
|
||||
clip = true;
|
||||
}
|
||||
|
||||
if (hmax > 32000) { // -3dB
|
||||
if (hmax > 0.708) { // -3dB
|
||||
clip = true;
|
||||
}
|
||||
|
||||
hmax /= scale;
|
||||
lmax /= scale;
|
||||
have /= scale;
|
||||
lave /= scale;
|
||||
hmax *= scale;
|
||||
lmax *= scale;
|
||||
have *= scale;
|
||||
lave *= scale;
|
||||
|
||||
if (clip) {
|
||||
g.setColor(new Color(200, 20, 0));
|
||||
} else {
|
||||
g.setColor(new Color(0, 20, 200));
|
||||
}
|
||||
g.drawLine(n, h/2 + lmax, n, h/2 - hmax);
|
||||
g.drawLine(n, (int)(h/2 + lmax), n, (int)(h/2 - hmax));
|
||||
g.setColor(new Color(0, 100, 255));
|
||||
g.drawLine(n, h/2 + (int)lave, n, h/2 - (int)have);
|
||||
g.drawLine(n, (int)(h/2 + lave), n, (int)(h/2 - have));
|
||||
}
|
||||
|
||||
g.setColor(new Color(255, 0, 0, 32));
|
||||
g.setColor(new Color(255, 0, 0, 64));
|
||||
g.fillRect(0, 0, (leftAltMarker - offset)/step, h);
|
||||
g.fillRect((rightAltMarker - offset)/step, 0, (num - rightAltMarker) / step , h);
|
||||
|
||||
@@ -142,6 +156,19 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
g.drawLine((leftMarker - offset)/step, 0, (leftMarker - offset)/step, h);
|
||||
g.drawLine((rightMarker - offset)/step, 0, (rightMarker - offset)/step, h);
|
||||
|
||||
if (displayCut || displaySplit) {
|
||||
g.setColor(new Color(0, 255, 255));
|
||||
g.drawLine((cutEntry - offset)/step, 0, (cutEntry - offset)/step, h);
|
||||
}
|
||||
|
||||
if (displayCut) {
|
||||
g.setColor(new Color(0, 255, 255));
|
||||
g.drawLine((cutExit - offset)/step, 0, (cutExit - offset)/step, h);
|
||||
|
||||
g.setColor(new Color(0, 255, 255, 80));
|
||||
g.fillRect((cutEntry - offset)/step, 0, ((cutExit - offset) - (cutEntry - offset))/step , h);
|
||||
}
|
||||
|
||||
g.setColor(new Color(0, 255, 255));
|
||||
for (int i = 0; i < h; i += 2) {
|
||||
g.drawLine((playMarker - offset) / step, i, (playMarker - offset) / step, i);
|
||||
@@ -186,9 +213,11 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setData(int[] s) {
|
||||
public void setData(double[][] s) {
|
||||
samples = s;
|
||||
playMarker = 0;
|
||||
displayCut = false;
|
||||
displaySplit = false;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@@ -218,6 +247,19 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
dragging = 2;
|
||||
return;
|
||||
}
|
||||
if (displayCut || displaySplit) {
|
||||
if ((x >= ((cutEntry - offset)/step) - 10) && (x <= ((cutEntry - offset)/step) + 10)) {
|
||||
dragging = 3;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (displayCut) {
|
||||
if ((x >= ((cutExit - offset)/step) - 10) && (x <= ((cutExit - offset)/step) + 10)) {
|
||||
dragging = 4;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
@@ -248,6 +290,19 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
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 ((x >= ((cutExit - offset)/step) - 10) && (x <= ((cutExit - offset)/step) + 10)) {
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||
|
||||
@@ -267,6 +322,18 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
if (rightMarker < leftMarker) {
|
||||
rightMarker = leftMarker;
|
||||
}
|
||||
} else if (dragging == 3) {
|
||||
cutEntry = (x * step) + offset;
|
||||
if (displayCut) {
|
||||
if (cutEntry > cutExit) {
|
||||
cutEntry = cutExit;
|
||||
}
|
||||
}
|
||||
} else if (dragging == 4) {
|
||||
cutExit = (x * step) + offset;
|
||||
if (cutExit < cutEntry) {
|
||||
cutExit = cutEntry;
|
||||
}
|
||||
}
|
||||
|
||||
repaint();
|
||||
@@ -296,4 +363,41 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
||||
playMarker = leftAltMarker + m;
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setDisplayCut(boolean c) {
|
||||
displayCut = c;
|
||||
displaySplit = false;
|
||||
if (displayCut) {
|
||||
int d = rightMarker - leftMarker;
|
||||
cutEntry = leftMarker + (d / 3);
|
||||
cutExit = leftMarker + (d / 3 * 2);
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
public void setDisplaySplit(boolean c) {
|
||||
displayCut = false;
|
||||
displaySplit = c;
|
||||
if (displaySplit) {
|
||||
int d = rightMarker - leftMarker;
|
||||
cutEntry = leftMarker + (d / 2);
|
||||
}
|
||||
repaint();
|
||||
}
|
||||
|
||||
public int getCutStart() {
|
||||
return cutEntry;
|
||||
}
|
||||
|
||||
public int getCutEnd() {
|
||||
return cutExit;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
loadedId = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return loadedId;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||