If you run in to problems while trying to use FBMMN with Linux FreeBASIC 0.16 >= apr.07.2006 and without an running eSound or Jack soundserver !
Make sure you have an ready to use sound setup on your linux distro.
Test it with your favorit mediaplayer.
If other apps has no problems with audio/video playback please help and try this short device tests.
(i can run all this simple test without any problems)
Please use the same order and give me your detailed result i can't setup more than 3 Linux distros at home.
Thank you very mutch.
Joshy
1. test alsatest.bas
Code: Select all
option explicit
enum boolean
false
true
end enum
#ifndef NULL
#define NULL 0
#endif
const EIO = -5 ' I/O error
const EAGAIN = -11 ' Try again
const EPIPE = -32 ' Broken pipe
const EBADFD = -77 ' File descriptor in bad state
const ESTRPIPE = -86 ' Streams pipe error
const BLOCK = 0
const NONBLOCK = 1
const ASYNC = 2
const SND_PCM_STREAM_PLAYBACK = 0
const SND_PCM_STREAM_CAPTURE = 1
const SND_PCM_FORMAT_S16_LE = 2
const SND_PCM_ACCESS_RW_INTERLEAVED= 3
type snd_pcm_t as any ptr
type snd_pcm_hw_params_t as any ptr
type snd_output_t as any ptr
' PCM
declare function snd_strerror cdecl alias "snd_strerror" ( _
byval ecode as integer) as zstring ptr
declare function snd_pcm_open cdecl alias "snd_pcm_open" ( _
byval pcm as snd_pcm_t ptr, _
byval device as string, _
byval direction as integer, _
byval mode as integer) as integer
declare function snd_pcm_close cdecl alias "snd_pcm_close" ( _
byval pcm as snd_pcm_t) as integer
declare function snd_pcm_start cdecl alias "snd_pcm_start" ( _
byval pcm as snd_pcm_t) as integer
declare function snd_pcm_drain cdecl alias "snd_pcm_drain" ( _
byval pcm as snd_pcm_t) as integer
declare function snd_pcm_hw_free cdecl alias "snd_pcm_hw_free" ( _
byval pcm as snd_pcm_t) as integer
declare function snd_pcm_nonblock cdecl alias "snd_pcm_nonblock" ( _
byval pcm as snd_pcm_t, _
byval nonblock as integer) as integer
declare function snd_pcm_prepare cdecl alias "snd_pcm_prepare" ( _
byval pcm as snd_pcm_t) as integer
declare function snd_pcm_writei cdecl alias "snd_pcm_writei" ( _
byval pcm as snd_pcm_t, _
byval buffer as any ptr, _
byval size as integer) as integer
declare function snd_pcm_avail_update cdecl alias "snd_pcm_avail_update" ( _
byval pcm as snd_pcm_t) as integer
declare function snd_pcm_wait cdecl alias "snd_pcm_wait" ( _
byval pcm as snd_pcm_t, _
byval msec as integer) as integer
declare function snd_pcm_resume cdecl alias "snd_pcm_resume" ( _
byval pcm as snd_pcm_t) as integer
'hardware
declare function snd_pcm_hw_params_malloc cdecl alias "snd_pcm_hw_params_malloc" ( _
byval hw as snd_pcm_hw_params_t ptr) as integer
declare function snd_pcm_hw_params_any cdecl alias "snd_pcm_hw_params_any" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t) as integer
declare function snd_pcm_hw_params_set_access cdecl alias "snd_pcm_hw_params_set_access" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t, _
byval mode as integer) as integer
declare function snd_pcm_hw_params_set_format cdecl alias "snd_pcm_hw_params_set_format" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t, _
byval fmt as integer) as integer
declare function snd_pcm_hw_params_set_channels cdecl alias "snd_pcm_hw_params_set_channels" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t, _
byval Channels as integer) as integer
declare function snd_pcm_hw_params_get_channels cdecl alias "snd_pcm_hw_params_get_channels" ( _
byval hw as snd_pcm_hw_params_t, _
byval lpChannels as integer ptr) as integer
declare function snd_pcm_hw_params_set_rate_near cdecl alias "snd_pcm_hw_params_set_rate_near" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t, _
byval lpRate as integer ptr, _
byval lpDir as integer ptr) as integer
declare function snd_pcm_hw_params_get_periods cdecl alias "snd_pcm_hw_params_get_periods" ( _
byval hw as snd_pcm_hw_params_t, _
byval lpValue as integer ptr, _
byval lpDir as integer ptr) as integer
declare function snd_pcm_hw_params_set_periods cdecl alias "snd_pcm_hw_params_set_periods" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t, _
byval Value as integer, _
byval lpDir as integer ptr) as integer
declare function snd_pcm_hw_params_set_periods_near cdecl alias "snd_pcm_hw_params_set_periods_near" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t, _
byval lpValue as integer ptr, _
byval lpDir as integer ptr) as integer
declare function snd_pcm_hw_params_get_period_size cdecl alias "snd_pcm_hw_params_get_period_size" ( _
byval params as snd_pcm_hw_params_t, _
byval lpFrames as integer ptr, _
byval lpDir as integer ptr) as integer
'int snd_pcm_hw_params_set_period_size_near (snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir)
declare function snd_pcm_hw_params_set_period_size_near cdecl alias "snd_pcm_hw_params_set_period_size_near" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t, _
byval lpValue as integer ptr, _
byval lpDir as integer ptr) as integer
declare function snd_pcm_hw_params_set_buffer_size_near cdecl alias "snd_pcm_hw_params_set_buffer_size_near" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t, _
byval lpFrames as integer ptr) as integer
declare function snd_pcm_hw_params_get_buffer_size cdecl alias "snd_pcm_hw_params_get_buffer_size" ( _
byval hw as snd_pcm_hw_params_t, _
byval lpFrames as integer ptr) as integer
declare function snd_pcm_hw_params cdecl alias "snd_pcm_hw_params" ( _
byval pcm as snd_pcm_t, _
byval hw as snd_pcm_hw_params_t) as integer
declare sub snd_pcm_hw_params_free cdecl alias "snd_pcm_hw_params_free" ( _
byval hw as snd_pcm_hw_params_t)
#inclib "asound"
'#define device "plughw:0,0"
'#define device "hw:0,0"
function AlsaWrite(byval Dev as snd_pcm_t, _
byval lpBuffer as short ptr, _
byval nBytes as integer) as integer
dim as integer ret,nFrames
if Dev = NULL then exit function
if lpBuffer = NULL then exit function
if nBytes < 4 then exit function
nFrames=nBytes
nFrames=nFrames shr 2
while(nFrames)
ret = snd_pcm_writei(Dev,lpBuffer,nFrames)
if ret<0 then
select case ret
case EAGAIN ' bussy+=1
case EPIPE ' overun+=1
ret = snd_pcm_prepare(Dev)
if (ret < 0) then print "can't recovery from underrun"
case ESTRPIPE ' suspend+=1
do: ret = snd_pcm_resume(Dev):loop while ret= EAGAIN
sleep 1
if (ret < 0) then
ret = snd_pcm_prepare(Dev)
if (ret < 0) then print "can't resume from suspend"
end if
case EBADFD,EIO
? "FATAL error: I/O or File descriptor in bad state!"
snd_pcm_close Dev
end 1
case else
print "unknow error!",ret
if snd_pcm_prepare(Dev) < 0 then exit function
end select
else
nFrames-=ret:ret=ret shl 1:lpBuffer+=ret
end if
wend
end function
dim as snd_pcm_t ptr hDevice
dim as snd_pcm_hw_params_t ptr hw
dim as integer ret,value,direction,speed,nbuffers,buffersize,nFrames,Periodsize
dim as zstring ptr strRet
' open device in non blocking mode
ret = snd_pcm_open(@hDevice,"default", SND_PCM_STREAM_PLAYBACK, NONBLOCK)
if (ret < 0) then
? "error: snd_pcm_open"
sleep :end -1
end if
#if 0
' switch to blocking mode
ret=snd_pcm_nonblock(hDevice,BLOCK)
if (ret < 0) then
? "error: nonblock"
snd_pcm_close hDevice
sleep:end -1
end if
#endif
' qwery hardware param
snd_pcm_hw_params_malloc(@hw)
ret = snd_pcm_hw_params_any(hDevice,hw)
if (ret < 0) then
? "error: snd_pcm_hw_param_any"
snd_pcm_hw_params_free hw
snd_pcm_close hDevice
sleep:end -1
end if
' set read access mode
ret = snd_pcm_hw_params_set_access(hDevice, hw, SND_PCM_ACCESS_RW_INTERLEAVED)
if (ret < 0) then
? "error: snd_pcm_set_access"
snd_pcm_hw_params_free hw
snd_pcm_close hDevice
sleep:end -1
end if
' set 16 bit
ret = snd_pcm_hw_params_set_format(hDevice,hw,2)
if (ret < 0) then
? "error: snd_pcm_set_format to 16 bit"
snd_pcm_hw_params_free hw
snd_pcm_close hDevice
sleep:end -1
end if
'set stero
ret = snd_pcm_hw_params_set_channels(hDevice,hw,2)
if (ret < 0) then
? "error: snd_pcm_set_channels to 2"
snd_pcm_hw_params_free hw
snd_pcm_close hDevice
sleep:end -1
end if
speed=44100 '96000,48000,44100,38000,36000,32000,22050,11025, ... 6000
value=speed 'set speed
ret = snd_pcm_hw_params_set_rate_near(hDevice,hw,@value,NULL)
if (ret < 0) then
? "error: snd_pcm_hw_set_rate_near 44100"
snd_pcm_hw_params_free hw
snd_pcm_close hDevice
sleep:end -1
end if
if value<>speed then
? "warning: changed speed from " & str(speed) & " to " & str(value)
speed=value
end if
nBuffers=2
Value=nBuffers
ret=snd_pcm_hw_params_set_periods_near(hDevice,hw,@Value, 0)
if (ret < 0) then
? "error: snd_pcm_hw_params_set_periods 2"
snd_pcm_hw_params_free hw
snd_pcm_close hDevice
sleep:end -1
end if
if Value<>nBuffers then
? "warning can't set periods to "+str(nBuffers)
nBuffers=Value
end if
nFrames=2048 ' one frame are 4 bytes
Value=nFrames
ret = snd_pcm_hw_params_set_period_size_near(hDevice, hw, @Value,0)
if (ret < 0) then
? "error: snd_pcm_hw_params_set_period_size_near"
snd_pcm_hw_params_free hw
snd_pcm_close hDevice
sleep:end -1
end if
if Value<>nFrames then
? "warning: changed nFrames from " & str(nFrames) & " to " & str(Value)
nFrames=Value
end if
BufferSize=nFrames*4*nBuffers
BufferSize\=nBuffers
' use curent config
ret = snd_pcm_hw_params(hDevice,hw)
if (ret < 0) then
? "error snd_pcm_hw_params"
snd_pcm_hw_params_free hw
snd_pcm_close hDevice
sleep:end -1
end if
' prepare output
ret = snd_pcm_prepare(hDevice)
if (ret < 0) then
? "error: snd_pcm_prepare"
snd_pcm_hw_params_free hw
snd_pcm_close hDevice
sleep:end -1
end if
snd_pcm_hw_params_free hw
? "speed =" & str(speed)
? "nFrames =" & str(nFrames)
? "buffersize =" & str(Buffersize)
? "buffer count =" & str(nBuffers)
ret=snd_pcm_avail_update(hDevice)
? "snd_pcm_avail_update=" & str(ret)
'
' main
'
dim as short ptr ptr lpBuffers
dim as integer i,j,p
dim as single osc1,o1
dim as single osc2,o2
o1=(8*atn(1))/speed*440
o2=(8*atn(1))/speed*220
lpBuffers=callocate(nBuffers * sizeof(short ptr))
for i=0 to nBuffers-1
lpBuffers[i]=allocate(Buffersize)
next
while asc(inkey)<>27
for i=0 to nBuffers-1
for p=0 to (Buffersize shr 1) - 2 step 2
lpBuffers[i][p ]=sin(osc1)*8000:osc1+=o1
lpBuffers[i][p+1]=sin(osc2)*8000:osc2+=o2
next
AlsaWrite(hDevice,lpBuffers[i],BufferSize)
next
sleep 1
wend
if hDevice<>NULL then snd_pcm_close hDevice:hDevice=NULL
if lpBuffers<>NULL then
for i=0 to nBuffers-1
if lpBuffers[i] <> NULL then deallocate lpBuffers[i]:lpBuffers[i]=NULL
next
deallocate lpBuffers:lpBuffers=NULL
end if
end
Code: Select all
option explicit
const _READ = 3
const _WRITE = 4
const _OPEN = 5
const _CLOSE = 6
const _ACCESS = 33
const _IOCTL = 54
const O_RDONLY = 0
const O_WRONLY = 1
const O_RDWR = 2
const EAGAIN = -11
const SNDCTL_DSP_RESET = &H00005000
const SNDCTL_DSP_SYNC = &H00005001
const SNDCTL_DSP_POST = &H00005008
const SNDCTL_DSP_NONBLOCK = &H0000500e
const SNDCTL_DSP_SPEED = &Hc0045002
const SNDCTL_DSP_STEREO = &Hc0045003 '0=mono 1=stereo
const SNDCTL_DSP_GETBLKSIZE = &Hc0045004
const SNDCTL_DSP_SETFMT = &Hc0045005
const SNDCTL_DSP_CHANNELS = &Hc0045006 '1=mono 2=stereo
const SOUND_PCM_WRITE_FILTER= &Hc0045007
const SNDCTL_DSP_SUBDIVIDE = &Hc0045009
const SNDCTL_DSP_SETFRAGMENT =&Hc004500A
'arg for SNDCTL_DSP_SETFMT cmd
const AFMT_MU_LAW = &H00000001
const AFMT_A_LAW = &H00000002
const AFMT_IMA_ADPCM = &H00000004
const AFMT_U8 = &H00000008
const AFMT_S16_LE = &H00000010 ' Little endian signed
const AFMT_S16_BE = &H00000020 ' Big endian signed 16
const AFMT_S8 = &H00000040
const AFMT_U16_LE = &H00000080 ' Little endian U16
const AFMT_U16_BE = &H00000100 ' Big endian U16
const AFMT_MPEG = &H00000200 ' MPEG (2) audio
const AFMT_AC3 = &H00000400 ' Dolby Digital AC3
function SYS_ACCESS(byval device as string,byval mode as integer) as integer
asm
mov eax, _ACCESS
mov ebx, [device]
mov ecx, [mode]
int &H80
mov [function],eax
end asm
end function
function SYS_OPEN(byval device as string,byval flag as integer,byval mode as integer=0) as integer
asm
mov eax, _OPEN
mov ebx, [device]
mov ecx, [flag]
mov edx, [mode]
int &H80
mov [function],eax
end asm
end function
function SYS_IOCTL (byval hFD as integer,byval io_cmd as integer,byval lpArg as integer ptr) as integer
asm
mov eax, _IOCTL
mov ebx, [hFD]
mov ecx, [io_cmd]
mov edx, [lpArg]
int &H80
mov [function],eax
end asm
end function
function SYS_WRITE (byval hFD as integer,byval lpBuffer as any ptr,byval Buffersize as integer) as integer
asm
mov eax, _WRITE
mov ebx, [hFD]
mov ecx, [lpBuffer]
mov edx, [BufferSize]
int &H80
mov [function],eax
end asm
end function
function SYS_READ(byval hFD as integer,byval lpBuffer as any ptr,byval Buffersize as integer) as integer
asm
mov eax, _READ
mov ebx, [hFD]
mov ecx, [lpBuffer]
mov edx, [Buffersize]
int &H80
mov [function],eax
end asm
end function
function SYS_CLOSE(byval hFD as integer) as integer
asm
mov eax, _READ
mov ebx, [hFD]
int &H80
mov [function],eax
end asm
end function
'
' main
'
dim as integer hDevice,nRate,cmd,arg,ret,nBuffers,Buffersize
function DSPWrite(byval hDevice as integer, _
byval lpBuffer as any ptr, _
byval nBytes as integer)
dim as integer ret,nErrors,BytesOut
while (nBytes>0) and (nErrors<3)
ret=EAGAIN
while ret=EAGAIN:ret=SYS_WRITE(hDevice,lpBuffer,nBytes):wend
if ret>0 then
lpBuffer+=ret
nBytes -=ret
else
nErrors+=1
end if
wend
end function
'/dev/dsp or /dev/dsp0 - 4
hDevice=SYS_OPEN("/dev/dsp",O_WRONLY)
if hDevice < 0 then
? "error: open device!"
sleep:end -1
end if
cmd=SNDCTL_DSP_RESET:arg=0
ret=SYS_IOCTL(hDevice,cmd,@arg)
if ret <0 then
? "error: DSP_RESET!"
sleep:end -1
end if
#if 0
cmd=SNDCTL_DSP_NONBLOCK:arg=0
ret=SYS_IOCTL(hDevice,cmd,@arg)
if ret <0 then
? "error: DSP_NONBLOCK!"
SYS_CLOSE(hDevice)
sleep:end -1
end if
#endif
cmd=SNDCTL_DSP_SETFRAGMENT:arg=&H2000B
ret=SYS_IOCTL(hDevice,cmd,@arg)
if ret <0 then
? "error: DSP_SETFRAGMENT!"
SYS_CLOSE(hDevice)
sleep:end -1
else
nbuffers = hiword(arg)
buffersize=2^loword(arg)
? "nBuffers =" + str(nbuffers)
? "Buffersize =" + str(buffersize)
end if
nRate=44100
cmd=SNDCTL_DSP_SPEED:arg=nRate
ret=SYS_IOCTL(hDevice,cmd,@arg)
if ret<0 then arg=48000:ret=SYS_IOCTL(hDevice,cmd,@arg)
if ret<0 then arg=22050:ret=SYS_IOCTL(hDevice,cmd,@arg)
if ret<0 then arg=11025:ret=SYS_IOCTL(hDevice,cmd,@arg)
if ret<0 then
? "error: can't set rate to 11025,22050,44100,48000"
SYS_CLOSE(hDevice)
sleep:end -1
end if
if arg<>nRate then nRate=arg
? "speed =" + str(nRate)
cmd=SNDCTL_DSP_SETFMT:arg=AFMT_S16_LE
ret=SYS_IOCTL(hDevice,cmd,@arg)
if ret <0 then
? "error: can't set 16 bit mode!"
SYS_CLOSE(hDevice)
sleep:end -1
end if
cmd=SNDCTL_DSP_CHANNELS:arg=2
ret=SYS_IOCTL(hDevice,cmd,@arg)
if ret <0 then
? "error: can't set stereo mode!"
SYS_CLOSE(hDevice)
sleep:end -1
end if
'
' main
'
dim as short ptr ptr lpBuffers
dim as integer i,j,p
dim as single osc1,o1
dim as single osc2,o2
o1=(8*atn(1))/nRate*440.0
o2=(8*atn(1))/nRate*220.0
lpBuffers=callocate(nBuffers * 4)
for i=0 to nBuffers-1
lpBuffers[i]=allocate(Buffersize)
next
while inkey<>chr(27)
for i=0 to nBuffers-1
for p=0 to (Buffersize shr 1) - 2 step 2
lpBuffers[i][p ]=sin(osc1)*8000:osc1+=o1
lpBuffers[i][p+1]=sin(osc2)*8000:osc2+=o2
next
DSPWrite(hDevice,lpBuffers[i],BufferSize)
next
sleep 1
wend
SYS_CLOSE hDevice
if lpBuffers<>0 then
for i=0 to nBuffers-1
if lpBuffers[i] <> 0 then deallocate lpBuffers[i]
next
deallocate lpBuffers
end if
end
You can find out if your distro runs an aRts server.
Code: Select all
$: ps -C artsd
Code: Select all
option explicit
type arts_stream_t as any ptr
' error codes
#define ARTS_E_NOSERVER ( -1 )
#define ARTS_E_NOBACKEND ( -2 )
#define ARTS_E_NOSTREAM ( -3 )
#define ARTS_E_NOINIT ( -4 )
#define ARTS_E_NOIMPL ( -5 )
' the values for stream parameters
' see arts_parameter_t
enum arts_parameter_t_enum
ARTS_P_BUFFER_SIZE = 1
ARTS_P_BUFFER_TIME = 2
ARTS_P_BUFFER_SPACE = 3
ARTS_P_SERVER_LATENCY = 4
ARTS_P_TOTAL_LATENCY = 5
ARTS_P_BLOCKING = 6
ARTS_P_PACKET_SIZE = 7
ARTS_P_PACKET_COUNT = 8
ARTS_P_PACKET_SETTINGS = 9
end enum
type arts_parameter_t as arts_parameter_t_enum
' parameters for streams
' ARTS_P_BUFFER_SIZE (rw) bytes = (ARTS_P_PACKET_SIZE * ARTS_P_PACKET_COUNT)
' ARTS_P_BUFFER_TIME (rw) ms
' ARTS_P_BUFFER_SPACE (r ) bytes
' ARTS_P_SERVER_LATENCY (r ) ms
' ARTS_P_TOTAL_LATENCY (r ) ms = (BUFFER_TIME + SERVER_LATENCY)
' ARTS_P_BLOCKING (rw) 1 / 0
' ARTS_P_PACKET_SIZE (r ) bytes
' ARTS_P_PACKET_COUNT (r ) count
' ARTS_P_PACKET_SETTINGS(rw) uinteger &HCCCCSSSS Size=2^SSSS
' initializes the aRts C API, and connects to the sound server
' return 0 if everything is all right, an error code otherwise
declare function arts_init cdecl alias "arts_init" () as integer
' disconnects from the sound server and frees the aRts C API internals
declare sub arts_free cdecl alias "arts_free" ()
' asks aRtsd to free the DSP device and
' return 1 if it was successful,
' return 0 if there were active non-suspendable modules
declare function arts_suspend cdecl alias "arts_suspend" () as integer
' asks aRtsd if the DSP device is free and
' return 1 if it is, 0 if not
declare function arts_suspended cdecl alias "arts_suspended" () as integer
' converts an error code to a human readable error message
declare function arts_error_text cdecl alias "arts_error_text" (byval errorcode as integer) as zstring ptr
' open a stream for playing 44100/22050 , 8/16, 1/2, "streamname"
declare function arts_play_stream cdecl alias "arts_play_stream" ( _
byval rate as integer, _
byval bits as integer, _
byval channels as integer, _
byval streamname as string) as arts_stream_t
' open a stream for recording 44100/22050 , 8/16, 1/2, "streamname"
declare function arts_record_stream cdecl alias "arts_record_stream" ( _
byval rate as integer, _
byval bits as integer, _
byval channels as integer, _
byval streamname as string) as arts_stream_t
' close a stream
declare sub arts_close_stream cdecl alias "arts_close_stream" ( _
byval stream as arts_stream_t)
' read samples from stream
' returns number of read bytes on success or error code
declare function arts_read cdecl alias "arts_read" ( _
byval stream as arts_stream_t, _
byval lpBuffer as any ptr , _
byval count as integer) as integer
' write samples to to stream
' returns number of written bytes on success or error code
declare function arts_write cdecl alias "arts_write" ( _
byval stream as arts_stream_t, _
byval lpBuffer as any ptr , _
byval count as integer) as integer
' configure a parameter of a stream
' returns the new value of the parameter, or an error code
declare function arts_stream_set cdecl alias "arts_stream_set" ( _
byval stream as arts_stream_t, _
byval param as arts_parameter_t, _
byval value as integer) as integer
' query a parameter of a stream
' returns the value of the parameter, or an error code
declare function arts_stream_get cdecl alias "arts_stream_get" ( _
byval stream as arts_stream_t, _
byval param as arts_parameter_t) as integer
#libpath "/opt/kde/lib"
#inclib "artsc"
dim as integer ret,nbuffers,buffersize,nRate
dim as arts_stream_t hDevice
private function ARTSWrite( hDevice as arts_stream_t, _
byval lpBuffer as any ptr , _
byval nBytes as integer) as integer
dim as integer ret,nErrors,Buffersize
' that should never hapent
if hDevice = 0 then exit function
if lpBuffer = 0 then exit function
if nBytes < 4 then exit function
Buffersize=nBytes
while (Buffersize>0) and (nErrors<3)
ret=arts_write(hDevice,lpBuffer,Buffersize)
if ret=0 then
sleep 1
elseif ret>0 then
Buffersize-=ret
lpBuffer +=ret
else
nErrors+=1
? "arts: error ["+ str(ret) + "]!"
end if
wend
end function
'init CAPI
ret=arts_init()
if ret<0 then
? "error: no aRts support!"
? *arts_error_text(ret)
sleep:end
end if
' create playback stream
nRate=44100
hDevice = arts_play_stream(nRate,16,2,"FB-Stream")
if hDevice<0 then nRate=48000:hDevice = arts_play_stream(nRate,16,2,"FB-Stream")
if hDevice<0 then nRate=22050:hDevice = arts_play_stream(nRate,16,2,"FB-Stream")
if hDevice<0 then nRate=11025:hDevice = arts_play_stream(nRate,16,2,"FB-Stream")
if hDevice<0 then
? "error: can't set any 16 bit stereo mode!"
? *arts_error_text(ret)
arts_free
sleep:end
end if
? "Speed =" + str(nRate)
ret=arts_stream_set(hDevice,ARTS_P_PACKET_SETTINGS,&H2000B)
if ret<0 then
? "error: set blocksize and count!"
? *arts_error_text(ret)
arts_close_stream hDevice
arts_free
sleep:end
end if
buffersize=2^loword(ret)
nbuffers = hiword(ret)
? "nBuffers =" + str(nbuffers)
? "buffersize =" + str(buffersize)
ret=arts_stream_set(hDevice,ARTS_P_BLOCKING,0)
if ret=1 then ? "warning: can't go in none blocking mode"
if ret<0 then
? "error: set non blocking mode!"
? *arts_error_text(ret)
arts_close_stream hDevice
arts_free
sleep:end
end if
'
' main
'
dim as short ptr ptr lpBuffers
dim as integer i,j,p
dim as single osc1,o1
dim as single osc2,o2
o1=(8*atn(1))/nRate*440.0
o2=(8*atn(1))/nRate*220.0
lpBuffers=callocate(nBuffers * sizeof(short ptr))
for i=0 to nBuffers-1
lpBuffers[i]=allocate(Buffersize)
next
while asc(inkey)<>27
for i=0 to nBuffers-1
for p=0 to (Buffersize shr 1) - 2 step 2
lpBuffers[i][p ]=sin(osc1)*8000:osc1+=o1
lpBuffers[i][p+1]=sin(osc2)*8000:osc2+=o2
next
ArtsWrite(hDevice,lpBuffers[i],BufferSize)
sleep 1
next
wend
arts_close_stream hDevice
arts_free
for i=0 to nBuffers-1
deallocate lpBuffers[i]
next
deallocate lpBuffers
end