1
1
/*
2
+ * *****************************************************************************
3
+ * Copyright (C) 2014-2023 Dennis Sheirer
2
4
*
3
- * * ******************************************************************************
4
- * * Copyright (C) 2014-2019 Dennis Sheirer
5
- * *
6
- * * This program is free software: you can redistribute it and/or modify
7
- * * it under the terms of the GNU General Public License as published by
8
- * * the Free Software Foundation, either version 3 of the License, or
9
- * * (at your option) any later version.
10
- * *
11
- * * This program is distributed in the hope that it will be useful,
12
- * * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * * GNU General Public License for more details.
15
- * *
16
- * * You should have received a copy of the GNU General Public License
17
- * * along with this program. If not, see <http://www.gnu.org/licenses/>
18
- * * *****************************************************************************
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
19
9
*
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
20
14
*
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
17
+ * ****************************************************************************
21
18
*/
22
19
23
20
package io .github .dsheirer .audio .codec .mbe ;
32
29
import io .github .dsheirer .preference .PreferenceType ;
33
30
import io .github .dsheirer .preference .UserPreferences ;
34
31
import io .github .dsheirer .sample .Listener ;
35
- import jmbe .iface .IAudioCodec ;
36
- import jmbe .iface .IAudioCodecLibrary ;
37
- import org .slf4j .Logger ;
38
- import org .slf4j .LoggerFactory ;
39
-
40
32
import java .lang .reflect .InvocationTargetException ;
41
33
import java .net .MalformedURLException ;
42
34
import java .net .URL ;
43
35
import java .net .URLClassLoader ;
44
36
import java .nio .file .Path ;
45
37
import java .util .ArrayList ;
46
38
import java .util .List ;
39
+ import jmbe .iface .IAudioCodec ;
40
+ import jmbe .iface .IAudioCodecLibrary ;
41
+ import org .slf4j .Logger ;
42
+ import org .slf4j .LoggerFactory ;
47
43
48
44
public abstract class JmbeAudioModule extends AbstractAudioModule implements Listener <IMessage >, IMessageListener ,
49
45
ISquelchStateListener
50
46
{
51
47
private static final Logger mLog = LoggerFactory .getLogger (JmbeAudioModule .class );
52
48
private static final String JMBE_AUDIO_LIBRARY = "JMBE" ;
53
- private static List <String > mLibraryLoadStatusLogged = new ArrayList <>();
49
+ private static final List <String > mLibraryLoadStatusLogged = new ArrayList <>();
54
50
private IAudioCodec mAudioCodec ;
55
- private UserPreferences mUserPreferences ;
51
+ private final UserPreferences mUserPreferences ;
52
+ private static Class sLoadedJmbeAudioConverterClass ;
56
53
57
54
public JmbeAudioModule (UserPreferences userPreferences , AliasList aliasList , int timeslot )
58
55
{
@@ -110,38 +107,67 @@ public void preferenceUpdated(PreferenceType preferenceType)
110
107
protected abstract String getCodecName ();
111
108
112
109
/**
113
- * Loads audio frame processing chain. Constructs an imbe targetdataline
114
- * to receive the raw imbe frames. Adds an IMBE to 8k PCM format conversion
115
- * stream wrapper. Finally, adds an upsampling (8k to 48k) stream wrapper.
110
+ * Loads JMBE audio converter library class and then instantiates new converter instances from the loaded class.
116
111
*/
117
112
protected void loadConverter ()
118
113
{
119
114
IAudioCodec audioConverter = null ;
120
115
121
- Path path = mUserPreferences .getJmbeLibraryPreference ().getPathJmbeLibrary ();
122
-
123
- if (path != null )
116
+ if (sLoadedJmbeAudioConverterClass == null )
124
117
{
125
- try
118
+ Path path = mUserPreferences .getJmbeLibraryPreference ().getPathJmbeLibrary ();
119
+
120
+ if (path != null )
126
121
{
127
122
if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY ))
128
123
{
129
- mLog .info ("Loading JMBE library from [" + path . toString () + "]" );
124
+ mLog .info ("Loading JMBE library from [" + path + "]" );
130
125
}
131
126
132
- URLClassLoader childClassLoader = new URLClassLoader (new URL []{path .toUri ().toURL ()},
133
- this .getClass ().getClassLoader ());
127
+ try
128
+ {
129
+ URLClassLoader childClassLoader = new URLClassLoader (new URL []{path .toUri ().toURL ()},
130
+ this .getClass ().getClassLoader ());
134
131
135
- Class classToLoad = Class .forName ("jmbe.JMBEAudioLibrary" , true , childClassLoader );
132
+ sLoadedJmbeAudioConverterClass = Class .forName ("jmbe.JMBEAudioLibrary" , true , childClassLoader );
133
+ }
134
+ catch (IllegalArgumentException iae )
135
+ {
136
+ if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY + getCodecName ()))
137
+ {
138
+ mLog .error ("Couldn't load JMBE audio conversion library - " + iae .getMessage ());
139
+ mLibraryLoadStatusLogged .add (JMBE_AUDIO_LIBRARY + getCodecName ());
140
+ }
141
+ }
142
+ catch (MalformedURLException mue )
143
+ {
144
+ if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY ))
145
+ {
146
+ mLog .error ("Couldn't load JMBE audio conversion library from path [" + path + "]" );
147
+ mLibraryLoadStatusLogged .add (JMBE_AUDIO_LIBRARY );
148
+ }
149
+ }
150
+ catch (ClassNotFoundException e1 )
151
+ {
152
+ if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY ))
153
+ {
154
+ mLog .error ("Couldn't load JMBE audio conversion library - class not found" );
155
+ mLibraryLoadStatusLogged .add (JMBE_AUDIO_LIBRARY );
156
+ }
157
+ }
158
+ }
159
+ }
136
160
137
- Object instance = classToLoad .getDeclaredConstructor ().newInstance ();
161
+ if (sLoadedJmbeAudioConverterClass != null )
162
+ {
163
+ try
164
+ {
165
+ Object instance = sLoadedJmbeAudioConverterClass .getDeclaredConstructor ().newInstance ();
138
166
139
- if (instance instanceof IAudioCodecLibrary )
167
+ if (instance instanceof IAudioCodecLibrary library )
140
168
{
141
- IAudioCodecLibrary library = (IAudioCodecLibrary )instance ;
142
-
143
169
if ((library .getMajorVersion () == 1 && library .getMinorVersion () >= 0 &&
144
- library .getBuildVersion () >= 0 ) || library .getMajorVersion () >= 1 )
170
+ library .getBuildVersion () >= 0 ) || library .getMajorVersion () >= 1 )
145
171
{
146
172
audioConverter = library .getAudioConverter (getCodecName ());
147
173
@@ -169,38 +195,6 @@ protected void loadConverter()
169
195
}
170
196
}
171
197
}
172
- catch (IllegalArgumentException iae )
173
- {
174
- if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY + getCodecName ()))
175
- {
176
- mLog .error ("Couldn't load JMBE audio conversion library - " + iae .getMessage ());
177
- mLibraryLoadStatusLogged .add (JMBE_AUDIO_LIBRARY + getCodecName ());
178
- }
179
- }
180
- catch (NoSuchMethodException nsme )
181
- {
182
- if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY ))
183
- {
184
- mLog .error ("Couldn't load JMBE audio conversion library - no such method exception" );
185
- mLibraryLoadStatusLogged .add (JMBE_AUDIO_LIBRARY );
186
- }
187
- }
188
- catch (MalformedURLException mue )
189
- {
190
- if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY ))
191
- {
192
- mLog .error ("Couldn't load JMBE audio conversion library from path [" + path + "]" );
193
- mLibraryLoadStatusLogged .add (JMBE_AUDIO_LIBRARY );
194
- }
195
- }
196
- catch (ClassNotFoundException e1 )
197
- {
198
- if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY ))
199
- {
200
- mLog .error ("Couldn't load JMBE audio conversion library - class not found" );
201
- mLibraryLoadStatusLogged .add (JMBE_AUDIO_LIBRARY );
202
- }
203
- }
204
198
catch (InvocationTargetException ite )
205
199
{
206
200
if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY ))
@@ -225,6 +219,14 @@ protected void loadConverter()
225
219
mLibraryLoadStatusLogged .add (JMBE_AUDIO_LIBRARY );
226
220
}
227
221
}
222
+ catch (NoSuchMethodException nsme )
223
+ {
224
+ if (!mLibraryLoadStatusLogged .contains (JMBE_AUDIO_LIBRARY ))
225
+ {
226
+ mLog .error ("Couldn't load JMBE audio conversion library - no such method exception" );
227
+ mLibraryLoadStatusLogged .add (JMBE_AUDIO_LIBRARY );
228
+ }
229
+ }
228
230
}
229
231
else
230
232
{
@@ -235,13 +237,6 @@ protected void loadConverter()
235
237
}
236
238
}
237
239
238
- if (audioConverter != null )
239
- {
240
- mAudioCodec = audioConverter ;
241
- }
242
- else
243
- {
244
- mAudioCodec = null ;
245
- }
240
+ mAudioCodec = audioConverter ;
246
241
}
247
242
}
0 commit comments