2017-02-06 14:09:08 +01:00
|
|
|
#
|
|
|
|
/******************************************************************************
|
|
|
|
** kjmp2 -- a minimal MPEG-1 Audio Layer II decoder library **
|
|
|
|
*******************************************************************************
|
|
|
|
** Copyright (C) 2006 Martin J. Fiedler <martin.fiedler@gmx.net> **
|
|
|
|
** **
|
|
|
|
** This software is provided 'as-is', without any express or implied **
|
|
|
|
** warranty. In no event will the authors be held liable for any damages **
|
|
|
|
** arising from the use of this software. **
|
|
|
|
** **
|
|
|
|
** Permission is granted to anyone to use this software for any purpose, **
|
|
|
|
** including commercial applications, and to alter it and redistribute it **
|
|
|
|
** freely, subject to the following restrictions: **
|
|
|
|
** 1. The origin of this software must not be misrepresented; you must not **
|
|
|
|
** claim that you wrote the original software. If you use this software **
|
|
|
|
** in a product, an acknowledgment in the product documentation would **
|
|
|
|
** be appreciated but is not required. **
|
|
|
|
** 2. Altered source versions must be plainly marked as such, and must not **
|
|
|
|
** be misrepresented as being the original software. **
|
|
|
|
** 3. This notice may not be removed or altered from any source **
|
|
|
|
** distribution. **
|
|
|
|
******************************************************************************/
|
|
|
|
//
|
|
|
|
// This software is a rewrite of the original kjmp2 software,
|
|
|
|
// Rewriting in the form of a class
|
|
|
|
// for use in the sdr-j DAB/DAB+ receiver
|
|
|
|
// all rights remain where they belong
|
2017-07-17 08:33:17 +02:00
|
|
|
|
2023-09-20 21:17:22 +02:00
|
|
|
#pragma once
|
2017-02-06 14:09:08 +01:00
|
|
|
|
2021-10-08 11:45:53 +02:00
|
|
|
#include <utility>
|
2019-07-08 23:43:00 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cmath>
|
|
|
|
#include <cstdio>
|
2023-11-05 14:11:28 +01:00
|
|
|
#include <complex>
|
|
|
|
#include <QObject>
|
2021-10-08 11:45:53 +02:00
|
|
|
#include "frame-processor.h"
|
2017-02-06 14:09:08 +01:00
|
|
|
#include "ringbuffer.h"
|
2017-02-16 21:04:08 +01:00
|
|
|
#include "pad-handler.h"
|
2017-02-06 14:09:08 +01:00
|
|
|
|
|
|
|
#define KJMP2_MAX_FRAME_SIZE 1440 // the maximum size of a frame
|
|
|
|
#define KJMP2_SAMPLES_PER_FRAME 1152 // the number of samples per frame
|
|
|
|
|
|
|
|
// quantizer specification structure
|
|
|
|
struct quantizer_spec {
|
|
|
|
int32_t nlevels;
|
|
|
|
uint8_t grouping;
|
|
|
|
uint8_t cw_bits;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RadioInterface;
|
|
|
|
|
2024-06-01 11:12:04 +02:00
|
|
|
class mp2Processor final: public QObject, public frameProcessor {
|
2017-02-06 14:09:08 +01:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
mp2Processor (RadioInterface *,
|
|
|
|
int16_t,
|
2023-11-05 14:11:28 +01:00
|
|
|
RingBuffer<std::complex<int16_t>> *,
|
2023-09-23 11:50:09 +02:00
|
|
|
bool);
|
|
|
|
~mp2Processor ();
|
2023-12-20 14:06:41 +01:00
|
|
|
void addtoFrame (const std::vector<uint8_t>);
|
2017-02-06 14:09:08 +01:00
|
|
|
|
|
|
|
private:
|
2017-03-27 16:32:49 +02:00
|
|
|
RadioInterface *myRadioInterface;
|
|
|
|
int16_t bitRate;
|
|
|
|
padHandler my_padhandler;
|
2017-02-06 14:09:08 +01:00
|
|
|
int32_t mp2sampleRate (uint8_t *);
|
|
|
|
int32_t mp2decodeFrame (uint8_t *, int16_t *);
|
2023-11-05 14:11:28 +01:00
|
|
|
RingBuffer<std::complex<int16_t>> *buffer;
|
2017-02-06 14:09:08 +01:00
|
|
|
int32_t baudRate;
|
|
|
|
void setSamplerate (int32_t);
|
|
|
|
struct quantizer_spec *read_allocation (int, int);
|
|
|
|
void read_samples (struct quantizer_spec *, int, int *);
|
|
|
|
int32_t get_bits (int32_t);
|
|
|
|
int16_t V [2][1024];
|
|
|
|
int16_t Voffs;
|
|
|
|
int16_t N [64][32];
|
|
|
|
struct quantizer_spec *allocation[2][32];
|
|
|
|
int32_t scfsi[2][32];
|
|
|
|
int32_t scalefactor[2][32][3];
|
|
|
|
int32_t sample[2][32][3];
|
|
|
|
int32_t U[512];
|
|
|
|
|
|
|
|
int32_t bit_window;
|
|
|
|
int32_t bits_in_window;
|
|
|
|
uint8_t *frame_pos;
|
2021-10-08 11:45:53 +02:00
|
|
|
uint8_t * MP2frame;
|
|
|
|
|
2017-02-06 14:09:08 +01:00
|
|
|
int16_t MP2framesize;
|
|
|
|
int16_t MP2Header_OK;
|
|
|
|
int16_t MP2headerCount;
|
|
|
|
int16_t MP2bitCount;
|
|
|
|
void addbittoMP2 (uint8_t *, uint8_t, int16_t);
|
|
|
|
int16_t numberofFrames;
|
|
|
|
int16_t errorFrames;
|
|
|
|
signals:
|
|
|
|
void show_frameErrors (int);
|
2023-11-23 16:13:49 +01:00
|
|
|
void newAudio (int, int, bool, bool);
|
2017-02-06 14:09:08 +01:00
|
|
|
void isStereo (bool);
|
|
|
|
};
|
|
|
|
|