2023-07-16 23:36:25 +00:00
|
|
|
#pragma once
|
|
|
|
|
2023-07-25 23:39:56 +00:00
|
|
|
#include <FLAC/stream_decoder.h>
|
|
|
|
#include <lame.h>
|
2023-07-18 23:05:32 +00:00
|
|
|
#include <jpeglib.h>
|
2023-07-25 23:39:56 +00:00
|
|
|
#include <id3v2tag.h>
|
2023-07-16 23:36:25 +00:00
|
|
|
|
|
|
|
#include <string>
|
2023-07-17 21:29:59 +00:00
|
|
|
#include <string_view>
|
|
|
|
#include <map>
|
|
|
|
#include <stdio.h>
|
2023-07-16 23:36:25 +00:00
|
|
|
|
2023-07-23 12:04:26 +00:00
|
|
|
#include "loggable.h"
|
|
|
|
|
|
|
|
class FLACtoMP3 : public Loggable {
|
2023-07-16 23:36:25 +00:00
|
|
|
public:
|
2023-07-23 12:04:26 +00:00
|
|
|
FLACtoMP3(Severity severity = info, uint8_t size = 4);
|
2023-07-16 23:36:25 +00:00
|
|
|
~FLACtoMP3();
|
|
|
|
|
|
|
|
void setInputFile(const std::string& path);
|
|
|
|
void setOutputFile(const std::string& path);
|
2023-07-19 22:12:18 +00:00
|
|
|
bool run();
|
2023-07-16 23:36:25 +00:00
|
|
|
|
|
|
|
private:
|
2023-07-17 21:29:59 +00:00
|
|
|
void processTags(const FLAC__StreamMetadata_VorbisComment& tags);
|
|
|
|
void processInfo(const FLAC__StreamMetadata_StreamInfo& info);
|
2023-07-18 23:05:32 +00:00
|
|
|
void processPicture(const FLAC__StreamMetadata_Picture& picture);
|
2023-07-17 21:29:59 +00:00
|
|
|
bool decodeFrame(const int32_t * const buffer[], uint32_t size);
|
|
|
|
bool flush();
|
|
|
|
bool initializeOutput();
|
2023-07-18 23:05:32 +00:00
|
|
|
bool scaleJPEG(const FLAC__StreamMetadata_Picture& picture);
|
2023-07-25 23:39:56 +00:00
|
|
|
void attachPictureFrame(const FLAC__StreamMetadata_Picture& picture, const TagLib::ByteVector& bytes);
|
2023-07-23 12:04:26 +00:00
|
|
|
|
2023-07-16 23:36:25 +00:00
|
|
|
static void error(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
|
|
|
|
static void metadata(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
|
|
|
|
static FLAC__StreamDecoderWriteStatus write(
|
|
|
|
const FLAC__StreamDecoder *decoder,
|
|
|
|
const FLAC__Frame *frame,
|
|
|
|
const FLAC__int32 * const buffer[],
|
|
|
|
void *client_data
|
|
|
|
);
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string inPath;
|
|
|
|
std::string outPath;
|
|
|
|
|
|
|
|
FLAC__StreamDecoder *decoder;
|
|
|
|
lame_t encoder;
|
|
|
|
FLAC__StreamDecoderInitStatus statusFLAC;
|
|
|
|
|
2023-07-17 21:29:59 +00:00
|
|
|
FILE* output;
|
2023-07-18 23:05:32 +00:00
|
|
|
uint8_t bufferMultiplier;
|
|
|
|
uint32_t flacMaxBlockSize;
|
2023-07-16 23:36:25 +00:00
|
|
|
uint32_t pcmCounter;
|
|
|
|
uint32_t pcmSize;
|
|
|
|
int16_t* pcm;
|
2023-07-17 21:29:59 +00:00
|
|
|
uint8_t* outputBuffer;
|
2023-07-18 23:05:32 +00:00
|
|
|
uint32_t outputBufferSize;
|
2023-07-17 21:29:59 +00:00
|
|
|
bool outputInitilized;
|
2023-07-18 23:05:32 +00:00
|
|
|
bool downscaleAlbumArt;
|
2023-07-25 23:39:56 +00:00
|
|
|
TagLib::ID3v2::Tag id3v2tag;
|
2023-07-16 23:36:25 +00:00
|
|
|
};
|