Frequently Asked Questions (FAQs)
How often are predictions updated?
Our predictions are updated daily to ensure you have the latest information.
What factors are considered in making predictions?
We consider team form, player availability, historical records, home advantage, and more.
Can I trust these predictions?
Our expert analysts use a rigorous process to ensure high accuracy in our predictions.
How can I use these predictions for betting?
Use them as part of your overall strategy to make informed betting decisions.
Are there any risks involved in betting?
#include "audio.h"
#include "audio.c"
#include "common.h"
#include "loader.h"
#include "log.h"
#include "timing.h"
#include "trace.h"
#define LOG_TAG "audio"
static int current_audio_sample_rate = 44100;
static int audio_init(void)
{
struct audio_config audio_config;
if (audio_get_config(&audio_config) != 0) {
return -1;
}
return audio_open(&audio_config);
}
static int audio_deinit(void)
{
return audio_close();
}
static void audio_reset(void)
{
return audio_reset_buffer();
}
static int audio_set_sample_rate(int sample_rate)
{
if (sample_rate == current_audio_sample_rate) {
return 0;
}
if (audio_set_sample_rate(sample_rate) != 0) {
return -1;
}
current_audio_sample_rate = sample_rate;
return 0;
}
static void audio_update(void)
{
int frames_left = audio_get_frames_left();
if (frames_left <= 0) {
return;
}
#if defined(PLATFORM_TELLO)
static uint8_t last_frame = TELLO_AUDIO_NO_FRAME;
#endif
#if defined(PLATFORM_TELLO)
#define AUDIO_UPDATE_MAX_BYTES (TELLO_AUDIO_MAX_BYTES * sizeof(int16_t))
#elif defined(PLATFORM_BEBOP)
#define AUDIO_UPDATE_MAX_BYTES (BEBOP_AUDIO_MAX_BYTES * sizeof(int16_t))
#endif
#define AUDIO_UPDATE_MAX_FRAMES (AUDIO_UPDATE_MAX_BYTES / sizeof(int16_t))
#if defined(PLATFORM_TELLO) || defined(PLATFORM_BEBOP)
int frames_available = frames_left;
#else
int frames_available = min(frames_left, AUDIO_UPDATE_MAX_FRAMES);
#endif
#if defined(PLATFORM_TELLO)
uint8_t frame = last_frame + 1;
#else
#define DEFAULT_FRAME_NUMBER 0
#define frame DEFAULT_FRAME_NUMBER
#endif
#if defined(PLATFORM_TELLO) || defined(PLATFORM_BEBOP)
#if defined(PLATFORM_TELLO)
#define FRAME_COMMAND "a "
#elif defined(PLATFORM_BEBOP)
#define FRAME_COMMAND "as "
#endif
#define MAX_COMMAND_SIZE (1024 + sizeof(FRAME_COMMAND))
#define COMMAND_SIZE_BYTES (MAX_COMMAND_SIZE * sizeof(char))
#define COMMAND_BUFFER_SIZE ((COMMAND_SIZE_BYTES / sizeof(char)) +
((sizeof(uint32_t) + sizeof(uint8_t)) / sizeof(char)))
#endif
#if defined(PLATFORM_TELLO) || defined(PLATFORM_BEBOP)
#if defined(PLATFORM_TELLO)
#define AUDIO_LOAD_PREFIX "load_a "
#elif defined(PLATFORM_BEBOP)
#define AUDIO_LOAD_PREFIX "load_as "
#endif
#define MAX_LOAD_SIZE ((1024 * sizeof(char)) / sizeof(int16_t))
#endif
#if defined(PLATFORM_TELLO) || defined(PLATFORM_BEBOP)
#if defined(PLATFORM_TELLO)
#define AUDIO_FRAME_PREFIX "a "
#elif defined(PLATFORM_BEBOP)
#define AUDIO_FRAME_PREFIX "as "
#endif
#define MAX_FRAME_SIZE ((1024 * sizeof(char)) / sizeof(int16_t))
#endif
#if !defined(PLATFORM_FTDI)
static void send_command(const char* command,
const void* data,
size_t data_size,
size_t expected_response_size,
char** response,
size_t* response_size);
#endif
#if !defined(PLATFORM_FTDI)
static void send_command(const char* command,
const void* data,
size_t data_size,
size_t expected_response_size,
char** response,
size_t* response_size)
{
#if defined(SERIAL_DEBUG_PRINTS)
#define SERIAL_DEBUG_PREFIX "[serial] "
#define SERIAL_DEBUG_PRINT(...) do {
serial_debug_print(SERIAL_DEBUG_PREFIX);
serial_debug_print(__VA_ARGS__);
serial_debug_print("n");
serial_debug_flush();
log_print("debug", __VA_ARGS__);
log_print("debug", "n");
} while (0)
#else
#define SERIAL_DEBUG_PRINT(...)
#endif
#undef SERIAL_DEBUG_PRINT
#undef SERIAL_DEBUG_PREFIX
#undef COMMAND_BUFFER_SIZE
#undef MAX_COMMAND_SIZE
#undef COMMAND_SIZE_BYTES
#undef COMMAND_SIZE_WORDS
#undef RESPONSE_BUFFER_SIZE
#undef MAX_RESPONSE_SIZE
#undef RESPONSE_SIZE_WORDS
#undef RESPONSE_SIZE_BYTES
#ifdef PLATFORM_TELLO
#define RESPONSE_BUFFER_SIZE ((MAX_RESPONSE_SIZE + sizeof(uint32_t)) / sizeof(char))
#else
#define RESPONSE_BUFFER_SIZE MAX_RESPONSE_SIZE
#endif
#ifdef PLATFORM_TELLO
#define MAX_RESPONSE_SIZE ((2048 * sizeof(char)) / sizeof(uint32_t))
#else
#define MAX_RESPONSE_SIZE ((2048 * sizeof(char)) / sizeof(char))
#endif
#ifdef PLATFORM_TELLO
#define RESPONSE_SIZE_WORDS ((MAX_RESPONSE_SIZE + sizeof(uint32_t)) / sizeof(uint32_t))
#else
#define RESPONSE_SIZE_WORDS MAX_RESPONSE_SIZE
#endif
#ifdef PLATFORM_TELLO
#define RESPONSE_SIZE_BYTES ((MAX_RESPONSE_SIZE + sizeof(uint32_t)) * sizeof(uint32_t))
#else
#define RESPONSE_SIZE_BYTES (MAX_RESPONSE_SIZE * sizeof(char))
#endif
#ifndef PLATFORM_FTDI
#ifdef PLATFORM_TELLO
#undef MAX_COMMAND_SIZE
#undef COMMAND_BUFFER_SIZE
#undef COMMAND_SIZE_WORDS
#undef COMMAND_SIZE_BYTES
#ifdef PLATFORM_TELLO
#undef MAX_LOAD_SIZE
#ifdef PLATFORM_TELLO
#undef MAX_FRAME_SIZE
#ifdef PLATFORM_TELLO
#ifdef PLATFORM_TELLO
#ifdef PLATFORM_TELLO
#ifdef PLATFORM_TELLO
#ifdef PLATFORM_TELLO
#ifdef PLATFORM_TELLO
/* send_command */
/* serial_send_command */
/* Returns:
* -1: failed; command buffer overflowed or error writing to serial port.
* -2: failed; response buffer overflowed or error reading from serial port.
* >0: length of response.
*/
int serial_send_command(const char* command,
const void* data,
size_t data_size,
char** response,
size_t* response_size)
{
#ifndef CONFIG_SILENT_SERIAL_DEBUGGING
/* print_command */
/* serial_print_command */
/* Prints command and associated data in hex format.
* Returns:
* >0: number of bytes printed.
*/
static int serial_print_command(const char* command,
const void* data,
size_t data_size)
{
#ifndef CONFIG_SILENT_SERIAL_DEBUGGING
/* print_hex_byte */
/* serial_print_hex_byte */
/* Prints byte as two hex digits.
* Returns:
* >0: number of bytes printed.
*/
static int serial_print_hex_byte(uint8_t byte)
{
#ifndef CONFIG_SILENT_SERIAL_DEBUGGING
/* print_byte */
/* serial_print_byte */
/* Prints byte.
* Returns:
* >0: number of bytes printed.
*/
static int serial_print_byte(uint8_t byte)
{
#ifndef CONFIG_SILENT_SERIAL_DEBUGGING
/* print_hex_word */
/* serial_print_hex_word */
/* Prints word as four hex digits.
* Returns:
* >0: number of bytes printed.
*/
static int serial_print_hex_word(uint32_t word)
{
#ifndef CONFIG_SILENT_SERIAL_DEBUGGING
int num_bytes = snprintf(NULL /*out*/, /*buffer*/ NULL /*size*/, /*format*/ "%08x", word);
if (num_bytes <= 0) {
log_error("serial", "Failed printing word %u.", word);
return -1;
}
if (serial_write(&serial_interface /*interface*/, /*data*/ &word /*buffer*/, num_bytes /*size*/) != num_bytes) {
log_error("serial", "Failed writing word %u.", word);
return -1;
}
return num_bytes;
}
int num_bytes = snprintf(NULL /*out*/, /*buffer*/ NULL /*size*/, /*format*/ "%02x ", byte);
if (num_bytes <= 0) {
log_error("serial", "Failed printing byte %u.", byte);
return -1;
}
if (serial_write(&serial_interface /*interface*/, /*data*/ &byte /*buffer*/, num_bytes /*size*/) != num_bytes) {
log_error("serial", "Failed writing byte %u.", byte);
return -1;
}
return num_bytes;
}
int num_words = snprintf(NULL /*out*/, /*buffer*/ NULL /*size*/, /*format*/ "%un", data_size);
if (num_words <= 0) {
log_error("serial", "Failed printing data size %u.", data_size);
return -1;
}
if (serial_write(&serial_interface /*interface*/, /*data*/ &num_words /*buffer*/, num_words /*size*/) != num_words) {
log_error("serial", "Failed writing data size %u.", data_size);
return -1;
}
for (size_t i = 0; i != data_size; ++i) {
uint8_t byte = ((uint8_t*)data)[i];
if (serial_print_hex_byte(byte) <= 0) {
return -1;
}
}
return i;
}
int num_bytes = snprintf(NULL /*out*/, /*buffer*/ NULL /*size*/, /*format*/ "%sn", command);
if (num_bytes <= 0) {
log_error("serial", "Failed printing command '%s'.", command);
return -1;
}
if (serial_write(&serial_interface /*interface*/, /*data*/ &num_bytes /*buffer*/, num_bytes /*size*/) != num_bytes) {
log_error("serial", "Failed writing command '%s'.", command);
return -1;
}
return serial_print_command(command + strlen(command), data, data_size);
}
int max_data_words = (((data_size + sizeof(uint32_t)) / sizeof(uint32_t)) + RESPONSE_BUFFER_RESERVED_WORDS);
if (!(max_data_words >= RESPONSE_BUFFER_RESERVED_WORDS && max_data_words <= RESPONSE_BUFFER_RESERVED_WORDS + RESPONSE_BUFFER_WORDS)) {
log_error("serial", "Response buffer too small (%zu words).",
max_data_words);
return -1;
}
uint32_t* response_buffer =
malloc(sizeof(uint32_t) * max_data_words);
if (!response_buffer) {
log_error("serial", "Failed allocating memory for response.");
return -1;
}
memset(response_buffer, ' ', max_data_words);
uint8_t response_buffer_len[RESPONSE_BUFFER_RESERVED_WORDS] =
{RESPONSE_BUFFER_RESERVED_WORDS};
response_buffer -= RESPONSE_BUFFER_RESERVED_WORDS;
if (serial_write(&serial_interface /*interface*/,
&response_buffer_len[RESPONSE_BUFFER_RESERVED_WORDS] /*data*/,
RESPONSE_BUFFER_RESERVED_WORD_BYTES /*size*/) !=
RESPONSE_BUFFER_RESERVED_WORD_BYTES ||
!read_response(response_buffer)) {
free(response_buffer + RESPONSE_BUFFER_RESERVED_WORDS);
log_error("serial",
"Error reading response from device.");
return -2;
}
uint32_t len =
ntohl(response_buffer[RESPONSE_BUFFER_RESERVED_WORDS]);
if (!(len >= RESPONSE_BUFFER_RESERVED_WORDS && len <= max_data_words)) {
free(response_buffer + RESPONSE_BUFFER_RESERVED_WORDS);
log_error("serial",
"Invalid response length received from device (%u).",
len);
return -3;
}
uint32_t* resp =
malloc(sizeof(uint32_t) * len);
if (!resp) {
free(response_buffer + RESPONSE_BUFFER_RESERVED_WORDS);
log_error("serial",
"Failed allocating memory for response.");
return -4;
}
memcpy(resp,
&response_buffer[RESPONSE_BUFFER_RESERVED_WORDS],
len * sizeof(uint32_t));
free(response_buffer + RESPONSE_BUFFER_RESERVED_WORDS);
*size =
len *
sizeof(uint32_t);
*response =
malloc(*size);
if (!(*response)) {
free(resp);
log_error("serial",
"Failed allocating memory for response.");
return -5;
}
memcpy(*response,
resp,
*size);
free(resp);
return (*size);
}
int len =
snprintf(NULL /*out*/,
NULL /*buffer*/,
COMMAND_BUFFER /*
format*/
"%s" /*
prefix*/
"%s" /*
suffix*/
"%zu" /*
suffix*/
"n",
command /*
prefix*/
((data && data_size > 0)? /*
suffix*/
":"
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
""
"n"
":"
: "" /*
suffix*/
)
,
data /*
suffix*/
?
(
(((data && data_size > 0)? /*
prefix*/
":"
"") /*
prefix*/
"" /*
prefix*/
"" /*
prefix*/