You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
2.5 KiB
125 lines
2.5 KiB
/*
|
|
* Copyright (C) 2014 by Jonathan Naylor G4KLX
|
|
* Copyright (C) 2022 by Geoffrey Merck F4FXL / KC3FRA
|
|
*
|
|
* This program 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.
|
|
*
|
|
* This program 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 this program; if not, write to the Free Software
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
*/
|
|
|
|
#include "DStarDefines.h"
|
|
#include "VoiceStore.h"
|
|
|
|
CVoiceStore::CVoiceStore(const std::vector<std::string>& filenames) :
|
|
m_filenames(),
|
|
m_header(NULL),
|
|
m_fileNumber(0U),
|
|
m_file()
|
|
{
|
|
for(auto f : filenames) {
|
|
m_filenames.push_back(f);
|
|
}
|
|
}
|
|
|
|
CVoiceStore::~CVoiceStore()
|
|
{
|
|
m_filenames.clear();
|
|
}
|
|
|
|
bool CVoiceStore::open()
|
|
{
|
|
std::string fileName = m_filenames.at(0U);
|
|
|
|
bool ret = m_file.open(fileName);
|
|
if (!ret)
|
|
return false;
|
|
|
|
DVTFR_TYPE type = m_file.read();
|
|
if (type != DVTFR_HEADER) {
|
|
m_file.close();
|
|
return false;
|
|
}
|
|
|
|
m_header = m_file.readHeader();
|
|
m_fileNumber = 0U;
|
|
|
|
return true;
|
|
}
|
|
|
|
CHeaderData* CVoiceStore::getHeader()
|
|
{
|
|
CHeaderData* header = m_header;
|
|
|
|
m_header = NULL;
|
|
|
|
return header;
|
|
}
|
|
|
|
CAMBEData* CVoiceStore::getAMBE()
|
|
{
|
|
DVTFR_TYPE type = m_file.read();
|
|
if (type == DVTFR_DATA) {
|
|
CAMBEData* ambe = m_file.readData();
|
|
if (ambe != NULL)
|
|
return ambe;
|
|
}
|
|
|
|
for (;;) {
|
|
m_file.close();
|
|
m_fileNumber++;
|
|
|
|
// The end of the last file?
|
|
if (m_fileNumber == m_filenames.size())
|
|
return NULL;
|
|
|
|
std::string filename = m_filenames.at(m_fileNumber);
|
|
|
|
bool ret = m_file.open(filename);
|
|
if (!ret)
|
|
return NULL;
|
|
|
|
// This should get the header
|
|
type = m_file.read();
|
|
|
|
if (type == DVTFR_HEADER) {
|
|
// Throw the header away
|
|
CHeaderData* header = m_file.readHeader();
|
|
delete header;
|
|
} else if (type == DVTFR_DATA) {
|
|
// Shouldn't usually happen
|
|
CAMBEData* ambe = m_file.readData();
|
|
if (ambe != NULL)
|
|
return ambe;
|
|
else
|
|
continue;
|
|
} else {
|
|
// !!!!
|
|
continue;
|
|
}
|
|
|
|
// This should get the first data record
|
|
type = m_file.read();
|
|
|
|
if (type == DVTFR_DATA) {
|
|
CAMBEData* ambe = m_file.readData();
|
|
if (ambe != NULL)
|
|
return ambe;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CVoiceStore::close()
|
|
{
|
|
m_file.close();
|
|
}
|