|
@@ -3,7 +3,7 @@ program sfplay;
|
|
|
{$mode objfpc}
|
|
|
{$h+}
|
|
|
|
|
|
-uses sndfile,linux;
|
|
|
+uses sndfile, baseunix;
|
|
|
|
|
|
Const
|
|
|
BUFFERLEN = 1024;
|
|
@@ -29,7 +29,6 @@ ResourceString
|
|
|
SErrSetSyncMode = 'Could not set sync mode';
|
|
|
|
|
|
Procedure PlayError(Msg : String);
|
|
|
-
|
|
|
begin
|
|
|
Writeln(stderr,Msg);
|
|
|
Halt(1);
|
|
@@ -38,68 +37,64 @@ end;
|
|
|
Function OpenDSPDevice(Channels,Samplerate : LongInt) : LongInt; forward;
|
|
|
|
|
|
procedure PlayFile(FileName : String);
|
|
|
-
|
|
|
-Var
|
|
|
- Buffer : Array[0..BUFFERLEN-1] of word;
|
|
|
- SoundFile : PSndFile;
|
|
|
- Info : SF_INFO;
|
|
|
- k, m, AudioDevice, readcount : Longint;
|
|
|
- ScaleData : Boolean;
|
|
|
-
|
|
|
+var
|
|
|
+ Buffer: Array[0..BUFFERLEN-1] of word;
|
|
|
+ SoundFile: PSndFile;
|
|
|
+ Info: TSF_INFO;
|
|
|
+ k, m, AudioDevice, readcount: Longint;
|
|
|
+ ScaleData: Boolean;
|
|
|
begin
|
|
|
Writeln(SPlaying,FileName);
|
|
|
- SoundFile:=sf_open_read(pChar(FileName),@Info);
|
|
|
+ SoundFile:=sf_open(pChar(FileName), SFM_READ, @Info);
|
|
|
If (SoundFile=Nil) then
|
|
|
begin
|
|
|
- sf_perror(Nil);
|
|
|
- exit;
|
|
|
+ sf_perror(Nil);
|
|
|
+ exit;
|
|
|
end;
|
|
|
If not (Info.Channels in [1,2]) then
|
|
|
PlayError(SerrChannels);
|
|
|
AudioDevice:=OpenDSPDevice(Info.channels, Info.samplerate);
|
|
|
- ScaleData:=(Info.pcmbitwidth < 16);
|
|
|
+ ScaleData:=(Info.samplerate < 16);
|
|
|
readcount:=sf_read_short(SoundFile,@Buffer,BUFFERLEN);
|
|
|
While ReadCount<>0 do
|
|
|
begin
|
|
|
- If ScaleData then
|
|
|
- For m:=0 to BufferLen-1 do
|
|
|
- Buffer[m]:=buffer[m] * 256;
|
|
|
- fdwrite (AudioDevice, buffer, readcount * sizeof (word)) ;
|
|
|
- readcount:=sf_read_short(SoundFile,@Buffer,BUFFERLEN);
|
|
|
+ If ScaleData then
|
|
|
+ For m:=0 to BufferLen-1 do
|
|
|
+ Buffer[m]:=buffer[m] * 256;
|
|
|
+ FpWrite(AudioDevice, buffer, readcount * sizeof (word)) ;
|
|
|
+ readcount:=sf_read_short(SoundFile,@Buffer,BUFFERLEN);
|
|
|
end;
|
|
|
sf_close (Soundfile) ;
|
|
|
- fdclose (AudioDevice) ;
|
|
|
+ FpClose(AudioDevice) ;
|
|
|
end;
|
|
|
|
|
|
Function OpenDSPDevice (channels,SampleRate : LongInt) : Longint;
|
|
|
-
|
|
|
var
|
|
|
fd, stereo, temp, error : longint ;
|
|
|
-
|
|
|
begin
|
|
|
- fd:=fdOpen('/dev/dsp',OPEN_WRONLY,0);
|
|
|
+ fd:=fpOpen('/dev/dsp',O_WRONLY,0);
|
|
|
if fd<0 then
|
|
|
PlayError(SErrOpeningDevice);
|
|
|
Stereo:=0;
|
|
|
- if Not ioctl(fd, SNDCTL_DSP_STEREO , @stereo) then
|
|
|
+ if Not (FpIOCtl(fd, SNDCTL_DSP_STEREO , @stereo) <> -1) then
|
|
|
PlayError(SErrSettingStereo);
|
|
|
- if Not ioctl (fd, SNDCTL_DSP_RESET, Nil) then
|
|
|
+ if Not (FpIOCtl(fd, SNDCTL_DSP_RESET, Nil) <> -1) then
|
|
|
PlayError(SErrResettingDevice);
|
|
|
temp := 16 ;
|
|
|
- If not ioctl (fd, SOUND_PCM_WRITE_BITS, @temp) then
|
|
|
+ If not (FpIOCtl(fd, SOUND_PCM_WRITE_BITS, @temp) <> -1) then
|
|
|
PlayError(SErrSetWriteBits);
|
|
|
- If not ioctl (fd, SOUND_PCM_WRITE_CHANNELS, @channels) then
|
|
|
+ If not (FpIOCtl(fd, SOUND_PCM_WRITE_CHANNELS, @channels) <> -1) then
|
|
|
PlayError(SErrSetChannels);
|
|
|
- If Not ioctl (fd, SOUND_PCM_WRITE_RATE, @SampleRate) then
|
|
|
+ If Not (FpIOCtl(fd, SOUND_PCM_WRITE_RATE, @SampleRate) <> -1) then
|
|
|
PlayError(SErrSetSampleRate);
|
|
|
- If not ioctl (fd, SNDCTL_DSP_SYNC, Nil) then
|
|
|
+ If not (FpIOCtl(fd, SNDCTL_DSP_SYNC, Nil) <> -1) then
|
|
|
PlayError(SErrSetSyncMode);
|
|
|
OpenDSPDevice:=Fd;
|
|
|
end;
|
|
|
|
|
|
+
|
|
|
Var
|
|
|
I : Integer;
|
|
|
-
|
|
|
begin
|
|
|
For I:=1 to ParamCount do
|
|
|
PlayFile(Paramstr(i));
|