You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

201 lines
4.1 KiB

#include "../types.h"
#include "stubs.h"
#include <SDL_image.h>
#include <SDL_mixer.h>
/*
#ifndef NO_GLOBALS
char gbSndInited;
char gbDupSounds;
UCHAR gbMusicOn;
UCHAR gbSoundOn;
#endif
*/
bool SoundInited;
char gbSndInited;
char gbDupSounds;
UCHAR gbMusicOn;
UCHAR gbSoundOn;
Mix_Music *gMusic = NULL;
Mix_Chunk *sample;
Mix_Music *music;
char *sgszMusicTracks[6] = {"Music\\DTowne.wav", "Music\\DLvlA.wav", "Music\\DLvlB.wav",
"Music\\DLvlC.wav", "Music\\DLvlD.wav", "Music\\Dintro.wav"};
void __fastcall snd_init(HWND hWnd)
{
DUMMY();
printf("SND INIT\n\n");
// Initialize SDL.
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
printf("ERROR : %s\n\n", SDL_GetError());
}
if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) < 0) {
printf("SDL_mixer could not initialize! SDL_mixer Error: %s\n", Mix_GetError());
}
gbSndInited = 1;
gbSoundOn = 1;
SoundInited = 1;
}
void *sgpMusicTrack;
void *buffer;
int bytestoread;
int channel = 2;
SDL_AudioSpec wanted;
static Uint8 *audio_chunk;
static Uint32 audio_len;
static Uint8 *audio_pos;
void fill_audio(void *udata, Uint8 *stream, int len)
{
/* Only play if we have data left */
if ( audio_len == 0 )
return;
/* Mix as much data as possible */
len = ( len > audio_len ? audio_len : len );
SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
audio_pos += len;
audio_len -= len;
}
void __fastcall music_start(int nTrack)
{
DUMMY();
wanted.freq = 22050;
wanted.format = AUDIO_S8;
wanted.channels = 5; /* 1 = mono, 2 = stereo */
wanted.samples = 1024; /* Good low-latency value for callback */
wanted.callback = fill_audio;
wanted.userdata = NULL;
gbSoundOn = true;
gbMusicOn = true;
int nread;
void *file;
int v6;
if (buffer != NULL) {
music_stop();
}
if (SoundInited) {
/// I know this needs clean up... I haven't the time to do this.
SFileOpenFile(sgszMusicTracks[nTrack], &sgpMusicTrack);
// This is a hack.... I don't like it .
// If you know this better than I , please help clean it up.
//SDL_OpenAudio(&wanted, NULL);
if (nTrack == 0) {
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 16);
channel = 2;
}
if (nTrack == 1) {
Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 1, 16);
channel = 1;
}
file = sgpMusicTrack;
bytestoread = (int)SFileGetFileSize((HANDLE)file, 0);
buffer = DiabloAllocPtr(bytestoread);
SFileReadFile(file, (char *)buffer, bytestoread, (unsigned long *)&nread, 0);
Mix_Chunk *Music = Mix_QuickLoad_WAV((Uint8 *)buffer);
Mix_PlayChannel(channel, Music, 0);
}
}
void *SFXbuffer;
int SFXsoundch = 1;
void LoadAndPlaySound(char *FilePath, int lVolume, int lPan)
{
int nrread;
void *file;
SFileOpenFile(FilePath, &SFXbuffer);
//Mix_OpenAudio(20000, AUDIO_S8, 3, 4096);
file = SFXbuffer;
bytestoread = (int)SFileGetFileSize((HANDLE)file, 0);
SFXbuffer = DiabloAllocPtr(bytestoread);
SFileReadFile(file, (char *)SFXbuffer, bytestoread, (unsigned long *)&nrread, 0);
Mix_Chunk *SoundFX = Mix_QuickLoad_WAV((Uint8 *)SFXbuffer);
Mix_PlayChannel(3, SoundFX, 0);
//Mix_FreeChunk(SoundFX);
}
void __cdecl music_stop()
{
DUMMY();
Mix_HaltMusic();
}
BOOL __fastcall snd_playing(TSnd *pSnd)
{
UNIMPLEMENTED();
}
void __fastcall snd_play_snd(TSnd *pSnd, int lVolume, int lPan)
{
//printf("Sound File %s",pSnd );
//UNIMPLEMENTED();
}
void __fastcall snd_stop_snd(TSnd *pSnd)
{
DUMMY();
Mix_HaltMusic();
}
TSnd *__fastcall sound_file_load(char *path)
{
printf("Sound_File_Load %s", path);
//UNIMPLEMENTED();
}
void __fastcall sound_file_cleanup(TSnd *sound_file)
{
UNIMPLEMENTED();
}
int __fastcall sound_get_or_set_sound_volume(int volume)
{
DUMMY_PRINT("volume: %d", volume);
return volume;
}
int __fastcall sound_get_or_set_music_volume(int volume)
{
DUMMY_PRINT("volume: %d", volume);
return volume;
}
void __fastcall snd_update(BOOL bStopAll)
{
//DUMMY_PRINT("stopall: %d", bStopAll);
}