Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   BASS Library - Delphi Snippet source code (https://www.clubdelphi.com/foros/showthread.php?t=96859)

navbuoy 27-09-2024 21:34:01

BASS Library - Delphi Snippet source code
 
Aqui os dejo un codigo fuente de Delphi que podria veniros bien para manejo de la BASS Library

Código:

function BASS_ErrorToString(BASS_ErrorCode : Integer) : String;

begin

 case BASS_ErrorCode of :
  0: Result := 'BASS_OK';
  1: Result := 'BASS_ERROR_MEM';
  2: Result := 'BASS_ERROR_FILEOPEN';
  3: Result := 'BASS_ERROR_DRIVER';
  4: Result := 'BASS_ERROR_BUFLOST';
  5: Result := 'BASS_ERROR_HANDLE';
  6: Result := 'BASS_ERROR_FORMAT';
  7: Result := 'BASS_ERROR_POSITION';
  8: Result := 'BASS_ERROR_INIT';
  9: Result := 'BASS_ERROR_START';
  14: Result := 'BASS_ERROR_ALREADY';
  18: Result := 'BASS_ERROR_NOCHAN';
  19: Result := 'BASS_ERROR_ILLTYPE';
  20: Result := 'BASS_ERROR_ILLPARAM';
  21: Result := 'BASS_ERROR_NO3D';
  22: Result := 'BASS_ERROR_NOEAX';
  23: Result := 'BASS_ERROR_DEVICE';
  24: Result := 'BASS_ERROR_NOPLAY';
  25: Result := 'BASS_ERROR_FREQ';
  27: Result := 'BASS_ERROR_NOTFILE';
  29: Result := 'BASS_ERROR_NOHW';
  31: Result := 'BASS_ERROR_EMPTY';
  32: Result := 'BASS_ERROR_NONET';
  33: Result := 'BASS_ERROR_CREATE';
  34: Result := 'BASS_ERROR_NOFX';
  37: Result := 'BASS_ERROR_NOTAVAIL';
  38: Result := 'BASS_ERROR_DECODE';
  39: Result := 'BASS_ERROR_DX';
  40: Result := 'BASS_ERROR_TIMEOUT';
  41: Result := 'BASS_ERROR_FILEFORM';
  42: Result := 'BASS_ERROR_SPEAKER';
  43: Result := 'BASS_ERROR_VERSION';
  44: Result := 'BASS_ERROR_CODEC';
  45: Result := 'BASS_ERROR_ENDED';
  46: Result := 'BASS_ERROR_BUSY';
 else
  Result := 'BASS_ERROR_UNKNOWN';
 end;
end;

procedure BassResultCheck(ResultCode : Integer);
begin
 if ResultCode = 0 then
  begin
  ResultCode := BASS_ErrorGetCode;
  raise Exception.CreateFmt('BASS error : %s(%d)', [BASS_ErrorToString(ResultCode), ResultCode]);
  end;
end;

procedure BassBoolCheck(const BoolResult : Boolean);
begin
 BassResultCheck(Integer(BoolResult));
end;

procedure PlaySample(const SampleFilename : String);

var
  Sample : HSAMPLE;
  Channel: HCHANNEL;


begin
 if not Dynamic_Bass.Load_BASSDLL('Library/Bass.dll') then
  raise Exception.Create('Could not load BASS DLL');
 // change device to -1 which is the default device
 BassBoolCheck(Dynamic_Bass.BASS_Init(-1,44000,Bass_DEVICE_SPEAKERS,0,nil);
 Sample := BASS_SampleLoad(FALSE, PChar(SampleFilename), 0, 0, 3, BASS_SAMPLE_OVER_POS OR BASS_UNICODE);
 BassResultCheck(Sample);
 Channel := BASS_SampleGetChannel(Sample, False);
 BassResultCheck(Channel);
 BassBoolCheck(BASS_ChannelPlay(Channel, False));
end;


navbuoy 05-10-2024 15:58:17

otra cosilla es el tema de controlar el volumen del stream o Channel

con un TrackBar podemos hacerlo, editamos su evento OnChange y:

C++Builder:

Código:

void __fastcall TForm1::sTrackBar1Change(TObject *Sender)
{
  // Invertir el valor del TrackBar (esto es para que el maximo volumen quede a la derecha si el TrackBar->Orientation = Horizontal)
        int valorInvertido = sTrackBar1->Max - sTrackBar1->Position;

        int volumen = 100 - valorInvertido;
        BASS_ChannelSetAttribute(stream, BASS_ATTRIB_VOL, 0.01 * volumen);
}

Delphi:

Código:

procedure TForm1.sTrackBar1Change(Sender: TObject);
var
  valorInvertido: Integer;
  volumen: Integer;
begin
  // Invertir el valor del TrackBar
  valorInvertido := sTrackBar1.Max - sTrackBar1.Position;

  volumen := 100 - valorInvertido;
  BASS_ChannelSetAttribute(stream, BASS_ATTRIB_VOL, 0.01 * volumen);
end;



La franja horaria es GMT +2. Ahora son las 18:29:46.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi