Compare commits
No commits in common. "c080e62637489139ed20d9781c231b691189dad5" and "30266e702bdac6aca2c101e549d2b1bbce667e5a" have entirely different histories.
c080e62637
...
30266e702b
83
sfxd.5
83
sfxd.5
|
@ -1,83 +0,0 @@
|
||||||
.\" Generated by scdoc 1.11.3
|
|
||||||
.\" Complete documentation for this program is not available as a GNU info page
|
|
||||||
.ie \n(.g .ds Aq \(aq
|
|
||||||
.el .ds Aq '
|
|
||||||
.nh
|
|
||||||
.ad l
|
|
||||||
.\" Begin generated content:
|
|
||||||
.TH "sfxd" "5" "2024-02-25"
|
|
||||||
.PP
|
|
||||||
.SH NAME
|
|
||||||
.PP
|
|
||||||
sfxd - configuration file and client commands list
|
|
||||||
.PP
|
|
||||||
.SH DESCRIPTION
|
|
||||||
.PP
|
|
||||||
Both configuration file and sfxc(1) commands use the same set of instructions.\&
|
|
||||||
.PP
|
|
||||||
Configuration file is \fBnot\fR loaded automatically, unless specified with `-C [path]` flag, but it can be loaded at a run-time via \fBsource\fR command.\&
|
|
||||||
.PP
|
|
||||||
.SH COMMANDS LIST
|
|
||||||
.PP
|
|
||||||
\fBload NAME FILE\fR Loads specified sound file and stores it under given key.\&
|
|
||||||
.br
|
|
||||||
When given key is already in use, it SHOULD be replaced with the new sound file.\&
|
|
||||||
.br
|
|
||||||
\fB\fRNAME\fB\fR is a string with no spaces, does not support escaping and used as a primary key for accessing loaded sound later.\&
|
|
||||||
.br
|
|
||||||
\fB\fRFILE\fB\fR is an absolute path to a sound file to be loaded.\& Only WAV and MP3 files are supported.\&
|
|
||||||
.PP
|
|
||||||
\fBplay NAME\fR Plays the sound with default pitch and volume.\&
|
|
||||||
.br
|
|
||||||
\fB\fRNAME\fB\fR is a key, used when \fBload\fRing a file.\&
|
|
||||||
.PP
|
|
||||||
\fBplay:rs NAME\fR Plays the sound with randomized pitch.\&
|
|
||||||
.br
|
|
||||||
Pitch range is specified with \fBset:pitch\fR command.\&
|
|
||||||
.br
|
|
||||||
\fB\fRNAME\fB\fR is a key, used when \fBload\fRing a file.\&
|
|
||||||
.PP
|
|
||||||
\fBset:pitch NAME MIN MAX\fR Sets the pitch range for \fBplay:rs\fR
|
|
||||||
.br
|
|
||||||
\fB\fRNAME\fB\fR is a key, used when \fBload\fRing a file.\&
|
|
||||||
.br
|
|
||||||
\fB\fRMIN\fB\fR is the minimum pitch.\& Can'\&t be less than 0.\&
|
|
||||||
.br
|
|
||||||
\fB\fRMAX\fB\fR is the maximum pitch.\& Can'\&t be less than 0.\&
|
|
||||||
.br
|
|
||||||
NOTE: if MAX is smaller than MIN, they are swapped.\&
|
|
||||||
.PP
|
|
||||||
\fBset:volume NAME VOLUME\fR Changes loudness for \fBplay\fR and \fBplay:rs\fR commands.\&
|
|
||||||
.br
|
|
||||||
\fB\fRNAME\fB\fR is a key, used when \fBload\fRing a file.\&
|
|
||||||
.br
|
|
||||||
\fB\fRVOLUME\fB\fR is the volume to be set.\& Can'\&t be outside of 0.\&.\&1 range
|
|
||||||
.PP
|
|
||||||
\fBsource PATH\fR Loads instructions from the configuration file.\&
|
|
||||||
.br
|
|
||||||
\fB\fRPATH\fB\fR is the file path for the configuration file.\&
|
|
||||||
.br
|
|
||||||
NOTE: there is a limit on how deep inclusion can go.\& By default it'\&s set to 32.\&
|
|
||||||
.PP
|
|
||||||
.SH DEBUG COMMANDS
|
|
||||||
.PP
|
|
||||||
\fBdbg:dump\fR Dumps contents of the hashmap.\&
|
|
||||||
.br
|
|
||||||
Prints each position of allocated hashmap and corresponding contents.\&
|
|
||||||
.br
|
|
||||||
Empty areas are shown as `(unused)`, while used ones contain volume, pitch range, calculated hash, key and file path.\&
|
|
||||||
.PP
|
|
||||||
\fBdbg:counters\fR Shows internal counters.\& Can be disabled at the compile-time.\&
|
|
||||||
.br
|
|
||||||
- `.\&pool_read` - number of reads
|
|
||||||
.br
|
|
||||||
- `.\&pool_write` - number of writes
|
|
||||||
.br
|
|
||||||
- `.\&hash_misses_read` - number of missed reads due to collision
|
|
||||||
.br
|
|
||||||
- `.\&hash_misses_write` - number of collisions in the map
|
|
||||||
.br
|
|
||||||
- `.\&pool.\&use` - number of used cells
|
|
||||||
.br
|
|
||||||
- `.\&pool.\&cap` - hashmap capacity
|
|
||||||
.PP
|
|
54
sfxd.5.scd
54
sfxd.5.scd
|
@ -1,54 +0,0 @@
|
||||||
sfxd(5)
|
|
||||||
|
|
||||||
# NAME
|
|
||||||
|
|
||||||
sfxd - configuration file and client commands list
|
|
||||||
|
|
||||||
# DESCRIPTION
|
|
||||||
|
|
||||||
Both configuration file and sfxc(1) commands use the same set of instructions.
|
|
||||||
|
|
||||||
Configuration file is *not* loaded automatically, unless specified with `-C [path]` flag, but it can be loaded at a run-time via *source* command.
|
|
||||||
|
|
||||||
# COMMANDS LIST
|
|
||||||
|
|
||||||
*load NAME FILE* Loads specified sound file and stores it under given key. ++
|
|
||||||
When given key is already in use, it SHOULD be replaced with the new sound file. ++
|
|
||||||
**NAME** is a string with no spaces, does not support escaping and used as a primary key for accessing loaded sound later. ++
|
|
||||||
**FILE** is an absolute path to a sound file to be loaded. Only WAV and MP3 files are supported.
|
|
||||||
|
|
||||||
*play NAME* Plays the sound with default pitch and volume. ++
|
|
||||||
**NAME** is a key, used when *load*ing a file.
|
|
||||||
|
|
||||||
*play:rs NAME* Plays the sound with randomized pitch. ++
|
|
||||||
Pitch range is specified with *set:pitch* command. ++
|
|
||||||
**NAME** is a key, used when *load*ing a file.
|
|
||||||
|
|
||||||
*set:pitch NAME MIN MAX* Sets the pitch range for *play:rs* ++
|
|
||||||
**NAME** is a key, used when *load*ing a file. ++
|
|
||||||
**MIN** is the minimum pitch. Can't be less than 0. ++
|
|
||||||
**MAX** is the maximum pitch. Can't be less than 0. ++
|
|
||||||
NOTE: if MAX is smaller than MIN, they are swapped.
|
|
||||||
|
|
||||||
*set:volume NAME VOLUME* Changes loudness for *play* and *play:rs* commands. ++
|
|
||||||
**NAME** is a key, used when *load*ing a file. ++
|
|
||||||
**VOLUME** is the volume to be set. Can't be outside of 0..1 range
|
|
||||||
|
|
||||||
*source PATH* Loads instructions from the configuration file. ++
|
|
||||||
**PATH** is the file path for the configuration file. ++
|
|
||||||
NOTE: there is a limit on how deep inclusion can go. By default it's set to 32.
|
|
||||||
|
|
||||||
# DEBUG COMMANDS
|
|
||||||
|
|
||||||
*dbg:dump* Dumps contents of the hashmap. ++
|
|
||||||
Prints each position of allocated hashmap and corresponding contents. ++
|
|
||||||
Empty areas are shown as `(unused)`, while used ones contain volume, pitch range, calculated hash, key and file path.
|
|
||||||
|
|
||||||
*dbg:counters* Shows internal counters. Can be disabled at the compile-time. ++
|
|
||||||
- `.pool_read` - number of reads ++
|
|
||||||
- `.pool_write` - number of writes ++
|
|
||||||
- `.hash_misses_read` - number of missed reads due to collision ++
|
|
||||||
- `.hash_misses_write` - number of collisions in the map ++
|
|
||||||
- `.pool.use` - number of used cells ++
|
|
||||||
- `.pool.cap` - hashmap capacity
|
|
||||||
|
|
23
src/sfxd.c
23
src/sfxd.c
|
@ -1,6 +1,5 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "miniaudio.h"
|
#include "miniaudio.h"
|
||||||
#include <errno.h>
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
@ -10,7 +9,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
@ -107,13 +105,6 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
struct stat statbuf;
|
|
||||||
int status = stat(sock_path, &statbuf);
|
|
||||||
if (status == 0 && !S_ISSOCK(statbuf.st_mode)) {
|
|
||||||
PANIC("Specified sock_path is not a socket");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ipc_init(sock_path)) {
|
if (!ipc_init(sock_path)) {
|
||||||
unlink(sock_path);
|
unlink(sock_path);
|
||||||
|
@ -225,7 +216,7 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
|
||||||
ma_sound_set_pitch(sfx, sound->pitch_min);
|
ma_sound_set_pitch(sfx, sound->pitch_min);
|
||||||
ma_sound_set_volume(sfx, sound->volume);
|
ma_sound_set_volume(sfx, sound->volume);
|
||||||
ma_sound_start(sfx);
|
ma_sound_start(sfx);
|
||||||
} else if (0 == strcmp(command, "play:rs")) {
|
} else if (0 == strcmp(command, "play:rs") || 0 == strcmp(command, "play_rs")) {
|
||||||
struct sfx_pool_item *sound = sfx_pool_lookup(params);
|
struct sfx_pool_item *sound = sfx_pool_lookup(params);
|
||||||
if (!sound) {
|
if (!sound) {
|
||||||
send_txt(tgt, "ERR: No such sound: '%s'\n", params);
|
send_txt(tgt, "ERR: No such sound: '%s'\n", params);
|
||||||
|
@ -239,7 +230,7 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
|
||||||
ma_sound_set_pitch(sfx, pitch);
|
ma_sound_set_pitch(sfx, pitch);
|
||||||
ma_sound_set_volume(sfx, sound->volume);
|
ma_sound_set_volume(sfx, sound->volume);
|
||||||
ma_sound_start(sfx);
|
ma_sound_start(sfx);
|
||||||
} else if (0 == strcmp(command, "set:pitch")) {
|
} else if (0 == strcmp(command, "set:pitch") || 0 == strcmp(command, "setpitchrange")) {
|
||||||
float min, max;
|
float min, max;
|
||||||
char *key;
|
char *key;
|
||||||
sscanf(params, "%ms %f %f", &key, &min, &max);
|
sscanf(params, "%ms %f %f", &key, &min, &max);
|
||||||
|
@ -265,7 +256,7 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
|
||||||
|
|
||||||
sound->pitch_min = min;
|
sound->pitch_min = min;
|
||||||
sound->pitch_max = max;
|
sound->pitch_max = max;
|
||||||
} else if (0 == strcmp(command, "set:volume")) {
|
} else if (0 == strcmp(command, "set:volume") || 0 == strcmp(command, "volume")) {
|
||||||
float vol;
|
float vol;
|
||||||
char *key;
|
char *key;
|
||||||
sscanf(params, "%ms %f", &key, &vol);
|
sscanf(params, "%ms %f", &key, &vol);
|
||||||
|
@ -277,13 +268,11 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vol < 0 || vol > 1) {
|
if (vol < 0 || vol > 1) {
|
||||||
send_txt(tgt, "ERR: Volume out of range: 0 <= %f <= 1\n", vol);
|
send_txt(tgt, "ERR: Volume out of range: 0 <= %f < 1\n", vol);
|
||||||
}
|
}
|
||||||
|
|
||||||
sound->volume = vol;
|
sound->volume = vol;
|
||||||
} else if (0 == strcmp(command, "source")) {
|
} else if (0 == strcmp(command, "dump")) {
|
||||||
execute_file(tgt, params, 0);
|
|
||||||
} else if (0 == strcmp(command, "dbg:dump")) {
|
|
||||||
for (int i = 0; i < sounds_pool.cap; i++) {
|
for (int i = 0; i < sounds_pool.cap; i++) {
|
||||||
struct sfx_pool_item item = sounds_pool.sounds[i];
|
struct sfx_pool_item item = sounds_pool.sounds[i];
|
||||||
if (item.key[0] == '\0') {
|
if (item.key[0] == '\0') {
|
||||||
|
@ -293,6 +282,8 @@ void execute_command(struct msg_target tgt, const char *command, const char *par
|
||||||
i, item.volume, item.pitch_min, item.pitch_max, adler32(item.key, strlen(item.key)), item.key, item.path);
|
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")) {
|
||||||
|
execute_file(tgt, params, 0);
|
||||||
} else if (0 == strcmp(command, "dbg:counters")) {
|
} else if (0 == strcmp(command, "dbg:counters")) {
|
||||||
#ifdef NO_COUNTERS
|
#ifdef NO_COUNTERS
|
||||||
send_txt(tgt, "ERR: counters are disabled at compile-time with NO_COUNTERS feature flag.");
|
send_txt(tgt, "ERR: counters are disabled at compile-time with NO_COUNTERS feature flag.");
|
||||||
|
|
Loading…
Reference in New Issue