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
37 changed files with 1042 additions and 1838 deletions

63
.gitignore vendored
View File

@ -1,64 +1 @@
###################################
# folders
###################################
CVS
.svn
Object_*
doxygen/API/
doxygen/ALL/
###################################
# backup files
###################################
*~
*.swp
*.old
*.bck
###################################
# Compiled source #
###################################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc
tags
#ewol
out
ewol_debug
ewol_release
###################################
# Packages #
###################################
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
###################################
# Logs and databases #
###################################
*.log
*.sql
*.sqlite
###################################
# OS generated files #
###################################
.DS_Store?
ehthumbs.db
Icon?
Thumbs.db
Sources/libewol/ewol/os/AndroidAbstraction.cpp
org_ewol_EwolConstants.h

373
LICENSE
View File

@ -1,373 +0,0 @@
Mozilla Public License Version 2.0
==================================
1. Definitions
--------------
1.1. "Contributor"
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used
by a Contributor and that particular Contributor's Contribution.
1.3. "Contribution"
means Covered Software of a particular Contributor.
1.4. "Covered Software"
means Source Code Form to which the initial Contributor has attached
the notice in Exhibit A, the Executable Form of such Source Code
Form, and Modifications of such Source Code Form, in each case
including portions thereof.
1.5. "Incompatible With Secondary Licenses"
means
(a) that the initial Contributor has attached the notice described
in Exhibit B to the Covered Software; or
(b) that the Covered Software was made available under the terms of
version 1.1 or earlier of the License, but not also under the
terms of a Secondary License.
1.6. "Executable Form"
means any form of the work other than Source Code Form.
1.7. "Larger Work"
means a work that combines Covered Software with other material, in
a separate file or files, that is not Covered Software.
1.8. "License"
means this document.
1.9. "Licensable"
means having the right to grant, to the maximum extent possible,
whether at the time of the initial grant or subsequently, any and
all of the rights conveyed by this License.
1.10. "Modifications"
means any of the following:
(a) any file in Source Code Form that results from an addition to,
deletion from, or modification of the contents of Covered
Software; or
(b) any new file in Source Code Form that contains any Covered
Software.
1.11. "Patent Claims" of a Contributor
means any patent claim(s), including without limitation, method,
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the
License, by the making, using, selling, offering for sale, having
made, import, or transfer of either its Contributions or its
Contributor Version.
1.12. "Secondary License"
means either the GNU General Public License, Version 2.0, the GNU
Lesser General Public License, Version 2.1, the GNU Affero General
Public License, Version 3.0, or any later versions of those
licenses.
1.13. "Source Code Form"
means the form of the work preferred for making modifications.
1.14. "You" (or "Your")
means an individual or a legal entity exercising rights under this
License. For legal entities, "You" includes any entity that
controls, is controlled by, or is under common control with You. For
purposes of this definition, "control" means (a) the power, direct
or indirect, to cause the direction or management of such entity,
whether by contract or otherwise, or (b) ownership of more than
fifty percent (50%) of the outstanding shares or beneficial
ownership of such entity.
2. License Grants and Conditions
--------------------------------
2.1. Grants
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license:
(a) under intellectual property rights (other than patent or trademark)
Licensable by such Contributor to use, reproduce, make available,
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or
as part of a Larger Work; and
(b) under Patent Claims of such Contributor to make, use, sell, offer
for sale, have made, import, and otherwise transfer either its
Contributions or its Contributor Version.
2.2. Effective Date
The licenses granted in Section 2.1 with respect to any Contribution
become effective for each Contribution on the date the Contributor first
distributes such Contribution.
2.3. Limitations on Grant Scope
The licenses granted in this Section 2 are the only rights granted under
this License. No additional rights or licenses will be implied from the
distribution or licensing of Covered Software under this License.
Notwithstanding Section 2.1(b) above, no patent license is granted by a
Contributor:
(a) for any code that a Contributor has removed from Covered Software;
or
(b) for infringements caused by: (i) Your and any other third party's
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor
Version); or
(c) under Patent Claims infringed by Covered Software in the absence of
its Contributions.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with
the notice requirements in Section 3.4).
2.4. Subsequent Licenses
No Contributor makes additional grants as a result of Your choice to
distribute the Covered Software under a subsequent version of this
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3).
2.5. Representation
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights
to grant the rights to its Contributions conveyed by this License.
2.6. Fair Use
This License is not intended to limit any rights You have under
applicable copyright doctrines of fair use, fair dealing, or other
equivalents.
2.7. Conditions
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
in Section 2.1.
3. Responsibilities
-------------------
3.1. Distribution of Source Form
All distribution of Covered Software in Source Code Form, including any
Modifications that You create or to which You contribute, must be under
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this
License, and how they can obtain a copy of this License. You may not
attempt to alter or restrict the recipients' rights in the Source Code
Form.
3.2. Distribution of Executable Form
If You distribute Covered Software in Executable Form then:
(a) such Covered Software must also be made available in Source Code
Form, as described in Section 3.1, and You must inform recipients of
the Executable Form how they can obtain a copy of such Source Code
Form by reasonable means in a timely manner, at a charge no more
than the cost of distribution to the recipient; and
(b) You may distribute such Executable Form under the terms of this
License, or sublicense it under different terms, provided that the
license for the Executable Form does not attempt to limit or alter
the recipients' rights in the Source Code Form under this License.
3.3. Distribution of a Larger Work
You may create and distribute a Larger Work under terms of Your choice,
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this
License permits You to additionally distribute such Covered Software
under the terms of such Secondary License(s), so that the recipient of
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary
License(s).
3.4. Notices
You may not remove or alter the substance of any license notices
(including copyright notices, patent notices, disclaimers of warranty,
or limitations of liability) contained within the Source Code Form of
the Covered Software, except that You may alter any license notices to
the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
---------------------------------------------------
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Software due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must
be placed in a text file included with all distributions of the Covered
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a
recipient of ordinary skill to be able to understand it.
5. Termination
--------------
5.1. The rights granted under this License will terminate automatically
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular
Contributor are reinstated (a) provisionally, unless and until such
Contributor explicitly and finally terminates Your grants, and (b) on an
ongoing basis, if such Contributor fails to notify You of the
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular
Contributor are reinstated on an ongoing basis if such Contributor
notifies You of the non-compliance by some reasonable means, this is the
first time You have received notice of non-compliance with this License
from such Contributor, and You become compliant prior to 30 days after
Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License
prior to termination shall survive termination.
************************************************************************
* *
* 6. Disclaimer of Warranty *
* ------------------------- *
* *
* Covered Software is provided under this License on an "as is" *
* basis, without warranty of any kind, either expressed, implied, or *
* statutory, including, without limitation, warranties that the *
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the *
* quality and performance of the Covered Software is with You. *
* Should any Covered Software prove defective in any respect, You *
* (not any Contributor) assume the cost of any necessary servicing, *
* repair, or correction. This disclaimer of warranty constitutes an *
* essential part of this License. No use of any Covered Software is *
* authorized under this License except under this disclaimer. *
* *
************************************************************************
************************************************************************
* *
* 7. Limitation of Liability *
* -------------------------- *
* *
* Under no circumstances and under no legal theory, whether tort *
* (including negligence), contract, or otherwise, shall any *
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, *
* special, incidental, or consequential damages of any character *
* including, without limitation, damages for lost profits, loss of *
* goodwill, work stoppage, computer failure or malfunction, or any *
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This *
* limitation of liability shall not apply to liability for death or *
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some *
* jurisdictions do not allow the exclusion or limitation of *
* incidental or consequential damages, so this exclusion and *
* limitation may not apply to You. *
* *
************************************************************************
8. Litigation
-------------
Any litigation relating to this License may be brought only in the
courts of a jurisdiction where the defendant maintains its principal
place of business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring
cross-claims or counter-claims.
9. Miscellaneous
----------------
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter
shall not be used to construe this License against a Contributor.
10. Versions of the License
---------------------------
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.

View File

@ -1,26 +0,0 @@
ewolsa
======
`ewolsa` ewol simple audio if a basig audio soud renderer for games.
Instructions
============
To compile and use see 'ewol' or 'edn' project
License (MPL v2.0)
=====================
Copyright ewolsa Edouard DUPIN
Licensed under the Mozilla Public License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.mozilla.org/MPL/2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -1,61 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <ethread/tools.hpp>
#include <audio/ess/debug.hpp>
#include <audio/ess/LoadedFile.hpp>
#include <audio/ess/decWav.hpp>
#include <audio/ess/decOgg.hpp>
void audio::ess::LoadedFile::threadCall() {
decode();
}
void audio::ess::LoadedFile::decode() {
EWOLSA_ERROR("Start decode OGG : " << m_file);
m_data = audio::ess::ogg::loadAudioFile(m_file, m_nbChanRequested);
m_nbSamples = m_data.size();
EWOLSA_ERROR("End decode OGG : " << m_file << " size=" << m_nbSamples);
}
audio::ess::LoadedFile::LoadedFile(const etk::String& _fileName, int8_t _nbChanRequested) :
m_file(_fileName),
m_nbSamples(0),
m_nbChanRequested(_nbChanRequested),
m_requestedTime(1) {
etk::String tmpName = etk::toLower(m_file);
// select the corect Loader :
if (etk::end_with(tmpName, ".wav") == true) {
m_data = audio::ess::wav::loadAudioFile(m_file, m_nbChanRequested);
m_nbSamples = m_data.size();
} else if (etk::end_with(tmpName, ".ogg") == true) {
#if 1
EWOLSA_INFO("create thread");
m_thread = ememory::makeShared<ethread::Thread>([&](){decode();}, "audioDecoding");
if (m_thread == null) {
EWOLSA_ERROR("Can not create thread ...");
return;
}
ethread::sleepMilliSeconds((1));
#else
decode();
#endif
} else {
EWOLSA_ERROR("Extention not managed '" << m_file << "' Sopported extention : .wav / .ogg");
return;
}
}
audio::ess::LoadedFile::~LoadedFile() {
if (m_thread != null) {
m_thread->join();
}
m_thread.reset();
}

