cleanup: mixer

This commit is contained in:
bnnm 2024-07-25 17:16:12 +02:00
parent aad9c819aa
commit 9c315221eb
3 changed files with 24 additions and 26 deletions

View File

@ -29,7 +29,7 @@
* segmented/layered layouts handle mixing on their own.
*/
void* mixer_init(int channels) {
mixer_t* mixer_init(int channels) {
mixer_t* mixer = calloc(1, sizeof(mixer_t));
if (!mixer) goto fail;
@ -45,16 +45,14 @@ fail:
return NULL;
}
void mixer_free(void* _mixer) {
mixer_t* mixer = _mixer;
void mixer_free(mixer_t* mixer) {
if (!mixer) return;
free(mixer->mixbuf);
free(mixer);
}
void mixer_update_channel(void* _mixer) {
mixer_t* mixer = _mixer;
void mixer_update_channel(mixer_t* mixer) {
if (!mixer) return;
/* lame hack for dual stereo, but dual stereo is pretty hack-ish to begin with */
@ -62,9 +60,7 @@ void mixer_update_channel(void* _mixer) {
mixer->output_channels++;
}
bool mixer_is_active(void* _mixer) {
mixer_t* mixer = _mixer;
bool mixer_is_active(mixer_t* mixer) {
/* no support or not need to apply */
if (!mixer || !mixer->active || mixer->chain_count == 0)
return false;
@ -73,8 +69,7 @@ bool mixer_is_active(void* _mixer) {
}
void mixer_process(void* _mixer, sample_t *outbuf, int32_t sample_count, int32_t current_pos) {
mixer_t* mixer = _mixer;
void mixer_process(mixer_t* mixer, sample_t* outbuf, int32_t sample_count, int32_t current_pos) {
/* no support or not need to apply */
if (!mixer || !mixer->active || mixer->chain_count == 0)

View File

@ -3,12 +3,14 @@
#include "../streamtypes.h"
typedef struct mixer_t mixer_t;
/* internal mixing pre-setup for vgmstream (doesn't imply usage).
* If init somehow fails next calls are ignored. */
void* mixer_init(int channels);
void mixer_free(void* mixer);
void mixer_update_channel(void* mixer);
void mixer_process(void* _mixer, sample_t *outbuf, int32_t sample_count, int32_t current_pos);
bool mixer_is_active(void* mixer);
mixer_t* mixer_init(int channels);
void mixer_free(mixer_t* mixer);
void mixer_update_channel(mixer_t* mixer);
void mixer_process(mixer_t* mixer, sample_t *outbuf, int32_t sample_count, int32_t current_pos);
bool mixer_is_active(mixer_t* mixer);
#endif

View File

@ -1,6 +1,7 @@
#ifndef _MIXER_PRIV_H_
#define _MIXER_PRIV_H_
#include "../streamtypes.h"
#include "mixer.h"
#define VGMSTREAM_MAX_MIXING 512
@ -32,7 +33,7 @@ typedef struct {
int32_t time_post; /* position after time_end where vol_end applies (-1 = end) */
} mix_op_t;
typedef struct {
struct mixer_t {
int input_channels; /* starting channels before mixing */
int output_channels; /* resulting channels after mixing */
int mixing_channels; /* max channels needed to mix */
@ -51,15 +52,15 @@ typedef struct {
int current_channels; /* state: channels may increase/decrease during ops */
int32_t current_subpos; /* state: current sample pos in the stream */
} mixer_t;
};
void mixer_op_swap(mixer_t* data, int32_t sample_count, mix_op_t* op);
void mixer_op_add(mixer_t* data, int32_t sample_count, mix_op_t* op);
void mixer_op_volume(mixer_t* data, int32_t sample_count, mix_op_t* op);
void mixer_op_limit(mixer_t* data, int32_t sample_count, mix_op_t* op);
void mixer_op_upmix(mixer_t* data, int32_t sample_count, mix_op_t* op);
void mixer_op_downmix(mixer_t* data, int32_t sample_count, mix_op_t* op);
void mixer_op_killmix(mixer_t* data, int32_t sample_count, mix_op_t* op);
void mixer_op_fade(mixer_t* data, int32_t sample_count, mix_op_t* op);
bool mixer_op_fade_is_active(mixer_t* data, int32_t current_start, int32_t current_end);
void mixer_op_swap(mixer_t* mixer, int32_t sample_count, mix_op_t* op);
void mixer_op_add(mixer_t* mixer, int32_t sample_count, mix_op_t* op);
void mixer_op_volume(mixer_t* mixer, int32_t sample_count, mix_op_t* op);
void mixer_op_limit(mixer_t* mixer, int32_t sample_count, mix_op_t* op);
void mixer_op_upmix(mixer_t* mixer, int32_t sample_count, mix_op_t* op);
void mixer_op_downmix(mixer_t* mixer, int32_t sample_count, mix_op_t* op);
void mixer_op_killmix(mixer_t* mixer, int32_t sample_count, mix_op_t* op);
void mixer_op_fade(mixer_t* mixer, int32_t sample_count, mix_op_t* op);
bool mixer_op_fade_is_active(mixer_t* mixer, int32_t current_start, int32_t current_end);
#endif