Descent3/sndlib/mixer.h

124 lines
2.9 KiB
C
Raw Permalink Normal View History

/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2024-04-16 03:43:29 +00:00
#ifndef __SOUND_MIXER_H______
#define __SOUND_MIXER_H______
#include "ssl_lib.h"
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;
2024-05-24 02:58:46 +00:00
virtual void Write(uint8_t *buffer, int amount) = 0;
2024-04-16 18:56:40 +00:00
2024-04-16 03:43:29 +00:00
private:
};
struct DSLOOPSTREAM {
2024-04-16 18:56:40 +00:00
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
// 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
int16_t m_mixer_type; // ds3d, ds_8?
int16_t 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;
2024-05-24 03:05:05 +00:00
int8_t bps;
2024-05-24 02:58:46 +00:00
uint8_t m_status; // Sound status
uint8_t pad;
2024-04-16 03:43:29 +00:00
};
struct tMixerInit {
2024-04-16 18:56:40 +00:00
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)(const char *fmt, ...);
2024-04-16 18:56:40 +00:00
int *p_error_code;
2024-04-16 03:43:29 +00:00
2024-04-16 18:56:40 +00:00
llsSystem *ll_sound_ptr;
};
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;
2024-05-24 02:58:46 +00:00
uint8_t *m_buffer;
2024-04-16 18:56:40 +00:00
int *m_max_sounds_available;
sound_buffer_info *m_sound_cache;
void (*m_fpSetError)(int code);
void (*m_fpErrorText)(const char *fmt, ...);
2024-04-16 18:56:40 +00:00
int *m_error_code;
2024-04-16 03:43:29 +00:00
};
#endif