Einzelnen Beitrag anzeigen

Wishmaster

Registriert seit: 14. Sep 2002
Ort: Steinbach, MB, Canada
301 Beiträge
 
Delphi XE2 Architect
 
#9

Re: bass.dll - stereo zu mono

  Alt 15. Okt 2009, 06:00
Hi

du kannst es mal mit DSP versuchen. BASS_ChannelSetDSP, BASS_ChannelRemoveDSP.


Zitat:
A panning DSP function for a stereo 16-bit channel (useful when using speaker assignment).
float pan; // panning position, set as you would the BASS_ATTRIB_PAN attribute
C++
Code:
void CALLBACK PanDSP(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user)
{
    short *s=buffer;
    if (!pan) return; // no processing neeeded for centre panning
    for (; length; length-=4, s+=2) {
        if (pan<0) s[1]=s[1]*(1+pan); // pan left = reduce right
        else s[0]=s[0]*(1-pan); // vice versa
    }
}
Pan goes from -100..100 Delphi
16 Bit

Delphi-Quellcode:
type
* TPanRec16 = array[0..1] of SmallInt;
* PPanRec16 = ^TPanRec16;
procedure PanDSPProc16(handle: HDSP; channel: DWORD; buffer: Pointer; length: DWORD; user: DWORD);
* stdcall;
var
* P: PPanRec16;
begin
* P := buffer;
* while ((length div 4) > 0) do
* begin
* * if (Pan < 0) then
* * begin
* * * P[1] := round(P[1] * (100 + pan) / 100); // pan left = reduce right
* * end
* * else if (Pan > 0) then
* * begin
* * * P[0] := round(P[0] * (100 - pan) / 100); // vice versa
* * end;
* * inc(P);
* * length := length - 4;
* end;
end;
32 Bit

Delphi-Quellcode:
type
* TPanRec32 = array[0..1] of Single;
* PPanRec32 = ^TPanRec32;
procedure PanDSPProc32(handle: HDSP; channel: DWORD; buffer: Pointer; length: DWORD; user: DWORD);
* stdcall;
var
* P: PPanRec32;
* a:DWORD;
begin
* P := buffer;
* a := 0;
* while (a < (length div 4)) do
* begin
* * if (Pan < 0) then
* * begin
* * * P[1] := P[1] * (1.0 + (pan/100)) / 1.0; // pan left = reduce right
* * end
* * else if (Pan > 0) then
* * begin
* * * P[0] := P[0] * (1.0 - (pan/100)) / 1.0; // vice versa
* * end;
* * Inc(P);
* * a := a + 2;
* end;
end;

hint

Delphi-Quellcode:
procedure ConvertMonoToStereo16(InOutBuf : PbyteArray; InSize : Integer; Mode : integer);
* var
* * i : Integer;
* begin
* * case Mode of
* * * 1://msmMonoToBoth :
* * * for i := (Insize shr 1) - 1 downto 0 do
* * * begin
* * * * InOutBuf[i shl 1] := InOutBuf[i];
* * * * InOutBuf[(i shl 1)+1] := InOutBuf[i];
* * * end;
* * * 2://msmMonoToLeft :
* * * for i := (Insize shr 1) - 1 downto 0 do
* * * begin
* * * * InOutBuf[i shl 1] := 0;
* * * * InOutBuf[(i shl 1)+1] := InOutBuf[i];
* * * end;
* * * 3://msmMonoToRight :
* * * for i := (Insize shr 1) - 1 downto 0 do
* * * begin
* * * * InOutBuf[i shl 1] := InOutBuf[i];
* * * * InOutBuf[(i shl 1)+1] := 0;
* * * end;
* * end;
* end;

//BASS_ChannelGetData(chan, @buf, BytesRead);
ConvertMonoToStereo16(@buf, bytesread*2, 1);
//RecStream.Write(buf, BytesRead*2);
  Mit Zitat antworten Zitat