Convert sndlib to use new logging facility

This commit is contained in:
Azamat H. Hackimov 2024-08-20 04:39:37 +03:00
parent df93488815
commit ae8e1b4a48
6 changed files with 49 additions and 59 deletions

View File

@ -26,6 +26,7 @@ target_link_libraries(sndlib PRIVATE
stream_audio
physics
SDL2::SDL2
plog::plog
)
target_include_directories(sndlib PUBLIC
$<BUILD_INTERFACE:

View File

@ -95,6 +95,7 @@
#include "pserror.h"
#include "byteswap.h"
#include "gamesequence.h"
#include "log.h"
sound_info Sounds[MAX_SOUNDS];
sound_file_info SoundFiles[MAX_SOUND_FILES];
@ -149,7 +150,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
if (e_type)
*e_type = SND_LOAD_ERROR_NO_FILE;
mprintf(0, "SOUND LOADER: %s not found\n", filename);
LOG_WARNING.printf("SOUND LOADER: %s not found", filename);
goto error_state;
}
@ -163,7 +164,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
// Make sure that it is a RIFF format
temp_long = (uint32_t)cf_ReadInt(cfptr);
if (temp_long != 0x46464952) {
mprintf(0, "SOUND LOADER: %s is not a RIFF format file\n", filename);
LOG_WARNING.printf("SOUND LOADER: %s is not a RIFF format file", filename);
goto error_state;
}
@ -174,7 +175,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
// Make sure it is a wave file
temp_long = (uint32_t)cf_ReadInt(cfptr);
if (temp_long != 0x45564157) {
mprintf(0, "SOUND LOADER: %s is not a WAVE file\n", filename);
LOG_WARNING.printf("SOUND LOADER: %s is not a WAVE file", filename);
goto error_state;
}
nextseek = cftell(cfptr);
@ -189,7 +190,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
ckid = cf_ReadInt(cfptr);
cksize = cf_ReadInt(cfptr);
if (cksize <= 0) {
mprintf(0, "SOUND LOADER: %s has an invalid block length\n", filename);
LOG_WARNING.printf("SOUND LOADER: %s has an invalid block length", filename);
goto error_state;
}
@ -201,7 +202,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
case 0x20746D66: // Format Chunk
// Make sure that this format was not preceeded by another format without data inbetween them.
if (f_fmt) {
mprintf(0, "Sound Loader: Found 2 formats in a row in file %s\n", filename);
LOG_WARNING.printf("Sound Loader: Found 2 formats in a row in file %s", filename);
goto error_state;
}
@ -272,7 +273,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
// Currently, we only support PCM wave files
if (fmttag != 0x0001) {
mprintf(0, "SOUND LOADER: %s is a type %s wavefile, we only support WAVE_FORMAT_PCM waves.\n", filename,
LOG_WARNING.printf("SOUND LOADER: %s is a type %s wavefile, we only support WAVE_FORMAT_PCM waves.", filename,
format_type);
goto error_state;
}
@ -280,16 +281,16 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
// Get the number of channels
number_channels = cf_ReadShort(cfptr);
if (number_channels != 1) {
mprintf(0, "SOUND LOADER: Invalid number of channels(%d)in %s, we want mono samples only.\n", number_channels,
filename);
LOG_WARNING.printf("SOUND LOADER: Invalid number of channels (%d) in %s, we want mono samples only.",
number_channels, filename);
goto error_state;
}
// Get the number of samples per second
samples_per_second = cf_ReadInt(cfptr);
if (samples_per_second != 22050) {
mprintf(0, "SOUND LOADER: Invalid sample per second(%d)in %s, we want 22k samples only.\n", samples_per_second,
filename);
LOG_WARNING.printf("SOUND LOADER: Invalid sample per second (%d) in %s, we want 22k samples only.",
samples_per_second, filename);
goto error_state;
}
@ -302,7 +303,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
// Get the Bits per sample
bits_per_sample = cf_ReadShort(cfptr);
if (bits_per_sample != 8 && bits_per_sample != 16) {
mprintf(0, "SOUND LOADER: Invalid bits per sample(%d)in %s, we want 8 or 16 bit samples only.\n",
LOG_WARNING.printf("SOUND LOADER: Invalid bits per sample (%d) in %s, we want 8 or 16 bit samples only.",
bits_per_sample, filename);
goto error_state;
}
@ -351,7 +352,7 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
// Data Chunk
case 0x61746164:
if (!f_fmt) {
mprintf(0, "SOUND LOADER: Format Chunk not defined before Data Chunk\n");
LOG_WARNING.printf("SOUND LOADER: Format Chunk not defined before Data Chunk");
goto error_state;
}
@ -416,12 +417,12 @@ char SoundLoadWaveFile(const char *filename, float percent_volume, int sound_fil
cfclose(cfptr);
if (SoundFiles[sound_file_index].sample_8bit != NULL) {
mprintf(0, "Sound file %s is 8bit please make a 16bit version", filename);
LOG_WARNING.printf("Sound file %s is 8bit, please make a 16bit version", filename);
}
// Make sure we got data and format information
if (SoundFiles[sound_file_index].sample_8bit == NULL && SoundFiles[sound_file_index].sample_16bit == NULL) {
mprintf(0, "SOUND LOADER: Did not find data and/or format in %s.\n", filename);
LOG_WARNING.printf("SOUND LOADER: Did not find data and/or format in %s.", filename);
goto error_state;
} else if (SoundFiles[sound_file_index].sample_8bit != NULL && !f_high_quality) {
// Doing the volume clipping with the low quality (8 bit) sound requires some tricky math -- see chris

View File

@ -449,7 +449,7 @@
#include "hlsoundlib.h"
#include "ssl_lib.h"
#include "mono.h"
#include "log.h"
#include "pserror.h"
#include "vecmat.h"
#include "args.h"
@ -504,7 +504,7 @@ void hlsSystem::SetLLSoundQuantity(int n_sounds) {
n_sounds = MAX_SOUNDS_MIXED;
}
n_lls_sounds = n_sounds;
mprintf(1, "SNDLIB: Allow %d sounds to be mixed.\n", n_sounds);
LOG_DEBUG.printf("SNDLIB: Allow %d sounds to be mixed.", n_sounds);
if (m_f_hls_system_init) {
InitSoundLib(NULL, Sound_mixer, Sound_quality, false);
}
@ -554,7 +554,7 @@ int hlsSystem::InitSoundLib(oeApplication *sos, char mixer_type, char quality, b
void hlsSystem::KillSoundLib(bool f_kill_sound_list) {
int i;
if (m_f_hls_system_init) {
mprintf(1, "m_sounds_played %d\n", m_sounds_played);
LOG_DEBUG.printf("m_sounds_played %d", m_sounds_played);
// clean up stream system
AudioStream::Shutdown();
for (i = 0; i < MAX_SOUND_OBJECTS; i++) {
@ -624,7 +624,7 @@ void hlsSystem::StopAllSounds() {
SoundRenderReset();
mprintf(0, "Stopped all sounds\n");
LOG_DEBUG << "Stopped all sounds";
}
// Code for the beginning and ending of a frame of action
// Begin_sound_frame(listener pos/orient/velocity)
@ -816,7 +816,6 @@ void hlsSystem::BeginSoundFrame(bool f_in_game) {
// mprintf(0, "BeginSoundFrame: used sound_objects %d\n", counter);
end_beginsoundframe:
AudioStream::Frame();
mprintf_at(3, 1, 0, "HNS: %04d", counter);
}
// Plays the deffered 3d stuff
@ -1101,7 +1100,7 @@ int hlsSystem::Play3dSound(int sound_index, pos_state *cur_pos, object *cur_obj,
}
// no free slots? hmmm....
if (i >= MAX_SOUND_OBJECTS) {
mprintf(2, "HLSOUNDLIB HOLY COW: Over %d sounds trying to play(beyond max) - %s\n", MAX_SOUND_OBJECTS,
LOG_WARNING.printf("HLSOUNDLIB HOLY COW: Over %d sounds trying to play(beyond max) - %s", MAX_SOUND_OBJECTS,
Sounds[sound_index].name);
// Int3();
return -1;
@ -1196,7 +1195,7 @@ int hlsSystem::Play2dSound(int sound_index, int priority, float volume, float pa
// mprintf(0, "HL %d\n", i);
// ASSERT(i < MAX_SOUND_OBJECTS);
if (i >= MAX_SOUND_OBJECTS) {
mprintf(3, "Play2DSound: Max Sounds Objects used\n");
LOG_WARNING << "Play2DSound: Max Sounds Objects used";
// Int3();
return -1;
}
@ -1227,7 +1226,7 @@ int hlsSystem::Play2dSound(int sound_index, int priority, float volume, float pa
if (m_sound_objects[i].m_sound_uid == -1) {
m_sound_objects[i].m_obj_type_flags = SIF_UNUSED;
m_sound_objects[i].m_hlsound_uid = -1;
mprintf(1, "Play2DSound: $%d Unplayed\n", i);
LOG_WARNING.printf("Play2DSound: $%d Unplayed", i);
return -1;
}
@ -1251,7 +1250,7 @@ int hlsSystem::PlayStream(int unique_handle, void *data, int size, int stream_fo
break;
}
if (i >= MAX_SOUND_OBJECTS) {
mprintf(2, "PlayStream:Max Sounds Objects\n");
LOG_WARNING << "PlayStream:Max Sounds Objects";
// Int3();
return -1;
}
@ -1275,7 +1274,7 @@ int hlsSystem::PlayStream(int unique_handle, void *data, int size, int stream_fo
if (m_sound_objects[i].m_sound_uid == -1) {
m_sound_objects[i].m_obj_type_flags = SIF_UNUSED;
m_sound_objects[i].m_hlsound_uid = -1;
mprintf(2, "LLSound full 1\n");
LOG_WARNING << "LLSound full 1";
return -1;
}
@ -1311,7 +1310,7 @@ void hlsSystem::StopSound(int sound_obj_index, uint8_t f_stop_priority) {
m_sound_objects[sound_obj_index].m_obj_type_flags &= (~SIF_LOOPING);
if (m_sound_objects[sound_obj_index].m_sound_uid != -1) {
mprintf(1, "stopSound %d \n", m_sound_objects[sound_obj_index].m_sound_uid);
LOG_DEBUG.printf("stopSound %d", m_sound_objects[sound_obj_index].m_sound_uid);
m_ll_sound_ptr->StopSound(m_sound_objects[sound_obj_index].m_sound_uid, f_stop_priority);
}
if (f_stop_priority == SKT_STOP_IMMEDIATELY || m_sound_objects[sound_obj_index].m_sound_uid == -1) {

View File

@ -19,7 +19,7 @@
#include <cstdlib>
#include <memory.h>
#include "mono.h"
#include "log.h"
#include "ssl_lib.h"
#include "mixer.h"
#include "pserror.h"
@ -50,7 +50,7 @@ software_mixer::~software_mixer() {
bool software_mixer::Initialize(tMixerInit *mi) {
if (m_init) {
mprintf(0, "Mixer: Already Init\n");
LOG_ERROR << "Mixer: Already Init";
Int3();
return false;
}
@ -58,7 +58,7 @@ bool software_mixer::Initialize(tMixerInit *mi) {
// Sam 6/29 - When using SDL, there's no primary buffer
// if(!mi->primary_buffer || !mi->ll_sound_ptr)
if (!mi->ll_sound_ptr) {
mprintf(0, "Mixer: Bad Value passed on init\n");
LOG_ERROR << "Mixer: Bad Value passed on init";
Int3();
return false;
}
@ -113,7 +113,7 @@ void software_mixer::StreamMixer(char *ptr, int len) {
// this code will assure that this function will not be called when sound system is in error mode.
if (*m_error_code != SSL_OK) {
mprintf(0, "MIX: Mixer in error code %d\n", *m_error_code);
LOG_ERROR.printf("MIX: Mixer in error code %d", *m_error_code);
return;
}
@ -121,7 +121,7 @@ void software_mixer::StreamMixer(char *ptr, int len) {
ASSERT(ptr && len >= 0);
if ((len % m_primary_alignment) != 0) {
mprintf(0, "MIX:Len is not aligned!\n");
LOG_ERROR << "MIX:Len is not aligned!";
(*m_fpSetError)(SSL_ERROR_STREAMMIXER);
(*m_fpErrorText)("ASSERT((len % ll_sound_ptr->m_primary_alignment) == 0)\nLen:%d PrA:%d", len, m_primary_alignment);
return;
@ -190,7 +190,7 @@ void software_mixer::StreamMixer(char *ptr, int len) {
loop_start = Sounds[sound_index].loop_start;
loop_end = Sounds[sound_index].loop_end;
if (!sample_16bit && !sample_8bit) {
mprintf(0, "sound file %s didn't have data for samples.\n", snd_file->name);
LOG_WARNING.printf("sound file %s didn't have data for samples.\n", snd_file->name);
}
}
@ -198,7 +198,7 @@ void software_mixer::StreamMixer(char *ptr, int len) {
// ASSERT(sample_16bit || sample_8bit);
if (!sample_16bit && !sample_8bit) {
sound_file_info *snd_file = &SoundFiles[Sounds[cur_buf->m_sound_index].sample_index];
mprintf(0, "MIX: No data for %s\n", snd_file->name);
LOG_WARNING.printf("MIX: No data for %s\n", snd_file->name);
(*m_fpSetError)(SSL_ERROR_SAMPLE_NODATA);
(*m_fpErrorText)("ASSERT(sample_16bit || sample_8bit)\nNo data found for sound file: %s", snd_file->name);
cur_buf->m_status = SSF_UNUSED;
@ -264,7 +264,6 @@ void software_mixer::StreamMixer(char *ptr, int len) {
if (num_write <= 0) {
num_write = 0;
mprintf(0, "d");
goto stream_done;
}
} else {
@ -286,7 +285,6 @@ void software_mixer::StreamMixer(char *ptr, int len) {
if ((num_write < 0) || (num_write > num_samples)) // this was an assert
{
num_write = 0;
mprintf(0, "D");
goto done;
}
@ -455,12 +453,12 @@ void software_mixer::StreamMixer(char *ptr, int len) {
}
loop_end -= 1;
} else {
mprintf(0, "SE: Data is NULL\n");
LOG_WARNING << "SE: Data is NULL";
cur_buf->m_status &= ~SSF_PLAY_STREAMING;
f_loop = false;
}
} else {
mprintf(0, "SE: Callback/data is NULL\n");
LOG_WARNING << "SE: Callback/data is NULL";
cur_buf->m_status &= ~SSF_PLAY_STREAMING;
f_loop = false;
}

View File

@ -25,7 +25,7 @@
#include "pserror.h"
#include "mem.h"
#include "mono.h"
#include "log.h"
#include "ssl_lib.h"
#include "application.h"
#include "sdlsound.h"
@ -105,7 +105,7 @@ int lnxsound::InitSoundLib(char mixer_type, oeApplication *sos, uint8_t max_soun
return false;
}
mprintf(0, "Sound: Hardware configured. Kicking off stream thread...");
LOG_INFO << "Sound: Hardware configured. Kicking off stream thread...";
SDL_PauseAudioDevice(sound_device, 0);
m_total_sounds_played = 0;
@ -254,17 +254,17 @@ int16_t lnxsound::FindFreeSoundSlot(float volume, int priority)
if (throw_out_slot > -1) {
sb = &sound_cache[throw_out_slot];
StopSound(sb->m_unique_id, SKT_HOLD_UNTIL_STOP);
mprintf(0, "DDSNDLIB: Replace sound (p:%d) with sound (p:%d) in slot %d\n", sb->play_info->priority, priority,
throw_out_slot);
LOG_DEBUG.printf("DDSNDLIB: Replace sound (p:%d) with sound (p:%d) in slot %d",
sb->play_info->priority, priority, throw_out_slot);
return throw_out_slot;
}
}
#ifdef _DEBUG
if (sound_index > -1) {
mprintf(0, "DDSNDLIB: Sound %s with priority (%d) too low.\n", Sounds[sound_index].name, priority);
LOG_DEBUG.printf("DDSNDLIB: Sound %s with priority (%d) too low.", Sounds[sound_index].name, priority);
} else {
mprintf(0, "DDSNDLIB: Sound unknown with priority (%d) too low.\n", priority);
LOG_DEBUG.printf("DDSNDLIB: Sound unknown with priority (%d) too low.", priority);
}
#endif
return -1;
@ -292,7 +292,7 @@ int lnxsound::PlaySound2d(play_information *play_info, int sound_index, float f_
// do common processing.
if (SoundFiles[Sounds[sound_index].sample_index].used == 0) {
mprintf(0, "Tryed to play %d sound, it DNE.\n", sound_index);
LOG_DEBUG.printf("Tried to play %d sound, it DNE.", sound_index);
return -1;
}
#ifdef _DEBUG
@ -617,7 +617,7 @@ bool lnxsound::CheckAndForceSoundDataAlloc(int sound_index) {
if (!result)
return false;
mprintf(0, "Sound %s loaded.\n", SoundFiles[sound_file_index].name);
LOG_DEBUG.printf("Sound %s loaded.", SoundFiles[sound_file_index].name);
return true;
}
@ -636,7 +636,7 @@ void lnxsound::SoundStartFrame() {
// perform necessary functions if sound events are pending for frame, this doesn't have to do anything
// if the mixer doesn't require such actions. Aureal does though.
if (m_pending_actions) {
mprintf(0, "pending actions\n");
LOG_DEBUG << "pending actions";
}
m_in_sound_frame = true;
@ -683,16 +683,6 @@ void lnxsound::SoundStartFrame() {
} else {
m_cache_stress_timer = 0.0f;
}
#ifdef _DEBUG
mprintf_at(3, 2, 0, "LNS: %02d/%02d", counter, MAX_SOUNDS_PLAYING_AT_ONCE);
mprintf_at(3, 3, 1, "Lp: %02d", loop_counter);
mprintf_at(3, 4, 1, "St: %02d", stream_counter);
mprintf_at(3, 5, 0, " Ot: %02d", counter - loop_counter - stream_counter);
mprintf_at(3, 2, 20, "P5:%02d P4:%02d P3:%02d", n_p5, n_p4, n_p3);
mprintf_at(3, 3, 20, "P2:%02d P1:%02d P0:%02d", n_p2, n_p1, n_p0);
#endif
}
// End sound frame

View File

@ -233,6 +233,7 @@
#include "ssl_lib.h"
#include "object.h"
#include "ddio.h"
#include "log.h"
#include "mem.h"
#include "soundload.h"
#include "weapon.h"
@ -422,7 +423,7 @@ int LoadSoundFile(const char *filename, float import_volume, bool f_get_data) {
// Make room for the new sound
sound_file_index = AllocSoundFile();
if (sound_file_index == -1) {
mprintf(0, "SOUND LOADER: No free sound file slots are available.\n", filename);
LOG_ERROR.printf("SOUND LOADER: No free sound file slots are available.", filename);
Int3();
return -1;
}
@ -431,7 +432,7 @@ int LoadSoundFile(const char *filename, float import_volume, bool f_get_data) {
len = strlen(filename);
if (len < 4) {
mprintf(0, "SOUND LOADER: %s does not have a 3 character extension.\n", filename);
LOG_ERROR.printf("SOUND LOADER: %s does not have a 3 character extension.", filename);
Int3(); // Get chris
goto error_state;
}
@ -442,11 +443,11 @@ int LoadSoundFile(const char *filename, float import_volume, bool f_get_data) {
strncpy(extension, &filename[len - 3], 5);
if (strnicmp("wav", extension, 3) == 0) {
if (!SoundLoadWaveFile(filename, import_volume, sound_file_index, false, f_get_data)) {
mprintf(0, "SOUND LOADER: Error loading %s.\n", filename);
LOG_ERROR.printf("SOUND LOADER: Error loading %s.", filename);
goto error_state;
}
} else {
mprintf(0, "SOUND LOADER: %s in not a supported file type.\n", extension);
LOG_ERROR.printf("SOUND LOADER: %s in not a supported file type.", extension);
goto error_state;
}