Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Resample.cpp « tests « src - github.com/mumble-voip/mumble.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ec0f256cd02eb98cbf58ba97c251741746eb9cf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright 2009-2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.

/**
 * Speex resampling test / information.
 */

#ifdef Q_OS_WIN
#	include "win.h"
#endif

#include "Timer.h"

#include <QtCore>

#define _USE_MATH_DEFINES
#include <cmath>

#include <speex/speex_resampler.h>

#include <ipp.h>

#define ITER 1000

int main(int argc, char **argv) {
	ippStaticInit();
	ippSetNumThreads(1);

#ifdef Q_OS_WIN
	if (!SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS))
		qWarning("Application: Failed to set priority!");
#endif

	QCoreApplication a(argc, argv);

	SpeexResamplerState *srs;

	int iMicFreq    = 44100;
	int iSampleRate = 48000;
	int iFrameSize  = iSampleRate / 100;
	int err         = 0;

	srs = speex_resampler_init(1, iMicFreq, iSampleRate, 3, &err);

	int iMicLength = (iFrameSize * iMicFreq) / iSampleRate;

	qWarning() << iMicFreq << iSampleRate << iFrameSize << iMicLength;

	float *pfInput  = new float[iMicLength];
	float *pfOutput = new float[iFrameSize];

	for (int i = 0; i < iMicLength; ++i) {
		pfInput[i] = sinf((M_PI * i * 20) / iMicLength);
	}

	for (int i = 0; i < iFrameSize; ++i)
		pfOutput[i] = 0;

	qWarning() << "speex resampler latency: " << speex_resampler_get_input_latency(srs);


	Timer t;

	for (int i = 0; i < ITER; ++i) {
		spx_uint32_t inlen  = iMicLength;
		spx_uint32_t outlen = iFrameSize;
		speex_resampler_process_float(srs, 0, pfInput, &inlen, pfOutput, &outlen);
	}

	quint64 e = t.elapsed();

	qWarning() << "speex us per iteration: " << (e / ITER);

	float min = 0.0;
	float max = 0.0;

	for (int i = 0; i < iFrameSize; ++i) {
		min = qMin(min, pfOutput[i]);
		max = qMax(max, pfOutput[i]);
	}

	qWarning() << "Speex bounds" << min << max;

	delete[] pfOutput;

	int history  = 24;
	int lastread = history;
	double time  = history;
	int olen     = 0;

	float *inBuf = ippsMalloc_32f(iMicLength + history * 2 + 2);
	ippsZero_32f(inBuf, iMicLength + history * 2 + 2);

	pfOutput = ippsMalloc_32f(iFrameSize + 2);

	for (int i = 0; i < iFrameSize; ++i)
		pfOutput[i] = 0;


	IppsResamplingPolyphaseFixed_32f *pSpec = nullptr;
	ippsResamplePolyphaseFixedInitAlloc_32f(&pSpec, iMicFreq, iSampleRate, 2 * history, 0.90f, 8.0f, ippAlgHintFast);

	t.restart();

	for (int i = 0; i < ITER; ++i) {
		ippsCopy_32f(pfInput, inBuf + history, iMicLength);

		ippsResamplePolyphaseFixed_32f(pSpec, inBuf, iMicLength, pfOutput, .99f, &time, &olen);

		time -= iMicLength;

		ippsMove_32f(inBuf + history, inBuf, history);
	}

	e = t.elapsed();
	qWarning() << "ipp us per iteration: " << (e / ITER);

	min = 0.0;
	max = 0.0;

	for (int i = 0; i < iFrameSize; ++i) {
		min = qMin(min, pfOutput[i]);
		max = qMax(max, pfOutput[i]);
	}

	qWarning() << "IPP bounds" << min << max;

	delete[] pfInput;

	return 0;
}

#undef _USE_MATH_DEFINES
#undef ITER