Skip to content

Commit

Permalink
PC Speaker sound implementation
Browse files Browse the repository at this point in the history
Thanks @nukeykt !

Corresponding PCDoom commit: nukeykt/PCDoom-v2@26e8291
  • Loading branch information
AXDOOMER committed May 29, 2017
1 parent e49aa81 commit b5e66fe
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 30 deletions.
107 changes: 85 additions & 22 deletions DMX.C
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//
// Copyright (C) 2015 Alexey Khokholov (Nuke.YKT)
// Copyright (C) 2005-2014 Simon Howard
// Copyright (C) 2015-2017 Alexey Khokholov (Nuke.YKT)
// Copyright (C) 2017 Alexandre-Xavier Labonté-Lamoureux
//
// This program is free software; you can redistribute it and/or
Expand All @@ -21,6 +22,42 @@
#include "music.h"
#include "task_man.h"
#include "mus2mid.h"
#include "pcfx.h"

unsigned short divisors[] = {
0,
6818, 6628, 6449, 6279, 6087, 5906, 5736, 5575,
5423, 5279, 5120, 4971, 4830, 4697, 4554, 4435,
4307, 4186, 4058, 3950, 3836, 3728, 3615, 3519,
3418, 3323, 3224, 3131, 3043, 2960, 2875, 2794,
2711, 2633, 2560, 2485, 2415, 2348, 2281, 2213,
2153, 2089, 2032, 1975, 1918, 1864, 1810, 1757,
1709, 1659, 1612, 1565, 1521, 1478, 1435, 1395,
1355, 1316, 1280, 1242, 1207, 1173, 1140, 1107,
1075, 1045, 1015, 986, 959, 931, 905, 879,
854, 829, 806, 783, 760, 739, 718, 697,
677, 658, 640, 621, 604, 586, 570, 553,
538, 522, 507, 493, 479, 465, 452, 439,
427, 415, 403, 391, 380, 369, 359, 348,
339, 329, 319, 310, 302, 293, 285, 276,
269, 261, 253, 246, 239, 232, 226, 219,
213, 207, 201, 195, 190, 184, 179,
};

typedef struct {
unsigned int length;
unsigned short priority;
unsigned short data[0x10000];
} pcspkmuse_t;

typedef struct {
unsigned short id;
unsigned short length;
unsigned char data[];
} dmxpcs_t;

pcspkmuse_t pcspkmuse;
int pcshandle = 0;

