aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/Classes/UAudioCore_Bass.pas
blob: 1d045b88d06d9b8ecd131ed8006573d45aeed331 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
unit UAudioCore_Bass;

interface

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}

{$I switches.inc}

uses
  Classes,
  SysUtils,
  UMusic,
  bass;     // (Note: DWORD is defined here)

type
  TAudioCore_Bass = class
    private
      constructor Create();
    public
      class function GetInstance(): TAudioCore_Bass;
      function ErrorGetString(): string; overload;
      function ErrorGetString(errCode: integer): string; overload;
      function ConvertAudioFormatToBASSFlags(Format: TAudioSampleFormat; out Flags: DWORD): boolean;
  end;


implementation

uses
  UMain,
  ULog;

var
  Instance: TAudioCore_Bass;

constructor TAudioCore_Bass.Create();
begin
  inherited;
end;

class function TAudioCore_Bass.GetInstance(): TAudioCore_Bass;
begin
  if not assigned(Instance) then
    Instance := TAudioCore_Bass.Create();
  Result := Instance;
end;

function TAudioCore_Bass.ErrorGetString(): string;
begin
  Result := ErrorGetString(BASS_ErrorGetCode());
end;

function TAudioCore_Bass.ErrorGetString(errCode: integer): string;
begin
  case errCode of
    BASS_OK:
      result := 'No error';
    BASS_ERROR_MEM:
      result := 'Insufficient memory';
    BASS_ERROR_FILEOPEN:
      result := 'File could not be opened';
    BASS_ERROR_DRIVER:
      result := 'Device driver not available';
    BASS_ERROR_BUFLOST:
      result := 'Buffer lost';
    BASS_ERROR_HANDLE:
      result := 'Invalid Handle';
    BASS_ERROR_FORMAT:
      result := 'Sample-Format not supported';
    BASS_ERROR_POSITION:
      result := 'Illegal position';
    BASS_ERROR_INIT:
      result := 'BASS_Init has not been successfully called';
    BASS_ERROR_START:
      result := 'Paused/stopped';
    BASS_ERROR_ALREADY:
      result := 'Already created/used';
    BASS_ERROR_NOCHAN:
      result := 'No free channels';
    BASS_ERROR_ILLTYPE:
      result := 'Type is invalid';
    BASS_ERROR_ILLPARAM:
      result := 'Illegal parameter';
    BASS_ERROR_NO3D:
      result := 'No 3D support';
    BASS_ERROR_NOEAX:
      result := 'No EAX support';
    BASS_ERROR_DEVICE:
      result := 'Invalid device number';
    BASS_ERROR_NOPLAY:
      result := 'Channel not playing';
    BASS_ERROR_FREQ:
      result := 'Freq out of range';
    BASS_ERROR_NOTFILE:
      result := 'Not a file stream';
    BASS_ERROR_NOHW:
      result := 'No hardware support';
    BASS_ERROR_EMPTY:
      result := 'Is empty';
    BASS_ERROR_NONET:
      result := 'Network unavailable';
    BASS_ERROR_CREATE:
      result := 'Creation error';
    BASS_ERROR_NOFX:
      result := 'DX8 effects unavailable';
    BASS_ERROR_NOTAVAIL:
      result := 'Not available';
    BASS_ERROR_DECODE:
      result := 'Is a decoding channel';
    BASS_ERROR_DX:
      result := 'Insufficient version of DirectX';
    BASS_ERROR_TIMEOUT:
      result := 'Timeout';
    BASS_ERROR_FILEFORM:
      result := 'File-Format not recognised/supported';
    BASS_ERROR_SPEAKER:
      result := 'Requested speaker(s) not support';
    BASS_ERROR_VERSION:
      result := 'Version error';
    BASS_ERROR_CODEC:
      result := 'Codec not available/supported';
    BASS_ERROR_ENDED:
      result := 'The channel/file has ended';
    BASS_ERROR_UNKNOWN:
      result := 'Unknown error';
    else
      result := 'Unknown error';
    end;
end;

function TAudioCore_Bass.ConvertAudioFormatToBASSFlags(Format: TAudioSampleFormat; out Flags: DWORD): boolean;
begin
  case Format of
    asfS16:
      Flags := 0;
    asfFloat:
      Flags := BASS_SAMPLE_FLOAT;
    asfU8:
      Flags := BASS_SAMPLE_8BITS;
    else begin
      Result := false;
      Exit;
    end;
  end;

  Result := true;
end;

end.