DSP recording

Interface

Procedure WMDSPAckRead(var Msg: TRMDMAAckRead); Message RM_DSPACKREAD;
Procedure Init;
Procedure Close;
...

Implementation

var
  Closing         : Boolean;
  Buffers         : Integer;
  hRadio          : Integer;
  DSPInBlockSize  : Integer;
  Wnd             : HWND;

Procedure WMDSPAckRead(var Msg: TRMDMAAckRead);
begin
  {inform API that the buffer has been received}
  dspBufferDone(Msg.hRadio, Msg.lpDSPHdr, SizeOf(TDSPHdr));
  ...
  {here comes the data handling routine}
  ...
  if (Closing = True)
  then begin
    Buffers := Buffers - 1;
    FreeMem(Msg.lpDSPHdr^.lpData);
    Dispose(Msg.lpDSPHdr);
  end
  else begin
    {send the buffer back to DSP}
    dspInAddBuffer(Msg.hRadio, Msg.lpDSPHdr, SizeOf(TDSPHdr));
  end;
end;

Procedure Init;
var
  i   : Integer;
  dh  : PDSPHdr;
  
begin
  Closing := False;
  Buffers := 0;

  Wnd := {create window};

  hRadio := OpenRadioDevice(0);
  if (hRadio = 0) then
    Exit;

  DSPInBlockSize := dspInOpen(hRadio, RWF_8kHz or RWF_16bit or RWF_Mono, Wnd);
  if (DSPInBlockSize = 0) then
    Exit;

  for i:=1 to 10 do
  begin
    New(dh);
    dh^.dwBufferLength := DSPInBlockSize;
    GetMem(Pointer(dh^.lpData), DSPInBlockSize);
    if (dspInAddBuffer(hRadio, dh, SizeOf(TDSPHdr)) = True) then
      Buffers := Buffers + 1;
  end;
end;

Procedure Close;
begin
  Closing := True;	

  repeat
    {process messages}
  until (Buffers = 0);

  dspClose(hRadio);
  CloseRadioDevice(hRadio);
end;

 

DSP playback

Interface

Procedure WMDSPAckWrite(var Msg: TRMDMAAckWrite); Message RM_DSPACKWRITE;
Procedure Init;
Procedure Close;
...

Implementation

var
  Closing          : Boolean;
  Buffers          : Integer;
  hRadio           : Integer;
  DSPOutBlockSize  : Integer;
  Wnd              : HWND;

Procedure WMDSPAckWrite(var Msg: TRMDMAAckWrite);
begin
  {inform API that the buffer has been received}
  dspBufferDone(Msg.hRadio, Msg.lpDSPHdr, SizeOf(TDSPHdr))

  if (Closing = True)
  then begin
    Buffers := Buffers - 1;
    FreeMem(Msg.lpDSPHdr^.lpData);
    Dispose(Msg.lpDSPHdr);
  end
  else begin
    {fill the buffer with next audio data and send it back to DSP}
    ...
    dspOutWrite(Msg.hRadio, Msg.lpDSPHdr, SizeOf(TDSPHdr));
  end;
end;

Procedure Init;
var
  i   : Integer;
  dh  : PDSPHdr;
  
begin
  Closing := False;
  Buffers := 0;

  Wnd := {create window};

  hRadio := OpenRadioDevice(0);
  if (hRadio = 0) then
    Exit;

  DSPOutBlockSize := dspOutOpen(hRadio, RWF_8kHz or RWF_16bit or RWF_Mono, Wnd);
  if (DSPOutBlockSize = 0) then
    Exit;

  for i:=1 to 10 do
  begin
    New(dh);
    dh^.dwBufferLength := DSPOutBlockSize;
    GetMem(Pointer(dh^.lpData), DSPOutBlockSize);
    ...
    {fill the buffer with audio data}
    ...
    if (dspOutWrite(hRadio, dh, SizeOf(TDSPHdr)) = True) then
      Buffers := Buffers + 1;
  end;
end;

Procedure Close;
begin
  Closing := True;	

  repeat
    {process messages}
  until (Buffers = 0);

  dspClose(hRadio);
  CloseRadioDevice(hRadio);
end;