2022-01-19 16:43:21 -06:00
|
|
|
#ifndef SOUND_H
|
|
|
|
#define SOUND_H
|
|
|
|
|
2023-08-30 18:22:32 -05:00
|
|
|
#include "cbuf.h"
|
2022-07-06 17:17:06 -05:00
|
|
|
|
2023-08-29 17:11:36 -05:00
|
|
|
typedef float soundbyte;
|
|
|
|
|
2022-07-06 17:17:06 -05:00
|
|
|
struct soundstream {
|
2022-07-19 15:13:15 -05:00
|
|
|
struct circbuf *buf;
|
2022-07-06 17:17:06 -05:00
|
|
|
};
|
|
|
|
|
2022-07-19 15:13:15 -05:00
|
|
|
struct soundstream *soundstream_make();
|
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 */
|
2022-06-23 02:34:51 -05:00
|
|
|
struct sound {
|
2023-01-15 23:27:28 -06:00
|
|
|
int loop; /* How many times to loop */
|
|
|
|
unsigned int frame; /* Pointing to the current frame on the wav */
|
2022-07-12 15:43:02 -05:00
|
|
|
int playing;
|
2022-07-12 01:28:41 -05:00
|
|
|
float gain;
|
|
|
|
|
2022-07-04 12:47:21 -05:00
|
|
|
struct wav *data;
|
2022-07-12 15:43:02 -05:00
|
|
|
struct bus *bus;
|
2023-01-16 13:20:07 -06:00
|
|
|
|
|
|
|
void (*endcb)(struct sound*);
|
2022-01-19 16:43:21 -06:00
|
|
|
};
|
|
|
|
|
2023-11-20 15:57:23 -06:00
|
|
|
/* Represents a sound file source, fulled loaded*/
|
2022-07-03 19:24:53 -05:00
|
|
|
struct wav {
|
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;
|
2022-07-12 15:43:02 -05:00
|
|
|
float gain; /* In dB */
|
2023-08-30 18:22:32 -05:00
|
|
|
soundbyte *data;
|
2022-07-03 19:24:53 -05:00
|
|
|
};
|
|
|
|
|
2023-11-20 15:57:23 -06:00
|
|
|
/* Represents a sound file stream */
|
2023-01-16 13:20:07 -06:00
|
|
|
struct mp3 {
|
2022-07-12 15:43:02 -05:00
|
|
|
|
2022-07-12 01:28:41 -05:00
|
|
|
};
|
|
|
|
|
2022-01-19 16:43:21 -06:00
|
|
|
void sound_init();
|
|
|
|
void audio_open(const char *device);
|
|
|
|
void audio_close();
|
|
|
|
|
2023-08-30 18:22:32 -05:00
|
|
|
void sound_fillbuf(struct sound *s, soundbyte *buf, int n);
|
2022-07-06 17:17:06 -05:00
|
|
|
|
2023-01-15 09:53:50 -06:00
|
|
|
struct wav *make_sound(const char *wav);
|
2023-01-15 11:16:25 -06:00
|
|
|
void free_sound(const char *wav);
|
2022-07-12 15:43:02 -05:00
|
|
|
void wav_norm_gain(struct wav *w, double lv);
|
2022-07-19 15:13:15 -05:00
|
|
|
struct sound *play_sound(struct wav *wav);
|
2023-01-16 13:20:07 -06:00
|
|
|
void play_oneshot(struct wav *wav);
|
2022-07-12 15:43:02 -05:00
|
|
|
|
2022-07-19 15:13:15 -05:00
|
|
|
int sound_playing(const struct sound *s);
|
|
|
|
int sound_paused(const struct sound *s);
|
|
|
|
int sound_stopped(const struct sound *s);
|
|
|
|
int sound_finished(const struct sound *s);
|
2022-07-12 15:43:02 -05:00
|
|
|
void sound_pause(struct sound *s);
|
|
|
|
void sound_resume(struct sound *s);
|
|
|
|
void sound_stop(struct sound *s);
|
|
|
|
|
2023-01-16 13:20:07 -06:00
|
|
|
struct mp3 make_mp3(const char *mp3);
|
2022-07-12 15:43:02 -05:00
|
|
|
|
2022-07-12 01:28:41 -05:00
|
|
|
const char *get_audio_driver();
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2023-08-30 18:22:32 -05:00
|
|
|
void soundstream_fillbuf(struct soundstream *stream, soundbyte *buf, int n);
|
2022-07-06 17:17:06 -05:00
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
void close_audio_device(int device);
|
|
|
|
int open_device(const char *adriver);
|
|
|
|
|
2022-07-11 23:21:57 -05:00
|
|
|
float short2db(short val);
|
|
|
|
short db2short(float db);
|
|
|
|
short short_gain(short val, float db);
|
|
|
|
|
2022-07-12 15:43:02 -05:00
|
|
|
float pct2db(float pct);
|
|
|
|
float pct2mult(float pct);
|
|
|
|
|
2022-01-19 16:43:21 -06:00
|
|
|
void audio_init();
|
|
|
|
|
2022-07-11 23:21:57 -05:00
|
|
|
|
|
|
|
|
2022-02-06 10:14:57 -06:00
|
|
|
#endif
|