FBMMN Linux only test.

Linux specific questions.
D.J.Peters
Posts: 8641
Joined: May 28, 2005 3:28
Contact:

FBMMN Linux only test.

Post by D.J.Peters »

Seams there are no problems on Windows 95,98, and XP.

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
2. test dsptest.bas

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
3. test artstest.bas
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
Last edited by D.J.Peters on May 01, 2006 15:13, edited 1 time in total.
E.K.Virtanen
Posts: 785
Joined: May 28, 2005 9:19
Location: Finland

Post by E.K.Virtanen »

Not much to paste. Order of programs is same than in your post.
lurah@dhcppc0:~$ fbc test.bas
lurah@dhcppc0:~$ ./test
error: snd_pcm_hw_params_set_periods 2

lurah@dhcppc0:~$ fbc test.bas
lurah@dhcppc0:~$ ./test
nBuffers =2
Buffersize =2048
speed =44100

lurah@dhcppc0:~$ fbc test.bas
lurah@dhcppc0:~$ ./test
error: no aRts support!
can't connect to aRts soundserver
lurah@dhcppc0:~$ ps -C artsd
PID TTY TIME CMD
lurah@dhcppc0:~$
Ubuntu.

[EDIT]
I forgot to tell, second program started to make some noise from right speaker.
[/EDIT]
Sisophon2001
Posts: 1706
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Post by Sisophon2001 »

I have a Fedora Core 2 basic setup.

My computer has a WinModem, so it has never been directly connected to the internet, and I have not installed a media player. When I double click on the mpg file, I am told the codec is not installed. When I double click a wav file, I get a player, but nothing plays.

I can play sounds, including your wav file sample using FMOD, so the sound is working.

-----------------------------------------
When I run the first program I get:
Speed = 44100
nFrames-2048
buffersize=8192
buffer count=2
snd_pcm_avail_update=4096

And a low tone sounds from the speakers

-----------------------------------------
When I run the second program I get:
nBuffers=2
Buffersize=2048
Speed=44100

And a low tone sounds from the speakers

-----------------------------------------
The third program fails to compile, reporting a missing library.
Ld: cannot find –lartsc

-----------------------------------------
When I try ps –C astsd I get:
PID TTY TIME DMD

-----------------------------------------
None of the above means much to me, but it is an advance on the segment faults of the first tests, and I heard a tone!

Good luck

Garvan
D.J.Peters
Posts: 8641
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Hello luhra first thank you for testing.
Please help and get the first "alsatest.bas" again.
I have changed the lines ..set_periods to ..set_periods_near

You must hear a noice on both speakers use your mixer and check the left right "balance" setting.

Let me know your new result on first test "alsatest.bas"

Thanx Joshy
D.J.Peters
Posts: 8641
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Garvan@:
Thanx for your test too.

Sounds good so far you has an ALSA soundsystem with OSS/DSP emulation.
On KDE desktops there are often "libartsc.so" under /opt/kde/lib.

But it is ok if ps -C artsd says you has no artsd server running.

FBMMN used ret=exec("ps"," -C artsd") to find out an running arts server.
That seams to be the point where you get an segmentation fault.
I can't reproduce this segfault here what for a FB Version you are using?

Can you make an simple EXEC test and let me know if it makes a segfault too?
any command

Code: Select all

ret=exec("ls"," -lha")
? ret
sleep
Thanx for your support.

Joshy
E.K.Virtanen
Posts: 785
Joined: May 28, 2005 9:19
Location: Finland

Post by E.K.Virtanen »

Sure Dj. But i can only find lots of "next alsa xxx" topics. Whats the first one you mean?
D.J.Peters
Posts: 8641
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

lurah wrote:Sure Dj. But i can only find lots of "next alsa xxx" topics. Whats the first one you mean?
I have posted the "new" version of "alsattest.bas" copy and paste the first example again thats all.

Thank you.

joshy
E.K.Virtanen
Posts: 785
Joined: May 28, 2005 9:19
Location: Finland

Post by E.K.Virtanen »

lurah@dhcppc0:~$ ./test
warning can't set periods to 2
warning: changed nFrames from 2048 to 940
speed =44100
nFrames =940
buffersize =3760
buffer count =15
snd_pcm_avail_update=15052
And yes. Sound from both speakers. Looks like i need to fix wire here.
D.J.Peters
Posts: 8641
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Hello lurah nice that the driver works now on your linux too.Image

