本文整理汇总了C++中SampleBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ SampleBuffer类的具体用法?C++ SampleBuffer怎么用?C++ SampleBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SampleBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write_image
void write_image(const string& file, const SampleBuffer& buffer)
{
const float samples = static_cast<float>(buffer.samples());
FIBITMAP* dib = FreeImage_Allocate(buffer.width(), buffer.height(),
32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK);
const unsigned int BYTESPP =
FreeImage_GetLine(dib) / FreeImage_GetWidth(dib);
for (unsigned int y = 0; y < FreeImage_GetHeight(dib); ++y) {
BYTE* bits = FreeImage_GetScanLine(dib, y);
for (unsigned int x = 0; x < FreeImage_GetWidth(dib); ++x) {
vec3 c = gamma_correct(buffer.get(x, y) / samples) * 255.0f;
bits[FI_RGBA_RED] = static_cast<BYTE>(c.r);
bits[FI_RGBA_GREEN] = static_cast<BYTE>(c.g);
bits[FI_RGBA_BLUE] = static_cast<BYTE>(c.b);
bits[FI_RGBA_ALPHA] = 255;
bits += BYTESPP;
}
}
if (!FreeImage_Save(FIF_PNG, dib, file.c_str(), 0)) {
string err = "Failed to save screenshot to file '";
err += file;
err += '\'';
throw err;
}
FreeImage_Unload(dib);
}
示例2: askUserDefWave
void LfoControllerDialog::askUserDefWave()
{
SampleBuffer * sampleBuffer = dynamic_cast<LfoController*>(this->model())->
m_userDefSampleBuffer;
QString fileName = sampleBuffer->openAndSetWaveformFile();
if( fileName.isEmpty() == false )
{
// TODO:
ToolTip::add( m_userWaveBtn, sampleBuffer->audioFile() );
}
}
示例3: append
void SampleBuffer::append(const SampleBuffer& other)
{
assert(width() == other.width() && height() == other.height());
auto it = _buffer.begin();
auto io = other._buffer.cbegin();
while (it < _buffer.cend()) {
*it += *io;
++it;
++io;
}
_samples += other.samples();
}
示例4:
void SampleFrontEnd<sample_base_t>::Clear( )
{
//temporary pointer
SampleBuffer<sample_base_t>* pSampleBuff;
for(std::map<std::string,std::pair<SampleSink*,SampleStreamInfo*>>::iterator mit = this->mSampleSinks.begin(); mit != this->mSampleSinks.end(); mit++)
{
pSampleBuff = dynamic_cast<SampleBuffer<sample_base_t>*>( mit->second.first );
if( pSampleBuff )
pSampleBuff->Flush();
}
};
示例5: NewSamples
/// Write the summary to disk, using the derived ReadData() to get the data
/// Here, the decoder ODTask associated with this file must fetch the samples with
/// the ODDecodeTask::Decode() method.
int ODDecodeBlockFile::WriteODDecodeBlockFile()
{
// To build the summary data, call ReadData (implemented by the
// derived classes) to get the sample data
SampleBuffer sampleData;// = NewSamples(mLen, floatSample);
int ret;
//use the decoder here.
mDecoderMutex.Lock();
if(!mDecoder)
{
mDecoderMutex.Unlock();
return -1;
}
//sampleData and mFormat are set by the decoder.
ret = mDecoder->Decode(sampleData, mFormat, mAliasStart, mLen, mAliasChannel);
mDecoderMutex.Unlock();
if(ret < 0) {
printf("ODDecodeBlockFile Decode failure\n");
return ret; //failure
}
//the summary is also calculated here.
mFileNameMutex.Lock();
//TODO: we may need to write a version of WriteSimpleBlockFile that uses threadsafe FILE vs wxFile
bool bSuccess =
WriteSimpleBlockFile(
sampleData.ptr(),
mLen,
mFormat,
NULL);//summaryData);
wxASSERT(bSuccess); // TODO: Handle failure here by alert to user and undo partial op.
wxUnusedVar(bSuccess);
mFileNameMutex.Unlock();
// delete [] (char *) summaryData;
mDataAvailableMutex.Lock();
mDataAvailable=true;
mDataAvailableMutex.Unlock();
return ret;
}
示例6: write_bitmap
void write_bitmap(char const * path, SampleBuffer const & buffer) {
FILE * fd = fopen(path, "wb");
BitmapHeader header;
BitmapInfo info = make_info(buffer.get_width(), buffer.get_height());
header.size() = sizeof(header) + sizeof(info) + buffer.get_size() * sizeof(uint32);
header.offset() = sizeof(header) + sizeof(info);
fwrite(&header, sizeof(header), 1, fd);
fwrite(&info, sizeof(info), 1, fd);
buffer.write_bitmap(fd);
fclose(fd);
}
示例7:
void DSP::Filter::Gain::processSamples(SampleBuffer& samples) {
for(int i = 0; i < samples.size(); ++i) {
auto scaled = static_cast<int64_t>(samples[i]) * m_gain;
samples[i] = saturate<int16_t>(scaled >> 16);
}
}
示例8: SampleBuffer
SampleBuffer *NativeFilm::GetFreeSampleBuffer() {
// Look for a free buffer
if (freeSampleBuffers.size() > 0) {
SampleBuffer *sb = freeSampleBuffers.front();
freeSampleBuffers.pop_front();
sb->Reset();
return sb;
} else {
// Need to allocate a new buffer
SampleBuffer *sb = new SampleBuffer(SampleBufferSize);
sampleBuffers.push_back(sb);
return sb;
}
}
示例9: setWaveToUser
QString graphModel::setWaveToUser()
{
SampleBuffer * sampleBuffer = new SampleBuffer;
QString fileName = sampleBuffer->openAndSetWaveformFile();
if( fileName.isEmpty() == false )
{
for( int i = 0; i < length(); i++ )
{
m_samples[i] = sampleBuffer->userWaveSample(
i / static_cast<float>( length() ) );
}
}
sharedObject::unref( sampleBuffer );
emit samplesChanged( 0, length() - 1 );
return fileName;
};
示例10: DEBUG_ASSERT
void SingularSampleBuffer::swapBuffers(SampleBuffer& secondaryBuffer) {
DEBUG_ASSERT_CLASS_INVARIANT_SingularSampleBuffer;
DEBUG_ASSERT(m_primaryBuffer.size() == secondaryBuffer.size());
// SampleUtil::copy() requires that the source and destination
// memory regions are disjunct. Double-buffering is necessary
// to satisfy this precondition.
SampleUtil::copy(
secondaryBuffer.data(),
m_primaryBuffer.data(m_headOffset),
getSize());
m_primaryBuffer.swap(secondaryBuffer);
// shift offsets
m_tailOffset -= m_headOffset;
m_headOffset = 0;
DEBUG_ASSERT_CLASS_INVARIANT_SingularSampleBuffer;
}
示例11: MusicHook
void SoundEngine::MusicHook(void* userdata, Uint8* stream, int len)
{
bool* musicFinishedPtr = reinterpret_cast<bool*>(userdata);
if (!*musicFinishedPtr)
{
SampleBuffer buffer;
Uint32 ret = musicDecoder.Decode(buffer, len);
if (ret == SOUND_DECODE_COMPLETED) {
musicDecoder.Close();
*musicFinishedPtr = true;
} else if (ret == SOUND_DECODE_ERROR) {
logger->error("Sound: Error during music decoding, stopping playback of current track.\n");
*musicFinishedPtr = true;
return;
}
memcpy(stream, &buffer[0], buffer.size());
}
}
示例12: Decode
//--Decoder stuff:
///Decodes the samples for this blockfile from the real file into a float buffer.
///This is file specific, so subclasses must implement this only.
///the buffer was defined like
///samplePtr sampleData = NewSamples(mLen, floatSample);
///this->ReadData(sampleData, floatSample, 0, mLen);
///This class should call ReadHeader() first, so it knows the length, and can prepare
///the file object if it needs to.
int ODFlacDecoder::Decode(SampleBuffer & data, sampleFormat & format, sampleCount start, size_t len, unsigned int channel)
{
//we need to lock this so the target stays fixed over the seek/write callback.
mFlacFileLock.Lock();
bool usingCache=mLastDecodeStartSample==start;
if(usingCache)
{
//we've just decoded this, so lets use a cache. (often so for
}
mDecodeBufferWritePosition=0;
mDecodeBufferLen = len;
data.Allocate(len, mFormat);
mDecodeBuffer = data.ptr();
format = mFormat;
mTargetChannel=channel;
// Third party library has its own type alias, check it
static_assert(sizeof(sampleCount::type) <=
sizeof(FLAC__int64),
"Type FLAC__int64 is too narrow to hold a sampleCount");
if(!mFile->seek_absolute(static_cast<FLAC__int64>( start.as_long_long() )))
{
mFlacFileLock.Unlock();
return -1;
}
while(mDecodeBufferWritePosition<mDecodeBufferLen)
mFile->process_single();
mFlacFileLock.Unlock();
if(!usingCache)
{
mLastDecodeStartSample=start;
}
//insert into blockfile and
//calculate summary happen in ODDecodeBlockFile::WriteODDecodeBlockFile, where this method is also called.
return 1;
}
示例13: lock
SampleBuffer *NativePixelDevice::GetFreeSampleBuffer() {
boost::mutex::scoped_lock lock(splatMutex);
// Look for a free buffer
if (freeSampleBuffers.size() > 0) {
SampleBuffer *sb = freeSampleBuffers.front();
freeSampleBuffers.pop_front();
sb->Reset();
return sb;
} else {
// Need to allocate a new buffer
SampleBuffer *sb = new SampleBuffer(SampleBufferSize);
sampleBuffers.push_back(sb);
return sb;
}
}
示例14: Exception
void UniformSampleGenerator2DCL::generateNextSamples(SampleBuffer& positionSamplesOut, const VECTOR_CLASS<cl::Event>* waitForEvents /*= nullptr*/, cl::Event* event /*= nullptr*/) {
if (kernel_ == NULL) {
return throw Exception("Invalid kernel: Kernel not found or failed to compile");
}
size2_t nSamples{static_cast<size_t>(std::sqrt(static_cast<double>(positionSamplesOut.getSize())))};
if (getUseGLSharing()) {
SyncCLGL glSync;
BufferCLGL* samples = positionSamplesOut.getEditableRepresentation<BufferCLGL>();
// Acquire shared representations before using them in OpenGL
// The SyncCLGL object will take care of synchronization between OpenGL and OpenCL
glSync.addToAquireGLObjectList(samples);
glSync.aquireAllObjects();
generateSamples(nSamples, positionSamplesOut.getSize(), samples, waitForEvents, event);
} else {
BufferCL* samples = positionSamplesOut.getEditableRepresentation<BufferCL>();
generateSamples(nSamples, positionSamplesOut.getSize(), samples, waitForEvents, event);
}
}
开发者ID:ResearchDaniel,项目名称:Correlated-Photon-Mapping-for-Interactive-Global-Illumination-of-Time-Varying-Volumetric-Data,代码行数:19,代码来源:uniformsamplegenerator2dcl.cpp
示例15: NewSamples
/// Write the summary to disk, using the derived ReadData() to get the data
/// Here, the decoder ODTask associated with this file must fetch the samples with
/// the ODDecodeTask::Decode() method.
int ODDecodeBlockFile::WriteODDecodeBlockFile()
{
// To build the summary data, call ReadData (implemented by the
// derived classes) to get the sample data
SampleBuffer sampleData;// = NewSamples(mLen, floatSample);
int ret;
{
//use the decoder here.
ODLocker locker{ &mDecoderMutex };
if(!mDecoder)
return -1;
//sampleData and mFormat are set by the decoder.
ret = mDecoder->Decode(sampleData, mFormat, mAliasStart, mLen, mAliasChannel);
if(ret < 0) {
wxPrintf("ODDecodeBlockFile Decode failure\n");
return ret; //failure
}
}
{
//the summary is also calculated here.
ODLocker locker{ &mFileNameMutex };
//TODO: we may need to write a version of WriteSimpleBlockFile that uses threadsafe FILE vs wxFile
bool bSuccess =
WriteSimpleBlockFile(
sampleData.ptr(),
mLen,
mFormat,
NULL);
if ( !bSuccess )
return -1;
}
wxAtomicInc( mDataAvailable );
return ret;
}