Compare commits

...

3 Commits

Author SHA1 Message Date
875e52574e [DEV] change log system 2014-04-30 22:18:00 +02:00
c25640d80e [DEV] add gitignore and missing return 2014-04-19 00:17:39 +02:00
143d319c91 [DEV] might work, but not ... 2014-04-03 12:01:23 +02:00
7 changed files with 99 additions and 75 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.pyc

View File

@ -12,48 +12,34 @@
#include <ewolsa/LoadedFile.h> #include <ewolsa/LoadedFile.h>
#include <ewolsa/decWav.h> #include <ewolsa/decWav.h>
#include <ewolsa/decOgg.h> #include <ewolsa/decOgg.h>
#include <thread>
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);
}
ewolsa::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanRequested) : ewolsa::LoadedFile::LoadedFile(const std::string& _fileName, int8_t _nbChanRequested) :
m_file(_fileName), m_file(_fileName),
m_nbSamples(0), m_nbSamples(0),
m_nbSamplesTotal(0),
m_nbChanRequested(_nbChanRequested), m_nbChanRequested(_nbChanRequested),
m_requestedTime(1), m_requestedTime(1),
m_data(NULL){ m_data(NULL) {
m_thread = NULL; m_stopRequested = false;
std::string tmpName = std::tolower(m_file); std::string tmpName = std::tolower(m_file);
// select the corect Loader : // select the corect Loader :
if (end_with(tmpName, ".wav") == true) { if (end_with(tmpName, ".wav") == true) {
m_data = ewolsa::wav::loadAudioFile(m_file, m_nbChanRequested, m_nbSamples); m_data = ewolsa::wav::loadAudioFile(m_file, m_nbChanRequested, m_nbSamples);
} else if (end_with(tmpName, ".ogg") == true) {
EWOLSA_DEBUG("create thread");
pthread_create(&m_thread2, NULL, &threadCallback2, this);
EWOLSA_DEBUG("done 1");
std::this_thread::sleep_for(std::chrono::milliseconds(1000)); std::this_thread::sleep_for(std::chrono::milliseconds(1000));
EWOLSA_DEBUG("done 2"); m_nbSamplesTotal = m_nbSamples;
} else if (end_with(tmpName, ".ogg") == true) {
pthread_create(&m_thread2, NULL, &ewolsa::ogg::loadFileThreadedMode, this);
} else { } else {
EWOLSA_ERROR("Extention not managed '" << m_file << "' Sopported extention : .wav / .ogg"); EWOLSA_ERROR("Extention not managed '" << m_file << "' Sopported extention : .wav / .ogg");
return; return;
} }
/*
if (m_data == NULL) {
// write an error ...
EWOLSA_ERROR("Can not open file : " << _fileName);
}
*/
} }
ewolsa::LoadedFile::~LoadedFile(void) { ewolsa::LoadedFile::~LoadedFile(void) {
m_stopRequested = true;
// TODO : wait end of thread... // TODO : wait end of thread...
if (m_data != NULL) { if (m_data != NULL) {
delete[] m_data; delete[] m_data;

View File

@ -11,19 +11,20 @@
#define __EWOLSA_LOADED_FILE_H__ #define __EWOLSA_LOADED_FILE_H__
#include <etk/types.h> #include <etk/types.h>
#include <thread>
#include <pthread.h> #include <pthread.h>
namespace ewolsa { namespace ewolsa {
class LoadedFile { class LoadedFile {
private: private:
std::thread* m_thread;
pthread_t m_thread2; pthread_t m_thread2;
public:
bool m_stopRequested;
public: public:
LoadedFile(const std::string& _fileName, int8_t _nbChanRequested=1); LoadedFile(const std::string& _fileName, int8_t _nbChanRequested=1);
~LoadedFile(void); ~LoadedFile(void);
std::string m_file; std::string m_file;
int32_t m_nbSamples; int32_t m_nbSamples;
int32_t m_nbSamplesTotal;
int32_t m_nbChanRequested; int32_t m_nbChanRequested;
int32_t m_requestedTime; int32_t m_requestedTime;
int16_t* m_data; int16_t* m_data;
@ -31,7 +32,6 @@ namespace ewolsa {
const std::string& getName(void) { const std::string& getName(void) {
return m_file; return m_file;
}; };
void decode(void);
}; };
}; };

View File

@ -6,7 +6,9 @@
* @license BSD 3 clauses (see license file) * @license BSD 3 clauses (see license file)
*/ */
#include <airtaudio/debug.h> #include <ewolsa/debug.h>
const char * ewolSaLibName = "ewol-sa ";
int32_t ewolsa::getLogId(void) {
static int32_t g_val = etk::log::registerInstance("ewol-sa");
return g_val;
}

View File

@ -9,20 +9,45 @@
#ifndef __EWOLSA_DEBUG_H__ #ifndef __EWOLSA_DEBUG_H__
#define __EWOLSA_DEBUG_H__ #define __EWOLSA_DEBUG_H__
#include <etk/types.h> #include <etk/log.h>
#include <etk/debugGeneric.h>
extern const char * ewolSaLibName; namespace ewolsa {
int32_t getLogId(void);
};
// TODO : Review this problem of multiple intanciation of "std::stringbuf sb"
#define EWOLSA_BASE(info,data) \
do { \
if (info <= etk::log::getLevel(ewolsa::getLogId())) { \
std::stringbuf sb; \
std::ostream tmpStream(&sb); \
tmpStream << data; \
etk::log::logStream(ewolsa::getLogId(), info, __LINE__, __class__, __func__, tmpStream); \
} \
} while(0)
#define EWOLSA_CRITICAL(data) EWOLSA_BASE(1, data)
#define EWOLSA_ERROR(data) EWOLSA_BASE(2, data)
#define EWOLSA_WARNING(data) EWOLSA_BASE(3, data)
#ifdef DEBUG
#define EWOLSA_INFO(data) EWOLSA_BASE(4, data)
#define EWOLSA_DEBUG(data) EWOLSA_BASE(5, data)
#define EWOLSA_VERBOSE(data) EWOLSA_BASE(6, data)
#define EWOLSA_TODO(data) EWOLSA_BASE(4, "TODO : " << data)
#else
#define EWOLSA_INFO(data) do { } while(false)
#define EWOLSA_DEBUG(data) do { } while(false)
#define EWOLSA_VERBOSE(data) do { } while(false)
#define EWOLSA_TODO(data) do { } while(false)
#endif
#define EWOLSA_ASSERT(cond,data) \
do { \
if (!(cond)) { \
EWOLSA_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)
#define EWOLSA_CRITICAL(data) ETK_CRITICAL(ewolSaLibName, data)
#define EWOLSA_WARNING(data) ETK_WARNING(ewolSaLibName, data)
#define EWOLSA_ERROR(data) ETK_ERROR(ewolSaLibName, data)
#define EWOLSA_INFO(data) ETK_INFO(ewolSaLibName, data)
#define EWOLSA_DEBUG(data) ETK_DEBUG(ewolSaLibName, data)
#define EWOLSA_VERBOSE(data) ETK_VERBOSE(ewolSaLibName, data)
#define EWOLSA_ASSERT(cond,data) ETK_ASSERT(ewolSaLibName, cond, data)
#define EWOLSA_CHECK_INOUT(cond) ETK_CHECK_INOUT(ewolSaLibName, cond)
#define EWOLSA_TODO(cond) ETK_TODO(ewolSaLibName, cond)
#endif #endif

View File

@ -12,10 +12,12 @@
#include <ewolsa/decOgg.h> #include <ewolsa/decOgg.h>
#include <tremor/ivorbiscodec.h> #include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h> #include <tremor/ivorbisfile.h>
#include <ewolsa/LoadedFile.h>
static size_t LocalReadFunc(void *ptr, size_t size, size_t nmemb, void *datasource) { static size_t LocalReadFunc(void *ptr, size_t size, size_t nmemb, void *datasource) {
etk::FSNode* file = static_cast<etk::FSNode*>(datasource); etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
EWOLSA_DEBUG("read : " << size << " " << nmemb);
return file->fileRead(ptr, size, nmemb); return file->fileRead(ptr, size, nmemb);
} }
@ -39,6 +41,7 @@ static int localSeekFunc(void *datasource, ogg_int64_t offset, int whence) {
static int localCloseFunc(void *datasource) { static int localCloseFunc(void *datasource) {
etk::FSNode* file = static_cast<etk::FSNode*>(datasource); etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
file->fileClose(); file->fileClose();
return 0;
} }
static long localTellFunc(void *datasource) { static long localTellFunc(void *datasource) {
@ -46,10 +49,16 @@ static long localTellFunc(void *datasource) {
return file->fileTell(); return file->fileTell();
} }
int16_t* ewolsa::ogg::loadAudioFile(const std::string& _filename, int8_t _nbChan, int32_t& _nbSampleOut) { void* ewolsa::ogg::loadFileThreadedMode(void *_ptr) {
_nbSampleOut = 0; ewolsa::LoadedFile* self = (ewolsa::LoadedFile*)_ptr;
if (self == NULL) {
EWOLSA_ERROR("NULL handle");
return NULL;
}
self->m_data = NULL;
self->m_nbSamples = 0;
self->m_nbSamplesTotal = 0;
OggVorbis_File vf; OggVorbis_File vf;
int32_t eof=0;
int32_t current_section; int32_t current_section;
ov_callbacks tmpCallback = { ov_callbacks tmpCallback = {
LocalReadFunc, LocalReadFunc,
@ -57,29 +66,29 @@ int16_t* ewolsa::ogg::loadAudioFile(const std::string& _filename, int8_t _nbChan
localCloseFunc, localCloseFunc,
localTellFunc localTellFunc
}; };
etk::FSNode fileAccess(_filename); EWOLSA_WARNING("open file (OGG) '" << self->m_file << "'");
etk::FSNode fileAccess(self->m_file);
// Start loading the XML : // Start loading the XML :
//EWOLSA_DEBUG("open file (OGG) \"" << fileAccess << "\"");
if (false == fileAccess.exist()) { if (false == fileAccess.exist()) {
//EWOLSA_ERROR("File Does not exist : \"" << fileAccess << "\""); EWOLSA_ERROR("File Does not exist : '" << fileAccess << "'");
return NULL; return NULL;
} }
int32_t fileSize = fileAccess.fileSize(); int32_t fileSize = fileAccess.fileSize();
if (0 == fileSize) { if (0 == fileSize) {
//EWOLSA_ERROR("This file is empty : \"" << fileAccess << "\""); EWOLSA_ERROR("This file is empty : '" << fileAccess << "'");
return NULL; return NULL;
} }
EWOLSA_WARNING("ogg file size = " << fileSize);
if (false == fileAccess.fileOpenRead()) { if (false == fileAccess.fileOpenRead()) {
//EWOLSA_ERROR("Can not open the file : \"" << fileAccess << "\""); EWOLSA_ERROR("Can not open the file : '" << fileAccess << "'");
return NULL; return NULL;
} }
if (ov_open_callbacks(&fileAccess, &vf, NULL, 0, tmpCallback) < 0) { if (ov_open_callbacks(&fileAccess, &vf, NULL, 0, tmpCallback) < 0) {
//EWOLSA_ERROR("Input does not appear to be an Ogg bitstream."); EWOLSA_ERROR("Input does not appear to be an Ogg bitstream.");
return NULL; return NULL;
} }
vorbis_info *vi=ov_info(&vf,-1); vorbis_info *vi=ov_info(&vf,-1);
_nbSampleOut = ov_pcm_total(&vf,-1) / vi->channels; self->m_nbSamplesTotal = ov_pcm_total(&vf,-1) / vi->channels;
/*
{ {
char **ptr=ov_comment(&vf,-1)->user_comments; char **ptr=ov_comment(&vf,-1)->user_comments;
while(*ptr){ while(*ptr){
@ -87,60 +96,62 @@ int16_t* ewolsa::ogg::loadAudioFile(const std::string& _filename, int8_t _nbChan
++ptr; ++ptr;
} }
EWOLSA_DEBUG("Bitstream is " << (int32_t)vi->channels << " channel, " << (int32_t)vi->rate << "Hz"); EWOLSA_DEBUG("Bitstream is " << (int32_t)vi->channels << " channel, " << (int32_t)vi->rate << "Hz");
EWOLSA_DEBUG("Decoded length: " << _nbSampleOut << " samples"); EWOLSA_DEBUG("Decoded length: " << self->m_nbSamplesTotal << " samples");
EWOLSA_DEBUG("Encoded by: " << ov_comment(&vf,-1)->vendor); EWOLSA_DEBUG("Encoded by: " << ov_comment(&vf,-1)->vendor);
EWOLSA_DEBUG("time: " << ((float)_nbSampleOut/(float)vi->rate)/60.0); EWOLSA_DEBUG("time: " << ((float)self->m_nbSamplesTotal/(float)vi->rate)/60.0);
} }
*/ self->m_data = new int16_t[self->m_nbSamplesTotal*self->m_nbChanRequested*sizeof(int16_t)];
int16_t* outputData = new int16_t[_nbSampleOut*_nbChan*sizeof(int16_t)]; if (NULL == self->m_data) {
if (NULL == outputData) { EWOLSA_ERROR("Allocation ERROR try to allocate " << (int32_t)(self->m_nbSamplesTotal*self->m_nbChanRequested*sizeof(int16_t) ) << "bytes");
//EWOLSA_ERROR("Allocation ERROR try to allocate " << (int32_t)(_nbSampleOut*_nbChan*sizeof(int16_t) ) << "bytes");
return NULL; return NULL;
} }
int32_t pos = 0;
self->m_nbSamples = 0;
char pcmout[4096]; char pcmout[4096];
while(!eof){ bool eof = false;
while ( eof == false
&& self->m_stopRequested == false) {
long ret=ov_read(&vf, pcmout, sizeof(pcmout), &current_section); long ret=ov_read(&vf, pcmout, sizeof(pcmout), &current_section);
if (ret == 0) { if (ret == 0) {
/* EOF */ /* EOF */
eof=1; eof = true;
} else if (ret < 0) { } else if (ret < 0) {
if(ret==OV_EBADLINK){ if(ret==OV_EBADLINK){
//EWOLSA_ERROR("Corrupt bitstream section! Exiting."); EWOLSA_ERROR("Corrupt bitstream section! Exiting.");
// TODO : Remove pointer data ... // TODO : Remove pointer data ...
return NULL; return NULL;
} }
} else { } else {
int16_t* pointerIn = (int16_t*)pcmout; int16_t* pointerIn = (int16_t*)pcmout;
int16_t* pointerOut = outputData+pos; int16_t* pointerOut = self->m_data+self->m_nbSamples;
if (_nbChan == vi->channels) { if (self->m_nbChanRequested == vi->channels) {
memcpy(pointerOut, pointerIn, ret); memcpy(pointerOut, pointerIn, ret);
pos += ret/2; self->m_nbSamples += ret/2;
} else { } else {
if ( _nbChan == 1 if ( self->m_nbChanRequested == 1
&& vi->channels == 2) { && vi->channels == 2) {
for (int32_t iii=0; iii<ret/4 ; ++iii) { for (int32_t iii=0; iii<ret/4 ; ++iii) {
pointerOut[iii] = pointerIn[iii*2]; pointerOut[iii] = pointerIn[iii*2];
} }
pos += ret/4; self->m_nbSamples += ret/4;
} else if ( _nbChan == 2 } else if ( self->m_nbChanRequested == 2
&& vi->channels == 1) { && vi->channels == 1) {
for (int32_t iii=0; iii<ret/2 ; ++iii) { for (int32_t iii=0; iii<ret/2 ; ++iii) {
pointerOut[iii*2] = pointerIn[iii]; pointerOut[iii*2] = pointerIn[iii];
pointerOut[iii*2+1] = pointerIn[iii]; pointerOut[iii*2+1] = pointerIn[iii];
} }
pos += ret; self->m_nbSamples += ret;
} else { } else {
//EWOLSA_ERROR("Can not convert " << (int32_t)vi->channels << " channels in " << _nbChan << " channels"); EWOLSA_ERROR("Can not convert " << (int32_t)vi->channels << " channels in " << self->m_nbChanRequested << " channels");
} }
} }
// fwrite(pcmout,1,ret,stdout); // fwrite(pcmout,1,ret,stdout);
//EWOLSA_DEBUG("get data : " << ret << " Bytes"); EWOLSA_DEBUG("get data : " << (int32_t)ret << " Bytes");
} }
} }
/* cleanup */ /* cleanup */
ov_clear(&vf); ov_clear(&vf);
//EWOLSA_DEBUG("Done."); EWOLSA_DEBUG("Done.");
return outputData;
}
return NULL;
}

View File

@ -13,8 +13,7 @@
namespace ewolsa { namespace ewolsa {
namespace ogg { namespace ogg {
int16_t* loadAudioFile(const std::string& _filename, int8_t _nbChan, int32_t& _nbSampleOut); void* loadFileThreadedMode(void *_ptr);
} }
}; };