WaveHeader & operator=(WaveHeader &&rhs)
	{
		WaveHeader(std::move(rhs)).swap(rhs);
		return *this;
	}
示例#2
0
文件: u_main.cpp 项目: fotisp/conqat
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
  TMemoryStream *d = new TMemoryStream();
  FormelIntr *fi = new FormelIntr();

  long double res;
  long double max = 0;
#define VARCOUNT 3
  FormIntrVar vars[VARCOUNT] = {
    { "rand" , 0 } ,
    { "t" , 0 } ,
    { "pi" , 3.141592654 }
  };
  FormIntrError error;

  int SampRate = StrToInt ( ComboBox1->Text.SubString ( 1, 5 ) );

  randomize();

  for ( long double i = 0;
        i < CSpinEdit1->Value * SampRate; i++ ) {
    vars[0].Val =
      (long double)(rand()*rand()) / ((long double)rand()+1);
    vars[1].Val = (long double)i / (long double)SampRate;
    fi->Calc ( res, Edit1->Text.c_str(), VARCOUNT, vars, error );
    if ( error.ErrNum != 0 ) res = 0.0;
    d->Write ( &res, sizeof ( res ) );
    if ( res > max ) max = res;
    else if ( res < (-max) ) max = -res;
  }

  if ( max == 0 ) {
    delete d;
    delete fi;
    OUTPUT ( "Error" );
    return;
  }

  long double scal = (long double)30000 / max;

  delete SoundBuffer;
  SoundBuffer = new TMemoryStream();
  Chart1->Series[0]->Clear();
  Chart2->Series[0]->Clear();

  WaveHeader ( SoundBuffer, SampRate, d->Size / sizeof(res) );
  d->Position = 0;

  short signed end = -1;
  short unsigned x1, x2;
  x2 = CSpinEdit2->Value;
  x1 = 0;

  while ( d->Read ( &res, sizeof(res) ) == sizeof( res ) ) {
    end = ( res * scal );
    SoundBuffer->Write ( &end, 2 );
    if ( x1 <= 0 ) {
      Chart1->Series[0]->AddY ( end, "", clTeeColor );
      Chart2->Series[0]->AddY ( end, "", clTeeColor );
      x1 = x2;
    }
    x1--;
  }

  delete d;
  delete fi;

  OUTPUT ( "Created" );
}