sm8350-common: vibratoreffect: Read vibration effects fifo data from vendor
Change-Id: I58c74f01d75e8616fdb03c27e3dc4c4df6838faa
This commit is contained in:
parent
b9612a44d0
commit
5ae87ffe5c
@ -8,6 +8,7 @@ cc_library_shared {
|
||||
srcs: ["effect.cpp"],
|
||||
shared_libs: [
|
||||
"libcutils",
|
||||
"liblog",
|
||||
"libutils",
|
||||
],
|
||||
export_include_dirs: ["."]
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2020, The Linux Foundation. All rights reserved.
|
||||
* Copyright (C) 2022 The LineageOS Project
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
@ -27,51 +28,111 @@
|
||||
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define LOG_TAG "libxiaomivibratoreffect"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <log/log.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "effect.h"
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a)))
|
||||
|
||||
/* ~170 HZ sine waveform */
|
||||
static const int8_t effect_0[] = {
|
||||
17, 34, 50, 65, 79, 92, 103, 112, 119, 124,
|
||||
127, 127, 126, 122, 116, 108, 98, 86, 73, 58,
|
||||
42, 26, 9, -8, -25, -41, -57, -72, -85, -97,
|
||||
-108, -116, -122, -126, -127, -127, -125, -120,
|
||||
-113, -104, -93, -80, -66, -51, -35, -18, -1,
|
||||
};
|
||||
|
||||
static const int8_t effect_1[] = {
|
||||
-1, -18, -35, -51, -66, -80, -93, -104, -113,
|
||||
-120, -125, -127, -127, -126, -122, -116, -108,
|
||||
-97, -85, -72, -57, -41, -25, -8, 9, 26, 42,
|
||||
58, 73, 86, 98, 108, 116, 122, 126, 127, 127,
|
||||
124, 119, 112, 103, 92, 79, 65, 50, 34, 17,
|
||||
};
|
||||
|
||||
static const struct effect_stream effects[] = {
|
||||
static struct effect_stream effects[] = {
|
||||
{
|
||||
.effect_id = 0,
|
||||
.data = effect_0,
|
||||
.length = ARRAY_SIZE(effect_0),
|
||||
.play_rate_hz = 8000,
|
||||
.data = 0,
|
||||
.length = 0,
|
||||
.play_rate_hz = 24000,
|
||||
},
|
||||
|
||||
{
|
||||
.effect_id = 1,
|
||||
.data = effect_1,
|
||||
.length = ARRAY_SIZE(effect_1),
|
||||
.play_rate_hz = 8000,
|
||||
.data = 0,
|
||||
.length = 0,
|
||||
.play_rate_hz = 24000,
|
||||
},
|
||||
{
|
||||
.effect_id = 2,
|
||||
.data = 0,
|
||||
.length = 0,
|
||||
.play_rate_hz = 24000,
|
||||
},
|
||||
{
|
||||
.effect_id = 3,
|
||||
.data = 0,
|
||||
.length = 0,
|
||||
.play_rate_hz = 24000,
|
||||
},
|
||||
{
|
||||
.effect_id = 4,
|
||||
.data = 0,
|
||||
.length = 0,
|
||||
.play_rate_hz = 24000,
|
||||
},
|
||||
{
|
||||
.effect_id = 5,
|
||||
.data = 0,
|
||||
.length = 0,
|
||||
.play_rate_hz = 24000,
|
||||
},
|
||||
};
|
||||
|
||||
// Array containing the paths to fifo data in vendor.
|
||||
// The position in the array must match the effect id.
|
||||
static const std::string fifo_data_paths[] = {
|
||||
"/vendor/firmware/seq_bin_wav1.bin",
|
||||
"/vendor/firmware/seq_bin_wav2.bin",
|
||||
"/vendor/firmware/seq_bin_wav3.bin",
|
||||
"/vendor/firmware/seq_bin_wav4.bin",
|
||||
"/vendor/firmware/seq_bin_wav5.bin",
|
||||
"/vendor/firmware/seq_bin_wav6.bin",
|
||||
};
|
||||
|
||||
// Function to parse custom fifo data from vendor
|
||||
int parse_custom_data(effect_stream *effect) {
|
||||
const char *path = fifo_data_paths[effect->effect_id].c_str();
|
||||
std::ifstream data;
|
||||
struct stat file_stat;
|
||||
int rc = 0;
|
||||
|
||||
ALOGI("Parsing custom fifo data for effect %d from path %s",
|
||||
effect->effect_id, path);
|
||||
|
||||
rc = stat(path, &file_stat);
|
||||
if (!rc) {
|
||||
effect->length = file_stat.st_size;
|
||||
} else {
|
||||
ALOGE("Could not open %s", path);
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Create a persistent 8-bit int array which contains the fifo data, one
|
||||
// slot of the array contains one byte of the fifo data from vendor.
|
||||
int8_t *custom_data = new int8_t[effect->length];
|
||||
|
||||
data.open(path, std::ios::in | std::ios::binary);
|
||||
data.read(reinterpret_cast<char *>(custom_data), effect->length);
|
||||
data.close();
|
||||
|
||||
effect->data = custom_data;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
const struct effect_stream *get_effect_stream(uint32_t effect_id)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(effects); i++) {
|
||||
if (effect_id == effects[i].effect_id)
|
||||
if (effect_id == effects[i].effect_id) {
|
||||
if (effects[i].length == 0 && parse_custom_data(&effects[i])) {
|
||||
ALOGE("Could not get custom_data for effect %d", effects[i].effect_id);
|
||||
return NULL;
|
||||
}
|
||||
return &effects[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user