本文整理汇总了C++中yse::sound类的典型用法代码示例。如果您正苦于以下问题:C++ sound类的具体用法?C++ sound怎么用?C++ sound使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了sound类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: reset
void reset() {
// YSE has a very flexible vector class built in
YSE::Vec pos;
pos.zero(); YSE::Listener().setPosition(pos);
pos.set(-5, 0, 5); sound1.setPosition(pos);
pos.set(5, 0, 5); sound2.setPosition(pos);
}
开发者ID:AchimTuran,项目名称:yse-soundengine,代码行数:7,代码来源:demo02.cpp
示例2: main
int main() {
YSE::System().init();
// create your dsp object and add it to the system
shepard s;
YSE::sound sound;
sound.create(s).play();
std::cout << "A DSP source object is used here instead of a sample." << std::endl;
std::cout << "Press 1/2 to adjust the lowpass filter frequency" << std::endl;
std::cout << "or e to exit." << std::endl;
while (true) {
if (_kbhit()) {
char ch = _getch();
switch (ch) {
case 'e': goto exit;
case '1': s.frequency(s.frequency() - 50); std::cout << s.frequency() << std::endl; break;
case '2': s.frequency(s.frequency() + 50); std::cout << s.frequency() << std::endl; break;
}
}
YSE::System().sleep(100);
YSE::System().update();
}
exit:
YSE::System().close();
return 0;
}
开发者ID:Ajj2,项目名称:yse-soundengine,代码行数:29,代码来源:demo07_dsp_source.cpp
示例3: main
int main() {
YSE::System().init();
sound.create("drone.ogg", NULL, true);
showDevices();
std::cout << "choose a device or type e to exit: ";
sound.play();
YSE::System().update();
while (true) {
if (_kbhit()) {
int choice = -1;
char ch = _getch();
// this code is not very good because we don't know how many
// devices there are, but it will do for an example
switch (ch) {
case '0': choice = 0; break;
case '1': choice = 1; break;
case '2': choice = 2; break;
case '3': choice = 3; break;
case '4': choice = 4; break;
case '5': choice = 5; break;
case '6': choice = 6; break;
case '7': choice = 7; break;
case '8': choice = 8; break;
case '9': choice = 9; break;
case 'e': goto exit;
}
if (choice >= 0) {
const std::vector<YSE::device> & list = YSE::System().getDevices();
if (choice < list.size()) {
YSE::deviceSetup setup;
setup.setOutput(list[choice]);
YSE::System().closeCurrentDevice();
YSE::System().openDevice(setup);
}
}
}
appTime += 0.1;
YSE::Vec pos;
pos.set(sin(appTime) * 5, 0, cos(appTime) * 5);
sound.setPosition(pos);
YSE::System().update();
YSE::System().sleep(100);
}
exit:
YSE::System().close();
return 0;
}
开发者ID:AchimTuran,项目名称:yse-soundengine,代码行数:55,代码来源:demo06.cpp
示例4: main
int main() {
YSE::System().init();
synth.create();
{
SineWaveVoice voice;
synth.addVoices(&voice, 16, 1);
}
sound.create(synth).play();
soundPos.set(5.f, 0.f, 1.f);
sound.setPosition(soundPos);
midiFile.create("demo.mid");
midiFile.connect(&synth);
std::cout << "YSE can also be used to play midifiles if you setup a virtual synth." << std::endl;
std::cout << "1: start midi file" << std::endl;
std::cout << "2: pause midi file" << std::endl;
std::cout << "3: stop midi file" << std::endl;
std::cout << "4/5: move sound position to left/right" << std::endl;
std::cout << "e: to exit" << std::endl;
Int counter = 0;
while (true) {
if (_kbhit()) {
char ch = _getch();
YSE::Vec pos = YSE::Listener().getPosition();
switch (ch) {
case '1': midiFile.play(); break;
case '2': midiFile.pause(); break;
case '3': midiFile.stop(); break;
case '4': soundPos.x -= 0.1; sound.setPosition(soundPos); break;
case '5': soundPos.x += 0.1; sound.setPosition(soundPos); break;
case 'e': goto exit;
}
}
YSE::System().sleep(100);
YSE::System().update();
}
exit:
YSE::System().close();
return 0;
}
开发者ID:Ajj2,项目名称:yse-soundengine,代码行数:48,代码来源:demo13_midi_file.cpp
示例5: main
int main() {
YSE::System().init();
// create a Triangle wavetable with 8 harmonics, 1024 samples long
wavetable.createTriangle(2, 1024);
// the sound will play this buffer (looping)
sound.create(wavetable, nullptr, true).play();
std::cout << "In this demo a small wavetable is created and played as a loop." << std::endl;
std::cout << "(Press e to exit.)" << std::endl;
while (true) {
if (_kbhit()) {
char ch = _getch();
switch (ch) {
case 'e': goto exit;
}
}
YSE::System().sleep(100);
YSE::System().update();
}
exit:
YSE::System().close();
return 0;
}
开发者ID:Ajj2,项目名称:yse-soundengine,代码行数:30,代码来源:demo18_wavetables.cpp
示例6: main
int main() {
// initialize audio system
YSE::System().init();
// load a sound in memory and get a pointer to it
sound1.create("drone.ogg", NULL, true).play();
sound2.create("kick.ogg", NULL, true).play();
reset();
std::cout << "Initial positions (xyz) are:" << std::endl;
std::cout << "Listener: 0 / 0 / 0" << std::endl;
std::cout << "Sound 1 : -5 / 0 / 5" << std::endl;
std::cout << "Sound 2 : 5 / 0 / 5" << std::endl;
std::cout << std::endl;
std::cout << "Press 1 to select sound 1, 2 for sound 2 and 3 for listener." << std::endl;
std::cout << "Use adws to move selected object (left/right/forward/backward)." << std::endl;
std::cout << "Press 'r' to reset all objects to the initial positions." << std::endl;
std::cout << "Press 'e' to exit this program." << std::endl;
while (true) {
if (_kbhit()) {
char ch = _getch();
switch (ch) {
case '1': selectedObject = 1; break;
case '2': selectedObject = 2; break;
case '3': selectedObject = 3; break;
case 'a': moveObject(LEFT); break;
case 'd': moveObject(RIGHT); break;
case 'w': moveObject(FORWARD); break;
case 's': moveObject(BACKWARD); break;
case 'r': reset(); break;
case 'e': goto exit;
}
}
YSE::System().sleep(100);
//YSE::Vec pos = sound1.getPosition();
//pos.x = sin(std::clock() / static_cast<Flt>(CLOCKS_PER_SEC)) * 10;
//sound1.setPosition(pos);
YSE::System().update();
}
exit:
YSE::System().close();
return 0;
}
开发者ID:AchimTuran,项目名称:yse-soundengine,代码行数:46,代码来源:demo02.cpp
示例7: main
int main() {
YSE::System().init();
if (!buffer.load("countdown.ogg")) {
std::cout << "sound 'countdown.ogg' not found" << std::endl;
std::cin.get();
goto exit;
}
// pass buffer to sound, so that it can be played
sound.create(buffer);
hpf.setFrequency(1000);
std::cout << "Sound is loaded. Please choose: " << std::endl;
std::cout << "1 to play" << std::endl;
std::cout << "2 to stop" << std::endl;
std::cout << "3 multiply wave by 0.5" << std::endl;
std::cout << "4 multiply wave by 2.0" << std::endl;
std::cout << "5 pass wave through high pass filter at 1000Hz" << std::endl;
std::cout << "...or e to exit." << std::endl;
while (true) {
if (_kbhit()) {
char ch = _getch();
switch (ch) {
case '1': sound.play(); break;
case '2': sound.stop(); break;
case '3': buffer *= 0.5; break;
case '4': buffer *= 2.0; break;
case '5': buffer = hpf(buffer); break;
case 'e': goto exit;
}
}
YSE::System().sleep(100);
YSE::System().update();
}
exit:
YSE::System().close();
return 0;
}
开发者ID:JulianYu123456,项目名称:yse-soundengine,代码行数:42,代码来源:demo14_AudioFileManipulation.cpp
示例8: main
int main() {
YSE::System().init();
YSE::sound s;
s.create("countdown.ogg", NULL, true);
std::cout << "Use keyboard to jump to a number." << std::endl;
std::cout << "...or e to exit." << std::endl;
std::cout << "This sound is " << s.getLength() / 44100 << " seconds long." << std::endl;
s.play();
while (true) {
#ifdef WINDOWS
_cprintf_s("Playing at time: %.2f \r", s.getTime() / 44100 * 1000);
#endif
if (_kbhit()) {
char ch = _getch();
switch (ch) {
case '0': s.setTime(11.2f * 44100); break;
case '1': s.setTime(10.0f * 44100); break;
case '2': s.setTime(9.0f * 44100); break;
case '3': s.setTime(8.0f * 44100); break;
case '4': s.setTime(6.7f * 44100); break;
case '5': s.setTime(5.5f * 44100); break;
case '6': s.setTime(4.3f * 44100); break;
case '7': s.setTime(3.2f * 44100); break;
case '8': s.setTime(2.0f * 44100); break;
case '9': s.setTime(1.0f * 44100); break;
case 'e': goto exit;
}
}
YSE::System().sleep(100);
YSE::System().update();
}
exit:
YSE::System().close();
return 0;
}
开发者ID:AchimTuran,项目名称:yse-soundengine,代码行数:42,代码来源:demo10.cpp
示例9: main
int main() {
// initialize audio system
YSE::System().init();
// load a sound in memory
sound.create("drone.ogg", NULL, true);
// false on validation means the sound could not be loaded
if (!sound.isValid()) {
std::cout << "sound 'drone.ogg' not found" << std::endl;
std::cin.get();
goto exit;
}
std::cout << "This is a bare-bones YSE example. It contains the minimum you need to start your own projects." << std::endl;
std::cout << "Press spacebar to toggle sound playing." << std::endl;
std::cout << "Or e to exit." << std::endl;
while (true) {
if (_kbhit()) {
char ch = _getch();
switch (ch) {
// toggle function toggles play / pause
case ' ': sound.toggle(); break;
case 'a': sound.play(); break;
case 's': sound.pause(); break;
case 'd': sound.stop(); break;
case 'e': goto exit;
}
}
/* the sleep function can be used to make sure the update function doesn't run at full
speed. In a simple demo it does not make sense to update that much. In real software
this should probably not be used. Just call YSE::System.update() in your main program loop.
*/
YSE::System().sleep(100);
/* The update function activates all changes you made to sounds and channels since the last call.
This function locks the audio processing thread for a short time. Calling it more than 50 times
a second is really overkill, so call it once in your main program loop, not after changing every setting.
*/
YSE::System().update();
}
exit:
// don't forget this...
YSE::System().close();
return 0;
}
开发者ID:Ajj2,项目名称:yse-soundengine,代码行数:49,代码来源:demo00_play.cpp
示例10: main
int main() {
YSE::System().init();
// setting the last parameter to true will enable streaming
sound.create("pulse1.ogg", NULL, true, 1.0f, true);
if (!sound.isValid()) {
std::cout << "sound 'pulse1.ogg' not found" << std::endl;
std::cin.get();
goto exit;
}
std::cout << "Use q/a to change the sound speed up and down." << std::endl;
std::cout << "Use s/d/f to pause/stop/play." << std::endl;
std::cout << "...or e to exit." << std::endl;
sound.play();
while (true) {
if (_kbhit()) {
char ch = _getch();
switch (ch) {
case 'q': sound.setSpeed(sound.getSpeed() + 0.01); break;
case 'a': sound.setSpeed(sound.getSpeed() - 0.01); break;
case 's': sound.pause(); break;
case 'd': sound.stop(); break;
case 'f': sound.play(); break;
case 'e': goto exit;
}
}
YSE::System().sleep(100);
YSE::System().update();
}
exit:
YSE::System().close();
return 0;
}
开发者ID:wchingwei,项目名称:yse-soundengine,代码行数:38,代码来源:demo09.cpp
示例11: main
int main() {
YSE::System().init();
sound.create("contact.ogg", NULL, true);
if (!sound.isValid()) {
std::cout << "sound 'contact.ogg' not found" << std::endl;
std::cin.get();
goto exit;
}
std::cout << "This shows how to alter basic sound properties." << std::endl;
std::cout << "Use q/a to change the sound speed up and down." << std::endl;
std::cout << "Use w/s to change the volume up and down." << std::endl;
std::cout << "...or e to exit." << std::endl;
sound.play();
while (true) {
if (_kbhit()) {
char ch = _getch();
switch (ch) {
case 'q': sound.setSpeed(sound.getSpeed() + 0.01f); break;
case 'a': sound.setSpeed(sound.getSpeed() - 0.01f); break;
case 's': sound.setVolume(sound.getVolume() - 0.1f); break;
case 'w': sound.setVolume(sound.getVolume() + 0.1f); break;
case 'e': goto exit;
}
}
YSE::System().sleep(100);
YSE::System().update();
}
exit:
YSE::System().close();
return 0;
}
开发者ID:Ajj2,项目名称:yse-soundengine,代码行数:36,代码来源:demo01_sound_properties.cpp
示例12: moveObject
void moveObject(direction d) {
if (selectedObject < 3) {
YSE::sound * s;
if (selectedObject == 1) s = &sound1;
else s = &sound2;
YSE::Vec pos = s->getPosition();
switch (d) {
case FORWARD: pos.z += 0.5f; s->setPosition(pos); break;
case BACKWARD: pos.z -= 0.5f; s->setPosition(pos); break;
case LEFT: pos.x -= 0.5f; s->setPosition(pos); break;
case RIGHT: pos.x += 0.5f; s->setPosition(pos); break;
}
}
else {
// you do not have to create the listener object, it's already there
YSE::Vec pos = YSE::Listener().getPosition();
switch (d) {
case FORWARD: pos.z += 0.5f; YSE::Listener().setPosition(pos); break;
case BACKWARD: pos.z -= 0.5f; YSE::Listener().setPosition(pos); break;
case LEFT: pos.x -= 0.5f; YSE::Listener().setPosition(pos); break;
case RIGHT: pos.x += 0.5f; YSE::Listener().setPosition(pos); break;
}
}
}
开发者ID:AchimTuran,项目名称:yse-soundengine,代码行数:24,代码来源:demo02.cpp
示例13: main
int main() {
YSE::System().init();
YSE::Randomize();
// create a synth with 32 voices
synth.create();
SineWaveVoice voice;
synth.addVoices(&voice, 32, 1);
// use this synth as a sound emitter
sound.create(synth).play();
soundPos.set(5.f, 0.f, 1.f);
sound.setPosition(soundPos);
// create 2 players which uses the synth, and set some starting values
player1.create(synth);
player2.create(synth);
player1.setMinimumPitch(60).setMaximumPitch(72);
player1.setMinimumLength(0.1).setMaximumLength(0.2);
player1.setMinimumVelocity(0.2).setMaximumVelocity(0.4);
player1.setVoices(1);
player2.setMinimumPitch(40).setMaximumPitch(50);
player2.setMinimumLength(2.f).setMaximumLength(4.f);
player2.setMinimumVelocity(0.9f).setMaximumVelocity(1.0f);
// create a scale which can be used by a player
scale1.add(YSE::NOTE::C4)
.add(YSE::NOTE::D4)
.add(YSE::NOTE::E4)
.add(YSE::NOTE::F4)
.add(YSE::NOTE::G4)
.add(YSE::NOTE::A4)
.add(YSE::NOTE::B4);
player1.setScale(scale1);
player2.setScale(scale1);
// create two distinct motifs
motif1.add(YSE::MUSIC::pNote(0, YSE::NOTE::C4, 1.0f, 0.25))
.add(YSE::MUSIC::pNote(0.25, YSE::NOTE::D4, 0.9f, 0.25))
.add(YSE::MUSIC::pNote(0.5, YSE::NOTE::E4, 0.8f, 0.25))
.add(YSE::MUSIC::pNote(0.5, YSE::NOTE::A4, 0.8f, 0.25))
.add(YSE::MUSIC::pNote(0.75, YSE::NOTE::F4, 0.7f, 0.25))
.add(YSE::MUSIC::pNote(1.0, YSE::NOTE::G4, 0.6f, 0.25))
.setLength();
motif2.add(YSE::MUSIC::pNote(0, YSE::NOTE::A5, 0.8f, 0.25))
.add(YSE::MUSIC::pNote(0.25, YSE::NOTE::G5, 0.7f, 0.25))
.add(YSE::MUSIC::pNote(0.50, YSE::NOTE::F5, 0.6f, 0.25))
.add(YSE::MUSIC::pNote(0.75, YSE::NOTE::E5, 0.6f, 1.25))
.setLength();
// these scales are used as a group of possible starting pitches for the
// motif. Transpositions will only happen to these pitches if such a
// scale is provided.
YSE::scale motif1Scale;
motif1Scale.add(YSE::NOTE::C4);
motif1.setFirstPitch(motif1Scale);
YSE::scale motif2Scale;
motif2Scale.add(YSE::NOTE::A5);
motif2.setFirstPitch(motif2Scale);
// instruct player 1 to play this motif. Notice it has a weight of 5. In STEP0 we
// will add another motif with a weight of 1. This results in this first motif being
// played most of the time.
player1.addMotif(motif1, 5).playMotifs(1);
// add some reverb
YSE::System().getGlobalReverb().setActive(true);
YSE::System().getGlobalReverb().setPreset(YSE::REVERB_HALL);
YSE::ChannelMaster().attachReverb();
// the interface
std::cout << "This demo doesn't give you a lot of options, but it will " << std::endl;
std::cout << "evolve on its own." << std::endl;
std::cout << "1 : start player" << std::endl;
std::cout << "2 : stop player" << std::endl;
std::cout << "e : exit" << std::endl;
Int counter = 0;
while (true) {
if (_kbhit()) {
char ch = _getch();
YSE::Vec pos = YSE::Listener().getPosition();
switch (ch) {
case '1': player1.play(); break;
case '2': {
player1.stop();
player2.stop();
progress = 0;
stages = STEP0;
break;
}
case 'e': goto exit;
//.........这里部分代码省略.........
开发者ID:JulianYu123456,项目名称:yse-soundengine,代码行数:101,代码来源:demo16_motifs.cpp
示例14: main
int main() {
YSE::System().init();
envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.f, 0.f, 0.2));
envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.1f, 1.f, 4));
envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.2f, 0.5f, 0.5, true));
envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.5f, 0.6f, 0.5));
envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(0.9f, 0.5f, 0.5, false, true));
envelope.addPoint(YSE::DSP::ADSRenvelope::breakPoint(1.0f, 0.f, 0.5));
envelope.generate();
envelope.saveToFile("ADSRtest");
std::cout << "press e to exit." << std::endl;
synth.create();
synthVoice voice;
synth.addVoices(&voice, 8, 1);
sound.create(synth).play();
int counter = 0;
while (true) {
// random player
if (YSE::Random(10) == 0) {
synth.noteOff(1, bassNote);
bassNote = YSE::Random(30, 50);
Flt vel = YSE::RandomF(0.8, 0.9);
synth.noteOn(1, bassNote, vel);
}
// melody
if (YSE::Random(6) == 0) {
synth.noteOff(1, middleNote);
synth.noteOff(1, middleNote - 3);
middleNote = YSE::Random(55, 65);
synth.noteOn(1, middleNote, YSE::RandomF(0.5, 0.7));
synth.noteOn(1, middleNote - 3, YSE::RandomF(0.5, 0.7));
}
/*if (counter % 20 == 0) {
synth.noteOn(1, 60, 0.3);
synth.noteOn(1, 67, 0.3);
synth.noteOff(1, 62);
synth.noteOff(1, 70);
}
else if (counter % 10 == 0) {
synth.noteOff(1, 60);
synth.noteOff(1, 67);
synth.noteOn(1, 62, 0.3);
synth.noteOn(1, 70, 0.3);
}*/
counter++;
if (_kbhit()) {
char ch = _getch();
switch (ch) {
case 'e': goto exit;
}
}
YSE::System().sleep(100);
YSE::System().update();
}
exit:
YSE::System().close();
return 0;
}
开发者ID:yantrabuddhi,项目名称:yse-soundengine,代码行数:73,代码来源:demo18_ADSR.cpp
示例15: main
int main() {
YSE::System().init();
// load handclap sound, non-looping
snare.create("snare.ogg", NULL, true);
if (!snare.isValid()) {
std::cout << "sound 'snare.ogg' not found" << std::endl;
std::cin.get();
goto exit;
}
// set global reverb
YSE::System().getGlobalReverb().setActive(true);
YSE::System().getGlobalReverb().setPreset(YSE::REVERB_GENERIC);
YSE::ChannelMaster().attachReverb();
// 'world' reverbs can be added at specific positions
// size is the maximum distance from the reverb at which it its influence is at maximum level
// rolloff indicates how far outside its size it will drop to zero influence (linear curve)
// add reverb at 5 meter
bathroom.create();
bathroom.setPosition(YSE::Vec(0, 0, 5)).setSize(1).setRollOff(1);
bathroom.setPreset(YSE::REVERB_BATHROOM);
// add reverb at 10 meter
hall.create();
hall.setPosition(YSE::Vec(0, 0, 10)).setSize(1).setRollOff(1);
hall.setPreset(YSE::REVERB_HALL);
// add reverb at 15 meter
sewer.create();
sewer.setPosition(YSE::Vec(0, 0, 15)).setSize(1).setRollOff(1);
sewer.setPreset(YSE::REVERB_SEWERPIPE);
// add reverb at 20 meter
custom.create();
custom.setPosition(YSE::Vec(0, 0, 20)).setSize(1).setRollOff(1);
// for this reverb we use custom parameters instead of a preset
// (these are meant to sound awkward)
custom.setRoomSize(1.0).setDamping(0.1).setDryWetBalance(0.0, 1.0).setModulation(6.5, 0.7);
custom.setReflection(0, 1000, 0.5).setReflection(1, 1500, 0.6);
custom.setReflection(2, 2100, 0.8).setReflection(3, 2999, 0.9);
std::cout << "This example as one global reverb. On top of that, there are several localized reverbs which will alter the listener's experience when moving around." << std::endl;
std::cout << "Use q/a to move sound and listener forward / back." << std::endl;
std::cout << "Use w/s to toggle global reverb on / off." << std::endl;
std::cout << "...or e to exit." << std::endl;
while (true) {
if (_kbhit()) {
char ch = _getch();
switch (ch) {
case 'q': {
YSE::Vec pos = YSE::Listener().getPosition();
pos.z += 0.1;
YSE::Listener().setPosition(pos);
snare.setPosition(pos);
break;
}
case 'a':{
YSE::Vec pos = YSE::Listener().getPosition();
pos.z -= 0.1;
YSE::Listener().setPosition(pos);
snare.setPosition(pos);
break;
}
case 'w': YSE::System().getGlobalReverb().setActive(true); break;
case 's': YSE::System().getGlobalReverb().setActive(false); break;
case 'e': goto exit;
}
}
if (snare.isStopped()) {
snare.play();
}
YSE::System().sleep(100);
YSE::System().update();
#ifdef WINDOWS
_cprintf_s("Position (z): %.2f \r", YSE::Listener().getPosition().z);
#endif
}
exit:
YSE::System().close();
return 0;
}
开发者ID:Ajj2,项目名称:yse-soundengine,代码行数:90,代码来源:demo05_reverb.cpp
注:本文中的yse::sound类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论