Skip to content

Commit

Permalink
Merge pull request #350 from sonninnos/audio-update
Browse files Browse the repository at this point in the history
Libretro: Update audio before video_cb
  • Loading branch information
ds22x authored May 14, 2024
2 parents ba9fc37 + f00b1d1 commit c921b37
Show file tree
Hide file tree
Showing 16 changed files with 787 additions and 589 deletions.
10 changes: 10 additions & 0 deletions core/cd_hw/cdd.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,16 @@ int cdd_load(char *filename, char *header)
return -1;
}

#ifdef __LIBRETRO__
if (config.cd_precache)
{
log_cb(RETRO_LOG_INFO, "Pre-caching \"%s\" ...\n", filename);
if (chd_precache(cdd.chd.file) != CHDERR_NONE)
return -1;
log_cb(RETRO_LOG_INFO, "Pre-cache done.\n");
}
#endif

/* retrieve CHD header */
head = chd_get_header(cdd.chd.file);

Expand Down
14 changes: 7 additions & 7 deletions core/cd_hw/libchdr/src/bitstream.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
*/
/***************************************************************************
* copyright-holders:Aaron Giles
***************************************************************************
bitstream.c
Helper classes for reading/writing at the bit level.
***************************************************************************/

#include "bitstream.h"
#include <stdlib.h>
#include <libchdr/bitstream.h>

/***************************************************************************
* INLINE FUNCTIONS
Expand Down Expand Up @@ -108,9 +107,10 @@ uint32_t bitstream_read_offset(struct bitstream* bitstream)
}


//-------------------------------------------------
// flush - flush to the nearest byte
//-------------------------------------------------
/*-------------------------------------------------
* flush - flush to the nearest byte
*-------------------------------------------------
*/

