void asset_path_test ( )

/******************************************************************************/
/*
  Purpose:

    ASSET_PATH_TEST tests ASSET_PATH.

  Licensing:

    This code is distributed under the GNU LGPL license.

  Modified:

    18 February 2012

  Author:

    John Burkardt
*/
{
  double mu;
  int n = 100;
  char output_filename[100] = "asset_path.txt";;
  double *s;
  double s0;
  int seed;
  double sigma;
  double t1;

  printf ( "\n" );
  printf ( "ASSET_PATH_TEST:\n" );
  printf ( "  Demonstrate the simulated of an asset price path.\n" );

  s0 = 2.0;
  mu = 0.1;
  sigma = 0.3;
  t1 = 1.0;
  seed = 123456789;

  printf ( "\n" );
  printf ( "  The asset price at time 0      S0    = %g\n", s0 );
  printf ( "  The asset expected growth rate MU    = %g\n", mu );
  printf ( "  The asset volatility           SIGMA = %g\n", sigma );
  printf ( "  The expiry date                T1    = %g\n", t1 );
  printf ( "  The number of time steps       N     = %d\n", n );
  printf ( "  The random number seed was     SEED  = %d\n", seed );

  s = asset_path ( s0, mu, sigma, t1, n, &seed );

  r8vec_print_part ( n + 1, s, 10, "  Partial results:" );

  r8vec_write ( output_filename, n + 1, s );

  printf ( "\n" );
  printf ( "  Full results written to \"%s\".\n", output_filename );

  free ( s );

  return;
}
Exemplo n.º 2
0
int main(int argc, char * argv[]) {
    
    // Lets find the bundle first
    // All this jazz simply deals with loading the bundle
    LOAD_API_BUNDLE;
    RETAIN_API_BUNDLE_VAR;
    
    initEnvFunc initEnv = set_initEnvFunc(API_BUNDLE_VAR);
    destroyEnvFunc destroyEnv = set_destroyEnvFunc(API_BUNDLE_VAR);
    startJuceFunc startJuce = set_startJuceFunc(API_BUNDLE_VAR);
    stopJuceFunc stopJuce = set_stopJuceFunc(API_BUNDLE_VAR);
    addSoundToRendererBankFunc addSound = set_addSoundToRendererBankFunc(API_BUNDLE_VAR);
    deactivateSoundInRendererBankFunc deactivateSoundInRendererBank = set_deactivateSoundInRendererBankFunc(API_BUNDLE_VAR);
    
    std::string asset_path(TEST_ASSET_PATH);
    std::string asset_one(asset_path + std::string("/ad-demo.wav"));
    std::string asset_two(asset_path + std::string("/cat.wav"));
    
    std::vector<char> asset_one_str(asset_one.begin(), asset_one.end());
    asset_one_str.push_back('\0');
    std::vector<char> asset_two_str(asset_two.begin(), asset_two.end());
    asset_two_str.push_back('\0');
    
// ---------------------------------------------------------------------- //
// ---------------------------------------------------------------------- //
// ---------------------------------------------------------------------- //

#define TESTING_JUCE_PLAYBACK
#ifdef TESTING_JUCE_PLAYBACK
    
    initEnv();
    addSound(&asset_one_str[0]);
    addSound(&asset_two_str[0]);
    startJuce();
    
    sleep(6);
    
    // Go away cat!
    deactivateSoundInRendererBank(&asset_two_str[0]);
    
    sleep(6);
    addSound(&asset_two_str[0]);
    sleep(3);
    
    stopJuce();
    deactivateSoundInRendererBank(&asset_one_str[0]);
    deactivateSoundInRendererBank(&asset_two_str[0]);
    destroyEnv();
    
#else
    
    initEnv();
    addSound(&asset_one_str[0]);
    
    sleep(2);
    
    removeSoundFromRendererBank(&asset_one_str[0]);
    destroyEnv();
    
#endif

// ---------------------------------------------------------------------- //
// ---------------------------------------------------------------------- //
// ---------------------------------------------------------------------- //
    
    printf("Releasing the bundle\n");
    RELEASE_API_BUNDLE_VAR;
    
    printf("Calling it a day\n");
    return 0;
}