View File

@ -1,44 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <ethread/Thread.hpp>
#include <ememory/memory.hpp>
namespace audio {
namespace ess {
class LoadedFile {
private:
int32_t m_uid;
public:
int32_t getUId() {
return m_uid;
}
private:
ememory::SharedPtr<ethread::Thread> m_thread;
public:
LoadedFile(const etk::String& _fileName, int8_t _nbChanRequested=1);
~LoadedFile();
etk::String m_file;
int32_t m_nbSamples;
int32_t m_nbChanRequested;
int32_t m_requestedTime;
etk::Vector<float> m_data;
public:
const etk::String& getName() {
return m_file;
};
void decode();
private:
#if defined(__TARGET_OS__Android)
static void* threadCallback(void* _userData);
#endif
void threadCall();
};
}
}

View File

@ -1,12 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <audio/ess/debug.hpp>
int32_t audio::ess::getLogId() {
static int32_t g_val = elog::registerInstance("audio-ess");
return g_val;
}

View File

@ -1,148 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <audio/ess/debug.hpp>
#include <audio/ess/decOgg.hpp>
#include <tremor/ivorbiscodec.h>
#include <tremor/ivorbisfile.h>
#include <ememory/UniquePtr.hpp>
static size_t LocalReadFunc(void *ptr, size_t size, size_t nmemb, void *datasource) {
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::io::Interface* fileIO = static_cast<etk::io::Interface*>(datasource);
etk::io::SeekMode mode = etk::io::SeekMode::Start;
if (whence == SEEK_SET) {
mode = etk::io::SeekMode::Start;
} else if (whence == SEEK_END) {
mode = etk::io::SeekMode::End;
} else if (whence == SEEK_CUR) {
mode = etk::io::SeekMode::Current;
}
if (fileIO->seek(offset, mode) == true) {
return 0;
} else {
return -1;
}
}
static int localCloseFunc(void *datasource) {
etk::io::Interface* fileIO = static_cast<etk::io::Interface*>(datasource);
fileIO->close();
return 0;
}
static long localTellFunc(void *datasource) {
etk::io::Interface* fileIO = static_cast<etk::io::Interface*>(datasource);
return fileIO->tell();
}
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;
int32_t current_section;
ov_callbacks tmpCallback = {
LocalReadFunc,
localSeekFunc,
localCloseFunc,
localTellFunc
};
// Start loading the XML :
EWOLSA_DEBUG("open file (OGG) " << _uri);
if (etk::uri::exist(_uri) == false) {
EWOLSA_ERROR("File Does not exist : " << _uri);
return out;
}
int32_t fileSize = etk::uri::fileSize(_uri);
if (fileSize == 0) {
EWOLSA_ERROR("This file is empty : " << _uri);
return out;
}
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;
}
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);
int32_t nbSampleOut = ov_pcm_total(&vf,-1) / vi->channels;
/*
{
char **ptr=ov_comment(&vf,-1)->user_comments;
while(*ptr){
EWOLSA_DEBUG("comment : " << *ptr);
++ptr;
}
EWOLSA_DEBUG("Bitstream is " << (int32_t)vi->channels << " channel, " << (int32_t)vi->rate << "Hz");
EWOLSA_DEBUG("Decoded length: " << _nbSampleOut << " samples");
EWOLSA_DEBUG("Encoded by: " << ov_comment(&vf,-1)->vendor);
EWOLSA_DEBUG("time: " << ((float)_nbSampleOut/(float)vi->rate)/60.0);
}
*/
out.resize(nbSampleOut*_nbChan, 0);
int32_t pos = 0;
char pcmout[4096];
while(!eof){
long ret=ov_read(&vf, pcmout, sizeof(pcmout), &current_section);
if (ret == 0) {
/* EOF */
eof=1;
} else if (ret < 0) {
if(ret==OV_EBADLINK){
//EWOLSA_ERROR("Corrupt bitstream section! Exiting.");
// TODO : Remove pointer data ...
return out;
}
} else {
int16_t* pointerIn = (int16_t*)pcmout;
float* pointerOut = &out[0]+pos;
if (_nbChan == vi->channels) {
// 1/32768 = 0.00003051757f
for (int32_t iii=0; iii<ret/2; ++iii) {
pointerOut[iii] = float(pointerIn[iii]) * 0.00003051757f;
}
pos += ret/2;
} else {
if ( _nbChan == 1
&& vi->channels == 2) {
for (int32_t iii=0; iii<ret/4 ; ++iii) {
pointerOut[iii] = float(pointerIn[iii*2]) * 0.00003051757f;
}
pos += ret/4;
} else if ( _nbChan == 2
&& vi->channels == 1) {
for (int32_t iii=0; iii<ret/2 ; ++iii) {
pointerOut[iii*2] = float(pointerIn[iii]) * 0.00003051757f;
pointerOut[iii*2+1] = float(pointerIn[iii]) * 0.00003051757f;
}
pos += ret;
} else {
//EWOLSA_ERROR("Can not convert " << (int32_t)vi->channels << " channels in " << _nbChan << " channels");
}
}
// fwrite(pcmout,1,ret,stdout);
//EWOLSA_DEBUG("get data : " << ret << " Bytes");
}
}
// cleanup
ov_clear(&vf);
//EWOLSA_DEBUG("Done.");
return out;
}

View File

@ -1,19 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/uri/uri.hpp>
namespace audio {
namespace ess {
namespace ogg {
etk::Vector<float> loadAudioFile(const etk::Uri& _uri, int8_t _nbChan);
}
}
}

View File

@ -1,18 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/uri/uri.hpp>
namespace audio {
namespace ess {
namespace wav {
etk::Vector<float> loadAudioFile(const etk::Uri& _uri, int8_t _nbChan);
}
}
}

View File

@ -1,160 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <audio/ess/debug.hpp>
#include <audio/ess/effects.hpp>
#include <audio/ess/decWav.hpp>
#include <cmath>
audio::ess::Effects::Effects(const ememory::SharedPtr<audio::river::Manager>& _manager) :
m_manager(_manager) {
ethread::UniqueLock lock(m_mutex);
//Set stereo output:
etk::Vector<audio::channel> channelMap;
channelMap.pushBack(audio::channel_frontCenter);
m_interface = m_manager->createOutput(48000,
channelMap,
audio::format_float,
"speaker");
if (m_interface == null) {
EWOLSA_ERROR("can not allocate output interface ... ");
return;
}
m_interface->setName("audio::ess::Effects");
m_interface->addVolumeGroup("EFFECT");
// set callback mode ...
m_interface->setOutputCallback([=] (void* _data,
const audio::Time& _playTime,
const size_t& _nbChunk,
enum audio::format _format,
uint32_t _sampleRate,
const etk::Vector<audio::channel>& _map) {
audio::ess::Effects::onDataNeeded(_data, _playTime, _nbChunk, _format, _sampleRate, _map);
});
m_interface->start();
}
audio::ess::Effects::~Effects() {
if (m_interface != null) {
m_interface->stop();
}
m_interface.reset();
m_manager.reset();
m_list.clear();
m_playing.clear();
}
static bool playData(const ememory::SharedPtr<audio::ess::LoadedFile>& _file, int32_t& _position, float* _bufferInterlace, int32_t _nbSample) {
if ( _file == null
|| _file->m_data.size() == 0) {
return true;
}
int32_t processTimeMax = etk::min(_nbSample, _file->m_nbSamples - _position);
processTimeMax = etk::max(0, processTimeMax);
float * pointer = _bufferInterlace;
const float * newData = &_file->m_data[_position];
//EWOLSA_DEBUG("AUDIO : Play slot... nb sample : " << processTimeMax << " playTime=" <<m_playTime << " nbCannels=" << nbChannels);
for (int32_t iii=0; iii<processTimeMax; iii++) {
*_bufferInterlace += *newData;
//EWOLSA_DEBUG("AUDIO : element : " << *pointer);
_bufferInterlace++;
newData++;
}
_position += processTimeMax;
// check end of playing ...
if (_file->m_nbSamples <= _position) {
return true;
}
return false;
}
void audio::ess::Effects::onDataNeeded(void* _data,
const audio::Time& _playTime,
const size_t& _nbChunk,
enum audio::format _format,
uint32_t _sampleRate,
const etk::Vector<audio::channel>& _map){
if (_format != audio::format_float) {
EWOLSA_ERROR("call wrong type ... (need float)");
}
EWOLSA_VERBOSE(" get data Effect: "<< _nbChunk);
ethread::UniqueLock lock(m_mutex);
auto it = m_playing.begin();
while (it != m_playing.end()) {
bool ret = playData((*it).first, (*it).second, static_cast<float*>(_data), _nbChunk);
if (ret == true) {
it = m_playing.erase(it);
} else {
++it;
}
}
}
void audio::ess::Effects::load(const etk::String& _file, const etk::String& _name) {
// load the file:
ememory::SharedPtr<audio::ess::LoadedFile> tmp = ememory::makeShared<audio::ess::LoadedFile>(_file, 2);
if (tmp == null) {
EWOLSA_ERROR("can not load audio Effects = " << _file);
return;
}
ethread::UniqueLock lock(m_mutex);
int32_t id = -1;
for (size_t iii=0; iii<m_list.size(); ++iii) {
if (m_list[iii].first == _name) {
id = iii;
break;
}
}
if (-1 <= id) {
m_list.pushBack(etk::Pair<etk::String,ememory::SharedPtr<audio::ess::LoadedFile>>(_name,tmp));
} else {
m_list[id].second = tmp;
}
}
int32_t audio::ess::Effects::getId(const etk::String& _name) {
ethread::UniqueLock lock(m_mutex);
for (size_t iii=0; iii<m_list.size(); ++iii) {
if (m_list[iii].first == _name) {
return iii;
}
}
m_list.pushBack(etk::Pair<etk::String,ememory::SharedPtr<audio::ess::LoadedFile>>(_name,null));
EWOLSA_WARNING("Can not find element name : '" << _name << "' added it ... (empty) ");
return m_list.size()-1;
}
void audio::ess::Effects::play(int32_t _id, const vec3& _pos) {
ethread::UniqueLock lock(m_mutex);
if ( _id < 0
|| _id >= m_list.size()) {
EWOLSA_ERROR(" Can not play element audio with ID=" << _id << " out of [0.." << m_list.size() << "[");
return;
}
m_playing.pushBack(etk::Pair<ememory::SharedPtr<audio::ess::LoadedFile>, int32_t>(m_list[_id].second, 0));
}
void audio::ess::Effects::play(const etk::String& _name, const vec3& _pos) {
play(getId(_name),_pos);
}
void audio::ess::Effects::stop() {
if (m_playing.size() == 0) {
EWOLSA_INFO("No current audio is playing");
}
ethread::UniqueLock lock(m_mutex);
m_playing.clear();
}
void audio::ess::Effects::clear() {
stop();
ethread::UniqueLock lock(m_mutex);
m_list.clear();
}

