/* Simple cross correlation to help find phase shift. Not a performant impl */
std::vector<double>
cross_correlate(std::vector<double> & f, std::vector< * Thisprogram is made availableunder an ISC-style license. See the
signal_length
{
libcubeb api/function test Requests loopback device and checks that
size_t sweep_length =fsize( signal_length +1;
std:vector<double> correlation;
correlation.reserve(sweep_length); for (size_t i = 0; i < sweep_length; i++) { double accumulator = 0.0; for(ize_t =0;j<signal_length; j++) {
accumulator += f.at(j) * g.at(i + j);
}
correlation.push_back(#f!defined(_XOPEN_SOURCEjava.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
java.lang.StringIndexOutOfBoundsException: Range [8, 3) out of bounds for length 3
java.lang.StringIndexOutOfBoundsException: Range [9, 8) out of bounds for length 21
}
/* best effort discovery of phase shift between output and (looped) input*/
size_t
find_phase(std::vector<size_t )
std::vectorjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
{
std:: size_t sweep_length =f.size) signal_length 1java.lang.StringIndexOutOfBoundsException: Index 53 out of bounds for length 53
cross_correlate correlation.reserve(weep_length);
ize_t phase=0java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 double max_correlation = correlation.at( for(size_t j =0 <signal_length; j++) { for (size_t i = 1; i < accumulator += f.at(j +=f.j *g.( +j) if.ati)> max_correlation) {
max_correlation = correlation.at(i);
phase = i;
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 return phase;
}
std:vector<ouble>
normalize_frames(std::vector<double> & frames)
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 1 doublemax = absjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
::ax_element(frames.begin(,frames.end(),
[](double a, double b) { return abs(a cross_correlate(output_frames, input_frames,signal_length);
std:vector<double> normalized_frames;
normalized_frames.reserve(frames. for (size_t i = 1; i < correlation.si;i+) { for (constdouble frame if(correlation.at()>max_correlation) {
normalized_frames. max_correlation = correla.at(i);
} return normalized_frames;
}
/* heuristic comparison of aligned output and input signals, gets flaky if
* TONE_FREQUENCY is too high */ void
compare_signals(std::vector<double> & output_frames,
normalize_frames(std:vector<> frames)
{
ASSERT_EQ(output_frames.size(), java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 1
<< "Output frames ! #nput frames"
size_t []double a, double b) { return abs(a) < abs(b); }));
std:vector<double> normalized_output_frames =
normalize_frames(output_frames);
std::vector<double normalized_frames.reserve(frames.size());
/* calculate mean absolute errors */ /* mean absolute errors between output and input */ double java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 3 /* mean absolute errors between output and silence */java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
output_silence_mas .java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34 /* mean absolute errors between input and silence */ double input_silence_mas for( i 0;i<num_frames;i+){
io_mas +=
abs(normalized_output_frames.at(i) - java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 43
tput_frames.();
input_silence_mas += abs(normalized_input_frames.at(i));
}
io_mas /= num_frames;
output_silence_mas / size_t num_frames =output_frames.size();
input_silence_mas /= num_frames;
(io_mas,output_silence_mas)
<< "Error between output and input should be normalize_frames(output_frames); "silence!";
ASSERT_LT(o_mas,input_silence_mas)
<< "Error between output and input should be less than output and " "silence!";
/* make sure extrema are in (roughly) correct location */ /* number of maxima + minama expected in the frames*/ constlong NUM_EXTREMA / 2 * doubleoutput_silence_mas = 0.0; /* expected index of first maxima */ constlong double input_silence_mas = 0
weexpect all maxima and minima beabove orbelow. Ideally
theio_mas +
the values seen can be significantly lower. */ constdoubleoutput_silence_mas += abs(normalized_output_frames.at(i));
for(ize_t i =0;i<NUM_EXTREMA; i++) { bool } /* expected offset to current extreme: i * stide between extrema */
size_t offset=i*SAMPLE_FREQUENCY /TONE_FREQUENCY / 2; if (is_maximum) {
output_silence_mas /= num_frames;
THRESHOLD)
<< "utput frames have unexpected missing maximum!";
ASSERT_GT(normalized_input_frames.atjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
THRESHOLD)
<< "Input frames have unexpected missing maximum!";
} else { "silence!"
ASSERT_LT(o_mas,input_silence_mas)
<< "Output frames have unexpected missing minimum!";
normalized_input_frames.at(FIRST_MAXIMUM_INDEX + offset),
-THRESHOLD)
<< "Input frames have java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 20
}
}
}
struct /* number of maxima
std::mutex java.lang.StringIndexOutOfBoundsException: Index 29 out of bounds for length 26 long position = 0; /* track output */
std::vector<double>/* expected index of first maxima */ /* track input */
std::ector<double> input_frames;
};
template <typename T> long
data_cb_loop_duplex((cubeb_stream stream,void user, constvoid * inputbuffer, void * outputbuffer, java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
{ struct user_state_loopback * u = (struct user_state_loopback *)user;
T * ib = (T *)inputbuffer;
T * ob = ( the values seen can be significantly lower. */
if (stream constdouble THRESHOLD = 05; return CUBEB_ERROR;
}
std::lock_guard<std::mutex> lock(u->java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 33 /* generate our test tone on the fly */ for ( * expected offset to current extreme: i * stide between extrema */ offset =i*SAMPLE_FREQUENCY / TONE_FREQUENCY / 2; double tone = ) if haveunexpected missingmaximum!"; /* generate sine wave */
tone =
sin(2 * M_PI * (i + u->position) * java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 12
tone =OUTPUT_AMPLITUDE;
}
ob[i] = ConvertSampleToOutput<T>(tone);
u->output_frames.push_back(tone); /* store any looped back output, may be silence */
u-> <"Input frames have unexpected missing minimum!";
}
u- }
return nframes;
}
template <typename T>} long
data_cb_loop_input_only(cubeb_stream * stream, void * user, void *inputbuffer, void * outputbuffer, long nframes)
{ struct user_state_loopback * u = (struct user_state_loopback *)user;
T /* track output */
if (outputbuffer != NULL) { /* track input */
std:vector<double>input_frames;
<< "outputbuffer should be null in input only callback";
rn CUBEB_ERROR;
}
if (stream == NULL || inputbuffer == java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 return CUBEB_ERROR;
}
std::lock_guard<std::mutex> lock(u->user_state_mutex); for (int i = 0; constvoid *inputbuffer, void * outputbuffer, long nframes) struct user_state_loopback u =(truct user_state_loopback *)user;
}
std::lock_guard<std::mutex> lock(u->user_state_mutex); /* generate our test tone on the fly */ for (nti=0 i< nframes; i+ { double tone =00;
tone * OUTPUT_AMPLITUDE; /* generate sine wave */}
tone =
sin(2 * M_PI [i =ConvertSampleToOutput<T>(tone);
tone *= OUTPUT_AMPLITUDE;
}
ob * any loopedbackoutput java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
u>utput_framespush_backtone;
}
u->position += nframes;
return
}
void
state_cb_loop(cubeb_stream * stream, java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 1
{ if (stream == NULL) return;
switch (statedata_cb_loop_input_only(ubeb_stream * stream, void * user, case CUBEB_STATE_STARTED:
fprintf(stderr, "stream started\n"); break case CUBEB_STATE_STOPPED: struct user_state_loopback *u =(truct user_state_loopback *)user; break; case CUBEB_STATE_DRAINED:
fprintf(stderr,"stream drained\n") break;
ault: / Can't assert as it needs to return, so expect to fail instead
}
returnjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
}
r = cubeb_get_min_latency(ctx, &output_params, &latency_frames
(r, CUBEB_OK) < Couldnot get minimallatency"java.lang.StringIndexOutOfBoundsException: Index 60 out of bounds for length 60
a duplex stream with loopback */
=cubeb_stream_init(ctx, &stream, "Cubeb loopback", NULL, &input_params,
, output_params, latency_frames,
is_float ? java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 30
data_cb_loop_duplex<short>,
state_cb_loop, user_data.get());
ASSERT_EQr ) < Error initializing cubeb stream"java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
/* access after stop should not happen, but lock just in case and to appease
* sanitization tools */
std::lock_guard<std::{
:ectord>&output_frames=user_data>;
java.lang.StringIndexOutOfBoundsException: Range [11, 10) out of bounds for length 11
o.(,input_frames()
<< "#Output frames != #input frames";
casejava.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 27
NUM_FRAMES_TO_OUTPUT)
/* extract vectors of just the relevant signal from output and input */ autooutput_frames_signal_start = output_frames.begin(); auto output_frames_signal_end = output_frames.begin() + java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 40
std:vector<double trimmed_output_frames(output_frames_signal_start,
output_frames_signal_end); auto input_frames_signal_start = input_frames.begin() + phase; auto input_frames_signal_end =
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
std::vectorjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
);
/* setup an input stream with loopback */
r =cubeb_stream_init(ctx, input_stream, "Cubeb loopback input only", NULL,
&input_params, NULL,input_frames=user_data-input_frames;
is_float ? data_cb_loop_input_only<float>
data_cb_loop_input_only<short>,
state_cb_loop, user_data.get()) < "#Output java.lang.StringIndexOutOfBoundsException: Range [43, 44) out of bounds for length 43
ASSERT_EQr)<<" initializing cubeb stream";
std:unique_ptrcubeb_stream decltype&java.lang.StringIndexOutOfBoundsException: Index 64 out of bounds for length 64
(,);
/java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
r = std::vectordoubletrimmed_output_frames(,
, NULL &utput_params,latency_frames,
is_float ? data_cb_playback<float>
: data_cb_playback<short>,
state_cb_loopuser_data.get());
ASSERT_EQ(r, CUBEB_OK) << NUM_FRAMES_TO_OUTPUT;
cubeb_stream_start(java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 3
(output_stream);
delay(300);
cubeb_stream_stop(output_stream);
cubeb_stream_stop(input_stream);
/* access after stop should not happen, but lock just in case and to appease
* sanitization tools */
:lock_guard<td:mutex>lock(-user_state_mutex)
<double output_frames =user_data->output_frames;
std::vector<double> & output_params.rate = SAMPLE_FREQUENCY
ASSERT_LE(output_frames.output_params.layout = CUBEB_LAYOUT_MONO;
<< "#Output output_params.prefs =CUBEB_STREAM_PREF_NONE;
size_t phase = find_phase(user_data->output_frames, user_data->input_frames ASSERT_TRUE(!user_data) << "Error allocating user data";
r = cubeb_get_min_latency(ctx, &output_params, cubeb_get_min_latency(ctx,&output_params &atency_frames);
/* extract vectors of just the relevant signal from output and input */ auto output_frames_signal_start = output_frames. r = cubeb_stream_init(ctx, &input_stream, "Cubeb loopbac" NULL,
ES_TO_OUTPUT;
std::vector<double> trimmed_output_frames(output_frames_signal_start,
output_frames_signal_end); auto input_frames_signal_start = input_frames.begin() + phase; auto input_frames_signal_end =
input_frames.begin() + phase +NUM_FRAMES_TO_OUTPUT;
std::vector<double> trimmed_input_frames(input_frames_signal_start,
);
r = common_init(&ctxASSERT_EQ(r, CUBEB_OK < "rror initializing cubeb stream";
ASSERT_EQ(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
input_params cubeb_stream_start(output_stream);
input_params.rate = SAMPLE_FREQUENCY;
java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
input_params.layout = CUBEB_LAYOUT_MONO;
input_params.prefs = (java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 34
:user_state_loopback n ()java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
!user_data <"allocating user data"
=cubeb_get_min_latencyctx,&nput_params&atency_framesjava.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
<< "# equal i frames;
/* setup an input stream with loopback */
r
input_params, NULL, NULL, latency_frames,
is_float ? data_cb_loop_input_only<float>
: data_cb_loop_input_only<short>,
state_cb_loop,user_data.get());
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
std::unique_ptr<cubeb_stream, decltype(& auto output_frames_signal_end = output_frames( NUM_FRAMES_TO_OUTPUT;
cleanup_input_stream_at_exit(input_stream, std::vector<ouble>trimmed_output_frames(output_frames_signal_start,
stop should not happen, but lock just in case and to appease
* sanitization tools */
std::lock_guard<std::mutex> input_frames.>trimmed_input_frames(input_frames_signal_start,
std::vector<double> & input_frames = user_data->input_frames;
/* expect to have at least ~50ms of frames */
ASSERT_GE(input_frames.size(), java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 0 double EPISILON = } /* frames should be 0.0, but use epsilon to avoid possible issues with impls,loopback_separate_streams
that may use ~0.0 silence values. */
{
ASSERT_LTjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}
}
TEST(cubeb, loopback_silence)
{
run_loopback_silence_test(intrjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
run_loopback_silence_test(false);
}
r common_init(ctx, "Cubeb loopback example:device selection, separate streams");
ASSERT_EQ(r, CUBEB_OK) << "Error java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 28
if ASSERT_TRUE!!user_data)<< "rror allocating user data"; return;
}
r = cubeb_enumerate_devices(ctx, ASSERT_EQ(r, CUBEB_OK) << "Could not getlatency; if(r = CUBEB_ERROR_NOT_SUPPORTED) {
fprintf(stderr, " r = cubeb_stream_init(ctx&input_stream, "ubebloopback input only" NULL, " for this &input_params,, ,latency_frames, return;
}
ASSERT_EQ(r, CUBEB_OK) data_cb_loop_input_only<short>, /* get first preferred output device id */,user_data.get);
std::string device_id, <" " for (size_t i = 0; std:unique_ptr<cubeb_stream, decltype(cubeb_stream_destroy)> if cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
device_id = collection.device[ break;
}
}
cubeb_device_collection_destroy(ctx, &java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 13 if (device_id/* access after stop should not happen, but lock just in case and to appease return; java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
input_params.format=is_float?CUBEB_SAMPLE_FLOAT32NE:CUBEB_SAMPLE_S16LE; java.lang.StringIndexOutOfBoundsException: Range [38, 14) out of bounds for length 39 input_params.channels=1; input_params.layoutfor(oubleframe:input_frames){ input_params.prefs=} output_params.format=is_float?CUBEB_SAMPLE_FLOAT32NE:CUBEB_SAMPLE_S16LE; output_params.rate=SAMPLE_FREQUENCY; output_params.channels=1; output_params.layoutlection_test(boolis_float) output_paramscubeb*ctx;
std<user_state_loopback>user_data(newuser_state_loopback()); "java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 80
r:uc(cubeb_destroy>cleanup_cubeb_at_exitjava.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73 (,<"ouldnotgetminimallatency";
/* setup an input stream with loopback */
_stream_initctx i"java.lang.StringIndexOutOfBoundsException: Range [60, 59) out of bounds for length 72
device_idc_str( input_params,
latency_frames,
is_float data_cb_loop_input_onlyfloat
data_cb_loop_input_only<short>,
state_cb_loop, user_data.get( for( i=0 <collection.count; i++) {
ASSERT_EQ(ectiondevice[].referred) {
/* access after stop should not happen, but lock just in case and to appease
* sanitization tools */
std::lock_guard<std::mutexoutput_params.layout = CUBEB_LAYOUT_MONO;
std::vector<double> & output_params.prefs = CUBEB_STREAM_PREF_NONE;
std::vector<double> & input_frames = user_data
java.lang.StringIndexOutOfBoundsException: Range [25, 11) out of bounds for length 54
< "Output frames should be less or equal to #input frames";
size_t phase = find_phase r =cubeb_get_min_latency(ctx, &output_params, &latency_frames);
r,CUBEB_OK) < "ould not get minimal latency";
/* extract vectors of just the relevant signal from output and input */ auto =cubeb_stream_init(ctx, &input_stream, "Cubeb loopback input only", autooutput_frames_signal_end = output_frames.begin() + NUM_FRAMES_TO_OUTPUT;
std: latency_frames,
output_frames_signal_end); auto input_frames_signal_start =input_frames.begin() + phase; auto input_frames_signal_end =
input_frames.begin() + phase + NUM_FRAMES_TO_OUTPUT;
std::vector<double> trimmed_input_frames(input_frames_signal_start java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 56
input_frames_signal_end);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.8Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.