void TSM_Install(int rate) {

Expand Down Expand Up @@ -156,26 +193,54 @@ int MUS_PlaySong(int handle, int volume) {
}

int SFX_PlayPatch(void *vdata, int pitch, int sep, int vol, int unk1, int unk2) {
unsigned int rate;
unsigned long len;
unsigned char *data = (unsigned char*)vdata;
unsigned int type = (data[1] << 8) | data[0];
unsigned int rate = (data[3] << 8) | data[2];
unsigned long len = (data[7] << 24) | (data[6] << 16) | (data[5] << 8) | data[4];
if (type != 3) {
return -1;
dmxpcs_t *dmxpcs = (dmxpcs_t*)vdata;
unsigned short i;
if (type == 0)
{
pcspkmuse.length = dmxpcs->length * 2;
pcspkmuse.priority = 100;
for (i = 0; i < dmxpcs->length; i++)
{
pcspkmuse.data[i] = divisors[dmxpcs->data[i]];
}
pcshandle = PCFX_Play((PCSound *)&pcspkmuse, 100, 0);
return pcshandle | 0x8000;
}
if (len <= 48) {
return -1;
else if (type == 3)
{
rate = (data[3] << 8) | data[2];
len = (data[7] << 24) | (data[6] << 16) | (data[5] << 8) | data[4];
if (len <= 48) {
return -1;
}
len -= 32;
return FX_PlayRaw(data + 24, len, rate, ((pitch - 128) * 2400) / 128, vol * 2, ((254 - sep) * vol) / 63, ((sep)* vol) / 63, 100, 0);
}
len -= 32;
return FX_PlayRaw(data + 24, len, rate, ((pitch - 128) * 2400) / 128, vol * 2, ((254 - sep) * vol) / 63, ((sep)* vol) / 63, 100, 0);
}
void SFX_StopPatch(int handle) {
if (handle & 0x8000)
{
PCFX_Stop(handle & 0x7fff);
return;
}
FX_StopSound(handle);
}
int SFX_Playing(int handle) {
if (handle & 0x8000)
{
return PCFX_SoundPlaying(handle & 0x7fff);
}
return FX_SoundActive(handle);
}
void SFX_SetOrigin(int handle, int pitch, int sep, int vol) {
if (handle & 0x8000)
{
return;
}
FX_SetPan(handle, vol * 2, ((254 - sep) * vol) / 63, ((sep)* vol) / 63);
FX_SetPitch(handle, ((pitch - 128) * 2400) / 128);
}
Expand Down Expand Up @@ -268,6 +333,7 @@ void MPU_SetCard(int port) {
int DMX_Init(int rate, int maxsng, int mdev, int sdev) {
long status, device;
dmx_sdev = sdev;
status = 0;

switch (mdev) {
case 0:
Expand All @@ -289,25 +355,23 @@ int DMX_Init(int rate, int maxsng, int mdev, int sdev) {
return -1;
break;
}
if (device == SoundBlaster) {

int MaxVoices;
int MaxBits;
int MaxChannels;

FX_SetupSoundBlaster(dmx_blaster, (int *)&MaxVoices, (int *)&MaxBits, (int *)&MaxChannels);
}
status = MUSIC_Init(device, dmx_mus_port);
if (status != MUSIC_Ok) {
return -1;
if (status == MUSIC_Ok) {
MUSIC_SetVolume(0);
}
MUSIC_SetVolume(0);
return 0;
if (sdev & AHW_PC_SPEAKER)
{
PCFX_Init();
PCFX_SetTotalVolume(255);
PCFX_UseLookup(0, 0);
}
return mdev | sdev;
}

void DMX_DeInit(void) {
MUSIC_Shutdown();
FX_Shutdown();
PCFX_Shutdown();
remove("ULTRAMID.INI");
if (mid_data)
{
Expand Down Expand Up @@ -342,7 +406,6 @@ void WAV_PlayMode(int channels, int samplerate) {
}
status = FX_Init(device, channels, 2, 16, samplerate);
FX_SetVolume(255);
printf("Status %i %i %i %i\n", device, device + 10, SoundBlaster, status);
}

int CODEC_Detect(int *a, int *b)
Expand Down
69 changes: 69 additions & 0 deletions PCFX.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright (C) 1994-1995 Apogee Software, Ltd.
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 2
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, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**********************************************************************
module: PCFX.H
author: James R. Dose
date: April 1, 1994
Public header for ADLIBFX.C
(c) Copyright 1994 James R. Dose. All Rights Reserved.
**********************************************************************/

#ifndef __PCFX_H
#define __PCFX_H

enum PCFX_Errors
{
PCFX_Warning = -2,
PCFX_Error = -1,
PCFX_Ok = 0,
PCFX_NoVoices,
PCFX_VoiceNotFound,
PCFX_DPMI_Error
};

#define PCFX_MaxVolume 255
#define PCFX_MinVoiceHandle 1

typedef struct
{
unsigned long length;
short int priority;
char data[];
} PCSound;

char *PCFX_ErrorString( int ErrorNumber );
int PCFX_Stop( int handle );
void PCFX_UseLookup( int use, unsigned value );
int PCFX_VoiceAvailable( int priority );
int PCFX_Play( PCSound *sound, int priority, unsigned long callbackval );
int PCFX_SoundPlaying( int handle );
int PCFX_SetTotalVolume( int volume );
int PCFX_GetTotalVolume( void );
void PCFX_SetCallBack( void ( *function )( unsigned long ) );
int PCFX_Init( void );
int PCFX_Shutdown( void );
#pragma aux PCFX_Shutdown frame;
void PCFX_UnlockMemory( void );
int PCFX_LockMemory( void );

#endif
Binary file added PCFX.OBJ
Binary file not shown.
38 changes: 37 additions & 1 deletion pcdoom.tgt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ WVList
0
10
WPickList
58
60
11
MItem
3
Expand Down Expand Up @@ -1207,3 +1207,39 @@ WVList
1
1
0
273
MItem
5
*.OBJ
274
WString
3
NIL
275
WVList
0
276
WVList
0
-1
1
1
0
277
MItem
8
PCFX.OBJ
278
WString
3
NIL
279
WVList
0
280
WVList
0
273
1
1
0
14 changes: 7 additions & 7 deletions pcdoom.wpj
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ projectIdent
VpeMain
1
WRect
1641
160
8448
1476
80
8440
9280
2
MProject
Expand All @@ -30,14 +30,14 @@ VComponent
WRect
0
0
5652
7093
5644
7080
0
0
9
WFileName
10
pcdoom.tgt
0
1
25
43
7

0 comments on commit b5e66fe

Please sign in to comment.