View File

@ -1,44 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/math/Vector3D.hpp>
#include <audio/river/Interface.hpp>
#include <audio/river/Manager.hpp>
#include <audio/ess/LoadedFile.hpp>
#include <ethread/Mutex.hpp>
namespace audio {
namespace ess {
class Effects {
private:
mutable ethread::Mutex m_mutex;
ememory::SharedPtr<audio::river::Manager> m_manager;
ememory::SharedPtr<audio::river::Interface> m_interface;
public:
Effects(const ememory::SharedPtr<audio::river::Manager>& _manager);
~Effects();
private:
void onDataNeeded(void* _data,
const audio::Time& _playTime,
const size_t& _nbChunk,
enum audio::format _format,
uint32_t _sampleRate,
const etk::Vector<audio::channel>& _map);
etk::Vector<etk::Pair<ememory::SharedPtr<audio::ess::LoadedFile>, int32_t>> m_playing; //!< current music read
etk::Vector<etk::Pair<etk::String, ememory::SharedPtr<audio::ess::LoadedFile>>> m_list; //!< list of all effect loaded
public:
void load(const etk::String& _file, const etk::String& _name);
int32_t getId(const etk::String& _name);
void play(const etk::String& _name, const vec3& _pos = vec3(0,0,0));
void play(int32_t _id, const vec3& _pos = vec3(0,0,0));
void stop();
void clear();
};
}
}

View File

@ -1,152 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <audio/river/Interface.hpp>
#include <audio/river/Manager.hpp>
#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;
ememory::SharedPtr<audio::ess::Music> g_music;
void audio::ess::init() {
g_audioManager = audio::river::Manager::create("ewol-sound-set");
g_effects = ememory::makeShared<audio::ess::Effects>(g_audioManager);
g_music = ememory::makeShared<audio::ess::Music>(g_audioManager);
}
void audio::ess::unInit() {
g_effects.reset();
g_music.reset();
g_audioManager.reset();
}
void audio::ess::soundSetParse(const etk::String& _data) {
ejson::Document doc;
doc.parse(_data);
ejson::Object obj = doc["musics"].toObject();
if ( obj.exist() == true
&& g_music != null) {
for (auto &it : obj.getKeys()) {
etk::String file = obj[it].toString().get();
EWOLSA_INFO("load Music : '" << it << "' file=" << file);
g_music->load(file, it);
}
}
obj = doc["effects"].toObject();
if ( obj.exist() == true
&& g_effects != null) {
for (auto &it : obj.getKeys()) {
etk::String file = obj[it].toString().get();
EWOLSA_INFO("load Effect : '" << it << "' file=" << file);
g_effects->load(file, it);
}
}
}
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) {
if (g_music == null) {
return;
}
g_music->play(_name);
}
void audio::ess::musicStop() {
if (g_music == null) {
return;
}
g_music->stop();
}
void audio::ess::musicSetVolume(float _dB) {
if (g_audioManager == null) {
return;
}
g_audioManager->setVolume("MUSIC", _dB);
}
float audio::ess::musicGetVolume() {
if (g_audioManager == null) {
return 0.0f;
}
return g_audioManager->getVolume("MUSIC");
}
void audio::ess::musicSetMute(bool _mute) {
if (g_audioManager == null) {
return;
}
g_audioManager->setMute("MUSIC", _mute);
}
bool audio::ess::musicGetMute() {
if (g_audioManager == null) {
return 0.0f;
}
return g_audioManager->getMute("MUSIC");
}
int32_t audio::ess::effectGetId(const etk::String& _name) {
if (g_effects == null) {
return -1;
}
return g_effects->getId(_name);
}
void audio::ess::effectPlay(int32_t _id, const vec3& _pos) {
if (g_effects == null) {
return;
}
g_effects->play(_id, _pos);
}
void audio::ess::effectPlay(const etk::String& _name, const vec3& _pos) {
if (g_effects == null) {
return;
}
g_effects->play(_name, _pos);
}
void audio::ess::effectSetVolume(float _dB) {
if (g_audioManager == null) {
return;
}
g_audioManager->setVolume("EFFECT", _dB);
}
float audio::ess::effectGetVolume() {
if (g_audioManager == null) {
return 0.0f;
}
return g_audioManager->getVolume("EFFECT");
}
void audio::ess::effectSetMute(bool _mute) {
if (g_audioManager == null) {
return;
}
g_audioManager->setMute("EFFECT", _mute);
}
bool audio::ess::effectGetMute() {
if (g_audioManager == null) {
return 0.0f;
}
return g_audioManager->getMute("EFFECT");
}

View File

@ -1,111 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <audio/ess/effects.hpp>
#include <audio/ess/music.hpp>
/**
* @brief Audio library namespace
*/
namespace audio {
/**
* @brief Audio-ess library namespace
*/
namespace ess {
/**
* @brief Initialize the Ess singleton (Only one interface for all the Process)
*/
void init();
/**
* @brief Release the Ess singleton (Only one interface for all the Process)
*/
void unInit();
/**
* @brief Parse a JSON configuration data of a soundset
* @param[in] _data JSON string data to parse
*/
void soundSetParse(const etk::String& _data);
/**
* @brief Parse a configuration file of a soundset
* @param[in] _uri JSON file to parse
*/
void soundSetLoad(const etk::Uri& _uri);
/**
* @brief Play a music with his name
* @param[in] _name Name of the music (not the Path)
*/
void musicPlay(const etk::String& _name);
/**
* @brief Stop the music played
*/
void musicStop();
/**
* @brief Set the music volume
* @param[in] _dB apply decibel volume at the music [-100..100]
*/
void musicSetVolume(float _dB);
/**
* @brief Get the current music volume
* @return Volume in dB of the music
*/
float musicGetVolume();
/**
* @brief Set mute state of the music
* @param[in] _mute New mute status
*/
void musicSetMute(bool _mute);
/**
* @brief Get the current Mute status of the music
* @return true The music is muted
* @return false The music is active
*/
bool musicGetMute();
/**
* @brief Get the Unique ID of an effect
* @param[in] _name Name of the effects
* @return the effect ID or -1 if it does not exist...
*/
int32_t effectGetId(const etk::String& _name);
/**
* @brief Play an effect with his ID
* @param[in] _id Id of the effect to play
* @param[in] _pos position of the efffect is played (not used / not implemented)
*/
void effectPlay(int32_t _id, const vec3& _pos=vec3(0,0,0));
/**
* @brief Play an effect with his name
* @param[in] _name Name of the effect to play
* @param[in] _pos position of the efffect is played (not used / not implemented)
*/
void effectPlay(const etk::String& _name, const vec3& _pos=vec3(0,0,0));
/**
* @brief Set the effects volume
* @param[in] _dB apply decibel volume at the effects [-100..100]
*/
void effectSetVolume(float _dB);
/**
* @brief Get the current effects volume
* @return Volume in dB of the effects
*/
float effectGetVolume();
/**
* @brief Set mute state of the effects
* @param[in] _mute New mute status
*/
void effectSetMute(bool _mute);
/**
* @brief Get the current Mute status of the effects
* @return true The effects is muted
* @return false The effects is active
*/
bool effectGetMute();
}
}

View File

