本文整理汇总了C++中ALValue::SetBinary方法的典型用法代码示例。如果您正苦于以下问题:C++ ALValue::SetBinary方法的具体用法?C++ ALValue::SetBinary怎么用?C++ ALValue::SetBinary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ALValue
的用法示例。
在下文中一共展示了ALValue::SetBinary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: playSineWaves
//.........这里部分代码省略.........
data_norm[i] = (float) value;
}
catch(AL::ALError &e)
{
//throw ALError("ALSoundGeneration", "playSineWaves()", e.getDescription());
data_norm[i] = 0.0;
}
}
// read activation from ALMemory
try
{
ALValue value = fProxyToALMemory.getData("ALSoundGeneration/activation");
activation = (float) value;
}
catch(AL::ALError &e)
{
//throw ALError("ALSoundGeneration", "playSineWaves()", e.getDescription());
activation = 0.0;
}
// (de)amplify
for(int i=0; i<num_bins; i++)
{
data_norm[i] *= activation; // use activation to set volume
}
// DEBUG
for(int i=0; i<num_bins; i++)
{
printf("%.1f ", data_norm[i]);
}
printf(" activation: %.1f", activation);
printf("\n");
// clear audio buffer
for(int j=0; j<num_samples; j++)
{
buffer_mono[j] = 0;
}
// fill audio buffer
int freq_sine;
double amplitude;
double samples_per_sine;
double silencing_factor = 0.1; // DEBUG: silence a bit
for(int i=0; i<num_bins; i++)
{
freq_sine = i * bin_size; // equal bin size assumed
freq_sine += bin_size / 2; // shift by half bin size
amplitude = data_norm[i];
// threshold
if(amplitude > 0.2)
{
samples_per_sine = (double) sample_rate / freq_sine;
for(int j=0; j<num_samples; j++)
{
buffer_mono[j] += (short) round(sin((double) j / samples_per_sine * 2 * PI) * silencing_factor * amplitude * SHRT_MAX);
}
}
}
// limit audio buffer
for(int j=0; j<num_samples; j++)
{
if(buffer_mono[j] > SHRT_MAX)
buffer_mono[j] = SHRT_MAX;
if(buffer_mono[j] < SHRT_MIN)
buffer_mono[j] = SHRT_MIN;
}
// convert to stereo
int i = 0;
for(int j=0; j<num_samples; j++)
{
buffer_stereo[i] = buffer_mono[j];
buffer_stereo[i+1] = buffer_mono[j];
i += 2;
}
// transform to binary samples
pDataBin.SetBinary(buffer_stereo, num_samples * sizeof(short) * 2);
// send to audiodevice module
try
{
audioDeviceProxy->call<bool>("sendRemoteBufferToOutput", num_samples, pDataBin);
}
catch(AL::ALError &e)
{
throw ALError("ALSoundGeneration", "playSineWaves()", e.getDescription());
}
// DEBUG
clock_t clockEnd = clock();
printf("processing took %.1f ms\n", (double) (clockEnd - clockBegin) / CLOCKS_PER_SEC * 1000);
}
}