1
0
mirror of https://github.com/JvanKatwijk/qt-dab.git synced 2025-10-06 16:22:41 +02:00
Files
SDR-DAB_Qt-DAB/includes/backend/audio/mp2processor.h

101 lines
3.5 KiB
C
Raw Normal View History

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>
2017-02-06 14:09:08 +01:00
#include <QObject>
2019-07-08 23:43:00 +02:00
#include <cstdio>
2021-10-08 11:45:53 +02:00
#include "frame-processor.h"
2017-02-06 14:09:08 +01:00
#include "ringbuffer.h"
#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;
2017-10-01 19:07:22 +02:00
class mp2Processor: public QObject, public frameProcessor {
2017-02-06 14:09:08 +01:00
Q_OBJECT
public:
mp2Processor (RadioInterface *,
int16_t,
2022-03-12 15:09:46 +01:00
RingBuffer<int16_t> *);
2019-07-08 23:44:33 +02:00
~mp2Processor();
2023-05-21 20:03:29 +02:00
void addtoFrame (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 *);
RingBuffer<int16_t> *buffer;
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);
2017-10-01 19:07:22 +02:00
void newAudio (int, int);
2017-02-06 14:09:08 +01:00
void isStereo (bool);
};