+ initial implementation

This commit is contained in:
michael 2002-05-06 20:19:29 +00:00
parent 682c2289fa
commit 3968683e2a
6 changed files with 1560 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,21 @@
#
# Makefile.fpc for MySql bindings
#
[package]
name=sndfile
version=1.0.6
[target]
units=sndfile
examples=sfplay
rsts=sfplay
[require]
libc=y
[install]
fpcpackage=y
[default]
fpcdir=../../..

View File

@ -0,0 +1,20 @@
This is the README file for the sndfile package.
The sndfile unit contains a straight translation of the sndfile library
header file (version 0.27). It should work exactly as the C header, so for any
API documentation, see the library's documentation.
To work with this unit, you need the sndfile library installed on your
system. (http://www.zip.com.au/~erikd/libsndfile/)
The sfplay program is a rewrite in Pascal of the sfplay.c example that
comes with the sndfile lib documentation. It accepts a list of filenames
on the command-line, and will attempt to play each of the files on the sound
card - provided the sound card is correctly configured.
The testc.c file was used to find out the meaning of some hideous kernel
sound IOCTL macros. Its output was pasted into the program as constants.
Enjoy!
Michael.

View File

@ -0,0 +1,106 @@
program sfplay;
{$mode objfpc}
{$h+}
uses sndfile,linux;
Const
BUFFERLEN = 1024;
Const
{ Values obtained from a C program - These are complex (!) C macros }
SNDCTL_DSP_STEREO = -1073459197;
SNDCTL_DSP_RESET = 20480;
SNDCTL_DSP_SYNC = 20481;
SOUND_PCM_WRITE_BITS = -1073459195;
SOUND_PCM_WRITE_CHANNELS = -1073459194;
SOUND_PCM_WRITE_RATE = -1073459198;
ResourceString
SPlaying = 'Playing : ';
SErrChannels = 'Error : Number of channels not supported: ';
SErrOpeningDevice = 'Could not open sound device';
SErrSettingStereo = 'Could not set stereo';
SErrResettingDevice = 'Could not reset DSP device';
SErrSetWriteBits = 'Could not set write bits to 16';
SErrSetChannels = 'Could not set channels';
SErrSetSampleRate = 'Could not set sync mode';
SErrSetSyncMode = 'Could not set sync mode';
Procedure PlayError(Msg : String);
begin
Writeln(stderr,Msg);
Halt(1);
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;
begin
Writeln(SPlaying,FileName);
SoundFile:=sf_open_read(pChar(FileName),@Info);
If (SoundFile=Nil) then
begin
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);
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);
end;
sf_close (Soundfile) ;
fdclose (AudioDevice) ;
end;
Function OpenDSPDevice (channels,SampleRate : LongInt) : Longint;
var
fd, stereo, temp, error : longint ;
begin
fd:=fdOpen('/dev/dsp',OPEN_WRONLY,0);
if fd<0 then
PlayError(SErrOpeningDevice);
Stereo:=0;
if Not ioctl(fd, SNDCTL_DSP_STEREO , @stereo) then
PlayError(SErrSettingStereo);
if Not ioctl (fd, SNDCTL_DSP_RESET, Nil) then
PlayError(SErrResettingDevice);
temp := 16 ;
If not ioctl (fd, SOUND_PCM_WRITE_BITS, @temp) then
PlayError(SErrSetWriteBits);
If not ioctl (fd, SOUND_PCM_WRITE_CHANNELS, @channels) then
PlayError(SErrSetChannels);
If Not ioctl (fd, SOUND_PCM_WRITE_RATE, @SampleRate) then
PlayError(SErrSetSampleRate);
If not ioctl (fd, SNDCTL_DSP_SYNC, Nil) then
PlayError(SErrSetSyncMode);
OpenDSPDevice:=Fd;
end;
Var
I : Integer;
begin
For I:=1 to ParamCount do
PlayFile(Paramstr(i));
end.

View File

