2022-01-19 16:43:21 -06:00
|
|
|
#ifndef SOUND_H
|
|
|
|
#define SOUND_H
|
|
|
|
|
2023-11-27 14:29:55 -06:00
|
|
|
#include "script.h"
|
2023-12-18 17:12:05 -06:00
|
|
|
#include "pthread.h"
|
2022-07-06 17:17:06 -05:00
|
|
|
|
2023-08-29 17:11:36 -05:00
|
|
|
typedef float soundbyte;
|
2023-12-18 17:12:05 -06:00
|
|
|
extern pthread_mutex_t soundrun;
|
2023-08-29 17:11:36 -05:00
|
|
|
|
2023-11-27 14:29:55 -06:00
|
|
|
struct dsp_node;
|
2022-07-06 17:17:06 -05:00
|
|
|
|
2023-08-30 18:22:32 -05:00
|
|
|
/* A bookmark into a wav, actually playing the sound */
|
2023-11-27 14:29:55 -06:00
|
|
|
typedef struct sound {
|
2023-01-15 23:27:28 -06:00
|
|
|
unsigned int frame; /* Pointing to the current frame on the wav */
|
2024-10-08 02:46:59 -05:00
|
|
|
struct pcm *data;
|
2023-11-27 14:29:55 -06:00
|
|
|
int loop;
|
|
|
|
} sound;
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2023-11-20 15:57:23 -06:00
|
|
|
/* Represents a sound file source, fulled loaded*/
|
2024-10-08 02:46:59 -05:00
|
|
|
typedef struct pcm {
|
2022-07-05 15:12:48 -05:00
|
|
|
unsigned int ch;
|
|
|
|
unsigned int samplerate;
|
2023-01-16 13:20:07 -06:00
|
|
|
unsigned long long frames;
|
2023-08-30 18:22:32 -05:00
|
|
|
soundbyte *data;
|
2024-10-08 02:46:59 -05:00
|
|
|
} pcm;
|
2022-07-12 15:43:02 -05:00
|
|
|
|
2022-01-19 16:43:21 -06:00
|
|
|
void sound_init();
|
|
|
|
void audio_open(const char *device);
|
|
|
|
void audio_close();
|
|
|
|
|
2024-10-08 02:46:59 -05:00
|
|
|
struct pcm *make_pcm(const char *file);
|
|
|
|
void pcm_free(pcm *pcm);
|
|
|
|
void pcm_norm_gain(struct pcm *w, double lv);
|
|
|
|
void pcm_format(pcm *pcm, int samplerate, int channels);
|
|
|
|
|
|
|
|
struct dsp_node *dsp_source(pcm *pcm);
|
2023-11-27 14:29:55 -06:00
|
|
|
struct dsp_node *dsp_mod(const char *path);
|
2022-07-12 15:43:02 -05:00
|
|
|
|
2022-07-19 15:13:15 -05:00
|
|
|
int sound_finished(const struct sound *s);
|
2022-07-12 15:43:02 -05:00
|
|
|
|
2022-07-11 23:21:57 -05:00
|
|
|
float short2db(short val);
|
|
|
|
short db2short(float db);
|
|
|
|
short short_gain(short val, float db);
|
2023-11-27 14:29:55 -06:00
|
|
|
float fgain(float val, float db);
|
|
|
|
float float2db(float val);
|
|
|
|
float db2float(float db);
|
2022-07-11 23:21:57 -05:00
|
|
|
|
2022-07-12 15:43:02 -05:00
|
|
|
float pct2db(float pct);
|
|
|
|
float pct2mult(float pct);
|
|
|
|
|
2024-10-08 02:46:59 -05:00
|
|
|
void save_qoa(char *file, pcm *pcm);
|
|
|
|
void save_wav(char *file, pcm *pcm);
|
2024-03-02 00:00:35 -06:00
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
#endif
|