Hier meine Version aus einem Programm:
Delphi-Quellcode:
type
WAVHDR = packed record
riff: array[0..3] of AnsiChar;
len: DWord;
cWavFmt: array[0..7] of AnsiChar;
dwHdrLen: DWord;
wFormat: Word;
wNumChannels: Word;
dwSampleRate: DWord;
dwBytesPerSec: DWord;
wBlockAlign: Word;
wBitsPerSample: Word;
cData: array[0..3] of AnsiChar;
dwDataLen: DWord;
end;
...
type
TfmNetRadio = class(TForm)
...
WaveStream : TFileStream;
...
end;
...
var
WaveHdr : WAVHDR; // WAV-Header
chan : HSTREAM = 0; // Wiedergabekanal
rchan : HRECORD; // Aufnahmekanal
...
procedure TfmNetRadio.acRecordExecute(Sender: TObject);
var
sFile : String;
dName : PAnsiChar;
level : Single;
i : Integer;
begin
acRecord.Checked := Not acRecord.Checked;
tmRecord.Enabled := acRecord.Checked;
if acRecord.Checked then begin
// Dateinamen aus Tagesdatum und Uhrzeit erstellen lassen.
sFile := '.\Record\' + GetNowAsFileName;
WaveStream := TFileStream.Create(sFile + '.wav', fmCreate);
dName := BASS_RecordGetInputName(0);
// generate header for WAV file
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;
WaveStream.Write(WaveHdr, SizeOf(WAVHDR));
// start recording @ 44100hz 16-bit stereo
rchan := BASS_RecordStart(44100, 2, 0, @RecordingCallback, nil);
if rchan = 0 then begin
MessageDlg('Die Aufnahme konnte nicht begonnen werden.', mtError, [mbOk], 0);
WaveStream.Free;
acRecord.Checked := False;
end;
end else begin
BASS_ChannelStop(rchan);
// complete the WAV header
WaveStream.Position := 4;
i := WaveStream.Size - 8;
WaveStream.Write(i, 4);
i := i - $24;
WaveStream.Position := 40;
WaveStream.Write(i, 4);
WaveStream.Position := 0;
WaveStream.Free;
end;
tmRecord.Enabled := acRecord.Checked;
end;
Die oben genutzte Callbackfunktion:
Delphi-Quellcode:
(* This is called while recording audio *)
function RecordingCallback(
Handle: HRECORD; buffer: Pointer; length : DWord; user: Pointer): boolean;
stdcall;
begin
// Copy new buffer contents to the memory buffer
fmNetRadio.WaveStream.
Write(buffer^, length);
// Allow recording to continue
Result := True;
end;
Es werden WAV-Dateien erstellt, die ich nachher mit "Get it on CD" schneiden kann, um sie dann auf Audio-CD zu brennen.