@ -1,137 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <audio/ess/music.hpp>
#include <audio/ess/debug.hpp>
#include <audio/ess/LoadedFile.hpp>
#include <cmath>
audio::ess::Music::Music(const ememory::SharedPtr<audio::river::Manager>& _manager) :
m_manager(_manager),
m_position(0) {
ethread::UniqueLock lock(m_mutex);
//Set stereo output:
etk::Vector<audio::channel> channelMap;
channelMap.pushBack(audio::channel_frontLeft);
channelMap.pushBack(audio::channel_frontRight);
m_interface = m_manager->createOutput(48000,
channelMap,
audio::format_float,
"speaker");
if (m_interface == null) {
EWOLSA_ERROR("can not allocate output interface ... ");
return;
}
m_interface->setName("audio::ess::music");
m_interface->addVolumeGroup("MUSIC");
// set callback mode ...
m_interface->setOutputCallback([=] (void* _data,
const audio::Time& _playTime,
const size_t& _nbChunk,
enum audio::format _format,
uint32_t _sampleRate,
const etk::Vector<audio::channel>& _map) {
audio::ess::Music::onDataNeeded(_data, _playTime, _nbChunk, _format, _sampleRate, _map);
});
m_interface->start();
}
audio::ess::Music::~Music() {
if (m_interface != null) {
m_interface->stop();
}
m_interface.reset();
m_manager.reset();
m_list.clear();
m_current.reset();
m_next.reset();
}
void audio::ess::Music::onDataNeeded(void* _data,
const audio::Time& _playTime,
const size_t& _nbChunk,
enum audio::format _format,
uint32_t _sampleRate,
const etk::Vector<audio::channel>& _map){
if (_format != audio::format_float) {
EWOLSA_ERROR("call wrong type ... (need float)");
}
EWOLSA_VERBOSE(" get data Music: "<< _nbChunk);
ethread::UniqueLock lock(m_mutex);
if (m_current != m_next) {
EWOLSA_INFO("change track " << (m_current==null?-1:m_current->getUId()) << " ==> " << (m_next==null?-1:m_next->getUId()));
m_current = m_next;
m_position = 0;
}
if (m_current == null) {
// nothing to play ...
return;
}
if (m_current->m_data.size() == 0) {
return;
}
int32_t processTimeMax = etk::min(int32_t(_nbChunk*_map.size()), int32_t(m_current->m_nbSamples - m_position));
processTimeMax = etk::max(0, processTimeMax);
float * pointer = static_cast<float*>(_data);
float * newData = &m_current->m_data[m_position];
EWOLSA_VERBOSE("AUDIO : Play slot... nb sample : " << processTimeMax << " map=" << _map << " _nbChunk=" << _nbChunk);
for (int32_t iii=0; iii<processTimeMax; iii++) {
*pointer++ = *newData++;
}
m_position += processTimeMax;
// check end of playing ...
if (m_current->m_nbSamples <= m_position) {
m_position = 0;
m_current.reset();
}
}
void audio::ess::Music::load(const etk::String& _file, const etk::String& _name) {
auto it = m_list.find(_name);
if (it != m_list.end()) {
return;
}
ememory::SharedPtr<audio::ess::LoadedFile> tmp = ememory::makeShared<audio::ess::LoadedFile>(_file, 2);
if (tmp == null) {
EWOLSA_ERROR("can not load audio Music = " << _file);
return;
}
ethread::UniqueLock lock(m_mutex);
m_list.add(_name, tmp);
}
void audio::ess::Music::play(const etk::String& _name) {
auto it = m_list.find(_name);
if (it == m_list.end()) {
EWOLSA_ERROR("Can not Play music : " << _name);
return;
}
// in all case we stop the current playing music ...
stop();
ethread::UniqueLock lock(m_mutex);
m_next = it->second;
EWOLSA_INFO("Playing track " << (m_current==null?-1:m_current->getUId()) << " request next : " << m_next->getUId());
}
void audio::ess::Music::stop() {
if (m_current == null) {
EWOLSA_INFO("No current audio is playing");
}
ethread::UniqueLock lock(m_mutex);
m_current.reset();
}
void audio::ess::Music::clear() {
stop();
m_current.reset();
m_next.reset();
m_position = 0;
m_list.clear();
}

View File

@ -1,45 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <audio/river/Interface.hpp>
#include <audio/river/Manager.hpp>
#include <audio/ess/LoadedFile.hpp>
#include <ethread/Mutex.hpp>
#include <etk/Map.hpp>
namespace audio {
namespace ess {
class Music {
private:
mutable ethread::Mutex m_mutex;
ememory::SharedPtr<audio::river::Manager> m_manager;
ememory::SharedPtr<audio::river::Interface> m_interface;
public:
Music(const ememory::SharedPtr<audio::river::Manager>& _manager);
~Music();
private:
void onDataNeeded(void* _data,
const audio::Time& _playTime,
const size_t& _nbChunk,
enum audio::format _format,
uint32_t _sampleRate,
const etk::Vector<audio::channel>& _map);
ememory::SharedPtr<audio::ess::LoadedFile> m_current; //!< current music read
int32_t m_position; //!< current position of music read
etk::Map<etk::String, ememory::SharedPtr<audio::ess::LoadedFile> > m_list; //!< list of all music loaded
ememory::SharedPtr<audio::ess::LoadedFile> m_next; //!< next music to read
public:
void load(const etk::String& _file, const etk::String& _name);
void play(const etk::String& _name);
void stop();
void clear();
};
}
}

View File

@ -1 +0,0 @@
MR Edouard DUPIN <yui.heero@gmail.com>

View File

