-/* === S I N F G =========================================================== */
+/* === S Y N F I G ========================================================= */
/*! \file audiocontainer.cpp
** \brief Audio Container implementation File
**
//#include <ETL/thread>
#include <glibmm/thread.h>
-#include <sinfg/general.h>
+#include <synfig/general.h>
#include <glibmm/main.h>
using namespace std;
using namespace etl;
-using namespace sinfg;
+using namespace synfig;
/* === M A C R O S ========================================================= */
#ifdef __WIN32
//trivial rejection...
if(!sample || sps < 1)
{
- sinfg::warning("build_profile: Sample rate was too low or sample was invalid");
+ synfig::warning("build_profile: Sample rate was too low or sample was invalid");
return false;
}
if(sizeall <= 0)
{
- sinfg::warning("ProfileAudio: Sample buffer cannot be size smaller than 1 (%X)",FSOUND_GetError());
+ synfig::warning("ProfileAudio: Sample buffer cannot be size smaller than 1 (%X)",FSOUND_GetError());
return false;
}
float stride = allsamplerate/(float)sps;
//down sampling to 8 bit min/max values
- sinfg::warning("About to downsample from %d Hz to %.1f Hz, sample stride: %f", allsamplerate, sps, stride);
+ synfig::warning("About to downsample from %d Hz to %.1f Hz, sample stride: %f", allsamplerate, sps, stride);
char *sampledata=0,*useless = 0;
unsigned int len1,len2;
{
if(!FSOUND_Sample_Lock(sample,0,sizeall,(void**)&sampledata,(void**)&useless,&len1,&len2))
{
- sinfg::warning("ProfileAudio: Unable to lock the sound buffer... (%X)",FSOUND_GetError());
+ synfig::warning("ProfileAudio: Unable to lock the sound buffer... (%X)",FSOUND_GetError());
return false;
}
- sinfg::warning("Locked: %X: %d bytes, %X: %d bytes",sampledata,len1,useless,len2);
+ synfig::warning("Locked: %X: %d bytes, %X: %d bytes",sampledata,len1,useless,len2);
if(channelsize == 1)
{
int i = 0;
//HACK - to prevent if statement inside inner loop
- //sinfg::warning("wo baby wo baby, inc: %d, stride: %f, size: %d", inc, stride, sizeall);
+ //synfig::warning("wo baby wo baby, inc: %d, stride: %f, size: %d", inc, stride, sizeall);
while(iter < end)
{
int maxs = 0, mins = 0;
int i = 0;
//HACK - to prevent if statement inside inner loop
- //sinfg::warning("wo baby wo baby, inc: %d, stride: %f, size: %d", inc, stride, sizeall);
+ //synfig::warning("wo baby wo baby, inc: %d, stride: %f, size: %d", inc, stride, sizeall);
while(iter < end)
{
int maxs = 0, mins = 0;
}
}
- sinfg::warning("Stats: %f seconds with %d bytes now %d bytes", (samples.size()/2)/sps, sizeall, samples.size());
- sinfg::warning(" %f seconds before", numsamples/(float)allsamplerate);
+ synfig::warning("Stats: %f seconds with %d bytes now %d bytes", (samples.size()/2)/sps, sizeall, samples.size());
+ synfig::warning(" %f seconds before", numsamples/(float)allsamplerate);
//we're done yay!, unlock
FSOUND_Sample_Unlock(sample,sampledata,useless,len1,len2);
- sinfg::info("Unlocked");
+ synfig::info("Unlocked");
//FSOUND_PlaySound(FSOUND_FREE,sound); //test
FSOUND_SetPaused(channel,true);
}else
{
- //sinfg::info("DSP f = %d Hz", freq);
+ //synfig::info("DSP f = %d Hz", freq);
FSOUND_SetPaused(channel,false);
if(!FSOUND_SetFrequency(channel,freq))
{
}
}
- //sinfg::info(dsp);
+ //synfig::info(dsp);
return newbuffer;
}
if(!loaded)
{
#ifdef WITH_FMOD
- sinfg::info("Initializing FMOD on demand...");
+ synfig::info("Initializing FMOD on demand...");
{
FSOUND_SetOutput(AUDIO_OUTPUT);
/*int numdrivers = FSOUND_GetNumDrivers();
- sinfg::info("Num FMOD drivers = %d",numdrivers);
- sinfg::info("Current Driver is #%d", FSOUND_GetDriver());
+ synfig::info("Num FMOD drivers = %d",numdrivers);
+ synfig::info("Current Driver is #%d", FSOUND_GetDriver());
for(int i = 0; i < numdrivers; ++i)
{
unsigned int caps = 0;
FSOUND_GetDriverCaps(i,&caps);
- sinfg::info(" Caps for driver %d (%s) = %x",i,FSOUND_GetDriverName(i),caps);
+ synfig::info(" Caps for driver %d (%s) = %x",i,FSOUND_GetDriverName(i),caps);
}
FSOUND_SetDriver(0);*/
if(!FSOUND_Init(44100, 32, 0))
{
- sinfg::warning("Unable to load FMOD");
+ synfig::warning("Unable to load FMOD");
}else
{
loaded = true;
//add to the refcount
++refcount;
- //sinfg::info("Audio: increment fmod refcount %d", refcount);
+ //synfig::info("Audio: increment fmod refcount %d", refcount);
}
void decref()
{
if(refcount <= 0)
{
- sinfg::warning("FMOD refcount is already 0...");
+ synfig::warning("FMOD refcount is already 0...");
}else
{
--refcount;
- //sinfg::info("Audio: decrement fmod refcount %d", refcount);
+ //synfig::info("Audio: decrement fmod refcount %d", refcount);
//NOTE: UNCOMMENT THIS IF YOU WANT FMOD TO UNLOAD ITSELF WHEN IT ISN'T NEEDED ANYMORE...
flush();
if(loaded && refcount <= 0)
{
#ifdef WITH_FMOD
- sinfg::info("Unloading FMOD");
+ synfig::info("Unloading FMOD");
if(scrubdspunit) FSOUND_DSP_Free(scrubdspunit);
FSOUND_Close();
#endif
channel = FSOUND_PlaySoundEx(FSOUND_FREE,sample,0,true);
if(channel < 0 || FSOUND_GetError() != FMOD_ERR_NONE)
{
- sinfg::warning("Could not play the sample...");
+ synfig::warning("Could not play the sample...");
return false;
}
}
//if we already have done our work, then we're good
if(profilevalid && prof)
{
- //sinfg::info("Using already built profile");
+ //synfig::info("Using already built profile");
return prof;
}
- //sinfg::info("Before profile");
+ //synfig::info("Before profile");
//make a new profile at current sample rate
//NOTE: We might want to reuse the structure already there...
if(!prof)
{
- sinfg::warning("Couldn't allocate audioprofile...");
+ synfig::warning("Couldn't allocate audioprofile...");
return handle<studio::AudioProfile>();
}
//setting the info for the sample rate
- //sinfg::info("Setting info...");
+ //synfig::info("Setting info...");
- sinfg::info("Building Profile...");
+ synfig::info("Building Profile...");
prof->samplerate = samplerate;
if(build_profile(imp->sample,prof->samplerate,prof->samples))
{
- sinfg::info(" Success!");
+ synfig::info(" Success!");
profilevalid = true;
return prof;
}else
if(!is_absolute_path(file))
{
file=filedirectory+filename;
- sinfg::warning("Not absolute hoooray");
+ synfig::warning("Not absolute hoooray");
}
- sinfg::info("Loading Audio file: %s", file.c_str());
+ synfig::info("Loading Audio file: %s", file.c_str());
//check to see if file exists
{
struct stat s;
if(stat(file.c_str(),&s) == -1 && errno == ENOENT)
{
- sinfg::info("There was no audio file...");
+ synfig::info("There was no audio file...");
return false;
}
}
//load fmod if we can...
- //sinfg::warning("I'm compiled with FMOD!");
+ //synfig::warning("I'm compiled with FMOD!");
fmodinit.addref();
//load the stream
if(!sm)
{
- sinfg::warning("Could not open the audio file as a sample: %s",file.c_str());
+ synfig::warning("Could not open the audio file as a sample: %s",file.c_str());
goto error;
}
- //sinfg::warning("Opened a file as a sample! :)");
+ //synfig::warning("Opened a file as a sample! :)");
/*{
int bufferlen = FSOUND_DSP_GetBufferLength();
- sinfg::info("Buffer length = %d samples, %.3lf s",bufferlen, bufferlen / (double)FSOUND_GetOutputRate());
+ synfig::info("Buffer length = %d samples, %.3lf s",bufferlen, bufferlen / (double)FSOUND_GetOutputRate());
}*/
//set all the variables since everything has worked out...
FSOUND_Sample_GetDefaults(sm,&sfreq,&volume,0,0);
//double len = length / (double)sfreq;
- //sinfg::info("Sound info: %.2lf s long, %d Hz, %d Vol",(double)length,sfreq,volume);
+ //synfig::info("Sound info: %.2lf s long, %d Hz, %d Vol",(double)length,sfreq,volume);
}
- //sinfg::warning("Got all info, and setting up everything, %.2f sec.", length);
- //sinfg::warning(" BigSample: composed of %d samples", FSOUND_Sample_GetLength(sm));
- sinfg::info("Successfully opened %s as a sample and initialized it.",file.c_str());
+ //synfig::warning("Got all info, and setting up everything, %.2f sec.", length);
+ //synfig::warning(" BigSample: composed of %d samples", FSOUND_Sample_GetLength(sm));
+ synfig::info("Successfully opened %s as a sample and initialized it.",file.c_str());
//set up the playable info
sample = sm;
if(t < 0)
{
unsigned int timeout = (int)floor(-t * 1000 + 0.5);
- //sinfg::info("Playing audio delayed by %d ms",timeout);
+ //synfig::info("Playing audio delayed by %d ms",timeout);
//delay for t seconds...
delaycon = Glib::signal_timeout().connect(
sigc::mem_fun(*this,&studio::AudioContainer::AudioImp::start_playing_now),timeout);
if(position >= FSOUND_Sample_GetLength(sample))
{
- sinfg::warning("Can't play audio when past length...");
+ synfig::warning("Can't play audio when past length...");
return;
}
FSOUND_SetCurrentPosition(channel,position);
FSOUND_SetPaused(channel,false);
- //sinfg::info("Playing audio with position %d samples",position);
+ //synfig::info("Playing audio with position %d samples",position);
#endif
}
void AudioContainer::AudioImp::start_scrubbing(double t)
{
- //sinfg::info("Start scrubbing: %lf", t);
+ //synfig::info("Start scrubbing: %lf", t);
if(playing) stop();
set_scrubbing(true);
scrinfo.pos = curscrubpos;
scrinfo.delaystart = delay_factor*buffer_length_sec;
- //sinfg::info("\tStarting at %d samps, with %d p %.3f delay",
+ //synfig::info("\tStarting at %d samps, with %d p %.3f delay",
// FSOUND_GetCurrentPosition(channel), (int)scrinfo.pos, scrinfo.delaystart);
}
//enable the dsp...
- //sinfg::info("\tActivating DSP");
+ //synfig::info("\tActivating DSP");
FSOUND_DSP_SetActive(scrubdspunit,true);
#endif
}
void AudioContainer::AudioImp::stop_scrubbing()
{
- //sinfg::info("Stop scrubbing");
+ //synfig::info("Stop scrubbing");
if(is_scrubbing())
{
g_scrubdata.scrub = 0;
//stop the dsp...
- //sinfg::info("\tDeactivating DSP");
+ //synfig::info("\tDeactivating DSP");
FSOUND_DSP_SetActive(scrubdspunit,false);
if(FSOUND_IsPlaying(channel)) FSOUND_SetPaused(channel,true);
#endif
void AudioContainer::AudioImp::scrub(double t)
{
#ifdef WITH_FMOD
- //sinfg::info("Scrub to %lf",t);
+ //synfig::info("Scrub to %lf",t);
if(is_scrubbing())
{
//What should we do?
//Outside so completely stopped...
if(newpos < 0 || oldpos >= length)
{
- //sinfg::info("\tOut +");
+ //synfig::info("\tOut +");
if(FSOUND_IsPlaying(channel))
{
FSOUND_SetPaused(channel,true);
init_play();
FSOUND_SetCurrentPosition(channel,0);
- sinfg::info("\tIn + %d", FSOUND_GetCurrentPosition(channel));
+ synfig::info("\tIn + %d", FSOUND_GetCurrentPosition(channel));
scrinfo.Lock();
scrinfo.pos = 0;
//should we restart the delay cycle... (is it done?)
if(!isRunning() || (scrinfo.delaystart <= 0 && scrinfo.deltatime <= 0 && isPaused()))
{
- //sinfg::info("Starting + at %d",(int)newpos);
+ //synfig::info("Starting + at %d",(int)newpos);
scrinfo.deltatime = 0;
scrinfo.delaystart = delay_factor*buffer_length_sec;
scrinfo.Unlock();
//completely stopped...
if(newpos >= length || oldpos < 0)
{
- //sinfg::info("Out -");
+ //synfig::info("Out -");
if(FSOUND_IsPlaying(channel))
{
FSOUND_SetPaused(channel,true);
//going in? - start going backwards at the end...
/*else if(oldpos >= length)
{
- sinfg::info("In -");
+ synfig::info("In -");
//Set up the sound to be playing paused at the start...
init_play();
FSOUND_SetCurrentPosition(channel,length-1);
//should we restart the delay cycle... (is it done?)
if(!isRunning() ||(scrinfo.delaystart <= 0 && scrinfo.deltatime <= 0 && isPaused()))
{
- //sinfg::info("Starting - at %d",(int)newpos);
+ //synfig::info("Starting - at %d",(int)newpos);
scrinfo.deltatime = 0;
scrinfo.delaystart = delay_factor*buffer_length_sec;
scrinfo.Unlock();