用TMediaplayer录音时他的音频的数据流没有在硬盘上,而是在内存中。
现在想问各位大哥一个问题,我是否可以在没有保存的时候直接访问在内存中的数据流,或其他什么办法可以实现在录音的同时处理输出的wav文件!

解决方案 »

  1.   

    在内存中播放是这样的,在资源文件中的情形
    var
      Form1: TForm1;
        PtrSound : PChar;
        hRes : THandle; {handle to the loaded resource
        if 0 indicates nothing playing}
    implementation{$R *.dfm}
    {$R nestexe.res}procedure TForm1.btnStartClick(Sender: TObject);
    begin
      sndplaysound(ptrSound,snd_async or snd_Memory);
    end;procedure TForm1.FormCreate(Sender: TObject);
    var
      hResInfo : THandle;
    begin 
      hResInfo := FindResource(HInstance, 'SOUND1', 'WAV');
      hRes := LoadResource(HInstance, hResInfo);
      if hRes > 32 then {its a good load}
      begin {lock the resource}
        ptrSound:=LockResource(hRes);
      end;
    end;
      

  2.   

    struct TWavHeader
    {
      long int rId;
      long int rLen;
      long int wId;
      long int fId;
      long int fLen;
      Word wFormatTag;
      Word nChannels;
      long int nSamplesPerSec;
      long int nAvgBytesPerSec;
      Word nBlockAlign ;
      Word wBitsPerSample;
      long int dId;
      long int wSampleLength;
    };//---------------------------------------------------------------------------
    void CreateWav(Word channels,Word resolution, long int rate,char* fn)
    {
      FILE *wf;
      TWavHeader wh;  wh.rId = 0x46464952; //wh.rId := $46464952;
      wh.rLen = 36;
      wh.wId = 0x45564157;
      wh.fId = 0x20746d66;
      wh.fLen = 16;
      wh.wFormatTag = 1;
      wh.nChannels = channels;
      wh.nSamplesPerSec = rate;
      wh.nAvgBytesPerSec = channels * rate * (resolution / 8);
      wh.nBlockAlign = channels*(resolution / 8);
      wh.wBitsPerSample = resolution;
      wh.dId = 0x61746164;
      wh.wSampleLength = 0;  wf=fopen(fn,"wb");  if(wf != NULL)
      {
         fwrite(&wh,1,sizeof(TWavHeader),wf);
      }
      else
      {
         ShowMessage("Can not Open File!");
       }
       fclose(wf);
    end;
    }//---------------------------------------------------------------------------
    void __fastcall TForm1::btn1Click(TObject *Sender)
    {
      if( FileExists("Temp.wav") ) DeleteFile("Temp.wav");  CreateWav(1,16,8000,"Temp.wav");  mp1->DeviceType = dtAutoSelect;
      mp1->FileName = "Temp.wav";
      mp1->Open();
      mp1->StartRecording();  mtimes = 3;
      mmo_result->Lines->Clear();
      mmo_result->Lines->Add("开始录音...");
      lb_status->Width = 0;
      tmr1->Enabled = true;}//---------------------------------------------------------------------------
    void __fastcall TForm1::btn2Click(TObject *Sender)
    {
       Sleep(500);
       mp1->Stop();
       mp1->Save();
       mp1->Close();
      

  3.   

    这个有点难呢!
    上次我也是用mediaplayer录音,但是不知怎样才能将内存里的数据直接处理而不通过先save,最后没有找到办法,就换成ACM控件啦