summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/flac.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/flac.h')
-rw-r--r--src/lib/util/flac.h43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/lib/util/flac.h b/src/lib/util/flac.h
index 20e3f1b9378..be3a0a8ac96 100644
--- a/src/lib/util/flac.h
+++ b/src/lib/util/flac.h
@@ -13,11 +13,12 @@
#pragma once
-#include "osdcore.h"
-#include "corefile.h"
+#include "utilfwd.h"
#include <FLAC/all.h>
+#include <cstdint>
+
//**************************************************************************
// TYPE DEFINITIONS
@@ -31,7 +32,7 @@ public:
// construction/destruction
flac_encoder();
flac_encoder(void *buffer, uint32_t buflength);
- flac_encoder(util::core_file &file);
+ flac_encoder(util::random_write &file);
~flac_encoder();
// configuration
@@ -47,7 +48,7 @@ public:
// reset
bool reset();
bool reset(void *buffer, uint32_t buflength);
- bool reset(util::core_file &file);
+ bool reset(util::random_write &file);
// encode a buffer
bool encode_interleaved(const int16_t *samples, uint32_t samples_per_channel, bool swap_endian = false);
@@ -61,22 +62,26 @@ private:
void init_common();
static FLAC__StreamEncoderWriteStatus write_callback_static(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
FLAC__StreamEncoderWriteStatus write_callback(const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame);
+ static FLAC__StreamEncoderSeekStatus seek_callback_static(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
+ FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64 absolute_byte_offset);
+ static FLAC__StreamEncoderTellStatus tell_callback_static(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
+ FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *absolute_byte_offset);
// internal state
FLAC__StreamEncoder * m_encoder; // actual encoder
- util::core_file * m_file; // output file
- uint32_t m_compressed_offset; // current offset with the compressed stream
+ util::random_write * m_file; // output file
+ uint32_t m_compressed_offset; // current offset with the compressed stream
FLAC__byte * m_compressed_start; // start of compressed data
- uint32_t m_compressed_length; // length of the compressed stream
+ uint32_t m_compressed_length; // length of the compressed stream
// parameters
- uint32_t m_sample_rate; // sample rate
- uint8_t m_channels; // number of channels
- uint32_t m_block_size; // block size
+ uint32_t m_sample_rate; // sample rate
+ uint8_t m_channels; // number of channels
+ uint32_t m_block_size; // block size
// header stripping
bool m_strip_metadata; // strip the metadata?
- uint32_t m_ignore_bytes; // how many bytes to ignore when writing
+ uint32_t m_ignore_bytes; // how many bytes to ignore when writing
bool m_found_audio; // have we hit the audio yet?
};
@@ -89,7 +94,7 @@ public:
// construction/destruction
flac_decoder();
flac_decoder(const void *buffer, uint32_t length, const void *buffer2 = nullptr, uint32_t length2 = 0);
- flac_decoder(util::core_file &file);
+ flac_decoder(util::read_stream &file);
~flac_decoder();
// getters (valid after reset)
@@ -104,7 +109,7 @@ public:
bool reset();
bool reset(const void *buffer, uint32_t length, const void *buffer2 = nullptr, uint32_t length2 = 0);
bool reset(uint32_t sample_rate, uint8_t num_channels, uint32_t block_size, const void *buffer, uint32_t length);
- bool reset(util::core_file &file);
+ bool reset(util::read_stream &file);
// decode to a buffer; num_samples must be a multiple of the block size
bool decode_interleaved(int16_t *samples, uint32_t num_samples, bool swap_endian = false);
@@ -114,18 +119,22 @@ public:
uint32_t finish();
private:
+ enum DECODE_MODE {
+ SCALE_UP, SCALE_DOWN, SCALE_SAME
+ };
// internal helpers
static FLAC__StreamDecoderReadStatus read_callback_static(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
FLAC__StreamDecoderReadStatus read_callback(FLAC__byte buffer[], size_t *bytes);
static void metadata_callback_static(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
static FLAC__StreamDecoderTellStatus tell_callback_static(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
- static FLAC__StreamDecoderWriteStatus write_callback_static(const FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
- FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
+ static FLAC__StreamDecoderWriteStatus write_callback_static(const FLAC__StreamDecoder *decoder, const ::FLAC__Frame *frame, const FLAC__int32 *const buffer[], void *client_data);
+ FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 *const buffer[]);
+ template <DECODE_MODE Mode, bool SwapEndian> FLAC__StreamDecoderWriteStatus write_callback(const ::FLAC__Frame *frame, const FLAC__int32 *const buffer[]);
static void error_callback_static(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
// output state
- FLAC__StreamDecoder * m_decoder; // actual encoder
- util::core_file * m_file; // output file
+ FLAC__StreamDecoder * m_decoder; // actual decoder
+ util::read_stream * m_file; // input file
uint32_t m_sample_rate; // decoded sample rate
uint8_t m_channels; // decoded number of channels
uint8_t m_bits_per_sample; // decoded bits per sample