2020-10-25 17:17:26 +03:00
|
|
|
#pragma once
|
2021-01-23 13:33:30 +03:00
|
|
|
#include "maths.h"
|
2020-10-25 17:17:26 +03:00
|
|
|
|
|
|
|
|
2022-09-29 14:45:14 +03:00
|
|
|
class TPinballComponent;
|
|
|
|
struct zmap_header_type;
|
|
|
|
struct gdrv_bitmap8;
|
2021-10-01 18:55:44 +03:00
|
|
|
class DatFile;
|
2020-10-25 17:17:26 +03:00
|
|
|
|
|
|
|
struct errorMsg
|
|
|
|
{
|
|
|
|
int Code;
|
|
|
|
const char* Message;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct soundListStruct
|
|
|
|
{
|
2021-08-27 13:29:41 +03:00
|
|
|
Mix_Chunk* WavePtr;
|
2020-10-25 17:17:26 +03:00
|
|
|
int GroupIndex;
|
|
|
|
int Loaded;
|
2020-12-25 16:46:06 +03:00
|
|
|
float Duration;
|
2020-10-25 17:17:26 +03:00
|
|
|
};
|
|
|
|
|
2021-01-29 16:42:05 +03:00
|
|
|
struct visualKickerStruct
|
2020-10-30 15:26:00 +03:00
|
|
|
{
|
2021-01-23 13:33:30 +03:00
|
|
|
float Threshold;
|
|
|
|
float Boost;
|
|
|
|
float ThrowBallMult;
|
2022-05-20 11:51:00 +03:00
|
|
|
vector3 ThrowBallDirection;
|
2021-01-23 13:33:30 +03:00
|
|
|
float ThrowBallAngleMult;
|
|
|
|
int HardHitSoundId;
|
2020-10-30 15:26:00 +03:00
|
|
|
};
|
|
|
|
|
2022-09-29 14:45:14 +03:00
|
|
|
struct SpriteData
|
|
|
|
{
|
|
|
|
gdrv_bitmap8* Bmp;
|
|
|
|
zmap_header_type* ZMap;
|
|
|
|
};
|
2020-10-30 15:26:00 +03:00
|
|
|
|
2021-01-29 16:42:05 +03:00
|
|
|
struct visualStruct
|
2020-10-30 15:26:00 +03:00
|
|
|
{
|
2021-01-23 13:33:30 +03:00
|
|
|
float Smoothness;
|
|
|
|
float Elasticity;
|
2020-12-20 14:13:12 +03:00
|
|
|
int FloatArrCount;
|
2020-10-30 15:26:00 +03:00
|
|
|
float* FloatArr;
|
2021-01-23 13:33:30 +03:00
|
|
|
int SoftHitSoundId;
|
2020-10-30 15:26:00 +03:00
|
|
|
visualKickerStruct Kicker;
|
2021-01-28 18:01:26 +03:00
|
|
|
int CollisionGroup;
|
2020-10-30 15:26:00 +03:00
|
|
|
int SoundIndex4;
|
|
|
|
int SoundIndex3;
|
2022-09-29 14:45:14 +03:00
|
|
|
SpriteData Bitmap;
|
2020-10-30 15:26:00 +03:00
|
|
|
};
|
|
|
|
|
2021-08-18 12:44:26 +03:00
|
|
|
#pragma pack(push)
|
|
|
|
#pragma pack(1)
|
|
|
|
// WAVE file header format
|
|
|
|
struct WaveHeader
|
|
|
|
{
|
|
|
|
unsigned char riff[4]; // RIFF string
|
|
|
|
|
|
|
|
unsigned int overall_size; // overall size of file in bytes
|
|
|
|
|
|
|
|
unsigned char wave[4]; // WAVE string
|
|
|
|
|
|
|
|
unsigned char fmt_chunk_marker[4]; // fmt string with trailing null char
|
|
|
|
|
|
|
|
unsigned int length_of_fmt; // length of the format data
|
|
|
|
|
|
|
|
unsigned short format_type; // format type. 1-PCM, 3- IEEE float, 6 - 8bit A law, 7 - 8bit mu law
|
|
|
|
|
|
|
|
unsigned short channels; // no.of channels
|
|
|
|
|
|
|
|
unsigned int sample_rate; // sampling rate (blocks per second)
|
|
|
|
|
|
|
|
unsigned int byterate; // SampleRate * NumChannels * BitsPerSample/8
|
|
|
|
|
|
|
|
unsigned short block_align; // NumChannels * BitsPerSample/8
|
|
|
|
|
|
|
|
unsigned short bits_per_sample; // bits per sample, 8- 8bits, 16- 16 bits etc
|
|
|
|
|
|
|
|
unsigned char data_chunk_header[4]; // DATA string or FLLR string
|
|
|
|
|
|
|
|
unsigned int data_size; // NumSamples * NumChannels * BitsPerSample/8 - size of the next chunk that will be read
|
|
|
|
};
|
|
|
|
#pragma pack(pop)
|
|
|
|
static_assert(sizeof(WaveHeader) == 44, "Wrong size of WaveHeader");
|
|
|
|
|
2020-10-25 17:17:26 +03:00
|
|
|
|
|
|
|
class loader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static int error(int errorCode, int captionCode);
|
2020-10-30 15:26:00 +03:00
|
|
|
static void default_vsi(visualStruct* visual);
|
2020-10-25 17:17:26 +03:00
|
|
|
static int get_sound_id(int groupIndex);
|
2020-10-30 15:26:00 +03:00
|
|
|
static void unload();
|
2021-09-21 13:14:39 +03:00
|
|
|
static void loadfrom(DatFile* datFile);
|
2020-10-25 17:17:26 +03:00
|
|
|
static int query_handle(LPCSTR lpString);
|
|
|
|
static short query_visual_states(int groupIndex);
|
2020-10-30 15:26:00 +03:00
|
|
|
static int material(int groupIndex, visualStruct* visual);
|
|
|
|
static int kicker(int groupIndex, visualKickerStruct* kicker);
|
|
|
|
static int state_id(int groupIndex, int groupIndexOffset);
|
|
|
|
static int query_visual(int groupIndex, int groupIndexOffset, visualStruct* visual);
|
2020-10-25 17:17:26 +03:00
|
|
|
static char* query_name(int groupIndex);
|
|
|
|
static float* query_float_attribute(int groupIndex, int groupIndexOffset, int firstValue);
|
2021-01-31 17:29:53 +03:00
|
|
|
static float query_float_attribute(int groupIndex, int groupIndexOffset, int firstValue, float defVal);
|
2021-02-16 19:03:45 +03:00
|
|
|
static int16_t* query_iattribute(int groupIndex, int firstValue, int* arraySize);
|
Implement stereo sound. (#138)
* Implement stereo sound.
Original Space Cadet has mono sound. To achieve stereo, the following
steps were accomplished:
- Add a game option to turn on/off stereo sound. Default is on.
- TPinballComponent objects were extended with a method called
get_coordinates() that returns a single 2D point, approximating the
on-screen position of the object, re-mapped between 0 and 1 vertically
and horizontally, {0, 0} being at the top-left.
- For static objects like bumpers and lights, the coordinate refers
to the geometric center of the corresponding graphic sprite, and
is precalculated at initialization.
- For ball objects, the coordinate refers to the geometric center of
the ball, calculated during play when requested.
- Extend all calls to sound-playing methods so that they include a
TPinballComponent* argument that refers to the sound source, e.g.
where the sound comes from. For instance, when a flipper is
activated, its method call to emit a sound now includes a reference to
the flipper object; when a ball goes under a SkillShotGate, its method
call to emit a sound now includes a reference to the corresponding
light; and so on.
For some cases, like light rollovers, the sound source is taken from
the ball that triggered the light rollover.
For other cases, like holes, flags and targets, the sound source is
taken from the object itself.
For some special cases like ramp activation, sound source is
taken from the nearest light position that makes sense.
For all game-progress sounds, like mission completion sounds or ball
drain sounds, the sound source is undefined (set to nullptr), and the
Sound::PlaySound() method takes care of positioning them at a default
location, where speakers on a pinball machine normally are.
- Make the Sound::PlaySound() method accept a new argument, a
TPinballComponent reference, as described above.
If the stereo option is turned on, the Sound::PlaySound() method calls
the get_coordinates() method of the TPinballComponent reference to get
the sound position.
This project uses SDL_mixer and there is a function called
Mix_SetPosition() that allows placing a sound in the stereo field, by
giving it a distance and an angle.
We arbitrarily place the player's ears at the bottom of the table; we
set the ears' height to half a table's length. Intensity of the
stereo effect is directly related to this value; the farther the
player's ears from the table, the narrowest the stereo picture gets,
and vice-versa.
From there we have all we need to calculate distance and angle; we do
just that and position all the sounds.
* Copy-paste typo fix.
2022-05-30 03:35:29 -04:00
|
|
|
static float play_sound(int soundIndex, TPinballComponent *soundSource, const char* info);
|
2021-09-21 13:14:39 +03:00
|
|
|
static DatFile* loader_table;
|
2020-11-01 18:45:29 +03:00
|
|
|
private:
|
2021-01-29 16:42:05 +03:00
|
|
|
static errorMsg loader_errors[];
|
2021-09-21 13:14:39 +03:00
|
|
|
static DatFile* sound_record_table;
|
2020-10-25 17:17:26 +03:00
|
|
|
static int sound_count;
|
|
|
|
static int loader_sound_count;
|
|
|
|
static soundListStruct sound_list[65];
|
|
|
|
};
|