Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-daemon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-daemon
Commits
97bf1a9b
Commit
97bf1a9b
authored
14 years ago
by
Alexandre Savard
Browse files
Options
Downloads
Patches
Plain Diff
[
#959
] Use audio processing class to encapsulate noise cancellation engine
parent
d423beee
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
sflphone-common/src/audio/audiortp/AudioRtpSession.h
+35
-36
35 additions, 36 deletions
sflphone-common/src/audio/audiortp/AudioRtpSession.h
with
35 additions
and
36 deletions
sflphone-common/src/audio/audiortp/AudioRtpSession.h
+
35
−
36
View file @
97bf1a9b
...
@@ -45,6 +45,9 @@
...
@@ -45,6 +45,9 @@
#include
"audio/audiolayer.h"
#include
"audio/audiolayer.h"
#include
"audio/codecs/audiocodec.h"
#include
"audio/codecs/audiocodec.h"
#include
"audio/samplerateconverter.h"
#include
"audio/samplerateconverter.h"
#include
"audio/audioprocessing.h"
#include
"audio/noisesuppress.h"
#include
"managerimpl.h"
#include
"managerimpl.h"
#include
<ccrtp/rtp.h>
#include
<ccrtp/rtp.h>
...
@@ -194,8 +197,10 @@ class AudioRtpSession : public ost::Thread, public ost::TimerPort
...
@@ -194,8 +197,10 @@ class AudioRtpSession : public ost::Thread, public ost::TimerPort
// this destination and update a new one
// this destination and update a new one
unsigned
short
_remote_port
;
unsigned
short
_remote_port
;
// Pointer to the session's codec
AudioCodec
*
_audiocodec
;
AudioCodec
*
_audiocodec
;
// Pointer to audio layer
AudioLayer
*
_audiolayer
;
AudioLayer
*
_audiolayer
;
/** Mic-data related buffers */
/** Mic-data related buffers */
...
@@ -286,11 +291,6 @@ class AudioRtpSession : public ost::Thread, public ost::TimerPort
...
@@ -286,11 +291,6 @@ class AudioRtpSession : public ost::Thread, public ost::TimerPort
*/
*/
int
_currentTime
;
int
_currentTime
;
/**
* Preprocess internal data
*/
SpeexPreprocessState
*
_noiseState
;
/**
/**
* State of mic fade in
* State of mic fade in
*/
*/
...
@@ -311,6 +311,15 @@ class AudioRtpSession : public ost::Thread, public ost::TimerPort
...
@@ -311,6 +311,15 @@ class AudioRtpSession : public ost::Thread, public ost::TimerPort
*/
*/
SFLDataFormat
_spkrAmplFactor
;
SFLDataFormat
_spkrAmplFactor
;
/**
* Audio process containing noise reduction engine
*/
AudioProcessing
*
_audioProcess
;
/**
* Noise reduction engine
*/
NoiseSuppress
*
_noiseSuppress
;
protected
:
protected
:
...
@@ -340,11 +349,12 @@ AudioRtpSession<D>::AudioRtpSession (ManagerImpl * manager, SIPCall * sipcall) :
...
@@ -340,11 +349,12 @@ AudioRtpSession<D>::AudioRtpSession (ManagerImpl * manager, SIPCall * sipcall) :
_timestampIncrement
(
0
),
_timestampIncrement
(
0
),
_timestampCount
(
0
),
_timestampCount
(
0
),
_countNotificationTime
(
0
),
_countNotificationTime
(
0
),
_noiseState
(
NULL
),
_micFadeInComplete
(
false
),
_micFadeInComplete
(
false
),
_spkrFadeInComplete
(
false
),
_spkrFadeInComplete
(
false
),
_micAmplFactor
(
32000
),
_micAmplFactor
(
32000
),
_spkrAmplFactor
(
32000
),
_spkrAmplFactor
(
32000
),
_audioProcess
(
NULL
),
_noiseSuppress
(
NULL
),
_ca
(
sipcall
)
_ca
(
sipcall
)
{
{
setCancel
(
cancelDefault
);
setCancel
(
cancelDefault
);
...
@@ -416,10 +426,15 @@ AudioRtpSession<D>::~AudioRtpSession()
...
@@ -416,10 +426,15 @@ AudioRtpSession<D>::~AudioRtpSession()
_audiocodec
=
NULL
;
_audiocodec
=
NULL
;
}
}
if
(
_noiseState
)
{
if
(
_audioProcess
)
{
speex_preprocess_state_destroy
(
_noiseState
);
delete
_audioProcess
;
_audioProcess
=
NULL
;
}
}
if
(
_noiseSuppress
)
{
delete
_noiseSuppress
;
_noiseSuppress
=
NULL
;
}
}
}
template
<
typename
D
>
template
<
typename
D
>
...
@@ -428,7 +443,7 @@ void AudioRtpSession<D>::initBuffers()
...
@@ -428,7 +443,7 @@ void AudioRtpSession<D>::initBuffers()
// Set sampling rate, main buffer choose the highest one
// Set sampling rate, main buffer choose the highest one
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
setInternalSamplingRate
(
_codecSampleRate
);
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
setInternalSamplingRate
(
_codecSampleRate
);
// may be different than one already set
ted
// may be different than one already set
_converterSamplingRate
=
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
getInternalSamplingRate
();
_converterSamplingRate
=
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
getInternalSamplingRate
();
// initialize SampleRate converter using AudioLayer's sampling rate
// initialize SampleRate converter using AudioLayer's sampling rate
...
@@ -497,28 +512,6 @@ void AudioRtpSession<D>::setSessionMedia (AudioCodec* audiocodec)
...
@@ -497,28 +512,6 @@ void AudioRtpSession<D>::setSessionMedia (AudioCodec* audiocodec)
static_cast
<
D
*>
(
this
)
->
setPayloadFormat
(
ost
::
StaticPayloadFormat
(
(
ost
::
StaticPayloadType
)
_audiocodec
->
getPayload
()));
static_cast
<
D
*>
(
this
)
->
setPayloadFormat
(
ost
::
StaticPayloadFormat
(
(
ost
::
StaticPayloadType
)
_audiocodec
->
getPayload
()));
}
}
if
(
_noiseState
)
{
speex_preprocess_state_destroy
(
_noiseState
);
_noiseState
=
NULL
;
}
_noiseState
=
speex_preprocess_state_init
(
_codecSampleRate
,
_codecFrameSize
);
int
i
=
1
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_DENOISE
,
&
i
);
i
=-
20
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_NOISE_SUPPRESS
,
&
i
);
i
=
0
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_AGC
,
&
i
);
i
=
8000
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_AGC_TARGET
,
&
i
);
i
=
16000
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_AGC_LEVEL
,
&
i
);
i
=
0
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_DEREVERB
,
&
i
);
float
f
=
0.0
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_DEREVERB_DECAY
,
&
f
);
f
=
0.0
;
speex_preprocess_ctl
(
_noiseState
,
SPEEX_PREPROCESS_SET_DEREVERB_LEVEL
,
&
f
);
}
}
template
<
typename
D
>
template
<
typename
D
>
...
@@ -682,12 +675,18 @@ int AudioRtpSession<D>::processDataEncode (void)
...
@@ -682,12 +675,18 @@ int AudioRtpSession<D>::processDataEncode (void)
nbSample
=
_converter
->
downsampleData
(
_micData
,
_micDataConverted
,
_audiocodec
->
getClockRate
(),
_mainBufferSampleRate
,
nb_sample_up
);
nbSample
=
_converter
->
downsampleData
(
_micData
,
_micDataConverted
,
_audiocodec
->
getClockRate
(),
_mainBufferSampleRate
,
nb_sample_up
);
if
(
_manager
->
audioPreference
.
getNoiseReduce
())
_audioProcess
->
processAudio
(
_micDataConverted
,
nbSample
*
sizeof
(
SFLDataFormat
));
compSize
=
_audiocodec
->
codecEncode
(
_micDataEncoded
,
_micDataConverted
,
nbSample
*
sizeof
(
SFLDataFormat
));
compSize
=
_audiocodec
->
codecEncode
(
_micDataEncoded
,
_micDataConverted
,
nbSample
*
sizeof
(
SFLDataFormat
));
}
else
{
}
else
{
_nSamplesMic
=
nbSample
;
_nSamplesMic
=
nbSample
;
if
(
_manager
->
audioPreference
.
getNoiseReduce
())
_audioProcess
->
processAudio
(
_micData
,
nbSample
*
sizeof
(
SFLDataFormat
));
// no resampling required
// no resampling required
compSize
=
_audiocodec
->
codecEncode
(
_micDataEncoded
,
_micData
,
nbSample
*
sizeof
(
SFLDataFormat
));
compSize
=
_audiocodec
->
codecEncode
(
_micDataEncoded
,
_micData
,
nbSample
*
sizeof
(
SFLDataFormat
));
...
@@ -724,8 +723,6 @@ void AudioRtpSession<D>::processDataDecode (unsigned char * spkrData, unsigned i
...
@@ -724,8 +723,6 @@ void AudioRtpSession<D>::processDataDecode (unsigned char * spkrData, unsigned i
// Store the number of samples for recording
// Store the number of samples for recording
_nSamplesSpkr
=
nbSample
;
_nSamplesSpkr
=
nbSample
;
speex_preprocess_run
(
_noiseState
,
_spkrDataConverted
);
// put data in audio layer, size in byte
// put data in audio layer, size in byte
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
putData
(
_spkrDataConverted
,
nbSample
*
sizeof
(
SFLDataFormat
),
100
,
_ca
->
getCallId
());
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
putData
(
_spkrDataConverted
,
nbSample
*
sizeof
(
SFLDataFormat
),
100
,
_ca
->
getCallId
());
...
@@ -734,8 +731,6 @@ void AudioRtpSession<D>::processDataDecode (unsigned char * spkrData, unsigned i
...
@@ -734,8 +731,6 @@ void AudioRtpSession<D>::processDataDecode (unsigned char * spkrData, unsigned i
// Store the number of samples for recording
// Store the number of samples for recording
_nSamplesSpkr
=
nbSample
;
_nSamplesSpkr
=
nbSample
;
// speex_preprocess_run(_noiseState, _spkrDataDecoded);
// put data in audio layer, size in byte
// put data in audio layer, size in byte
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
putData
(
_spkrDataDecoded
,
expandedSize
,
100
,
_ca
->
getCallId
());
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
putData
(
_spkrDataDecoded
,
expandedSize
,
100
,
_ca
->
getCallId
());
}
}
...
@@ -882,13 +877,17 @@ void AudioRtpSession<D>::run ()
...
@@ -882,13 +877,17 @@ void AudioRtpSession<D>::run ()
throw
AudioRtpSessionException
();
throw
AudioRtpSessionException
();
}
}
// Set recording sampling rate
_ca
->
setRecordingSmplRate
(
_audiocodec
->
getClockRate
());
_ca
->
setRecordingSmplRate
(
_audiocodec
->
getClockRate
());
// init noise reduction process
_noiseSuppress
=
new
NoiseSuppress
(
_codecFrameSize
,
_audiocodec
->
getClockRate
());
_audioProcess
=
new
AudioProcessing
(
_noiseSuppress
);
// Start audio stream (if not started) AND flush all buffers (main and urgent)
// Start audio stream (if not started) AND flush all buffers (main and urgent)
_manager
->
getAudioDriver
()
->
startStream
();
_manager
->
getAudioDriver
()
->
startStream
();
static_cast
<
D
*>
(
this
)
->
startRunning
();
static_cast
<
D
*>
(
this
)
->
startRunning
();
_debug
(
"RTP: Entering mainloop for call %s"
,
_ca
->
getCallId
().
c_str
());
_debug
(
"RTP: Entering mainloop for call %s"
,
_ca
->
getCallId
().
c_str
());
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
getInternalSamplingRate
();
_manager
->
getAudioDriver
()
->
getMainBuffer
()
->
getInternalSamplingRate
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment