12
{ Values obtained from a C program - These are complex (!) C macros }
13
SNDCTL_DSP_STEREO = -1073459197;
14
SNDCTL_DSP_RESET = 20480;
15
SNDCTL_DSP_SYNC = 20481;
16
SOUND_PCM_WRITE_BITS = -1073459195;
17
SOUND_PCM_WRITE_CHANNELS = -1073459194;
18
SOUND_PCM_WRITE_RATE = -1073459198;
21
SPlaying = 'Playing : ';
22
SErrChannels = 'Error : Number of channels not supported: ';
23
SErrOpeningDevice = 'Could not open sound device';
24
SErrSettingStereo = 'Could not set stereo';
25
SErrResettingDevice = 'Could not reset DSP device';
26
SErrSetWriteBits = 'Could not set write bits to 16';
27
SErrSetChannels = 'Could not set channels';
28
SErrSetSampleRate = 'Could not set sync mode';
29
SErrSetSyncMode = 'Could not set sync mode';
31
Procedure PlayError(Msg : String);
38
Function OpenDSPDevice(Channels,Samplerate : LongInt) : LongInt; forward;
40
procedure PlayFile(FileName : String);
43
Buffer : Array[0..BUFFERLEN-1] of word;
46
k, m, AudioDevice, readcount : Longint;
50
Writeln(SPlaying,FileName);
51
SoundFile:=sf_open_read(pChar(FileName),@Info);
52
If (SoundFile=Nil) then
57
If not (Info.Channels in [1,2]) then
58
PlayError(SerrChannels);
59
AudioDevice:=OpenDSPDevice(Info.channels, Info.samplerate);
60
ScaleData:=(Info.pcmbitwidth < 16);
61
readcount:=sf_read_short(SoundFile,@Buffer,BUFFERLEN);
65
For m:=0 to BufferLen-1 do
66
Buffer[m]:=buffer[m] * 256;
67
fdwrite (AudioDevice, buffer, readcount * sizeof (word)) ;
68
readcount:=sf_read_short(SoundFile,@Buffer,BUFFERLEN);
70
sf_close (Soundfile) ;
71
fdclose (AudioDevice) ;
74
Function OpenDSPDevice (channels,SampleRate : LongInt) : Longint;
77
fd, stereo, temp, error : longint ;
80
fd:=fdOpen('/dev/dsp',OPEN_WRONLY,0);
82
PlayError(SErrOpeningDevice);
84
if Not ioctl(fd, SNDCTL_DSP_STEREO , @stereo) then
85
PlayError(SErrSettingStereo);
86
if Not ioctl (fd, SNDCTL_DSP_RESET, Nil) then
87
PlayError(SErrResettingDevice);
89
If not ioctl (fd, SOUND_PCM_WRITE_BITS, @temp) then
90
PlayError(SErrSetWriteBits);
91
If not ioctl (fd, SOUND_PCM_WRITE_CHANNELS, @channels) then
92
PlayError(SErrSetChannels);
93
If Not ioctl (fd, SOUND_PCM_WRITE_RATE, @SampleRate) then
94
PlayError(SErrSetSampleRate);
95
If not ioctl (fd, SNDCTL_DSP_SYNC, Nil) then
96
PlayError(SErrSetSyncMode);
104
For I:=1 to ParamCount do
105
PlayFile(Paramstr(i));