From 48a56af4a7f1071cd45d4a8a02b5d018b1ed87f3 Mon Sep 17 00:00:00 2001 From: nicola02nb <61830443+nicola02nb@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:31:40 +0200 Subject: [PATCH 1/2] Added equalizer info for artico nova pro wireless, artic nova 3, artic nova 7 plus Fix a crash caused by get_float_data_from_parameter() function and added allocatioo and deallocation for equalizer bands_values Added Bands step for equalizer info; changed equlalizer preset values type; added equalizer info and refactor in steelseries_artic_nova_7.c Added equalizer and equalizer preset output json info --- .gitignore | 1 + src/device.h | 24 +++++- src/devices/headsetcontrol_test.c | 19 ++++- src/devices/steelseries_arctis_7_plus.c | 2 + src/devices/steelseries_arctis_nova_3.c | 2 + src/devices/steelseries_arctis_nova_7.c | 80 ++++++++++++++----- .../steelseries_arctis_nova_pro_wireless.c | 2 + src/main.c | 8 +- src/output.c | 33 ++++++++ src/output.h | 5 ++ src/utility.c | 11 ++- 11 files changed, 159 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 43a75c3..4af754c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ cmake-build-debug/ .vscode/* *.code-workspace +*.cache/ .DS_Store \ No newline at end of file diff --git a/src/device.h b/src/device.h index 422e607..71f6f60 100644 --- a/src/device.h +++ b/src/device.h @@ -90,6 +90,24 @@ typedef struct { enum microphone_status microphone_status; } BatteryInfo; +typedef struct { + int bands_count; + int bands_baseline; + float bands_step; + int bands_min; + int bands_max; +} EqualizerInfo; + +typedef struct { + char* name; + float* values; +} EqualizerPreset; + +typedef struct { + int count; + EqualizerPreset presets[]; +} EqualizerPresets; + enum headsetcontrol_errors { HSC_ERROR = -100, HSC_READ_TIMEOUT = -101, @@ -128,7 +146,7 @@ struct equalizer_settings { /// The size of the bands array int size; /// The equalizer frequency bands values - float bands_values[]; + float* bands_values; }; /** @brief Defines the basic data of a device @@ -148,6 +166,10 @@ struct device { /// Name of device, used as information for the user char device_name[64]; + // Equalizer Infos + EqualizerInfo* equalizer; + EqualizerPresets* eqaulizer_presets; + wchar_t device_hid_vendorname[64]; wchar_t device_hid_productname[64]; diff --git a/src/devices/headsetcontrol_test.c b/src/devices/headsetcontrol_test.c index 65a7a51..6c83bfe 100644 --- a/src/devices/headsetcontrol_test.c +++ b/src/devices/headsetcontrol_test.c @@ -9,7 +9,22 @@ static struct device device_headsetcontrol_test; #define TESTBYTES_SEND 32 -static const uint16_t PRODUCT_IDS[] = { PRODUCT_TESTDEVICE }; +#define EQUALIZER_BANDS_COUNT 10 +#define EQUALIZER_BASELINE 0 +#define EQUALIZER_STEP 0.5 +#define EQUALIZER_BAND_MIN -10 +#define EQUALIZER_BAND_MAX +10 +#define EQUALIZER_PRESETS_COUNT 2 + +static const uint16_t PRODUCT_IDS[] = { PRODUCT_TESTDEVICE }; +static EqualizerInfo EQUALIZER = { EQUALIZER_BANDS_COUNT, EQUALIZER_BASELINE, EQUALIZER_STEP, EQUALIZER_BAND_MIN, EQUALIZER_BAND_MAX }; +static float preset_flat[EQUALIZER_BANDS_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +static float preset_random[EQUALIZER_BANDS_COUNT] = { 6, -8, 1.5, 7, -1, -7.5, -9, 0, 9, 10 }; +static EqualizerPresets EQUALIZER_PRESETS = { + EQUALIZER_PRESETS_COUNT, + { { "flat", preset_flat }, + { "random", preset_random } } +}; static int headsetcontrol_test_send_sidetone(hid_device* device_handle, uint8_t num); static BatteryInfo headsetcontrol_test_request_battery(hid_device* device_handle); @@ -39,6 +54,8 @@ void headsetcontrol_test_init(struct device** device) device_headsetcontrol_test.idVendor = VENDOR_TESTDEVICE; device_headsetcontrol_test.idProductsSupported = PRODUCT_IDS; device_headsetcontrol_test.numIdProducts = 1; + device_headsetcontrol_test.equalizer = &EQUALIZER; + device_headsetcontrol_test.eqaulizer_presets = &EQUALIZER_PRESETS; strncpy(device_headsetcontrol_test.device_name, "HeadsetControl Test device", sizeof(device_headsetcontrol_test.device_name)); // normally filled by hid in main.c diff --git a/src/devices/steelseries_arctis_7_plus.c b/src/devices/steelseries_arctis_7_plus.c index 4e95cbd..432a1cd 100644 --- a/src/devices/steelseries_arctis_7_plus.c +++ b/src/devices/steelseries_arctis_7_plus.c @@ -27,6 +27,7 @@ static struct device device_arctis; #define EQUALIZER_BAND_MAX +12 static const uint16_t PRODUCT_IDS[] = { ID_ARCTIS_7_PLUS, ID_ARCTIS_7_PLUS_PS5, ID_ARCTIS_7_PLUS_XBOX, ID_ARCTIS_7_PLUS_DESTINY }; +static EqualizerInfo EQUALIZER = { EQUALIZER_BANDS_SIZE, 0, 0.5, EQUALIZER_BAND_MIN, EQUALIZER_BAND_MAX }; static int arctis_7_plus_send_sidetone(hid_device* device_handle, uint8_t num); static int arctis_7_plus_send_inactive_time(hid_device* device_handle, uint8_t num); @@ -42,6 +43,7 @@ void arctis_7_plus_init(struct device** device) device_arctis.idVendor = VENDOR_STEELSERIES; device_arctis.idProductsSupported = PRODUCT_IDS; device_arctis.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]); + device_arctis.equalizer = &EQUALIZER; strncpy(device_arctis.device_name, "SteelSeries Arctis 7+", sizeof(device_arctis.device_name)); diff --git a/src/devices/steelseries_arctis_nova_3.c b/src/devices/steelseries_arctis_nova_3.c index 628dd6c..f33df7e 100644 --- a/src/devices/steelseries_arctis_nova_3.c +++ b/src/devices/steelseries_arctis_nova_3.c @@ -17,6 +17,7 @@ static struct device device_arctis; static const uint16_t PRODUCT_IDS[] = { ID_ARCTIS_NOVA_3 }; static const uint8_t SAVE_DATA[MSG_SIZE] = { 0x06, 0x09 }; // Command to save settings to headset +static EqualizerInfo EQUALIZER = { EQUALIZER_BANDS_SIZE, 0, 0.5, EQUALIZER_BAND_MIN, EQUALIZER_BAND_MAX }; static int arctis_nova_3_send_sidetone(hid_device* device_handle, uint8_t num); static int arctis_nova_3_send_equalizer_preset(hid_device* device_handle, uint8_t num); @@ -29,6 +30,7 @@ void arctis_nova_3_init(struct device** device) device_arctis.idVendor = VENDOR_STEELSERIES; device_arctis.idProductsSupported = PRODUCT_IDS; device_arctis.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]); + device_arctis.equalizer = &EQUALIZER; strncpy(device_arctis.device_name, "SteelSeries Arctis Nova 3", sizeof(device_arctis.device_name)); diff --git a/src/devices/steelseries_arctis_nova_7.c b/src/devices/steelseries_arctis_nova_7.c index 70293e8..93d32de 100644 --- a/src/devices/steelseries_arctis_nova_7.c +++ b/src/devices/steelseries_arctis_nova_7.c @@ -22,12 +22,29 @@ static struct device device_arctis; #define HEADSET_OFFLINE 0x00 #define STATUS_BUF_SIZE 8 -#define EQUALIZER_BANDS_SIZE 10 -#define EQUALIZER_BASELINE 0x14 -#define EQUALIZER_BAND_MIN -10 -#define EQUALIZER_BAND_MAX +10 - -static const uint16_t PRODUCT_IDS[] = { ID_ARCTIS_NOVA_7, ID_ARCTIS_NOVA_7x, ID_ARCTIS_NOVA_7x_v2, ID_ARCTIS_NOVA_7p, ID_ARCTIS_NOVA_7_DIABLO_IV }; +#define EQUALIZER_BANDS_COUNT 10 +#define EQUALIZER_BASELINE 0 +#define EQUALIZER_STEP 0.5 +#define EQUALIZER_BAND_MIN -10 +#define EQUALIZER_BAND_MAX +10 +#define EQUALIZER_PRESETS_COUNT 4 + +static const uint16_t PRODUCT_IDS[] = { ID_ARCTIS_NOVA_7, ID_ARCTIS_NOVA_7x, ID_ARCTIS_NOVA_7x_v2, ID_ARCTIS_NOVA_7p, ID_ARCTIS_NOVA_7_DIABLO_IV }; +static const uint8_t SAVE_DATA[MSG_SIZE] = { 0x06, 0x09 }; + +float flat[EQUALIZER_BANDS_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; +float bass[EQUALIZER_BANDS_COUNT] = { 3.5, 5.5, 4, 1, -1.5, -1.5, -1, -1, -1, -1 }; +float focus[EQUALIZER_BANDS_COUNT] = { -5, -3.5, -1, -3.5, -2.5, 4, 6, -3.5, 0 }; +float smiley[EQUALIZER_BANDS_COUNT] = { 3, 3.5, 1.5, -1.5, -4, -4, -2.5, 1.5, 3, 4 }; + +static EqualizerInfo EQUALIZER = { EQUALIZER_BANDS_COUNT, EQUALIZER_BASELINE, EQUALIZER_STEP, EQUALIZER_BAND_MIN, EQUALIZER_BAND_MAX }; +static EqualizerPresets EQUALIZER_PRESETS = { + EQUALIZER_PRESETS_COUNT, + { { "flat", flat }, + { "bass", bass }, + { "focus", focus }, + { "smiley", smiley } } +}; static int arctis_nova_7_send_sidetone(hid_device* device_handle, uint8_t num); static int arctis_nova_7_send_inactive_time(hid_device* device_handle, uint8_t num); @@ -48,6 +65,8 @@ void arctis_nova_7_init(struct device** device) device_arctis.idVendor = VENDOR_STEELSERIES; device_arctis.idProductsSupported = PRODUCT_IDS; device_arctis.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]); + device_arctis.equalizer = &EQUALIZER; + device_arctis.eqaulizer_presets = &EQUALIZER_PRESETS; strncpy(device_arctis.device_name, "SteelSeries Arctis Nova 7", sizeof(device_arctis.device_name)); @@ -142,10 +161,16 @@ static BatteryInfo arctis_nova_7_request_battery(hid_device* device_handle) int bat = data_read[2]; - if (bat > BATTERY_MAX) + if (bat >= BATTERY_MAX) info.level = 100; + else if (bat == 0x3) + info.level = 50; + else if (bat == 0x2) + info.level = 15; + else if (bat == 0x1) + info.level = 5; else - info.level = map(bat, BATTERY_MIN, BATTERY_MAX, 0, 100); + info.level = 0; return info; } @@ -184,35 +209,47 @@ static int arctis_nova_7_send_equalizer_preset(hid_device* device_handle, uint8_ { // This headset supports only 4 presets: // flat (default), bass boost, smiley, focus + struct equalizer_settings preset; + preset.size = EQUALIZER_BANDS_COUNT; switch (num) { case 0: { - uint8_t flat[MSG_SIZE] = { 0x0, 0x33, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x0 }; - return hid_write(device_handle, flat, MSG_SIZE); + preset.bands_values = flat; + break; + // uint8_t flat[MSG_SIZE] = { 0x0, 0x33, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x0 }; + // return hid_write(device_handle, flat, MSG_SIZE); } case 1: { - uint8_t bass[MSG_SIZE] = { 0x0, 0x33, 0x1b, 0x1f, 0x1c, 0x16, 0x11, 0x11, 0x12, 0x12, 0x12, 0x12, 0x0 }; - return hid_write(device_handle, bass, MSG_SIZE); + preset.bands_values = bass; + break; + // uint8_t bass[MSG_SIZE] = { 0x0, 0x33, 0x1b, 0x1f, 0x1c, 0x16, 0x11, 0x11, 0x12, 0x12, 0x12, 0x12, 0x0 }; + // return hid_write(device_handle, bass, MSG_SIZE); } case 2: { - uint8_t smiley[MSG_SIZE] = { 0x0, 0x33, 0x0a, 0x0d, 0x12, 0x0d, 0x0f, 0x1c, 0x20, 0x1b, 0x0d, 0x14, 0x0 }; - return hid_write(device_handle, smiley, MSG_SIZE); + preset.bands_values = focus; + break; + // uint8_t focus[MSG_SIZE] = { 0x0, 0x33, 0x1a, 0x1b, 0x17, 0x11, 0x0c, 0x0c, 0x0f, 0x17, 0x1a, 0x1c, 0x0 }; + // return hid_write(device_handle, focus, MSG_SIZE); } case 3: { - uint8_t focus[MSG_SIZE] = { 0x0, 0x33, 0x1a, 0x1b, 0x17, 0x11, 0x0c, 0x0c, 0x0f, 0x17, 0x1a, 0x1c, 0x0 }; - return hid_write(device_handle, focus, MSG_SIZE); + preset.bands_values = smiley; + break; + // uint8_t smiley[MSG_SIZE] = { 0x0, 0x33, 0x0a, 0x0d, 0x12, 0x0d, 0x0f, 0x1c, 0x20, 0x1b, 0x0d, 0x14, 0x0 }; + // return hid_write(device_handle, smiley, MSG_SIZE); } default: { printf("Device only supports 0-3 range for presets.\n"); return HSC_OUT_OF_BOUNDS; } } + + return arctis_nova_7_send_equalizer(device_handle, &preset); } static int arctis_nova_7_send_equalizer(hid_device* device_handle, struct equalizer_settings* settings) { - if (settings->size != EQUALIZER_BANDS_SIZE) { - printf("Device only supports %d bands.\n", EQUALIZER_BANDS_SIZE); + if (settings->size != EQUALIZER_BANDS_COUNT) { + printf("Device only supports %d bands.\n", EQUALIZER_BANDS_COUNT); return HSC_OUT_OF_BOUNDS; } @@ -224,7 +261,7 @@ static int arctis_nova_7_send_equalizer(hid_device* device_handle, struct equali return HSC_OUT_OF_BOUNDS; } - data[i + 2] = (uint8_t)(EQUALIZER_BASELINE + band_value); + data[i + 2] = (uint8_t)(0x14 + band_value); } data[settings->size + 3] = 0x0; @@ -244,10 +281,9 @@ int arctis_nova_7_read_device_status(hid_device* device_handle, unsigned char* d static int arctis_nova_7_bluetooth_when_powered_on(hid_device* device_handle, uint8_t num) { - unsigned char data[MSG_SIZE] = { 0x00, 0xb2, num }; - unsigned char data2[MSG_SIZE] = { 0x00, 0x09, 0 }; + unsigned char data[MSG_SIZE] = { 0x00, 0xb2, num }; if (hid_write(device_handle, data, MSG_SIZE) >= 0) { - return hid_write(device_handle, data2, MSG_SIZE); + return hid_write(device_handle, SAVE_DATA, MSG_SIZE); } return HSC_READ_TIMEOUT; } diff --git a/src/devices/steelseries_arctis_nova_pro_wireless.c b/src/devices/steelseries_arctis_nova_pro_wireless.c index e158881..4e44533 100644 --- a/src/devices/steelseries_arctis_nova_pro_wireless.c +++ b/src/devices/steelseries_arctis_nova_pro_wireless.c @@ -48,6 +48,7 @@ enum { }; static const uint16_t PRODUCT_IDS[] = { ID_ARCTIS_NOVA_PRO_WIRELESS_BASE_STATION }; +static EqualizerInfo EQUALIZER = { EQUALIZER_BANDS_SIZE, 0, 0.5, EQUALIZER_BAND_MIN, EQUALIZER_BAND_MAX }; static int set_sidetone(hid_device* device_handle, uint8_t num); static BatteryInfo get_battery(hid_device* device_handle); @@ -64,6 +65,7 @@ void arctis_nova_pro_wireless_init(struct device** device) device_arctis.idVendor = VENDOR_STEELSERIES; device_arctis.idProductsSupported = PRODUCT_IDS; device_arctis.numIdProducts = sizeof(PRODUCT_IDS) / sizeof(PRODUCT_IDS[0]); + device_arctis.equalizer = &EQUALIZER; strncpy(device_arctis.device_name, "SteelSeries Arctis Nova Pro Wireless", sizeof(device_arctis.device_name)); diff --git a/src/main.c b/src/main.c index 68e7b98..78ce798 100644 --- a/src/main.c +++ b/src/main.c @@ -605,8 +605,9 @@ int main(int argc, char* argv[]) return 1; } - equalizer = malloc(sizeof(struct equalizer_settings) + size * sizeof(float)); - equalizer->size = size; + equalizer = malloc(sizeof(struct equalizer_settings)); + equalizer->size = size; + equalizer->bands_values = malloc(sizeof(float) * size); for (int i = 0; i < size; i++) { equalizer->bands_values[i] = read_buffer[i]; } @@ -950,6 +951,9 @@ int main(int argc, char* argv[]) free(featureRequests[i].result.message); } + if (equalizer != NULL) { + free(equalizer->bands_values); + } free(equalizer); terminate_hid(&device_handle, &hid_path); diff --git a/src/output.c b/src/output.c index d061c0b..38e585c 100644 --- a/src/output.c +++ b/src/output.c @@ -167,6 +167,11 @@ void initializeHeadsetInfo(HeadsetInfo* info, struct device* device) info->vendor_name = device->device_hid_vendorname; info->product_name = device->device_hid_productname; + info->equalizer = device->equalizer; + info->equalizer_presets = device->eqaulizer_presets, + info->has_equalizer_info = info->equalizer != NULL; + info->has_equalizer_presets_info = info->equalizer_presets != NULL; + info->capabilities_amount = 0; for (int i = 0; i < NUM_CAPABILITIES; i++) { @@ -378,6 +383,34 @@ void output_json(HeadsetControlStatus* status, HeadsetInfo* infos) printf(" }"); } + if (info->has_equalizer_info) { + printf(",\n \"equalizer\": {\n"); + printf(" \"bands\": %d,\n", info->equalizer->bands_count); + printf(" \"baseline\": %d,\n", info->equalizer->bands_baseline); + printf(" \"step\": %.1f,\n", info->equalizer->bands_step); + printf(" \"min\": %d,\n", info->equalizer->bands_min); + printf(" \"max\": %d\n", info->equalizer->bands_max); + printf(" }"); + + if (info->has_equalizer_presets_info) { + printf(",\n \"equalizer_presets_count\": %d", info->equalizer_presets->count); + printf(",\n \"equalizer_presets\": {\n"); + for (int i = 0; i < info->equalizer_presets->count; i++) { + EqualizerPreset* presets = info->equalizer_presets->presets; + printf(" \"%s\": [ ", presets[i].name); + for (int j = 0; j < info->equalizer->bands_count; j++) { + printf("%.1f", presets[i].values[j]); + if (j < info->equalizer->bands_count - 1) + printf(", "); + } + printf(" ]"); + if (i < info->equalizer_presets->count - 1) + printf(",\n"); + } + printf("\n }"); + } + } + if (info->has_chatmix_info) { printf(",\n \"chatmix\": %d", info->chatmix); } diff --git a/src/output.h b/src/output.h index a866af7..d2efd96 100644 --- a/src/output.h +++ b/src/output.h @@ -73,6 +73,11 @@ typedef struct { bool has_chatmix_info; int chatmix; + bool has_equalizer_info; + EqualizerInfo* equalizer; + bool has_equalizer_presets_info; + EqualizerPresets* equalizer_presets; + Action actions[MAX_ACTIONS]; int action_count; diff --git a/src/utility.c b/src/utility.c index 224e37d..441872b 100644 --- a/src/utility.c +++ b/src/utility.c @@ -106,8 +106,15 @@ int get_float_data_from_parameter(char* input, float* dest, size_t len) { const char* delim = " ,{}\n\r"; - // For each token in the string, parse and store in buf[]. - char* token = strtok(input, delim); + // Make a copy of the input string to avoid modifying the original + char* input_copy = strdup(input); + if (input_copy == NULL) { + // Memory allocation failed + return -1; + } + + // For each token in the string, parse and store in dest[]. + char* token = strtok(input_copy, delim); int i = 0; while (token) { char* endptr; From 8d16f38585a17938b967025c2d05554f52dcc9b6 Mon Sep 17 00:00:00 2001 From: Denis Arnst Date: Mon, 22 Jul 2024 15:32:32 +0200 Subject: [PATCH 2/2] Increase api version utility: Make get_byte_data behave the same way Add equalizer info also as JSON --- src/output.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++----- src/utility.c | 7 ++++++ 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/output.c b/src/output.c index 38e585c..a0419c1 100644 --- a/src/output.c +++ b/src/output.c @@ -9,7 +9,7 @@ #include #include -const char* APIVERSION = "1.1"; +const char* APIVERSION = "1.2"; const char* HEADSETCONTROL_NAME = "HeadsetControl"; // Function to convert enum to string @@ -485,12 +485,38 @@ const char* yaml_replace_spaces_with_dash(const char* str) return result; } -void yaml_print_listitem(const char* value, int indent) +void yaml_print_listitem(const char* value, int indent, bool newline) { - for (int i = 0; i < indent; i++) { + if (newline) { + for (int i = 0; i < indent; i++) { + putchar(' '); + } + } + + printf("- %s", value); + + if (newline) { + putchar('\n'); + } else { + putchar(' '); + } +} + +void yaml_print_listitemfloat(const float value, int indent, bool newline) +{ + if (newline) { + for (int i = 0; i < indent; i++) { + putchar(' '); + } + } + + printf("- %.1f", value); + + if (newline) { + putchar('\n'); + } else { putchar(' '); } - printf("- %s\n", value); } void output_yaml(HeadsetControlStatus* status, HeadsetInfo* infos) @@ -532,12 +558,12 @@ void output_yaml(HeadsetControlStatus* status, HeadsetInfo* infos) yaml_print("capabilities", "", 4); for (int j = 0; j < info->capabilities_amount; j++) { - yaml_print_listitem(info->capabilities[j], 6); + yaml_print_listitem(info->capabilities[j], 6, true); } yaml_print("capabilities_str", "", 4); for (int j = 0; j < info->capabilities_amount; j++) { - yaml_print_listitem(info->capabilities_str[j], 6); + yaml_print_listitem(info->capabilities_str[j], 6, true); } if (info->has_battery_info) { @@ -546,6 +572,34 @@ void output_yaml(HeadsetControlStatus* status, HeadsetInfo* infos) yaml_printint("level", info->battery_level, 6); } + if (info->has_equalizer_info) { + yaml_print("equalizer", "", 4); + yaml_printint("bands", info->equalizer->bands_count, 6); + yaml_printint("baseline", info->equalizer->bands_baseline, 6); + yaml_printint("step", info->equalizer->bands_step, 6); + yaml_printint("min", info->equalizer->bands_min, 6); + yaml_printint("max", info->equalizer->bands_max, 6); + + if (info->has_equalizer_presets_info) { + yaml_printint("equalizer_presets_count", info->equalizer_presets->count, 4); + yaml_print("equalizer_presets", "", 4); + for (int i = 0; i < info->equalizer_presets->count; i++) { + EqualizerPreset* presets = info->equalizer_presets->presets; + + yaml_print_listitem(presets[i].name, 6, true); + + // Spaces for the list + for (int i = 0; i < 8; i++) { + putchar(' '); + } + for (int j = 0; j < info->equalizer->bands_count; j++) { + yaml_print_listitemfloat(presets[i].values[j], 8, false); + } + putchar('\n'); + } + } + } + if (info->has_chatmix_info) { yaml_printint("chatmix", info->chatmix, 4); } diff --git a/src/utility.c b/src/utility.c index 441872b..b618563 100644 --- a/src/utility.c +++ b/src/utility.c @@ -85,6 +85,13 @@ int get_byte_data_from_parameter(char* input, unsigned char* dest, size_t len) { const char* delim = " ,{}\n\r"; + // Make a copy of the input string to avoid modifying the original + char* input_copy = strdup(input); + if (input_copy == NULL) { + // Memory allocation failed + return -1; + } + // For each token in the string, parse and store in buf[]. char* token = strtok(input, delim); int i = 0;