Adds de-emphasis filter to P25 decoded IMBE audio output.

This commit is contained in:
denny
2015-12-11 13:34:20 -05:00
parent d9fe979ccf
commit 6763a4bdd6
6 changed files with 88 additions and 13 deletions

View File

@@ -95,7 +95,8 @@ public class StereoAudioOutput extends AudioOutput
catch ( LineUnavailableException e ) catch ( LineUnavailableException e )
{ {
mLog.error( "Couldn't obtain source data line for 48kHz PCM stereo " mLog.error( "Couldn't obtain source data line for 48kHz PCM stereo "
+ "audio output" ); + "audio output - mixer [" + mixer.getMixerInfo().getName() +
"] channel [" + mMixerChannel.name() + "]" );
} }
} }

View File

@@ -40,6 +40,11 @@ public class FloatCircularBuffer
Arrays.fill( mBuffer, (float)0.0 ); Arrays.fill( mBuffer, (float)0.0 );
} }
public int getSize()
{
return mBuffer.length;
}
public float[] getBuffer() public float[] getBuffer()
{ {
return mBuffer; return mBuffer;

View File

@@ -0,0 +1,60 @@
package dsp.filter.iir;
import sample.real.RealBuffer;
public class DeemphasisFilter
{
private static final float MAX_SAMPLE_VALUE = 0.95f;
private float mAlpha;
private float mGain;
private float mPrevious = 0.0f;
public DeemphasisFilter( float sampleRate, float cutoff, float gain )
{
mAlpha = (float)Math.exp( -2.0 * Math.PI * cutoff * ( 1.0 / sampleRate ) );
mGain = gain;
}
public float filter( float sample )
{
mPrevious = sample + ( mAlpha * mPrevious );
return declip( mPrevious * mGain );
}
private float declip( float value )
{
if( value > MAX_SAMPLE_VALUE )
{
return MAX_SAMPLE_VALUE;
}
else if( value < -MAX_SAMPLE_VALUE )
{
return -MAX_SAMPLE_VALUE;
}
else return value;
}
public float[] filter( float[] samples )
{
for( int x = 0; x < samples.length; x++ )
{
samples[ x ] = filter( samples[ x ] );
}
return samples;
}
public RealBuffer filter( RealBuffer buffer )
{
float[] samples = buffer.getSamples();
for( int x = 0; x < samples.length; x++ )
{
samples[ x ] = filter( samples[ x ] );
}
return buffer;
}
}

View File

@@ -149,7 +149,7 @@ public class P25DecoderPanel extends DecoderPanel
{ {
mFromAlias.setText( from.getName() ); mFromAlias.setText( from.getName() );
String icon = from.getIconName(); final String icon = from.getIconName();
if( icon != null ) if( icon != null )
{ {
@@ -180,7 +180,7 @@ public class P25DecoderPanel extends DecoderPanel
{ {
mToAlias.setText( to.getName() ); mToAlias.setText( to.getName() );
String icon = to.getIconName(); final String icon = to.getIconName();
if( icon != null ) if( icon != null )
{ {

View File

@@ -6,8 +6,6 @@ import message.IMessageListener;
import message.Message; import message.Message;
import module.Module; import module.Module;
import module.decode.p25.message.ldu.LDUMessage; import module.decode.p25.message.ldu.LDUMessage;
import module.decode.p25.message.tdu.TDUMessage;
import module.decode.p25.message.tdu.lc.TDULinkControlMessage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -23,6 +21,8 @@ import audio.squelch.ISquelchStateListener;
import audio.squelch.SquelchState; import audio.squelch.SquelchState;
import controller.channel.ChannelEvent; import controller.channel.ChannelEvent;
import controller.channel.IChannelEventListener; import controller.channel.IChannelEventListener;
import dsp.audio.P25AGC;
import dsp.filter.iir.DeemphasisFilter;
public class P25AudioModule extends Module implements Listener<Message>, public class P25AudioModule extends Module implements Listener<Message>,
IAudioPacketProvider, IMessageListener, IChannelEventListener, IAudioPacketProvider, IMessageListener, IChannelEventListener,
@@ -43,6 +43,8 @@ public class P25AudioModule extends Module implements Listener<Message>,
private AudioMetadata mAudioMetadata; private AudioMetadata mAudioMetadata;
private ChannelEventListener mChannelEventListener = new ChannelEventListener(); private ChannelEventListener mChannelEventListener = new ChannelEventListener();
private SquelchStateListener mSquelchStateListener = new SquelchStateListener(); private SquelchStateListener mSquelchStateListener = new SquelchStateListener();
// private P25AGC mAGC = new P25AGC( 2.0, 10.0 );
private DeemphasisFilter mDeemphasis = new DeemphasisFilter( 48000.0f, 300.0f, 0.6f );
public P25AudioModule( boolean record ) public P25AudioModule( boolean record )
{ {
@@ -89,9 +91,10 @@ public class P25AudioModule extends Module implements Listener<Message>,
} }
/** /**
* Primary inject point for p25 imbe audio frame messages. Each LDU audio * Primary processing method for p25 imbe audio frame messages. Each LDU
* message contains 9 imbe voice frames. If the audio is not encrypted, * audio message contains 9 imbe voice frames. Each frame is converted to
* we insert each audio frame asynchronously into the audio converter. * audio when the JMBE library is loaded, processed by auto-gain, and
* broadcast to the audio packet listener.
*/ */
public void receive( Message message ) public void receive( Message message )
{ {
@@ -101,15 +104,15 @@ public class P25AudioModule extends Module implements Listener<Message>,
{ {
LDUMessage ldu = (LDUMessage)message; LDUMessage ldu = (LDUMessage)message;
/* If we detect a valid LDU message with the encryption flag /* Only process unencrypted audio frames */
* set to true, we toggle the encrypted audio state until we
* receive the first TDU or TDULC message, then reset it. */
if( !( ldu.isValid() && ldu.isEncrypted() ) ) if( !( ldu.isValid() && ldu.isEncrypted() ) )
{ {
for( byte[] frame: ((LDUMessage)message).getIMBEFrames() ) for( byte[] frame: ldu.getIMBEFrames() )
{ {
float[] audio = mAudioConverter.decode( frame ); float[] audio = mAudioConverter.decode( frame );
audio = mDeemphasis.filter( audio );
mAudioPacketListener.receive( mAudioPacketListener.receive(
new AudioPacket( audio, mAudioMetadata.copyOf() ) ); new AudioPacket( audio, mAudioMetadata.copyOf() ) );
} }

View File

@@ -36,7 +36,8 @@ import source.IControllableFileSource;
import source.IFrameLocationListener; import source.IFrameLocationListener;
import source.RealSource; import source.RealSource;
public class RealWaveSource extends RealSource implements IControllableFileSource public class RealWaveSource extends RealSource
implements IControllableFileSource, AutoCloseable
{ {
private final static Logger mLog = private final static Logger mLog =
LoggerFactory.getLogger( RealWaveSource.class ); LoggerFactory.getLogger( RealWaveSource.class );
@@ -168,6 +169,11 @@ public class RealWaveSource extends RealSource implements IControllableFileSourc
{ {
if( samplesRead < buffer.length ) if( samplesRead < buffer.length )
{ {
if( samplesRead == -1 )
{
throw new IOException( "End of recording" );
}
buffer = Arrays.copyOf( buffer, samplesRead ); buffer = Arrays.copyOf( buffer, samplesRead );
} }