uint32_t bitstream_flush(struct bitstream* bitstream)
{
Expand Down
2 changes: 1 addition & 1 deletion core/cd_hw/libchdr/src/bitstream.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************
***************************************************************************
bitstream.h
Expand Down
53 changes: 26 additions & 27 deletions core/cd_hw/libchdr/src/cdrom.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************
cdrom.c
Expand All @@ -15,12 +15,12 @@
schemes will differ after track 1!
***************************************************************************/
#ifdef WANT_RAW_DATA_SECTOR

#include <assert.h>
#include <string.h>

#include "cdrom.h"
#include <libchdr/cdrom.h>

#ifdef WANT_RAW_DATA_SECTOR

/***************************************************************************
DEBUGGING
Expand Down Expand Up @@ -64,8 +64,6 @@ void CLIB_DECL logerror(const char *text, ...) ATTR_PRINTF(1,2);
#define LOG(x)
#endif



/***************************************************************************
CONSTANTS
***************************************************************************/
Expand All @@ -92,8 +90,6 @@ void CLIB_DECL logerror(const char *text, ...) ATTR_PRINTF(1,2);
/** @brief 43 bytes each. */
#define ECC_Q_COMP 43



/**
* @brief -------------------------------------------------
* ECC lookup tables pre-calculated tables for ECC data calcs
Expand Down Expand Up @@ -301,16 +297,16 @@ static const uint16_t qoffsets[ECC_Q_NUM_BYTES][ECC_Q_COMP] =
{ 0x867,0x003,0x05b,0x0b3,0x10b,0x163,0x1bb,0x213,0x26b,0x2c3,0x31b,0x373,0x3cb,0x423,0x47b,0x4d3,0x52b,0x583,0x5db,0x633,0x68b,0x6e3,0x73b,0x793,0x7eb,0x843,0x89b,0x037,0x08f,0x0e7,0x13f,0x197,0x1ef,0x247,0x29f,0x2f7,0x34f,0x3a7,0x3ff,0x457,0x4af,0x507,0x55f }
};

/*-------------------------------------------------
* ecc_source_byte - return data from the sector
* at the given offset, masking anything
* particular to a mode
*-------------------------------------------------
*/

//-------------------------------------------------
// ecc_source_byte - return data from the sector
// at the given offset, masking anything
// particular to a mode
//-------------------------------------------------

static inline uint8_t ecc_source_byte(const uint8_t *sector, uint32_t offset)
INLINE uint8_t ecc_source_byte(const uint8_t *sector, uint32_t offset)
{
// in mode 2 always treat these as 0 bytes
/* in mode 2 always treat these as 0 bytes */
return (sector[MODE_OFFSET] == 2 && offset < 4) ? 0x00 : sector[SYNC_OFFSET + SYNC_NUM_BYTES + offset];
}

Expand All @@ -330,8 +326,9 @@ static inline uint8_t ecc_source_byte(const uint8_t *sector, uint32_t offset)

void ecc_compute_bytes(const uint8_t *sector, const uint16_t *row, int rowlen, uint8_t *val1, uint8_t *val2)
{
int component;
*val1 = *val2 = 0;
for (int component = 0; component < rowlen; component++)
for (component = 0; component < rowlen; component++)
{
*val1 ^= ecc_source_byte(sector, row[component]);
*val2 ^= ecc_source_byte(sector, row[component]);
Expand All @@ -355,17 +352,18 @@ void ecc_compute_bytes(const uint8_t *sector, const uint16_t *row, int rowlen, u

int ecc_verify(const uint8_t *sector)
{
// first verify P bytes
for (int byte = 0; byte < ECC_P_NUM_BYTES; byte++)
int byte;
/* first verify P bytes */
for (byte = 0; byte < ECC_P_NUM_BYTES; byte++)
{
uint8_t val1, val2;
ecc_compute_bytes(sector, poffsets[byte], ECC_P_COMP, &val1, &val2);
if (sector[ECC_P_OFFSET + byte] != val1 || sector[ECC_P_OFFSET + ECC_P_NUM_BYTES + byte] != val2)
return 0;
}

// then verify Q bytes
for (int byte = 0; byte < ECC_Q_NUM_BYTES; byte++)
/* then verify Q bytes */
for (byte = 0; byte < ECC_Q_NUM_BYTES; byte++)
{
uint8_t val1, val2;
ecc_compute_bytes(sector, qoffsets[byte], ECC_Q_COMP, &val1, &val2);
Expand All @@ -388,12 +386,13 @@ int ecc_verify(const uint8_t *sector)

void ecc_generate(uint8_t *sector)
{
// first verify P bytes
for (int byte = 0; byte < ECC_P_NUM_BYTES; byte++)
int byte;
/* first verify P bytes */
for (byte = 0; byte < ECC_P_NUM_BYTES; byte++)
ecc_compute_bytes(sector, poffsets[byte], ECC_P_COMP, &sector[ECC_P_OFFSET + byte], &sector[ECC_P_OFFSET + ECC_P_NUM_BYTES + byte]);

// then verify Q bytes
for (int byte = 0; byte < ECC_Q_NUM_BYTES; byte++)
/* then verify Q bytes */
for (byte = 0; byte < ECC_Q_NUM_BYTES; byte++)
ecc_compute_bytes(sector, qoffsets[byte], ECC_Q_COMP, &sector[ECC_Q_OFFSET + byte], &sector[ECC_Q_OFFSET + ECC_Q_NUM_BYTES + byte]);
}

Expand Down
56 changes: 48 additions & 8 deletions core/cd_hw/libchdr/src/cdrom.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* license:BSD-3-Clause */
/* copyright-holders:Aaron Giles */
/***************************************************************************
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************
cdrom.h
Expand All @@ -14,15 +14,14 @@
#define __CDROM_H__

#include <stdint.h>

#include <libchdr/chdconfig.h>

/***************************************************************************
CONSTANTS
***************************************************************************/

/* tracks are padded to a multiple of this many frames */
#define CD_TRACK_PADDING (4)

#define CD_TRACK_PADDING (4)
#define CD_MAX_TRACKS (99) /* AFAIK the theoretical limit */
#define CD_MAX_SECTOR_DATA (2352)
#define CD_MAX_SUBCODE_DATA (96)
Expand Down Expand Up @@ -53,8 +52,8 @@ enum
CD_SUB_NONE /* no subcode data stored */
};

#define CD_FLAG_GDROM 0x00000001 // disc is a GD-ROM, all tracks should be stored with GD-ROM metadata
#define CD_FLAG_GDROMLE 0x00000002 // legacy GD-ROM, with little-endian CDDA data
#define CD_FLAG_GDROM 0x00000001 /* disc is a GD-ROM, all tracks should be stored with GD-ROM metadata */
#define CD_FLAG_GDROMLE 0x00000002 /* legacy GD-ROM, with little-endian CDDA data */

/***************************************************************************
FUNCTION PROTOTYPES
Expand All @@ -67,4 +66,45 @@ void ecc_generate(uint8_t *sector);
void ecc_clear(uint8_t *sector);
#endif



/***************************************************************************
INLINE FUNCTIONS
***************************************************************************/

INLINE uint32_t msf_to_lba(uint32_t msf)
{
return ( ((msf&0x00ff0000)>>16) * 60 * 75) + (((msf&0x0000ff00)>>8) * 75) + ((msf&0x000000ff)>>0);
}

INLINE uint32_t lba_to_msf(uint32_t lba)
{
uint8_t m, s, f;

m = lba / (60 * 75);
lba -= m * (60 * 75);
s = lba / 75;
f = lba % 75;

return ((m / 10) << 20) | ((m % 10) << 16) |
((s / 10) << 12) | ((s % 10) << 8) |
((f / 10) << 4) | ((f % 10) << 0);
}

/**
* segacd needs it like this.. investigate
* Angelo also says PCE tracks often start playing at the
* wrong address.. related?
**/
INLINE uint32_t lba_to_msf_alt(int lba)
{
uint32_t ret = 0;

ret |= ((lba / (60 * 75))&0xff)<<16;
ret |= (((lba / 75) % 60)&0xff)<<8;
ret |= ((lba % 75)&0xff)<<0;

return ret;
}

#endif /* __CDROM_H__ */
Loading

0 comments on commit c921b37

Please sign in to comment.