diff --git a/packages/sndfile/examples/sfplay.pp b/packages/sndfile/examples/sfplay.pp index 983a7e421e..83ae3a2b85 100644 --- a/packages/sndfile/examples/sfplay.pp +++ b/packages/sndfile/examples/sfplay.pp @@ -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)); diff --git a/packages/sndfile/src/sndfile.pp b/packages/sndfile/src/sndfile.pp index ea62f0e968..f5133a2b72 100644 --- a/packages/sndfile/src/sndfile.pp +++ b/packages/sndfile/src/sndfile.pp @@ -255,6 +255,7 @@ type TSF_INFO = record frames : Tsf_count_t; // Used to be called samples. Changed to avoid confusion. samplerate : ctypes.cint; + channels : ctypes.cint; format : ctypes.cint; sections : ctypes.cint; seekable : ctypes.cint; @@ -409,7 +410,7 @@ type ** to sf_perror () or sf_error_str (). ** All calls to sf_open() should be matched with a call to sf_close(). } -function sf_open (path : ctypes.pcchar; mode : ctypes.cint; sfinfo : PSF_INFO) : PSNDFILE; cdecl; +function sf_open (path : pChar; mode : ctypes.cint; sfinfo : PSF_INFO) : PSNDFILE; cdecl; external sndfilelib name 'sf_open'; {