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;
}
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;
}
示例#3
0
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;
}
示例#4
0
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;
}
示例#5
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;
}
示例#6
0
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;
}
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;
}
示例#8
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;
}
示例#9
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() {
  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();

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

    if (player1.isPlaying() || player2.isPlaying()) progress += 0.1;

    // This switch adds changes to the music every 10 seconds
    switch (stages) {
    case STEP0:
      if (progress > 10) {
        std::cout << "step 1 started." << std::endl;
        std::cout << " --> second motif added" << std::endl;
        player1.addMotif(motif2, 1);
        stages = STEP1;

      }
      break;

    case STEP1:
      if (progress > 20) {
        motif1Scale.add(YSE::NOTE::G5);
        player1.setVoices(3, 10).setMaximumPitch(YSE::NOTE::C7, 20);
        std::cout << "step 2 started." << std::endl;
        std::cout << " --> add more voices and play higher" << std::endl;
        stages = STEP2;

      }
      break;

    case STEP2:
      if (progress > 30) {
        player2.play();
        player2.setVoices(3, 10);
        std::cout << "step 3 started." << std::endl;
        std::cout << " --> add some bass" << std::endl;
        stages = STEP3;

      }
      break;

    case STEP3:
      if (progress > 40) {
        player1.playMotifs(0.5, 10).setMinimumLength(2.f).setMaximumLength(4.f);
        player1.setVoices(8, 20);
        std::cout << "step 4 started." << std::endl;
        std::cout << " --> add more voices to player 1" << std::endl;
        std::cout << " --> have player 1 play random notes half of the time" << std::endl;
        stages = STEP4;

      }
      break;

    case STEP4:
      if (progress > 50) {
        std::cout << "step 5 started." << std::endl;
        std::cout << " --> add new notes to the scale" << std::endl;
        std::cout << " --> play less motifs and more random notes" << std::endl;
        scale1.add(YSE::NOTE::EF4).add(YSE::NOTE::BF4);
        player1.playMotifs(0.2, 10).setMinimumPitch(YSE::NOTE::C5, 20);
        stages = STEP5;

      }
      break;

    case STEP5:
      if (progress > 60) {
        std::cout << "step 6 started." << std::endl;
        std::cout << " --> add new notes to the scale" << std::endl;
        std::cout << " --> add new first pitches to motif 2" << std::endl;
        std::cout << " --> remove motif 1 from the player" << std::endl;
        std::cout << " --> add rests in player 2 (bass)" << std::endl;
        scale1.add(YSE::NOTE::FS4).add(YSE::NOTE::CS4);
        motif2Scale.add(YSE::NOTE::C4).add(YSE::NOTE::CS4).add(YSE::NOTE::D4);
        player1.removeMotif(motif1);
        player2.setMinimumGap(2, 10).setMaximumGap(5, 20);
        player2.setVoices(1);
        stages = STEP6;

      }
      break;

    case STEP6:
      if (progress > 70) {
        std::cout << "step 7 started." << std::endl;
        std::cout << " --> play more motifs, but mostly partial" << std::endl;
        player1.playMotifs(1.0, 5);
        player1.playPartialMotifs(0.5, 10);
        player2.stop();
        stages = STEP7;

      }
      break;

    case STEP7:
      if (progress > 80) {
        std::cout << "step 8 started." << std::endl;
        std::cout << " --> play lower notes" << std::endl;
        std::cout << " --> add more voices" << std::endl;
        std::cout << " --> play louder" << std::endl;
        player1.setMinimumPitch(30, 10);
        player1.setVoices(20, 20);
        player1.setMinimumVelocity(0.9, 10).setMaximumVelocity(1.0, 10);
        stages = STEP8;

      }
      break;

    case STEP8:
      if (progress > 90) {
        std::cout << "step 9 started." << std::endl;
        std::cout << " --> have player 2 play wide chords at random" << std::endl;
        stages = STEP9;
        player2.setVoices(15);
        player2.setMinimumLength(3).setMaximumLength(5);
        player2.setMinimumVelocity(0.9).setMaximumVelocity(1.0);
        player2.setMinimumPitch(20).setMaximumPitch(100);
        player2.setMinimumGap(0).setMaximumGap(0);
        player2.playMotifs(0);
        player2.play();
      }
      break;

    case STEP9:
      if (progress > 100) {
        std::cout << "step 10 started." << std::endl;
        std::cout << " --> player 1 stops" << std::endl;
        std::cout << " --> player 2 plays even more long notes" << std::endl;
        stages = STEP10;
        player1.stop();
        player2.setVoices(30);
      }
      break;

    case STEP10:
      if (progress > 110) {
        std::cout << "step 11 started." << std::endl;
        std::cout << " --> reset player 1 to motif 1" << std::endl;
        std::cout << " --> fade out player 2" << std::endl;
        stages = STEP11;
        player1.removeMotif(motif2).addMotif(motif1);
        player1.setVoices(1);
        player1.setMinimumVelocity(0.4).setMaximumVelocity(0.6);
        player1.playMotifs(1).playPartialMotifs(0);
        player1.play();
        player2.setMinimumVelocity(0.1, 10).setMaximumVelocity(0.2, 10);
        player2.setMinimumPitch(70, 10);
      }
      break;

    case STEP11:
      if (progress > 120) {
        std::cout << "step 12 started." << std::endl;
        std::cout << " --> player 2 stops" << std::endl;
        std::cout << " --> player 1 players only partial motifs" << std::endl;
        player2.stop();
        motif1Scale.remove(YSE::NOTE::G5);
        player1.playPartialMotifs(1, 10);
        scale1.remove(YSE::NOTE::FS4).remove(YSE::NOTE::CS4);
        scale1.remove(YSE::NOTE::EF4).remove(YSE::NOTE::BF4);
        player1.setVoices(4, 10);
        stages = STEP12;

      }
      break;

    case STEP12:
      if (progress > 130) {
        std::cout << "step 13 started." << std::endl;
        std::cout << " --> nothing new" << std::endl;
        stages = STEP13;

      }
      break;

    case STEP13:
      if (progress > 140) {
        std::cout << "step 14 started." << std::endl;
        std::cout << " --> player 1 plays louder" << std::endl;
        player1.setMinimumVelocity(0.8, 10).setMaximumVelocity(1.0, 10);
        stages = STEP14;

      }
      break;

    case STEP14:
      if (progress > 150) {
        std::cout << "step 15 started." << std::endl;
        std::cout << " --> nothing new" << std::endl;
        stages = STEP15;

      }
      break;

    case STEP15:
      if (progress > 160) {
        std::cout << "step 16 started." << std::endl;
        std::cout << " --> add short 'F' repetitions on player 2" << std::endl;
        scale1.clear();
        scale1.add(YSE::NOTE::F4);
        player2.setMinimumLength(0.1).setMaximumLength(0.2);
        player2.setMinimumGap(0.1).setMaximumGap(0.2);
        player2.setMinimumVelocity(0.9, 10).setMaximumVelocity(1.0,10);
        player2.setMinimumPitch(70).setMaximumPitch(100);
        player2.setVoices(15);
        player2.play();
        stages = STEP16;

      }
      break;

    case STEP16:
      if (progress > 170) {
        std::cout << "step 17 started." << std::endl;
        std::cout << " --> player 2 add 'B'" << std::endl;
        stages = STEP17;
        scale1.add(YSE::NOTE::B4);
        
      }
      break;

    case STEP17:
      if (progress > 180) {
        std::cout << "step 18 started." << std::endl;
        std::cout << " --> no more partial motifs on player 1" << std::endl;
        std::cout << " --> set player 1 to only one voice" << std::endl;
        std::cout << " --> player 2 fade out" << std::endl;
        stages = STEP18;
        player1.playPartialMotifs(0, 5);
        player1.setVoices(1, 5);
        player2.setMinimumVelocity(0.1, 10).setMaximumVelocity(2.0, 10);
      }
      break;

    case STEP18:
      if (progress > 190) {
        std::cout << "step 19 started." << std::endl;
        std::cout << " --> player 2 stops again" << std::endl;
        player2.stop();
        stages = STEP19;

      }
      break;

    case STEP19:
      if (progress > 200) {
        std::cout << "THE END." << std::endl;
        player1.stop();
        player2.stop();
        stages = STEP0;
        progress = 0;
      }
      break;
    }

    YSE::System().sleep(100);

    YSE::System().update();

  }

exit:
  YSE::System().close();
  return 0;
}
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;
}
示例#13
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;
}