зеркало из https://github.com/mozilla/cubeb.git
tests: check correctly the audio buffer values range (BMO 1484541). (#461)
* tests: check correctly the audio buffer values range (BMO 1484541). * tests: create a comfortable way to enable logs in tests * duplex test: check audio range correctly and change the input channel to stereo to avoid AD mixer (BMO 1484541). * test_duplex: Revert back input channel to mono
This commit is contained in:
Родитель
d4b8c31cfd
Коммит
5066cfcf42
|
@ -93,6 +93,18 @@ void print_log(const char * msg, ...)
|
|||
* override. */
|
||||
int common_init(cubeb ** ctx, char const * ctx_name)
|
||||
{
|
||||
#ifdef ENABLE_NORMAL_LOG
|
||||
if (cubeb_set_log_callback(CUBEB_LOG_NORMAL, print_log) != CUBEB_OK) {
|
||||
fprintf(stderr, "Set normal log callback failed\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_VERBOSE_LOG
|
||||
if (cubeb_set_log_callback(CUBEB_LOG_VERBOSE, print_log) != CUBEB_OK) {
|
||||
fprintf(stderr, "Set verbose log callback failed\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
int r;
|
||||
char const * backend;
|
||||
char const * ctx_backend;
|
||||
|
|
|
@ -17,9 +17,12 @@
|
|||
#include <memory>
|
||||
#include <string.h>
|
||||
#include "cubeb/cubeb.h"
|
||||
#include "common.h"
|
||||
#include <string>
|
||||
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define MAX_NUM_CHANNELS 32
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright © 2017 Mozilla Foundation
|
||||
* Copyright <EFBFBD> 2017 Mozilla Foundation
|
||||
*
|
||||
* This program is made available under an ISC-style license. See the
|
||||
* accompanying file LICENSE for details.
|
||||
|
@ -15,6 +15,9 @@
|
|||
#include <atomic>
|
||||
#include <string>
|
||||
#include "cubeb/cubeb.h"
|
||||
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
const uint32_t SAMPLE_FREQUENCY = 48000;
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h" // for layout_infos
|
||||
#include "cubeb/cubeb.h" // for cubeb utils
|
||||
#include "cubeb_utils.h" // for owned_critical_section, auto_lock
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
#include <string.h>
|
||||
#include <memory>
|
||||
#include "cubeb/cubeb.h"
|
||||
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
|
||||
|
|
|
@ -16,15 +16,22 @@
|
|||
#include <math.h>
|
||||
#include <memory>
|
||||
#include "cubeb/cubeb.h"
|
||||
#include "common.h"
|
||||
#include <atomic>
|
||||
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
#define SAMPLE_FREQUENCY 48000
|
||||
#define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32LE
|
||||
#define INPUT_CHANNELS 1
|
||||
#define INPUT_LAYOUT CUBEB_LAYOUT_MONO
|
||||
#define OUTPUT_CHANNELS 2
|
||||
#define OUTPUT_LAYOUT CUBEB_LAYOUT_STEREO
|
||||
|
||||
struct user_state_duplex
|
||||
{
|
||||
std::atomic<int> seen_audio{ 0 };
|
||||
std::atomic<int> invalid_audio_value{ 0 };
|
||||
};
|
||||
|
||||
long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
|
||||
|
@ -32,7 +39,6 @@ long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer
|
|||
user_state_duplex * u = reinterpret_cast<user_state_duplex*>(user);
|
||||
float *ib = (float *)inputbuffer;
|
||||
float *ob = (float *)outputbuffer;
|
||||
bool seen_audio = 1;
|
||||
|
||||
if (stream == NULL || inputbuffer == NULL || outputbuffer == NULL) {
|
||||
return CUBEB_ERROR;
|
||||
|
@ -42,16 +48,14 @@ long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer
|
|||
// checking if there is noise in the process.
|
||||
long output_index = 0;
|
||||
for (long i = 0; i < nframes; i++) {
|
||||
if (ib[i] <= -1.0 && ib[i] >= 1.0) {
|
||||
seen_audio = 0;
|
||||
if (ib[i] <= -1.0 || ib[i] >= 1.0) {
|
||||
u->invalid_audio_value = 1;
|
||||
break;
|
||||
}
|
||||
ob[output_index] = ob[output_index + 1] = ib[i];
|
||||
output_index += 2;
|
||||
}
|
||||
|
||||
u->seen_audio |= seen_audio;
|
||||
|
||||
return nframes;
|
||||
}
|
||||
|
||||
|
@ -98,14 +102,14 @@ TEST(cubeb, duplex)
|
|||
|
||||
/* typical user-case: mono input, stereo output, low latency. */
|
||||
input_params.format = STREAM_FORMAT;
|
||||
input_params.rate = 48000;
|
||||
input_params.channels = 1;
|
||||
input_params.layout = CUBEB_LAYOUT_MONO;
|
||||
input_params.rate = SAMPLE_FREQUENCY;
|
||||
input_params.channels = INPUT_CHANNELS;
|
||||
input_params.layout = INPUT_LAYOUT;
|
||||
input_params.prefs = CUBEB_STREAM_PREF_NONE;
|
||||
output_params.format = STREAM_FORMAT;
|
||||
output_params.rate = 48000;
|
||||
output_params.channels = 2;
|
||||
output_params.layout = CUBEB_LAYOUT_STEREO;
|
||||
output_params.rate = SAMPLE_FREQUENCY;
|
||||
output_params.channels = OUTPUT_CHANNELS;
|
||||
output_params.layout = OUTPUT_LAYOUT;
|
||||
output_params.prefs = CUBEB_STREAM_PREF_NONE;
|
||||
|
||||
r = cubeb_get_min_latency(ctx, &output_params, &latency_frames);
|
||||
|
@ -123,7 +127,7 @@ TEST(cubeb, duplex)
|
|||
delay(500);
|
||||
cubeb_stream_stop(stream);
|
||||
|
||||
ASSERT_TRUE(stream_state.seen_audio.load());
|
||||
ASSERT_FALSE(stream_state.invalid_audio_value.load());
|
||||
}
|
||||
|
||||
void device_collection_changed_callback(cubeb * context, void * user)
|
||||
|
@ -156,14 +160,14 @@ TEST(cubeb, duplex_collection_change)
|
|||
|
||||
/* typical user-case: mono input, stereo output, low latency. */
|
||||
input_params.format = STREAM_FORMAT;
|
||||
input_params.rate = 48000;
|
||||
input_params.channels = 1;
|
||||
input_params.layout = CUBEB_LAYOUT_MONO;
|
||||
input_params.rate = SAMPLE_FREQUENCY;
|
||||
input_params.channels = INPUT_CHANNELS;
|
||||
input_params.layout = INPUT_LAYOUT;
|
||||
input_params.prefs = CUBEB_STREAM_PREF_NONE;
|
||||
output_params.format = STREAM_FORMAT;
|
||||
output_params.rate = 48000;
|
||||
output_params.channels = 2;
|
||||
output_params.layout = CUBEB_LAYOUT_STEREO;
|
||||
output_params.rate = SAMPLE_FREQUENCY;
|
||||
output_params.channels = OUTPUT_CHANNELS;
|
||||
output_params.layout = OUTPUT_LAYOUT;
|
||||
output_params.prefs = CUBEB_STREAM_PREF_NONE;
|
||||
|
||||
r = cubeb_get_min_latency(ctx, &output_params, &latency_frames);
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <memory>
|
||||
#include "cubeb/cubeb.h"
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
TEST(cubeb, latency)
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
#include <mutex>
|
||||
#include <string>
|
||||
#include "cubeb/cubeb.h"
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
const uint32_t SAMPLE_FREQUENCY = 48000;
|
||||
const uint32_t TONE_FREQUENCY = 440;
|
||||
const double OUTPUT_AMPLITUDE = 0.25;
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include <memory>
|
||||
#include <atomic>
|
||||
#include "cubeb/cubeb.h"
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
#define SAMPLE_FREQUENCY 48000
|
||||
|
|
|
@ -15,15 +15,18 @@
|
|||
#include <math.h>
|
||||
#include <memory>
|
||||
#include "cubeb/cubeb.h"
|
||||
#include "common.h"
|
||||
#include <atomic>
|
||||
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
#define SAMPLE_FREQUENCY 48000
|
||||
#define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32LE
|
||||
|
||||
struct user_state_record
|
||||
{
|
||||
std::atomic<int> seen_audio{ 0 };
|
||||
std::atomic<int> invalid_audio_value{ 0 };
|
||||
};
|
||||
|
||||
long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
|
||||
|
@ -35,16 +38,13 @@ long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer
|
|||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
bool seen_audio = 1;
|
||||
for (long i = 0; i < nframes; i++) {
|
||||
if (b[i] <= -1.0 && b[i] >= 1.0) {
|
||||
seen_audio = 0;
|
||||
if (b[i] <= -1.0 || b[i] >= 1.0) {
|
||||
u->invalid_audio_value = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
u->seen_audio |= seen_audio;
|
||||
|
||||
return nframes;
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,6 @@ TEST(cubeb, record)
|
|||
// user callback does not arrive in Linux, silence the error
|
||||
fprintf(stderr, "Check is disabled in Linux\n");
|
||||
#else
|
||||
ASSERT_TRUE(stream_state.seen_audio.load());
|
||||
ASSERT_FALSE(stream_state.invalid_audio_value.load());
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
#define STREAM_RATE 44100
|
||||
|
|
|
@ -16,9 +16,13 @@
|
|||
#include <memory>
|
||||
#include <limits.h>
|
||||
#include "cubeb/cubeb.h"
|
||||
#include "common.h"
|
||||
#include <atomic>
|
||||
|
||||
//#define ENABLE_NORMAL_LOG
|
||||
//#define ENABLE_VERBOSE_LOG
|
||||
#include "common.h"
|
||||
|
||||
|
||||
#define SAMPLE_FREQUENCY 48000
|
||||
#define STREAM_FORMAT CUBEB_SAMPLE_S16LE
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче