本文整理汇总了C++中AUD_Reference::read方法的典型用法代码示例。如果您正苦于以下问题:C++ AUD_Reference::read方法的具体用法?C++ AUD_Reference::read怎么用?C++ AUD_Reference::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AUD_Reference
的用法示例。
在下文中一共展示了AUD_Reference::read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writeReader
void AUD_FileWriter::writeReader(AUD_Reference<AUD_IReader> reader, std::vector<AUD_Reference<AUD_IWriter> >& writers, unsigned int length, unsigned int buffersize)
{
AUD_Buffer buffer(buffersize * AUD_SAMPLE_SIZE(reader->getSpecs()));
AUD_Buffer buffer2(buffersize * sizeof(sample_t));
sample_t* buf = buffer.getBuffer();
sample_t* buf2 = buffer2.getBuffer();
int len;
bool eos = false;
int channels = reader->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 channel = 0; channel < channels; channel++)
{
for(int i = 0; i < len; i++)
{
// clamping!
if(buf[i * channels + channel] > 1)
buf2[i] = 1;
else if(buf[i * channels + channel] < -1)
buf2[i] = -1;
else
buf2[i] = buf[i * channels + channel];
}
writers[channel]->write(len, buf2);
}
}
}
示例2: 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;
}
示例3:
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);
}
示例4: 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;
}