audio-ess/ewolsa/LoadedFile.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2014-03-20 10:24:13 +01:00
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#include <etk/types.h>
#include <ewolsa/debug.h>
#include <ewolsa/LoadedFile.h>
#include <ewolsa/decWav.h>
2014-03-31 16:36:09 +02:00
#include <ewolsa/decOgg.h>
2014-03-20 10:24:13 +01:00
2014-04-03 11:00:51 +02:00
static void* threadCallback2(void *_ptr) {
ewolsa::LoadedFile* decodeFile = (ewolsa::LoadedFile*)_ptr;
decodeFile->decode();
return NULL;
}
void ewolsa::LoadedFile::decode(void) {
m_data = ewolsa::ogg::loadAudioFile(m_file, m_nbChanRequested, m_nbSamples);
}
2014-03-20 10:24:13 +01:00
2014-03-31 16:36:09 +02:00
ewolsa::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanRequested) :
m_file(_fileName),
2014-03-20 10:24:13 +01:00
m_nbSamples(0),
m_nbChanRequested(_nbChanRequested),
2014-03-20 10:24:13 +01:00
m_requestedTime(1),
2014-04-03 11:00:51 +02:00
m_data(NULL){
m_thread = NULL;
std::string tmpName = std::tolower(m_file);
2014-03-31 16:36:09 +02:00
// select the corect Loader :
if (end_with(tmpName, ".wav") == true) {
m_data = ewolsa::wav::loadAudioFile(m_file, m_nbChanRequested, m_nbSamples);
2014-03-31 16:36:09 +02:00
} else if (end_with(tmpName, ".ogg") == true) {
2014-04-03 11:00:51 +02:00
EWOLSA_DEBUG("create thread");
pthread_create(&m_thread2, NULL, &threadCallback2, this);
EWOLSA_DEBUG("done 1");
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
EWOLSA_DEBUG("done 2");
2014-03-31 16:36:09 +02:00
} else {
EWOLSA_ERROR("Extention not managed '" << m_file << "' Sopported extention : .wav / .ogg");
2014-03-31 16:36:09 +02:00
return;
}
2014-04-03 11:00:51 +02:00
/*
if (m_data == NULL) {
// write an error ...
EWOLSA_ERROR("Can not open file : " << _fileName);
}
*/
2014-03-20 10:24:13 +01:00
}
ewolsa::LoadedFile::~LoadedFile(void) {
// TODO : wait end of thread...
2014-03-20 10:24:13 +01:00
if (m_data != NULL) {
delete[] m_data;
m_data = NULL;
}
}