Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 146bf5a3c2 | |||
| b05bfde094 | |||
| 37d372b8f5 | |||
| c01fee3b73 | |||
| c907e735c6 | |||
| 7545e33d2f | |||
| ebf961449a | |||
| 45d6882527 | |||
| 2ec370ad61 | |||
| 63d5c4af8e | |||
| 9619fd574e | |||
| adeb42070d | |||
| d207d246bf | |||
| 4dd3a3b874 | |||
| 52b04a754c | |||
| c0efd152e8 | |||
| 9bda80d40d | |||
| 0e12995063 | |||
| 424ebafab5 | |||
| 73d4feb679 | |||
| 887b2a9205 | |||
| 927eb3e1ff | |||
| fd19f5befe | |||
| 382775d6ab |
77
ExampleFilters/README.md
Normal file
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>
|
||||||
7
ExampleFilters/alien.eff
Normal file
7
ExampleFilters/alien.eff
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<effect name="Alien">
|
||||||
|
<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" />
|
||||||
|
<lfo frequency="100" depth="0.5" />
|
||||||
|
</effect>
|
||||||
13
ExampleFilters/bigecho.eff
Normal file
13
ExampleFilters/bigecho.eff
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<effect name="Big Echo">
|
||||||
|
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||||
|
<delayline>
|
||||||
|
<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
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
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" attack="0.1" decay="0.01" />
|
||||||
|
</effect>
|
||||||
23
ExampleFilters/ethereal.eff
Normal file
23
ExampleFilters/ethereal.eff
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<effect name="Ethereal Voice">
|
||||||
|
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||||
|
<amplifier gain="0.1" />
|
||||||
|
<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
2
ExampleFilters/flat.eff
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<effect name="Flat">
|
||||||
|
</effect>
|
||||||
18
ExampleFilters/largeroom.eff
Normal file
18
ExampleFilters/largeroom.eff
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<effect name="Large Room (quiet)">
|
||||||
|
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||||
|
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||||
|
<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>
|
||||||
18
ExampleFilters/largeroomloud.eff
Normal file
18
ExampleFilters/largeroomloud.eff
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<effect name="Large Room (loud)">
|
||||||
|
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||||
|
<biquad type="lowpass" fc="10000" q="1" gain="-10" />
|
||||||
|
<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>
|
||||||
11
ExampleFilters/phone.eff
Normal file
11
ExampleFilters/phone.eff
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<effect name="Telephone">
|
||||||
|
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||||
|
<biquad type="lowshelf" fc="400" q="10" gain="-20" />
|
||||||
|
<biquad type="highshelf" fc="8000" q="10" gain="-20" />
|
||||||
|
<delayline>
|
||||||
|
<delay samples="100" gain="0.5" />
|
||||||
|
</delayline>
|
||||||
|
<amplifier gain="1.4" />
|
||||||
|
</effect>
|
||||||
14
ExampleFilters/radio.eff
Normal file
14
ExampleFilters/radio.eff
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<effect name="Radio">
|
||||||
|
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||||
|
<amplifier gain="0.1" />
|
||||||
|
<biquad type="peak" fc="1000" q="10" gain="45" />
|
||||||
|
<lfo frequency="5000" depth="0.3" />
|
||||||
|
<clipping clip="0.3" />
|
||||||
|
<biquad type="highshelf" fc="8000" q="1" gain="-20" />
|
||||||
|
<delayline>
|
||||||
|
<delay samples="100" gain="0.7" />
|
||||||
|
<delay samples="200" gain="0.5" />
|
||||||
|
</delayline>
|
||||||
|
</effect>
|
||||||
13
ExampleFilters/robotic.eff
Normal file
13
ExampleFilters/robotic.eff
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<effect name="Robotic">
|
||||||
|
<biquad type="notch" fc="28" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="91" q="20" gain="-50" />
|
||||||
|
<biquad type="notch" fc="120" q="20" gain="-50" />
|
||||||
|
<biquad type="lowshelf" fc="100" q="2" gain="-20" />
|
||||||
|
<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>
|
||||||
@@ -8,6 +8,7 @@ A system for easing the task of recording and editing audiobooks.
|
|||||||
* Zero editing
|
* Zero editing
|
||||||
* MP3 export
|
* MP3 export
|
||||||
* Chapter management
|
* Chapter management
|
||||||
|
* Audio effect chains (biquad, delay line, etc)
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
@@ -52,17 +53,13 @@ edit the text of this ID to identify the recordings. You
|
|||||||
may, for instance, change it to have the same text as the
|
may, for instance, change it to have the same text as the
|
||||||
audio contains.
|
audio contains.
|
||||||
|
|
||||||
To help with this CMU Sphinx (US EN dictionary) is bundled
|
To help with this the Haven On-Demand online speech recognition
|
||||||
with the system and can be used to try and convert the
|
service is integrated with the system and can be used to try and convert the
|
||||||
audio into text. Right clicking on a recording brings
|
audio into text. Right clicking on a recording brings
|
||||||
up a menu which includes the option to try and convert
|
up a menu which includes the option to try and convert
|
||||||
the audio into text. The detected text is then used to
|
the audio into text. The detected text is then used to
|
||||||
replace the current recording ID / text.
|
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.
|
|
||||||
|
|
||||||
File layout
|
File layout
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
debug="true"
|
debug="true"
|
||||||
debuglevel="lines,vars,source"
|
debuglevel="lines,vars,source"
|
||||||
encoding="UTF-8"
|
encoding="UTF-8"
|
||||||
bootclasspath="${bootclass.path}"
|
bootclasspath="/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar"
|
||||||
includeAntRuntime="false"
|
includeAntRuntime="false"
|
||||||
deprecation="true"
|
deprecation="true"
|
||||||
srcdir="src"
|
srcdir="src"
|
||||||
|
|||||||
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
Normal file
BIN
deps/sphinx4-core-5prealpha-SNAPSHOT.jar
LFS
vendored
Normal file
Binary file not shown.
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
Normal file
BIN
deps/sphinx4-data-5prealpha-SNAPSHOT.jar
LFS
vendored
Normal file
Binary file not shown.
@@ -1 +1 @@
|
|||||||
version=0.1.4
|
version=0.1.7
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
67
src/uk/co/majenko/audiobookrecorder/AGC.java
Normal file
67
src/uk/co/majenko/audiobookrecorder/AGC.java
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
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) {
|
||||||
|
ceiling = c;
|
||||||
|
attack = a;
|
||||||
|
decay = d;
|
||||||
|
limit = l;
|
||||||
|
gain = 1d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "AGC (Ceiling = " + ceiling + " attack = " + attack + " decay = " + decay + " limit = " + limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process(Sample[] samples) {
|
||||||
|
gain = 1d;
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
double absSampleLeft = Math.abs(samples[i].left) * gain;
|
||||||
|
double absSampleRight = Math.abs(samples[i].right) * gain;
|
||||||
|
|
||||||
|
if (absSampleLeft > ceiling) {
|
||||||
|
gain -= attack;
|
||||||
|
if (gain < 0) gain = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (absSampleRight > ceiling) {
|
||||||
|
gain -= attack;
|
||||||
|
if (gain < 0) gain = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((absSampleLeft < ceiling) && (absSampleRight < ceiling)) {
|
||||||
|
gain += decay;
|
||||||
|
if (gain > limit) {
|
||||||
|
gain = limit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
samples[i].left *= gain;
|
||||||
|
samples[i].right *= gain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(double sr) {
|
||||||
|
gain = 1d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dump() {
|
||||||
|
System.out.println(toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
47
src/uk/co/majenko/audiobookrecorder/Amplifier.java
Normal file
47
src/uk/co/majenko/audiobookrecorder/Amplifier.java
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Amplifier implements Effect {
|
||||||
|
double gain;
|
||||||
|
public Amplifier() {
|
||||||
|
gain = 1.0d;
|
||||||
|
}
|
||||||
|
public Amplifier(double g) {
|
||||||
|
gain = g;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "Amplifier (" + gain + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Effect> getChildEffects() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process(Sample[] samples) {
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
samples[i].left *= gain;
|
||||||
|
samples[i].right *= gain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getGain() {
|
||||||
|
return gain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGain(double g) {
|
||||||
|
gain = g;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dump() {
|
||||||
|
System.out.println(toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(double sf) {
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
255
src/uk/co/majenko/audiobookrecorder/Biquad.java
Normal file
255
src/uk/co/majenko/audiobookrecorder/Biquad.java
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
// Biquad.java
|
||||||
|
//
|
||||||
|
// Created by Nigel Redmon on 11/24/12
|
||||||
|
// EarLevel Engineering: earlevel.com
|
||||||
|
// Copyright 2012 Nigel Redmon
|
||||||
|
// Translated to Java 2019 Majenko Technologies
|
||||||
|
//
|
||||||
|
// For a complete explanation of the Biquad code:
|
||||||
|
// http://www.earlevel.com/main/2012/11/26/biquad-c-source-code/
|
||||||
|
//
|
||||||
|
// License:
|
||||||
|
//
|
||||||
|
// This source code is provided as is, without warranty.
|
||||||
|
// You may copy and distribute verbatim copies of this document.
|
||||||
|
// You may modify and use this source code to create binary code
|
||||||
|
// for your own purposes, free or commercial.
|
||||||
|
//
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
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() {
|
||||||
|
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) {
|
||||||
|
setBiquad(type, Fc, Q, peakGainDB);
|
||||||
|
lz1 = 0.0;
|
||||||
|
lz2 = 0.0;
|
||||||
|
rz1 = 0.0;
|
||||||
|
rz2 = 0.0;
|
||||||
|
sampleFrequency = 44100d;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(int typei) {
|
||||||
|
type = typei;
|
||||||
|
calcBiquad();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQ(double Qi) {
|
||||||
|
Q = Qi;
|
||||||
|
calcBiquad();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFc(double Fci) {
|
||||||
|
Fc = Fci;
|
||||||
|
calcBiquad();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPeakGain(double peakGainDB) {
|
||||||
|
peakGain = peakGainDB;
|
||||||
|
calcBiquad();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBiquad(int typei, double Fci, double Qi, double peakGainDB) {
|
||||||
|
type = typei;
|
||||||
|
Q = Qi;
|
||||||
|
Fc = Fci;
|
||||||
|
setPeakGain(peakGainDB);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process(Sample[] samples) {
|
||||||
|
lz1 = 0d;
|
||||||
|
lz2 = 0d;
|
||||||
|
rz1 = 0d;
|
||||||
|
rz2 = 0d;
|
||||||
|
for (Sample in : samples) {
|
||||||
|
double lout = in.left * a0 + lz1;
|
||||||
|
|
||||||
|
lz1 = in.left * a1 + lz2 - b1 * lout;
|
||||||
|
lz2 = in.left * a2 - b2 * lout;
|
||||||
|
|
||||||
|
double rout = in.right * a0 + rz1;
|
||||||
|
|
||||||
|
rz1 = in.right * a1 + rz2 - b1 * rout;
|
||||||
|
rz2 = in.right * a2 - b2 * rout;
|
||||||
|
|
||||||
|
in.left = lout;
|
||||||
|
in.right = rout;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(double sf) {
|
||||||
|
sampleFrequency = sf;
|
||||||
|
lz1 = 0d;
|
||||||
|
lz2 = 0d;
|
||||||
|
rz1 = 0d;
|
||||||
|
rz2 = 0d;
|
||||||
|
calcBiquad();
|
||||||
|
}
|
||||||
|
|
||||||
|
void calcBiquad() {
|
||||||
|
|
||||||
|
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() {
|
||||||
|
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() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dump() {
|
||||||
|
System.out.println(toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@ import java.util.*;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import javax.swing.tree.*;
|
import javax.swing.tree.*;
|
||||||
import davaguine.jeq.core.IIRControls;
|
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
||||||
|
|
||||||
public class Book extends DefaultMutableTreeNode {
|
public class Book extends DefaultMutableTreeNode {
|
||||||
@@ -25,10 +24,6 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
|
|
||||||
ImageIcon icon;
|
ImageIcon icon;
|
||||||
|
|
||||||
public Equaliser[] equaliser = new Equaliser[2];
|
|
||||||
|
|
||||||
float[] eqChannels = new float[31];
|
|
||||||
|
|
||||||
Properties prefs;
|
Properties prefs;
|
||||||
|
|
||||||
public Book(Properties p, String bookname) {
|
public Book(Properties p, String bookname) {
|
||||||
@@ -36,8 +31,6 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
|
|
||||||
prefs = p;
|
prefs = p;
|
||||||
name = bookname;
|
name = bookname;
|
||||||
equaliser[0] = new Equaliser("Default");
|
|
||||||
equaliser[1] = new Equaliser("Phone");
|
|
||||||
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
AudiobookRecorder.window.setTitle("AudioBook Recorder :: " + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,4 +180,30 @@ public class Book extends DefaultMutableTreeNode {
|
|||||||
public void set(String key, Integer value) {
|
public void set(String key, Integer value) {
|
||||||
prefs.setProperty(key, "" + value);
|
prefs.setProperty(key, "" + value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getBookFolder() {
|
||||||
|
File dir = new File(Options.get("path.storage"), name);
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getUsedEffects() {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,9 +31,11 @@ public class BookTreeRenderer extends DefaultTreeCellRenderer {
|
|||||||
icn.add(Overlays.important, OverlayIcon.TOP_RIGHT);
|
icn.add(Overlays.important, OverlayIcon.TOP_RIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s.getEthereal()) {
|
if (s.getEffectChain() != null) {
|
||||||
|
if (!s.getEffectChain().equals("none")) {
|
||||||
icn.add(Overlays.filter, OverlayIcon.BOTTOM_RIGHT);
|
icn.add(Overlays.filter, OverlayIcon.BOTTOM_RIGHT);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret.setIcon(icn);
|
ret.setIcon(icn);
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,8 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
attributes.setAudioAttributes(audioAttributes);
|
attributes.setAudioAttributes(audioAttributes);
|
||||||
|
|
||||||
|
|
||||||
AudioFormat format = AudiobookRecorder.window.roomNoise.getAudioFormat();
|
AudioFormat sampleformat = AudiobookRecorder.window.roomNoise.getAudioFormat();
|
||||||
|
AudioFormat format = new AudioFormat(sampleformat.getSampleRate(), 16, 1, true, false);
|
||||||
byte[] data;
|
byte[] data;
|
||||||
|
|
||||||
int fullLength = 0;
|
int fullLength = 0;
|
||||||
@@ -149,7 +150,7 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
kidno++;
|
kidno++;
|
||||||
if (exportDialog != null) exportDialog.setProgress(kidno * 1000 / kids);
|
if (exportDialog != null) exportDialog.setProgress(kidno * 1000 / kids);
|
||||||
Sentence snt = (Sentence)s.nextElement();
|
Sentence snt = (Sentence)s.nextElement();
|
||||||
data = snt.getRawAudioData();
|
data = snt.getPCMData();
|
||||||
|
|
||||||
fullLength += data.length;
|
fullLength += data.length;
|
||||||
fos.write(data);
|
fos.write(data);
|
||||||
@@ -214,4 +215,22 @@ public class Chapter extends DefaultMutableTreeNode {
|
|||||||
return totalTime;
|
return totalTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getUsedEffects() {
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
49
src/uk/co/majenko/audiobookrecorder/Clipping.java
Normal file
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(Sample[] samples) {
|
||||||
|
for (Sample sample : samples) {
|
||||||
|
if (sample.left > clip) sample.left = clip;
|
||||||
|
if (sample.left < -clip) sample.left = -clip;
|
||||||
|
if (sample.right > clip) sample.right = clip;
|
||||||
|
if (sample.right < -clip) sample.right = -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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
109
src/uk/co/majenko/audiobookrecorder/DelayLine.java
Normal file
109
src/uk/co/majenko/audiobookrecorder/DelayLine.java
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
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(Sample[] samples) {
|
||||||
|
Sample[] savedSamples = new Sample[samples.length];
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
savedSamples[i] = new Sample(samples[i].left, samples[i].right);
|
||||||
|
}
|
||||||
|
if (wetOnly) {
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
samples[i].left = 0d;
|
||||||
|
samples[i].right = 0d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DelayLineStore d : delayLines) {
|
||||||
|
Sample[] subSamples = new Sample[samples.length];
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
subSamples[i] = new Sample(savedSamples[i].left, savedSamples[i].right);
|
||||||
|
}
|
||||||
|
|
||||||
|
d.process(subSamples);
|
||||||
|
|
||||||
|
for (int i = 0; i < subSamples.length; i++) {
|
||||||
|
int off = i + d.getSamples();
|
||||||
|
if ((off < samples.length) && (off > 0)) {
|
||||||
|
|
||||||
|
Sample ns = mix(samples[off], subSamples[i]);
|
||||||
|
samples[off].left = ns.left;
|
||||||
|
samples[off].right = ns.right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Sample mix(Sample a, Sample b) {
|
||||||
|
Sample out = new Sample(0, 0);
|
||||||
|
|
||||||
|
if ((a.left < 0) && (b.left < 0)) {
|
||||||
|
out.left = (a.left + b.left) - (a.left * b.left);
|
||||||
|
} else if ((a.left > 0) && (b.left > 0)) {
|
||||||
|
out.left = (a.left + b.left) - (a.left * b.left);
|
||||||
|
} else {
|
||||||
|
out.left = a.left + b.left;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((a.right < 0) && (b.right < 0)) {
|
||||||
|
out.right = (a.right + b.right) - (a.right * b.right);
|
||||||
|
} else if ((a.right > 0) && (b.right > 0)) {
|
||||||
|
out.right = (a.right + b.right) - (a.right * b.right);
|
||||||
|
} else {
|
||||||
|
out.right = a.right + b.right;
|
||||||
|
}
|
||||||
|
|
||||||
|
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
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(Sample[] samples) {
|
||||||
|
for (Effect e : effects) {
|
||||||
|
e.process(samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Sample sample : samples) {
|
||||||
|
sample.left *= gain;
|
||||||
|
sample.right *= gain;
|
||||||
|
|
||||||
|
if (pan < 0) {
|
||||||
|
double p = 1 + pan;
|
||||||
|
sample.right *= p;
|
||||||
|
} else {
|
||||||
|
double p = 1 - pan;
|
||||||
|
sample.left *= 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
12
src/uk/co/majenko/audiobookrecorder/Effect.java
Normal file
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(Sample[] 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
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(Sample[] 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,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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
67
src/uk/co/majenko/audiobookrecorder/LFO.java
Normal file
67
src/uk/co/majenko/audiobookrecorder/LFO.java
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class LFO implements Effect {
|
||||||
|
|
||||||
|
double phase;
|
||||||
|
double frequency;
|
||||||
|
double depth;
|
||||||
|
double sampleRate;
|
||||||
|
double sampleStep;
|
||||||
|
|
||||||
|
public LFO(double f, double d) {
|
||||||
|
frequency = f;
|
||||||
|
depth = d;
|
||||||
|
phase = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LFO(double f, double d, double p) {
|
||||||
|
frequency = f;
|
||||||
|
depth = d;
|
||||||
|
phase = p;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void process(Sample[] samples) {
|
||||||
|
for (Sample sample : samples) {
|
||||||
|
double v = Math.sin(phase);
|
||||||
|
phase += sampleStep;
|
||||||
|
if (phase > (Math.PI * 2d)) {
|
||||||
|
phase -= (Math.PI * 2d);
|
||||||
|
}
|
||||||
|
|
||||||
|
// // Make it between 0 and 1.
|
||||||
|
// v = 1d + v;
|
||||||
|
// v /= 2d;
|
||||||
|
|
||||||
|
// Multiply it by the gain factor
|
||||||
|
v *= depth;
|
||||||
|
|
||||||
|
// Apply it to the sample
|
||||||
|
sample.left += (sample.left * v);
|
||||||
|
sample.right += (sample.right * v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(); }
|
||||||
|
|
||||||
|
}
|
||||||
@@ -86,9 +86,9 @@ public class MainToolBar extends JToolBar {
|
|||||||
add(stopPlaying);
|
add(stopPlaying);
|
||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
eq = new JButtonSpacePlay(Icons.eq, "Equaliser", new ActionListener() {
|
eq = new JButtonSpacePlay(Icons.eq, "Reload Effects", new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
root.showEqualiser();
|
root.loadEffects();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.awt.event.*;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.prefs.*;
|
import java.util.prefs.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import javax.swing.tree.*;
|
||||||
|
|
||||||
public class Options extends JDialog {
|
public class Options extends JDialog {
|
||||||
|
|
||||||
@@ -15,6 +16,8 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
GridBagConstraints constraint;
|
GridBagConstraints constraint;
|
||||||
|
|
||||||
|
public static ArrayList<EffectGroup> effectChains;
|
||||||
|
|
||||||
JComboBox<KVPair> mixerList;
|
JComboBox<KVPair> mixerList;
|
||||||
JComboBox<KVPair> playbackList;
|
JComboBox<KVPair> playbackList;
|
||||||
JComboBox<KVPair> channelList;
|
JComboBox<KVPair> channelList;
|
||||||
@@ -28,22 +31,21 @@ public class Options extends JDialog {
|
|||||||
JSpinner postSentenceGap;
|
JSpinner postSentenceGap;
|
||||||
JSpinner shortSentenceGap;
|
JSpinner shortSentenceGap;
|
||||||
JSpinner postParagraphGap;
|
JSpinner postParagraphGap;
|
||||||
|
JSpinner postSectionGap;
|
||||||
JTextField ffmpegLocation;
|
JTextField ffmpegLocation;
|
||||||
JComboBox<KVPair> bitRate;
|
JComboBox<KVPair> bitRate;
|
||||||
JComboBox<KVPair> exportRate;
|
JComboBox<KVPair> exportRate;
|
||||||
JCheckBox enableParsing;
|
JCheckBox enableParsing;
|
||||||
JSpinner cacheSize;
|
JSpinner cacheSize;
|
||||||
|
|
||||||
|
JSpinner fftThreshold;
|
||||||
|
|
||||||
JSpinner etherealIterations;
|
JSpinner etherealIterations;
|
||||||
JSpinner etherealAttenuation;
|
JSpinner etherealAttenuation;
|
||||||
JSpinner etherealOffset;
|
JSpinner etherealOffset;
|
||||||
|
|
||||||
JTextField havenApiKey;
|
|
||||||
|
|
||||||
JTextField externalEditor;
|
JTextField externalEditor;
|
||||||
|
|
||||||
Equaliser equaliser;
|
|
||||||
|
|
||||||
JTextArea startupScript;
|
JTextArea startupScript;
|
||||||
|
|
||||||
ArrayList<JTextField[]> processorList;
|
ArrayList<JTextField[]> processorList;
|
||||||
@@ -294,6 +296,7 @@ public class Options extends JDialog {
|
|||||||
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"));
|
rateList = addDropdown(optionsPanel, "Sample rate:", getSampleRateList(), get("audio.recording.samplerate"));
|
||||||
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"));
|
bitDepth = addDropdown(optionsPanel, "Sample resolution:", getResolutionList(), get("audio.recording.resolution"));
|
||||||
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"));
|
trimMethod = addDropdown(optionsPanel, "Auto-trim method:", getTrimMethods(), get("audio.recording.trim"));
|
||||||
|
fftThreshold = addSpinner(optionsPanel, "FFT threshold:", 0, 100, 1, getInteger("audio.recording.trim.fft"), "");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
@@ -309,6 +312,7 @@ public class Options extends JDialog {
|
|||||||
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms");
|
postSentenceGap = addSpinner(optionsPanel, "Default post-sentence gap:", 0, 5000, 100, getInteger("catenation.post-sentence"), "ms");
|
||||||
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms");
|
shortSentenceGap = addSpinner(optionsPanel, "Short post-sentence gap:", 0, 5000, 100, getInteger("catenation.short-sentence"), "ms");
|
||||||
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms");
|
postParagraphGap = addSpinner(optionsPanel, "Default post-paragraph gap:", 0, 5000, 100, getInteger("catenation.post-paragraph"), "ms");
|
||||||
|
postSectionGap = addSpinner(optionsPanel, "Default post-section gap:", 0, 5000, 100, getInteger("catenation.post-section"), "ms");
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
@@ -319,8 +323,7 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
enableParsing = addCheckBox(optionsPanel, "Enable automatic speech-to-text submission", getBoolean("process.haven.auto"));
|
enableParsing = addCheckBox(optionsPanel, "Enable automatic sphinx speech-to-text (**SLOW**)", getBoolean("process.sphinx"));
|
||||||
havenApiKey = addTextField(optionsPanel, "Haven OnDemand API Key", get("process.haven.apikey"));
|
|
||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
|
|
||||||
@@ -332,11 +335,23 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
addSeparator(optionsPanel);
|
addSeparator(optionsPanel);
|
||||||
tabs.add("Options", new JScrollPane(optionsPanel));
|
tabs.add("Options", new JScrollPane(optionsPanel));
|
||||||
equaliser = new Equaliser("Default");
|
|
||||||
for (int i = 0; i < 31; i++) {
|
JPanel effectChains = new JPanel();
|
||||||
equaliser.setChannel(i, Options.getFloat("audio.eq." + i));
|
effectChains.setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
JPanel effectDetails = new JPanel() {
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return new Dimension(200, 400);
|
||||||
}
|
}
|
||||||
tabs.add("Default EQ", new JScrollPane(equaliser));
|
};
|
||||||
|
|
||||||
|
DefaultTreeModel m = new DefaultTreeModel(new DefaultMutableTreeNode("Effect Chains"));
|
||||||
|
|
||||||
|
JTree effectChainTree = new JTree(m);
|
||||||
|
effectChains.add(effectChainTree, BorderLayout.CENTER);
|
||||||
|
effectChains.add(effectDetails, BorderLayout.EAST);
|
||||||
|
|
||||||
|
tabs.add("Effects Chains", new JScrollPane(effectChains));
|
||||||
|
|
||||||
JPanel startScript = new JPanel();
|
JPanel startScript = new JPanel();
|
||||||
startScript.setLayout(new BorderLayout());
|
startScript.setLayout(new BorderLayout());
|
||||||
@@ -440,6 +455,7 @@ public class Options extends JDialog {
|
|||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
static KVPair<String, String>[] getRecordingMixerList() {
|
static KVPair<String, String>[] getRecordingMixerList() {
|
||||||
TreeSet<KVPair<String, String>> list = new TreeSet<KVPair<String, String>>();
|
TreeSet<KVPair<String, String>> list = new TreeSet<KVPair<String, String>>();
|
||||||
|
|
||||||
@@ -555,6 +571,9 @@ public class Options extends JDialog {
|
|||||||
defaultPrefs.put("catenation.post-sentence", "1000");
|
defaultPrefs.put("catenation.post-sentence", "1000");
|
||||||
defaultPrefs.put("catenation.short-sentence", "100");
|
defaultPrefs.put("catenation.short-sentence", "100");
|
||||||
defaultPrefs.put("catenation.post-paragraph", "2000");
|
defaultPrefs.put("catenation.post-paragraph", "2000");
|
||||||
|
defaultPrefs.put("catenation.post-section", "3000");
|
||||||
|
|
||||||
|
defaultPrefs.put("audio.recording.trim.fft", "10");
|
||||||
|
|
||||||
defaultPrefs.put("path.storage", (new File(System.getProperty("user.home"), "Recordings")).toString());
|
defaultPrefs.put("path.storage", (new File(System.getProperty("user.home"), "Recordings")).toString());
|
||||||
defaultPrefs.put("path.archive", (new File(new File(System.getProperty("user.home"), "Recordings"),"archive")).toString());
|
defaultPrefs.put("path.archive", (new File(new File(System.getProperty("user.home"), "Recordings"),"archive")).toString());
|
||||||
@@ -562,46 +581,12 @@ public class Options extends JDialog {
|
|||||||
|
|
||||||
defaultPrefs.put("audio.export.bitrate", "256000");
|
defaultPrefs.put("audio.export.bitrate", "256000");
|
||||||
defaultPrefs.put("audio.export.samplerate", "44100");
|
defaultPrefs.put("audio.export.samplerate", "44100");
|
||||||
|
|
||||||
defaultPrefs.put("process.sphinx", "false");
|
defaultPrefs.put("process.sphinx", "false");
|
||||||
defaultPrefs.put("process.haven.apikey", "");
|
|
||||||
|
|
||||||
defaultPrefs.put("editor.external", "");
|
defaultPrefs.put("editor.external", "");
|
||||||
|
|
||||||
defaultPrefs.put("cache.size", "100");
|
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("scripts.startup", "");
|
||||||
|
|
||||||
defaultPrefs.put("effects.ethereal.offset", "50");
|
defaultPrefs.put("effects.ethereal.offset", "50");
|
||||||
@@ -639,6 +624,14 @@ public class Options extends JDialog {
|
|||||||
return 0;
|
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) {
|
public static Float getFloat(String key) {
|
||||||
try {
|
try {
|
||||||
Float f = Float.parseFloat(get(key));
|
Float f = Float.parseFloat(get(key));
|
||||||
@@ -708,21 +701,18 @@ public class Options extends JDialog {
|
|||||||
set("catenation.post-sentence", postSentenceGap.getValue());
|
set("catenation.post-sentence", postSentenceGap.getValue());
|
||||||
set("catenation.short-sentence", shortSentenceGap.getValue());
|
set("catenation.short-sentence", shortSentenceGap.getValue());
|
||||||
set("catenation.post-paragraph", postParagraphGap.getValue());
|
set("catenation.post-paragraph", postParagraphGap.getValue());
|
||||||
|
set("catenation.post-section", postSectionGap.getValue());
|
||||||
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
set("audio.export.bitrate", ((KVPair)bitRate.getSelectedItem()).key);
|
||||||
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
set("audio.export.samplerate", ((KVPair)exportRate.getSelectedItem()).key);
|
||||||
set("process.sphinx", enableParsing.isSelected());
|
set("process.sphinx", enableParsing.isSelected());
|
||||||
set("process.haven.apikey", havenApiKey.getText());
|
|
||||||
set("editor.external", externalEditor.getText());
|
set("editor.external", externalEditor.getText());
|
||||||
set("cache.size", cacheSize.getValue());
|
set("cache.size", cacheSize.getValue());
|
||||||
|
set("audio.recording.trim.fft", fftThreshold.getValue());
|
||||||
|
|
||||||
set("effects.ethereal.offset", etherealOffset.getValue());
|
set("effects.ethereal.offset", etherealOffset.getValue());
|
||||||
set("effects.ethereal.iterations", etherealIterations.getValue());
|
set("effects.ethereal.iterations", etherealIterations.getValue());
|
||||||
set("effects.ethereal.attenuation", etherealAttenuation.getValue());
|
set("effects.ethereal.attenuation", etherealAttenuation.getValue());
|
||||||
|
|
||||||
for (int i = 0; i < 31; i++) {
|
|
||||||
set("audio.eq." + i, equaliser.getChannel(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
set("scripts.startup", startupScript.getText());
|
set("scripts.startup", startupScript.getText());
|
||||||
|
|
||||||
int procNo = 0;
|
int procNo = 0;
|
||||||
@@ -778,8 +768,9 @@ public class Options extends JDialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static KVPair[] getResolutionList() {
|
public static KVPair[] getResolutionList() {
|
||||||
KVPair[] pairs = new KVPair[1];
|
KVPair[] pairs = new KVPair[2];
|
||||||
pairs[0] = new KVPair<String, String>("16", "16 Bit");
|
pairs[0] = new KVPair<String, String>("16", "16 Bit");
|
||||||
|
pairs[1] = new KVPair<String, String>("24", "24 Bit");
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -789,4 +780,52 @@ public class Options extends JDialog {
|
|||||||
pairs[1] = new KVPair<String, String>("fft", "FFT Analysis");
|
pairs[1] = new KVPair<String, String>("fft", "FFT Analysis");
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void createEffectChains() {
|
||||||
|
effectChains = new ArrayList<EffectGroup>();
|
||||||
|
|
||||||
|
for (int i = 0; i < 999999; i++) {
|
||||||
|
if (get("effects." + i + ".name") == null) {
|
||||||
|
EffectGroup e = new EffectGroup(get("effects." + i + ".name"));
|
||||||
|
for (int j = 0; i < 999999; j++) {
|
||||||
|
String type = get("effects." + i + ".children." + j + ".type");
|
||||||
|
if (type == null) break;
|
||||||
|
|
||||||
|
if (type.equals("biquad")) {
|
||||||
|
int bqt = getInteger("effects." + i + ".children." + j + ".filtertype");
|
||||||
|
double fc = getDouble("effects." + i + ".children." + j + ".fc");
|
||||||
|
double q = getDouble("effects." + i + ".children." + j + ".q");
|
||||||
|
double gain = getDouble("effects." + i + ".children." + j + ".gain");
|
||||||
|
Biquad b = new Biquad(bqt, fc, q, gain);
|
||||||
|
e.addEffect(b);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.equals("amplifier")) {
|
||||||
|
double gain = getDouble("effects." + i + ".children." + j + ".gain");
|
||||||
|
Amplifier a = new Amplifier(gain);
|
||||||
|
e.addEffect(a);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.equals("delayline")) {
|
||||||
|
DelayLine l = new DelayLine();
|
||||||
|
for (int c = 0; c < 999999; c++) {
|
||||||
|
if (get("effects." + i + ".children." + j + ".lines." + c + ".samples") == null) break;
|
||||||
|
int samples = getInteger("effects." + i + ".children." + j + ".lines." + c + ".samples");
|
||||||
|
double gain = getDouble("effects." + i + ".children." + j + ".lines." + c + ".gain");
|
||||||
|
l.addDelayLine(samples, gain);
|
||||||
|
}
|
||||||
|
e.addEffect(l);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
effectChains.add(e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
52
src/uk/co/majenko/audiobookrecorder/Pan.java
Normal file
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(Sample[] samples) {
|
||||||
|
for (Sample sample : samples) {
|
||||||
|
if (pan < 0) {
|
||||||
|
double p = 1 + pan;
|
||||||
|
sample.right *= p;
|
||||||
|
} else {
|
||||||
|
double p = 1 - pan;
|
||||||
|
sample.left *= 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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/uk/co/majenko/audiobookrecorder/Sample.java
Normal file
28
src/uk/co/majenko/audiobookrecorder/Sample.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package uk.co.majenko.audiobookrecorder;
|
||||||
|
|
||||||
|
public class Sample {
|
||||||
|
public double left;
|
||||||
|
public double right;
|
||||||
|
|
||||||
|
public Sample(double m) {
|
||||||
|
left = m;
|
||||||
|
right = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sample(double l, double r) {
|
||||||
|
left = l;
|
||||||
|
right = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLeft() {
|
||||||
|
return left;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getRight() {
|
||||||
|
return right;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getMono() {
|
||||||
|
return (left + right) / 2.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,8 +9,6 @@ import java.io.*;
|
|||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
import javax.swing.tree.*;
|
import javax.swing.tree.*;
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
||||||
import davaguine.jeq.spi.EqualizerInputStream;
|
|
||||||
import davaguine.jeq.core.IIRControls;
|
|
||||||
|
|
||||||
import org.apache.http.HttpEntity;
|
import org.apache.http.HttpEntity;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
@@ -23,6 +21,10 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
|||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
|
||||||
|
import edu.cmu.sphinx.api.*;
|
||||||
|
import edu.cmu.sphinx.decoder.adaptation.*;
|
||||||
|
import edu.cmu.sphinx.result.*;
|
||||||
|
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
@@ -47,18 +49,10 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
boolean inSample;
|
boolean inSample;
|
||||||
boolean attention = false;
|
boolean attention = false;
|
||||||
|
|
||||||
int eqProfile = 0;
|
String effectChain = null;
|
||||||
|
|
||||||
double gain = 1.0d;
|
double gain = 1.0d;
|
||||||
|
|
||||||
String havenJobId = "";
|
|
||||||
|
|
||||||
// 0: Not processed
|
|
||||||
// 1: Submitted
|
|
||||||
// 2: Procesisng finished
|
|
||||||
// 3: Processing failed
|
|
||||||
int havenStatus = 0;
|
|
||||||
|
|
||||||
String overrideText = null;
|
String overrideText = null;
|
||||||
|
|
||||||
public void setOverrideText(String s) { overrideText = s; }
|
public void setOverrideText(String s) { overrideText = s; }
|
||||||
@@ -69,7 +63,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
AudioFormat storedFormat = null;
|
AudioFormat storedFormat = null;
|
||||||
double storedLength = -1d;
|
double storedLength = -1d;
|
||||||
|
|
||||||
int[] storedAudioData = null;
|
Sample[] audioData = null;
|
||||||
|
Sample[] processedAudio = null;
|
||||||
|
|
||||||
RecordingThread recordingThread;
|
RecordingThread recordingThread;
|
||||||
|
|
||||||
@@ -163,7 +158,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
recordingThread = new RecordingThread(getTempFile(), getFile(), AudiobookRecorder.window.book.getAudioFormat());
|
recordingThread = new RecordingThread(getTempFile(), getFile(), Options.getAudioFormat());
|
||||||
|
|
||||||
Thread rc = new Thread(recordingThread);
|
Thread rc = new Thread(recordingThread);
|
||||||
rc.setDaemon(true);
|
rc.setDaemon(true);
|
||||||
@@ -181,7 +176,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
storedAudioData = null;
|
audioData = null;
|
||||||
storedFormat = null;
|
storedFormat = null;
|
||||||
storedLength = -1;
|
storedLength = -1;
|
||||||
|
|
||||||
@@ -192,11 +187,10 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
} else if (tm.equals("fft")) {
|
} else if (tm.equals("fft")) {
|
||||||
autoTrimSampleFFT();
|
autoTrimSampleFFT();
|
||||||
}
|
}
|
||||||
if (Options.getBoolean("process.haven.auto")) {
|
if (Options.getBoolean("process.sphinx")) {
|
||||||
recognise();
|
recognise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int FFTBuckets = 1024;
|
public static final int FFTBuckets = 1024;
|
||||||
@@ -205,7 +199,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
double[] real = new double[FFTBuckets];
|
double[] real = new double[FFTBuckets];
|
||||||
double[] imag = new double[FFTBuckets];
|
double[] imag = new double[FFTBuckets];
|
||||||
|
|
||||||
int[] samples = getAudioData();
|
Sample[] samples = getProcessedAudioData();
|
||||||
int slices = (samples.length / FFTBuckets) + 1;
|
int slices = (samples.length / FFTBuckets) + 1;
|
||||||
|
|
||||||
double[][] out = new double[slices][];
|
double[][] out = new double[slices][];
|
||||||
@@ -215,7 +209,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
for (int i = 0; i < samples.length; i += FFTBuckets) {
|
for (int i = 0; i < samples.length; i += FFTBuckets) {
|
||||||
for (int j = 0; j < FFTBuckets; j++) {
|
for (int j = 0; j < FFTBuckets; j++) {
|
||||||
if (i + j < samples.length) {
|
if (i + j < samples.length) {
|
||||||
real[j] = samples[i+j] / 32768d;
|
real[j] = samples[i+j].getMono();
|
||||||
imag[j] = 0;
|
imag[j] = 0;
|
||||||
} else {
|
} else {
|
||||||
real[j] = 0;
|
real[j] = 0;
|
||||||
@@ -234,7 +228,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
public void autoTrimSampleFFT() {
|
public void autoTrimSampleFFT() {
|
||||||
crossStartOffset = -1;
|
crossStartOffset = -1;
|
||||||
crossEndOffset = -1;
|
crossEndOffset = -1;
|
||||||
int[] samples = getAudioData();
|
Sample[] samples = getProcessedAudioData();
|
||||||
if (samples == null) return;
|
if (samples == null) return;
|
||||||
|
|
||||||
int blocks = samples.length / 4096 + 1;
|
int blocks = samples.length / 4096 + 1;
|
||||||
@@ -248,7 +242,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
for (int j = 0; j < 4096; j++) {
|
for (int j = 0; j < 4096; j++) {
|
||||||
if (i + j < samples.length) {
|
if (i + j < samples.length) {
|
||||||
real[j] = samples[i+j] / 32768d;
|
real[j] = samples[i+j].getMono();
|
||||||
imag[j] = 0;
|
imag[j] = 0;
|
||||||
} else {
|
} else {
|
||||||
real[j] = 0;
|
real[j] = 0;
|
||||||
@@ -272,14 +266,15 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
block++;
|
block++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find first block with > 0 intensity and subtract one.
|
int limit = Options.getInteger("audio.recording.trim.fft");
|
||||||
|
|
||||||
|
// Find first block with > 1 intensity and subtract one.
|
||||||
|
|
||||||
int start = 0;
|
int start = 0;
|
||||||
for (int i = 0; i < blocks; i++) {
|
for (int i = 0; i < blocks; i++) {
|
||||||
if (intens[i] > 0) break;
|
if (intens[i] > limit) break;
|
||||||
start = i;
|
start = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,9 +287,9 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
if (startOffset >= samples.length) startOffset = samples.length;
|
if (startOffset >= samples.length) startOffset = samples.length;
|
||||||
|
|
||||||
int end = blocks - 1;
|
int end = blocks - 1;
|
||||||
// And last block with > 0 intensity and add one.
|
// And last block with > 1 intensity and add one.
|
||||||
for (int i = blocks-1; i >= 0; i--) {
|
for (int i = blocks-1; i >= 0; i--) {
|
||||||
if (intens[i] > 0) break;
|
if (intens[i] > limit) break;
|
||||||
end = i;
|
end = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,14 +311,15 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
public void autoTrimSamplePeak() {
|
public void autoTrimSamplePeak() {
|
||||||
crossStartOffset = -1;
|
crossStartOffset = -1;
|
||||||
crossEndOffset = -1;
|
crossEndOffset = -1;
|
||||||
int[] samples = getAudioData();
|
Sample[] samples = getProcessedAudioData();
|
||||||
if (samples == null) return;
|
if (samples == null) return;
|
||||||
int noiseFloor = AudiobookRecorder.window.getNoiseFloor();
|
double noiseFloor = AudiobookRecorder.window.getNoiseFloor();
|
||||||
|
noiseFloor *= 1.1;
|
||||||
|
|
||||||
// Find start
|
// Find start
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
startOffset = i;
|
startOffset = i;
|
||||||
if (Math.abs(samples[i]) > noiseFloor) {
|
if (Math.abs(samples[i].getMono()) > noiseFloor) {
|
||||||
startOffset --;
|
startOffset --;
|
||||||
if (startOffset < 0) startOffset = 0;
|
if (startOffset < 0) startOffset = 0;
|
||||||
break;
|
break;
|
||||||
@@ -338,7 +334,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
for (int i = samples.length-1; i >= 0; i--) {
|
for (int i = samples.length-1; i >= 0; i--) {
|
||||||
endOffset = i;
|
endOffset = i;
|
||||||
if (Math.abs(samples[i]) > noiseFloor) {
|
if (Math.abs(samples[i].getMono()) > noiseFloor) {
|
||||||
endOffset ++;
|
endOffset ++;
|
||||||
if (endOffset >= samples.length-1) endOffset = samples.length-1;
|
if (endOffset >= samples.length-1) endOffset = samples.length-1;
|
||||||
break;
|
break;
|
||||||
@@ -396,7 +392,11 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return text;
|
if (effectChain == null) return text;
|
||||||
|
if (effectChain.equals("none")) return text;
|
||||||
|
Effect e = AudiobookRecorder.window.effects.get(effectChain);
|
||||||
|
if (e == null) return text;
|
||||||
|
return text + " (" + e.toString() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRecording() {
|
public boolean isRecording() {
|
||||||
@@ -425,91 +425,6 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] getAudioDataS16LE(AudioInputStream s, AudioFormat format) throws IOException {
|
|
||||||
return getAudioDataS16LE(s, format, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getAudioDataS16LE(AudioInputStream s, AudioFormat format, boolean amplify) throws IOException {
|
|
||||||
long len = s.getFrameLength();
|
|
||||||
int frameSize = format.getFrameSize();
|
|
||||||
int chans = format.getChannels();
|
|
||||||
int bytes = frameSize / chans;
|
|
||||||
|
|
||||||
byte[] frame = new byte[frameSize];
|
|
||||||
int[] samples = new int[(int)len];
|
|
||||||
|
|
||||||
for (long fno = 0; fno < len; fno++) {
|
|
||||||
|
|
||||||
s.read(frame);
|
|
||||||
int sample = 0;
|
|
||||||
if (chans == 2) { // Stereo
|
|
||||||
int left = (frame[1] << 8) | frame[0];
|
|
||||||
int right = (frame[3] << 8) | frame[2];
|
|
||||||
sample = (left + right) / 2;
|
|
||||||
} else {
|
|
||||||
sample = (frame[1] << 8) | frame[0];
|
|
||||||
}
|
|
||||||
if (amplify) {
|
|
||||||
double amped = (double)sample * gain;
|
|
||||||
samples[(int)fno] = (int)amped;
|
|
||||||
} else {
|
|
||||||
samples[(int)fno] = sample;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return samples;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getAudioData() {
|
|
||||||
if (storedAudioData != null) {
|
|
||||||
return storedAudioData;
|
|
||||||
}
|
|
||||||
File f = getFile();
|
|
||||||
try {
|
|
||||||
AudioInputStream s = AudioSystem.getAudioInputStream(f);
|
|
||||||
AudioFormat format = getAudioFormat();
|
|
||||||
|
|
||||||
int[] samples = null;
|
|
||||||
|
|
||||||
switch (format.getSampleSizeInBits()) {
|
|
||||||
case 16:
|
|
||||||
samples = getAudioDataS16LE(s, format);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
s.close();
|
|
||||||
sampleSize = samples.length;
|
|
||||||
storedAudioData = samples;
|
|
||||||
CacheManager.addToCache(this);
|
|
||||||
return samples;
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int[] getUnprocessedAudioData() {
|
|
||||||
File f = getFile();
|
|
||||||
try {
|
|
||||||
AudioInputStream s = AudioSystem.getAudioInputStream(f);
|
|
||||||
AudioFormat format = getAudioFormat();
|
|
||||||
|
|
||||||
int[] samples = null;
|
|
||||||
|
|
||||||
switch (format.getSampleSizeInBits()) {
|
|
||||||
case 16:
|
|
||||||
samples = getAudioDataS16LE(s, format, false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
s.close();
|
|
||||||
return samples;
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int getStartCrossing() {
|
public int getStartCrossing() {
|
||||||
return crossStartOffset;
|
return crossStartOffset;
|
||||||
}
|
}
|
||||||
@@ -559,33 +474,11 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public int getSampleSize() {
|
public int getSampleSize() {
|
||||||
if (sampleSize == -1) {
|
if (sampleSize == -1) {
|
||||||
getAudioData();
|
loadFile();
|
||||||
}
|
}
|
||||||
return sampleSize;
|
return sampleSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the audio file as an AudioInputStream and automatically
|
|
||||||
// skip the first startOffset frames.
|
|
||||||
public EqualizerInputStream getAudioStream() {
|
|
||||||
File f = getFile();
|
|
||||||
try {
|
|
||||||
AudioInputStream s = AudioSystem.getAudioInputStream(f);
|
|
||||||
EqualizerInputStream eq = new EqualizerInputStream(s, 31);
|
|
||||||
AudioFormat format = getAudioFormat();
|
|
||||||
IIRControls controls = eq.getControls();
|
|
||||||
AudiobookRecorder.window.book.equaliser[eqProfile].apply(controls, format.getChannels());
|
|
||||||
|
|
||||||
int frameSize = format.getFrameSize();
|
|
||||||
|
|
||||||
eq.skip(frameSize * startOffset);
|
|
||||||
|
|
||||||
return eq;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AudioFormat getAudioFormat() {
|
public AudioFormat getAudioFormat() {
|
||||||
if (storedFormat != null) return storedFormat;
|
if (storedFormat != null) return storedFormat;
|
||||||
|
|
||||||
@@ -601,152 +494,57 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte[] getRawAudioData() {
|
public void doRecognition(StreamSpeechRecognizer recognizer) {
|
||||||
File f = getFile();
|
|
||||||
try {
|
try {
|
||||||
updateCrossings();
|
setText("[recognising...]");
|
||||||
AudioInputStream s = AudioSystem.getAudioInputStream(f);
|
AudiobookRecorder.window.bookTreeModel.reload(this);
|
||||||
EqualizerInputStream eq = new EqualizerInputStream(s, 31);
|
|
||||||
|
|
||||||
|
byte[] inData = getPCMData();
|
||||||
|
|
||||||
AudioFormat format = getAudioFormat();
|
ByteArrayInputStream bas = new ByteArrayInputStream(inData);
|
||||||
IIRControls controls = eq.getControls();
|
recognizer.startRecognition(bas);
|
||||||
AudiobookRecorder.window.book.equaliser[eqProfile].apply(controls, format.getChannels());
|
SpeechResult result;
|
||||||
|
String res = "";
|
||||||
int frameSize = format.getFrameSize();
|
while ((result = recognizer.getResult()) != null) {
|
||||||
int length = crossEndOffset - crossStartOffset;
|
res += result.getHypothesis();
|
||||||
|
res += " ";
|
||||||
int bytesToRead = length * frameSize;
|
|
||||||
byte[] data = new byte[bytesToRead];
|
|
||||||
byte[] buf = new byte[65536];
|
|
||||||
|
|
||||||
int pos = 0;
|
|
||||||
|
|
||||||
eq.skip(crossStartOffset * frameSize);
|
|
||||||
|
|
||||||
while (bytesToRead > 0) {
|
|
||||||
int r = eq.read(buf, 0, bytesToRead > 65536 ? 65536 : bytesToRead);
|
|
||||||
for (int i = 0; i < r; i++) {
|
|
||||||
data[pos++] = buf[i];
|
|
||||||
bytesToRead--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
recognizer.stopRecognition();
|
||||||
|
|
||||||
data = postProcessData(data);
|
setText(res);
|
||||||
|
AudiobookRecorder.window.bookTreeModel.reload(this);
|
||||||
return data;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] adjustGain(byte[] data) {
|
|
||||||
AudioFormat format = getAudioFormat();
|
|
||||||
int frameSize = format.getFrameSize();
|
|
||||||
int channels = format.getChannels();
|
|
||||||
int bytesPerChannel = frameSize / channels;
|
|
||||||
|
|
||||||
int frames = data.length / frameSize;
|
|
||||||
|
|
||||||
int byteNo = 0;
|
|
||||||
|
|
||||||
byte[] out = new byte[data.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < frames; i++) {
|
|
||||||
if (channels == 1) {
|
|
||||||
int l = data[i * frameSize] >= 0 ? data[i * frameSize] : 256 + data[i * frameSize];
|
|
||||||
int h = data[(i * frameSize) + 1] >= 0 ? data[(i * frameSize) + 1] : 256 + data[(i * frameSize) + 1];
|
|
||||||
|
|
||||||
int sample = (h << 8) | l;
|
|
||||||
if ((sample & 0x8000) == 0x8000) sample |= 0xFFFF0000;
|
|
||||||
|
|
||||||
double sampleDouble = (double)sample;
|
|
||||||
sampleDouble *= gain;
|
|
||||||
sample = (int)sampleDouble;
|
|
||||||
|
|
||||||
if (sample > 32767) sample = 32767;
|
|
||||||
if (sample < -32768) sample = -32768;
|
|
||||||
out[i * frameSize] = (byte)(sample & 0xFF);
|
|
||||||
out[(i * frameSize) + 1] = (byte)((sample & 0xFF00) >> 8);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] postProcessData(byte[] data) {
|
|
||||||
data = adjustGain(data);
|
|
||||||
|
|
||||||
if (effectEthereal) {
|
|
||||||
data = processEtherealEffect(data);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] processEtherealEffect(byte[] data) {
|
|
||||||
AudioFormat format = getAudioFormat();
|
|
||||||
int frameSize = format.getFrameSize();
|
|
||||||
int channels = format.getChannels();
|
|
||||||
int bytesPerChannel = frameSize / channels;
|
|
||||||
|
|
||||||
int frames = data.length / frameSize;
|
|
||||||
|
|
||||||
int byteNo = 0;
|
|
||||||
|
|
||||||
double fpms = (double)format.getFrameRate() / 1000d;
|
|
||||||
double doubleOffset = fpms * (double) AudiobookRecorder.window.book.getInteger("effects.ethereal.offset");
|
|
||||||
int offset = (int)doubleOffset;
|
|
||||||
double attenuation = 1d - ((double)AudiobookRecorder.window.book.getInteger("effects.ethereal.attenuation") / 100d);
|
|
||||||
|
|
||||||
int copies = AudiobookRecorder.window.book.getInteger("effects.ethereal.iterations");
|
|
||||||
|
|
||||||
byte[] out = new byte[data.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < frames; i++) {
|
|
||||||
if (channels == 1) {
|
|
||||||
int l = data[i * frameSize] >= 0 ? data[i * frameSize] : 256 + data[i * frameSize];
|
|
||||||
int h = data[(i * frameSize) + 1] >= 0 ? data[(i * frameSize) + 1] : 256 + data[(i * frameSize) + 1];
|
|
||||||
|
|
||||||
int sample = (h << 8) | l;
|
|
||||||
if ((sample & 0x8000) == 0x8000) sample |= 0xFFFF0000;
|
|
||||||
|
|
||||||
double sampleDouble = (double)sample;
|
|
||||||
|
|
||||||
int used = 0;
|
|
||||||
for (int j = 0; j < copies; j++) {
|
|
||||||
if (i + (j * offset) < frames) {
|
|
||||||
used++;
|
|
||||||
int lx = data[(i + (j * offset)) * frameSize] >= 0 ? data[(i + (j * offset)) * frameSize] : 256 + data[(i + (j * offset)) * frameSize];
|
|
||||||
int hx = data[((i + (j * offset)) * frameSize) + 1] >= 0 ? data[((i + (j * offset)) * frameSize) + 1] : 256 + data[((i + (j * offset)) * frameSize) + 1];
|
|
||||||
int futureSample = (hx << 8) | lx;
|
|
||||||
if ((futureSample & 0x8000) == 0x8000) futureSample |= 0xFFFF0000;
|
|
||||||
double futureDouble = (double)futureSample;
|
|
||||||
for (int k = 0; k < copies; k++) {
|
|
||||||
futureDouble *= attenuation;
|
|
||||||
}
|
|
||||||
sampleDouble = mix(sampleDouble, futureDouble);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sample = (int)sampleDouble;
|
|
||||||
if (sample > 32767) sample = 32767;
|
|
||||||
if (sample < -32768) sample = -32768;
|
|
||||||
out[i * frameSize] = (byte)(sample & 0xFF);
|
|
||||||
out[(i * frameSize) + 1] = (byte)((sample & 0xFF00) >> 8);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recognise() {
|
public void recognise() {
|
||||||
AudiobookRecorder.window.havenQueue.submit(Sentence.this);
|
Thread t = new Thread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
Configuration sphinxConfig = new Configuration();
|
||||||
|
|
||||||
|
sphinxConfig.setAcousticModelPath(AudiobookRecorder.SPHINX_MODEL);
|
||||||
|
sphinxConfig.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
|
||||||
|
sphinxConfig.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
|
||||||
|
|
||||||
|
AudioInputStream s = AudioSystem.getAudioInputStream(getFile());
|
||||||
|
AudioFormat format = getAudioFormat();
|
||||||
|
|
||||||
|
sphinxConfig.setSampleRate((int)(format.getSampleRate()));
|
||||||
|
|
||||||
|
StreamSpeechRecognizer recognizer;
|
||||||
|
|
||||||
|
recognizer = new StreamSpeechRecognizer(sphinxConfig);
|
||||||
|
|
||||||
|
doRecognition(recognizer);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocked(boolean l) {
|
public void setLocked(boolean l) {
|
||||||
@@ -766,8 +564,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clearCache() {
|
public void clearCache() {
|
||||||
storedAudioData = null;
|
audioData = null;
|
||||||
// System.gc();
|
processedAudio = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean lockedInCache() {
|
public boolean lockedInCache() {
|
||||||
@@ -775,7 +573,7 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int findNearestZeroCrossing(int pos, int range) {
|
public int findNearestZeroCrossing(int pos, int range) {
|
||||||
int[] data = getAudioData();
|
Sample[] data = getProcessedAudioData();
|
||||||
if (data == null) return 0;
|
if (data == null) return 0;
|
||||||
if (data.length == 0) return 0;
|
if (data.length == 0) return 0;
|
||||||
|
|
||||||
@@ -785,19 +583,19 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
int backwards = pos;
|
int backwards = pos;
|
||||||
int forwards = pos;
|
int forwards = pos;
|
||||||
|
|
||||||
int backwardsPrev = data[backwards];
|
double backwardsPrev = data[backwards].getMono();
|
||||||
int forwardsPrev = data[forwards];
|
double forwardsPrev = data[forwards].getMono();
|
||||||
|
|
||||||
while (backwards > 0 || forwards < data.length-2) {
|
while (backwards > 0 || forwards < data.length-2) {
|
||||||
|
|
||||||
if (forwards < data.length-2) forwards++;
|
if (forwards < data.length-2) forwards++;
|
||||||
if (backwards > 0) backwards--;
|
if (backwards > 0) backwards--;
|
||||||
|
|
||||||
if (backwardsPrev >= 0 && data[backwards] < 0) { // Found one!
|
if (backwardsPrev >= 0 && data[backwards].getMono() < 0) { // Found one!
|
||||||
return backwards;
|
return backwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (forwardsPrev < 0 && data[forwards] >= 0) {
|
if (forwardsPrev < 0 && data[forwards].getMono() >= 0) {
|
||||||
return forwards;
|
return forwards;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -806,8 +604,8 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
backwardsPrev = data[backwards];
|
backwardsPrev = data[backwards].getMono();
|
||||||
forwardsPrev = data[forwards];
|
forwardsPrev = data[forwards].getMono();
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
@@ -848,178 +646,26 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
return attention;
|
return attention;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHavenJobId() {
|
public double getPeakValue() {
|
||||||
return havenJobId;
|
double oldGain = gain;
|
||||||
}
|
gain = 1.0d;
|
||||||
|
Sample[] samples = getProcessedAudioData();
|
||||||
public void setHavenJobId(String i) {
|
gain = oldGain;
|
||||||
havenJobId = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getHavenStatus() {
|
|
||||||
return havenStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHavenStatus(int i) {
|
|
||||||
havenStatus = i;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean postHavenData() {
|
|
||||||
String apiKey = Options.get("process.haven.apikey");
|
|
||||||
if (apiKey == null || apiKey.equals("")) return false;
|
|
||||||
|
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
||||||
|
|
||||||
setOverrideText("[submitting...]");
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(this);
|
|
||||||
|
|
||||||
try {
|
|
||||||
HttpPost httppost = new HttpPost("https://api.havenondemand.com/1/api/async/recognizespeech/v2?apikey=" + apiKey);
|
|
||||||
|
|
||||||
FileBody bin = new FileBody(getFile());
|
|
||||||
StringBody language = new StringBody("en-GB");
|
|
||||||
|
|
||||||
HttpEntity reqEntity = MultipartEntityBuilder.create()
|
|
||||||
.addPart("language_model", language)
|
|
||||||
.addPart("file", bin)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
httppost.setEntity(reqEntity);
|
|
||||||
|
|
||||||
CloseableHttpResponse response = httpclient.execute(httppost);
|
|
||||||
try {
|
|
||||||
if (response.getStatusLine().getStatusCode() != 200) {
|
|
||||||
System.err.println("Error posting data: " + response.getStatusLine().getStatusCode());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpEntity resEntity = response.getEntity();
|
|
||||||
if (resEntity != null) {
|
|
||||||
JSONObject obj = new JSONObject(EntityUtils.toString(resEntity));
|
|
||||||
havenJobId = obj.getString("jobID");
|
|
||||||
System.err.println("Submitted new Haven OnDemand job #" + havenJobId);
|
|
||||||
havenStatus = 1;
|
|
||||||
}
|
|
||||||
EntityUtils.consume(resEntity);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return true;
|
|
||||||
// eddec91c-6018-4dcd-bd8d-5e96b23e334c --form "language_model=en-US" --form "file=@3e67460c-f298-4e2c-a412-d375d489e1b3.wav"
|
|
||||||
}
|
|
||||||
|
|
||||||
public void processPendingHaven() {
|
|
||||||
if (havenStatus != 1) return;
|
|
||||||
|
|
||||||
|
|
||||||
String apiKey = Options.get("process.haven.apikey");
|
|
||||||
if (apiKey == null || apiKey.equals("")) return;
|
|
||||||
|
|
||||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
|
||||||
HttpPost httppost = new HttpPost("https://api.havenondemand.com/1/job/status/" + havenJobId + "?apikey=" + apiKey);
|
|
||||||
|
|
||||||
HttpEntity reqEntity = MultipartEntityBuilder.create().build();
|
|
||||||
httppost.setEntity(reqEntity);
|
|
||||||
|
|
||||||
CloseableHttpResponse response = httpclient.execute(httppost);
|
|
||||||
try {
|
|
||||||
if (response.getStatusLine().getStatusCode() != 200) {
|
|
||||||
havenStatus = 3;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpEntity resEntity = response.getEntity();
|
|
||||||
if (resEntity != null) {
|
|
||||||
JSONObject obj = new JSONObject(EntityUtils.toString(resEntity));
|
|
||||||
|
|
||||||
System.err.println(havenJobId + ": " + obj.getString("status"));
|
|
||||||
|
|
||||||
if (obj.getString("status").equals("finished")) {
|
|
||||||
havenStatus = 2;
|
|
||||||
JSONArray textItems = obj.getJSONArray("actions").getJSONObject(0).getJSONObject("result").getJSONArray("items");
|
|
||||||
|
|
||||||
StringBuilder out = new StringBuilder();
|
|
||||||
|
|
||||||
for (int i = 0; i < textItems.length(); i++) {
|
|
||||||
out.append(textItems.getJSONObject(i).getString("text"));
|
|
||||||
out.append(" ");
|
|
||||||
}
|
|
||||||
String result = out.toString();
|
|
||||||
setText(result.trim());
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
|
||||||
System.err.println(result);
|
|
||||||
} else if (obj.getString("status").equals("queued")) {
|
|
||||||
havenStatus = 1;
|
|
||||||
setOverrideText("[processing...]");
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
|
||||||
} else {
|
|
||||||
text = id;
|
|
||||||
AudiobookRecorder.window.bookTreeModel.reload(Sentence.this);
|
|
||||||
havenStatus = 3;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EntityUtils.consume(resEntity);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
ex.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEthereal(boolean e) {
|
|
||||||
effectEthereal = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getEthereal() {
|
|
||||||
return effectEthereal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double mix(double a, double b) {
|
|
||||||
double z;
|
|
||||||
double fa, fb, fz;
|
|
||||||
fa = a + 32768d;
|
|
||||||
fb = b + 32768d;
|
|
||||||
|
|
||||||
if (fa < 32768d && fb < 32768d) {
|
|
||||||
fz = (fa * fb) / 32768d;
|
|
||||||
} else {
|
|
||||||
fz = (2d * (fa + fb)) - ((fa * fb) / 32768d) - 65536d;
|
|
||||||
}
|
|
||||||
|
|
||||||
z = fz - 32768d;
|
|
||||||
return z;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPeakValue() {
|
|
||||||
int[] samples = getUnprocessedAudioData();
|
|
||||||
if (samples == null) {
|
if (samples == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int ms = 0;
|
double ms = 0;
|
||||||
for (int i = 0; i < samples.length; i++) {
|
for (int i = 0; i < samples.length; i++) {
|
||||||
if (Math.abs(samples[i]) > ms) {
|
if (Math.abs(samples[i].getMono()) > ms) {
|
||||||
ms = Math.abs(samples[i]);
|
ms = Math.abs(samples[i].getMono());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ms;
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHeadroom() {
|
public int getHeadroom() {
|
||||||
int nf = getPeakValue();
|
double r = getPeakValue();
|
||||||
if (nf == 0) return 0;
|
if (r == 0) return 0;
|
||||||
double r = nf / 32767d;
|
|
||||||
double l10 = Math.log10(r);
|
double l10 = Math.log10(r);
|
||||||
double db = 20d * l10;
|
double db = 20d * l10;
|
||||||
|
|
||||||
@@ -1029,9 +675,12 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
public void setGain(double g) {
|
public void setGain(double g) {
|
||||||
if (g <= 0.0001d) g = 1.0d;
|
if (g <= 0.0001d) g = 1.0d;
|
||||||
if (g == gain) return;
|
if (g == gain) return;
|
||||||
gain = g;
|
|
||||||
|
if (gain != g) {
|
||||||
clearCache();
|
clearCache();
|
||||||
}
|
}
|
||||||
|
gain = g;
|
||||||
|
}
|
||||||
|
|
||||||
public double getGain() {
|
public double getGain() {
|
||||||
return gain;
|
return gain;
|
||||||
@@ -1039,20 +688,12 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
|
|
||||||
public void normalize() {
|
public void normalize() {
|
||||||
if (locked) return;
|
if (locked) return;
|
||||||
int max = getPeakValue();
|
double max = getPeakValue();
|
||||||
double d = 23192d / max;
|
double d = 0.708 / max;
|
||||||
if (d > 1.1d) d = 1.1d;
|
if (d > 1d) d = 1d;
|
||||||
setGain(d);
|
setGain(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getEQProfile() {
|
|
||||||
return eqProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEQProfile(int e) {
|
|
||||||
eqProfile = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
class ExternalEditor implements Runnable {
|
class ExternalEditor implements Runnable {
|
||||||
Sentence sentence;
|
Sentence sentence;
|
||||||
ExternalEditor(Sentence s) {
|
ExternalEditor(Sentence s) {
|
||||||
@@ -1219,4 +860,193 @@ public class Sentence extends DefaultMutableTreeNode implements Cacheable {
|
|||||||
AudiobookRecorder.window.updateWaveform();
|
AudiobookRecorder.window.updateWaveform();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Sample[] getDoubleDataS16LE(AudioInputStream s, AudioFormat format) throws IOException {
|
||||||
|
long len = s.getFrameLength();
|
||||||
|
int frameSize = format.getFrameSize();
|
||||||
|
int chans = format.getChannels();
|
||||||
|
int bytes = frameSize / chans;
|
||||||
|
|
||||||
|
byte[] frame = new byte[frameSize];
|
||||||
|
Sample[] samples = new Sample[(int)len];
|
||||||
|
|
||||||
|
for (long fno = 0; fno < len; fno++) {
|
||||||
|
|
||||||
|
s.read(frame);
|
||||||
|
if (chans == 2) { // Stereo
|
||||||
|
int ll = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||||
|
int lh = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
||||||
|
int rl = frame[2] >= 0 ? frame[2] : 256 + frame[2];
|
||||||
|
int rh = frame[3] >= 0 ? frame[3] : 256 + frame[3];
|
||||||
|
int left = (lh << 8) | ll;
|
||||||
|
int right = (rh << 8) | rl;
|
||||||
|
if ((left & 0x8000) == 0x8000) left |= 0xFFFF0000;
|
||||||
|
if ((right & 0x8000) == 0x8000) right |= 0xFFFF0000;
|
||||||
|
samples[(int)fno] = new Sample((double)left / 32768d, (double)right / 32768d);
|
||||||
|
} else {
|
||||||
|
int l = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||||
|
int h = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
||||||
|
int mono = (h << 8) | l;
|
||||||
|
if ((mono & 0x8000) == 0x8000) mono |= 0xFFFF0000;
|
||||||
|
samples[(int)fno] = new Sample((double)mono / 32768d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sample[] getDoubleDataS24LE(AudioInputStream s, AudioFormat format) throws IOException {
|
||||||
|
long len = s.getFrameLength();
|
||||||
|
int frameSize = format.getFrameSize();
|
||||||
|
int chans = format.getChannels();
|
||||||
|
int bytes = frameSize / chans;
|
||||||
|
|
||||||
|
byte[] frame = new byte[frameSize];
|
||||||
|
Sample[] samples = new Sample[(int)len];
|
||||||
|
|
||||||
|
for (long fno = 0; fno < len; fno++) {
|
||||||
|
|
||||||
|
s.read(frame);
|
||||||
|
int sample = 0;
|
||||||
|
if (chans == 2) { // Stereo
|
||||||
|
int ll = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||||
|
int lm = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
||||||
|
int lh = frame[2] >= 0 ? frame[2] : 256 + frame[2];
|
||||||
|
int rl = frame[3] >= 0 ? frame[3] : 256 + frame[3];
|
||||||
|
int rm = frame[4] >= 0 ? frame[4] : 256 + frame[4];
|
||||||
|
int rh = frame[5] >= 0 ? frame[5] : 256 + frame[5];
|
||||||
|
int left = (lh << 16) | (lm << 8) | ll;
|
||||||
|
int right = (rh << 16) | (rm << 8) | rl;
|
||||||
|
if ((left & 0x800000) == 0x800000) left |= 0xFF000000;
|
||||||
|
if ((right & 0x800000) == 0x800000) right |= 0xFF000000;
|
||||||
|
samples[(int)fno] = new Sample((double)left / 8388608d, (double)right / 8388608d);
|
||||||
|
} else {
|
||||||
|
int l = frame[0] >= 0 ? frame[0] : 256 + frame[0];
|
||||||
|
int m = frame[1] >= 0 ? frame[1] : 256 + frame[1];
|
||||||
|
int h = frame[2] >= 0 ? frame[2] : 256 + frame[2];
|
||||||
|
int mono = (h << 16) | (m << 8) | l;
|
||||||
|
if ((mono & 0x800000) == 0x800000) mono |= 0xFF000000;
|
||||||
|
samples[(int)fno] = new Sample((double)mono / 8388608d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadFile() {
|
||||||
|
if (audioData != null) return;
|
||||||
|
|
||||||
|
File f = getFile();
|
||||||
|
try {
|
||||||
|
AudioInputStream s = AudioSystem.getAudioInputStream(f);
|
||||||
|
AudioFormat format = getAudioFormat();
|
||||||
|
|
||||||
|
Sample[] samples = null;
|
||||||
|
|
||||||
|
switch (format.getSampleSizeInBits()) {
|
||||||
|
case 16:
|
||||||
|
samples = getDoubleDataS16LE(s, format);
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
samples = getDoubleDataS24LE(s, format);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
s.close();
|
||||||
|
sampleSize = samples.length;
|
||||||
|
audioData = samples;
|
||||||
|
CacheManager.addToCache(this);
|
||||||
|
} catch (Exception e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sample[] getProcessedAudioData() {
|
||||||
|
loadFile();
|
||||||
|
if (processedAudio != null) return processedAudio;
|
||||||
|
|
||||||
|
if (audioData == null) return null;
|
||||||
|
processedAudio = new Sample[audioData.length];
|
||||||
|
for (int i = 0; i < audioData.length; i++) {
|
||||||
|
processedAudio[i] = new Sample(audioData[i].left, audioData[i].right);
|
||||||
|
}
|
||||||
|
// Add processing in here.
|
||||||
|
|
||||||
|
|
||||||
|
String def = AudiobookRecorder.window.getDefaultEffectsChain();
|
||||||
|
Effect eff = AudiobookRecorder.window.effects.get(def);
|
||||||
|
|
||||||
|
if (eff != null) {
|
||||||
|
eff.init(getAudioFormat().getFrameRate());
|
||||||
|
eff.process(processedAudio);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (effectChain != null) {
|
||||||
|
// Don't double up the default chain
|
||||||
|
if (!effectChain.equals(def)) {
|
||||||
|
eff = AudiobookRecorder.window.effects.get(effectChain);
|
||||||
|
if (eff != null) {
|
||||||
|
eff.init(getAudioFormat().getFrameRate());
|
||||||
|
eff.process(processedAudio);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add final master gain stage
|
||||||
|
for (int i = 0; i < processedAudio.length; i++) {
|
||||||
|
processedAudio[i].left = processedAudio[i].left * gain;
|
||||||
|
processedAudio[i].right = processedAudio[i].right * gain;
|
||||||
|
}
|
||||||
|
return processedAudio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sample[] getDoubleAudioData() {
|
||||||
|
return getProcessedAudioData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sample[] getCroppedAudioData() {
|
||||||
|
Sample[] inSamples = getDoubleAudioData();
|
||||||
|
if (inSamples == null) return null;
|
||||||
|
updateCrossings();
|
||||||
|
|
||||||
|
int length = crossEndOffset - crossStartOffset;
|
||||||
|
|
||||||
|
Sample[] samples = new Sample[length];
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
samples[i] = inSamples[crossStartOffset + i];
|
||||||
|
}
|
||||||
|
return samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPCMData() {
|
||||||
|
Sample[] croppedData = getCroppedAudioData();
|
||||||
|
if (croppedData == null) return null;
|
||||||
|
int length = croppedData.length;
|
||||||
|
byte[] pcmData = new byte[length * 4];
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
double sd = croppedData[i].left * 32768d;
|
||||||
|
int si = (int)sd;
|
||||||
|
if (si > 32767) si = 32767;
|
||||||
|
if (si < -32768) si = -32768;
|
||||||
|
pcmData[i * 4] = (byte)(si & 0xFF);
|
||||||
|
pcmData[(i * 4) + 1] = (byte)((si & 0xFF00) >> 8);
|
||||||
|
sd = croppedData[i].right * 32768d;
|
||||||
|
si = (int)sd;
|
||||||
|
if (si > 32767) si = 32767;
|
||||||
|
if (si < -32768) si = -32768;
|
||||||
|
pcmData[(i * 4) + 2] = (byte)(si & 0xFF);
|
||||||
|
pcmData[(i * 4) + 3] = (byte)((si & 0xFF00) >> 8);
|
||||||
|
}
|
||||||
|
return pcmData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEffectChain(String key) {
|
||||||
|
if ((effectChain != null) && (!effectChain.equals(key))) {
|
||||||
|
clearCache();
|
||||||
|
}
|
||||||
|
effectChain = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEffectChain() {
|
||||||
|
if (effectChain == null) return "none";
|
||||||
|
return effectChain;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import javax.sound.sampled.*;
|
|||||||
|
|
||||||
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
public class Waveform extends JPanel implements MouseListener, MouseMotionListener {
|
||||||
|
|
||||||
int[] samples = null;
|
Sample[] samples = null;
|
||||||
|
|
||||||
int leftMarker = 0;
|
int leftMarker = 0;
|
||||||
int rightMarker = 0;
|
int rightMarker = 0;
|
||||||
@@ -62,12 +62,15 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
g.drawLine(x, 0, x, h);
|
g.drawLine(x, 0, x, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int h2 = h/2;
|
||||||
|
int db3 = (int) (h2 * 0.708);
|
||||||
|
|
||||||
for (int x = 0; x < w; x += 4) {
|
for (int x = 0; x < w; x += 4) {
|
||||||
g.drawLine(x, h/4, x, h/4);
|
g.drawLine(x, h2 + db3, x, h2 + db3);
|
||||||
g.drawLine(x, h/4*3, x, h/4*3);
|
g.drawLine(x, h2 - db3, x, h2 - db3);
|
||||||
}
|
}
|
||||||
|
|
||||||
int scale = 32768/(h/2);
|
double scale = (h/2);
|
||||||
|
|
||||||
if (samples != null) {
|
if (samples != null) {
|
||||||
|
|
||||||
@@ -81,15 +84,15 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
|
|
||||||
for (int n = 0; n < w; n++) {
|
for (int n = 0; n < w; n++) {
|
||||||
int hcnt = 0;
|
int hcnt = 0;
|
||||||
long have = 0;
|
double have = 0;
|
||||||
int hmax = 0;
|
double hmax = 0;
|
||||||
|
|
||||||
int lcnt = 0;
|
int lcnt = 0;
|
||||||
int lave = 0;
|
double lave = 0;
|
||||||
int lmax = 0;
|
double lmax = 0;
|
||||||
|
|
||||||
for (int o = 0; o < step; o++) {
|
for (int o = 0; o < step; o++) {
|
||||||
int sample = samples[offset + (n * step) + o];
|
double sample = samples[offset + (n * step) + o].getMono();
|
||||||
if (sample >= 0) {
|
if (sample >= 0) {
|
||||||
have += sample;
|
have += sample;
|
||||||
hcnt++;
|
hcnt++;
|
||||||
@@ -107,27 +110,27 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
|
|
||||||
boolean clip = false;
|
boolean clip = false;
|
||||||
|
|
||||||
if (lmax > 32000) { // -3dB == 23198?
|
if (lmax > 0.708) { // -3dB == 23198?
|
||||||
clip = true;
|
clip = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hmax > 32000) { // -3dB
|
if (hmax > 0.708) { // -3dB
|
||||||
clip = true;
|
clip = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
hmax /= scale;
|
hmax *= scale;
|
||||||
lmax /= scale;
|
lmax *= scale;
|
||||||
have /= scale;
|
have *= scale;
|
||||||
lave /= scale;
|
lave *= scale;
|
||||||
|
|
||||||
if (clip) {
|
if (clip) {
|
||||||
g.setColor(new Color(200, 20, 0));
|
g.setColor(new Color(200, 20, 0));
|
||||||
} else {
|
} else {
|
||||||
g.setColor(new Color(0, 20, 200));
|
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.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, 32));
|
||||||
@@ -186,7 +189,7 @@ public class Waveform extends JPanel implements MouseListener, MouseMotionListen
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setData(int[] s) {
|
public void setData(Sample[] s) {
|
||||||
samples = s;
|
samples = s;
|
||||||
playMarker = 0;
|
playMarker = 0;
|
||||||
repaint();
|
repaint();
|
||||||
|
|||||||
Reference in New Issue
Block a user