mirror of
https://github.com/JvanKatwijk/dab-cmdline
synced 2025-10-05 23:52:50 +02:00
modified xml filereader
This commit is contained in:
196
devices/xml-filereader-old/element-reader.h
Normal file
196
devices/xml-filereader-old/element-reader.h
Normal file
@@ -0,0 +1,196 @@
|
||||
#
|
||||
/*
|
||||
* Copyright (C) 2014 .. 2019
|
||||
* Jan van Katwijk (J.vanKatwijk@gmail.com)
|
||||
* Lazy Chair Computing
|
||||
*
|
||||
* This file is part of eti-cmdline
|
||||
*
|
||||
* eti-cmdline is free software; you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* eti-cmdline is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with eti-cmdline; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
//
|
||||
//
|
||||
// THIS FILE WILL BE INCLUDED IN xml-reader.cpp
|
||||
//
|
||||
static
|
||||
float uint8_Table [] = {
|
||||
-128 / 128.0 , -127 / 128.0 , -126 / 128.0 , -125 / 128.0 , -124 / 128.0 , -123 / 128.0 , -122 / 128.0 , -121 / 128.0 , -120 / 128.0 , -119 / 128.0 , -118 / 128.0 , -117 / 128.0 , -116 / 128.0 , -115 / 128.0 , -114 / 128.0 , -113 / 128.0
|
||||
, -112 / 128.0 , -111 / 128.0 , -110 / 128.0 , -109 / 128.0 , -108 / 128.0 , -107 / 128.0 , -106 / 128.0 , -105 / 128.0 , -104 / 128.0 , -103 / 128.0 , -102 / 128.0 , -101 / 128.0 , -100 / 128.0 , -99 / 128.0 , -98 / 128.0 , -97 / 128.0
|
||||
, -96 / 128.0 , -95 / 128.0 , -94 / 128.0 , -93 / 128.0 , -92 / 128.0 , -91 / 128.0 , -90 / 128.0 , -89 / 128.0 , -88 / 128.0 , -87 / 128.0 , -86 / 128.0 , -85 / 128.0 , -84 / 128.0 , -83 / 128.0 , -82 / 128.0 , -81 / 128.0
|
||||
, -80 / 128.0 , -79 / 128.0 , -78 / 128.0 , -77 / 128.0 , -76 / 128.0 , -75 / 128.0 , -74 / 128.0 , -73 / 128.0 , -72 / 128.0 , -71 / 128.0 , -70 / 128.0 , -69 / 128.0 , -68 / 128.0 , -67 / 128.0 , -66 / 128.0 , -65 / 128.0
|
||||
, -64 / 128.0 , -63 / 128.0 , -62 / 128.0 , -61 / 128.0 , -60 / 128.0 , -59 / 128.0 , -58 / 128.0 , -57 / 128.0 , -56 / 128.0 , -55 / 128.0 , -54 / 128.0 , -53 / 128.0 , -52 / 128.0 , -51 / 128.0 , -50 / 128.0 , -49 / 128.0
|
||||
, -48 / 128.0 , -47 / 128.0 , -46 / 128.0 , -45 / 128.0 , -44 / 128.0 , -43 / 128.0 , -42 / 128.0 , -41 / 128.0 , -40 / 128.0 , -39 / 128.0 , -38 / 128.0 , -37 / 128.0 , -36 / 128.0 , -35 / 128.0 , -34 / 128.0 , -33 / 128.0
|
||||
, -32 / 128.0 , -31 / 128.0 , -30 / 128.0 , -29 / 128.0 , -28 / 128.0 , -27 / 128.0 , -26 / 128.0 , -25 / 128.0 , -24 / 128.0 , -23 / 128.0 , -22 / 128.0 , -21 / 128.0 , -20 / 128.0 , -19 / 128.0 , -18 / 128.0 , -17 / 128.0
|
||||
, -16 / 128.0 , -15 / 128.0 , -14 / 128.0 , -13 / 128.0 , -12 / 128.0 , -11 / 128.0 , -10 / 128.0 , -9 / 128.0 , -8 / 128.0 , -7 / 128.0 , -6 / 128.0 , -5 / 128.0 , -4 / 128.0 , -3 / 128.0 , -2 / 128.0 , -1 / 128.0
|
||||
, 0 / 128.0 , 1 / 128.0 , 2 / 128.0 , 3 / 128.0 , 4 / 128.0 , 5 / 128.0 , 6 / 128.0 , 7 / 128.0 , 8 / 128.0 , 9 / 128.0 , 10 / 128.0 , 11 / 128.0 , 12 / 128.0 , 13 / 128.0 , 14 / 128.0 , 15 / 128.0
|
||||
, 16 / 128.0 , 17 / 128.0 , 18 / 128.0 , 19 / 128.0 , 20 / 128.0 , 21 / 128.0 , 22 / 128.0 , 23 / 128.0 , 24 / 128.0 , 25 / 128.0 , 26 / 128.0 , 27 / 128.0 , 28 / 128.0 , 29 / 128.0 , 30 / 128.0 , 31 / 128.0
|
||||
, 32 / 128.0 , 33 / 128.0 , 34 / 128.0 , 35 / 128.0 , 36 / 128.0 , 37 / 128.0 , 38 / 128.0 , 39 / 128.0 , 40 / 128.0 , 41 / 128.0 , 42 / 128.0 , 43 / 128.0 , 44 / 128.0 , 45 / 128.0 , 46 / 128.0 , 47 / 128.0
|
||||
, 48 / 128.0 , 49 / 128.0 , 50 / 128.0 , 51 / 128.0 , 52 / 128.0 , 53 / 128.0 , 54 / 128.0 , 55 / 128.0 , 56 / 128.0 , 57 / 128.0 , 58 / 128.0 , 59 / 128.0 , 60 / 128.0 , 61 / 128.0 , 62 / 128.0 , 63 / 128.0
|
||||
, 64 / 128.0 , 65 / 128.0 , 66 / 128.0 , 67 / 128.0 , 68 / 128.0 , 69 / 128.0 , 70 / 128.0 , 71 / 128.0 , 72 / 128.0 , 73 / 128.0 , 74 / 128.0 , 75 / 128.0 , 76 / 128.0 , 77 / 128.0 , 78 / 128.0 , 79 / 128.0
|
||||
, 80 / 128.0 , 81 / 128.0 , 82 / 128.0 , 83 / 128.0 , 84 / 128.0 , 85 / 128.0 , 86 / 128.0 , 87 / 128.0 , 88 / 128.0 , 89 / 128.0 , 90 / 128.0 , 91 / 128.0 , 92 / 128.0 , 93 / 128.0 , 94 / 128.0 , 95 / 128.0
|
||||
, 96 / 128.0 , 97 / 128.0 , 98 / 128.0 , 99 / 128.0 , 100 / 128.0 , 101 / 128.0 , 102 / 128.0 , 103 / 128.0 , 104 / 128.0 , 105 / 128.0 , 106 / 128.0 , 107 / 128.0 , 108 / 128.0 , 109 / 128.0 , 110 / 128.0 , 111 / 128.0
|
||||
, 112 / 128.0 , 113 / 128.0 , 114 / 128.0 , 115 / 128.0 , 116 / 128.0 , 117 / 128.0 , 118 / 128.0 , 119 / 128.0 , 120 / 128.0 , 121 / 128.0 , 122 / 128.0 , 123 / 128.0 , 124 / 128.0 , 125 / 128.0 , 126 / 128.0 , 127 / 128.0 };
|
||||
|
||||
class elementReader {
|
||||
protected:
|
||||
FILE *theFile;
|
||||
xmlDescriptor *fd;
|
||||
float scaler;
|
||||
public:
|
||||
elementReader (FILE *theFile, xmlDescriptor *fd) {
|
||||
this -> theFile = theFile;
|
||||
this -> fd = fd;
|
||||
int a = fd -> bitsperChannel;
|
||||
int r = 1;
|
||||
while (-- a > 0)
|
||||
r <<= 1;
|
||||
scaler = float (r);
|
||||
}
|
||||
|
||||
virtual ~elementReader () {}
|
||||
virtual float readElement () { return 0; }
|
||||
};
|
||||
|
||||
class int8_reader: public elementReader {
|
||||
public:
|
||||
int8_reader (FILE *theFile, xmlDescriptor *fs):
|
||||
elementReader (theFile, fd) {
|
||||
}
|
||||
|
||||
~int8_reader () {
|
||||
}
|
||||
|
||||
float readElement () {
|
||||
uint8_t s1;
|
||||
fread (&s1, 1, 1, theFile);
|
||||
return (float)((int8_t)s1) / 127.0;
|
||||
}
|
||||
};
|
||||
|
||||
class uint8_reader : public elementReader {
|
||||
public:
|
||||
uint8_reader (FILE *theFile, xmlDescriptor *fd):
|
||||
elementReader (theFile, fd){
|
||||
}
|
||||
~uint8_reader () {
|
||||
}
|
||||
|
||||
float readElement () {
|
||||
uint8_t s1;
|
||||
|
||||
fread (&s1, 1, 1, theFile);
|
||||
return uint8_Table [s1];
|
||||
}
|
||||
};
|
||||
|
||||
class int16_reader : public elementReader {
|
||||
public:
|
||||
int16_reader (FILE *theFile, xmlDescriptor *fd):
|
||||
elementReader (theFile, fd) {
|
||||
}
|
||||
|
||||
~int16_reader () {
|
||||
}
|
||||
|
||||
float readElement () {
|
||||
uint8_t bytes_16 [2];
|
||||
int16_t temp_16;
|
||||
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
fread (bytes_16, 2, 1, theFile);
|
||||
temp_16 = (bytes_16 [0] << 8) | bytes_16 [1];
|
||||
return ((float)temp_16) / scaler;
|
||||
}
|
||||
else {
|
||||
fread (&temp_16, 2, 1, theFile);
|
||||
return ((float)temp_16) / scaler;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class int24_reader : public elementReader {
|
||||
public:
|
||||
int24_reader (FILE *theFile, xmlDescriptor *fd):
|
||||
elementReader (theFile, fd) {
|
||||
}
|
||||
|
||||
~int24_reader () {}
|
||||
|
||||
float readElement () {
|
||||
uint8_t bytes_24 [3];
|
||||
uint32_t temp_32;
|
||||
|
||||
fread (bytes_24, 3, 1, theFile);
|
||||
if (fd -> byteOrder == "MSB")
|
||||
temp_32 = (bytes_24 [0]<< 16) |
|
||||
(bytes_24 [1] << 8) | bytes_24 [2];
|
||||
else
|
||||
temp_32 = (bytes_24 [2]<< 16) |
|
||||
(bytes_24 [1] << 8) | bytes_24 [0];
|
||||
if (temp_32 & 0x800000)
|
||||
temp_32 |= 0xFF000000;
|
||||
return (float)temp_32 / scaler;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class int32_reader : public elementReader {
|
||||
public:
|
||||
int32_reader (FILE *theFile, xmlDescriptor *fd) :
|
||||
elementReader (theFile, fd) {
|
||||
}
|
||||
|
||||
~int32_reader () {}
|
||||
|
||||
float readElement () {
|
||||
uint8_t bytes_32 [4];
|
||||
uint32_t temp_32;
|
||||
|
||||
fread (bytes_32, sizeof (int32_t), 1, theFile);
|
||||
if (fd -> byteOrder == "MSB")
|
||||
temp_32 = (bytes_32 [0]<< 24) | (bytes_32 [1] << 16) |
|
||||
(bytes_32 [2] << 8) | bytes_32 [3];
|
||||
else
|
||||
temp_32 = (bytes_32 [3] << 24) | (bytes_32 [2] << 16) |
|
||||
(bytes_32 [1] << 8) | bytes_32 [0];
|
||||
return (float)temp_32 / scaler;
|
||||
}
|
||||
};
|
||||
|
||||
class float_reader : public elementReader {
|
||||
public:
|
||||
float_reader (FILE *theFile, xmlDescriptor *fd):
|
||||
elementReader (theFile, fd) {
|
||||
}
|
||||
|
||||
~float_reader () {}
|
||||
|
||||
float readElement () {
|
||||
uint8_t bytes_32 [4];
|
||||
uint32_t temp_32;
|
||||
|
||||
fread (bytes_32, sizeof (float), 1, theFile);
|
||||
if (fd -> byteOrder == "MSB")
|
||||
temp_32 = (bytes_32 [0]<< 24) | (bytes_32 [1] << 16) |
|
||||
(bytes_32 [2] << 8) | bytes_32 [3];
|
||||
else
|
||||
temp_32 = (bytes_32 [3] << 24) | (bytes_32 [2] << 16) |
|
||||
(bytes_32 [1] << 8) | bytes_32 [0];
|
||||
return *(float*)(&temp_32);
|
||||
}
|
||||
};
|
||||
|
||||
|
52
devices/xml-filereader-old/license.txt
Normal file
52
devices/xml-filereader-old/license.txt
Normal file
@@ -0,0 +1,52 @@
|
||||
Use of this software is granted under one of the following two licenses,
|
||||
to be chosen freely by the user.
|
||||
|
||||
1. Boost Software License - Version 1.0 - August 17th, 2003
|
||||
===============================================================================
|
||||
|
||||
Copyright (c) 2006, 2007 Marcin Kalicinski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
2. The MIT License
|
||||
===============================================================================
|
||||
|
||||
Copyright (c) 2006, 2007 Marcin Kalicinski
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
IN THE SOFTWARE.
|
2596
devices/xml-filereader-old/rapidxml.h
Normal file
2596
devices/xml-filereader-old/rapidxml.h
Normal file
File diff suppressed because it is too large
Load Diff
2596
devices/xml-filereader-old/rapidxml.hpp
Normal file
2596
devices/xml-filereader-old/rapidxml.hpp
Normal file
File diff suppressed because it is too large
Load Diff
174
devices/xml-filereader-old/rapidxml_iterators.hpp
Normal file
174
devices/xml-filereader-old/rapidxml_iterators.hpp
Normal file
@@ -0,0 +1,174 @@
|
||||
#ifndef RAPIDXML_ITERATORS_HPP_INCLUDED
|
||||
#define RAPIDXML_ITERATORS_HPP_INCLUDED
|
||||
|
||||
// Copyright (C) 2006, 2009 Marcin Kalicinski
|
||||
// Version 1.13
|
||||
// Revision $DateTime: 2009/05/13 01:46:17 $
|
||||
//! \file rapidxml_iterators.hpp This file contains rapidxml iterators
|
||||
|
||||
#include "rapidxml.hpp"
|
||||
|
||||
namespace rapidxml
|
||||
{
|
||||
|
||||
//! Iterator of child nodes of xml_node
|
||||
template<class Ch>
|
||||
class node_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef typename xml_node<Ch> value_type;
|
||||
typedef typename xml_node<Ch> &reference;
|
||||
typedef typename xml_node<Ch> *pointer;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
|
||||
node_iterator()
|
||||
: m_node(0)
|
||||
{
|
||||
}
|
||||
|
||||
node_iterator(xml_node<Ch> *node)
|
||||
: m_node(node->first_node())
|
||||
{
|
||||
}
|
||||
|
||||
reference operator *() const
|
||||
{
|
||||
assert(m_node);
|
||||
return *m_node;
|
||||
}
|
||||
|
||||
pointer operator->() const
|
||||
{
|
||||
assert(m_node);
|
||||
return m_node;
|
||||
}
|
||||
|
||||
node_iterator& operator++()
|
||||
{
|
||||
assert(m_node);
|
||||
m_node = m_node->next_sibling();
|
||||
return *this;
|
||||
}
|
||||
|
||||
node_iterator operator++(int)
|
||||
{
|
||||
node_iterator tmp = *this;
|
||||
++this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
node_iterator& operator--()
|
||||
{
|
||||
assert(m_node && m_node->previous_sibling());
|
||||
m_node = m_node->previous_sibling();
|
||||
return *this;
|
||||
}
|
||||
|
||||
node_iterator operator--(int)
|
||||
{
|
||||
node_iterator tmp = *this;
|
||||
++this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator ==(const node_iterator<Ch> &rhs)
|
||||
{
|
||||
return m_node == rhs.m_node;
|
||||
}
|
||||
|
||||
bool operator !=(const node_iterator<Ch> &rhs)
|
||||
{
|
||||
return m_node != rhs.m_node;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
xml_node<Ch> *m_node;
|
||||
|
||||
};
|
||||
|
||||
//! Iterator of child attributes of xml_node
|
||||
template<class Ch>
|
||||
class attribute_iterator
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
typedef typename xml_attribute<Ch> value_type;
|
||||
typedef typename xml_attribute<Ch> &reference;
|
||||
typedef typename xml_attribute<Ch> *pointer;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
|
||||
attribute_iterator()
|
||||
: m_attribute(0)
|
||||
{
|
||||
}
|
||||
|
||||
attribute_iterator(xml_node<Ch> *node)
|
||||
: m_attribute(node->first_attribute())
|
||||
{
|
||||
}
|
||||
|
||||
reference operator *() const
|
||||
{
|
||||
assert(m_attribute);
|
||||
return *m_attribute;
|
||||
}
|
||||
|
||||
pointer operator->() const
|
||||
{
|
||||
assert(m_attribute);
|
||||
return m_attribute;
|
||||
}
|
||||
|
||||
attribute_iterator& operator++()
|
||||
{
|
||||
assert(m_attribute);
|
||||
m_attribute = m_attribute->next_attribute();
|
||||
return *this;
|
||||
}
|
||||
|
||||
attribute_iterator operator++(int)
|
||||
{
|
||||
attribute_iterator tmp = *this;
|
||||
++this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
attribute_iterator& operator--()
|
||||
{
|
||||
assert(m_attribute && m_attribute->previous_attribute());
|
||||
m_attribute = m_attribute->previous_attribute();
|
||||
return *this;
|
||||
}
|
||||
|
||||
attribute_iterator operator--(int)
|
||||
{
|
||||
attribute_iterator tmp = *this;
|
||||
++this;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
bool operator ==(const attribute_iterator<Ch> &rhs)
|
||||
{
|
||||
return m_attribute == rhs.m_attribute;
|
||||
}
|
||||
|
||||
bool operator !=(const attribute_iterator<Ch> &rhs)
|
||||
{
|
||||
return m_attribute != rhs.m_attribute;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
xml_attribute<Ch> *m_attribute;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
292
devices/xml-filereader-old/xml-descriptor.cpp
Normal file
292
devices/xml-filereader-old/xml-descriptor.cpp
Normal file
@@ -0,0 +1,292 @@
|
||||
#
|
||||
/*
|
||||
* Copyright (C) 2014 .. 2019
|
||||
* Jan van Katwijk (J.vanKatwijk@gmail.com)
|
||||
* Lazy Chair Computing
|
||||
*
|
||||
* This file is part of eti-cmdline
|
||||
*
|
||||
* eti-cmdline is free software; you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* eti-cmdline is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with eti-cmdline; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "xml-descriptor.h"
|
||||
#include "rapidxml.hpp"
|
||||
|
||||
using namespace rapidxml;
|
||||
|
||||
xmlDescriptor::~xmlDescriptor () {
|
||||
}
|
||||
|
||||
void xmlDescriptor::printDescriptor () {
|
||||
fprintf (stderr, "sampleRate = %d\n", sampleRate);
|
||||
fprintf (stderr, "nrChannels = %d\n", nrChannels);
|
||||
fprintf (stderr, "bitsperChannel = %d\n", bitsperChannel);
|
||||
fprintf (stderr, "container = %s\n", container. c_str ());
|
||||
fprintf (stderr, "byteOrder = %s\n",
|
||||
byteOrder. c_str ());
|
||||
fprintf (stderr, "iqOrder = %s\n",
|
||||
iqOrder. c_str ());
|
||||
fprintf (stderr, "nrBlocks = %d (%d)\n",
|
||||
nrBlocks, (int)(blockList. size ()));
|
||||
for (int i = 0; i < (int)blockList. size (); i ++)
|
||||
fprintf (stderr, ">>> %d %d %s %d %s\n",
|
||||
blockList. at (i). blockNumber,
|
||||
blockList. at (i). nrElements,
|
||||
blockList. at (i). typeofUnit. c_str (),
|
||||
blockList. at (i). frequency,
|
||||
blockList. at (i). modType. c_str ());
|
||||
}
|
||||
|
||||
void xmlDescriptor::setSamplerate (int sr) {
|
||||
this -> sampleRate = sr;
|
||||
}
|
||||
|
||||
void xmlDescriptor::setChannels (int nrChannels,
|
||||
int bitsperChannel,
|
||||
std::string ct,
|
||||
std::string byteOrder) {
|
||||
this -> nrChannels = nrChannels;
|
||||
this -> bitsperChannel = bitsperChannel;
|
||||
this -> container = ct;
|
||||
this -> byteOrder = byteOrder;
|
||||
}
|
||||
|
||||
void xmlDescriptor::addChannelOrder (int channelOrder, std::string Value) {
|
||||
if (channelOrder > 1)
|
||||
return;
|
||||
if (channelOrder == 0) // first element
|
||||
this -> iqOrder = Value == "I" ? "I_ONLY" : "Q_ONLY";
|
||||
else
|
||||
if ((this -> iqOrder == "I_ONLY") && (Value == "Q"))
|
||||
this -> iqOrder = "IQ";
|
||||
else
|
||||
if ((this -> iqOrder == "Q_ONLY") && (Value == "I"))
|
||||
this -> iqOrder = "QI";
|
||||
}
|
||||
|
||||
void xmlDescriptor::add_dataBlock (int currBlock, int Count,
|
||||
int blockNumber, std::string Unit) {
|
||||
Blocks b;
|
||||
b. blockNumber = blockNumber;
|
||||
b. nrElements = Count;
|
||||
b. typeofUnit = Unit;
|
||||
blockList. push_back (b);
|
||||
}
|
||||
|
||||
void xmlDescriptor::add_freqtoBlock (int blockno, int freq) {
|
||||
blockList. at (blockno). frequency = freq;
|
||||
}
|
||||
|
||||
void xmlDescriptor::add_modtoBlock (int blockno, std::string modType) {
|
||||
blockList. at (blockno). modType = modType;
|
||||
}
|
||||
//
|
||||
// precondition: file exists and is readable.
|
||||
// Note that after the object is filled, the
|
||||
// file pointer points to where the contents starts
|
||||
xmlDescriptor::xmlDescriptor (FILE *f, bool *ok) {
|
||||
xml_document<> doc;
|
||||
uint8_t theBuffer [10000];
|
||||
int zeroCount = 0;
|
||||
//
|
||||
// set default values
|
||||
sampleRate = 2048000;
|
||||
nrChannels = 2;
|
||||
bitsperChannel = 16;
|
||||
container = "int16_t";
|
||||
byteOrder = std::string ("MSB");
|
||||
iqOrder ="IQ";
|
||||
uint8_t theChar;
|
||||
int index = 0;
|
||||
while (zeroCount < 500) {
|
||||
theChar = fgetc (f);
|
||||
if (theChar == 0)
|
||||
zeroCount ++;
|
||||
else
|
||||
zeroCount = 0;
|
||||
|
||||
theBuffer [index++] = theChar;
|
||||
}
|
||||
|
||||
*ok = false;
|
||||
doc. parse <0>((char *)theBuffer);
|
||||
|
||||
xml_node<> *root_node = doc. first_node ();
|
||||
if (root_node == nullptr) {
|
||||
fprintf (stderr, "failing to extract valid xml text\n");
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf (stderr, "rootnode %s\n", root_node -> name ());
|
||||
xml_node<> *node = root_node -> first_node ();
|
||||
while (node != nullptr) {
|
||||
if (std::string (node -> name ()) == "Recorder") {
|
||||
for (xml_attribute<>*attr = node -> first_attribute ();
|
||||
attr;attr = attr -> next_attribute ()) {
|
||||
if (std::string (attr -> name ()) == "Name")
|
||||
this -> recorderName = std::string (attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Version")
|
||||
this -> recorderVersion = std::string (attr -> value ());
|
||||
}
|
||||
}
|
||||
|
||||
if (std::string (node -> name ()) == "Device") {
|
||||
for (xml_attribute<>*attr = node -> first_attribute ();
|
||||
attr;attr = attr -> next_attribute ()) {
|
||||
if (std::string (attr -> name ()) == "Name")
|
||||
this -> deviceName = std::string (attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Model")
|
||||
this -> deviceModel = std::string (attr -> value ());
|
||||
}
|
||||
}
|
||||
|
||||
if (std::string (node -> name ()) == "Time") {
|
||||
for (xml_attribute<>*attr = node -> first_attribute ();
|
||||
attr;attr = attr -> next_attribute ()) {
|
||||
if (std::string (attr -> name ()) == "Value")
|
||||
this -> recordingTime = std::string (attr -> value ());
|
||||
}
|
||||
}
|
||||
|
||||
if (std::string (node -> name ()) == "Sample") {
|
||||
xml_node<>* subNode = node -> first_node ();
|
||||
while (subNode != nullptr) {
|
||||
if (std::string (subNode -> name ()) == "Samplerate") {
|
||||
std::string SR = "2048000";
|
||||
std::string Hz = "Hz";
|
||||
for (xml_attribute<>* attr = node -> first_attribute ();
|
||||
attr; attr = attr -> next_attribute ()) {
|
||||
if (std::string (attr -> name ()) == "Value")
|
||||
SR = std::string (attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Unit") {
|
||||
Hz = std::string (attr -> value ());
|
||||
int factor = Hz == "Hz" ? 1 :
|
||||
(Hz == "KHz") || (Hz == "Khz") ? 1000 :
|
||||
1000000;
|
||||
setSamplerate (std::stoi (SR) * factor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (std::string (subNode -> name ()) == "Channels") {
|
||||
std::string Amount = "2";
|
||||
std::string Bits = "16";
|
||||
std::string Container = "uint8";
|
||||
std::string Ordering = "N/A";
|
||||
for (xml_attribute<>* attr = subNode -> first_attribute ();
|
||||
attr; attr = attr -> next_attribute ()) {
|
||||
if (std::string (attr -> name ()) == "Amount")
|
||||
Amount = std::string (attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Bits")
|
||||
Bits = std::string (attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Container")
|
||||
Container = std::string (attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Ordering")
|
||||
Ordering = std::string (attr -> value ());
|
||||
}
|
||||
setChannels (std::stoi (Amount),
|
||||
std::stoi (Bits),
|
||||
Container,
|
||||
Ordering);
|
||||
|
||||
xml_node <>* subsubNode = subNode -> first_node ();
|
||||
int channelOrder = 0;
|
||||
while (subsubNode != nullptr) {
|
||||
if (std::string (subsubNode -> name ()) == "Channel") {
|
||||
std::string Value = "I/Q";
|
||||
xml_attribute <>* attr =
|
||||
subsubNode -> first_attribute ();
|
||||
if (std::string (attr -> name ()) == "Value")
|
||||
Value = std::string (attr -> value ());
|
||||
addChannelOrder (channelOrder, Value);
|
||||
channelOrder ++;
|
||||
}
|
||||
subsubNode = subsubNode -> next_sibling ();
|
||||
}
|
||||
}
|
||||
|
||||
subNode = subNode -> next_sibling ();
|
||||
}
|
||||
}
|
||||
|
||||
if (std::string (node -> name ()) == "Datablocks") {
|
||||
this -> nrBlocks = 0;
|
||||
int currBlock = 0;
|
||||
xml_node<>* subNode = node -> first_node ();
|
||||
while (subNode != nullptr) {
|
||||
if (std::string (subNode -> name ()) == "Datablock") {
|
||||
fprintf (stderr, "Datablock detected\n");
|
||||
std::string Count = "100";
|
||||
std::string Number = "10";
|
||||
std::string Unit = "Channel";
|
||||
for (xml_attribute<>* attr = subNode -> first_attribute ();
|
||||
attr; attr = attr -> next_attribute ()) {
|
||||
fprintf (stderr, "attribute %s (%s)\n",
|
||||
attr -> name (), attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Count")
|
||||
Count = std::string (attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Number")
|
||||
Number = std::string (attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Channel")
|
||||
Unit = std::string (attr -> value ());
|
||||
}
|
||||
add_dataBlock (currBlock, std::stoi (Count),
|
||||
std::stoi (Number), Unit);
|
||||
|
||||
xml_node <>* subsubNode = subNode -> first_node ();
|
||||
while (subsubNode != nullptr) {
|
||||
if (std::string (subsubNode -> name ()) == "Frequency") {
|
||||
std::string Unit = "Hz";
|
||||
std::string Value = "200";
|
||||
for (xml_attribute<>* attr =
|
||||
subsubNode -> first_attribute ();
|
||||
attr; attr = attr -> next_attribute ()) {
|
||||
if (std::string (attr -> name ()) == "Unit")
|
||||
Unit = std::string (attr -> value ());
|
||||
if (std::string (attr -> name ()) == "Value")
|
||||
Value = std::string (attr -> value ());
|
||||
}
|
||||
int Frequency =
|
||||
Unit == "Hz" ? std::stoi (Value) :
|
||||
((Unit == "KHz") | (Unit == "Khz")) ?
|
||||
std::stoi (Value) * 1000 :
|
||||
std::stoi (Value) * 1000000;
|
||||
add_freqtoBlock (currBlock, Frequency);
|
||||
}
|
||||
|
||||
if (std::string (subsubNode -> name ()) == "Modulation") {
|
||||
for (xml_attribute<>* attr =
|
||||
subsubNode -> first_attribute ();
|
||||
attr; attr = attr -> next_attribute ()) {
|
||||
if (std::string (attr -> name ()) == "Value") {
|
||||
std::string Value =
|
||||
std::string (attr -> value ());
|
||||
add_modtoBlock (currBlock, Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
subsubNode = subsubNode -> next_sibling ();
|
||||
}
|
||||
currBlock ++;
|
||||
}
|
||||
subNode = subNode -> next_sibling ();
|
||||
}
|
||||
nrBlocks = currBlock;
|
||||
}
|
||||
node = node -> next_sibling ();
|
||||
}
|
||||
*ok = nrBlocks > 0;
|
||||
printDescriptor ();
|
||||
}
|
||||
|
74
devices/xml-filereader-old/xml-descriptor.h
Normal file
74
devices/xml-filereader-old/xml-descriptor.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#
|
||||
/*
|
||||
* Copyright (C) 2014 .. 2019
|
||||
* Jan van Katwijk (J.vanKatwijk@gmail.com)
|
||||
* Lazy Chair Computing
|
||||
*
|
||||
* This file is part of eti-cmdline
|
||||
*
|
||||
* eti-cmdline is free software; you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* eti-cmdline is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with eti-cmdline; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef __XML_DESCRIPTOR__
|
||||
#define __XML_DESCRIPTOR__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
class Blocks {
|
||||
public:
|
||||
Blocks () {}
|
||||
~Blocks () {}
|
||||
int blockNumber;
|
||||
int nrElements;
|
||||
std::string typeofUnit;
|
||||
int frequency;
|
||||
std::string modType;
|
||||
};
|
||||
|
||||
class xmlDescriptor {
|
||||
public:
|
||||
std::string deviceName;
|
||||
std::string deviceModel;
|
||||
std::string recorderName;
|
||||
std::string recorderVersion;
|
||||
std::string recordingTime;
|
||||
int sampleRate;
|
||||
int nrChannels;
|
||||
int bitsperChannel;
|
||||
std::string container;
|
||||
std::string byteOrder;
|
||||
std::string iqOrder;
|
||||
int nrBlocks;
|
||||
std::vector<Blocks> blockList;
|
||||
xmlDescriptor (FILE *, bool *);
|
||||
~xmlDescriptor ();
|
||||
void printDescriptor ();
|
||||
void setSamplerate (int sr);
|
||||
void setChannels (int nrChannels,
|
||||
int bitsperChannel,
|
||||
std::string ct,
|
||||
std::string byteOrder);
|
||||
void addChannelOrder (int channelOrder,
|
||||
std::string Value);
|
||||
void add_dataBlock (int currBlock, int Count,
|
||||
int blockNumber, std::string Unit);
|
||||
void add_freqtoBlock (int blockno, int freq);
|
||||
void add_modtoBlock (int blockno, std::string modType);
|
||||
};
|
||||
|
||||
#endif
|
109
devices/xml-filereader-old/xml-filereader.cpp
Normal file
109
devices/xml-filereader-old/xml-filereader.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
#
|
||||
/*
|
||||
* Copyright (C) 2013 .. 2017
|
||||
* Jan van Katwijk (J.vanKatwijk@gmail.com)
|
||||
* Lazy Chair Computing
|
||||
*
|
||||
* This file is part of dab-cmdline
|
||||
*
|
||||
* dab-cmdline is free software; you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* dab-cmdline is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with dab-cmdline; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "xml-filereader.h"
|
||||
#include <cstdio>
|
||||
#include <unistd.h>
|
||||
#include <cstdlib>
|
||||
#include <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
#include <ctime>
|
||||
#include "device-exceptions.h"
|
||||
#include "xml-descriptor.h"
|
||||
#include "xml-reader.h"
|
||||
|
||||
#define INPUT_FRAMEBUFFERSIZE 8 * 32768
|
||||
//
|
||||
//
|
||||
xml_fileReader::xml_fileReader (std::string fileName,
|
||||
bool continue_on_eof) {
|
||||
this -> fileName = fileName;
|
||||
_I_Buffer = new RingBuffer<std::complex<float>>(INPUT_FRAMEBUFFERSIZE);
|
||||
theFile = fopen (fileName.c_str (), "rb");
|
||||
if (theFile == nullptr) {
|
||||
DEBUG_PRINT ("file %s cannot open\n",
|
||||
fileName. c_str ());
|
||||
delete _I_Buffer;
|
||||
throw OpeningFileFailed(fileName.c_str(),strerror(errno));
|
||||
}
|
||||
|
||||
bool ok = false;
|
||||
theDescriptor = new xmlDescriptor (theFile, &ok);
|
||||
if (!ok) {
|
||||
DEBUG_PRINT ("%s probably not an xml file\n",
|
||||
fileName. c_str ());
|
||||
delete _I_Buffer;
|
||||
throw OpeningFileFailed(fileName.c_str(),"Not a xml file");
|
||||
}
|
||||
|
||||
DEBUG_PRINT ("nrElements = %d\n",
|
||||
theDescriptor -> blockList [0].nrElements);
|
||||
theReader = nullptr;
|
||||
}
|
||||
|
||||
xml_fileReader::~xml_fileReader () {
|
||||
if (theReader != nullptr)
|
||||
delete theReader;
|
||||
|
||||
if (theFile != nullptr)
|
||||
fclose (theFile);
|
||||
|
||||
delete _I_Buffer;
|
||||
delete theDescriptor;
|
||||
}
|
||||
|
||||
bool xml_fileReader::restartReader (int32_t freq) {
|
||||
(void)freq;
|
||||
if (theReader != nullptr)
|
||||
return true;
|
||||
theReader = new xml_Reader (theFile,
|
||||
theDescriptor,
|
||||
5000,
|
||||
_I_Buffer,
|
||||
continue_on_eof);
|
||||
return true;
|
||||
}
|
||||
|
||||
void xml_fileReader::stopReader () {
|
||||
if (theReader != nullptr)
|
||||
delete theReader;
|
||||
theReader = nullptr;
|
||||
}
|
||||
|
||||
// size is in "samples"
|
||||
int32_t xml_fileReader::getSamples (std::complex<float> *V,
|
||||
int32_t size) {
|
||||
|
||||
if (theFile == nullptr) // should not happen
|
||||
return 0;
|
||||
|
||||
while ((int32_t)(_I_Buffer -> GetRingBufferReadAvailable()) < size)
|
||||
usleep (1000);
|
||||
|
||||
return _I_Buffer -> getDataFromBuffer (V, size);
|
||||
}
|
||||
|
||||
int32_t xml_fileReader::Samples () {
|
||||
if (theFile == nullptr)
|
||||
return 0;
|
||||
return _I_Buffer -> GetRingBufferReadAvailable();
|
||||
}
|
58
devices/xml-filereader-old/xml-filereader.h
Normal file
58
devices/xml-filereader-old/xml-filereader.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#
|
||||
/*
|
||||
* Copyright (C) 2013 .. 2019
|
||||
* Jan van Katwijk (J.vanKatwijk@gmail.com)
|
||||
* Lazy Chair Computing
|
||||
*
|
||||
* This file is part of the DAB library
|
||||
*
|
||||
* DAB library is free software; you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* DAB library is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with DAB library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef __XML_FILEREADER__
|
||||
#define __XML_FILEREADER__
|
||||
|
||||
#include <string>
|
||||
#include <atomic>
|
||||
#include <thread>
|
||||
#include "dab-constants.h"
|
||||
#include "device-handler.h"
|
||||
#include "ringbuffer.h"
|
||||
|
||||
class xmlDescriptor;
|
||||
class xml_Reader;
|
||||
/*
|
||||
*/
|
||||
class xml_fileReader: public deviceHandler {
|
||||
public:
|
||||
xml_fileReader (std::string, bool);
|
||||
~xml_fileReader ();
|
||||
int32_t getSamples (std::complex<float> *,
|
||||
int32_t);
|
||||
int32_t Samples ();
|
||||
bool restartReader (int32_t);
|
||||
void stopReader (void);
|
||||
private:
|
||||
bool continue_on_eof;
|
||||
FILE *theFile;
|
||||
std::atomic<bool> running;
|
||||
std::string fileName;
|
||||
RingBuffer<std::complex<float>> *_I_Buffer;
|
||||
uint32_t filePointer;
|
||||
xmlDescriptor *theDescriptor;
|
||||
xml_Reader *theReader;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
723
devices/xml-filereader-old/xml-reader.cpp
Normal file
723
devices/xml-filereader-old/xml-reader.cpp
Normal file
@@ -0,0 +1,723 @@
|
||||
#
|
||||
/*
|
||||
* Copyright (C) 2014 .. 2019
|
||||
* Jan van Katwijk (J.vanKatwijk@gmail.com)
|
||||
* Lazy Chair Computing
|
||||
*
|
||||
* This file is part of eti-cmdline
|
||||
*
|
||||
* eti-cmdline is free software; you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* eti-cmdline is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with eti-cmdline; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "xml-reader.h"
|
||||
#include "xml-descriptor.h"
|
||||
#include "xml-filereader.h"
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static int shift (int a) {
|
||||
int r = 1;
|
||||
while (-- a > 0) {
|
||||
r <<= 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline
|
||||
std::complex<float> compmul (std::complex<float> a, float b) {
|
||||
return std::complex<float> (real (a) * b, imag (a) * b);
|
||||
}
|
||||
|
||||
static inline
|
||||
uint64_t currentTime () {
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday (&tv, nullptr);
|
||||
return (uint64_t)(tv. tv_sec * 1000000 +
|
||||
(uint64_t)tv. tv_usec);
|
||||
}
|
||||
|
||||
xml_Reader::xml_Reader (FILE *f,
|
||||
xmlDescriptor *fd,
|
||||
uint32_t filePointer,
|
||||
RingBuffer<std::complex<float>> *b,
|
||||
bool continue_on_eof) {
|
||||
this -> file = f;
|
||||
this -> fd = fd;
|
||||
this -> filePointer = filePointer;
|
||||
sampleBuffer = b;
|
||||
this -> continue_on_eof = continue_on_eof;
|
||||
//
|
||||
// convBufferSize is a little confusing since the actual
|
||||
// buffer is one larger
|
||||
convBufferSize = fd -> sampleRate / 1000;
|
||||
|
||||
for (int i = 0; i < 2048; i ++) {
|
||||
float inVal = float (fd -> sampleRate / 1000);
|
||||
mapTable_int [i] = (int)(floor (i * (inVal / 2048.0)));
|
||||
mapTable_float [i] = i * (inVal / 2048.0) - mapTable_int [i];
|
||||
}
|
||||
|
||||
convIndex = 0;
|
||||
convBuffer. resize (convBufferSize + 1);
|
||||
nrElements = fd -> blockList [0]. nrElements;
|
||||
|
||||
running. store (false);
|
||||
threadHandle = std::thread (&xml_Reader::run, this);
|
||||
}
|
||||
|
||||
xml_Reader::~xml_Reader () {
|
||||
if (running. load ()) {
|
||||
running. store (false);
|
||||
threadHandle. join ();
|
||||
}
|
||||
}
|
||||
|
||||
void xml_Reader::stopReader () {
|
||||
if (running. load ()) {
|
||||
running. store (false);
|
||||
threadHandle. join ();
|
||||
}
|
||||
}
|
||||
|
||||
static int cycleCount = 0;
|
||||
void xml_Reader::run () {
|
||||
int samplesRead = 0;
|
||||
uint64_t nextStop;
|
||||
int startPoint = filePointer;
|
||||
|
||||
fseek (file, filePointer, SEEK_SET);
|
||||
nextStop = currentTime ();
|
||||
running. store (true);
|
||||
for (int blocks = 0; blocks < fd -> nrBlocks; blocks ++) {
|
||||
samplesToRead = compute_nrSamples (file, blocks);
|
||||
fprintf (stderr, "samples to read %d\n", samplesToRead);
|
||||
samplesRead = 0;
|
||||
do {
|
||||
while ((samplesRead <= samplesToRead) && running. load ()) {
|
||||
|
||||
if (fd -> iqOrder == "IQ")
|
||||
samplesRead += readSamples (file,
|
||||
&xml_Reader::readElements_IQ);
|
||||
else
|
||||
if (fd -> iqOrder == "QI")
|
||||
samplesRead += readSamples (file,
|
||||
&xml_Reader::readElements_QI);
|
||||
else
|
||||
if (fd -> iqOrder == "I_Only")
|
||||
samplesRead += readSamples (file,
|
||||
&xml_Reader::readElements_I);
|
||||
else
|
||||
samplesRead += readSamples (file,
|
||||
&xml_Reader::readElements_Q);
|
||||
|
||||
//
|
||||
// the readSamples function returns 1 msec of data,
|
||||
// we assume taking this data does not take time
|
||||
// nextStop = nextStop + ((uint64_t)blockSize * 1000) / 2048;
|
||||
nextStop = nextStop + (uint64_t)1000;
|
||||
if (nextStop > currentTime ())
|
||||
usleep ( nextStop - currentTime ());
|
||||
}
|
||||
filePointer = startPoint;
|
||||
fseek (file, filePointer, SEEK_SET);
|
||||
samplesRead = 0;
|
||||
} while (running.load () && continue_on_eof);
|
||||
}
|
||||
}
|
||||
|
||||
int xml_Reader::compute_nrSamples (FILE *f, int blockNumber) {
|
||||
int nrElements = fd -> blockList. at (blockNumber). nrElements;
|
||||
int samplesToRead = 0;
|
||||
|
||||
(void)f;
|
||||
if (fd -> blockList. at (blockNumber). typeofUnit == "Channel") {
|
||||
if ((fd -> iqOrder == "IQ") ||
|
||||
(fd -> iqOrder == "QI"))
|
||||
samplesToRead = nrElements / 2;
|
||||
else
|
||||
samplesToRead = nrElements;
|
||||
}
|
||||
else // typeofUnit = "sample"
|
||||
samplesToRead = nrElements;
|
||||
|
||||
fprintf (stderr, "%d samples have to be read, order is %s\n",
|
||||
samplesToRead, fd -> iqOrder. c_str ());
|
||||
return samplesToRead;
|
||||
}
|
||||
|
||||
int xml_Reader::readSamples (FILE *theFile,
|
||||
void(xml_Reader::*r)(FILE *theFile,
|
||||
std::complex<float> *, int)) {
|
||||
std::complex<float> temp [2048];
|
||||
|
||||
(*this.*r) (theFile, &convBuffer [1], convBufferSize);
|
||||
for (int i = 0; i < 2048; i ++) {
|
||||
int16_t inpBase = mapTable_int [i];
|
||||
float inpRatio = mapTable_float [i];
|
||||
temp [i] = compmul (convBuffer [inpBase + 1], inpRatio) +
|
||||
compmul (convBuffer [inpBase], 1 - inpRatio);
|
||||
}
|
||||
convBuffer [0] = convBuffer [convBufferSize];
|
||||
convIndex = 1;
|
||||
sampleBuffer -> putDataIntoBuffer (temp, 2048);
|
||||
return 2048;
|
||||
}
|
||||
|
||||
static
|
||||
float mapTable [] = {
|
||||
-128 / 128.0 , -127 / 128.0 , -126 / 128.0 , -125 / 128.0 , -124 / 128.0 , -123 / 128.0 , -122 / 128.0 , -121 / 128.0 , -120 / 128.0 , -119 / 128.0 , -118 / 128.0 , -117 / 128.0 , -116 / 128.0 , -115 / 128.0 , -114 / 128.0 , -113 / 128.0
|
||||
, -112 / 128.0 , -111 / 128.0 , -110 / 128.0 , -109 / 128.0 , -108 / 128.0 , -107 / 128.0 , -106 / 128.0 , -105 / 128.0 , -104 / 128.0 , -103 / 128.0 , -102 / 128.0 , -101 / 128.0 , -100 / 128.0 , -99 / 128.0 , -98 / 128.0 , -97 / 128.0
|
||||
, -96 / 128.0 , -95 / 128.0 , -94 / 128.0 , -93 / 128.0 , -92 / 128.0 , -91 / 128.0 , -90 / 128.0 , -89 / 128.0 , -88 / 128.0 , -87 / 128.0 , -86 / 128.0 , -85 / 128.0 , -84 / 128.0 , -83 / 128.0 , -82 / 128.0 , -81 / 128.0
|
||||
, -80 / 128.0 , -79 / 128.0 , -78 / 128.0 , -77 / 128.0 , -76 / 128.0 , -75 / 128.0 , -74 / 128.0 , -73 / 128.0 , -72 / 128.0 , -71 / 128.0 , -70 / 128.0 , -69 / 128.0 , -68 / 128.0 , -67 / 128.0 , -66 / 128.0 , -65 / 128.0
|
||||
, -64 / 128.0 , -63 / 128.0 , -62 / 128.0 , -61 / 128.0 , -60 / 128.0 , -59 / 128.0 , -58 / 128.0 , -57 / 128.0 , -56 / 128.0 , -55 / 128.0 , -54 / 128.0 , -53 / 128.0 , -52 / 128.0 , -51 / 128.0 , -50 / 128.0 , -49 / 128.0
|
||||
, -48 / 128.0 , -47 / 128.0 , -46 / 128.0 , -45 / 128.0 , -44 / 128.0 , -43 / 128.0 , -42 / 128.0 , -41 / 128.0 , -40 / 128.0 , -39 / 128.0 , -38 / 128.0 , -37 / 128.0 , -36 / 128.0 , -35 / 128.0 , -34 / 128.0 , -33 / 128.0
|
||||
, -32 / 128.0 , -31 / 128.0 , -30 / 128.0 , -29 / 128.0 , -28 / 128.0 , -27 / 128.0 , -26 / 128.0 , -25 / 128.0 , -24 / 128.0 , -23 / 128.0 , -22 / 128.0 , -21 / 128.0 , -20 / 128.0 , -19 / 128.0 , -18 / 128.0 , -17 / 128.0
|
||||
, -16 / 128.0 , -15 / 128.0 , -14 / 128.0 , -13 / 128.0 , -12 / 128.0 , -11 / 128.0 , -10 / 128.0 , -9 / 128.0 , -8 / 128.0 , -7 / 128.0 , -6 / 128.0 , -5 / 128.0 , -4 / 128.0 , -3 / 128.0 , -2 / 128.0 , -1 / 128.0
|
||||
, 0 / 128.0 , 1 / 128.0 , 2 / 128.0 , 3 / 128.0 , 4 / 128.0 , 5 / 128.0 , 6 / 128.0 , 7 / 128.0 , 8 / 128.0 , 9 / 128.0 , 10 / 128.0 , 11 / 128.0 , 12 / 128.0 , 13 / 128.0 , 14 / 128.0 , 15 / 128.0
|
||||
, 16 / 128.0 , 17 / 128.0 , 18 / 128.0 , 19 / 128.0 , 20 / 128.0 , 21 / 128.0 , 22 / 128.0 , 23 / 128.0 , 24 / 128.0 , 25 / 128.0 , 26 / 128.0 , 27 / 128.0 , 28 / 128.0 , 29 / 128.0 , 30 / 128.0 , 31 / 128.0
|
||||
, 32 / 128.0 , 33 / 128.0 , 34 / 128.0 , 35 / 128.0 , 36 / 128.0 , 37 / 128.0 , 38 / 128.0 , 39 / 128.0 , 40 / 128.0 , 41 / 128.0 , 42 / 128.0 , 43 / 128.0 , 44 / 128.0 , 45 / 128.0 , 46 / 128.0 , 47 / 128.0
|
||||
, 48 / 128.0 , 49 / 128.0 , 50 / 128.0 , 51 / 128.0 , 52 / 128.0 , 53 / 128.0 , 54 / 128.0 , 55 / 128.0 , 56 / 128.0 , 57 / 128.0 , 58 / 128.0 , 59 / 128.0 , 60 / 128.0 , 61 / 128.0 , 62 / 128.0 , 63 / 128.0
|
||||
, 64 / 128.0 , 65 / 128.0 , 66 / 128.0 , 67 / 128.0 , 68 / 128.0 , 69 / 128.0 , 70 / 128.0 , 71 / 128.0 , 72 / 128.0 , 73 / 128.0 , 74 / 128.0 , 75 / 128.0 , 76 / 128.0 , 77 / 128.0 , 78 / 128.0 , 79 / 128.0
|
||||
, 80 / 128.0 , 81 / 128.0 , 82 / 128.0 , 83 / 128.0 , 84 / 128.0 , 85 / 128.0 , 86 / 128.0 , 87 / 128.0 , 88 / 128.0 , 89 / 128.0 , 90 / 128.0 , 91 / 128.0 , 92 / 128.0 , 93 / 128.0 , 94 / 128.0 , 95 / 128.0
|
||||
, 96 / 128.0 , 97 / 128.0 , 98 / 128.0 , 99 / 128.0 , 100 / 128.0 , 101 / 128.0 , 102 / 128.0 , 103 / 128.0 , 104 / 128.0 , 105 / 128.0 , 106 / 128.0 , 107 / 128.0 , 108 / 128.0 , 109 / 128.0 , 110 / 128.0 , 111 / 128.0
|
||||
, 112 / 128.0 , 113 / 128.0 , 114 / 128.0 , 115 / 128.0 , 116 / 128.0 , 117 / 128.0 , 118 / 128.0 , 119 / 128.0 , 120 / 128.0 , 121 / 128.0 , 122 / 128.0 , 123 / 128.0 , 124 / 128.0 , 125 / 128.0 , 126 / 128.0 , 127 / 128.0 };
|
||||
|
||||
//
|
||||
// the readers
|
||||
void xml_Reader::readElements_IQ (FILE *theFile,
|
||||
std::complex<float> *buffer,
|
||||
int amount) {
|
||||
|
||||
int nrBits = fd -> bitsperChannel;
|
||||
float scaler = float (shift (nrBits));
|
||||
|
||||
if (fd -> container == "int8") {
|
||||
uint8_t lbuf [2 * amount];
|
||||
fread (lbuf, 1, 2 * amount, theFile);
|
||||
for (int i = 0; i < amount; i ++)
|
||||
buffer [i] = std::complex<float> (((int8_t)lbuf [2 * i]) / 127.0,
|
||||
((int8_t)lbuf [2 * i + 1]) / 127.0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "uint8") {
|
||||
uint8_t lbuf [2 * amount];
|
||||
fread (lbuf, 1, 2 * amount, theFile);
|
||||
for (int i = 0; i < amount; i ++)
|
||||
buffer [i] = std::complex<float> (mapTable [lbuf [2 * i]],
|
||||
mapTable [lbuf [2 * i + 1]]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int16") {
|
||||
uint8_t lbuf [4 * amount];
|
||||
fread (lbuf, 2, 2 * amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int16_t temp_16_1 = (lbuf [4 * i] << 8) | lbuf [4 * i + 1];
|
||||
int16_t temp_16_2 = (lbuf [4 * i + 2] << 8) | lbuf [4 * i + 3];
|
||||
buffer [i] = std::complex<float> ((float)temp_16_1 / scaler,
|
||||
(float)temp_16_2 / scaler);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int16_t temp_16_1 = (lbuf [4 * i + 1] << 8) | lbuf [4 * i];
|
||||
int16_t temp_16_2 = (lbuf [4 * i + 3] << 8) | lbuf [4 * i + 2];
|
||||
buffer [i] = std::complex<float> ((float)temp_16_1 / scaler,
|
||||
(float)temp_16_2 / scaler);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int24") {
|
||||
uint8_t lbuf [6 * amount];
|
||||
fread (lbuf, 3, 2 * amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [6 * i] << 16) |
|
||||
(lbuf [6 * i + 1] << 8) | lbuf [6 * i + 2];
|
||||
int32_t temp_32_2 = (lbuf [6 * i + 3] << 16) |
|
||||
(lbuf [4 * i + 4] << 8) | lbuf [6 * i + 5];
|
||||
if (temp_32_1 & 0x800000)
|
||||
temp_32_1 |= 0xFF000000;
|
||||
if (temp_32_2 & 0x800000)
|
||||
temp_32_2 |= 0xFF000000;
|
||||
buffer [i] = std::complex<float> ((float)temp_32_1 / scaler,
|
||||
(float)temp_32_2 / scaler);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [6 * i + 2] << 16) |
|
||||
(lbuf [6 * i + 1] << 8) | lbuf [6 * i];
|
||||
int32_t temp_32_2 = (lbuf [6 * i + 5] << 16) |
|
||||
(lbuf [6 * i + 4] << 8) | lbuf [6 * i + 3];
|
||||
if (temp_32_1 & 0x800000)
|
||||
temp_32_1 |= 0xFF000000;
|
||||
if (temp_32_2 & 0x800000)
|
||||
temp_32_2 |= 0xFF000000;
|
||||
buffer [i] = std::complex<float> ((float)temp_32_1 / scaler,
|
||||
(float)temp_32_2 / scaler);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int32") {
|
||||
uint8_t lbuf [8 * amount];
|
||||
fread (lbuf, 4, 2 * amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [8 * i] << 24) |
|
||||
(lbuf [8 * i + 1] << 16) |
|
||||
(lbuf [8 * i + 2] << 8) | lbuf [8 * i + 3];
|
||||
int32_t temp_32_2 = (lbuf [8 * i + 4] << 24) |
|
||||
(lbuf [8 * i + 5] << 16) |
|
||||
(lbuf [8 * i + 6] << 8) | lbuf [8 * i + 7];
|
||||
buffer [i] = std::complex<float> ((float)temp_32_1 / scaler,
|
||||
(float)temp_32_2 / scaler);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [8 * i + 3] << 24) |
|
||||
(lbuf [8 * i + 2] << 16) |
|
||||
(lbuf [8 * i + 1] << 8) | lbuf [8 * i];
|
||||
int32_t temp_32_2 = (lbuf [8 * i + 7] << 24) |
|
||||
(lbuf [8 * i + 6] << 16) |
|
||||
(lbuf [8 * i + 5] << 8) | lbuf [8 * i + 4];
|
||||
buffer [i] = std::complex<float> ((float)temp_32_1 / scaler,
|
||||
(float)temp_32_2 / scaler);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "float32") {
|
||||
uint8_t lbuf [8 * amount];
|
||||
fread (lbuf, 4, 2 * amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [8 * i] << 24) |
|
||||
(lbuf [8 * i + 1] << 16) |
|
||||
(lbuf [8 * i + 2] << 8) | lbuf [8 * i + 3];
|
||||
float t1 =*(float *)(&temp_32_1);
|
||||
int32_t temp_32_2 = (lbuf [8 * i + 4] << 24) |
|
||||
(lbuf [8 * i + 5] << 16) |
|
||||
(lbuf [8 * i + 6] << 8) | lbuf [8 * i + 7];
|
||||
float t2 =*(float *)(&temp_32_2);
|
||||
buffer [i] = std::complex<float> (t1, t2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [8 * i + 3] << 24) |
|
||||
(lbuf [8 * i + 2] << 16) |
|
||||
(lbuf [8 * i + 1] << 8) | lbuf [8 * i];
|
||||
float t1 =*(float *)(&temp_32_1);
|
||||
int32_t temp_32_2 = (lbuf [8 * i + 7] << 24) |
|
||||
(lbuf [8 * i + 6] << 16) |
|
||||
(lbuf [8 * i + 5] << 8) | lbuf [8 * i + 4];
|
||||
float t2 =*(float *)(&temp_32_2);
|
||||
buffer [i] = std::complex<float> (t1, t2);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void xml_Reader::readElements_QI (FILE *theFile,
|
||||
std::complex<float> *buffer,
|
||||
int amount) {
|
||||
|
||||
int nrBits = fd -> bitsperChannel;
|
||||
float scaler = float (shift (nrBits));
|
||||
|
||||
if (fd -> container == "int8") {
|
||||
uint8_t lbuf [2 * amount];
|
||||
fread (lbuf, 1, 2 * amount, theFile);
|
||||
for (int i = 0; i < amount; i ++)
|
||||
buffer [i] = std::complex<float> (((int8_t)lbuf [2 * i + 1]) / 127.0,
|
||||
((int8_t)lbuf [2 * i]) / 127.0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "uint8") {
|
||||
uint8_t lbuf [2 * amount];
|
||||
fread (lbuf, 1, 2 * amount, theFile);
|
||||
for (int i = 0; i < amount; i ++)
|
||||
buffer [i] = std::complex<float> (mapTable [2 * i + 1],
|
||||
mapTable [2 * i]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int16") {
|
||||
uint8_t lbuf [4 * amount];
|
||||
fread (lbuf, 2, 2 * amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int16_t temp_16_1 = (lbuf [4 * i] << 8) | lbuf [4 * i + 1];
|
||||
int16_t temp_16_2 = (lbuf [4 * i + 2] << 8) | lbuf [4 * i + 3];
|
||||
buffer [i] = std::complex<float> ((float)temp_16_2 / scaler,
|
||||
(float)temp_16_1 / scaler);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int16_t temp_16_1 = (lbuf [4 * i + 1] << 8) | lbuf [4 * i];
|
||||
int16_t temp_16_2 = (lbuf [4 * i + 3] << 8) | lbuf [4 * i + 2];
|
||||
buffer [i] = std::complex<float> ((float)temp_16_2 / scaler,
|
||||
(float)temp_16_1 / scaler);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int24") {
|
||||
uint8_t lbuf [6 * amount];
|
||||
fread (lbuf, 3, 2 * amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [6 * i] << 16) |
|
||||
(lbuf [6 * i + 1] << 8) | lbuf [6 * i + 2];
|
||||
int32_t temp_32_2 = (lbuf [6 * i + 3] << 16) |
|
||||
(lbuf [4 * i + 4] << 8) | lbuf [6 * i + 5];
|
||||
if (temp_32_1 & 0x800000)
|
||||
temp_32_1 |= 0xFF000000;
|
||||
if (temp_32_2 & 0x800000)
|
||||
temp_32_2 |= 0xFF000000;
|
||||
buffer [i] = std::complex<float> ((float)temp_32_2 / scaler,
|
||||
(float)temp_32_1 / scaler);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [6 * i + 2] << 16) |
|
||||
(lbuf [6 * i + 1] << 8) | lbuf [6 * i];
|
||||
int32_t temp_32_2 = (lbuf [6 * i + 5] << 16) |
|
||||
(lbuf [6 * i + 4] << 8) | lbuf [6 * i + 3];
|
||||
if (temp_32_1 & 0x800000)
|
||||
temp_32_1 |= 0xFF000000;
|
||||
if (temp_32_2 & 0x800000)
|
||||
temp_32_2 |= 0xFF000000;
|
||||
buffer [i] = std::complex<float> ((float)temp_32_2 / scaler,
|
||||
(float)temp_32_1 / scaler);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int32") {
|
||||
uint8_t lbuf [8 * amount];
|
||||
fread (lbuf, 4, 2 * amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [8 * i] << 24) |
|
||||
(lbuf [8 * i + 1] << 16) |
|
||||
(lbuf [8 * i + 2] << 8) | lbuf [8 * i + 3];
|
||||
int32_t temp_32_2 = (lbuf [8 * i + 4] << 24) |
|
||||
(lbuf [8 * i + 5] << 16) |
|
||||
(lbuf [8 * i + 6] << 8) | lbuf [8 * i + 7];
|
||||
buffer [i] = std::complex<float> ((float)temp_32_2 / scaler,
|
||||
(float)temp_32_1 / scaler);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [8 * i + 3] << 24) |
|
||||
(lbuf [8 * i + 2] << 16) |
|
||||
(lbuf [8 * i + 1] << 8) | lbuf [8 * i];
|
||||
int32_t temp_32_2 = (lbuf [8 * i + 7] << 24) |
|
||||
(lbuf [8 * i + 6] << 16) |
|
||||
(lbuf [8 * i + 5] << 8) | lbuf [8 * i + 4];
|
||||
buffer [i] = std::complex<float> ((float)temp_32_2 / scaler,
|
||||
(float)temp_32_1 / scaler);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "float32") {
|
||||
uint8_t lbuf [8 * amount];
|
||||
fread (lbuf, 4, 2 * amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [8 * i] << 24) |
|
||||
(lbuf [8 * i + 1] << 16) |
|
||||
(lbuf [8 * i + 2] << 8) | lbuf [8 * i + 3];
|
||||
float t1 =*(float *)(&temp_32_1);
|
||||
int32_t temp_32_2 = (lbuf [8 * i + 4] << 24) |
|
||||
(lbuf [8 * i + 5] << 16) |
|
||||
(lbuf [8 * i + 6] << 8) | lbuf [8 * i + 7];
|
||||
float t2 =*(float *)(&temp_32_2);
|
||||
buffer [i] = std::complex<float> (t1, t2);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [8 * i + 3] << 24) |
|
||||
(lbuf [8 * i + 2] << 16) |
|
||||
(lbuf [8 * i + 1] << 8) | lbuf [8 * i];
|
||||
float t1 =*(float *)(&temp_32_1);
|
||||
int32_t temp_32_2 = (lbuf [8 * i + 7] << 24) |
|
||||
(lbuf [8 * i + 6] << 16) |
|
||||
(lbuf [8 * i + 5] << 8) | lbuf [8 * i + 4];
|
||||
float t2 =*(float *)(&temp_32_2);
|
||||
buffer [i] = std::complex<float> (t1, t2);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
void xml_Reader::readElements_I (FILE *theFile,
|
||||
std::complex<float> *buffer,
|
||||
int amount) {
|
||||
|
||||
int nrBits = fd -> bitsperChannel;
|
||||
float scaler = float (shift (nrBits));
|
||||
|
||||
if (fd -> container == "int8") {
|
||||
uint8_t lbuf [amount];
|
||||
fread (lbuf, 1, amount, theFile);
|
||||
for (int i = 0; i < amount; i ++)
|
||||
buffer [i] =
|
||||
std::complex<float> ((int8_t)lbuf [i] / 127.0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "uint8") {
|
||||
uint8_t lbuf [amount];
|
||||
fread (lbuf, 1, amount, theFile);
|
||||
for (int i = 0; i < amount; i ++)
|
||||
buffer [i] = std::complex<float> (mapTable [lbuf [i]], 0);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int16") {
|
||||
uint8_t lbuf [2 * amount];
|
||||
fread (lbuf, 2, amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int16_t temp_16_1 = (lbuf [2 * i] << 8) | lbuf [2 * i + 1];
|
||||
buffer [i] =
|
||||
std::complex<float> ((float)temp_16_1 / scaler, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int16_t temp_16_1 = (lbuf [2 * i + 1] << 8) | lbuf [2 * i];
|
||||
buffer [i] =
|
||||
std::complex<float> ((float)temp_16_1 / scaler, 0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int24") {
|
||||
uint8_t lbuf [3 * amount];
|
||||
fread (lbuf, 3, amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [3 * i] << 16) |
|
||||
(lbuf [3 * i + 1] << 8) | lbuf [3 * i + 2];
|
||||
if (temp_32_1 & 0x800000)
|
||||
temp_32_1 |= 0xFF000000;
|
||||
buffer [i] =
|
||||
std::complex<float> ((float)temp_32_1 / scaler, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [3 * i + 2] << 16) |
|
||||
(lbuf [3 * i + 1] << 8) | lbuf [3 * i];
|
||||
if (temp_32_1 & 0x800000)
|
||||
temp_32_1 |= 0xFF000000;
|
||||
buffer [i] =
|
||||
std::complex<float> ((float)temp_32_1 / scaler, 0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int32") {
|
||||
uint8_t lbuf [4 * amount];
|
||||
fread (lbuf, 4, amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [4 * i] << 24) |
|
||||
(lbuf [4 * i + 1] << 16) |
|
||||
(lbuf [4 * i + 2] << 8) | lbuf [4 * i + 3];
|
||||
buffer [i] =
|
||||
std::complex<float> ((float)temp_32_1 / scaler, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [4 * i + 3] << 24) |
|
||||
(lbuf [4 * i + 2] << 16) |
|
||||
(lbuf [4 * i + 1] << 8) | lbuf [4 * i];
|
||||
buffer [i] =
|
||||
std::complex<float> ((float)temp_32_1 / scaler, 0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "float32") {
|
||||
uint8_t lbuf [4 * amount];
|
||||
fread (lbuf, 4, amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [4 * i] << 24) |
|
||||
(lbuf [4 * i + 1] << 16) |
|
||||
(lbuf [4 * i + 2] << 8) | lbuf [4 * i + 3];
|
||||
float t1 =*(float *)(&temp_32_1);
|
||||
buffer [i] = std::complex<float> (t1, 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [4 * i + 3] << 24) |
|
||||
(lbuf [4 * i + 2] << 16) |
|
||||
(lbuf [4 * i + 1] << 8) | lbuf [4 * i];
|
||||
float t1 =*(float *)(&temp_32_1);
|
||||
buffer [i] = std::complex<float> (t1, 0);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
void xml_Reader::readElements_Q (FILE *theFile,
|
||||
std::complex<float> *buffer,
|
||||
int amount) {
|
||||
|
||||
int nrBits = fd -> bitsperChannel;
|
||||
float scaler = float (shift (nrBits));
|
||||
|
||||
if (fd -> container == "int8") {
|
||||
uint8_t lbuf [amount];
|
||||
fread (lbuf, 1, amount, theFile);
|
||||
for (int i = 0; i < amount; i ++)
|
||||
buffer [i] =
|
||||
std::complex<float> (127.0, ((int8_t)lbuf [i] / 127.0));
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "uint8") {
|
||||
uint8_t lbuf [amount];
|
||||
fread (lbuf, 1, amount, theFile);
|
||||
for (int i = 0; i < amount; i ++)
|
||||
buffer [i] = std::complex<float> (0, mapTable [lbuf [i]]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int16") {
|
||||
uint8_t lbuf [2 * amount];
|
||||
fread (lbuf, 2, amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int16_t temp_16_1 = (lbuf [2 * i] << 8) | lbuf [2 * i + 1];
|
||||
buffer [i] =
|
||||
std::complex<float> (0, (float)temp_16_1 / scaler);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int16_t temp_16_1 = (lbuf [2 * i + 1] << 8) | lbuf [2 * i];
|
||||
buffer [i] =
|
||||
std::complex<float> (0, (float)temp_16_1 / scaler);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int24") {
|
||||
uint8_t lbuf [3 * amount];
|
||||
fread (lbuf, 3, amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [3 * i] << 16) |
|
||||
(lbuf [3 * i + 1] << 8) | lbuf [3 * i + 2];
|
||||
if (temp_32_1 & 0x800000)
|
||||
temp_32_1 |= 0xFF000000;
|
||||
buffer [i] =
|
||||
std::complex<float> (0, (float)temp_32_1 / scaler);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [3 * i + 2] << 16) |
|
||||
(lbuf [3 * i + 1] << 8) | lbuf [3 * i];
|
||||
if (temp_32_1 & 0x800000)
|
||||
temp_32_1 |= 0xFF000000;
|
||||
buffer [i] =
|
||||
std::complex<float> (0, (float)temp_32_1 / scaler);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "int32") {
|
||||
uint8_t lbuf [4 * amount];
|
||||
fread (lbuf, 4, amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [4 * i] << 24) |
|
||||
(lbuf [4 * i + 1] << 16) |
|
||||
(lbuf [4 * i + 2] << 8) | lbuf [4 * i + 3];
|
||||
buffer [i] =
|
||||
std::complex<float> (0, (float)temp_32_1 / scaler);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [4 * i + 3] << 24) |
|
||||
(lbuf [4 * i + 2] << 16) |
|
||||
(lbuf [4 * i + 1] << 8) | lbuf [4 * i];
|
||||
buffer [i] =
|
||||
std::complex<float> (0, (float)temp_32_1 / scaler);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fd -> container == "float32") {
|
||||
uint8_t lbuf [4 * amount];
|
||||
fread (lbuf, 4, amount, theFile);
|
||||
if (fd -> byteOrder == "MSB") {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [4 * i] << 24) |
|
||||
(lbuf [4 * i + 1] << 16) |
|
||||
(lbuf [4 * i + 2] << 8) | lbuf [4 * i + 3];
|
||||
float t1 =*(float *)(&temp_32_1);
|
||||
buffer [i] = std::complex<float> (0, t1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < amount; i ++) {
|
||||
int32_t temp_32_1 = (lbuf [4 * i + 3] << 24) |
|
||||
(lbuf [4 * i + 2] << 16) |
|
||||
(lbuf [4 * i + 1] << 8) | lbuf [4 * i];
|
||||
float t1 =*(float *)(&temp_32_1);
|
||||
buffer [i] = std::complex<float> (0, t1);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
78
devices/xml-filereader-old/xml-reader.h
Normal file
78
devices/xml-filereader-old/xml-reader.h
Normal file
@@ -0,0 +1,78 @@
|
||||
#
|
||||
/*
|
||||
* Copyright (C) 2014 .. 2019
|
||||
* Jan van Katwijk (J.vanKatwijk@gmail.com)
|
||||
* Lazy Chair Computing
|
||||
*
|
||||
* This file is part of the eti-cmdline program
|
||||
*
|
||||
* eti-cmdline is free software; you can redistribute it and/or modify
|
||||
* 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.
|
||||
*
|
||||
* eti-cmdline is distributed in the hope that it will be useful,
|
||||
* 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
|
||||
* along with eti-cmdline; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef __XML_READER__
|
||||
#define __XML_READER__
|
||||
|
||||
#include <thread>
|
||||
#include <stdio.h>
|
||||
#include "ringbuffer.h"
|
||||
#include <stdint.h>
|
||||
#include <complex>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
|
||||
class xml_fileReader;
|
||||
class xmlDescriptor;
|
||||
|
||||
class xml_Reader {
|
||||
public:
|
||||
xml_Reader (FILE *f,
|
||||
xmlDescriptor *fd,
|
||||
uint32_t filePointer,
|
||||
RingBuffer<std::complex<float>> *b,
|
||||
bool continue_on_eof);
|
||||
~xml_Reader ();
|
||||
void stopReader ();
|
||||
private:
|
||||
bool continue_on_eof;
|
||||
FILE *file;
|
||||
xmlDescriptor *fd;
|
||||
uint32_t filePointer;
|
||||
RingBuffer<std::complex<float>> *sampleBuffer;
|
||||
int nrElements;
|
||||
int samplesToRead;
|
||||
std::atomic<bool> running;
|
||||
void run ();
|
||||
std::thread threadHandle;
|
||||
int compute_nrSamples (FILE *f, int blockNumber);
|
||||
int readSamples (FILE *f,
|
||||
void(xml_Reader::*)(FILE *,
|
||||
std::complex<float> *, int));
|
||||
void readElements_IQ (FILE *f,
|
||||
std::complex<float> *, int amount);
|
||||
void readElements_QI (FILE *f,
|
||||
std::complex<float> *, int amount);
|
||||
void readElements_I (FILE *f,
|
||||
std::complex<float> *, int amount);
|
||||
void readElements_Q (FILE *f,
|
||||
std::complex<float> *, int amount);
|
||||
//
|
||||
// for the conversion - if any
|
||||
int16_t convBufferSize;
|
||||
int16_t convIndex;
|
||||
std::vector <std::complex<float> > convBuffer;
|
||||
int16_t mapTable_int [2048];
|
||||
float mapTable_float [2048];
|
||||
};
|
||||
|
||||
#endif
|
@@ -75,7 +75,7 @@ void xmlDescriptor::addChannelOrder (int channelOrder, std::string Value) {
|
||||
this -> iqOrder = "QI";
|
||||
}
|
||||
|
||||
void xmlDescriptor::add_dataBlock (int currBlock, int Count,
|
||||
void xmlDescriptor::add_dataBlock (int currBlock, uint64_t Count,
|
||||
int blockNumber, std::string Unit) {
|
||||
Blocks b;
|
||||
b. blockNumber = blockNumber;
|
||||
@@ -241,7 +241,9 @@ int zeroCount = 0;
|
||||
if (std::string (attr -> name ()) == "Channel")
|
||||
Unit = std::string (attr -> value ());
|
||||
}
|
||||
add_dataBlock (currBlock, std::stoi (Count),
|
||||
char *nix;
|
||||
add_dataBlock (currBlock,
|
||||
std::strtol (Count. c_str (), &nix, 10),
|
||||
std::stoi (Number), Unit);
|
||||
|
||||
xml_node <>* subsubNode = subNode -> first_node ();
|
||||
|
@@ -35,9 +35,9 @@ public:
|
||||
~Blocks () {}
|
||||
int blockNumber;
|
||||
int nrElements;
|
||||
std::string typeofUnit;
|
||||
std::string typeofUnit;
|
||||
int frequency;
|
||||
std::string modType;
|
||||
std::string modType;
|
||||
};
|
||||
|
||||
class xmlDescriptor {
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
std::string byteOrder);
|
||||
void addChannelOrder (int channelOrder,
|
||||
std::string Value);
|
||||
void add_dataBlock (int currBlock, int Count,
|
||||
void add_dataBlock (int currBlock, uint64_t Count,
|
||||
int blockNumber, std::string Unit);
|
||||
void add_freqtoBlock (int blockno, int freq);
|
||||
void add_modtoBlock (int blockno, std::string modType);
|
||||
|
@@ -49,7 +49,7 @@ private:
|
||||
std::atomic<bool> running;
|
||||
std::string fileName;
|
||||
RingBuffer<std::complex<float>> *_I_Buffer;
|
||||
uint32_t filePointer;
|
||||
uint64_t filePointer;
|
||||
xmlDescriptor *theDescriptor;
|
||||
xml_Reader *theReader;
|
||||
};
|
||||
|
@@ -50,7 +50,7 @@ struct timeval tv;
|
||||
|
||||
xml_Reader::xml_Reader (FILE *f,
|
||||
xmlDescriptor *fd,
|
||||
uint32_t filePointer,
|
||||
uint64_t filePointer,
|
||||
RingBuffer<std::complex<float>> *b,
|
||||
bool continue_on_eof) {
|
||||
this -> file = f;
|
||||
@@ -93,7 +93,7 @@ void xml_Reader::stopReader () {
|
||||
|
||||
static int cycleCount = 0;
|
||||
void xml_Reader::run () {
|
||||
int samplesRead = 0;
|
||||
uint64_t samplesRead = 0;
|
||||
uint64_t nextStop;
|
||||
int startPoint = filePointer;
|
||||
|
||||
@@ -137,9 +137,9 @@ int startPoint = filePointer;
|
||||
}
|
||||
}
|
||||
|
||||
int xml_Reader::compute_nrSamples (FILE *f, int blockNumber) {
|
||||
int nrElements = fd -> blockList. at (blockNumber). nrElements;
|
||||
int samplesToRead = 0;
|
||||
uint64_t xml_Reader::compute_nrSamples (FILE *f, int blockNumber) {
|
||||
uint64_t nrElements = fd -> blockList. at (blockNumber). nrElements;
|
||||
uint64_t samplesToRead = 0;
|
||||
|
||||
(void)f;
|
||||
if (fd -> blockList. at (blockNumber). typeofUnit == "Channel") {
|
||||
@@ -157,7 +157,7 @@ int samplesToRead = 0;
|
||||
return samplesToRead;
|
||||
}
|
||||
|
||||
int xml_Reader::readSamples (FILE *theFile,
|
||||
uint64_t xml_Reader::readSamples (FILE *theFile,
|
||||
void(xml_Reader::*r)(FILE *theFile,
|
||||
std::complex<float> *, int)) {
|
||||
std::complex<float> temp [2048];
|
||||
|
@@ -38,7 +38,7 @@ class xml_Reader {
|
||||
public:
|
||||
xml_Reader (FILE *f,
|
||||
xmlDescriptor *fd,
|
||||
uint32_t filePointer,
|
||||
uint64_t filePointer,
|
||||
RingBuffer<std::complex<float>> *b,
|
||||
bool continue_on_eof);
|
||||
~xml_Reader ();
|
||||
@@ -47,15 +47,15 @@ private:
|
||||
bool continue_on_eof;
|
||||
FILE *file;
|
||||
xmlDescriptor *fd;
|
||||
uint32_t filePointer;
|
||||
uint64_t filePointer;
|
||||
RingBuffer<std::complex<float>> *sampleBuffer;
|
||||
int nrElements;
|
||||
int samplesToRead;
|
||||
uint64_t nrElements;
|
||||
uint64_t samplesToRead;
|
||||
std::atomic<bool> running;
|
||||
void run ();
|
||||
std::thread threadHandle;
|
||||
int compute_nrSamples (FILE *f, int blockNumber);
|
||||
int readSamples (FILE *f,
|
||||
uint64_t compute_nrSamples (FILE *f, int blockNumber);
|
||||
uint64_t readSamples (FILE *f,
|
||||
void(xml_Reader::*)(FILE *,
|
||||
std::complex<float> *, int));
|
||||
void readElements_IQ (FILE *f,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required( VERSION 2.8.11 )
|
||||
cmake_minimum_required( VERSION 3.25 )
|
||||
set (objectName dab_cmdline-2)
|
||||
#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -flto")
|
||||
#set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
|
||||
@@ -164,6 +164,7 @@ endif ()
|
||||
if (NOT FFTW3F_FOUND)
|
||||
message(FATAL_ERROR "please install FFTW3")
|
||||
endif ()
|
||||
list(APPEND extraLibs ${FFTW3F_LIBRARIES})
|
||||
|
||||
find_package(Faad)
|
||||
if (NOT FAAD_FOUND )
|
||||
@@ -665,7 +666,6 @@ endif ()
|
||||
endif()
|
||||
|
||||
target_link_libraries (${objectName}
|
||||
${FFTW3F_LIBRARIES}
|
||||
${extraLibs}
|
||||
${FAAD_LIBRARIES}
|
||||
${CMAKE_DL_LIBS}
|
||||
|
Reference in New Issue
Block a user