Fixed compiler warnings and added wrapping for ndx

This commit is contained in:
Casey 2024-02-25 13:30:34 +03:00
parent df23dfb874
commit 30266e702b
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
2 changed files with 17 additions and 11 deletions

View File

@ -31,7 +31,7 @@ int main(int argc, char **argv) {
printf("send: '%s'\n", buffer);
EXPECT(sendto(sock_fd, buffer, strlen(buffer), 0, (struct sockaddr *)&sa_server, sizeof(sa_server)), == strlen(buffer));
EXPECT(sendto(sock_fd, buffer, strlen(buffer), 0, (struct sockaddr *)&sa_server, sizeof(sa_server)), == (ssize_t)strlen(buffer));
int data_len;
while ((data_len = recv(sock_fd, buffer, BUFFER_SIZE, 0)) > 0) {
printf("%.*s", data_len, buffer);

View File

@ -46,7 +46,7 @@ struct sfx_pool {
int cap, use;
};
ssize_t send_data(struct msg_target tgt, const void *data, size_t len);
ssize_t send_data(struct msg_target tgt, const void *data, ssize_t len);
ssize_t send_txt(struct msg_target tgt, const char *fmt, ...);
void execute_command(struct msg_target tgt, const char *command, const char *params);
bool execute_file(struct msg_target tgt, const char *path, int depth);
@ -77,6 +77,8 @@ struct global_counters {
void usage(int argc, char **argv) {
// TODO
(void)argc;
(void)argv;
}
int main(int argc, char **argv) {
@ -131,16 +133,16 @@ void ipc_loop(void) {
socklen_t sl_client = sizeof(ipc.sa_client);
while ((data_len = recvfrom(ipc.sock_fd, buffer_ipc_loop, sizeof(buffer_ipc_loop) - 1, 0, (struct sockaddr *)&ipc.sa_client, &sl_client)) != -1) {
buffer_ipc_loop[data_len] = '\0';
struct sockaddr_un *sau_client = &ipc.sa_client;
struct sockaddr *sa_client = (struct sockaddr *)&ipc.sa_client;
char *command = buffer_ipc_loop;
char *params = strchr(command, ' ');
if (params != NULL) {
*params = '\0';
params++;
}
execute_command((struct msg_target) { 0, ipc.sock_fd, (struct sockaddr *)&ipc.sa_client, sl_client }, command, params);
SOFT_EXPECT(sendto(ipc.sock_fd, "OK\n", 4, 0, (struct sockaddr *)&ipc.sa_client, sl_client), == 4,);
SOFT_EXPECT(sendto(ipc.sock_fd, "", 0, 0, (struct sockaddr *)&ipc.sa_client, sl_client), == 0,);
execute_command((struct msg_target) { 0, ipc.sock_fd, sa_client, sl_client }, command, params);
SOFT_EXPECT(sendto(ipc.sock_fd, "OK\n", 4, 0, sa_client, sl_client), == 4,);
SOFT_EXPECT(sendto(ipc.sock_fd, "", 0, 0, sa_client, sl_client), == 0,);
sl_client = sizeof(ipc.sa_client);
}
}
@ -151,7 +153,7 @@ bool audio_init(void) {
return true;
}
ssize_t send_data(struct msg_target tgt, const void *data, size_t len) {
ssize_t send_data(struct msg_target tgt, const void *data, ssize_t len) {
ssize_t written;
if (tgt.file_handle) {
if ((written = fwrite(data, 1, len, tgt.file_handle)) != len) {
@ -208,7 +210,9 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
return;
}
ma_sound *sfx = &sound->sounds[(sound->last_index++) % MAX_SOUNDS_PER_KEY];
sound->last_index = (sound->last_index + 1) % MAX_SOUNDS_PER_KEY;
ma_sound *sfx = &sound->sounds[sound->last_index];
ma_sound_set_pitch(sfx, sound->pitch_min);
ma_sound_set_volume(sfx, sound->volume);
ma_sound_start(sfx);
@ -219,7 +223,9 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
return;
}
ma_sound *sfx = &sound->sounds[(sound->last_index++) % MAX_SOUNDS_PER_KEY];
sound->last_index = (sound->last_index + 1) % MAX_SOUNDS_PER_KEY;
ma_sound *sfx = &sound->sounds[sound->last_index];
float pitch = sound->pitch_min + (rand() / (float)RAND_MAX) * (sound->pitch_max - sound->pitch_min);
ma_sound_set_pitch(sfx, pitch);
ma_sound_set_volume(sfx, sound->volume);
@ -272,8 +278,8 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
if (item.key[0] == '\0') {
send_txt(tgt, "%3d (unused)\n", i);
} else {
send_txt(tgt, "%3d vol=%7.5f pitch=%7.5f..%7.5f @%2d (0x%08x) \"%s\"\n",
i, item.volume, item.pitch_min, item.pitch_max, item.last_index, adler32(item.key, strlen(item.key)), item.key);
send_txt(tgt, "%3d vol=%7.5f pitch=%7.5f..%7.5f (0x%08x) \"%s\" from %s\n",
i, item.volume, item.pitch_min, item.pitch_max, adler32(item.key, strlen(item.key)), item.key, item.path);
}
}
} else if (0 == strcmp(command, "source")) {