Compare commits
3 Commits
main
...
dev_archiv
Author | SHA1 | Date | |
---|---|---|---|
875e52574e | |||
c25640d80e | |||
143d319c91 |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
*.pyc
|
@ -12,48 +12,34 @@
|
||||
#include <ewolsa/LoadedFile.h>
|
||||
#include <ewolsa/decWav.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) :
|
||||
m_file(_fileName),
|
||||
m_nbSamples(0),
|
||||
m_nbSamplesTotal(0),
|
||||
m_nbChanRequested(_nbChanRequested),
|
||||
m_requestedTime(1),
|
||||
m_data(NULL){
|
||||
m_thread = NULL;
|
||||
m_data(NULL) {
|
||||
m_stopRequested = false;
|
||||
std::string tmpName = std::tolower(m_file);
|
||||
// select the corect Loader :
|
||||
if (end_with(tmpName, ".wav") == true) {
|
||||
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));
|
||||
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 {
|
||||
EWOLSA_ERROR("Extention not managed '" << m_file << "' Sopported extention : .wav / .ogg");
|
||||
return;
|
||||
}
|
||||
/*
|
||||
if (m_data == NULL) {
|
||||
// write an error ...
|
||||
EWOLSA_ERROR("Can not open file : " << _fileName);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
ewolsa::LoadedFile::~LoadedFile(void) {
|
||||
m_stopRequested = true;
|
||||
// TODO : wait end of thread...
|
||||
if (m_data != NULL) {
|
||||
delete[] m_data;
|
||||
|
@ -11,19 +11,20 @@
|
||||
#define __EWOLSA_LOADED_FILE_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <thread>
|
||||
#include <pthread.h>
|
||||
|
||||
namespace ewolsa {
|
||||
class LoadedFile {
|
||||
private:
|
||||
std::thread* m_thread;
|
||||
pthread_t m_thread2;
|
||||
public:
|
||||
bool m_stopRequested;
|
||||
public:
|
||||
LoadedFile(const std::string& _fileName, int8_t _nbChanRequested=1);
|
||||
~LoadedFile(void);
|
||||
std::string m_file;
|
||||
int32_t m_nbSamples;
|
||||
int32_t m_nbSamplesTotal;
|
||||
int32_t m_nbChanRequested;
|
||||
int32_t m_requestedTime;
|
||||
int16_t* m_data;
|
||||
@ -31,7 +32,6 @@ namespace ewolsa {
|
||||
const std::string& getName(void) {
|
||||
return m_file;
|
||||
};
|
||||
void decode(void);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,9 @@
|
||||
* @license BSD 3 clauses (see license file)
|
||||
*/
|
||||
|
||||
#include <airtaudio/debug.h>
|
||||
|
||||
const char * ewolSaLibName = "ewol-sa ";
|
||||
#include <ewolsa/debug.h>
|
||||
|
||||
int32_t ewolsa::getLogId(void) {
|
||||
static int32_t g_val = etk::log::registerInstance("ewol-sa");
|
||||
return g_val;
|
||||
}
|
||||
|
@ -9,20 +9,45 @@
|
||||
#ifndef __EWOLSA_DEBUG_H__
|
||||
#define __EWOLSA_DEBUG_H__
|
||||
|
||||
#include <etk/types.h>
|
||||
#include <etk/debugGeneric.h>
|
||||
#include <etk/log.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
|
||||
|
||||
|
@ -12,10 +12,12 @@
|
||||
#include <ewolsa/decOgg.h>
|
||||
#include <tremor/ivorbiscodec.h>
|
||||
#include <tremor/ivorbisfile.h>
|
||||
#include <ewolsa/LoadedFile.h>
|
||||
|
||||
|
||||
static size_t LocalReadFunc(void *ptr, size_t size, size_t nmemb, void *datasource) {
|
||||
etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
|
||||
EWOLSA_DEBUG("read : " << 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) {
|
||||
etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
|
||||
file->fileClose();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long localTellFunc(void *datasource) {
|
||||
@ -46,10 +49,16 @@ static long localTellFunc(void *datasource) {
|
||||
return file->fileTell();
|
||||
}
|
||||
|
||||
int16_t* ewolsa::ogg::loadAudioFile(const std::string& _filename, int8_t _nbChan, int32_t& _nbSampleOut) {
|
||||
_nbSampleOut = 0;
|
||||
void* ewolsa::ogg::loadFileThreadedMode(void *_ptr) {
|
||||
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;
|
||||
int32_t eof=0;
|
||||
int32_t current_section;
|
||||
ov_callbacks tmpCallback = {
|
||||
LocalReadFunc,
|
||||
@ -57,29 +66,29 @@ int16_t* ewolsa::ogg::loadAudioFile(const std::string& _filename, int8_t _nbChan
|
||||
localCloseFunc,
|
||||
localTellFunc
|
||||
};
|
||||
etk::FSNode fileAccess(_filename);
|
||||
EWOLSA_WARNING("open file (OGG) '" << self->m_file << "'");
|
||||
etk::FSNode fileAccess(self->m_file);
|
||||
// Start loading the XML :
|
||||
//EWOLSA_DEBUG("open file (OGG) \"" << fileAccess << "\"");
|
||||
if (false == fileAccess.exist()) {
|
||||
//EWOLSA_ERROR("File Does not exist : \"" << fileAccess << "\"");
|
||||
EWOLSA_ERROR("File Does not exist : '" << fileAccess << "'");
|
||||
return NULL;
|
||||
}
|
||||
int32_t fileSize = fileAccess.fileSize();
|
||||
if (0 == fileSize) {
|
||||
//EWOLSA_ERROR("This file is empty : \"" << fileAccess << "\"");
|
||||
EWOLSA_ERROR("This file is empty : '" << fileAccess << "'");
|
||||
return NULL;
|
||||
}
|
||||
EWOLSA_WARNING("ogg file size = " << fileSize);
|
||||
if (false == fileAccess.fileOpenRead()) {
|
||||
//EWOLSA_ERROR("Can not open the file : \"" << fileAccess << "\"");
|
||||
EWOLSA_ERROR("Can not open the file : '" << fileAccess << "'");
|
||||
return NULL;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
while(*ptr){
|
||||
@ -87,60 +96,62 @@ int16_t* ewolsa::ogg::loadAudioFile(const std::string& _filename, int8_t _nbChan
|
||||
++ptr;
|
||||
}
|
||||
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("time: " << ((float)_nbSampleOut/(float)vi->rate)/60.0);
|
||||
EWOLSA_DEBUG("time: " << ((float)self->m_nbSamplesTotal/(float)vi->rate)/60.0);
|
||||
}
|
||||
*/
|
||||
int16_t* outputData = new int16_t[_nbSampleOut*_nbChan*sizeof(int16_t)];
|
||||
if (NULL == outputData) {
|
||||
//EWOLSA_ERROR("Allocation ERROR try to allocate " << (int32_t)(_nbSampleOut*_nbChan*sizeof(int16_t) ) << "bytes");
|
||||
self->m_data = new int16_t[self->m_nbSamplesTotal*self->m_nbChanRequested*sizeof(int16_t)];
|
||||
if (NULL == self->m_data) {
|
||||
EWOLSA_ERROR("Allocation ERROR try to allocate " << (int32_t)(self->m_nbSamplesTotal*self->m_nbChanRequested*sizeof(int16_t) ) << "bytes");
|
||||
return NULL;
|
||||
}
|
||||
int32_t pos = 0;
|
||||
|
||||
self->m_nbSamples = 0;
|
||||
char pcmout[4096];
|
||||
while(!eof){
|
||||
bool eof = false;
|
||||
while ( eof == false
|
||||
&& self->m_stopRequested == false) {
|
||||
long ret=ov_read(&vf, pcmout, sizeof(pcmout), ¤t_section);
|
||||
if (ret == 0) {
|
||||
/* EOF */
|
||||
eof=1;
|
||||
eof = true;
|
||||
} else if (ret < 0) {
|
||||
if(ret==OV_EBADLINK){
|
||||
//EWOLSA_ERROR("Corrupt bitstream section! Exiting.");
|
||||
EWOLSA_ERROR("Corrupt bitstream section! Exiting.");
|
||||
// TODO : Remove pointer data ...
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
int16_t* pointerIn = (int16_t*)pcmout;
|
||||
int16_t* pointerOut = outputData+pos;
|
||||
if (_nbChan == vi->channels) {
|
||||
int16_t* pointerOut = self->m_data+self->m_nbSamples;
|
||||
if (self->m_nbChanRequested == vi->channels) {
|
||||
memcpy(pointerOut, pointerIn, ret);
|
||||
pos += ret/2;
|
||||
self->m_nbSamples += ret/2;
|
||||
} else {
|
||||
if ( _nbChan == 1
|
||||
if ( self->m_nbChanRequested == 1
|
||||
&& vi->channels == 2) {
|
||||
for (int32_t iii=0; iii<ret/4 ; ++iii) {
|
||||
pointerOut[iii] = pointerIn[iii*2];
|
||||
}
|
||||
pos += ret/4;
|
||||
} else if ( _nbChan == 2
|
||||
self->m_nbSamples += ret/4;
|
||||
} else if ( self->m_nbChanRequested == 2
|
||||
&& vi->channels == 1) {
|
||||
for (int32_t iii=0; iii<ret/2 ; ++iii) {
|
||||
pointerOut[iii*2] = pointerIn[iii];
|
||||
pointerOut[iii*2+1] = pointerIn[iii];
|
||||
}
|
||||
pos += ret;
|
||||
self->m_nbSamples += ret;
|
||||
} 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);
|
||||
//EWOLSA_DEBUG("get data : " << ret << " Bytes");
|
||||
EWOLSA_DEBUG("get data : " << (int32_t)ret << " Bytes");
|
||||
}
|
||||
}
|
||||
/* cleanup */
|
||||
ov_clear(&vf);
|
||||
//EWOLSA_DEBUG("Done.");
|
||||
return outputData;
|
||||
EWOLSA_DEBUG("Done.");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,7 @@
|
||||
|
||||
namespace ewolsa {
|
||||
namespace ogg {
|
||||
int16_t* loadAudioFile(const std::string& _filename, int8_t _nbChan, int32_t& _nbSampleOut);
|
||||
|
||||
void* loadFileThreadedMode(void *_ptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user