remove SAMPLE_DATA length hack

This commit is contained in:
rr- 2021-03-29 23:49:53 +02:00
parent 0bbaeea3df
commit f1ccd02c30
No known key found for this signature in database
GPG key ID: CC65E6FD28CAE42A
2 changed files with 11 additions and 21 deletions

View file

@ -1983,7 +1983,7 @@ typedef struct MN_SFX_PLAY_INFO {
void *handle;
PHD_3DPOS *pos;
uint32_t loudness;
int16_t volume; // Need
int16_t volume;
int16_t pan;
int16_t fxnum;
int16_t mn_flags;
@ -1997,21 +1997,15 @@ typedef struct SAMPLE_INFO {
} SAMPLE_INFO;
typedef struct SAMPLE_DATA {
/* 0000 */ char *data;
/* 0004 */ int16_t length; // TODO: make me 32-bit!
/* 0006 */ int16_t bits_per_sample;
/* 0008 */ int16_t channels;
/* 000A */ int16_t unk1;
/* 000C */ int16_t sample_rate;
/* 000E */ int16_t unk2;
/* 0010 */ int16_t block_align;
/* 0012 */ int32_t unk3;
/* 0016 */ int16_t volume;
/* 0018 */ int32_t pan;
/* 001C */ int16_t unk4;
/* 001E */ void *handle;
/* 0022 */ int32_t unk5;
/* 0026 end */
char *data;
int32_t length;
int16_t bits_per_sample;
int16_t channels;
int16_t sample_rate;
int16_t block_align;
int16_t volume;
int32_t pan;
void *handle;
} SAMPLE_DATA;
#pragma pack(pop)

View file

@ -199,13 +199,11 @@ SAMPLE_DATA *SoundLoadSample(char *content)
SAMPLE_DATA *sample_data = malloc(sizeof(SAMPLE_DATA));
memset(sample_data, 0, sizeof(SAMPLE_DATA));
sample_data->unk2 = 0;
sample_data->data = content + sizeof(WAVE_FILE_HEADER);
sample_data->length =
hdr->data_chunk.subchunk_size - sizeof(WAVE_FILE_HEADER);
sample_data->bits_per_sample = hdr->fmt_chunk.bits_per_sample;
sample_data->channels = hdr->fmt_chunk.num_channels;
sample_data->unk1 = 0;
sample_data->block_align =
sample_data->channels * hdr->fmt_chunk.bits_per_sample / 8;
sample_data->sample_rate = hdr->fmt_chunk.sample_rate;
@ -233,9 +231,7 @@ int32_t SoundMakeSample(SAMPLE_DATA *sample_data)
buffer_desc.dwSize = sizeof(DSBUFFERDESC);
buffer_desc.dwFlags = DSBCAPS_STATIC | DSBCAPS_CTRLVOLUME | DSBCAPS_CTRLPAN
| DSBCAPS_CTRLFREQUENCY;
// re-read DATA chunk size.
// TODO: use SAMPLE_DATA->length
buffer_desc.dwBufferBytes = *(int32_t *)&sample_data->data[-4];
buffer_desc.dwBufferBytes = sample_data->length;
buffer_desc.dwReserved = 0;
buffer_desc.lpwfxFormat = &wave_format;
CLAMP(buffer_desc.dwBufferBytes, DSBSIZE_MIN, DSBSIZE_MAX);