@ -1,82 +0,0 @@
Build lib & build sample {#audio_ess_build}
========================
@tableofcontents
Download: {#audio_ess_build_download}
=========
ege use some tools to manage source and build it:
need google repo: {#audio_ess_build_download_repo}
-----------------
see: http://source.android.com/source/downloading.html#installing-repo
On all platform:
```{.sh}
mkdir ~/.bin
PATH=~/.bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
chmod a+x ~/.bin/repo
```
On ubuntu
```{.sh}
sudo apt-get install repo
```
On archlinux
```{.sh}
sudo pacman -S repo
```
lutin (build-system): {#audio_ess_build_download_lutin}
---------------------
```{.sh}
pip install lutin --user
# optionnal dependency of lutin (manage image changing size for application release)
pip install pillow --user
```
dependency: {#audio_ess_build_download_dependency}
-----------
```{.sh}
mkdir -p WORKING_DIRECTORY/framework
cd WORKING_DIRECTORY/framework
repo init -u git://github.com/atria-soft/manifest.git
repo sync -j8
cd ../..
```
sources: {#audio_ess_build_download_sources}
--------
They are already download in the repo manifest in:
```{.sh}
cd WORKING_DIRECTORY/framework/musicdsp/audio-ess
```
Build: {#audio_ess_build_build}
======
you must stay in zour working directory...
```{.sh}
cd WORKING_DIRECTORY
```
library: {#audio_ess_build_build_library}
--------
```{.sh}
lutin -mdebug audio-ess
```
Sample: {#audio_ess_build_build_sample}
-------
No sample availlable now

View File

@ -1,58 +0,0 @@
AUDIO-ESS library {#mainpage}
=================
@tableofcontents
What is AUDIO-ESS: {#audio_ess_mainpage_what}
==================
AUDIO-ESS, or Ewol Sound Set interface is designed to be a 'small game' audio effects engine.
==> fast to generate sound without attention at how thay are play and do not pay attention at the stop.
What it does: {#audio_ess_mainpage_what_it_does}
=============
- Load ogg/wav efffects and stay ready to play it
- play file without latency
- Manage a basic soundset
AUDIO-ESS is dependent of the STL (compatible with MacOs stl (CXX))
What languages are supported? {#audio_ess_mainpage_language}
=============================
AUDIO-ESS is written in C++.
Are there any licensing restrictions? {#audio_ess_mainpage_license_restriction}
=====================================
AUDIO-ESS is **FREE software** and _all sub-library are FREE and staticly linkable !!!_
License (MPL v2.0) {#audio_ess_mainpage_license}
==================
Copyright AUDIO-ESS Edouard DUPIN
Licensed under the Mozilla Public License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
<https://www.mozilla.org/MPL/2.0>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Other pages {#audio_ess_mainpage_sub_page}
===========
- @ref audio_ess_build
- @ref audio_ess_tuto
- [**ewol coding style**](http://atria-soft.github.io/ewol/ewol_coding_style.html)

View File

@ -1,101 +0,0 @@
Tutoral: use sound-set {#audio_ess_tuto}
======================
@tableofcontents
Objectifs: {#audio_ess_tuto_objectif}
==========
- Understand config file
- Create a simple playing sounds
Create a configuration file {#audio_ess_tuto_config_file}
===========================
configuration file is really simple:
```{.sh}
soundSet.json
```
it contain 2 mains object:
- **musics:** That containig the list of all music files
- **effects:** That contain all effects files
A simple example:
```{.json}
{
musics:{
"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"
}
}
```
what you need to do first: {#audio_ess_tuto_include}
==========================
Include and basic init:
```{.cpp}
#include <audio/ess/ess.hpp>
//in the main application:
int main(...) {
audio::ess::init();
/*
* Do your stuff
*/
audio::ess::unInit();
return 0;
}
```
Select your sound set file:
```{.cpp}
audio::ess::soundSetLoad("DATA:soundSet.json");
```
Play a background music: {#audio_ess_tuto_play_music}
========================
Start playing:
```{.cpp}
audio::ess::musicPlay("BG-22");
```
Stop playing:
```{.cpp}
audio::ess::musicStop();
```
Change volume: (reduce at -5dB)
```{.cpp}
audio::ess::musicSetVolume(-5.0f);
```
Play an effect: {#audio_ess_tuto_play_effect}
===============
Start playing:
```{.cpp}
audio::ess::effectPlay("error");
sleep(1);
audio::ess::effectPlay("levelup");
```
or (faster way):
```{.cpp}
int32_t effectId = audio::ess::effectGetId("error");
audio::ess::effectPlay(effectId);
```
**Note:** An effect can not stopped ...
Change volume: (reduce at -5dB)
```{.cpp}
audio::ess::effectSetVolume(-5.0f);
```

View File

@ -1,35 +0,0 @@
#!/usr/bin/python
import os
import doxy.module as module
import doxy.debug as debug
import doxy.tools as tools
def create(target, module_name):
my_module = module.Module(__file__, module_name)
my_module.set_version("version.txt")
my_module.set_title("audio-ess: ewol sound set")
my_module.set_website("http://musicdsp.github.io/" + module_name)
my_module.set_website_sources("http://github.com/musicdsp/" + module_name)
my_module.add_path([
"audio",
"doc"
])
my_module.add_sample_path([
"sample",
])
my_module.add_depend([
'audio-river',
'ejson'
])
my_module.add_exclude_symbols([
'*operator<<*',
])
my_module.add_exclude_file([
'debug.h',
])
my_module.add_file_patterns([
'ess.h',
'*.md',
])
return my_module

50
ewolsa/LoadedFile.cpp Normal file
View File

@ -0,0 +1,50 @@
/**
* @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>
#include <ewolsa/decOgg.h>
#include <thread>
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_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);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
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;
}
}
ewolsa::LoadedFile::~LoadedFile(void) {
m_stopRequested = true;
// TODO : wait end of thread...
if (m_data != NULL) {
delete[] m_data;
m_data = NULL;
}
}

39
ewolsa/LoadedFile.h Normal file
View File

@ -0,0 +1,39 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __EWOLSA_LOADED_FILE_H__
#define __EWOLSA_LOADED_FILE_H__
#include <etk/types.h>
#include <pthread.h>
namespace ewolsa {
class LoadedFile {
private:
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;
public:
const std::string& getName(void) {
return m_file;
};
};
};
#endif

14
ewolsa/debug.cpp Normal file
View File

@ -0,0 +1,14 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#include <ewolsa/debug.h>
int32_t ewolsa::getLogId(void) {
static int32_t g_val = etk::log::registerInstance("ewol-sa");
return g_val;
}

View File

@ -1,19 +1,29 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*
* @license BSD v3 (see license file)
*/
#pragma once
#include <elog/log.hpp>
#ifndef __EWOLSA_DEBUG_H__
#define __EWOLSA_DEBUG_H__
#include <etk/log.h>
namespace audio {
namespace ess {
int32_t getLogId();
}
}
#define EWOLSA_BASE(info,data) ELOG_BASE(audio::ess::getLogId(),info,data)
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)
@ -39,3 +49,5 @@ namespace audio {
} while (0)
#endif

157
ewolsa/decOgg.cpp Normal file
View File

@ -0,0 +1,157 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#include <etk/types.h>
#include <etk/os/FSNode.h>
#include <ewolsa/debug.h>
#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);
}
static int localSeekFunc(void *datasource, ogg_int64_t offset, int whence) {
etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
enum etk::seekNode mode = etk::FSN_SEEK_START;
if (whence == SEEK_SET) {
mode = etk::FSN_SEEK_START;
} else if (whence == SEEK_END) {
mode = etk::FSN_SEEK_END;
} else if (whence == SEEK_CUR) {
mode = etk::FSN_SEEK_CURRENT;
}
if (file->fileSeek(offset, mode) == true) {
return 0;
} else {
return -1;
}
}
static int localCloseFunc(void *datasource) {
etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
file->fileClose();
return 0;
}
static long localTellFunc(void *datasource) {
etk::FSNode* file = static_cast<etk::FSNode*>(datasource);
return file->fileTell();
}
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 current_section;
ov_callbacks tmpCallback = {
LocalReadFunc,
localSeekFunc,
localCloseFunc,
localTellFunc
};
EWOLSA_WARNING("open file (OGG) '" << self->m_file << "'");
etk::FSNode fileAccess(self->m_file);
// Start loading the XML :
if (false == fileAccess.exist()) {
EWOLSA_ERROR("File Does not exist : '" << fileAccess << "'");
return NULL;
}
int32_t fileSize = fileAccess.fileSize();
if (0 == fileSize) {
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 << "'");
return NULL;
}
if (ov_open_callbacks(&fileAccess, &vf, NULL, 0, tmpCallback) < 0) {
EWOLSA_ERROR("Input does not appear to be an Ogg bitstream.");
return NULL;
}
vorbis_info *vi=ov_info(&vf,-1);
self->m_nbSamplesTotal = ov_pcm_total(&vf,-1) / vi->channels;
{
char **ptr=ov_comment(&vf,-1)->user_comments;
while(*ptr){
EWOLSA_DEBUG("comment : " << *ptr);
++ptr;
}
EWOLSA_DEBUG("Bitstream is " << (int32_t)vi->channels << " channel, " << (int32_t)vi->rate << "Hz");
EWOLSA_DEBUG("Decoded length: " << self->m_nbSamplesTotal << " samples");
EWOLSA_DEBUG("Encoded by: " << ov_comment(&vf,-1)->vendor);
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)];
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;
}
self->m_nbSamples = 0;
char pcmout[4096];
bool eof = false;
while ( eof == false
&& self->m_stopRequested == false) {
long ret=ov_read(&vf, pcmout, sizeof(pcmout), &current_section);
if (ret == 0) {
/* EOF */
eof = true;
} else if (ret < 0) {
if(ret==OV_EBADLINK){
EWOLSA_ERROR("Corrupt bitstream section! Exiting.");
// TODO : Remove pointer data ...
return NULL;
}
} else {
int16_t* pointerIn = (int16_t*)pcmout;
int16_t* pointerOut = self->m_data+self->m_nbSamples;
if (self->m_nbChanRequested == vi->channels) {
memcpy(pointerOut, pointerIn, ret);
self->m_nbSamples += ret/2;
} else {
if ( self->m_nbChanRequested == 1
&& vi->channels == 2) {
for (int32_t iii=0; iii<ret/4 ; ++iii) {
pointerOut[iii] = pointerIn[iii*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];
}
self->m_nbSamples += ret;
} else {
EWOLSA_ERROR("Can not convert " << (int32_t)vi->channels << " channels in " << self->m_nbChanRequested << " channels");
}
}
// fwrite(pcmout,1,ret,stdout);
EWOLSA_DEBUG("get data : " << (int32_t)ret << " Bytes");
}
}
/* cleanup */
ov_clear(&vf);
EWOLSA_DEBUG("Done.");
return NULL;
}

20
ewolsa/decOgg.h Normal file
View File

@ -0,0 +1,20 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __EWOLSA_DEC_OGG_H__
#define __EWOLSA_DEC_OGG_H__
#include <etk/types.h>
namespace ewolsa {
namespace ogg {
void* loadFileThreadedMode(void *_ptr);
}
};
#endif

View File

@ -1,12 +1,15 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*
* @license BSD 3 clauses (see license file)
*/
#include <etk/types.hpp>
#include <audio/ess/debug.hpp>
#include <audio/ess/decWav.hpp>
#include <etk/types.h>
#include <etk/os/FSNode.h>
#include <ewolsa/debug.h>
#include <ewolsa/decWav.h>
typedef struct {
@ -56,41 +59,38 @@ typedef struct {
#define COMPR_G721 (64)
#define COMPR_MPEG (80)
etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::Uri& _uri, int8_t _nbChan) {
etk::Vector<float> out;
int16_t* ewolsa::wav::loadAudioFile(const std::string& _filename, int8_t _nbChan, int32_t& _nbSampleOut) {
_nbSampleOut = 0;
waveHeader myHeader;
memset(&myHeader, 0, sizeof(waveHeader));
etk::FSNode fileAccess(_filename);
// Start loading the XML :
EWOLSA_DEBUG("open file (WAV) " << _uri);
if (etk::uri::exist(_uri) == false) {
EWOLSA_ERROR("File Does not exist : " << _uri);
return out;
EWOLSA_DEBUG("open file (WAV) \"" << fileAccess << "\"");
if (false == fileAccess.exist()) {
EWOLSA_ERROR("File Does not exist : \"" << fileAccess << "\"");
return NULL;
}
int32_t fileSize = etk::uri::fileSize(_uri);
int32_t fileSize = fileAccess.fileSize();
if (0 == fileSize) {
EWOLSA_ERROR("This file is empty : " << _uri);
return out;
EWOLSA_ERROR("This file is empty : \"" << fileAccess << "\"");
return NULL;
}
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;
if (false == fileAccess.fileOpenRead()) {
EWOLSA_ERROR("Can not open the file : \"" << fileAccess << "\"");
return NULL;
}
// try to find endienness :
if (fileSize < (int64_t)sizeof(waveHeader)) {
EWOLSA_ERROR("File : " << _uri << " == > has not enouth data inside might be minumum of " << (int32_t)(sizeof(waveHeader)));
return out;
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > has not enouth data inside might be minumum of " << (int32_t)(sizeof(waveHeader)));
return NULL;
}
// ----------------------------------------------
// read the header :
// ----------------------------------------------
if (fileIO->read(&myHeader.riffTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
if (fileAccess.fileRead(&myHeader.riffTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
return NULL;
}
bool littleEndien = false;
if( myHeader.riffTag[0] == 'R'
@ -101,56 +101,56 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::Uri& _uri, int8_t _
littleEndien = true;
}
} else {
EWOLSA_ERROR("file: " << _uri << " Does not start with 'RIF' " );
return out;
EWOLSA_ERROR("file: \"" << fileAccess << "\" Does not start with \"RIF\" " );
return NULL;
}
// get the data size :
unsigned char tmpData[32];
if (fileIO->read(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
if (fileAccess.fileRead(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
return NULL;
}
myHeader.size = CONVERT_UINT32(littleEndien, tmpData);
// get the data size :
if (fileIO->read(&myHeader.waveTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
if (fileAccess.fileRead(&myHeader.waveTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
return NULL;
}
if( myHeader.waveTag[0] != 'W'
|| myHeader.waveTag[1] != 'A'
|| myHeader.waveTag[2] != 'V'
|| myHeader.waveTag[3] != 'E' ) {
EWOLSA_ERROR("file: " << _uri << " This is not a wave file " << myHeader.waveTag[0] << myHeader.waveTag[1] << myHeader.waveTag[2] << myHeader.waveTag[3] );
return out;
EWOLSA_ERROR("file: \"" << fileAccess << "\" This is not a wave file " << myHeader.waveTag[0] << myHeader.waveTag[1] << myHeader.waveTag[2] << myHeader.waveTag[3] );
return NULL;
}
// get the data size :
if (fileIO->read(&myHeader.fmtTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
if (fileAccess.fileRead(&myHeader.fmtTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
return NULL;
}
if( myHeader.fmtTag[0] != 'f'
|| myHeader.fmtTag[1] != 'm'
|| myHeader.fmtTag[2] != 't'
|| myHeader.fmtTag[3] != ' ' ) {
EWOLSA_ERROR("file: " << _uri << " header error ..." << myHeader.fmtTag[0] << myHeader.fmtTag[1] << myHeader.fmtTag[2] << myHeader.fmtTag[3]);
return out;
EWOLSA_ERROR("file: \"" << fileAccess << "\" header error ..." << myHeader.fmtTag[0] << myHeader.fmtTag[1] << myHeader.fmtTag[2] << myHeader.fmtTag[3]);
return NULL;
}
// get the data size :
if (fileIO->read(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
if (fileAccess.fileRead(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
return NULL;
}
myHeader.waveFormatSize = CONVERT_UINT32(littleEndien, tmpData);
if (myHeader.waveFormatSize != 16) {
EWOLSA_ERROR("file : " << _uri << " == > header error ...");
return out;
EWOLSA_ERROR("file : \"" << fileAccess << "\" == > header error ...");
return NULL;
}
if (fileIO->read(tmpData, 1, 16)!=16) {
EWOLSA_ERROR("Can not 16 element in the file : " << _uri);
return out;
if (fileAccess.fileRead(tmpData, 1, 16)!=16) {
EWOLSA_ERROR("Can not 16 element in the file : \"" << fileAccess << "\"");
return NULL;
}
unsigned char * tmppp = tmpData;
myHeader.waveFormat.type = CONVERT_UINT16(littleEndien, tmppp);
@ -172,21 +172,21 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::Uri& _uri, int8_t _
EWOLSA_DEBUG(" bytesPerFrame : " << myHeader.waveFormat.bytesPerFrame);
EWOLSA_DEBUG(" bitsPerSample : " << myHeader.waveFormat.bitsPerSample);
// get the data size :
if (fileIO->read(&myHeader.dataTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
if (fileAccess.fileRead(&myHeader.dataTag, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
return NULL;
}
if( myHeader.dataTag[0] != 'd'
|| myHeader.dataTag[1] != 'a'
|| myHeader.dataTag[2] != 't'
|| myHeader.dataTag[3] != 'a' ) {
EWOLSA_ERROR("file: " << _uri << " header error ..." << myHeader.dataTag[0] << myHeader.dataTag[1] << myHeader.dataTag[2] << myHeader.dataTag[3]);
return out;
EWOLSA_ERROR("file: \"" << fileAccess << "\" header error ..." << myHeader.dataTag[0] << myHeader.dataTag[1] << myHeader.dataTag[2] << myHeader.dataTag[3]);
return NULL;
}
// get the data size :
if (fileIO->read(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : " << _uri);
return out;
if (fileAccess.fileRead(tmpData, 1, 4)!=4) {
EWOLSA_ERROR("Can not 4 element in the file : \"" << fileAccess << "\"");
return NULL;
}
myHeader.dataSize = CONVERT_UINT32(littleEndien, tmpData);
@ -196,94 +196,98 @@ etk::Vector<float> audio::ess::wav::loadAudioFile(const etk::Uri& _uri, int8_t _
//Parse the data and transform it if needed ...
if (COMPR_PCM != myHeader.waveFormat.type) {
EWOLSA_ERROR("File : " << _uri << " == > support only PCM compression ...");
return out;
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > support only PCM compression ...");
return NULL;
}
if (myHeader.waveFormat.channelCount == 0 || myHeader.waveFormat.channelCount>2) {
EWOLSA_ERROR("File : " << _uri << " == > support only mono or stereo ..." << myHeader.waveFormat.channelCount);
return out;
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > support only mono or stereo ..." << myHeader.waveFormat.channelCount);
return NULL;
}
if ( ! ( myHeader.waveFormat.bitsPerSample == 16
|| myHeader.waveFormat.bitsPerSample == 24
|| myHeader.waveFormat.bitsPerSample == 32 ) ) {
EWOLSA_ERROR("File : " << _uri << " == > not supported bit/sample ..." << myHeader.waveFormat.bitsPerSample);
return out;
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > not supported bit/sample ..." << myHeader.waveFormat.bitsPerSample);
return NULL;
}
if( ! ( 44100 == myHeader.waveFormat.samplesPerSec
|| 48000 == myHeader.waveFormat.samplesPerSec) ) {
EWOLSA_ERROR("File : " << _uri << " == > not supported frequency " << myHeader.waveFormat.samplesPerSec << " != 48000");
return out;
EWOLSA_ERROR("File : \"" << fileAccess << "\" == > not supported frequency " << myHeader.waveFormat.samplesPerSec << " != 48000");
return NULL;
}
EWOLSA_DEBUG(" dataSize : " << myHeader.dataSize);
//int32_t globalDataSize = myHeader.dataSize;
int32_t nbSample = (myHeader.dataSize/((myHeader.waveFormat.bitsPerSample/8)*myHeader.waveFormat.channelCount));
int32_t outputSize = _nbChan*nbSample;
out.resize(outputSize, 0);
float * tmpOut = &out[0];
int16_t * outputData = new int16_t[outputSize*sizeof(int16_t)];
if (NULL == outputData) {
EWOLSA_ERROR("Allocation ERROR try to allocate " << (int32_t)(outputSize*sizeof(int16_t) ) << "bytes");
return NULL;
}
int16_t * tmpOut = outputData;
for( int32_t iii=0; iii<nbSample; iii++) {
int32_t left;
int32_t right;
char audioSample[8];
if (myHeader.waveFormat.bitsPerSample == 16) {
if (myHeader.waveFormat.channelCount == 1) {
if (fileIO->read(audioSample, 1, 2)!=2) {
if (fileAccess.fileRead(audioSample, 1, 2)!=2) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
return NULL;
}
left = ((int32_t)((int16_t)CONVERT_INT16(littleEndien, audioSample))) << 16;
right = left;
} else {
if (fileIO->read(audioSample, 1, 4)!=4) {
if (fileAccess.fileRead(audioSample, 1, 4)!=4) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
return NULL;
}
left = (int32_t)((int16_t)CONVERT_INT16(littleEndien, audioSample)) << 16;
right = (int32_t)((int16_t)CONVERT_INT16(littleEndien, audioSample+2)) << 16;
}
} else if (myHeader.waveFormat.bitsPerSample == 24) {
if (myHeader.waveFormat.channelCount == 1) {
if (fileIO->read(audioSample, 1, 3)!=3) {
if (fileAccess.fileRead(audioSample, 1, 3)!=3) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
return NULL;
}
left = CONVERT_INT24(littleEndien, audioSample);
right = left;
} else {
if (fileIO->read(audioSample, 1, 6)!=6) {
if (fileAccess.fileRead(audioSample, 1, 6)!=6) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
return NULL;
}
left = CONVERT_INT24(littleEndien, audioSample);
right = CONVERT_INT24(littleEndien, audioSample+3);
}
} else if (myHeader.waveFormat.bitsPerSample == 32) {
if (myHeader.waveFormat.channelCount == 1) {
if (fileIO->read(audioSample, 1, 4)!=4) {
if (fileAccess.fileRead(audioSample, 1, 4)!=4) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
return NULL;
}
left = CONVERT_INT32(littleEndien, audioSample);
right = left;
} else {
if (fileIO->read(audioSample, 1, 8)!=8) {
if (fileAccess.fileRead(audioSample, 1, 8)!=8) {
EWOLSA_ERROR("Read Error at position : " << iii);
return out;
return NULL;
}
left = CONVERT_INT32(littleEndien, audioSample);
right = CONVERT_INT32(littleEndien, audioSample+4);
}
}
// 1/32768 = 0.00003051757f
if (_nbChan == 1) {
*tmpOut++ = float(((left>>1) + (right>>1))>>16) * 0.00003051757f;
*tmpOut++ = (int16_t)(((left>>1) + (right>>1))>>16);
} else {
*tmpOut++ = float(left>>16) * 0.00003051757f;
*tmpOut++ = float(right>>16) * 0.00003051757f;
*tmpOut++ = (int16_t)(left>>16);
*tmpOut++ = (int16_t)(right>>16);
}
}
// close the file:
fileIO->close();
return out;
fileAccess.fileClose();
_nbSampleOut = nbSample;
return outputData;
}

21
ewolsa/decWav.h Normal file
View File

@ -0,0 +1,21 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __EWOLSA_DEC_WAV_H__
#define __EWOLSA_DEC_WAV_H__
#include <etk/types.h>
namespace ewolsa {
namespace wav {
int16_t* loadAudioFile(const std::string& _filename, int8_t _nbChan, int32_t& _nbSampleOut);
}
};
#endif

205
ewolsa/effects.cpp Normal file
View File

@ -0,0 +1,205 @@
/**
* @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/effects.h>
#include <ewolsa/decWav.h>
#include <math.h>
#include <ewolsa/LoadedFile.h>
#include <mutex>
static std::mutex localMutex;
static bool effectsMute = false;
static float effectsVolume = 0;
static int32_t effectsVolumeApply = 1<<16;
//----------------------------------------------------------------------------------------------------------
// Effects ...
//----------------------------------------------------------------------------------------------------------
class RequestPlay {
private:
bool m_freeSlot;
ewolsa::LoadedFile* m_effect; // reference to the effects
int32_t m_playTime; // position in sample playing in the audio effects
public :
RequestPlay(ewolsa::LoadedFile * _effect) :
m_freeSlot(false),
m_effect(_effect),
m_playTime(0) {
};
void reset(ewolsa::LoadedFile * _effect) {
m_effect=_effect;
m_playTime=0;
m_freeSlot=false;
};
bool isFree(void) {
return m_freeSlot;
};
void play(int16_t * _bufferInterlace, int32_t _nbSample, int32_t _nbChannels) {
if (true == m_freeSlot) {
return;
}
if (m_effect->m_data == NULL) {
m_freeSlot = true;
return;
}
int32_t processTimeMax = etk_min(_nbSample, m_effect->m_nbSamples - m_playTime);
processTimeMax = etk_max(0, processTimeMax);
int16_t * pointer = _bufferInterlace;
int16_t * newData = &m_effect->m_data[m_playTime];
//EWOLSA_DEBUG("AUDIO : Play slot... nb sample : " << processTimeMax << " playTime=" <<m_playTime << " nbCannels=" << nbChannels);
for (int32_t iii=0; iii<processTimeMax; iii++) {
// TODO : set volume and spacialisation ...
for (int32_t jjj=0; jjj<_nbChannels; jjj++) {
int32_t tmppp = *pointer + ((((int32_t)*newData)*effectsVolumeApply)>>16);
*pointer = etk_avg(-32767, tmppp, 32766);
//EWOLSA_DEBUG("AUDIO : element : " << *pointer);
pointer++;
}
newData++;
}
m_playTime += processTimeMax;
// check end of playing ...
if (m_effect->m_nbSamples <= m_playTime) {
m_freeSlot=true;
}
}
};
#include <vector>
std::vector<ewolsa::LoadedFile*> ListEffects;
std::vector<RequestPlay*> ListEffectsPlaying;
void ewolsa::effects::init(void) {
ewolsa::effects::volumeSet(0);
ewolsa::effects::muteSet(false);
}
void ewolsa::effects::unInit(void) {
ewolsa::effects::volumeSet(-1000);
ewolsa::effects::muteSet(true);
}
int32_t ewolsa::effects::add(const std::string& _file) {
for (size_t iii=0; iii<ListEffects.size(); iii++) {
if (ListEffects[iii] == NULL) {
continue;
}
if (ListEffects[iii]->m_file == _file) {
ListEffects[iii]->m_requestedTime++;
return iii;
}
}
// effect does not exist ... create a new one ...
ewolsa::LoadedFile * tmpEffect = new ewolsa::LoadedFile(_file);
if (NULL == tmpEffect) {
EWOLSA_ERROR("Error to load the effects : \"" << _file << "\"");
return -1;
}
ListEffects.push_back(tmpEffect);
return ListEffects.size()-1;
}
void ewolsa::effects::rm(int32_t _effectId) {
// find element ...
if (_effectId <0 || _effectId >= (int64_t)ListEffects.size()) {
EWOLSA_ERROR("Wrong effect ID : " << _effectId << " != [0.." << ListEffects.size()-1 << "] == > can not remove it ...");
return;
}
if (ListEffects[_effectId] == NULL) {
EWOLSA_ERROR("effect ID : " << _effectId << " == > has already been removed");
return;
}
// check number of requested
if (ListEffects[_effectId]->m_requestedTime <= 0) {
EWOLSA_ERROR("effect ID : " << _effectId << " == > request more than predicted a removed of an effects");
return;
}
ListEffects[_effectId]->m_requestedTime--;
// mark to be removed ... TODO : Really removed it when no other element readed it ...
// TODO : ...
}
void ewolsa::effects::play(int32_t _effectId, float _xxx, float _yyy) {
if (_effectId <0 || _effectId >= (int64_t)ListEffects.size()) {
EWOLSA_ERROR("Wrong effect ID : " << _effectId << " != [0.." << ListEffects.size()-1 << "] == > can not play it ...");
return;
}
if (ListEffects[_effectId] == NULL) {
EWOLSA_ERROR("effect ID : " << _effectId << " == > has been removed");
return;
}
EWOLSA_VERBOSE("effect play : " << _effectId );
// try to find an empty slot :
for (size_t iii=0; iii<ListEffectsPlaying.size(); iii++) {
if (ListEffectsPlaying[iii]->isFree()) {
ListEffectsPlaying[iii]->reset(ListEffects[_effectId]);
return;
}
}
RequestPlay* newPlay = new RequestPlay(ListEffects[_effectId]);
if (NULL == newPlay) {
EWOLSA_CRITICAL("Allocation error of a playing element : " << _effectId);
return;
}
ListEffectsPlaying.push_back(newPlay);
}
float ewolsa::effects::volumeGet(void) {
return effectsVolume;
}
static void uptateEffectVolume(void) {
if (effectsMute == true) {
effectsVolumeApply = 0;
} else {
// convert in an fixpoint value
// V2 = V1*10^(db/20)
double coef = pow(10, (effectsVolume/20) );
effectsVolumeApply = (int32_t)(coef * (double)(1<<16));
}
}
void ewolsa::effects::volumeSet(float _newVolume) {
effectsVolume = _newVolume;
effectsVolume = etk_avg(-100, effectsVolume, 20);
EWOLSA_INFO("Set music Volume at " << _newVolume << "dB == > " << effectsVolume << "dB");
uptateEffectVolume();
}
bool ewolsa::effects::muteGet(void) {
return effectsMute;
}
void ewolsa::effects::muteSet(bool _newMute) {
effectsMute = _newMute;
EWOLSA_INFO("Set effects Mute at " << _newMute);
uptateEffectVolume();
}
void ewolsa::effects::getData(int16_t* _bufferInterlace, int32_t _nbSample, int32_t _nbChannels) {
for (size_t iii = 0; iii < ListEffectsPlaying.size(); ++iii) {
if (ListEffectsPlaying[iii]!= NULL) {
ListEffectsPlaying[iii]->play(_bufferInterlace, _nbSample, _nbChannels);
}
}
}

35
ewolsa/effects.h Normal file
View File

@ -0,0 +1,35 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __EWOLSA_EFFECTS_H__
#define __EWOLSA_EFFECTS_H__
#include <etk/types.h>
namespace ewolsa {
// note effect is loaded in memory (then don't create long effect) and unload only when requested
namespace effects {
void init(void);
void unInit(void);
// note : support file (Mono, 16bit, 48kHz) : .raw or .wav (no encodage) or .ogg (decoded with tremor lib)
int32_t add(const std::string& _file);
void rm(int32_t _effectId);
void play(int32_t _effectId, float _xxx=0, float _yyy=0);
// in db
float volumeGet(void);
void volumeSet(float _newVolume);
bool muteGet(void);
void muteSet(bool _newMute);
void getData(int16_t* _bufferInterlace, int32_t _nbSample, int32_t _nbChannels);
};
};
#endif

86
ewolsa/ewolsa.cpp Normal file
View File

@ -0,0 +1,86 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#include <etk/types.h>
#include <airtaudio/Interface.h>
#include <ewolsa/ewolsa.h>
#include <ewolsa/debug.h>
airtaudio::Interface* g_dac;
static int airtAudioCallBack(void *_outputBuffer,
void *_inputBuffer,
unsigned int _nBufferFrames,
double _streamTime,
airtaudio::streamStatus _status,
void* _userData) {
if (_outputBuffer == NULL) {
EWOLSA_ERROR("Null output buffer pointer");
return -1;
}
// Reset output data, in case ...
memset(_outputBuffer, 0, _nBufferFrames*2*sizeof(int16_t));
// call music
ewolsa::music::getData((int16_t*)_outputBuffer, _nBufferFrames, 2);
// call Effects
ewolsa::effects::getData((int16_t*)_outputBuffer, _nBufferFrames, 2);
return 0;
}
void ewolsa::init(void) {
if (g_dac != NULL) {
EWOLSA_ERROR("multiple init requested ... at the audio system ...");
return;
}
ewolsa::effects::init();
ewolsa::music::init();
g_dac = new airtaudio::Interface();
if (g_dac == NULL) {
EWOLSA_ERROR("Can not create AirTAudio interface");
return;
}
g_dac->instanciate();
if ( g_dac->getDeviceCount() < 1 ) {
EWOLSA_ERROR("No audio devices found!");
return;
}
airtaudio::StreamParameters parameters;
parameters.deviceId = g_dac->getDefaultOutputDevice();
parameters.nChannels = 2;
parameters.firstChannel = 0;
unsigned int bufferFrames = 256;
EWOLSA_DEBUG("init Stream ...");
g_dac->openStream(&parameters, NULL, airtaudio::SINT16, 48000, &bufferFrames, &airtAudioCallBack, NULL);
g_dac->startStream();
}
void ewolsa::unInit(void) {
if (g_dac == NULL) {
EWOLSA_ERROR("multiple un-init requested ... at the audio system ...");
return;
}
ewolsa::effects::init();
ewolsa::music::init();
// Stop the stream
g_dac->stopStream();
if ( g_dac->isStreamOpen() ) {
g_dac->closeStream();
}
delete(g_dac);
g_dac = NULL;
}

23
ewolsa/ewolsa.h Normal file
View File

@ -0,0 +1,23 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __EWOLSA_H__
#define __EWOLSA_H__
#include <etk/types.h>
#include <ewolsa/effects.h>
#include <ewolsa/music.h>
namespace ewolsa {
void init(void);
void unInit(void);
};
#endif

213
ewolsa/music.cpp Normal file
View File

@ -0,0 +1,213 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#include <etk/types.h>
#include <ewolsa/music.h>
#include <ewolsa/debug.h>
#include <ewolsa/LoadedFile.h>
#include <math.h>
#include <mutex>
static std::mutex localMutex;
static bool musicMute = false;
static float musicVolume = 0;
static int32_t musicVolumeApply = 1<<16;
static int32_t musicFadingTime = 0;
static int32_t musicPositionReading = 0;
static std::vector<ewolsa::LoadedFile*> musicListRead;
static int32_t musicCurrentRead = -1;
static int32_t musicNextRead = -1;
void ewolsa::music::init(void) {
ewolsa::music::volumeSet(0);
ewolsa::music::muteSet(false);
std::unique_lock<std::mutex> lck(localMutex);
musicCurrentRead = -1;
musicNextRead = -1;
musicPositionReading = 0;
for (size_t iii=0; iii<musicListRead.size(); ++iii) {
if (musicListRead[iii] == NULL) {
continue;
}
delete musicListRead[iii];
musicListRead[iii] = NULL;
}
musicListRead.clear();
}
void ewolsa::music::unInit(void) {
ewolsa::music::volumeSet(-1000);
ewolsa::music::muteSet(true);
std::unique_lock<std::mutex> lck(localMutex);
musicCurrentRead = -1;
musicNextRead = -1;
musicPositionReading = 0;
for (size_t iii=0; iii<musicListRead.size(); ++iii) {
if (musicListRead[iii] == NULL) {
continue;
}
delete musicListRead[iii];
musicListRead[iii] = NULL;
}
musicListRead.clear();
}
void ewolsa::music::fading(int32_t _timeMs) {
musicFadingTime = _timeMs;
musicFadingTime = etk_avg(-100, musicFadingTime, 20);
EWOLSA_INFO("Set music fading time at " << _timeMs << "ms == > " << musicFadingTime << "ms");
}
void ewolsa::music::preLoad(const std::string& _file) {
// check if music already existed ...
for (size_t iii=0; iii<musicListRead.size(); ++iii) {
if (musicListRead[iii] == NULL) {
continue;
}
if (musicListRead[iii]->getName() == _file) {
return;
}
}
ewolsa::LoadedFile* tmp = new ewolsa::LoadedFile(_file, 2);
if (tmp != NULL) {
/*
if (tmp->m_data == NULL) {
EWOLSA_ERROR("Music has no data ... : " << _file);
delete(tmp);
return;
}*/
std::unique_lock<std::mutex> lck(localMutex);
musicListRead.push_back(tmp);
} else {
EWOLSA_ERROR("can not preload audio Music");
}
}
bool ewolsa::music::play(const std::string& _file) {
preLoad(_file);
// in all case we stop the current playing music ...
stop();
int32_t idMusic = -1;
// check if music already existed ...
for (size_t iii=0; iii<musicListRead.size(); ++iii) {
if (musicListRead[iii] == NULL) {
continue;
}
if (musicListRead[iii]->getName() == _file) {
idMusic = iii;
break;
}
}
if (idMusic == -1) {
return false;
}
std::unique_lock<std::mutex> lck(localMutex);
musicNextRead = idMusic;
EWOLSA_INFO("Playing track " << musicCurrentRead << " request next : " << idMusic);
return true;
}
bool ewolsa::music::stop(void) {
if (musicCurrentRead == -1) {
EWOLSA_INFO("No current audio is playing");
return false;
}
std::unique_lock<std::mutex> lck(localMutex);
musicNextRead = -1;
return true;
}
float ewolsa::music::volumeGet(void) {
return musicVolume;
}
static void uptateMusicVolume(void) {
if (musicMute == true) {
musicVolumeApply = 0;
} else {
// convert in an fixpoint value
// V2 = V1*10^(db/20)
double coef = pow(10, (musicVolume/20) );
std::unique_lock<std::mutex> lck(localMutex);
musicVolumeApply = (int32_t)(coef * (double)(1<<16));
}
}
void ewolsa::music::volumeSet(float _newVolume) {
musicVolume = _newVolume;
musicVolume = etk_avg(-1000, musicVolume, 40);
EWOLSA_INFO("Set music Volume at " << _newVolume << "dB == > " << musicVolume << "dB");
uptateMusicVolume();
}
bool ewolsa::music::muteGet(void) {
return musicMute;
}
void ewolsa::music::muteSet(bool _newMute) {
musicMute = _newMute;
EWOLSA_INFO("Set music Mute at " << _newMute);
uptateMusicVolume();
}
void ewolsa::music::getData(int16_t * _bufferInterlace, int32_t _nbSample, int32_t _nbChannels) {
EWOLSA_VERBOSE("Music !!! " << musicCurrentRead << " ... " << musicNextRead << " pos: " << musicPositionReading);
std::unique_lock<std::mutex> lck(localMutex);
if (musicCurrentRead != musicNextRead) {
EWOLSA_DEBUG("change track " << musicCurrentRead << " ==> " << musicNextRead);
// TODO : create fading ....
musicCurrentRead = musicNextRead;
musicPositionReading = 0;
}
if (musicCurrentRead < 0) {
// nothing to play ...
return;
}
if ( musicCurrentRead >= musicListRead.size()
|| musicListRead[musicCurrentRead] == NULL) {
musicCurrentRead = -1;
musicPositionReading = 0;
EWOLSA_ERROR("request read an unexisting audio track ... : " << musicCurrentRead << "/" << musicListRead.size());
return;
}
if (musicListRead[musicCurrentRead]->m_data == NULL) {
return;
}
int32_t processTimeMax = etk_min(_nbSample*_nbChannels, musicListRead[musicCurrentRead]->m_nbSamples - musicPositionReading);
processTimeMax = etk_max(0, processTimeMax);
int16_t * pointer = _bufferInterlace;
int16_t * newData = &musicListRead[musicCurrentRead]->m_data[musicPositionReading];
//EWOLSA_DEBUG("AUDIO : Play slot... nb sample : " << processTimeMax << " playTime=" <<m_playTime << " nbCannels=" << nbChannels);
for (int32_t iii=0; iii<processTimeMax; iii++) {
int32_t tmppp = *pointer + ((((int32_t)*newData)*musicVolumeApply)>>16);
*pointer = etk_avg(-32767, tmppp, 32766);
//EWOLSA_DEBUG("AUDIO : element : " << *pointer);
pointer++;
newData++;
}
musicPositionReading += processTimeMax;
// check end of playing ...
if (musicListRead[musicCurrentRead]->m_nbSamples <= musicPositionReading) {
musicPositionReading = 0;
musicCurrentRead = -1;
}
}

36
ewolsa/music.h Normal file
View File

@ -0,0 +1,36 @@
/**
* @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved
*
* @license BSD 3 clauses (see license file)
*/
#ifndef __EWOLSA_MUSIC_H__
#define __EWOLSA_MUSIC_H__
#include <etk/types.h>
namespace ewolsa {
namespace music {
void init(void);
void unInit(void);
void fading(int32_t _timeMs);
void preLoad(const std::string& _file);
bool play(const std::string& _file);
bool stop(void);
// in db
float volumeGet(void);
void volumeSet(float _newVolume);
bool muteGet(void);
void muteSet(bool _newMute);
void getData(int16_t * _bufferInterlace, int32_t _nbSample, int32_t _nbChannels);
};
};
#endif

View File

@ -1,53 +0,0 @@
#!/usr/bin/python
import lutin.tools as tools
import realog.debug as debug
def get_type():
return "LIBRARY"
def get_desc():
return "ewol sound set interface for 'small game' audio effects"
def get_licence():
return "MPL-2"
def get_compagny_type():
return "com"
def get_compagny_name():
return "atria-soft"
def get_maintainer():
return "version.txt"
def get_version():
return "version.txt"
def configure(target, my_module):
# System core
my_module.add_src_file([
'audio/ess/debug.cpp',
'audio/ess/decWav.cpp',
'audio/ess/decOgg.cpp',
'audio/ess/effects.cpp',
'audio/ess/ess.cpp',
'audio/ess/music.cpp',
'audio/ess/LoadedFile.cpp'
])
my_module.add_header_file([
'audio/ess/effects.hpp',
'audio/ess/ess.hpp',
'audio/ess/music.hpp',
'audio/ess/LoadedFile.hpp'
])
# name of the dependency
my_module.add_depend(['etk', 'audio-river', 'ogg', 'ejson'])
if "Android" in target.get_type():
# TODO : Change this ...
my_module.add_export_flag('c++', ["-pthread", "-frtti", "-fexceptions"])
my_module.add_path(".")
return True

33
lutin_ewolsa.py Normal file
View File

@ -0,0 +1,33 @@
#!/usr/bin/python
import lutinModule as module
import lutinTools as tools
import lutinDebug as debug
def get_desc():
return "ewolsa : ewol simple audio interface for 'small game' audio effects"
def create(target):
myModule = module.Module(__file__, 'ewolsa', 'LIBRARY')
# System core
myModule.add_src_file([
'ewolsa/debug.cpp',
'ewolsa/decWav.cpp',
'ewolsa/decOgg.cpp',
'ewolsa/effects.cpp',
'ewolsa/ewolsa.cpp',
'ewolsa/music.cpp',
'ewolsa/LoadedFile.cpp'
])
# name of the dependency
myModule.add_module_depend(['ewol', 'airtaudio', 'ogg'])
if target.name=="Android":
myModule.add_export_flag_CC("-pthread -frtti -fexceptions")
myModule.add_export_path(tools.get_current_path(__file__))
# add the currrent module at the
return myModule

View File

@ -1 +0,0 @@
1.0.0