summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/libogcfpc/src/asndlib.pp
blob: ca36d43a85e2795928f475c79987897a6b6ed98f (plain)
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
152
unit asndlib;
{$mode objfpc} 
{$J+}
{$INLINE ON}
{$MACRO ON}
{$PACKRECORDS C}
{$ASSERTIONS ON}

interface

uses
  ctypes, gctypes;

const
  ASND_LIB = $100;
  SND_LIB = ( ASND_LIB + 2 );
  SND_OK = 0;
  SND_INVALID = - 1;
  SND_ISNOTASONGVOICE = - 2;
  SND_BUSY = 1;
  SND_UNUSED = 0;  (*!< This voice is available for use.  *)
  SND_WORKING = 1;  (*!< This voice is currently in progress.  *)
  SND_WAITING = 2;  (*!< This voice is currently in progress and waiting to one SND_AddVoice() function (the voice handler is called continuously)  *)

  VOICE_MONO_8BIT       = 0;
  VOICE_MONO_16BIT      = 1;
  VOICE_MONO_16BIT_BE   = 1;
  VOICE_STEREO_8BIT     = 2;
  VOICE_STEREO_16BIT    = 3;
  VOICE_STEREO_16BIT_BE = 3;
  VOICE_MONO_8BIT_U     = 4;
  VOICE_MONO_16BIT_LE   = 5;
  VOICE_STEREO_8BIT_U   = 6;
  VOICE_STEREO_16BIT_LE = 7;

  MIN_VOLUME = 0;
  MID_VOLUME = 127;
  MAX_VOLUME = 255;
  MIN_PITCH = 1;  (*!< 1Hz  *)
  F44100HZ_PITCH = 44100;  (*!< 44100Hz  *)
  MAX_PITCH = 144000;  (*!< 144000Hz (more process time for pitch>48000)  *)

  NOTE_DO = 0;
  NOTE_DOs = 1;
  NOTE_REb = NOTE_DOs;
  NOTE_RE = NOTE_REb + 1;
  NOTE_REs = NOTE_RE + 1;
  NOTE_MIb = NOTE_REs;
  NOTE_MI = NOTE_MIb + 1;
  NOTE_FA = NOTE_MI + 1;
  NOTE_FAs = NOTE_FA + 1;
  NOTE_SOLb = NOTE_FAs;
  NOTE_SOL = NOTE_SOLb + 1;
  NOTE_SOLs = NOTE_SOL + 1;
  NOTE_LAb = NOTE_SOLs;
  NOTE_LA = NOTE_LAb + 1;
  NOTE_LAs = NOTE_LA + 1;
  NOTE_SIb = NOTE_LAs;
  NOTE_SI = NOTE_SIb + 1;

  NOTE_C = 0;
  NOTE_Cs = 1;
  NOTE_Db = NOTE_Cs;
  NOTE_D = NOTE_Db + 1;
  NOTE_Ds = NOTE_D + 1;
  NOTE_Eb = NOTE_Ds;
  NOTE_E = NOTE_Eb + 1;
  NOTE_F = NOTE_E + 1;
  NOTE_Fs = NOTE_F + 1;
  NOTE_Gb = NOTE_Fs;
  NOTE_G = NOTE_Gb + 1;
  NOTE_Gs = NOTE_G + 1;
  NOTE_Ab = NOTE_Gs;
  NOTE_A = NOTE_Ab + 1;
  NOTE_As = NOTE_A + 1;
  NOTE_Bb = NOTE_As;
  NOTE_B = NOTE_Bb + 1;


function _NOTE(note, octave: cint): cint; inline;

{$define Note2Freq               := ANote2Freq}
{$define SND_Init                := ASND_Init}
{$define SND_End                 := ASND_End}
{$define SND_Pause               := ASND_Pause}
{$define SND_Is_Paused           := ASND_Is_Paused}
{$define SND_GetTime             := ASND_GetTime}
{$define SND_GetSampleCounter    := ASND_GetSampleCounter}
{$define SND_GetSamplesPerTick   := ASND_GetSamplesPerTick}
{$define SND_SetTime             := ASND_SetTime}
{$define SND_SetCallback         := ASND_SetCallback}
{$define SND_GetAudioRate        := ASND_GetAudioRate}
{$define SND_SetVoice            := ASND_SetVoice}
{$define SND_AddVoice            := ASND_AddVoice}
{$define SND_StopVoice           := ASND_StopVoice}
{$define SND_PauseVoice          := ASND_PauseVoice}
{$define SND_StatusVoice         := ASND_StatusVoice}
{$define SND_GetFirstUnusedVoice := ASND_GetFirstUnusedVoice}
{$define SND_ChangePitchVoice    := ASND_ChangePitchVoice}
{$define SND_ChangeVolumeVoice   := ASND_ChangeVolumeVoice}
{$define SND_ChangeVolumeVoice   := ASND_ChangeVolumeVoice}
{$define SND_GetTickCounterVoice := ASND_GetTickCounterVoice}
{$define SND_GetTimerVoice       := ASND_GetTimerVoice}
{$define SND_TestPointer         := ASND_TestPointer}



type
  ASNDVoiceCallback = procedure(voice: cint32); cdecl;

function ANote2Freq(note, freq_base, note_base: cint): cint; cdecl; external;
procedure ASND_Init; cdecl; external;
procedure ASND_End; cdecl; external;
procedure ASND_Pause(paused: cint32); cdecl; external;
function ASND_Is_Paused: cint32; cdecl; external;
function ASND_GetTime: cuint32; cdecl; external;
function ASND_GetSampleCounter: cuint32; cdecl; external;
function ASND_GetSamplesPerTick: cuint32; cdecl; external;
procedure ASND_SetTime(time: cuint32); cdecl; external;

type
  TAuxCallback0 = procedure; cdecl;
procedure ASND_SetCallback(callback: TAuxCallback0); cdecl; external;
function ASND_GetAudioRate: cint32; cdecl; external;
function ASND_SetVoice(voice, format, pitch, delay: cint32; snd: pointer; size_snd, volume_l, volume_r: cint32; callback: ASNDVoiceCallback): cint32; cdecl; external;
function ASND_SetInfiniteVoice(voice, format, pitch, delay: cint32; snd: pointer; size_snd, volume_l, volume_r: cint32): cint32; cdecl; external;
function ASND_AddVoice(voice: cint32; snd: pointer; size_snd: cint32): cint32; cdecl; external;
function ASND_StopVoice(voice: cint32): cint32; cdecl; external;
function ASND_PauseVoice(voice, pause: cint32): cint32; cdecl; external;
function ASND_StatusVoice(voice: cint32): cint32; cdecl; external;
function ASND_GetFirstUnusedVoice: cint32; cdecl; external;
function ASND_ChangePitchVoice(voice, pitch: cint32): cint32; cdecl; external;
function ASND_ChangeVolumeVoice(voice, volume_l, volume_r: cint32): cint32; cdecl; external;
function ASND_GetTickCounterVoice(voice: cint32): cuint32; cdecl; external;
function ASND_GetTimerVoice(voice: cint32): cuint32; cdecl; external;
function ASND_TestPointer(voice: cint32; pointer: pointer): cint32; cdecl; external;
function ASND_TestVoiceBufferReady(voice: cint32): cint32; cdecl; external;
function ASND_GetDSP_PercentUse: cuint32; cdecl; external;
function ASND_GetDSP_ProcessTime: cuint32; cdecl; external;

implementation

function _NOTE(note, octave: cint): cint; inline;
begin
  _NOTE := note + (octave shl 3) + (octave shl 2);
end;

initialization

{$linklib asnd}

end.