本文整理汇总了C++中Blip_Buffer::sample_rate方法的典型用法代码示例。如果您正苦于以下问题:C++ Blip_Buffer::sample_rate方法的具体用法?C++ Blip_Buffer::sample_rate怎么用?C++ Blip_Buffer::sample_rate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blip_Buffer
的用法示例。
在下文中一共展示了Blip_Buffer::sample_rate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
// Setup left buffer and wave
int left_time = 0;
int left_amp = 0;
setup_demo( left, left_synth );
left.clock_rate( left.sample_rate() * 100 );
// Setup right buffer and wave
int right_time = 0;
int right_amp = 0;
setup_demo( right, right_synth );
right.clock_rate( right.sample_rate() * 100 );
while ( !button_pressed() )
{
blip_time_t length = 100000;
// mouse sets frequency of left wave
int period = 1000 + 6 * mouse_x();
// Add saw wave to left buffer
do {
left_synth.update( left_time, left_amp = (left_amp + 1) % 10 );
} while ( (left_time += period) < length );
left.end_frame( length );
left_time -= length;
// Add saw wave of slightly lower pitch to right buffer
do {
right_synth.update( right_time, right_amp = (right_amp + 1) % 10 );
} while ( (right_time += 1000) < length );
right.end_frame( length );
right_time -= length;
// buffer to read samples into
int const buf_size = 2048;
static blip_sample_t samples [buf_size];
// Read left channel into even samples, right channel into odd samples:
// LRLRLRLRLR...
long count = left.read_samples( samples, buf_size / 2, 1 );
right.read_samples( samples + 1, count, 1 );
play_stereo_samples( samples, count * 2 );
}
return 0;
}
示例2: main
int main () {
if (!alureInitDevice(NULL, NULL)) {
std::fprintf(stderr, "Failed to open OpenAL device: %s\n", alureGetErrorString());
return 1;
}
alGenSources(1, &src);
if (alGetError() != AL_NO_ERROR) {
std::fprintf(stderr, "Failed to create OpenAL source!\n");
alureShutdownDevice();
return 1;
}
// Seeting Blip Buffer
synth.treble_eq( -18.0f );
synth.volume (0.80);
synth.output (&blipbuf);
// Init Blip Buffer with a buffer of 250ms (second paramter is time in ms)
if ( blipbuf.set_sample_rate( SR, 1000 / 4 ) ) {
std::fprintf(stderr, "Failed to create Blip Buffer! Our of Memory\n");
alureShutdownDevice();
return 1;
}
blipbuf.clock_rate( blipbuf.sample_rate() );
blipbuf.bass_freq(300); // Equalization like a TV speaker
stream = alureCreateStreamFromCallback (StreamCB, nullptr, AL_FORMAT_MONO16, SR, SR/2, 0, nullptr);
if(!stream) {
std::fprintf(stderr, "Error creating stream! %s\n", alureGetErrorString());
alDeleteSources(1, &src);
alureShutdownDevice();
return 1;
}
if (!alurePlaySourceStream(src, stream, 4, 0, eos_callback, NULL)) {
std::fprintf(stderr, "Failed to play stream: %s\n", alureGetErrorString());
isdone = 1;
}
alureUpdateInterval(0.005f); // Should be a independint thread playing the stream
while(!isdone) {
freq -= 1;
if (freq < 1) {
freq = 600;
}
alureSleep(0.02f);
}
alureStopSource(src, AL_FALSE);
alDeleteSources(1, &src);
alureDestroyStream(stream, 0, NULL);
alureShutdownDevice();
return 0;
}