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; }
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; }
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; }
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; }
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; }
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; }
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; }