本文整理汇总了C++中AUD_Reference类的典型用法代码示例。如果您正苦于以下问题:C++ AUD_Reference类的具体用法?C++ AUD_Reference怎么用?C++ AUD_Reference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AUD_Reference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeReader
void AUD_FileWriter::writeReader(AUD_Reference<AUD_IReader> reader, AUD_Reference<AUD_IWriter> writer, unsigned int length, unsigned int buffersize)
{
AUD_Buffer buffer(buffersize * AUD_SAMPLE_SIZE(writer->getSpecs()));
sample_t* buf = buffer.getBuffer();
int len;
bool eos = false;
int channels = writer->getSpecs().channels;
for(unsigned int pos = 0; ((pos < length) || (length <= 0)) && !eos; pos += len)
{
len = buffersize;
if((len > length - pos) && (length > 0))
len = length - pos;
reader->read(len, eos, buf);
for(int i = 0; i < len * channels; i++)
{
// clamping!
if(buf[i] > 1)
buf[i] = 1;
else if(buf[i] < -1)
buf[i] = -1;
}
writer->write(len, buf);
}
}
示例2: AUD_pauseAfter
AUD_Handle* AUD_pauseAfter(AUD_Handle* handle, float seconds)
{
AUD_Reference<AUD_IFactory> silence = new AUD_SilenceFactory;
AUD_Reference<AUD_IFactory> limiter = new AUD_LimiterFactory(silence, 0, seconds);
AUD_device->lock();
try
{
AUD_Handle handle2 = AUD_device->play(limiter);
if(!handle2.isNull())
{
handle2->setStopCallback((stopCallback)pauseSound, handle);
AUD_device->unlock();
return new AUD_Handle(handle2);
}
}
catch(AUD_Exception&)
{
}
AUD_device->unlock();
return NULL;
}
示例3: AUD_getInfo
AUD_SoundInfo AUD_getInfo(AUD_Sound* sound)
{
assert(sound);
AUD_SoundInfo info;
info.specs.channels = AUD_CHANNELS_INVALID;
info.specs.rate = AUD_RATE_INVALID;
info.length = 0.0f;
try
{
AUD_Reference<AUD_IReader> reader = (*sound)->createReader();
if(!reader.isNull())
{
info.specs = reader->getSpecs();
info.length = reader->getLength() / (float) info.specs.rate;
}
}
catch(AUD_Exception&)
{
}
return info;
}
示例4:
AUD_DoubleReader::AUD_DoubleReader(AUD_Reference<AUD_IReader> reader1,
AUD_Reference<AUD_IReader> reader2) :
m_reader1(reader1), m_reader2(reader2), m_finished1(false)
{
AUD_Specs s1, s2;
s1 = reader1->getSpecs();
s2 = reader2->getSpecs();
}
示例5: AUD_init
int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
{
AUD_Reference<AUD_IDevice> dev;
if(!AUD_device.isNull())
AUD_exit();
try
{
switch(device)
{
case AUD_NULL_DEVICE:
dev = new AUD_NULLDevice();
break;
#ifdef WITH_SDL
case AUD_SDL_DEVICE:
dev = new AUD_SDLDevice(specs, buffersize);
break;
#endif
#ifdef WITH_OPENAL
case AUD_OPENAL_DEVICE:
dev = new AUD_OpenALDevice(specs, buffersize);
break;
#endif
#ifdef WITH_JACK
case AUD_JACK_DEVICE:
#ifdef __APPLE__
struct stat st;
if(stat("/Library/Frameworks/Jackmp.framework", &st) != 0)
{
printf("Warning: Jack Framework not installed\n");
// No break, fall through to default, to return false
}
else
{
#endif
dev = new AUD_JackDevice("Blender", specs, buffersize);
break;
#ifdef __APPLE__
}
#endif
#endif
default:
return false;
}
AUD_device = dev;
AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device.get());
return true;
}
catch(AUD_Exception&)
{
return false;
}
}
示例6: AUD_readSound
int AUD_readSound(AUD_Sound* sound, sample_t* buffer, int length, int samples_per_second)
{
AUD_DeviceSpecs specs;
sample_t* buf;
AUD_Buffer aBuffer;
specs.rate = AUD_RATE_INVALID;
specs.channels = AUD_CHANNELS_MONO;
specs.format = AUD_FORMAT_INVALID;
AUD_Reference<AUD_IReader> reader = AUD_ChannelMapperFactory(*sound, specs).createReader();
specs.specs = reader->getSpecs();
int len;
float samplejump = specs.rate / samples_per_second;
float min, max, power;
bool eos;
for(int i = 0; i < length; i++)
{
len = floor(samplejump * (i+1)) - floor(samplejump * i);
aBuffer.assureSize(len * AUD_SAMPLE_SIZE(specs));
buf = aBuffer.getBuffer();
reader->read(len, eos, buf);
max = min = *buf;
power = *buf * *buf;
for(int j = 1; j < len; j++)
{
if(buf[j] < min)
min = buf[j];
if(buf[j] > max)
max = buf[j];
power += buf[j] * buf[j];
}
buffer[i * 3] = min;
buffer[i * 3 + 1] = max;
buffer[i * 3 + 2] = sqrt(power) / len;
if(eos)
{
length = i;
break;
}
}
return length;
}
示例7: getReader
AUD_Reference<AUD_IReader> AUD_EnvelopeFactory::createReader()
{
AUD_Reference<AUD_IReader> reader = getReader();
EnvelopeParameters* param = new EnvelopeParameters();
param->arthreshold = m_arthreshold;
param->attack = pow(m_arthreshold, 1.0f/(static_cast<float>(reader->getSpecs().rate) * m_attack));
param->release = pow(m_arthreshold, 1.0f/(static_cast<float>(reader->getSpecs().rate) * m_release));
param->threshold = m_threshold;
return new AUD_CallbackIIRFilterReader(reader, 1, 2,
(doFilterIIR) envelopeFilter,
(endFilterIIR) endEnvelopeFilter,
param);
}
示例8: AUD_readSoundBuffer
float* AUD_readSoundBuffer(const char* filename, float low, float high,
float attack, float release, float threshold,
int accumulate, int additive, int square,
float sthreshold, double samplerate, int* length)
{
AUD_Buffer buffer;
AUD_DeviceSpecs specs;
specs.channels = AUD_CHANNELS_MONO;
specs.rate = (AUD_SampleRate)samplerate;
AUD_Reference<AUD_IFactory> sound;
AUD_Reference<AUD_IFactory> file = new AUD_FileFactory(filename);
AUD_Reference<AUD_IReader> reader = file->createReader();
AUD_SampleRate rate = reader->getSpecs().rate;
sound = new AUD_ChannelMapperFactory(file, specs);
if(high < rate)
sound = new AUD_LowpassFactory(sound, high);
if(low > 0)
sound = new AUD_HighpassFactory(sound, low);
sound = new AUD_EnvelopeFactory(sound, attack, release, threshold, 0.1f);
sound = new AUD_LinearResampleFactory(sound, specs);
if(square)
sound = new AUD_SquareFactory(sound, sthreshold);
if(accumulate)
sound = new AUD_AccumulatorFactory(sound, additive);
else if(additive)
sound = new AUD_SumFactory(sound);
reader = sound->createReader();
if(reader.isNull())
return NULL;
int len;
int position = 0;
bool eos;
do
{
len = samplerate;
buffer.resize((position + len) * sizeof(float), true);
reader->read(len, eos, buffer.getBuffer() + position);
position += len;
} while(!eos);
float* result = (float*)malloc(position * sizeof(float));
memcpy(result, buffer.getBuffer(), position * sizeof(float));
*length = position;
return result;
}
示例9: AUD_init
int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize)
{
AUD_Reference<AUD_IDevice> dev;
if(!AUD_device.isNull())
AUD_exit();
try
{
switch(device)
{
case AUD_NULL_DEVICE:
dev = new AUD_NULLDevice();
break;
#ifdef WITH_SDL
case AUD_SDL_DEVICE:
dev = new AUD_SDLDevice(specs, buffersize);
break;
#endif
#ifdef WITH_OPENAL
case AUD_OPENAL_DEVICE:
dev = new AUD_OpenALDevice(specs, buffersize);
break;
#endif
#ifdef WITH_JACK
case AUD_JACK_DEVICE:
dev = new AUD_JackDevice("Blender", specs, buffersize);
break;
#endif
default:
return false;
}
AUD_device = dev;
AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device.get());
return true;
}
catch(AUD_Exception&)
{
return false;
}
}
示例10: AUD_mixdown
const char* AUD_mixdown(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate)
{
try
{
AUD_SequencerFactory* f = dynamic_cast<AUD_SequencerFactory*>(sound->get());
f->setSpecs(specs.specs);
AUD_Reference<AUD_IReader> reader = f->createQualityReader();
reader->seek(start);
AUD_Reference<AUD_IWriter> writer = AUD_FileWriter::createWriter(filename, specs, format, codec, bitrate);
AUD_FileWriter::writeReader(reader, writer, length, buffersize);
return NULL;
}
catch(AUD_Exception& e)
{
return e.str;
}
}
示例11:
AUD_OpenALDevice::AUD_OpenALHandle::AUD_OpenALHandle(AUD_OpenALDevice* device, ALenum format, AUD_Reference<AUD_IReader> reader, bool keep) :
m_isBuffered(false), m_reader(reader), m_keep(keep), m_format(format), m_current(0),
m_eos(false), m_loopcount(0), m_stop(NULL), m_stop_data(NULL), m_status(AUD_STATUS_PLAYING),
m_device(device)
{
AUD_DeviceSpecs specs = m_device->m_specs;
specs.specs = m_reader->getSpecs();
// OpenAL playback code
alGenBuffers(CYCLE_BUFFERS, m_buffers);
if(alGetError() != AL_NO_ERROR)
AUD_THROW(AUD_ERROR_OPENAL, genbuffer_error);
try
{
m_device->m_buffer.assureSize(m_device->m_buffersize * AUD_DEVICE_SAMPLE_SIZE(specs));
int length;
bool eos;
for(int i = 0; i < CYCLE_BUFFERS; i++)
{
length = m_device->m_buffersize;
reader->read(length, eos, m_device->m_buffer.getBuffer());
alBufferData(m_buffers[i], m_format, m_device->m_buffer.getBuffer(),
length * AUD_DEVICE_SAMPLE_SIZE(specs),
specs.rate);
if(alGetError() != AL_NO_ERROR)
AUD_THROW(AUD_ERROR_OPENAL, bufferdata_error);
}
alGenSources(1, &m_source);
if(alGetError() != AL_NO_ERROR)
AUD_THROW(AUD_ERROR_OPENAL, gensource_error);
try
{
alSourceQueueBuffers(m_source, CYCLE_BUFFERS,
m_buffers);
if(alGetError() != AL_NO_ERROR)
AUD_THROW(AUD_ERROR_OPENAL, queue_error);
}
catch(AUD_Exception&)
{
alDeleteSources(1, &m_source);
throw;
}
}
catch(AUD_Exception&)
{
alDeleteBuffers(CYCLE_BUFFERS, m_buffers);
throw;
}
alSourcei(m_source, AL_SOURCE_RELATIVE, 1);
}
示例12: AUD_mixdown_per_channel
const char* AUD_mixdown_per_channel(AUD_Sound* sound, unsigned int start, unsigned int length, unsigned int buffersize, const char* filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate)
{
try
{
AUD_SequencerFactory* f = dynamic_cast<AUD_SequencerFactory*>(sound->get());
f->setSpecs(specs.specs);
std::vector<AUD_Reference<AUD_IWriter> > writers;
int channels = specs.channels;
specs.channels = AUD_CHANNELS_MONO;
for(int i = 0; i < channels; i++)
{
std::stringstream stream;
std::string fn = filename;
size_t index = fn.find_last_of('.');
size_t index_slash = fn.find_last_of('/');
size_t index_backslash = fn.find_last_of('\\');
if((index == std::string::npos) ||
((index < index_slash) && (index_slash != std::string::npos)) ||
((index < index_backslash) && (index_backslash != std::string::npos)))
stream << filename << "_" << (i + 1);
else
stream << fn.substr(0, index) << "_" << (i + 1) << fn.substr(index);
writers.push_back(AUD_FileWriter::createWriter(stream.str(), specs, format, codec, bitrate));
}
AUD_Reference<AUD_IReader> reader = f->createQualityReader();
reader->seek(start);
AUD_FileWriter::writeReader(reader, writers, length, buffersize);
return NULL;
}
catch(AUD_Exception& e)
{
return e.str;
}
}
示例13: sizeof
AUD_BaseIIRFilterReader::AUD_BaseIIRFilterReader(AUD_Reference<AUD_IReader> reader, int in,
int out) :
AUD_EffectReader(reader),
m_specs(reader->getSpecs()),
m_xlen(in), m_ylen(out),
m_xpos(0), m_ypos(0), m_channel(0)
{
m_x = new sample_t[m_xlen * m_specs.channels];
m_y = new sample_t[m_ylen * m_specs.channels];
memset(m_x, 0, sizeof(sample_t) * m_xlen * m_specs.channels);
memset(m_y, 0, sizeof(sample_t) * m_ylen * m_specs.channels);
}
示例14: AUD_getCDevice
static PyObject* AUD_getCDevice(PyObject* self)
{
if(!AUD_device.isNull())
{
Device* device = (Device*)Device_empty();
if(device != NULL)
{
device->device = new AUD_Reference<AUD_IDevice>(AUD_device);
return (PyObject*)device;
}
}
Py_RETURN_NONE;
}
示例15: AUD_ConverterReader
AUD_Reference<AUD_IHandle> AUD_OpenALDevice::play(AUD_Reference<AUD_IReader> reader, bool keep)
{
AUD_Specs specs = reader->getSpecs();
// check format
if(specs.channels == AUD_CHANNELS_INVALID)
return AUD_Reference<AUD_IHandle>();
if(m_specs.format != AUD_FORMAT_FLOAT32)
reader = new AUD_ConverterReader(reader, m_specs);
ALenum format;
if(!getFormat(format, specs))
return AUD_Reference<AUD_IHandle>();
lock();
alcSuspendContext(m_context);
AUD_Reference<AUD_OpenALDevice::AUD_OpenALHandle> sound;
try
{
// create the handle
sound = new AUD_OpenALDevice::AUD_OpenALHandle(this, format, reader, keep);
}
catch(AUD_Exception&)
{
alcProcessContext(m_context);
unlock();
throw;
}
alcProcessContext(m_context);
// play sound
m_playingSounds.push_back(sound);
start();
unlock();
return AUD_Reference<AUD_IHandle>(sound);
}