2014-06-01 17:55:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the DXX-Rebirth project <http://www.dxx-rebirth.com/>.
|
|
|
|
* It is copyright by its individual contributors, as recorded in the
|
|
|
|
* project's Git history. See COPYING.txt at the top level for license
|
|
|
|
* terms and a link to the Git history.
|
|
|
|
*/
|
2006-10-06 16:34:53 +00:00
|
|
|
/*
|
2007-09-18 13:37:39 +00:00
|
|
|
* Digital audio support
|
|
|
|
* Library-independent stub for dynamic selection of sound system
|
2006-10-06 16:34:53 +00:00
|
|
|
*/
|
|
|
|
|
2012-07-07 18:35:06 +00:00
|
|
|
#include "dxxerror.h"
|
2010-06-14 08:13:16 +00:00
|
|
|
#include "vecmat.h"
|
|
|
|
#include "piggy.h"
|
2014-06-03 01:34:39 +00:00
|
|
|
#include "config.h"
|
2010-06-14 08:13:16 +00:00
|
|
|
#include "digi.h"
|
|
|
|
#include "sounds.h"
|
2008-04-06 20:23:28 +00:00
|
|
|
#include "console.h"
|
2009-03-03 12:55:27 +00:00
|
|
|
#include "rbaudio.h"
|
|
|
|
#include "jukebox.h"
|
2013-03-03 01:03:33 +00:00
|
|
|
#include "args.h"
|
2006-03-20 16:43:15 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2007-09-18 13:37:39 +00:00
|
|
|
#include <digi.h>
|
|
|
|
#include <digi_audio.h>
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2007-09-18 13:37:39 +00:00
|
|
|
#ifdef USE_SDLMIXER
|
|
|
|
#include <digi_mixer.h>
|
2006-03-20 16:43:15 +00:00
|
|
|
#endif
|
2010-06-15 18:27:10 +00:00
|
|
|
#ifdef _WIN32
|
2010-07-18 20:28:15 +00:00
|
|
|
#include "hmp.h"
|
2010-06-15 18:27:10 +00:00
|
|
|
#endif
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2007-09-18 13:37:39 +00:00
|
|
|
/* Sound system function pointers */
|
|
|
|
|
|
|
|
int (*fptr_init)() = NULL;
|
|
|
|
void (*fptr_close)() = NULL;
|
|
|
|
void (*fptr_reset)() = NULL;
|
|
|
|
|
|
|
|
void (*fptr_set_channel_volume)(int, int) = NULL;
|
|
|
|
void (*fptr_set_channel_pan)(int, int) = NULL;
|
|
|
|
|
|
|
|
int (*fptr_start_sound)(short, fix, int, int, int, int, int) = NULL;
|
|
|
|
void (*fptr_stop_sound)(int) = NULL;
|
|
|
|
void (*fptr_end_sound)(int) = NULL;
|
|
|
|
|
|
|
|
int (*fptr_is_sound_playing)(int) = NULL;
|
|
|
|
int (*fptr_is_channel_playing)(int) = NULL;
|
|
|
|
void (*fptr_stop_all_channels)() = NULL;
|
|
|
|
void (*fptr_set_digi_volume)(int) = NULL;
|
|
|
|
|
|
|
|
void digi_select_system(int n) {
|
|
|
|
switch (n) {
|
|
|
|
#ifdef USE_SDLMIXER
|
|
|
|
case SDLMIXER_SYSTEM:
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf(CON_NORMAL,"Using SDL_mixer library");
|
2007-09-18 13:37:39 +00:00
|
|
|
fptr_init = digi_mixer_init;
|
|
|
|
fptr_close = digi_mixer_close;
|
|
|
|
fptr_reset = digi_mixer_reset;
|
|
|
|
fptr_set_channel_volume = digi_mixer_set_channel_volume;
|
|
|
|
fptr_set_channel_pan = digi_mixer_set_channel_pan;
|
|
|
|
fptr_start_sound = digi_mixer_start_sound;
|
|
|
|
fptr_stop_sound = digi_mixer_stop_sound;
|
|
|
|
fptr_end_sound = digi_mixer_end_sound;
|
|
|
|
fptr_is_sound_playing = digi_mixer_is_sound_playing;
|
|
|
|
fptr_is_channel_playing = digi_mixer_is_channel_playing;
|
|
|
|
fptr_stop_all_channels = digi_mixer_stop_all_channels;
|
|
|
|
fptr_set_digi_volume = digi_mixer_set_digi_volume;
|
|
|
|
break;
|
2006-10-06 16:34:53 +00:00
|
|
|
#endif
|
2007-09-18 13:37:39 +00:00
|
|
|
case SDLAUDIO_SYSTEM:
|
|
|
|
default:
|
2013-12-07 00:47:27 +00:00
|
|
|
con_printf(CON_NORMAL,"Using plain old SDL audio");
|
2007-09-18 13:37:39 +00:00
|
|
|
fptr_init = digi_audio_init;
|
|
|
|
fptr_close = digi_audio_close;
|
|
|
|
fptr_reset = digi_audio_reset;
|
|
|
|
fptr_set_channel_volume = digi_audio_set_channel_volume;
|
|
|
|
fptr_set_channel_pan = digi_audio_set_channel_pan;
|
|
|
|
fptr_start_sound = digi_audio_start_sound;
|
|
|
|
fptr_stop_sound = digi_audio_stop_sound;
|
|
|
|
fptr_end_sound = digi_audio_end_sound;
|
|
|
|
fptr_is_sound_playing = digi_audio_is_sound_playing;
|
|
|
|
fptr_is_channel_playing = digi_audio_is_channel_playing;
|
|
|
|
fptr_stop_all_channels = digi_audio_stop_all_channels;
|
|
|
|
fptr_set_digi_volume = digi_audio_set_digi_volume;
|
|
|
|
break;
|
2006-03-20 16:43:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-18 13:37:39 +00:00
|
|
|
/* Common digi functions */
|
2007-12-29 14:18:49 +00:00
|
|
|
#ifndef NDEBUG
|
2007-09-18 19:24:44 +00:00
|
|
|
static int digi_initialised = 0;
|
2007-12-29 14:18:49 +00:00
|
|
|
#endif
|
2013-03-03 01:03:33 +00:00
|
|
|
#if defined(DXX_BUILD_DESCENT_I)
|
2007-09-18 13:37:39 +00:00
|
|
|
int digi_sample_rate = SAMPLE_RATE_11K;
|
2013-03-03 01:03:33 +00:00
|
|
|
#endif
|
2007-09-18 13:37:39 +00:00
|
|
|
int digi_volume = SOUND_MAX_VOLUME;
|
2006-10-06 16:34:53 +00:00
|
|
|
|
2010-06-14 08:13:16 +00:00
|
|
|
void digi_set_volume(int dvolume) {
|
2007-09-18 13:37:39 +00:00
|
|
|
digi_volume = dvolume;
|
|
|
|
if (fptr_set_digi_volume) digi_set_digi_volume(dvolume);
|
2006-10-06 16:34:53 +00:00
|
|
|
}
|
|
|
|
|
2007-09-18 13:37:39 +00:00
|
|
|
/* Stub functions */
|
2006-10-06 16:34:53 +00:00
|
|
|
|
2008-09-30 00:07:07 +00:00
|
|
|
int digi_init()
|
2010-06-14 08:13:16 +00:00
|
|
|
{
|
2008-09-30 00:07:07 +00:00
|
|
|
digi_init_sounds();
|
|
|
|
return fptr_init();
|
|
|
|
}
|
|
|
|
|
2007-09-18 13:37:39 +00:00
|
|
|
void digi_close() { fptr_close(); }
|
|
|
|
void digi_reset() { fptr_reset(); }
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2007-09-18 13:37:39 +00:00
|
|
|
void digi_set_channel_volume(int channel, int volume) { fptr_set_channel_volume(channel, volume); }
|
|
|
|
void digi_set_channel_pan(int channel, int pan) { fptr_set_channel_pan(channel, pan); }
|
2006-03-20 16:43:15 +00:00
|
|
|
|
2007-09-18 13:37:39 +00:00
|
|
|
int digi_start_sound(short soundnum, fix volume, int pan, int looping, int loop_start, int loop_end, int soundobj) { return fptr_start_sound(soundnum, volume, pan, looping, loop_start, loop_end, soundobj); }
|
|
|
|
void digi_stop_sound(int channel) { fptr_stop_sound(channel); }
|
|
|
|
void digi_end_sound(int channel) { fptr_end_sound(channel); }
|
2007-06-15 08:10:19 +00:00
|
|
|
|
2007-09-18 13:37:39 +00:00
|
|
|
int digi_is_sound_playing(int soundno) { return fptr_is_sound_playing(soundno); }
|
|
|
|
int digi_is_channel_playing(int channel) { return fptr_is_channel_playing(channel); }
|
|
|
|
void digi_stop_all_channels() { fptr_stop_all_channels(); }
|
|
|
|
void digi_set_digi_volume(int dvolume) { fptr_set_digi_volume(dvolume); }
|
2006-10-06 16:34:53 +00:00
|
|
|
|
2010-06-14 08:13:16 +00:00
|
|
|
#ifndef NDEBUG
|
|
|
|
void digi_debug()
|
2009-03-03 12:55:27 +00:00
|
|
|
{
|
2010-06-14 08:13:16 +00:00
|
|
|
int n_voices = 0;
|
|
|
|
|
|
|
|
if (!digi_initialised) return;
|
|
|
|
|
2014-09-26 02:42:13 +00:00
|
|
|
for (int i = 0; i < digi_max_channels; i++)
|
2009-03-03 12:55:27 +00:00
|
|
|
{
|
2010-06-14 08:13:16 +00:00
|
|
|
if (digi_is_channel_playing(i))
|
|
|
|
n_voices++;
|
|
|
|
}
|
|
|
|
}
|
2009-03-03 12:55:27 +00:00
|
|
|
#endif
|
2010-06-14 08:13:16 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Windows native-MIDI stuff.
|
2010-06-15 18:27:10 +00:00
|
|
|
int digi_win32_midi_song_playing=0;
|
2014-08-05 02:29:43 +00:00
|
|
|
static std::unique_ptr<hmp_file> cur_hmp;
|
2011-07-15 08:43:01 +00:00
|
|
|
static int firstplay = 1;
|
2010-07-18 20:28:15 +00:00
|
|
|
|
2010-06-14 08:13:16 +00:00
|
|
|
void digi_win32_set_midi_volume( int mvolume )
|
|
|
|
{
|
2014-08-05 02:29:43 +00:00
|
|
|
hmp_setvolume(cur_hmp.get(), mvolume*MIDI_VOLUME_SCALE/8);
|
2010-06-14 08:13:16 +00:00
|
|
|
}
|
|
|
|
|
2013-08-03 20:02:45 +00:00
|
|
|
int digi_win32_play_midi_song( const char * filename, int loop )
|
2010-06-14 08:13:16 +00:00
|
|
|
{
|
2011-07-15 08:43:01 +00:00
|
|
|
if (firstplay)
|
|
|
|
{
|
|
|
|
hmp_reset();
|
|
|
|
firstplay = 0;
|
|
|
|
}
|
|
|
|
digi_win32_stop_midi_song();
|
2010-06-14 08:13:16 +00:00
|
|
|
|
|
|
|
if (filename == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2010-07-18 20:28:15 +00:00
|
|
|
if ((cur_hmp = hmp_open(filename)))
|
2010-06-14 08:13:16 +00:00
|
|
|
{
|
2011-01-09 16:51:45 +00:00
|
|
|
/*
|
|
|
|
* FIXME: to be implemented as soon as we have some kind or checksum function - replacement for ugly hack in hmp.c for descent.hmp
|
|
|
|
* if (***filesize check*** && ***CRC32 or MD5 check***)
|
|
|
|
* (((*cur_hmp).trks)[1]).data[6] = 0x6C;
|
|
|
|
*/
|
2014-08-05 02:29:43 +00:00
|
|
|
if (hmp_play(cur_hmp.get(),loop) != 0)
|
2010-06-14 08:13:16 +00:00
|
|
|
return 0; // error
|
2010-06-15 18:27:10 +00:00
|
|
|
digi_win32_midi_song_playing = 1;
|
2010-11-28 15:49:32 +00:00
|
|
|
digi_win32_set_midi_volume(GameCfg.MusicVolume);
|
2010-06-14 08:13:16 +00:00
|
|
|
return 1;
|
2009-03-03 12:55:27 +00:00
|
|
|
}
|
2010-06-14 08:13:16 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-03-03 12:55:27 +00:00
|
|
|
}
|
|
|
|
|
2010-11-28 15:49:32 +00:00
|
|
|
void digi_win32_pause_midi_song()
|
|
|
|
{
|
2014-08-05 02:29:43 +00:00
|
|
|
hmp_pause(cur_hmp.get());
|
2010-11-28 15:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void digi_win32_resume_midi_song()
|
|
|
|
{
|
2014-08-05 02:29:43 +00:00
|
|
|
hmp_resume(cur_hmp.get());
|
2010-11-28 15:49:32 +00:00
|
|
|
}
|
|
|
|
|
2011-07-15 08:43:01 +00:00
|
|
|
void digi_win32_stop_midi_song()
|
2010-06-14 08:13:16 +00:00
|
|
|
{
|
2011-07-07 23:46:27 +00:00
|
|
|
if (!digi_win32_midi_song_playing)
|
|
|
|
return;
|
2014-08-05 02:29:43 +00:00
|
|
|
cur_hmp.reset();
|
2011-07-07 23:46:27 +00:00
|
|
|
digi_win32_midi_song_playing = 0;
|
2010-11-28 15:49:32 +00:00
|
|
|
hmp_reset();
|
2008-04-06 20:23:28 +00:00
|
|
|
}
|
2007-09-18 19:24:44 +00:00
|
|
|
#endif
|