@ -0,0 +1,146 @@
unit sndfile;
interface
{
Automatically converted by H2Pas 0.99.15 from sndfile.h
The following command line parameters were used:
-D
-p
-e
sndfile.h
}
const
External_library='sndfile'; {Setup as you need}
{ Pointers to basic pascal types, inserted by h2pas conversion program.}
Type
PLongint = ^Longint;
PSmallInt = ^SmallInt;
PByte = ^Byte;
PWord = ^Word;
PDWord = ^DWord;
PDouble = ^Double;
size_t = Longint;
{$PACKRECORDS C}
Const
SF_FORMAT_WAV = $10000;
SF_FORMAT_AIFF = $20000;
SF_FORMAT_AU = $30000;
SF_FORMAT_AULE = $40000;
SF_FORMAT_RAW = $50000;
SF_FORMAT_PAF = $60000;
SF_FORMAT_SVX = $70000;
SF_FORMAT_NIST = $80000;
SF_FORMAT_WMA = $90000;
SF_FORMAT_SMPLTD = $A0000;
SF_FORMAT_VOC = $B0000;
SF_FORMAT_SD2 = $C0000;
SF_FORMAT_REX2 = $D0000;
SF_FORMAT_IRCAM = $E0000;
SF_FORMAT_PCM = $0001;
SF_FORMAT_FLOAT = $0002;
SF_FORMAT_ULAW = $0003;
SF_FORMAT_ALAW = $0004;
SF_FORMAT_IMA_ADPCM = $0005;
SF_FORMAT_MS_ADPCM = $0006;
SF_FORMAT_PCM_BE = $0007;
SF_FORMAT_PCM_LE = $0008;
SF_FORMAT_PCM_S8 = $0009;
SF_FORMAT_PCM_U8 = $000A;
SF_FORMAT_SVX_FIB = $000B;
SF_FORMAT_SVX_EXP = $000C;
SF_FORMAT_GSM610 = $000D;
SF_FORMAT_G721_32 = $000E;
SF_FORMAT_G723_24 = $000F;
SF_FORMAT_FLOAT_BE = $0010;
SF_FORMAT_FLOAT_LE = $0011;
SF_FORMAT_SUBMASK = $FFFF;
SF_FORMAT_TYPEMASK = $7FFF0000;
SF_FORMAT_RAW_BE = SF_FORMAT_PCM_BE;
SF_FORMAT_RAW_LE = SF_FORMAT_PCM_LE;
SF_FORMAT_RAW_S8 = SF_FORMAT_PCM_S8;
SF_FORMAT_RAW_U8 = SF_FORMAT_PCM_U8;
type
PSNDFILE = Pointer;
PSF_INFO = ^SF_INFO;
SF_INFO = record
samplerate : dword;
samples : dword;
channels : dword;
pcmbitwidth : dword;
format : dword;
sections : dword;
seekable : dword;
end;
function sf_open_read(path:Pchar; sfinfo:PSF_INFO):PSNDFILE;cdecl;external External_library name 'sf_open_read';
function sf_open_write(path:Pchar; sfinfo:PSF_INFO):PSNDFILE;cdecl;external External_library name 'sf_open_write';
function sf_perror(sndfile:PSNDFILE):longint;cdecl;external External_library name 'sf_perror';
function sf_error_str(sndfile:PSNDFILE; str:Pchar; len:size_t):longint;cdecl;external External_library name 'sf_error_str';
function sf_error_number(errnum:longint; str:Pchar; maxlen:size_t):longint;cdecl;external External_library name 'sf_error_number';
function sf_get_header_info(sndfile:PSNDFILE; buffer:Pchar; bufferlen:size_t; offset:size_t):size_t;cdecl;external External_library name 'sf_get_header_info';
function sf_get_lib_version(buffer:Pchar; bufferlen:size_t):size_t;cdecl;external External_library name 'sf_get_lib_version';
function sf_command(sndfile:PSNDFILE; cmd:Pchar; data:pointer; datasize:longint):longint;cdecl;external External_library name 'sf_command';
function sf_format_check(info:PSF_INFO):longint;cdecl;external External_library name 'sf_format_check';
function sf_signal_max(sndfile:PSNDFILE):double;cdecl;external External_library name 'sf_signal_max';
function sf_seek(sndfile:PSNDFILE; frames:longint; whence:longint):longint;cdecl;external External_library name 'sf_seek';
function sf_read_raw(sndfile:PSNDFILE; ptr:pointer; bytes:size_t):size_t;cdecl;external External_library name 'sf_read_raw';
function sf_write_raw(sndfile:PSNDFILE; ptr:pointer; bytes:size_t):size_t;cdecl;external External_library name 'sf_write_raw';
function sf_readf_short(sndfile:PSNDFILE; ptr:Psmallint; frames:size_t):size_t;cdecl;external External_library name 'sf_readf_short';
function sf_writef_short(sndfile:PSNDFILE; ptr:Psmallint; frames:size_t):size_t;cdecl;external External_library name 'sf_writef_short';
function sf_readf_int(sndfile:PSNDFILE; ptr:Plongint; frames:size_t):size_t;cdecl;external External_library name 'sf_readf_int';
function sf_writef_int(sndfile:PSNDFILE; ptr:Plongint; frames:size_t):size_t;cdecl;external External_library name 'sf_writef_int';
function sf_readf_float(sndfile:PSNDFILE; ptr:Pdouble; frames:size_t):size_t;cdecl;external External_library name 'sf_readf_float';
function sf_writef_float(sndfile:PSNDFILE; ptr:Pdouble; frames:size_t):size_t;cdecl;external External_library name 'sf_writef_float';
function sf_readf_double(sndfile:PSNDFILE; ptr:Pdouble; frames:size_t; normalize:longint):size_t;cdecl;external External_library name 'sf_readf_double';
function sf_writef_double(sndfile:PSNDFILE; ptr:Pdouble; frames:size_t; normalize:longint):size_t;cdecl;external External_library name 'sf_writef_double';
function sf_read_short(sndfile:PSNDFILE; ptr:Psmallint; items:size_t):size_t;cdecl;external External_library name 'sf_read_short';
function sf_write_short(sndfile:PSNDFILE; ptr:Psmallint; items:size_t):size_t;cdecl;external External_library name 'sf_write_short';
function sf_read_int(sndfile:PSNDFILE; ptr:Plongint; items:size_t):size_t;cdecl;external External_library name 'sf_read_int';
function sf_write_int(sndfile:PSNDFILE; ptr:Plongint; items:size_t):size_t;cdecl;external External_library name 'sf_write_int';
function sf_read_float(sndfile:PSNDFILE; ptr:Pdouble; items:size_t):size_t;cdecl;external External_library name 'sf_read_float';
function sf_write_float(sndfile:PSNDFILE; ptr:Pdouble; items:size_t):size_t;cdecl;external External_library name 'sf_write_float';
function sf_read_double(sndfile:PSNDFILE; ptr:Pdouble; items:size_t; normalize:longint):size_t;cdecl;external External_library name 'sf_read_double';
function sf_write_double(sndfile:PSNDFILE; ptr:Pdouble; items:size_t; normalize:longint):size_t;cdecl;external External_library name 'sf_write_double';
function sf_close(sndfile:PSNDFILE):longint;cdecl;external External_library name 'sf_close';
implementation
end.

View File

@ -0,0 +1,13 @@
#include <stdio.h>
#include <sys/soundcard.h>
int main ()
{
printf("SNDCTL_DSP_STEREO = %d;\n",SNDCTL_DSP_STEREO);
printf("SNDCTL_DSP_RESET = %d;\n",SNDCTL_DSP_RESET);
printf("SNDCTL_DSP_SYNC = %d;\n",SNDCTL_DSP_SYNC);
printf("SOUND_PCM_WRITE_BITS = %d;\n",SOUND_PCM_WRITE_BITS);
printf("SOUND_PCM_WRITE_CHANNELS = %d;\n",SOUND_PCM_WRITE_CHANNELS);
printf("SOUND_PCM_WRITE_RATE = %d;\n",SOUND_PCM_WRITE_RATE);
printf("{ Sizeof(short) = %d; }\n",sizeof(short));
}