Skip to content

Commit ee5ba68

Browse files
authored
Merge pull request #135 from Audio4Linux/libjamesdsp_upgrade
2 parents c620ea3 + 87fde17 commit ee5ba68

File tree

93 files changed

+15317
-13257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+15317
-13257
lines changed

libjamesdsp/JdspImpResToolbox.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ void circshift(float *x, int n, int k)
258258
k < 0 ? shift(x, -k, n) : shift(x, n - k, n);
259259
}
260260
#define NUMPTS 15
261-
ierper pch1, pch2;
261+
#define NUMPTS_DRS (7)
262+
ierper pch1, pch2, pch3;
262263
__attribute__((constructor)) static void initialize(void)
263264
{
264265
if (decompressedCoefficients)
@@ -267,14 +268,16 @@ __attribute__((constructor)) static void initialize(void)
267268
decompressResamplerMQ(compressedCoeffMQ, decompressedCoefficients);
268269
initIerper(&pch1, NUMPTS + 2);
269270
initIerper(&pch2, NUMPTS + 2);
271+
initIerper(&pch3, NUMPTS_DRS + 2);
270272
}
271273
__attribute__((destructor)) static void destruction(void)
272274
{
273275
free(decompressedCoefficients);
274276
decompressedCoefficients = 0;
275277
freeIerper(&pch1);
276278
freeIerper(&pch2);
277-
}
279+
freeIerper(&pch3);
280+
}
278281
static void JamesDSPOfflineResampling(float const *in, float *out, size_t lenIn, size_t lenOut, int channels, double src_ratio, int resampleQuality)
279282
{
280283
if (lenOut == lenIn && lenIn == 1)
@@ -534,3 +537,49 @@ int ComputeEqResponse(const double* jfreq, double* jgain, int interpolationMode,
534537
return 0;
535538
}
536539

540+
int ComputeCompResponse(int n, const double* jfreq, const double* jgain, int queryPts, const double* dispFreq, float* response)
541+
{
542+
double freqComp[NUMPTS_DRS + 2];
543+
double gainComp[NUMPTS_DRS + 2];
544+
545+
memcpy(freqComp + 1, jfreq, NUMPTS_DRS * sizeof(double));
546+
memcpy(gainComp + 1, jgain, NUMPTS_DRS * sizeof(double));
547+
548+
freqComp[0] = 0.0;
549+
gainComp[0] = gainComp[1];
550+
freqComp[NUMPTS_DRS + 1] = 24000.0;
551+
gainComp[NUMPTS_DRS + 1] = gainComp[NUMPTS_DRS];
552+
makima(&pch3, freqComp, gainComp, NUMPTS_DRS + 2, 1, 1);
553+
ierper *lerpPtr = &pch3;
554+
for (int i = 0; i < queryPts; i++)
555+
response[i] = (float)getValueAt(&lerpPtr->cb, dispFreq[i]);
556+
return 0;
557+
}
558+
559+
void ComputeIIREqualizerCplx(int srate, int order, const double* freqs, double* gains, int nPts, const double* dispFreq, double* cplxRe, double* cplxIm)
560+
{
561+
for (int i = 0; i < nPts; i++)
562+
{
563+
cplxRe[i] = 1;
564+
cplxIm[i] = 0;
565+
}
566+
567+
for (int i = 0; i < NUMPTS - 1; i++)
568+
{
569+
double dB = gains[i + 1] - gains[i];
570+
double designFreq;
571+
if (i)
572+
designFreq = (freqs[i + 1] + freqs[i]) * 0.5;
573+
else
574+
designFreq = freqs[i];
575+
double overallGain = i == 0 ? gains[i] : 0.0;
576+
HSHOResponse(48000, designFreq, order, dB, overallGain, nPts, dispFreq, cplxRe, cplxIm);
577+
}
578+
}
579+
580+
void ComputeIIREqualizerResponse(int nPts, const double* cplxRe, const double* cplxIm, float* response)
581+
{
582+
for(int i = 0; i < nPts; i++) {
583+
response[i] = 20.0f * log10f(hypot(cplxRe[i], cplxIm[i]));
584+
}
585+
}

libjamesdsp/JdspImpResToolbox.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@
33

44
extern float* ReadImpulseResponseToFloat(const char* mIRFileName, int targetSampleRate, int* jImpInfo, int convMode, int* javaAdvSetPtr);
55
extern int ComputeEqResponse(const double* jfreq, double* jgain, int interpolationMode, int queryPts, double* dispFreq, float* response);
6-
6+
extern int ComputeCompResponse(int n, const double* jfreq, const double* jgain, int queryPts, const double* dispFreq, float* response);
7+
extern void ComputeIIREqualizerCplx(int srate, int order, const double* freq, double* gains, int nPts, const double* dispFreq, double* cplxRe, double* cplxIm);
8+
extern void ComputeIIREqualizerResponse(int nPts, const double* cplxRe, const double* cplxIm, float* response);
79
#endif // JDSPIMPRESTOOLBOX_H
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "PrintfStdOutExtension.h"
2+
#include <stdarg.h>
3+
4+
static stdOutHandler _printfStdOutHandlerPtr = 0;
5+
static void* _printfStdOutHandlerUserPtr = 0;
6+
7+
int redirected_printf(const char * format, ...) {
8+
// Make formatted string.
9+
char* outstr = 0;
10+
va_list ap;
11+
va_start(ap, format);
12+
int result = vasprintf(&outstr, format, ap);
13+
va_end(ap);
14+
if(result < 0) // Error occurred and `outstr` undefined if result < 0.
15+
return result;
16+
17+
if(_printfStdOutHandlerPtr != 0)
18+
{
19+
_printfStdOutHandlerPtr(outstr, _printfStdOutHandlerUserPtr);
20+
}
21+
22+
free(outstr);
23+
return result;
24+
}
25+
26+
void __android_log_print(int severity, const char* tag, const char* msg) {
27+
char *s;
28+
if (asprintf(&s, "%s: %s", tag, msg) > 0 && s != 0)
29+
{
30+
if(_printfStdOutHandlerPtr != 0)
31+
{
32+
_printfStdOutHandlerPtr(s, _printfStdOutHandlerUserPtr);
33+
}
34+
free(s);
35+
}
36+
}
37+
38+
void setPrintfStdOutHandler(stdOutHandler funcPtr, void* userData)
39+
{
40+
_printfStdOutHandlerPtr = funcPtr;
41+
_printfStdOutHandlerUserPtr = userData;
42+
}
43+
44+
int isPrintfStdOutHandlerSet()
45+
{
46+
return _printfStdOutHandlerPtr != 0;
47+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef EELSTDOUTEXTENSION_H
2+
#define EELSTDOUTEXTENSION_H
3+
4+
typedef void (*stdOutHandler)(const char*, void*);
5+
6+
7+
extern void setPrintfStdOutHandler(stdOutHandler funcPtr, void* userData);
8+
extern int isPrintfStdOutHandlerSet();
9+
10+
#endif // EELSTDOUTEXTENSION_H

libjamesdsp/libjamesdsp.pro

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ QMAKE_CFLAGS += -std=gnu11 -O2
1010

1111
CONFIG += warn_off # Disable warnings for library
1212

13+
# Enable liveprog logging redirection
1314
DEFINES += CUSTOM_CMD
1415

16+
# Redirect printf & android logging to our custom handlers
17+
DEFINES += printf=redirected_printf ANDROID_LOG_INFO=0 DEBUG
18+
1519
BASEPATH = $$PWD/subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/
1620

1721
INCLUDEPATH += $$BASEPATH \
@@ -50,6 +54,7 @@ HEADERS += \
5054
$$BASEPATH/generalDSP/spectralInterpolatorFloat.h \
5155
$$BASEPATH/jdsp_header.h \
5256
EELStdOutExtension.h \
57+
PrintfStdOutExtension.h \
5358
JdspImpResToolbox.h
5459

5560
SOURCES += \
@@ -84,7 +89,6 @@ SOURCES += \
8489
$$BASEPATH/Effects/eel2/numericSys/solvopt.c \
8590
$$BASEPATH/Effects/eel2/s_str.c \
8691
$$BASEPATH/Effects/eel2/y.tab.c \
87-
$$BASEPATH/Effects/firEqualizer.c \
8892
$$BASEPATH/Effects/liveprogWrapper.c \
8993
$$BASEPATH/Effects/reverb.c \
9094
$$BASEPATH/Effects/stereoEnhancement.c \
@@ -99,7 +103,9 @@ SOURCES += \
99103
$$BASEPATH/generalDSP/spectralInterpolatorFloat.c \
100104
$$BASEPATH/jdspController.c \
101105
EELStdOutExtension.c \
102-
JdspImpResToolbox.c
106+
PrintfStdOutExtension.c \
107+
JdspImpResToolbox.c \
108+
subtree/Main/libjamesdsp/jni/jamesdsp/jdsp/Effects/multimodalEQ.c
103109

104110
unix {
105111
isEmpty(LIBDIR) {

libjamesdsp/subtree/Main/DSPManager/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<application
1212
android:icon="@drawable/icon"
1313
android:label="@string/app_name"
14-
android:requestLegacyExternalStorage="true"
1514
android:persistent="true"
1615
android:allowBackup="true">
1716
<activity

libjamesdsp/subtree/Main/DSPManager/jni/main/JdspImpResToolbox.c

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ void circshift(float *x, int n, int k)
398398
k < 0 ? shift(x, -k, n) : shift(x, n - k, n);
399399
}
400400
#define NUMPTS 15
401-
ierper pch1, pch2;
401+
#define NUMPTS_DRS (7)
402+
ierper pch1, pch2, pch3;
402403
__attribute__((constructor)) static void initialize(void)
403404
{
404405
if (decompressedCoefficients)
@@ -407,13 +408,15 @@ __attribute__((constructor)) static void initialize(void)
407408
decompressResamplerMQ(compressedCoeffMQ, decompressedCoefficients);
408409
initIerper(&pch1, NUMPTS + 2);
409410
initIerper(&pch2, NUMPTS + 2);
411+
initIerper(&pch3, NUMPTS_DRS + 2);
410412
}
411413
__attribute__((destructor)) static void destruction(void)
412414
{
413415
free(decompressedCoefficients);
414416
decompressedCoefficients = 0;
415417
freeIerper(&pch1);
416418
freeIerper(&pch2);
419+
freeIerper(&pch3);
417420
}
418421
void JamesDSPOfflineResampling(float const *in, float *out, size_t lenIn, size_t lenOut, int channels, double src_ratio, int resampleQuality)
419422
{
@@ -680,9 +683,32 @@ JNIEXPORT jint JNICALL Java_james_dsp_activity_JdspImpResToolbox_ComputeEqRespon
680683
lerpPtr = &pch2;
681684
}
682685
for (int i = 0; i < queryPts; i++)
683-
{
684686
javaResponsePtr[i] = (float)getValueAt(&lerpPtr->cb, javadispFreqPtr[i]);
685-
}
687+
(*env)->ReleaseDoubleArrayElements(env, dispFreq, javadispFreqPtr, 0);
688+
(*env)->SetFloatArrayRegion(env, response, 0, queryPts, javaResponsePtr);
689+
return 0;
690+
}
691+
double freqComp[NUMPTS_DRS + 2];
692+
double gainComp[NUMPTS_DRS + 2];
693+
JNIEXPORT jint JNICALL Java_james_dsp_activity_JdspImpResToolbox_ComputeCompResponse
694+
(JNIEnv *env, jobject obj, jint n, jdoubleArray jfreq, jdoubleArray jgain, jint queryPts, jdoubleArray dispFreq, jfloatArray response)
695+
{
696+
jdouble *javaFreqPtr = (jdouble*) (*env)->GetDoubleArrayElements(env, jfreq, 0);
697+
jdouble *javaGainPtr = (jdouble*) (*env)->GetDoubleArrayElements(env, jgain, 0);
698+
jdouble *javadispFreqPtr = (jdouble*) (*env)->GetDoubleArrayElements(env, dispFreq, 0);
699+
jfloat *javaResponsePtr = (jfloat*) (*env)->GetFloatArrayElements(env, response, 0);
700+
memcpy(freqComp + 1, javaFreqPtr, NUMPTS_DRS * sizeof(double));
701+
memcpy(gainComp + 1, javaGainPtr, NUMPTS_DRS * sizeof(double));
702+
(*env)->ReleaseDoubleArrayElements(env, jfreq, javaFreqPtr, 0);
703+
(*env)->ReleaseDoubleArrayElements(env, jgain, javaGainPtr, 0);
704+
freqComp[0] = 0.0;
705+
gainComp[0] = gainComp[1];
706+
freqComp[NUMPTS_DRS + 1] = 24000.0;
707+
gainComp[NUMPTS_DRS + 1] = gainComp[NUMPTS_DRS];
708+
makima(&pch3, freqComp, gainComp, NUMPTS_DRS + 2, 1, 1);
709+
ierper *lerpPtr = &pch3;
710+
for (int i = 0; i < queryPts; i++)
711+
javaResponsePtr[i] = (float)getValueAt(&lerpPtr->cb, javadispFreqPtr[i]);
686712
(*env)->ReleaseDoubleArrayElements(env, dispFreq, javadispFreqPtr, 0);
687713
(*env)->SetFloatArrayRegion(env, response, 0, queryPts, javaResponsePtr);
688714
return 0;

libjamesdsp/subtree/Main/DSPManager/project.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
1212

1313
# Project target.
14-
target=android-29
14+
target=android-28
1515
proguard.config=proguard.txt
16-
android.library.reference.1=../../appcompatSupport
16+
android.library.reference.1=../../../appcompatSupport

libjamesdsp/subtree/Main/DSPManager/res/layout/equalizer.xml renamed to libjamesdsp/subtree/Main/DSPManager/res/layout/compander.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
android:layout_gravity="center"
66
android:layout_width="fill_parent">
77

8-
<james.dsp.preference.EqualizerSurface
9-
android:id="@+id/FrequencyResponse"
8+
<james.dsp.preference.CompanderSurface
9+
android:id="@+id/DynamicResponse"
1010
android:layout_height="fill_parent"
1111
android:layout_width="fill_parent" />
1212
</LinearLayout>

libjamesdsp/subtree/Main/DSPManager/res/layout/equalizer_popup.xml renamed to libjamesdsp/subtree/Main/DSPManager/res/layout/compander_popup.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
android:layout_width="fill_parent"
55
android:layout_height="300dp">
66

7-
<james.dsp.preference.EqualizerSurface
8-
android:id="@+id/FrequencyResponse"
7+
<james.dsp.preference.CompanderSurface
8+
android:id="@+id/DynamicResponse"
99
android:layout_width="fill_parent"
1010
android:layout_height="fill_parent" />
1111
</LinearLayout>

0 commit comments

Comments
 (0)