From 9a22336cecf5e8cca7642657754e44bc9f0244a0 Mon Sep 17 00:00:00 2001 From: spicyjpeg Date: Fri, 5 Dec 2025 08:57:13 +0100 Subject: [PATCH] Flip loop point endianness, add notes to README --- README.md | 9 ++++++--- psxavenc/filefmt.c | 13 ++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b964b6f..63598a2 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,14 @@ Notes: at the beginning of the file. The header is always 48 bytes long for `vag` files, while in the case of `vagi` files it is padded to the size specified using the `-a` option (2048 bytes by default). The `vagi` format extends the - standard .vag header by adding the following fields: + header with the following fields: - the file's interleave size at offset `0x08-0x0B` (little endian); - the loop start offset in bytes-per-channel, if any, at offset `0x14-0x17` - (little endian); - - the file's channel count at offset `0x1E`. + (big endian). *Note that this field is specific to psxavenc and not part of* + *the standard interleaved .vag header*; + - the file's channel count at offset `0x1E`. *This field is not part of the* + *interleaved .vag header either, but can be found in other variants of the* + *format.* - The `spu` and `vag` formats support encoding a loop point as part of the ADPCM data, while `vagi` supports storing one in the header for use by the stream diff --git a/psxavenc/filefmt.c b/psxavenc/filefmt.c index b625590..d444b32 100644 --- a/psxavenc/filefmt.c +++ b/psxavenc/filefmt.c @@ -131,7 +131,7 @@ static void write_vag_header(const args_t *args, int size_per_channel, uint8_t * header[0x12] = (uint8_t)(args->audio_frequency >> 8); header[0x13] = (uint8_t)args->audio_frequency; - // Loop point in bytes (little endian, non-standard) + // Loop point in bytes (big endian, non-standard) if (args->format == FORMAT_VAGI && args->audio_loop_point >= 0) { int loop_start_block = (args->audio_loop_point * args->audio_frequency) / (PSX_AUDIO_SPU_SAMPLES_PER_BLOCK * 1000); @@ -139,15 +139,14 @@ static void write_vag_header(const args_t *args, int size_per_channel, uint8_t * loop_start_block++; int loop_point = loop_start_block * PSX_AUDIO_SPU_BLOCK_SIZE; - header[0x14] = (uint8_t)loop_point; - header[0x15] = (uint8_t)(loop_point >> 8); - header[0x16] = (uint8_t)(loop_point >> 16); - header[0x17] = (uint8_t)(loop_point >> 24); + header[0x14] = (uint8_t)(loop_point >> 24); + header[0x15] = (uint8_t)(loop_point >> 16); + header[0x16] = (uint8_t)(loop_point >> 8); + header[0x17] = (uint8_t)loop_point; } - // Number of channels (little endian, non-standard) + // Number of channels (non-standard) header[0x1E] = (uint8_t)args->audio_channels; - header[0x1F] = 0x00; // Filename int name_offset = strlen(args->output_file);