Commit 59d5c727 authored by Libretro-Admin's avatar Libretro-Admin
Browse files
parent f56ebf47
......@@ -15,6 +15,8 @@ FORCE_GLES := 0
STATIC_LINKING:= 0
HAVE_TEXUPSCALE := 1
HAVE_OPENMP := 1
HAVE_CHD := 1
ifeq ($(HAVE_OIT), 1)
TARGET_NAME := reicast_oit
......@@ -595,6 +597,10 @@ ifeq ($(NEED_CXX11), 1)
CXXFLAGS += -std=c++11
endif
ifeq ($(HAVE_CHD),1)
CORE_DEFINES += -DFLAC__HAS_OGG=0 -FLAC__NO_DLL -DHAVE_LROUND -DHAVE_STDINT_H -DHAVE_STDLIB_H -DHAVE_SYS_PARAM_H -D_7ZIP_ST -DUSE_FLAC -DUSE_LZMA
endif
RZDCY_CFLAGS += $(CORE_DEFINES)
RZDCY_CXXFLAGS += $(CORE_DEFINES)
CFLAGS += $(CORE_DEFINES)
......
......@@ -78,7 +78,6 @@ SOURCES_CXX := \
$(CORE_DIR)/core/stdclass.cpp \
\
$(DEPS_DIR)/coreio/coreio.cpp \
$(DEPS_DIR)/chdr/chdr.cpp \
$(DEPS_DIR)/crypto/sha1.cpp \
$(DEPS_DIR)/crypto/sha256.cpp \
$(DEPS_DIR)/crypto/md5.cpp \
......@@ -92,6 +91,13 @@ SOURCES_CXX := \
$(CORE_DIR)/core/reios/reios.cpp \
$(CORE_DIR)/core/reios/gdrom_hle.cpp \
$(CORE_DIR)/core/reios/descrambl.cpp
SOURCES_C += \
$(DEPS_DIR)/chdr/bitstream.c \
$(DEPS_DIR)/chdr/cdrom.c \
$(DEPS_DIR)/chdr/chd.c \
$(DEPS_DIR)/chdr/flac.c \
$(DEPS_DIR)/chdr/huffman.c
SOURCES_ASM :=
ifeq ($(NO_REND), 1)
......@@ -186,6 +192,27 @@ ifeq ($(HAVE_TEXUPSCALE),1)
SOURCES_CXX += $(DEPS_DIR)/xbrz/xbrz.cpp
endif
ifeq ($(HAVE_CHD),1)
INCFLAGS += -I$(DEPS_DIR)/flac/include
SOURCES_C += \
$(DEPS_DIR)/flac/bitmath.c \
$(DEPS_DIR)/flac/bitreader.c \
$(DEPS_DIR)/flac/cpu.c \
$(DEPS_DIR)/flac/crc.c \
$(DEPS_DIR)/flac/fixed.c \
$(DEPS_DIR)/flac/float.c \
$(DEPS_DIR)/flac/format.c \
$(DEPS_DIR)/flac/lpc.c \
$(DEPS_DIR)/flac/md5.c \
$(DEPS_DIR)/flac/memory.c \
$(DEPS_DIR)/flac/stream_decoder.c
SOURCES_C += $(DEPS_DIR)/lzma/C/LzFind.c \
$(DEPS_DIR)/lzma/C/LzmaDec.c \
$(DEPS_DIR)/lzma/C/LzmaEnc.c
endif
SOURCES_C += $(DEPS_DIR)/zlib/deflate.c \
$(DEPS_DIR)/zlib/gzlib.c \
$(DEPS_DIR)/zlib/uncompr.c \
......
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************
bitstream.c
Helper classes for reading/writing at the bit level.
***************************************************************************/
#include "bitstream.h"
#include <stdlib.h>
/***************************************************************************
* INLINE FUNCTIONS
***************************************************************************
*/
int bitstream_overflow(struct bitstream* bitstream) { return ((bitstream->doffset - bitstream->bits / 8) > bitstream->dlength); }
/*-------------------------------------------------
* create_bitstream - constructor
*-------------------------------------------------
*/
struct bitstream* create_bitstream(const void *src, uint32_t srclength)
{
struct bitstream* bitstream = (struct bitstream*)malloc(sizeof(struct bitstream));
bitstream->buffer = 0;
bitstream->bits = 0;
bitstream->read = (const uint8_t*)src;
bitstream->doffset = 0;
bitstream->dlength = srclength;
return bitstream;
}
/*-----------------------------------------------------
* bitstream_peek - fetch the requested number of bits
* but don't advance the input pointer
*-----------------------------------------------------
*/
uint32_t bitstream_peek(struct bitstream* bitstream, int numbits)
{
if (numbits == 0)
return 0;
/* fetch data if we need more */
if (numbits > bitstream->bits)
{
while (bitstream->bits <= 24)
{
if (bitstream->doffset < bitstream->dlength)
bitstream->buffer |= bitstream->read[bitstream->doffset] << (24 - bitstream->bits);
bitstream->doffset++;
bitstream->bits += 8;
}
}
/* return the data */
return bitstream->buffer >> (32 - numbits);
}
/*-----------------------------------------------------
* bitstream_remove - advance the input pointer by the
* specified number of bits
*-----------------------------------------------------
*/
void bitstream_remove(struct bitstream* bitstream, int numbits)
{
bitstream->buffer <<= numbits;
bitstream->bits -= numbits;
}
/*-----------------------------------------------------
* bitstream_read - fetch the requested number of bits
*-----------------------------------------------------
*/
uint32_t bitstream_read(struct bitstream* bitstream, int numbits)
{
uint32_t result = bitstream_peek(bitstream, numbits);
bitstream_remove(bitstream, numbits);
return result;
}
/*-------------------------------------------------
* read_offset - return the current read offset
*-------------------------------------------------
*/
uint32_t bitstream_read_offset(struct bitstream* bitstream)
{
uint32_t result = bitstream->doffset;
int bits = bitstream->bits;
while (bits >= 8)
{
result--;
bits -= 8;
}
return result;
}
/*-------------------------------------------------
* flush - flush to the nearest byte
*-------------------------------------------------
*/
uint32_t bitstream_flush(struct bitstream* bitstream)
{
while (bitstream->bits >= 8)
{
bitstream->doffset--;
bitstream->bits -= 8;
}
bitstream->bits = bitstream->buffer = 0;
return bitstream->doffset;
}
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************
bitstream.h
Helper classes for reading/writing at the bit level.
***************************************************************************/
#pragma once
#ifndef __BITSTREAM_H__
#define __BITSTREAM_H__
#include <stdint.h>
/***************************************************************************
* TYPE DEFINITIONS
***************************************************************************
*/
/* helper class for reading from a bit buffer */
struct bitstream
{
uint32_t buffer; /* current bit accumulator */
int bits; /* number of bits in the accumulator */
const uint8_t * read; /* read pointer */
uint32_t doffset; /* byte offset within the data */
uint32_t dlength; /* length of the data */
};
struct bitstream* create_bitstream(const void *src, uint32_t srclength);
int bitstream_overflow(struct bitstream* bitstream);
uint32_t bitstream_read_offset(struct bitstream* bitstream);
uint32_t bitstream_read(struct bitstream* bitstream, int numbits);
uint32_t bitstream_peek(struct bitstream* bitstream, int numbits);
void bitstream_remove(struct bitstream* bitstream, int numbits);
uint32_t bitstream_flush(struct bitstream* bitstream);
#endif
This diff is collapsed.
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************
cdrom.h
Generic MAME cd-rom implementation
***************************************************************************/
#pragma once
#ifndef __CDROM_H__
#define __CDROM_H__
#include <stdint.h>
/***************************************************************************
CONSTANTS
***************************************************************************/
/* tracks are padded to a multiple of this many frames */
extern const uint32_t CD_TRACK_PADDING;
#define CD_MAX_TRACKS (99) /* AFAIK the theoretical limit */
#define CD_MAX_SECTOR_DATA (2352)
#define CD_MAX_SUBCODE_DATA (96)
#define CD_FRAME_SIZE (CD_MAX_SECTOR_DATA + CD_MAX_SUBCODE_DATA)
#define CD_FRAMES_PER_HUNK (8)
#define CD_METADATA_WORDS (1+(CD_MAX_TRACKS * 6))
enum
{
CD_TRACK_MODE1 = 0, /* mode 1 2048 bytes/sector */
CD_TRACK_MODE1_RAW, /* mode 1 2352 bytes/sector */
CD_TRACK_MODE2, /* mode 2 2336 bytes/sector */
CD_TRACK_MODE2_FORM1, /* mode 2 2048 bytes/sector */
CD_TRACK_MODE2_FORM2, /* mode 2 2324 bytes/sector */
CD_TRACK_MODE2_FORM_MIX, /* mode 2 2336 bytes/sector */
CD_TRACK_MODE2_RAW, /* mode 2 2352 bytes / sector */
CD_TRACK_AUDIO, /* redbook audio track 2352 bytes/sector (588 samples) */
CD_TRACK_RAW_DONTCARE /* special flag for cdrom_read_data: just return me whatever is there */
};
enum
{
CD_SUB_NORMAL = 0, /* "cooked" 96 bytes per sector */
CD_SUB_RAW, /* raw uninterleaved 96 bytes per sector */
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 */
/***************************************************************************
FUNCTION PROTOTYPES
***************************************************************************/
/* ECC utilities */
int ecc_verify(const uint8_t *sector);
void ecc_generate(uint8_t *sector);
void ecc_clear(uint8_t *sector);
/***************************************************************************
INLINE FUNCTIONS
***************************************************************************/
static inline uint32_t msf_to_lba(uint32_t msf)
{
return ( ((msf&0x00ff0000)>>16) * 60 * 75) + (((msf&0x0000ff00)>>8) * 75) + ((msf&0x000000ff)>>0);
}
static 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?
**/
static 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__ */
This diff is collapsed.
#include "types.h"
#ifndef __CORETYPES_H__
#define __CORETYPES_H__
typedef u64 UINT64;
typedef u32 UINT32;
typedef u16 UINT16;
typedef u8 UINT8;
#include <stdint.h>
#include <stdio.h>
typedef s64 INT64;
typedef s32 INT32;
typedef s16 INT16;
typedef s8 INT8;
#define ARRAY_LENGTH(x) (sizeof(x)/sizeof(x[0]))
typedef uint64_t UINT64;
typedef uint32_t UINT32;
typedef uint16_t UINT16;
typedef uint8_t UINT8;
typedef int64_t INT64;
typedef int32_t INT32;
typedef int16_t INT16;
typedef int8_t INT8;
#define core_file FILE
#define core_fopen(file) fopen(file, "rb")
#define core_fseek fseek
#define core_fread(fc, buff, len) fread(buff, 1, len, fc)
#define core_fclose fclose
#define core_ftell ftell
static size_t core_fsize(core_file *f)
{
long p = ftell(f);
fseek(f, 0, SEEK_END);
long rv = ftell(f);
fseek(f, p, SEEK_SET);
return rv;
}
#endif
/* license:BSD-3-Clause
* copyright-holders:Aaron Giles
***************************************************************************
flac.c
FLAC compression wrappers
***************************************************************************/
#include <assert.h>
#include <string.h>
#include "flac.h"
/***************************************************************************
* FLAC DECODER
***************************************************************************
*/
static FLAC__StreamDecoderReadStatus flac_decoder_read_callback_static(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
FLAC__StreamDecoderReadStatus flac_decoder_read_callback(void* client_data, FLAC__byte buffer[], size_t *bytes);
static void flac_decoder_metadata_callback_static(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
static FLAC__StreamDecoderTellStatus flac_decoder_tell_callback_static(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
static FLAC__StreamDecoderWriteStatus flac_decoder_write_callback_static(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
FLAC__StreamDecoderWriteStatus flac_decoder_write_callback(void* client_data, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
static void flac_decoder_error_callback_static(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
/* getters (valid after reset) */
static uint32_t sample_rate(flac_decoder *decoder) { return decoder->sample_rate; }
static uint8_t channels(flac_decoder *decoder) { return decoder->channels; }
static uint8_t bits_per_sample(flac_decoder *decoder) { return decoder->bits_per_sample; }
static uint32_t total_samples(flac_decoder *decoder) { return FLAC__stream_decoder_get_total_samples(decoder->decoder); }
static FLAC__StreamDecoderState state(flac_decoder *decoder) { return FLAC__stream_decoder_get_state(decoder->decoder); }
static const char *state_string(flac_decoder *decoder) { return FLAC__stream_decoder_get_resolved_state_string(decoder->decoder); }
/*-------------------------------------------------
* flac_decoder - constructor
*-------------------------------------------------
*/
void flac_decoder_init(flac_decoder *decoder)
{
decoder->decoder = FLAC__stream_decoder_new();
decoder->sample_rate = 0;
decoder->channels = 0;
decoder->bits_per_sample = 0;
decoder->compressed_offset = 0;
decoder->compressed_start = NULL;
decoder->compressed_length = 0;
decoder->compressed2_start = NULL;
decoder->compressed2_length = 0;
decoder->uncompressed_offset = 0;
decoder->uncompressed_length = 0;
decoder->uncompressed_swap = 0;
}
/*-------------------------------------------------
* flac_decoder - destructor
*-------------------------------------------------
*/
void flac_decoder_free(flac_decoder* decoder)
{
if ((decoder != NULL) && (decoder->decoder != NULL))
FLAC__stream_decoder_delete(decoder->decoder);
}
/*-------------------------------------------------
* reset - reset state with the original
* parameters
*-------------------------------------------------
*/
static int flac_decoder_internal_reset(flac_decoder* decoder)
{
decoder->compressed_offset = 0;
if (FLAC__stream_decoder_init_stream(decoder->decoder,
&flac_decoder_read_callback_static,
NULL,
&flac_decoder_tell_callback_static,
NULL,
NULL,
&flac_decoder_write_callback_static,
&flac_decoder_metadata_callback_static,
&flac_decoder_error_callback_static, decoder) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
return 0;
return FLAC__stream_decoder_process_until_end_of_metadata(decoder->decoder);
}
/*-------------------------------------------------
* reset - reset state with new memory parameters
* and a custom-generated header
*-------------------------------------------------
*/
int flac_decoder_reset(flac_decoder* decoder, uint32_t sample_rate, uint8_t num_channels, uint32_t block_size, const void *buffer, uint32_t length)
{
/* modify the template header with our parameters */
static const uint8_t s_header_template[0x2a] =
{
0x66, 0x4C, 0x61, 0x43, /* +00: 'fLaC' stream header */
0x80, /* +04: metadata block type 0 (STREAMINFO), */
/* flagged as last block */
0x00, 0x00, 0x22, /* +05: metadata block length = 0x22 */
0x00, 0x00, /* +08: minimum block size */
0x00, 0x00, /* +0A: maximum block size */
0x00, 0x00, 0x00, /* +0C: minimum frame size (0 == unknown) */
0x00, 0x00, 0x00, /* +0F: maximum frame size (0 == unknown) */
0x0A, 0xC4, 0x42, 0xF0, 0x00, 0x00, 0x00, 0x00, /* +12: sample rate (0x0ac44 == 44100), */
/* numchannels (2), sample bits (16), */
/* samples in stream (0 == unknown) */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* +1A: MD5 signature (0 == none) */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* +2A: start of stream data */
};
memcpy(decoder->custom_header, s_header_template, sizeof(s_header_template));
decoder->custom_header[0x08] = decoder->custom_header[0x0a] = block_size >> 8;
decoder->custom_header[0x09] = decoder->custom_header[0x0b] = block_size & 0xff;
decoder->custom_header[0x12] = sample_rate >> 12;
decoder->custom_header[0x13] = sample_rate >> 4;
decoder->custom_header[0x14] = (sample_rate << 4) | ((num_channels - 1) << 1);
/* configure the header ahead of the provided buffer */
decoder->compressed_start = (const FLAC__byte *)(decoder->custom_header);
decoder->compressed_length = sizeof(decoder->custom_header);
decoder->compressed2_start = (const FLAC__byte *)(buffer);
decoder->compressed2_length = length;
return flac_decoder_internal_reset(decoder);
}
/*-------------------------------------------------
* decode_interleaved - decode to an interleaved
* sound stream
*-------------------------------------------------
*/
int flac_decoder_decode_interleaved(flac_decoder* decoder, int16_t *samples, uint32_t num_samples, int swap_endian)
{
/* configure the uncompressed buffer */
memset(decoder->uncompressed_start, 0, sizeof(decoder->uncompressed_start));
decoder->uncompressed_start[0] = samples;
decoder->uncompressed_offset = 0;
decoder->uncompressed_length = num_samples;
decoder->uncompressed_swap = swap_endian;
/* loop until we get everything we want */
while (decoder->uncompressed_offset < decoder->uncompressed_length)
if (!FLAC__stream_decoder_process_single(decoder->decoder))
return 0;
return 1;
}
#if 0
/*-------------------------------------------------
* decode - decode to an multiple independent
* data streams
*-------------------------------------------------
*/
bool flac_decoder::decode(int16_t **samples, uint32_t num_samples, bool swap_endian)
{
/* make sure we don't have too many channels */
int chans = channels();
if (chans > ARRAY_LENGTH(m_uncompressed_start))
return false;
/* configure the uncompressed buffer */
memset(m_uncompressed_start, 0, sizeof(m_uncompressed_start));
for (int curchan = 0; curchan < chans; curchan++)
m_uncompressed_start[curchan] = samples[curchan];
m_uncompressed_offset = 0;
m_uncompressed_length = num_samples;
m_uncompressed_swap = swap_endian;
/* loop until we get everything we want */
while (m_uncompressed_offset < m_uncompressed_length)
if (!FLAC__stream_decoder_process_single(m_decoder))
return false;
return true;
}
#endif
/*-------------------------------------------------
* finish - finish up the decode
*-------------------------------------------------
*/
uint32_t flac_decoder_finish(flac_decoder* decoder)
{
/* get the final decoding position and move forward */
FLAC__uint64 position = 0;
FLAC__stream_decoder_get_decode_position(decoder->decoder, &position);
FLAC__stream_decoder_finish(decoder->decoder);
/* adjust position if we provided the header */
if (position == 0)
return 0;
if (decoder->compressed_start == (const FLAC__byte *)(decoder->custom_header))
position -= decoder->compressed_length;
return position;
}
/*-------------------------------------------------
* read_callback - handle reads from the input
* stream
*-------------------------------------------------
*/
#define MIN(x, y) ((x) < (y) ? (x) : (y))
FLAC__StreamDecoderReadStatus flac_decoder_read_callback_static(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
{
return flac_decoder_read_callback(client_data, buffer, bytes);
}
FLAC__StreamDecoderReadStatus flac_decoder_read_callback(void* client_data, FLAC__byte buffer[], size_t *bytes)
{
flac_decoder* decoder = (flac_decoder*)client_data;
uint32_t expected = *bytes;
/* copy from primary buffer first */
uint32_t outputpos = 0;
if (outputpos < *bytes && decoder->compressed_offset < decoder->compressed_length)
{
uint32_t bytes_to_copy = MIN(*bytes - outputpos, decoder->compressed_length - decoder->compressed_offset);
memcpy(&buffer[outputpos], decoder->compressed_start + decoder->compressed_offset, bytes_to_copy);