2008-07-20 07:41:41 +02:00
|
|
|
#include "meta.h"
|
2018-03-16 15:42:01 +01:00
|
|
|
#include "../coding/coding.h"
|
2018-09-04 22:42:21 +02:00
|
|
|
#include "../coding/acm_decoder_libacm.h"
|
2008-07-20 07:41:41 +02:00
|
|
|
|
2018-03-16 15:42:01 +01:00
|
|
|
/* ACM - InterPlay infinity engine games [Planescape: Torment (PC), Baldur's Gate (PC)] */
|
2021-12-11 12:43:31 +01:00
|
|
|
VGMSTREAM* init_vgmstream_acm(STREAMFILE* sf) {
|
2008-07-20 07:41:41 +02:00
|
|
|
VGMSTREAM * vgmstream = NULL;
|
2021-12-11 12:43:31 +01:00
|
|
|
int loop_flag = 0, channels, sample_rate, num_samples;
|
2018-09-04 22:42:21 +02:00
|
|
|
int force_channel_number = 0;
|
2018-03-16 18:02:17 +01:00
|
|
|
acm_codec_data *data = NULL;
|
2008-07-20 07:41:41 +02:00
|
|
|
|
|
|
|
|
2018-03-16 13:03:39 +01:00
|
|
|
/* checks */
|
2018-09-04 22:42:21 +02:00
|
|
|
/* .acm: plain ACM extension (often but not always paired with .mus, parsed elsewhere)
|
2021-12-11 12:43:31 +01:00
|
|
|
* .tun: Descent to Undermountain (PC)
|
2018-09-04 22:42:21 +02:00
|
|
|
* .wavc: header id for WAVC sfx (from bigfiles, extensionless) */
|
2021-12-11 12:43:31 +01:00
|
|
|
if (!check_extensions(sf, "acm,tun,wavc"))
|
2018-03-16 13:03:39 +01:00
|
|
|
goto fail;
|
2021-12-11 12:43:31 +01:00
|
|
|
if (read_u32be(0x00,sf) != 0x97280301 && /* header id (music) */
|
|
|
|
!is_id32be(0x00,sf, "WAVC")) /* sfx */
|
2018-03-16 13:03:39 +01:00
|
|
|
goto fail;
|
2008-07-20 07:41:41 +02:00
|
|
|
|
|
|
|
|
2021-12-11 12:43:31 +01:00
|
|
|
/* Plain ACM "channels" in the header (at 0x08) may be set to 2 for mono voices [FO1] or 1 for music [P:T],
|
2018-09-04 22:42:21 +02:00
|
|
|
* but actually seem related to ACM rows/cols and have nothing to do with channels.
|
|
|
|
*
|
2021-12-11 12:43:31 +01:00
|
|
|
* libacm will set plain ACM (not WAVC) to 2ch unless changed, but only Fallout (PC)
|
|
|
|
* and Descent to Undermountain (PC) seems to use plain ACM for sfx/voices,
|
|
|
|
* others are WAVC (which do have channels).
|
|
|
|
* DtU seems to use the field
|
2018-09-04 22:42:21 +02:00
|
|
|
*
|
|
|
|
* Doesn't look like there is any way to detect mono/stereo, so as a quick hack if
|
|
|
|
* we have a plain ACM (not WAVC) named .wavc we will force 1ch. */
|
2021-12-11 12:43:31 +01:00
|
|
|
if (check_extensions(sf, "wavc") && read_u32be(0x00,sf) == 0x97280301) {
|
2018-09-04 22:42:21 +02:00
|
|
|
force_channel_number = 1;
|
|
|
|
}
|
|
|
|
|
2018-03-16 13:03:39 +01:00
|
|
|
/* init decoder */
|
|
|
|
{
|
2018-09-04 18:37:51 +02:00
|
|
|
ACMStream *handle;
|
2021-12-11 12:43:31 +01:00
|
|
|
data = init_acm(sf, force_channel_number);
|
2018-03-16 18:02:17 +01:00
|
|
|
if (!data) goto fail;
|
2018-03-16 13:03:39 +01:00
|
|
|
|
2018-09-04 18:37:51 +02:00
|
|
|
handle = data->handle;
|
2021-12-11 12:43:31 +01:00
|
|
|
channels = handle->info.channels;
|
2018-09-04 18:37:51 +02:00
|
|
|
sample_rate = handle->info.rate;
|
|
|
|
num_samples = handle->total_values / handle->info.channels;
|
2008-07-20 07:41:41 +02:00
|
|
|
}
|
|
|
|
|
2018-03-16 13:03:39 +01:00
|
|
|
|
|
|
|
/* build the VGMSTREAM */
|
2021-12-11 12:43:31 +01:00
|
|
|
vgmstream = allocate_vgmstream(channels, loop_flag);
|
2008-07-20 07:41:41 +02:00
|
|
|
if (!vgmstream) goto fail;
|
|
|
|
|
2018-03-16 13:03:39 +01:00
|
|
|
vgmstream->sample_rate = sample_rate;
|
|
|
|
vgmstream->num_samples = num_samples;
|
2008-07-20 07:41:41 +02:00
|
|
|
|
2018-03-16 13:03:39 +01:00
|
|
|
vgmstream->meta_type = meta_ACM;
|
|
|
|
vgmstream->coding_type = coding_ACM;
|
|
|
|
vgmstream->layout_type = layout_none;
|
2008-07-20 07:41:41 +02:00
|
|
|
|
|
|
|
vgmstream->codec_data = data;
|
|
|
|
|
|
|
|
return vgmstream;
|
|
|
|
|
|
|
|
fail:
|
2018-03-16 15:42:01 +01:00
|
|
|
free_acm(data);
|
2018-03-16 13:03:39 +01:00
|
|
|
close_vgmstream(vgmstream);
|
2008-07-20 07:41:41 +02:00
|
|
|
return NULL;
|
|
|
|
}
|