Einzelnen Beitrag anzeigen

Ducksoul

Registriert seit: 19. Apr 2006
Ort: Ilmenau
87 Beiträge
 
RAD-Studio 2009 Pro
 
#4

Re: Ende von Aufnahme erkennen 'bass.dll'

  Alt 26. Aug 2008, 11:29
Hallo. Also um mal ein bisschen Code mitzuteilen:

Die Wiedergabe läuft folgendermaßen:
Delphi-Quellcode:
  (* PlayButtonClick || Wiedergabe der Aufnahme *)
  procedure TRecordForm.PlayExecute(Sender: TObject);
    var hEndSync: HSYNC;
    begin
          case BASS_ChannelIsActive(chan) of
            BASS_Active_Stopped:
              begin
                BASS_ChannelPlay(chan, True);
                ToggleStatus(1);
              end;
            BASS_Active_Playing:
              begin
                BASS_ChannelPause(chan);
                ToggleStatus(2);
              end;
            BASS_Active_Paused:
              begin
                BASS_ChannelPlay(chan, False);
                ToggleStatus(1);
              end;
          end; // case
    end; // procedure PlayExecute

Beim Aufnehmen sieht es so aus:
Delphi-Quellcode:
  (* Aufnahme Start *)
  procedure TRecordForm.StartRecording;
    var
      vol: Float;
      i: Integer;
      Flag: DWord;
    begin

        // Aufnahme je nach Aufnahmemodus
      if OverwriteRadioButton.Checked = True
        then begin

           if WaveStream.Size > 0
            then begin
                // alte Aufnahme löschen
                BASS_StreamFree(chan);
                WaveStream.Clear;
             end; // if
        end
      else if InsertRadioButton.Checked = True
              then begin
                WaveStream.Position := ProgressBar.Position;

              end
      else if EndRadioButton.Checked = True
              then begin
                WaveStream.Position := WaveStream.Size;
                ProgressBar.Position := ProgressBar.Max;
              end; // if

         // Header für WAV-File generieren
       with WaveHdr do
        begin
            riff := 'RIFF';
            len := 36;
            cWavFmt := 'WAVEfmt ';
            dwHdrLen := 16;
            wFormat := 1;
            wNumChannels := 2;
            dwSampleRate := 44100;
            wBlockAlign := 4;
            dwBytesPerSec := 176400;
            wBitsPerSample := 16;
            cData := 'data';
            dwDataLen := 0;
        end; // with

         WaveStream.Write(WaveHdr, SizeOf(WAVHDR));
         i := 0;


        vol := RecordPegelBar.Position/100;
         while BASS_RecordSetInput(i, BASS_INPUT_OFF, vol)
          do i := i + 1;


          // ---LoWord-- ----HiWord----
        Flag := MakeLong(c16BitAudio, cRecordingTime);
           // Aufnahmebeginn @ 44100hz 16-bit stereo
         rchan := BASS_RecordStart(cSamplerate,
                                  cNumChannels,
                                  Flag,
                                  @RecordingCallback,
                                  nil);

         if rchan = 0
          then begin
              MessageDlg('Aufnahme konnte nicht gestartet werden!',
                        mtError, [mbOk], 0);
              WaveStream.Clear;
           end;
    end; // procedure StartRecording

  (* Stop recording *)
  procedure TRecordForm.StopRecording;
    var
       i: integer;
    begin
       BASS_ChannelStop(rchan);

         // WAV-Header komplettieren
       WaveStream.Position := 4;
       i := WaveStream.Size - 8;
       WaveStream.Write(i, 4);
       i := i - $24;
       WaveStream.Position := 40;
       WaveStream.Write(i, 4);
       WaveStream.Position := 0;
         // Stream für aufgenomme Daten kreieren
       chan := BASS_StreamCreateFile(True, WaveStream.Memory, 0, WaveStream.Size, 0);

       if chan <> 0
        then begin
          ProgressBar.Max := WaveStream.Size;
          BASS_ChannelSetPosition(chan, ProgressBar.Max, BASS_POS_BYTE);
          ProgressBar.Position := BASS_ChannelGetPosition(chan, BASS_POS_BYTE);
         end
      else begin
          MessageDlg('Fehler beim Erstellen eines Streams aus der Aufnahme!',
                    mtError, [mbOk], 0);
        end; // if
    end; // procedure StopRecording

  (* RecordButtonClick || Start Aufnahme *)
  procedure TRecordForm.RecExecute(Sender: TObject);
    begin
      if BASS_ChannelIsActive(rchan) = BASS_Active_Stopped then // Aufnahme starten
        begin

          if BASS_ChannelIsActive(chan) <> BASS_Active_Stopped then
            begin
              BASS_ChannelStop(chan);
              ProgressBar.Position := ProgressBar.Max;
              StartRecording;
            end
          else
          begin
            ProgressBar.Position := ProgressBar.Max;
            StartRecording;
          end; // if
          ToggleStatus(8);

        end
      else if BASS_ChannelIsActive(rchan) = BASS_Active_Playing then // Aufnahme beenden
        begin
          StopRecording;
          ToggleStatus(3);
      end;
    end; //procedure RecExecute


  (* StopButtonClick || Stop Aufnahme *)
  procedure TRecordForm.StopExecute(Sender: TObject);
    begin
      case BASS_ChannelIsActive(chan) of
        BASS_Active_Stopped:
          begin
            BASS_ChannelSetPosition(chan, 0, BASS_POS_BYTE);
            ProgressBar.Position := BASS_ChannelGetPosition(chan, BASS_POS_BYTE);
            ToggleStatus(3);
          end; // case BASS_Active_Stopped
        BASS_Active_Playing:
          begin
            BASS_ChannelStop(chan);
            BASS_ChannelSetPosition(chan, 0, BASS_POS_BYTE);
            ProgressBar.Position := BASS_ChannelGetPosition(chan, BASS_POS_BYTE);
            ToggleStatus(3);
          end; // case BASS_Active_Playing
        BASS_Active_Paused:
          begin
            BASS_ChannelStop(chan);
            BASS_ChannelSetPosition(chan, 0, BASS_POS_BYTE);
            ProgressBar.Position := BASS_ChannelGetPosition(chan, BASS_POS_BYTE);
            ToggleStatus(3);
          end; // case BASS_Active_Paused
      end; //case
    end; // procedure StopExecute
Franz
  Mit Zitat antworten Zitat