diff options
author | Thorvald Natvig <slicer@users.sourceforge.net> | 2008-02-26 03:04:00 +0300 |
---|---|---|
committer | Thorvald Natvig <slicer@users.sourceforge.net> | 2008-02-26 03:04:00 +0300 |
commit | 4c5f56d4c491480dfa3d49abb696ffaad86a3077 (patch) | |
tree | 6942869d425f9c2d921296c27cfb2a45262e3506 /speexbuild/SpeexMark.cpp | |
parent | a9adffb2369b4263b3669f6c882e8696207c9675 (diff) |
Support profile-optimized libspeex. Slim gain so far, waiting to test on Core2
git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@955 05730e5d-ab1b-0410-a4ac-84af385074fa
Diffstat (limited to 'speexbuild/SpeexMark.cpp')
-rw-r--r-- | speexbuild/SpeexMark.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/speexbuild/SpeexMark.cpp b/speexbuild/SpeexMark.cpp new file mode 100644 index 000000000..c913487ec --- /dev/null +++ b/speexbuild/SpeexMark.cpp @@ -0,0 +1,97 @@ +#include <QtCore> +#include <math.h> +#include <speex/speex.h> +#include <speex/speex_jitter.h> +#include <speex/speex_preprocess.h> +#include <speex/speex_echo.h> +#include <speex/speex_callbacks.h> +#include <valgrind/callgrind.h> + +#include "Timer.h" + +int main(int argc, char **argv) { + + CALLGRIND_STOP_INSTRUMENTATION; + CALLGRIND_ZERO_STATS; + + QCoreApplication a(argc, argv); + + QFile f((argc >= 2) ? argv[1] : "wb_male.wav"); + if (! f.open(QIODevice::ReadOnly)) { + qFatal("Failed to open file!"); + } + f.seek(36 + 8); + + void *enc = speex_encoder_init(&speex_wb_mode); + + int iarg = 1; + speex_encoder_ctl(enc, SPEEX_SET_VBR, &iarg); + iarg = 0; + speex_encoder_ctl(enc, SPEEX_SET_VAD, &iarg); + speex_encoder_ctl(enc, SPEEX_SET_DTX, &iarg); + + float farg = 6.0; + speex_encoder_ctl(enc, SPEEX_SET_VBR_QUALITY, &farg); + speex_encoder_ctl(enc, SPEEX_GET_BITRATE, &iarg); + speex_encoder_ctl(enc, SPEEX_SET_VBR_MAX_BITRATE, &iarg); + + iarg = 4; + speex_encoder_ctl(enc, SPEEX_SET_COMPLEXITY, &iarg); + + int iFrameSize; + speex_encoder_ctl(enc, SPEEX_GET_FRAME_SIZE, &iFrameSize); + + SpeexPreprocessState *spp = speex_preprocess_state_init(iFrameSize, 16000); + iarg = 1; + speex_preprocess_ctl(spp, SPEEX_PREPROCESS_SET_VAD, &iarg); + speex_preprocess_ctl(spp, SPEEX_PREPROCESS_SET_DENOISE, &iarg); + speex_preprocess_ctl(spp, SPEEX_PREPROCESS_SET_AGC, &iarg); + speex_preprocess_ctl(spp, SPEEX_PREPROCESS_SET_DEREVERB, &iarg); + + SpeexEchoState *ses = speex_echo_state_init(iFrameSize, iFrameSize * 10); + iarg = 16000; + speex_echo_ctl(ses, SPEEX_SET_SAMPLING_RATE, &iarg); + speex_preprocess_ctl(spp, SPEEX_PREPROCESS_SET_ECHO_STATE, ses); + + QVector<QByteArray> v; + while(1) { + QByteArray qba = f.read(iFrameSize * 2); + if (qba.size() != iFrameSize * 2) + break; + v.append(qba); + } + + int nframes = v.size(); + + qWarning("Ready to process %d frames of %d samples", nframes, iFrameSize); + + QVector<short *> sv; + + short tframe[iFrameSize]; + for(int i=0;i<iFrameSize;i++) + tframe[i] = 0; + + for(int i=0;i<nframes;i++) { + sv.append(reinterpret_cast<short *>(v[i].data())); + } + + SpeexBits sb; + speex_bits_init(&sb); + + Timer t; + t.restart(); + + CALLGRIND_START_INSTRUMENTATION; + for(int i=0;i<nframes-2;i++) { + speex_bits_reset(&sb); + speex_echo_cancellation(ses, sv[i], sv[i+2], tframe); + speex_preprocess_run(spp, tframe); + speex_encode_int(enc, tframe, &sb); + } + CALLGRIND_STOP_INSTRUMENTATION; + + quint64 e = t.elapsed(); + + qWarning("Used %llu usec", e); + qWarning("%.2f times realtime", (20000ULL * nframes) / (e * 1.0)); +} |