But i wondering about the values of your driver / card

15 Buffers a 3760 bytes = 56400 bytes
44100 samples per second * 4 bytes = 176400 bytes.
And avial update = 15052 bytes can be written in one chunk to play.

56400 / 15052=3.747010364Image
176400/15052=11.71937284Image
15052/3760=4.00319Image

I can't see any relation between this values but ok if it works.

Joshy
D.J.Peters
Posts: 8641
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Hello lurah please test this example too and post the result.
http://fbportal.de/libs/alsatest2.bas

Again thank you.

Joshy
E.K.Virtanen
Posts: 785
Joined: May 28, 2005 9:19
Location: Finland

Post by E.K.Virtanen »

Code: Select all

lurah@dhcppc0:~$ fbc test.bas
lurah@dhcppc0:~$ ./test
warning: can't set nBuffers to 2
warning: nBuffers was chaged from 2 to 15
warning: changed nFrames from 2048 to 940
speed        =44100
nFrames      =940
buffersize   =3760
buffer count =15
snd_pcm_avail_update=15052
And that annoying sound comes too :D
Sisophon2001
Posts: 1706
Joined: May 27, 2005 6:34
Location: Cambodia, Thailand, Lao, Ireland etc.
Contact:

Post by Sisophon2001 »

D.J.Peters wrote:Garvan@:
Thanx for your test too.

Sounds good so far you has an ALSA soundsystem with OSS/DSP emulation.
On KDE desktops there are often "libartsc.so" under /opt/kde/lib.

But it is ok if ps -C artsd says you has no artsd server running.

FBMMN used ret=exec("ps"," -C artsd") to find out an running arts server.
That seams to be the point where you get an segmentation fault.
I can't reproduce this segfault here what for a FB Version you are using?

Can you make an simple EXEC test and let me know if it makes a segfault too?
any command

Code: Select all

ret=exec("ls"," -lha")
? ret
sleep
Thanx for your support.

Joshy
Hi Joshy:

This code returns an error message saying ls cannot be found. Using the ps command, I get an error report “Garbage Option”.

The space before the option is causing the problem. Was this just a typo?

This runs correctly:

Code: Select all

ret=exec("ls","-lha") 
? ret 
sleep
After I delete the space.

I have the latest testing release of FB.

Garvan
D.J.Peters
Posts: 8641
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Now for the signal processing part of FBSOUND i rewrote the linux plugouts .
I'm so sorry but i need all your support again.
Please download this short test programm and report problems if any.
Best is you can post the debug output from terminal window.

It must be run from desktop inside an terminal window.

http://freebasic.eu/fbsound/fbsound_test.tar.gz

Thank you very mutch for your support.

Joshy
redcrab
Posts: 624
Joined: Feb 07, 2006 15:29
Location: France / Luxemburg
Contact:

Post by redcrab »

I think it's perfect !
I got this
redcrab@followme:~/projects/fbsound_test> ./test14
./test14: Symbol `ospeed' has different size in shared object, consider re-linking
debug: cpu:()
debug: FPU TSC CMOV MMX SSE SSEII
debug: modules:init debug: MHz~2026
debug: fbs:()
debug: alsa:()
debug: alsa:init()
debug: alsa: only INFO buffersize in frames are ok 6144
debug: nBuffers : 3
debug: nFrames : 2048
debug: nFramesize : 4
debug: nBuffersize: 8192
debug: wholesize : 24576
debug: alsa:init~
debug: alsa:start
debug: alsa:writethread()
debug: alsa:fillthread()
debug: alsa:mainthread()
debug: alsa:start~
debug: alsa:stop()
debug: alsa: ok mainthread~
debug: alsa:writethread~ debug: alsa:fillthread~
debug: alsa:stop~
debug: alsa:exit()
debug: alsa:exit~
debug: fbs:~
debug: cpu:~
debug: alsa:~
edevaux@followme:~/projects/fbsound_test>
Nice gfx occiloscope
a nice drums beat loop
with some shift to have stereo effect


So all seams to works perfectly !

context:

SuSE Linux Enterprise Desktop 10
Pentium 4
mobile computer Dell Latitude C640
1Gb ram
2Ghz
D.J.Peters
Posts: 8641
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

Thank you for your test i found out that my new driver need 2 times more CPU time as the old driver. I will switch back to the my old but stable driver design.

Again thanx

Joshy
Post Reply