2024-04-20 15:57:49 +00:00
|
|
|
/*
|
|
|
|
* 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 __LINUX_DD_SOUND_H_
|
|
|
|
#define __LINUX_DD_SOUND_H_
|
|
|
|
|
2024-05-20 11:29:06 +00:00
|
|
|
#include <SDL_audio.h>
|
|
|
|
|
2024-04-16 03:43:29 +00:00
|
|
|
#include "ssl_lib.h"
|
|
|
|
#include "mixer.h"
|
|
|
|
|
|
|
|
class sound_buffer_info;
|
|
|
|
|
|
|
|
void lnxsound_SetError(int code);
|
2024-04-28 04:39:29 +00:00
|
|
|
void lnxsound_ErrorText(const char *fmt, ...);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
class emulated_listener {
|
2024-04-16 03:43:29 +00:00
|
|
|
public:
|
2024-04-16 18:56:40 +00:00
|
|
|
matrix orient;
|
|
|
|
vector position;
|
|
|
|
vector velocity;
|
2024-04-16 03:43:29 +00:00
|
|
|
};
|
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
class lnxsound : public llsSystem {
|
|
|
|
// Public functions
|
2024-04-16 03:43:29 +00:00
|
|
|
public:
|
2024-04-16 18:56:40 +00:00
|
|
|
lnxsound();
|
|
|
|
~lnxsound();
|
|
|
|
|
|
|
|
// may be called before init (must be to be valid, the card passed here will be initialized in InitSoundLib)
|
2024-05-20 10:49:01 +00:00
|
|
|
void SetSoundCard(const char *name) override;
|
|
|
|
void PauseSound(int sound_uid) override;
|
|
|
|
void ResumeSound(int sound_uid) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
// set special parameters for the 3d environment.
|
|
|
|
// of strcuture passed, you must set the appropriate 'flags' value for values you wish to modify
|
2024-05-20 10:49:01 +00:00
|
|
|
void SetEnvironmentValues(const t3dEnvironmentValues *env) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// get special parameters for the 3d environment.
|
|
|
|
// of strcuture passed, you must set the appropriate 'flags' value for values you wish to modify
|
2024-05-20 10:49:01 +00:00
|
|
|
void GetEnvironmentValues(t3dEnvironmentValues *env) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// enable special parameters for the 3d environment.
|
|
|
|
// of strcuture passed, you must set the appropriate 'flags' value for values you wish to modify
|
2024-05-20 10:49:01 +00:00
|
|
|
void SetEnvironmentToggles(const t3dEnvironmentToggles *env) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// get states of special parameters for the 3d environment.
|
|
|
|
// of strcuture passed, you must set the appropriate 'flags' value for values you wish to modify
|
2024-05-20 10:49:01 +00:00
|
|
|
void GetEnvironmentToggles(t3dEnvironmentToggles *env) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// Starts the sound library, maybe have it send back some information -- 3d support?
|
2024-05-24 02:58:46 +00:00
|
|
|
int InitSoundLib(char mixer_type, oeApplication *sos, uint8_t max_sounds_played) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
// Cleans up after the Sound Library
|
2024-05-20 10:49:01 +00:00
|
|
|
void DestroySoundLib() override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// Locks and unlocks sounds (used when changing play_info data)
|
2024-05-20 10:49:01 +00:00
|
|
|
bool LockSound(int sound_uid) override;
|
|
|
|
bool UnlockSound(int sound_uid) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
2024-05-20 10:49:01 +00:00
|
|
|
bool SetSoundQuality(char quality) override;
|
|
|
|
char GetSoundQuality() override;
|
|
|
|
bool SetSoundMixer(char mixer_type) override;
|
|
|
|
char GetSoundMixer() override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// Plays a 2d sound
|
2024-05-20 10:49:01 +00:00
|
|
|
int PlaySound2d(play_information *play_info, int sound_index, float volume, float pan, bool f_looped) override;
|
|
|
|
int PlayStream(play_information *play_info) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
2024-05-20 10:49:01 +00:00
|
|
|
void SetListener(pos_state *cur_pos) override;
|
|
|
|
int PlaySound3d(play_information *play_info, int sound_index, pos_state *cur_pos, float master_volume,
|
|
|
|
bool f_looped, float reverb = 0.5f) override;
|
2024-05-24 03:03:29 +00:00
|
|
|
void AdjustSound(int sound_uid, float f_volume, float f_pan, uint16_t frequency) override;
|
2024-05-20 10:49:01 +00:00
|
|
|
void AdjustSound(int sound_uid, pos_state *cur_pos, float adjusted_volume, float reverb = 0.5f) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
2024-05-20 10:49:01 +00:00
|
|
|
void StopAllSounds() override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// Checks if a sound is playing (removes finished sound);
|
2024-05-20 10:49:01 +00:00
|
|
|
bool IsSoundInstancePlaying(int sound_uid) override;
|
|
|
|
int IsSoundPlaying(int sound_index) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// virtual void AdjustSound(int sound_uid, play_information *play_info) = 0;
|
|
|
|
|
|
|
|
// Stops 2d and 3d sounds
|
2024-05-24 02:58:46 +00:00
|
|
|
void StopSound(int sound_uid, uint8_t f_immediately = SKT_STOP_IMMEDIATELY) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// Pause all sounds/resume all sounds
|
2024-05-20 10:49:01 +00:00
|
|
|
void PauseSounds() override;
|
|
|
|
void ResumeSounds() override;
|
|
|
|
bool CheckAndForceSoundDataAlloc(int sound_file_index) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// Begin sound frame
|
2024-05-20 10:49:01 +00:00
|
|
|
void SoundStartFrame() override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// End sound frame
|
2024-05-20 10:49:01 +00:00
|
|
|
void SoundEndFrame() override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// returns the error string.
|
2024-04-28 04:39:29 +00:00
|
|
|
virtual const char *GetErrorStr() const;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
// environmental sound interface
|
|
|
|
// volume modifier (0-1), damping(0-1), 1 = complete, 0 = none
|
|
|
|
// decay 0.1 to 100 seconds, how long it takes for a sound to die.
|
2024-05-20 10:49:01 +00:00
|
|
|
bool SetGlobalReverbProperties(float volume, float damping, float decay) override;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
2024-05-24 02:51:16 +00:00
|
|
|
bool GetDeviceSettings(SDL_AudioDeviceID *sound_device, uint32_t *freq, uint32_t *bit_depth,
|
|
|
|
uint32_t *channels) const;
|
2024-04-16 18:56:40 +00:00
|
|
|
|
|
|
|
friend void lnxsound_SetError(int code);
|
2024-04-28 04:39:29 +00:00
|
|
|
friend void lnxsound_ErrorText(const char *fmt, ...);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
#ifdef _DEBUG
|
2024-05-24 03:27:12 +00:00
|
|
|
int16_t FindFreeSoundSlot(int sound_index, float volume, int priority);
|
2024-04-16 03:43:29 +00:00
|
|
|
#else
|
2024-05-24 03:27:12 +00:00
|
|
|
int16_t FindFreeSoundSlot(float volume, int priority);
|
2024-04-16 03:43:29 +00:00
|
|
|
#endif
|
2024-04-16 18:56:40 +00:00
|
|
|
// This function limits the number of sounds cached to 255(8bits) and 256 bit is for invalid channel
|
|
|
|
// The purpose is to create unique signatures for each sound played (and allow for
|
|
|
|
// the slot_number to be quickly determined)
|
2024-05-20 09:03:22 +00:00
|
|
|
inline int MakeUniqueId(int sound_slot) const;
|
|
|
|
static inline int ValidateUniqueId(int sound_uid);
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// Sound System Error Handler.
|
2024-05-20 10:49:01 +00:00
|
|
|
void CheckForErrors() override;
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-05-20 09:03:22 +00:00
|
|
|
void StartStreaming();
|
|
|
|
void EndStreaming();
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
int m_primary_frequency; // Set to the primary buffers frequency -- cmphack
|
|
|
|
int m_primary_alignment;
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-05-20 11:29:06 +00:00
|
|
|
SDL_AudioDeviceID sound_device;
|
2024-04-16 18:56:40 +00:00
|
|
|
bool in_at_exit;
|
|
|
|
bool m_in_sound_frame;
|
|
|
|
bool m_pending_actions;
|
|
|
|
char m_sound_quality;
|
|
|
|
float m_cache_stress_timer;
|
|
|
|
float m_timer_last_frametime;
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
int m_total_sounds_played;
|
|
|
|
int m_cur_sounds_played;
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
emulated_listener m_emulated_listener;
|
2024-04-16 03:43:29 +00:00
|
|
|
|
2024-04-16 18:56:40 +00:00
|
|
|
// Sam 6/29 - Added support for SDL
|
|
|
|
software_mixer m_mixer;
|
2024-04-16 03:43:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|