diff options
author | Gerald Begumisa <ben_g@users.sourceforge.net> | 2009-01-12 21:23:34 +0000 |
---|---|---|
committer | Gerald Begumisa <ben_g@users.sourceforge.net> | 2009-01-12 21:23:34 +0000 |
commit | 66a503098b38b2ee2c6f58cf8b3548ef003ea99b (patch) | |
tree | 1b782bf3b7bbf0f4a3d8522c0e147141a2be609f | |
parent | 650105c2e53d80741292d2752cb48b3d9625ca09 (diff) |
Modified the AudioGain filter and: Implemented change on gain calculation; Corrected sample range error; Changed configuration variables from AudioGain, AudioGainChannel1 and AudioGainChannel2 to AudioGainDb, AudioGainChannel1Db and AudioGainChannel2Db
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@593 09dcff7a-b715-0410-9601-b79a96267cd0
-rw-r--r-- | orkbasecxx/BatchProcessing.cpp | 14 | ||||
-rw-r--r-- | orkbasecxx/Config.cpp | 12 | ||||
-rw-r--r-- | orkbasecxx/Config.h | 18 | ||||
-rw-r--r-- | orkbasecxx/filters/audiogain/AudioGain.cpp | 46 |
4 files changed, 38 insertions, 52 deletions
diff --git a/orkbasecxx/BatchProcessing.cpp b/orkbasecxx/BatchProcessing.cpp index e82a248..560ac3e 100644 --- a/orkbasecxx/BatchProcessing.cpp +++ b/orkbasecxx/BatchProcessing.cpp @@ -288,13 +288,16 @@ void BatchProcessing::ThreadHandler(void *args) numSamplesS1 += tmpChunkRef->GetNumSamples(); } } + + audiogain->AudioChunkIn(tmpChunkRef); + audiogain->AudioChunkOut(tmpChunkRef); filter->AudioChunkIn(tmpChunkRef); filter->AudioChunkOut(tmpChunkRef); + } else { + audiogain->AudioChunkIn(tmpChunkRef); + audiogain->AudioChunkOut(tmpChunkRef); } - audiogain->AudioChunkIn(tmpChunkRef); - audiogain->AudioChunkOut(tmpChunkRef); - outFileRef->WriteChunk(tmpChunkRef); if(tmpChunkRef.get()) { @@ -340,16 +343,11 @@ void BatchProcessing::ThreadHandler(void *args) filter->AudioChunkIn(stopChunk); filter->AudioChunkOut(tmpChunkRef); - audiogain->AudioChunkIn(tmpChunkRef); - audiogain->AudioChunkOut(tmpChunkRef); - while(tmpChunkRef.get()) { outFileRef->WriteChunk(tmpChunkRef); numSamplesOut += tmpChunkRef->GetNumSamples(); filter->AudioChunkOut(tmpChunkRef); - audiogain->AudioChunkIn(tmpChunkRef); - audiogain->AudioChunkOut(tmpChunkRef); } } diff --git a/orkbasecxx/Config.cpp b/orkbasecxx/Config.cpp index db8622f..47199e7 100644 --- a/orkbasecxx/Config.cpp +++ b/orkbasecxx/Config.cpp @@ -73,9 +73,9 @@ Config::Config() m_tapeDurationMinimumSec = TAPE_DURATION_MINIMUM_SEC_DEFAULT; m_transcodingSleepEveryNumFrames = TRANSCODING_SLEEP_EVERY_NUM_FRAMES_DEFAULT; m_transcodingSleepUs = TRANSCODING_SLEEP_US_DEFAULT; - m_audioGain = AUDIO_GAIN_DEFAULT; - m_audioGainChannel1 = AUDIO_GAIN_CHANNEL_1_DEFAULT; - m_audioGainChannel2 = AUDIO_GAIN_CHANNEL_2_DEFAULT; + m_audioGainDb = AUDIO_GAIN_DB_DEFAULT; + m_audioGainChannel1Db = AUDIO_GAIN_CHANNEL_1_DB_DEFAULT; + m_audioGainChannel2Db = AUDIO_GAIN_CHANNEL_2_DB_DEFAULT; m_eventStreamingServerPort = STREAMING_SERVER_PORT_DEFAULT; } @@ -154,9 +154,9 @@ void Config::Define(Serializer* s) s->IntValue(TAPE_DURATION_MINIMUM_SEC_PARAM, m_tapeDurationMinimumSec); s->IntValue(TRANSCODING_SLEEP_EVERY_NUM_FRAMES_PARAM, m_transcodingSleepEveryNumFrames); s->IntValue(TRANSCODING_SLEEP_US_PARAM, m_transcodingSleepUs); - s->DoubleValue(AUDIO_GAIN_PARAM, m_audioGain); - s->DoubleValue(AUDIO_GAIN_CHANNEL_1_PARAM, m_audioGainChannel1); - s->DoubleValue(AUDIO_GAIN_CHANNEL_2_PARAM, m_audioGainChannel2); + s->DoubleValue(AUDIO_GAIN_DB_PARAM, m_audioGainDb); + s->DoubleValue(AUDIO_GAIN_CHANNEL_1_DB_PARAM, m_audioGainChannel1Db); + s->DoubleValue(AUDIO_GAIN_CHANNEL_2_DB_PARAM, m_audioGainChannel2Db); s->IntValue(STREAMING_SERVER_PORT_PARAM, m_eventStreamingServerPort); } diff --git a/orkbasecxx/Config.h b/orkbasecxx/Config.h index 0d8d565..d90ff24 100644 --- a/orkbasecxx/Config.h +++ b/orkbasecxx/Config.h @@ -116,12 +116,12 @@ #define TRANSCODING_SLEEP_EVERY_NUM_FRAMES_DEFAULT 0 #define TRANSCODING_SLEEP_US_PARAM "TranscodingSleepUs" #define TRANSCODING_SLEEP_US_DEFAULT 0 -#define AUDIO_GAIN_PARAM "AudioGain" -#define AUDIO_GAIN_DEFAULT 0 -#define AUDIO_GAIN_CHANNEL_1_PARAM "AudioGainChannel1" -#define AUDIO_GAIN_CHANNEL_1_DEFAULT 0 -#define AUDIO_GAIN_CHANNEL_2_PARAM "AudioGainChannel2" -#define AUDIO_GAIN_CHANNEL_2_DEFAULT 0 +#define AUDIO_GAIN_DB_PARAM "AudioGainDb" +#define AUDIO_GAIN_DB_DEFAULT 0 +#define AUDIO_GAIN_CHANNEL_1_DB_PARAM "AudioGainChannel1Db" +#define AUDIO_GAIN_CHANNEL_1_DB_DEFAULT 0 +#define AUDIO_GAIN_CHANNEL_2_DB_PARAM "AudioGainChannel2Db" +#define AUDIO_GAIN_CHANNEL_2_DB_DEFAULT 0 class DLL_IMPORT_EXPORT_ORKBASE Config : public Object { @@ -187,9 +187,9 @@ public: int m_tapeDurationMinimumSec; int m_transcodingSleepEveryNumFrames; int m_transcodingSleepUs; - double m_audioGain; - double m_audioGainChannel1; - double m_audioGainChannel2; + double m_audioGainDb; + double m_audioGainChannel1Db; + double m_audioGainChannel2Db; private: log4cxx::LoggerPtr m_log; diff --git a/orkbasecxx/filters/audiogain/AudioGain.cpp b/orkbasecxx/filters/audiogain/AudioGain.cpp index 59fec5d..0976b98 100644 --- a/orkbasecxx/filters/audiogain/AudioGain.cpp +++ b/orkbasecxx/filters/audiogain/AudioGain.cpp @@ -77,46 +77,34 @@ void AudioGainFilter::AudioChunkIn(AudioChunkRef& inputAudioChunk) short* outputBuffer = (short*)m_outputAudioChunk->CreateBuffer(outputDetails);
short* inputBuffer = (short*)inputAudioChunk->m_pBuffer;
int sample = 0;
+ double multiplier, multiplier1, multiplier2;
+
+ multiplier = 0.0;
+ multiplier1 = 0.0;
+ multiplier2 = 0.0;
+
+ multiplier = pow(10, (CONFIG.m_audioGainDb / 20.0));
+ multiplier1 = pow(10, (CONFIG.m_audioGainChannel1Db / 20.0));
+ multiplier2 = pow(10, (CONFIG.m_audioGainChannel2Db / 20.0));
for(i = 0; i < r_samples; i++) {
sample = inputBuffer[i];
- if(CONFIG.m_audioGain != 0)
+ if(CONFIG.m_audioGainDb != 0)
{
- if(CONFIG.m_audioGain < 0)
- {
- sample = (int)((double)sample / sqrt(fabs(CONFIG.m_audioGain)));
- }
- else
- {
- sample = (int)((double)sample * sqrt(fabs(CONFIG.m_audioGain)));
- }
+ sample = sample * multiplier;
}
- if(CONFIG.m_audioGainChannel1 != 0)
+ if(CONFIG.m_audioGainChannel1Db != 0)
{
if(outputDetails.m_channel == 1)
{
- if(CONFIG.m_audioGainChannel1 < 0)
- {
- sample = (int)((double)sample / sqrt(fabs(CONFIG.m_audioGainChannel1)));
- }
- else
- {
- sample = (int)((double)sample * sqrt(fabs(CONFIG.m_audioGainChannel1)));
- }
+ sample = sample * multiplier1;
}
}
- if(CONFIG.m_audioGainChannel2 != 0)
+ if(CONFIG.m_audioGainChannel2Db != 0)
{
if(outputDetails.m_channel == 2)
{
- if(CONFIG.m_audioGainChannel2 < 0)
- {
- sample = (int)((double)sample / sqrt(fabs(CONFIG.m_audioGainChannel2)));
- }
- else
- {
- sample = (int)((double)sample / sqrt(fabs(CONFIG.m_audioGainChannel2)));
- }
+ sample = sample * multiplier2;
}
}
@@ -124,9 +112,9 @@ void AudioGainFilter::AudioChunkIn(AudioChunkRef& inputAudioChunk) {
sample = -32768;
}
- if(sample > 32768)
+ if(sample > 32767)
{
- sample = 32768;
+ sample = 32767;
}
outputBuffer[i] = sample;
|