Compare commits

...

2 Commits

Author SHA1 Message Date
a981693121 [DEBUG] update new API of lutin log 2019-05-03 10:18:23 +02:00
398828ab6e [DEV] update new etk Uri API 2018-10-23 22:19:32 +02:00
8 changed files with 92 additions and 82 deletions

View File

@ -5,7 +5,6 @@
*/
#include <etk/types.hpp>
#include <etk/os/FSNode.hpp>
#include <audio/ess/debug.hpp>
#include <audio/ess/decOgg.hpp>
#include <tremor/ivorbiscodec.h>
@ -14,21 +13,21 @@
static size_t LocalReadFunc(void *ptr, size_t size, size_t nmemb, void *datasource) {
etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
return file->fileRead(ptr, size, nmemb);
etk::io::Interface* fileIO = static_cast<etk::io::Interface*>(datasource);
return fileIO->read(ptr, size, nmemb);
}
static int localSeekFunc(void *datasource, ogg_int64_t offset, int whence) {
etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
enum etk::seekNode mode = etk::seekNode_start;
etk::io::Interface* fileIO = static_cast<etk::io::Interface*>(datasource);
etk::io::SeekMode mode = etk::io::SeekMode::Start;
if (whence == SEEK_SET) {
mode = etk::seekNode_start;
mode = etk::io::SeekMode::Start;
} else if (whence == SEEK_END) {
mode = etk::seekNode_end;
mode = etk::io::SeekMode::End;
} else if (whence == SEEK_CUR) {
mode = etk::seekNode_current;
mode = etk::io::SeekMode::Current;
}
if (file->fileSeek(offset, mode) == true) {
if (fileIO->seek(offset, mode) == true) {
return 0;
} else {
return -1;
@ -36,17 +35,17 @@ 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();
etk::io::Interface* fileIO = static_cast<etk::io::Interface*>(datasource);
fileIO->close();
return 0;
}
static long localTellFunc(void *datasource) {
etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
return file->fileTell();
etk::io::Interface* fileIO = static_cast<etk::io::Interface*>(datasource);
return fileIO->tell();
}
etk::Vector<float> audio::ess::ogg::loadAudioFile(const etk::String& _filename, int8_t _nbChan) {
etk::Vector<float> audio::ess::ogg::loadAudioFile(const etk::Uri& _uri, int8_t _nbChan) {
etk::Vector<float> out;
OggVorbis_File vf;
int32_t eof=0;
@ -57,24 +56,28 @@ etk::Vector<float> audio::ess::ogg::loadAudioFile(const etk::String& _filename,
localCloseFunc,
localTellFunc
};
ememory::UniquePtr<etk::FSNode> fileAccess = ememory::UniquePtr<etk::FSNode>(ETK_NEW(etk::FSNode, _filename));
// Start loading the XML :
//EWOLSA_DEBUG("open file (OGG) \"" << fileAccess << "\"");
if (false == fileAccess->exist()) {
EWOLSA_ERROR("File Does not exist : \"" << *fileAccess << "\"");
EWOLSA_DEBUG("open file (OGG) " << _uri);
if (etk::uri::exist(_uri) == false) {
EWOLSA_ERROR("File Does not exist : " << _uri);
return out;
}
int32_t fileSize = fileAccess->fileSize();
if (0 == fileSize) {
EWOLSA_ERROR("This file is empty : \"" << *fileAccess << "\"");
int32_t fileSize = etk::uri::fileSize(_uri);
if (fileSize == 0) {
EWOLSA_ERROR("This file is empty : " << _uri);
return out;
}
if (false == fileAccess->fileOpenRead()) {
EWOLSA_ERROR("Can not open the file : \"" << *fileAccess << "\"");
ememory::SharedPtr<etk::io::Interface> fileIO = etk::uri::get(_uri);
if (fileIO == null) {
EWOLSA_ERROR("CAn not get file interface : " << _uri);
return out;
}
if (ov_open_callbacks(&(*fileAccess), &vf, null, 0, tmpCallback) < 0) {
EWOLSA_ERROR("Input does not appear to be an Ogg bitstream.");
if (fileIO->open(etk::io::OpenMode::Read) == false) {
EWOLSA_ERROR("Can not open the file : " << _uri);
return out;
}
if (ov_open_callbacks(fileIO.get(), &vf, null, 0, tmpCallback) < 0) {
EWOLSA_ERROR("Input does not appear to be an Ogg bitstream: " << _uri);
return out;
}
vorbis_info *vi=ov_info(&vf,-1);

View File

@ -6,11 +6,12 @@
#pragma once
#include <etk/types.hpp>
#include <etk/uri/uri.hpp>
namespace audio {
namespace ess {
namespace ogg {
etk::Vector<float> loadAudioFile(const etk::String& _filename, int8_t _nbChan);
etk::Vector<float> loadAudioFile(const etk::Uri& _uri, int8_t _nbChan);
}
}

View File

@ -5,7 +5,6 @@
*/
#include <etk/types.hpp>
#include <etk/os/FSNode.hpp>
#include <audio/ess/debug.hpp>
#include <audio/ess/decWav.hpp>
@ -57,37 +56,40 @@ typedef struct {
#define COMPR_G721 (64)
#define COMPR_MPEG (80)
etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::String& _filename, int8_t _nbChan) {
etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::Uri& _uri, int8_t _nbChan) {
etk::Vector<float> out;
waveHeader myHeader;
memset(&myHeader, 0, sizeof(waveHeader));
etk::FSNode fileAccess(_filename);
// Start loading the XML :
EWOLSA_DEBUG("open file (WAV) \"" << fileAccess << "\"");
if (false == fileAccess.exist()) {
EWOLSA_ERROR("File Does not exist : \"" << fileAccess << "\"");
EWOLSA_DEBUG("open file (WAV) " << _uri);
if (etk::uri::exist(_uri) == false) {
EWOLSA_ERROR("File Does not exist : " << _uri);
return out;
}
int32_t fileSize = fileAccess.fileSize();
int32_t fileSize = etk::uri::fileSize(_uri);
if (0 == fileSize) {
EWOLSA_ERROR("This file is empty : \"" << fileAccess << "\"");
EWOLSA_ERROR("This file is empty : " << _uri);
return out;
}
if (false == fileAccess.fileOpenRead()) {
EWOLSA_ERROR("Can not open the file : \"" << fileAccess << "\"");
ememory::SharedPtr<etk::io::Interface> fileIO = etk::uri::get(_uri);
if (fileIO == null) {
EWOLSA_ERROR("CAn not get file interface : " << _uri);
return out;
}
if (fileIO->open(etk::io::OpenMode::Read) == false) {
EWOLSA_ERROR("Can not open the file : " << _uri);
return out;
}
// try to find endienness :
if (fileSize < (int64_t)sizeof(waveHeader)) {
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > has not enouth data inside might be minumum of " << (int32_t)(sizeof(waveHeader)));
EWOLSA_ERROR("File : " << _uri << " == > has not enouth data inside might be minumum of " << (int32_t)(sizeof(waveHeader)));
return out;
}
// ----------------------------------------------
// read the header :
// ----------------------------------------------
if (fileAccess.fileRead(&myHeader.riffTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
if (fileIO->read(&myHeader.riffTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
}
bool littleEndien = false;
@ -99,55 +101,55 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::String& _filename,
littleEndien = true;
}
} else {
EWOLSA_ERROR("file: \"" << fileAccess << "\" Does not start with \"RIF\" " );
EWOLSA_ERROR("file: " << _uri << " Does not start with 'RIF' " );
return out;
}
// get the data size :
unsigned char tmpData[32];
if (fileAccess.fileRead(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
if (fileIO->read(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
}
myHeader.size = CONVERT_UINT32(littleEndien, tmpData);
// get the data size :
if (fileAccess.fileRead(&myHeader.waveTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
if (fileIO->read(&myHeader.waveTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
}
if( myHeader.waveTag[0] != 'W'
|| myHeader.waveTag[1] != 'A'
|| myHeader.waveTag[2] != 'V'
|| myHeader.waveTag[3] != 'E' ) {
EWOLSA_ERROR("file: \"" << fileAccess << "\" This is not a wave file " << myHeader.waveTag[0] << myHeader.waveTag[1] << myHeader.waveTag[2] << myHeader.waveTag[3] );
EWOLSA_ERROR("file: " << _uri << " This is not a wave file " << myHeader.waveTag[0] << myHeader.waveTag[1] << myHeader.waveTag[2] << myHeader.waveTag[3] );
return out;
}
// get the data size :
if (fileAccess.fileRead(&myHeader.fmtTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
if (fileIO->read(&myHeader.fmtTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
}
if( myHeader.fmtTag[0] != 'f'
|| myHeader.fmtTag[1] != 'm'
|| myHeader.fmtTag[2] != 't'
|| myHeader.fmtTag[3] != ' ' ) {
EWOLSA_ERROR("file: \"" << fileAccess << "\" header error ..." << myHeader.fmtTag[0] << myHeader.fmtTag[1] << myHeader.fmtTag[2] << myHeader.fmtTag[3]);
EWOLSA_ERROR("file: " << _uri << " header error ..." << myHeader.fmtTag[0] << myHeader.fmtTag[1] << myHeader.fmtTag[2] << myHeader.fmtTag[3]);
return out;
}
// get the data size :
if (fileAccess.fileRead(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
if (fileIO->read(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
}
myHeader.waveFormatSize = CONVERT_UINT32(littleEndien, tmpData);
if (myHeader.waveFormatSize != 16) {
EWOLSA_ERROR("file : \"" << fileAccess << "\" == > header error ...");
EWOLSA_ERROR("file : " << _uri << " == > header error ...");
return out;
}
if (fileAccess.fileRead(tmpData, 1, 16)!=16) {
EWOLSA_ERROR("Can not 16 element in the file : \"" << fileAccess << "\"");
if (fileIO->read(tmpData, 1, 16)!=16) {
EWOLSA_ERROR("Can not 16 element in the file : " << _uri);
return out;
}
unsigned char * tmppp = tmpData;
@ -170,20 +172,20 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::String& _filename,
EWOLSA_DEBUG(" bytesPerFrame : " << myHeader.waveFormat.bytesPerFrame);
EWOLSA_DEBUG(" bitsPerSample : " << myHeader.waveFormat.bitsPerSample);
// get the data size :
if (fileAccess.fileRead(&myHeader.dataTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
if (fileIO->read(&myHeader.dataTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
}
if( myHeader.dataTag[0] != 'd'
|| myHeader.dataTag[1] != 'a'
|| myHeader.dataTag[2] != 't'
|| myHeader.dataTag[3] != 'a' ) {
EWOLSA_ERROR("file: \"" << fileAccess << "\" header error ..." << myHeader.dataTag[0] << myHeader.dataTag[1] << myHeader.dataTag[2] << myHeader.dataTag[3]);
EWOLSA_ERROR("file: " << _uri << " header error ..." << myHeader.dataTag[0] << myHeader.dataTag[1] << myHeader.dataTag[2] << myHeader.dataTag[3]);
return out;
}
// get the data size :
if (fileAccess.fileRead(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
if (fileIO->read(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
}
myHeader.dataSize = CONVERT_UINT32(littleEndien, tmpData);
@ -194,22 +196,22 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::String& _filename,
//Parse the data and transform it if needed ...
if (COMPR_PCM != myHeader.waveFormat.type) {
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > support only PCM compression ...");
EWOLSA_ERROR("File : " << _uri << " == > support only PCM compression ...");
return out;
}
if (myHeader.waveFormat.channelCount == 0 || myHeader.waveFormat.channelCount>2) {
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > support only mono or stereo ..." << myHeader.waveFormat.channelCount);
EWOLSA_ERROR("File : " << _uri << " == > support only mono or stereo ..." << myHeader.waveFormat.channelCount);
return out;
}
if ( ! ( myHeader.waveFormat.bitsPerSample == 16
|| myHeader.waveFormat.bitsPerSample == 24
|| myHeader.waveFormat.bitsPerSample == 32 ) ) {
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > not supported bit/sample ..." << myHeader.waveFormat.bitsPerSample);
EWOLSA_ERROR("File : " << _uri << " == > not supported bit/sample ..." << myHeader.waveFormat.bitsPerSample);
return out;
}
if( ! ( 44100 == myHeader.waveFormat.samplesPerSec
|| 48000 == myHeader.waveFormat.samplesPerSec) ) {
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > not supported frequency " << myHeader.waveFormat.samplesPerSec << " != 48000");
EWOLSA_ERROR("File : " << _uri << " == > not supported frequency " << myHeader.waveFormat.samplesPerSec << " != 48000");
return out;
}
EWOLSA_DEBUG(" dataSize : " << myHeader.dataSize);
@ -224,14 +226,14 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::String& _filename,
char audioSample[8];
if (myHeader.waveFormat.bitsPerSample == 16) {
if (myHeader.waveFormat.channelCount == 1) {
if (fileAccess.fileRead(audioSample, 1, 2)!=2) {
if (fileIO->read(audioSample, 1, 2)!=2) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
}
left = ((int32_t)((int16_t)CONVERT_INT16(littleEndien, audioSample))) << 16;
right = left;
} else {
if (fileAccess.fileRead(audioSample, 1, 4)!=4) {
if (fileIO->read(audioSample, 1, 4)!=4) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
}
@ -240,14 +242,14 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::String& _filename,
}
} else if (myHeader.waveFormat.bitsPerSample == 24) {
if (myHeader.waveFormat.channelCount == 1) {
if (fileAccess.fileRead(audioSample, 1, 3)!=3) {
if (fileIO->read(audioSample, 1, 3)!=3) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
}
left = CONVERT_INT24(littleEndien, audioSample);
right = left;
} else {
if (fileAccess.fileRead(audioSample, 1, 6)!=6) {
if (fileIO->read(audioSample, 1, 6)!=6) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
}
@ -256,14 +258,14 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::String& _filename,
}
} else if (myHeader.waveFormat.bitsPerSample == 32) {
if (myHeader.waveFormat.channelCount == 1) {
if (fileAccess.fileRead(audioSample, 1, 4)!=4) {
if (fileIO->read(audioSample, 1, 4)!=4) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
}
left = CONVERT_INT32(littleEndien, audioSample);
right = left;
} else {
if (fileAccess.fileRead(audioSample, 1, 8)!=8) {
if (fileIO->read(audioSample, 1, 8)!=8) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
}
@ -280,7 +282,7 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::String& _filename,
}
}
// close the file:
fileAccess.fileClose();
fileIO->close();
return out;
}

View File

@ -6,11 +6,12 @@
#pragma once
#include <etk/types.hpp>
#include <etk/uri/uri.hpp>
namespace audio {
namespace ess {
namespace wav {
etk::Vector<float> loadAudioFile(const etk::String& _filename, int8_t _nbChan);
etk::Vector<float> loadAudioFile(const etk::Uri& _uri, int8_t _nbChan);
}
}
}

View File

@ -12,6 +12,7 @@
#include <audio/ess/ess.hpp>
#include <audio/ess/debug.hpp>
#include <ejson/ejson.hpp>
#include <etk/uri/uri.hpp>
ememory::SharedPtr<audio::river::Manager> g_audioManager;
ememory::SharedPtr<audio::ess::Effects> g_effects;
@ -52,8 +53,10 @@ void audio::ess::soundSetParse(const etk::String& _data) {
}
}
void audio::ess::soundSetLoad(const etk::String& _file) {
soundSetParse(etk::FSNodeReadAllData(_file));
void audio::ess::soundSetLoad(const etk::Uri& _uri) {
etk::String data;
etk::uri::readAll(_uri, data);
soundSetParse(data);
}
void audio::ess::musicPlay(const etk::String& _name) {

View File

@ -32,9 +32,9 @@ namespace audio {
void soundSetParse(const etk::String& _data);
/**
* @brief Parse a configuration file of a soundset
* @param[in] _file JSON file to parse
* @param[in] _uri JSON file to parse
*/
void soundSetLoad(const etk::String& _file);
void soundSetLoad(const etk::Uri& _uri);
/**
* @brief Play a music with his name

View File

@ -24,14 +24,14 @@ A simple example:
```{.json}
{
musics:{
"BG-1":"DATA:audio/Clean Soul.ogg"
"BG-22":"DATA:audio/Dark knight.ogg"
"BG-1":"DATA:///audio/Clean Soul.ogg"
"BG-22":"DATA:///audio/Dark knight.ogg"
},
effects:{
"end":"DATA:audio/end.wav",
"error":"DATA:audio/error.wav",
"levelup":"DATA:audio/levelup.wav",
"ok":"DATA:audio/ok.wav"
"end":"DATA:///audio/end.wav",
"error":"DATA:///audio/error.wav",
"levelup":"DATA:///audio/levelup.wav",
"ok":"DATA:///audio/ok.wav"
}
}
```

View File

@ -1,6 +1,6 @@
#!/usr/bin/python
import lutin.tools as tools
import lutin.debug as debug
import realog.debug as debug
def get_type():