| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #ifndef __SOUND_MIXER_H______ |
| 20 | #define __SOUND_MIXER_H______ |
| 21 | |
| 22 | #include "ssl_lib.h" |
| 23 | |
| 24 | class sound_buffer { |
| 25 | public: |
| 26 | virtual int GetNumBufferBytes(void) = 0; |
| 27 | virtual void Write(uint8_t *buffer, int amount) = 0; |
| 28 | |
| 29 | private: |
| 30 | }; |
| 31 | |
| 32 | struct DSLOOPSTREAM { |
| 33 | int playing; |
| 34 | int please_close; |
| 35 | char *current_position; |
| 36 | int bytes_left; |
| 37 | int no_callbacks; |
| 38 | int half_buffer_point; |
| 39 | int last_half; |
| 40 | int close_on_next; |
| 41 | char silence_byte; |
| 42 | bool f_sample_16bit; |
| 43 | int num_written; |
| 44 | bool kill_me; |
| 45 | }; |
| 46 | |
| 47 | // Sound item info (cache list) |
| 48 | // override if you need to keep more information |
| 49 | class sound_buffer_info { |
| 50 | public: |
| 51 | sound_buffer_info() { |
| 52 | m_status = SSF_UNUSED; |
| 53 | s = NULL; |
| 54 | } |
| 55 | |
| 56 | play_information *play_info; |
| 57 | |
| 58 | int m_sound_index; // Index of sound |
| 59 | int m_unique_id; // Unique id for the currently playing sample |
| 60 | |
| 61 | // Not needed by the software mixer |
| 62 | volatile DSLOOPSTREAM *s; // Streaming info for a looping sample |
| 63 | |
| 64 | int16_t m_mixer_type; // ds3d, ds_8? |
| 65 | int16_t m_buffer_type; // Buffer type 2d or 3d |
| 66 | |
| 67 | char *sample_data; |
| 68 | int sample_length; // used for storage purposes. |
| 69 | |
| 70 | float m_volume; |
| 71 | |
| 72 | bool stereo; |
| 73 | int8_t bps; |
| 74 | uint8_t m_status; // Sound status |
| 75 | uint8_t pad; |
| 76 | }; |
| 77 | |
| 78 | struct tMixerInit { |
| 79 | sound_buffer *primary_buffer; |
| 80 | int primary_frequency; |
| 81 | int primary_alignment; |
| 82 | int *max_sounds_available; // pointer to the variable that is updated with the # of sounds in the sound_cache |
| 83 | sound_buffer_info *sound_cache; // the array of sound information |
| 84 | |
| 85 | void (*fp_SetError)(int code); |
| 86 | void (*fp_ErrorText)(const char *fmt, ...); |
| 87 | int *p_error_code; |
| 88 | |
| 89 | llsSystem *ll_sound_ptr; |
| 90 | }; |
| 91 | |
| 92 | class software_mixer { |
| 93 | public: |
| 94 | software_mixer(); |
| 95 | ~software_mixer(); |
| 96 | |
| 97 | bool Initialize(tMixerInit *mi); |
| 98 | void DoFrame(void); |
| 99 | |
| 100 | // The actual mixer code that sum's the sounds on each channel and does all the actual |
| 101 | // mixing and effects (writes data to the locked primary buffer) |
| 102 | void StreamMixer(char *ptr, int len); |
| 103 | |
| 104 | private: |
| 105 | llsSystem *m_ll_sound_ptr; |
| 106 | bool m_init; |
| 107 | sound_buffer *m_primary_buffer; |
| 108 | int *Fast_mixer; |
| 109 | int Fast_mixer_len; |
| 110 | int m_primary_alignment; |
| 111 | int m_BufferSize; |
| 112 | |
| 113 | uint8_t *m_buffer; |
| 114 | |
| 115 | int *m_max_sounds_available; |
| 116 | sound_buffer_info *m_sound_cache; |
| 117 | |
| 118 | void (*m_fpSetError)(int code); |
| 119 | void (*m_fpErrorText)(const char *fmt, ...); |
| 120 | int *m_error_code; |
| 121 | }; |
| 122 | |
| 123 | #endif |