Descent3/lib/linux/mixer.h

138 lines
3.1 KiB
C
Raw Normal View History

2024-04-16 03:43:29 +00:00
#ifndef __SOUND_MIXER_H______
#define __SOUND_MIXER_H______
#include "ssl_lib.h"
// Sound Library Internal Error Codes
2024-04-16 18:56:40 +00:00
#define SSL_OK 0
#define SSL_ERROR_GENERIC -1
#define SSL_ERROR_SAMPLE_NODATA -2
#define SSL_ERROR_STREAMMIXER -3
2024-04-16 03:43:29 +00:00
// Sound Status
2024-04-16 18:56:40 +00:00
#define SSF_UNUSED 0
#define SSF_PLAY_NORMAL 1
#define SSF_PLAY_LOOPING 2
#define SSF_PAUSED 4
#define SSF_PLAY_STREAMING 8
#define SSF_BUFFERED_LOOP 64
#define SSF_BUFFERED_STRM 128
#define SBT_PRIMARY 0
#define SBT_2D 1
#define SBT_3D 2
2024-04-16 03:43:29 +00:00
// looping methods
2024-04-16 18:56:40 +00:00
#define DSLOOP_SMART_METHOD 0
#define DSLOOP_BUFFER_METHOD 1
#define DSLOOP_STREAM_METHOD 2
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
#define DSBUFLOOP_INIT_STEP -1
#define DSBUFLOOP_LOOP_STEP 0
#define DSBUFLOOP_FINISH_STEP 1
2024-04-16 03:43:29 +00:00
// This is the update rate at which to call sound_mixer::DoFrame()
// (sleep this amount each frame of the thread)
2024-04-16 18:56:40 +00:00
#define MIXER_TICK_INTERVAL 0.01f
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
class sound_buffer {
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
virtual int GetNumBufferBytes(void) = 0;
virtual void Write(unsigned char *buffer, int amount) = 0;
2024-04-16 03:43:29 +00:00
private:
};
2024-04-16 18:56:40 +00:00
typedef struct DSLOOPSTREAM {
int playing;
int please_close;
char *current_position;
int bytes_left;
int no_callbacks;
int half_buffer_point;
int last_half;
int close_on_next;
char silence_byte;
bool f_sample_16bit;
int num_written;
bool kill_me;
2024-04-16 03:43:29 +00:00
} DSLOOPSTREAM;
// Sound item info (cache list)
// override if you need to keep more information
2024-04-16 18:56:40 +00:00
class sound_buffer_info {
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
sound_buffer_info() {
m_status = SSF_UNUSED;
s = NULL;
}
play_information *play_info;
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
int m_sound_index; // Index of sound
int m_unique_id; // Unique id for the currently playing sample
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// Not needed by the software mixer
volatile DSLOOPSTREAM *s; // Streaming info for a looping sample
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
short m_mixer_type; // aureal, ds3d, ds_8?
short m_buffer_type; // Buffer type 2d or 3d
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
char *sample_data;
int sample_length; // used for storage purposes.
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
float m_volume;
bool stereo;
sbyte bps;
unsigned char m_status; // Sound status
unsigned char pad;
2024-04-16 03:43:29 +00:00
};
2024-04-16 18:56:40 +00:00
typedef struct {
sound_buffer *primary_buffer;
int primary_frequency;
int primary_alignment;
int *max_sounds_available; // pointer to the variable that is updated with the # of sounds in the sound_cache
sound_buffer_info *sound_cache; // the array of sound information
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
void (*fp_SetError)(int code);
void (*fp_ErrorText)(char *fmt, ...);
int *p_error_code;
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
llsSystem *ll_sound_ptr;
} tMixerInit;
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
class software_mixer {
2024-04-16 03:43:29 +00:00
public:
2024-04-16 18:56:40 +00:00
software_mixer();
~software_mixer();
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
bool Initialize(tMixerInit *mi);
void DoFrame(void);
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
// The actual mixer code that sum's the sounds on each channel and does all the actual
// mixing and effects (writes data to the locked primary buffer)
void StreamMixer(char *ptr, int len);
2024-04-16 03:43:29 +00:00
private:
2024-04-16 18:56:40 +00:00
llsSystem *m_ll_sound_ptr;
bool m_init;
sound_buffer *m_primary_buffer;
int *Fast_mixer;
int Fast_mixer_len;
int m_primary_alignment;
int m_BufferSize;
unsigned char *m_buffer;
int *m_max_sounds_available;
sound_buffer_info *m_sound_cache;
void (*m_fpSetError)(int code);
void (*m_fpErrorText)(char *fmt, ...);
int *m_error_code;
2024-04-16 03:43:29 +00:00
};
#endif