2017-02-01 19:54:22 +01:00
|
|
|
#
|
|
|
|
/*
|
2017-02-24 22:29:06 +01:00
|
|
|
* Copyright (C) 2013 .. 2017
|
2017-02-01 19:54:22 +01:00
|
|
|
* Jan van Katwijk (J.vanKatwijk@gmail.com)
|
|
|
|
* Lazy Chair Programming
|
|
|
|
*
|
2017-02-19 21:30:39 +01:00
|
|
|
* This file is part of the DAB-library
|
|
|
|
* DAB-library is free software; you can redistribute it and/or modify
|
2017-02-01 19:54:22 +01:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2017-02-19 21:30:39 +01:00
|
|
|
* DAB-library is distributed in the hope that it will be useful,
|
2017-02-01 19:54:22 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2017-02-24 22:29:06 +01:00
|
|
|
* along with DAB-library; if not, write to the Free Software
|
2017-02-01 19:54:22 +01:00
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#
|
|
|
|
#include "dab-constants.h"
|
|
|
|
#include "msc-handler.h"
|
|
|
|
#include "dab-virtual.h"
|
|
|
|
#include "dab-audio.h"
|
2017-05-19 15:20:19 +02:00
|
|
|
#include "dab-data.h"
|
2017-04-07 16:38:38 +02:00
|
|
|
#include "dab-params.h"
|
2017-02-01 19:54:22 +01:00
|
|
|
//
|
|
|
|
// Interface program for processing the MSC.
|
|
|
|
// Merely a dispatcher for the selected service
|
|
|
|
//
|
|
|
|
// The ofdm processor assumes the existence of an msc-handler, whether
|
|
|
|
// a service is selected or not.
|
|
|
|
|
|
|
|
#define CUSize (4 * 16)
|
|
|
|
// Note CIF counts from 0 .. 3
|
|
|
|
//
|
2017-05-19 15:20:19 +02:00
|
|
|
mscHandler::mscHandler (uint8_t Mode,
|
|
|
|
audioOut_t soundOut,
|
|
|
|
dataOut_t dataOut,
|
2017-08-02 13:13:21 +02:00
|
|
|
bytesOut_t bytesOut,
|
2017-05-19 15:20:19 +02:00
|
|
|
programQuality_t mscQuality,
|
|
|
|
void *userData):
|
|
|
|
params (Mode) {
|
2017-02-19 21:30:39 +01:00
|
|
|
this -> soundOut = soundOut;
|
|
|
|
this -> dataOut = dataOut;
|
2017-08-02 13:13:21 +02:00
|
|
|
this -> bytesOut = bytesOut;
|
2017-05-19 15:20:19 +02:00
|
|
|
this -> programQuality = mscQuality;
|
|
|
|
this -> userData = userData;
|
2017-02-01 19:54:22 +01:00
|
|
|
|
|
|
|
cifVector = new int16_t [55296];
|
|
|
|
cifCount = 0; // msc blocks in CIF
|
|
|
|
blkCount = 0;
|
|
|
|
dabHandler = new dabVirtual;
|
|
|
|
newChannel = false;
|
|
|
|
work_to_be_done = false;
|
|
|
|
dabModus = 0;
|
2017-05-19 15:20:19 +02:00
|
|
|
BitsperBlock = 2 * params. get_carriers ();
|
|
|
|
if (Mode == 4) // 2 CIFS per 76 blocks
|
2017-02-01 19:54:22 +01:00
|
|
|
numberofblocksperCIF = 36;
|
|
|
|
else
|
2017-05-19 15:20:19 +02:00
|
|
|
if (Mode == 1) // 4 CIFS per 76 blocks
|
2017-02-01 19:54:22 +01:00
|
|
|
numberofblocksperCIF = 18;
|
|
|
|
else
|
2017-05-19 15:20:19 +02:00
|
|
|
if (Mode == 2) // 1 CIF per 76 blocks
|
2017-02-01 19:54:22 +01:00
|
|
|
numberofblocksperCIF = 72;
|
|
|
|
else // shouldnot/cannot happen
|
|
|
|
numberofblocksperCIF = 18;
|
|
|
|
|
|
|
|
audioService = true; // default
|
|
|
|
}
|
|
|
|
|
|
|
|
mscHandler::~mscHandler (void) {
|
|
|
|
delete[] cifVector;
|
|
|
|
dabHandler -> stopRunning ();
|
|
|
|
delete dabHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Note, the set_xxx functions are called from within a
|
|
|
|
// different thread than the process_mscBlock method,
|
|
|
|
// so, a little bit of locking seems wise while
|
|
|
|
// the actual changing of the settings is done in the
|
|
|
|
// thread executing process_mscBlock
|
|
|
|
void mscHandler::set_audioChannel (audiodata *d) {
|
|
|
|
mutexer. lock ();
|
|
|
|
audioService = true;
|
2017-02-18 13:46:38 +01:00
|
|
|
new_shortForm = d -> shortForm;
|
2017-02-01 19:54:22 +01:00
|
|
|
new_startAddr = d -> startAddr;
|
|
|
|
new_Length = d -> length;
|
|
|
|
new_protLevel = d -> protLevel;
|
|
|
|
new_bitRate = d -> bitRate;
|
|
|
|
new_language = d -> language;
|
|
|
|
new_type = d -> programType;
|
|
|
|
new_ASCTy = d -> ASCTy;
|
|
|
|
new_dabModus = new_ASCTy == 077 ? DAB_PLUS : DAB;
|
|
|
|
newChannel = true;
|
|
|
|
mutexer. unlock ();
|
|
|
|
}
|
2017-05-19 15:20:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
void mscHandler::set_dataChannel (packetdata *d) {
|
|
|
|
mutexer. lock ();
|
|
|
|
audioService = false;
|
|
|
|
new_shortForm = d -> shortForm;
|
|
|
|
new_startAddr = d -> startAddr;
|
|
|
|
new_Length = d -> length;
|
|
|
|
new_protLevel = d -> protLevel;
|
|
|
|
new_DGflag = d -> DGflag;
|
|
|
|
new_bitRate = d -> bitRate;
|
|
|
|
new_FEC_scheme = d -> FEC_scheme;
|
|
|
|
new_DSCTy = d -> DSCTy;
|
|
|
|
new_packetAddress = d -> packetAddress;
|
|
|
|
new_appType = d -> appType;
|
|
|
|
newChannel = true;
|
|
|
|
mutexer. unlock ();
|
|
|
|
}
|
|
|
|
|
2017-02-01 19:54:22 +01:00
|
|
|
//
|
|
|
|
// add blocks. First is (should be) block 5, last is (should be) 76
|
|
|
|
// Note that this method is called from within the ofdm-processor thread
|
|
|
|
// while the set_xxx methods are called from within the
|
|
|
|
// gui thread
|
|
|
|
//
|
|
|
|
// Any change in the selected service will only be active
|
|
|
|
// during te next process_mscBlock call.
|
|
|
|
void mscHandler::process_mscBlock (int16_t *fbits,
|
|
|
|
int16_t blkno) {
|
|
|
|
int16_t currentblk;
|
|
|
|
int16_t *myBegin;
|
|
|
|
|
|
|
|
if (!work_to_be_done && !newChannel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
currentblk = (blkno - 4) % numberofblocksperCIF;
|
|
|
|
//
|
|
|
|
if (newChannel) {
|
|
|
|
mutexer. lock ();
|
|
|
|
newChannel = false;
|
|
|
|
dabHandler -> stopRunning ();
|
|
|
|
delete dabHandler;
|
|
|
|
|
2017-02-19 21:30:39 +01:00
|
|
|
if (audioService) {
|
|
|
|
dabHandler = new dabAudio (new_dabModus,
|
2017-02-01 19:54:22 +01:00
|
|
|
new_Length * CUSize,
|
|
|
|
new_bitRate,
|
2017-02-18 13:46:38 +01:00
|
|
|
new_shortForm,
|
2017-02-01 19:54:22 +01:00
|
|
|
new_protLevel,
|
2017-02-19 21:30:39 +01:00
|
|
|
soundOut,
|
2017-04-02 15:27:15 +02:00
|
|
|
dataOut,
|
2017-05-19 15:20:19 +02:00
|
|
|
programQuality,
|
|
|
|
userData
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dabHandler = new dabData (new_DSCTy,
|
|
|
|
new_appType,
|
|
|
|
new_packetAddress,
|
|
|
|
new_Length * CUSize,
|
|
|
|
new_bitRate,
|
|
|
|
new_shortForm,
|
|
|
|
new_protLevel,
|
|
|
|
new_DGflag,
|
|
|
|
new_FEC_scheme,
|
2017-08-02 13:13:21 +02:00
|
|
|
bytesOut,
|
|
|
|
userData);
|
2017-02-01 19:54:22 +01:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// these we need for actual processing
|
|
|
|
startAddr = new_startAddr;
|
|
|
|
Length = new_Length;
|
|
|
|
// and this one to get started
|
|
|
|
work_to_be_done = true;
|
|
|
|
mutexer. unlock ();
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// and the normal operation is:
|
|
|
|
memcpy (&cifVector [currentblk * BitsperBlock],
|
|
|
|
fbits, BitsperBlock * sizeof (int16_t));
|
|
|
|
if (currentblk < numberofblocksperCIF - 1)
|
|
|
|
return;
|
|
|
|
//
|
|
|
|
// OK, now we have a full CIF
|
|
|
|
blkCount = 0;
|
|
|
|
cifCount = (cifCount + 1) & 03;
|
|
|
|
myBegin = &cifVector [startAddr * CUSize];
|
|
|
|
// Here we move the vector to be processed to a
|
|
|
|
// separate task or separate function, depending on
|
|
|
|
// the settings in the ini file, we might take advantage of multi cores
|
|
|
|
(void) dabHandler -> process (myBegin, Length * CUSize);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
|
|
|
void mscHandler::stopProcessing (void) {
|
|
|
|
work_to_be_done = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void mscHandler::stopHandler (void) {
|
|
|
|
work_to_be_done = false;
|
|
|
|
dabHandler -> stopRunning ();
|
|
|
|
}
|
|
|
|
|