SoundStream.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5468 e9da15c1a36c
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5424
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
     1
"{ Encoding: utf8 }"
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
     2
4
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     3
"
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1993 by Claus Gittinger
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
     5
              All Rights Reserved
4
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     6
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     7
 This software is furnished under a license and may be used
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     8
 only in accordance with the terms of that license and with the
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
    10
 be provided or otherwise made available to, or used by, any
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
    11
 other person.  No title to or ownership of the software is
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
    12
 hereby transferred.
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
    13
"
918
c93d55269f9d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
    14
"{ Package: 'stx:libbasic2' }"
c93d55269f9d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
    15
3482
a78459c5bfaf class: SoundStream
Claus Gittinger <cg@exept.de>
parents: 3226
diff changeset
    16
"{ NameSpace: Smalltalk }"
a78459c5bfaf class: SoundStream
Claus Gittinger <cg@exept.de>
parents: 3226
diff changeset
    17
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    18
FileStream subclass:#SoundStream
5447
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    19
	instanceVariableNames:'sampleRate numberOfChannels bitsPerSample audioFormat handle1
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    20
		handle2 bufferOffset bufferSize lastErrorString fragmentSize
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    21
		openMode openAttributes'
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    22
	classVariableNames:'IsInitialized UnsupportedOperationSignal ConcreteClass'
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    23
	poolDictionaries:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    24
	category:'Streams-External'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    25
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    26
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    27
SoundStream subclass:#DevAudio
5447
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    28
	instanceVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    29
	classVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    30
	poolDictionaries:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    31
	privateIn:SoundStream
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    32
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    33
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    34
SoundStream subclass:#IRISAudio
5447
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    35
	instanceVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    36
	classVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    37
	poolDictionaries:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    38
	privateIn:SoundStream
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    39
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    40
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    41
SoundStream subclass:#JackAudio
5447
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    42
	instanceVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    43
	classVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    44
	poolDictionaries:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    45
	privateIn:SoundStream
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    46
!
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    47
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    48
SoundStream subclass:#PortAudio
5447
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    49
	instanceVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    50
	classVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    51
	poolDictionaries:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    52
	privateIn:SoundStream
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    53
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    54
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    55
SoundStream subclass:#Win32DirectSound
5447
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    56
	instanceVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    57
	classVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    58
	poolDictionaries:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    59
	privateIn:SoundStream
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    60
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    61
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    62
SoundStream subclass:#Win32WaveSound
5447
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    63
	instanceVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    64
	classVariableNames:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    65
	poolDictionaries:''
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
    66
	privateIn:SoundStream
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    67
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
    68
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    69
!SoundStream primitiveDefinitions!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    70
%{
725
c18d8d084a17 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 724
diff changeset
    71
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
    72
#include "stxOSDefs.h"
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
    73
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    74
#ifndef NO_SOUND
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    75
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    76
# ifdef __win32__
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
    77
#  define xxxSUPPORT_WIN32_DIRECTSOUND
5406
23d4715dbf4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5405
diff changeset
    78
#  ifndef SUPPORT_WIN32_WAVESOUND
23d4715dbf4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5405
diff changeset
    79
#   define SUPPORT_WIN32_WAVESOUND
23d4715dbf4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5405
diff changeset
    80
#  endif
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    81
# endif /* __win32__ */
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    82
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    83
# ifdef __iris__
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    84
#  ifndef IRIX5
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    85
#   ifndef SUPPORT_IRIS_AUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    86
#    define SUPPORT_IRIS_AUDIO
5406
23d4715dbf4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5405
diff changeset
    87
#   endif
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
    88
#  endif
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    89
# endif // __iris__
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    90
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    91
# ifndef SUPPORT_IRIS_AUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    92
#  ifndef SUPPORT_ALSA_AUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    93
#   ifdef LINUX
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    94
#    ifndef SUPPORT_DEV_AUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    95
#     define SUPPORT_DEV_AUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    96
#    endif
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    97
#   endif // LINUX
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    98
#  endif
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
    99
# endif // SUPPORT_IRIS_AUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   100
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   101
# ifdef __osx__
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   102
#  ifndef SUPPORT_PORTAUDIO
5468
e9da15c1a36c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5447
diff changeset
   103
#   define xxxSUPPORT_PORTAUDIO 	// def comes from config file
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   104
#  endif
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   105
# endif // __osx__
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   106
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   107
#endif /* NO_SOUND */
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   108
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   109
#ifdef SUPPORT_IRIS_AUDIO
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   110
# include <audio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   111
# define __ALportVal(o)  (ALport)(__externalAddressVal(o))
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   112
# define alPort handle1
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   113
#endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   114
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   115
#ifdef SUPPORT_ALSA_AUDIO
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   116
# ifdef LINUX
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   117
#  include <alsa/asoundlib.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   118
#  define MAX_NR_OF_CHANNELS 8
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   119
#  define DEBUG_SOUND
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   120
#  define readHandle handle1
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   121
#  define writeHandle handle2
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   122
# endif
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   123
#endif
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   124
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   125
#ifdef SUPPORT_DEV_AUDIO
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   126
# ifdef LINUX
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   127
#  include <stdio.h>
5426
c9d3c51e1b53 Fix compile error in linux
Stefan Vogel <sv@exept.de>
parents: 5425
diff changeset
   128
#  include <errno.h>
c9d3c51e1b53 Fix compile error in linux
Stefan Vogel <sv@exept.de>
parents: 5425
diff changeset
   129
#  include <signal.h>
c9d3c51e1b53 Fix compile error in linux
Stefan Vogel <sv@exept.de>
parents: 5425
diff changeset
   130
#  include <sys/ioctl.h>
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   131
#  include <sys/soundcard.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   132
#  define DEV_AUDIO_DEFAULT_FREQ (8000)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   133
#  define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   134
# endif
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   135
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   136
# ifdef FREEBSD
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   137
#  include <stdio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   138
#  include <sys/time.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   139
#  include <sys/ioctl.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   140
#  include <machine/pcaudioio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   141
#  define DEV_AUDIO_DEFAULT_FREQ (8000)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   142
#  define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   143
# endif
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   144
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   145
# if defined(sunos) || defined(solaris)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   146
#  include <stdio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   147
#  ifdef solaris
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   148
#   include <sys/audioio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   149
#  else
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   150
#   include <sun/audioio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   151
#  endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   152
#  define DEV_AUDIO_DEFAULT_FREQ (8000)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   153
#  define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
   154
# endif
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
   155
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   156
# if defined(hpux)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   157
#  include <stdio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   158
#  include <sys/ioctl.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   159
#  include <sys/inode.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   160
#  include <sys/audio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   161
#  include <sys/time.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   162
#  include <unistd.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   163
#  define DEV_AUDIO_DEFAULT_FREQ (22050)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   164
#  define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   165
# endif
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   166
#endif /* SUPPORT_DEV_AUDIO */
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   167
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   168
#ifdef SUPPORT_PORTAUDIO
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   169
// # include "pthread.h"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   170
# include "portaudio.h"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   171
# define PORTAUDIO_DEFAULT_FREQ (44100)
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   172
# define PORTAUDIO_DEFAULT_BUFFERSIZE (16384)
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   173
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   174
# define xINITLOCK(lk)    { pthread_mutex_init(&(lk), NULL); }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   175
# define xRELEASELOCK(lk) { pthread_mutex_destroy(&(lk)); }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   176
# define xLOCK(lk)        { pthread_mutex_lock(&(lk)); }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   177
# define xUNLOCK(lk)      { pthread_mutex_unlock(&(lk)); }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   178
# define xMUTEX            pthread_mutex_t
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   179
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   180
# define INITLOCK(lk)    { (lk) = 0; }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   181
# define RELEASELOCK(lk) { (lk) = 0; }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   182
# define LOCK(lk)        { while ((lk)) ; (lk) = 1; }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   183
# define UNLOCK(lk)      { (lk) = 0; }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   184
# define MUTEX           int
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   185
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   186
#endif // SUPPORT_PORTAUDIO
720
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   187
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   188
#ifdef SUPPORT_JACKAUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   189
# include "jack/jack.h"
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   190
#endif // SUPPORT_JACKAUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   191
3846
7c9889bed912 win32 defs
Claus Gittinger <cg@exept.de>
parents: 3622
diff changeset
   192
#ifdef __win32__
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   193
# define _WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   194
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   195
# undef INT
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   196
# undef Array
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   197
# undef Number
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   198
# undef Method
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   199
# undef Point
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   200
# undef Rectangle
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   201
# undef Block
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   202
# undef String
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   203
# undef Message
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   204
# undef Object
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   205
# undef Context
753
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   206
# undef Time
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   207
# undef Date
1853
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   208
# undef Process
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   209
# undef Processor
861
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   210
# undef Set
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   211
# undef Signal
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   212
# undef Delay
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   213
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   214
/* # include <stdarg.h> /* */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   215
# include <stdio.h> /* */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   216
# include <windows.h>
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   217
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   218
# ifdef SUPPORT_WIN32_DIRECTSOUND
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   219
#  define CINTERFACE
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   220
#  include "dsound.h"
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   221
#  define __DirectSoundVal(o) (LPDIRECTSOUND)(__externalAddressVal(o))
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   222
#  define __DSBufferVal(o)    (LPDIRECTSOUNDBUFFER)(__externalAddressVal(o))
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   223
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   224
#  define RT_BUFFER_SIZE 4096
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   225
#  define NBUFS          4
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   226
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   227
#  define pDirectSound handle1
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   228
#  define pDSBuffer    handle2
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   229
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   230
# else /* USE WAVE... */
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   231
#  ifdef SUPPORT_WIN32_WAVESOUND
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   232
#   define __WaveHandleVal(o)    (HWAVEOUT)(__externalAddressVal(o))
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   233
#   define MAXBUF      10        /* Maximum number of buffers */
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   234
#   define DATALEN     2048      /* Size of wave data buffer */
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   235
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   236
struct buf {
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   237
    WAVEHDR hdr;                /* Wave data header */
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   238
    char data[DATALEN];         /* Actual wave data */
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   239
    struct buf *next;           /* Next buffer in free list */
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   240
};
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   241
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   242
static struct buf *free_list = NULL;      /* List of available buffers */
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   243
static CRITICAL_SECTION free_list_lock;
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   244
static int free_buffers = 0;             /* Number of buffers in free list */
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   245
static int total_buffers = 0;            /* Total number of buffers allocated */
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   246
static HANDLE free_buffer_event;         /* Automatic-reset event triggered whenever */
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   247
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   248
#   define waveHandle handle1
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   249
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   250
#  endif /* SUPPORT_WIN32_WAVESOUND */
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   251
# endif /* SUPPORT_WIN32_DIRECTSOUND */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   252
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   253
# ifdef __DEF_Array
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   254
#  define Array __DEF_Array
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   255
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   256
# ifdef __DEF_Number
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   257
#  define Number __DEF_Number
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   258
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   259
# ifdef __DEF_Method
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   260
#  define Method __DEF_Method
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   261
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   262
# ifdef __DEF_Point
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   263
#  define Point __DEF_Point
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   264
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   265
# ifdef __DEF_Block
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   266
#  define Block __DEF_Block
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   267
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   268
# ifdef __DEF_String
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   269
#  define String __DEF_String
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   270
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   271
# ifdef __DEF_Message
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   272
#  define Message __DEF_Message
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   273
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   274
# ifdef __DEF_Object
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   275
#  define Object __DEF_Object
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   276
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   277
# ifdef __DEF_Context
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   278
#  define Context __DEF_Context
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   279
# endif
753
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   280
# ifdef __DEF_Time
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   281
#  define Time __DEF_Time
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   282
# endif
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   283
# ifdef __DEF_Date
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   284
#  define Date __DEF_Date
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   285
# endif
1853
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   286
#ifdef __DEF_Process
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   287
# define Process __DEF_Process
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   288
#endif
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   289
#ifdef __DEF_Processor
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   290
# define Processor __DEF_Processor
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   291
#endif
861
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   292
#ifdef __DEF_Set
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   293
# define Set __DEF_Set
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   294
#endif
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   295
#ifdef __DEF_Signal
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   296
# define Signal __DEF_Signal
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   297
#endif
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   298
#ifdef __DEF_Delay
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   299
# define Delay __DEF_Delay
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   300
#endif
753
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   301
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
   302
# define INT  STX_INT
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
   303
# define UINT STX_UINT
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   304
3846
7c9889bed912 win32 defs
Claus Gittinger <cg@exept.de>
parents: 3622
diff changeset
   305
#endif /* __win32__ */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   306
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   307
#ifdef DEBUG_SOUND
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
   308
# define DPRINTF(x) console_printf x
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   309
#else
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   310
# define DPRINTF(x) /* as nothing */
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   311
#endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   312
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   313
%}
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   314
! !
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   315
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   316
!SoundStream primitiveVariables!
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   317
%{
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   318
static int DEBUGGING = 0;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   319
%}
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   320
! !
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   321
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   322
!SoundStream primitiveFunctions!
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   323
%{
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   324
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   325
#ifdef SUPPORT_WIN32_WAVESOUND
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   326
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   327
/*
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   328
 * This routine will be called by windows when audio is needed.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   329
 * It may called at interrupt level and by a separate thread, so don't do anything
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   330
 * that could mess up the system like calling malloc() or free().
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   331
 */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   332
static void CALLBACK
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
   333
waveCallBack(HWAVE waveHandle, UINT msg, DWORD_PTR inst, DWORD_PTR p1, DWORD_PTR p2)
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   334
{
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   335
    if (msg == MM_WOM_DONE) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   336
        struct buf *bp = (struct buf *)p1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   337
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   338
        EnterCriticalSection(&free_list_lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   339
        bp->next = free_list;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   340
        free_list = bp;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   341
        free_buffers++;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   342
        SetEvent(free_buffer_event);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   343
        LeaveCriticalSection(&free_list_lock);
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   344
    }
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   345
}
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   346
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   347
#endif /* SUPPORT_WIN32_WAVESOUND */
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   348
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   349
#ifdef SUPPORT_PORTAUDIO
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   350
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   351
struct paBuffer {
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   352
    void* sampleData;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   353
    int bufferSize;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   354
    struct paBuffer* nextBuffer;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   355
};
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   356
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   357
struct paStreamData {
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   358
    PaStream *stream;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   359
    MUTEX lock;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   360
    int readOffset;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   361
    int bytesPerSample;     // bytesPerSample (1, 2 or 4)
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   362
    int nChannels;          // num channels (1 or 2)
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   363
    int hasFinished;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   364
    struct paBuffer* currentBuffer;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   365
    struct paBuffer* lastBuffer;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   366
    struct paBuffer* freeList;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   367
};
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   368
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   369
/*
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   370
 * This routine will be called by the PortAudio engine when audio is needed.
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   371
 * It may called at interrupt level on some machines, so don't do anything
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   372
 * that could mess up the system like calling malloc() or free().
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   373
 */
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   374
static int
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   375
paCallback( const void *inputBuffer, void *outputBuffer,
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   376
            unsigned long framesPerBuffer,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   377
            const PaStreamCallbackTimeInfo* timeInfo,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   378
            PaStreamCallbackFlags statusFlags,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   379
            void *userData )
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   380
{
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   381
    struct paStreamData *streamData = (struct paStreamData *)userData;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   382
    struct paBuffer *buffer = streamData->currentBuffer;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   383
    int nBytesToOutput = streamData->bytesPerSample * streamData->nChannels * framesPerBuffer;
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   384
    int nBytesLeftInBuffer;
5416
641bc1f8e62f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5415
diff changeset
   385
    int readOffset;
641bc1f8e62f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5415
diff changeset
   386
    int writeOffset = 0;
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   387
    int nSent;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   388
    int retVal = paContinue;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   389
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   390
    readOffset = streamData->readOffset;
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
   391
  again:
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   392
    if (buffer != NULL) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   393
        nBytesLeftInBuffer = buffer->bufferSize - readOffset;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   394
        if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   395
            fprintf(stderr, "pa: %d from %p[%d] to [%d]; next: %p last: %p)\n",
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   396
                        nBytesLeftInBuffer, buffer, readOffset, writeOffset,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   397
                        buffer->nextBuffer, streamData->lastBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   398
        }
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   399
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   400
        nBytesLeftInBuffer = 0;
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   401
    }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   402
    if (nBytesLeftInBuffer >= nBytesToOutput) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   403
        memcpy(outputBuffer+writeOffset, buffer->sampleData+readOffset, nBytesToOutput);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   404
        nSent = nBytesToOutput;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   405
        if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   406
            fprintf(stderr, "pa: %d from buffer\n", nSent);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   407
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   408
        nBytesToOutput = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   409
        readOffset += nSent;
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   410
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   411
        nSent = nBytesLeftInBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   412
        if (nSent > 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   413
            memcpy(outputBuffer+writeOffset, buffer->sampleData+readOffset, nBytesLeftInBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   414
            if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   415
                fprintf(stderr, "pa: %d from buffer\n", nBytesLeftInBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   416
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   417
            nBytesToOutput -= nSent;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   418
            readOffset += nBytesLeftInBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   419
        }
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   420
    }
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   421
    if (buffer != NULL) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   422
        streamData->readOffset = readOffset;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   423
        if (readOffset >= buffer->bufferSize) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   424
            LOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   425
            // next buffer
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   426
            streamData->currentBuffer = buffer->nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   427
            streamData->readOffset = readOffset = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   428
            // this buffer onto freeList
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   429
            buffer->nextBuffer = streamData->freeList;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   430
            streamData->freeList = buffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   431
            if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   432
                fprintf(stderr, "pa: put on freelist: %p\n", buffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   433
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   434
            if (streamData->currentBuffer == NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   435
                if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   436
                    fprintf(stderr, "pa: done with last buffer\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   437
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   438
                streamData->lastBuffer = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   439
                retVal = paComplete;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   440
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   441
            UNLOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   442
            if (nBytesToOutput > 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   443
                writeOffset += nSent;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   444
                if (streamData->currentBuffer == NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   445
                    memset(outputBuffer+writeOffset, 0, nBytesToOutput);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   446
                } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   447
                    buffer = streamData->currentBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   448
                    readOffset = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   449
                    if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   450
                        fprintf(stderr, "pa: %d more\n", nBytesToOutput);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   451
                    }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   452
                    goto again;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   453
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   454
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   455
        }
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   456
    }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   457
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   458
    return paContinue;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   459
}
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   460
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   461
/*
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   462
 * This routine is called by portaudio when playback is done.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   463
 */
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   464
static void
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   465
paStreamFinished( void* userData )
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   466
{
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   467
    struct paStreamData *streamData = (struct paStreamData *)userData;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   468
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   469
    streamData->hasFinished = 1;
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   470
    if (DEBUGGING) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   471
        fprintf(stderr, "pa: Stream Completed\n" );
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   472
    }
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   473
}
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   474
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   475
#endif /* SUPPORT_PORTAUDIO */
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   476
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   477
#ifdef SUPPORT_JACKAUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   478
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   479
struct jackBuffer {
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   480
    void* sampleData;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   481
    int bufferSize;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   482
    struct jackBuffer* nextBuffer;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   483
};
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   484
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   485
struct jackStreamData {
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   486
    jack_port_t *jack_input_port;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   487
    jack_port_t *jack_output_port;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   488
    jack_client_t *jack_client;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   489
    MUTEX lock;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   490
    int readOffset;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   491
    int bytesPerSample;     // bytesPerSample (1, 2 or 4)
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   492
    int nChannels;          // num channels (1 or 2)
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   493
    int hasFinished;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   494
    struct jackBuffer* currentBuffer;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   495
    struct jackBuffer* lastBuffer;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   496
    struct jackBuffer* freeList;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   497
};
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   498
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   499
/*
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   500
 * This routine will be called by the Jack engine when audio is needed.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   501
 * It may called at interrupt level on some machines, so don't do anything
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   502
 * that could mess up the system like calling malloc() or free().
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   503
 */
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   504
static int
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   505
jack_callback(jack_nframes_t nframes, void *userData)
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   506
{
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   507
    struct jackStreamData *streamData = (struct jackStreamData*)userData;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   508
    struct jackBuffer *buffer = streamData->currentBuffer;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   509
    int nBytesToOutput = streamData->bytesPerSample * streamData->nChannels * nframes;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   510
    // int nBytesToOutput = sizeof (jack_default_audio_sample_t) * nframes;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   511
    int nBytesLeftInBuffer;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   512
    int readOffset;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   513
    int writeOffset = 0;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   514
    int nSent;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   515
    int retVal = paContinue;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   516
    jack_default_audio_sample_t *in, *out;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   517
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   518
    in = jack_port_get_buffer (streamData->jack_input_port, nframes);
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   519
    out = jack_port_get_buffer (streamData->jack_output_port, nframes);
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   520
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   521
    readOffset = streamData->readOffset;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   522
  again:
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   523
    if (buffer != NULL) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   524
        nBytesLeftInBuffer = buffer->bufferSize - readOffset;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   525
        if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   526
            fprintf(stderr, "jack: %d from %p[%d] to [%d]; next: %p last: %p)\n",
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   527
                        nBytesLeftInBuffer, buffer, readOffset, writeOffset,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   528
                        buffer->nextBuffer, streamData->lastBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   529
        }
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   530
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   531
        nBytesLeftInBuffer = 0;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   532
    }
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   533
    if (nBytesLeftInBuffer >= nBytesToOutput) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   534
        memcpy(out+writeOffset, buffer->sampleData+readOffset, nBytesToOutput);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   535
        nSent = nBytesToOutput;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   536
        if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   537
            fprintf(stderr, "jack: %d from buffer\n", nSent);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   538
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   539
        nBytesToOutput = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   540
        readOffset += nSent;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   541
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   542
        nSent = nBytesLeftInBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   543
        if (nSent > 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   544
            memcpy(out+writeOffset, buffer->sampleData+readOffset, nBytesLeftInBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   545
            if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   546
                fprintf(stderr, "jack: %d from buffer\n", nBytesLeftInBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   547
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   548
            nBytesToOutput -= nSent;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   549
            readOffset += nBytesLeftInBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   550
        }
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   551
    }
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   552
    if (buffer != NULL) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   553
        streamData->readOffset = readOffset;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   554
        if (readOffset >= buffer->bufferSize) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   555
            LOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   556
            // next buffer
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   557
            streamData->currentBuffer = buffer->nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   558
            streamData->readOffset = readOffset = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   559
            // this buffer onto freeList
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   560
            buffer->nextBuffer = streamData->freeList;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   561
            streamData->freeList = buffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   562
            if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   563
                fprintf(stderr, "jack: put on freelist: %p\n", buffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   564
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   565
            if (streamData->currentBuffer == NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   566
                if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   567
                    fprintf(stderr, "jack: done with last buffer\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   568
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   569
                streamData->lastBuffer = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   570
                retVal = paComplete;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   571
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   572
            UNLOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   573
            if (nBytesToOutput > 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   574
                writeOffset += nSent;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   575
                if (streamData->currentBuffer == NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   576
                    memset(out+writeOffset, 0, nBytesToOutput);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   577
                } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   578
                    buffer = streamData->currentBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   579
                    readOffset = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   580
                    if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   581
                        fprintf(stderr, "jack: %d more\n", nBytesToOutput);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   582
                    }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   583
                    goto again;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   584
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   585
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   586
        }
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   587
    }
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   588
    return 0;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   589
}
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   590
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   591
/**
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   592
 * JACK calls this shutdown_callback if the server ever shuts down or
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   593
 * decides to disconnect the client.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   594
 */
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   595
void
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   596
jack_shutdown (void *userData)
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   597
{
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   598
    struct jackStreamData *streamData = (struct jackStreamData*)userData;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   599
}
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   600
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   601
#endif /* SUPPORT_JACKAUDIO */
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   602
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   603
%}
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
   604
! !
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
   605
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   606
!SoundStream class methodsFor:'documentation'!
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   607
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   608
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   609
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   610
 COPYRIGHT (c) 1993 by Claus Gittinger
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   611
              All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   612
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   613
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   614
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   615
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   616
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   617
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   618
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   619
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   620
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   621
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   622
documentation
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   623
"
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   624
    Preliminary (unfinished) interface to an audio device.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   625
    Currently works with
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   626
        LINUXs
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   627
        SUNs (and other) /dev/audio driver
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   628
        IRIX (indy).
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   629
        PORTAUDIO (osx).
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   630
    On iris, the default setup is for 8 bit mono
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   631
    so I can play the standard sound files I have here.
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   632
    It needs much more work, for stereo, different sampling rates etc.
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   633
5424
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
   634
    This is an experimental class - its interface & implementation may change in the future.
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   635
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   636
    [author:]
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   637
        Claus Gittinger
5447
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
   638
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
   639
    [caveat:]
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
   640
        this class was written in the early 90's to experiment with a cheap soundblaster board,
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
   641
        to provide output for a modular synth at that time.
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
   642
        It is not supported or to be taken serious...
02f8ff42a4bc #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 5429
diff changeset
   643
        Actually, it seems to be broken.
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   644
"
152
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
   645
! !
45
claus
parents: 36
diff changeset
   646
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   647
!SoundStream class methodsFor:'initialization'!
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   648
5411
67e5d96c2f7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
   649
debug:aBoolean
67e5d96c2f7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
   650
%{
67e5d96c2f7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
   651
    DEBUGGING = (aBoolean == true);
67e5d96c2f7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
   652
%}
67e5d96c2f7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
   653
!
67e5d96c2f7a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5410
diff changeset
   654
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   655
initialize
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   656
    UnsupportedOperationSignal isNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   657
        UnsupportedOperationSignal := StreamError newSignalMayProceed:true.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   658
        UnsupportedOperationSignal nameClass:self message:#unsupportedOperationSignal.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   659
        UnsupportedOperationSignal notifierString:'unsupported operation'.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   660
    ]
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   661
! !
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   662
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   663
!SoundStream class methodsFor:'instance creation'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   664
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   665
determineConcreteClass
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   666
    self allSubclassesDo:[:each |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   667
        each isAbstract ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   668
            each isSupported ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   669
                ^ each
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   670
            ]
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   671
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   672
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   673
    ^ nil
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   674
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   675
    "
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   676
     self determineConcreteClass
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
   677
    "
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   678
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   679
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   680
new
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   681
    self == SoundStream ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   682
        ConcreteClass isNil ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   683
            ConcreteClass := self determineConcreteClass.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   684
            ConcreteClass isNil ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   685
                OpenError raiseErrorString:'missing sound support'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   686
            ].
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   687
        ].
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   688
        ^ ConcreteClass new.
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   689
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   690
    ^ self basicNew initialize
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   691
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   692
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   693
     SoundStream new
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   694
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   695
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   696
932
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   697
readWrite
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   698
    "create and return a new soundStream for readWrite (i.e. filtering)"
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   699
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   700
    |newStream|
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
   701
5403
7b72eccc4366 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   702
    newStream := self new.
932
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   703
    newStream openForReadWrite isNil ifTrue:[^nil].
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   704
    ^ newStream
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   705
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   706
    "SoundStream readWrite"
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   707
!
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   708
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   709
reading
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   710
    "create and return a new soundStream for reading (i.e. recording)"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   711
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   712
    |newStream|
5403
7b72eccc4366 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   713
7b72eccc4366 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   714
    newStream := self new.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   715
    newStream openForReading isNil ifTrue:[^nil].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   716
    ^ newStream
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   717
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   718
    "SoundStream reading"
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   719
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   720
    "Modified: / 12.12.1997 / 16:51:56 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   721
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   722
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   723
writing
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   724
    "create and return a new soundStream for writing (i.e. playback)"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   725
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   726
    |newStream|
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   727
5403
7b72eccc4366 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   728
    newStream := self new.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   729
    newStream openForWriting isNil ifTrue:[^nil].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   730
    ^ newStream
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   731
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   732
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   733
     SoundStream writing
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   734
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   735
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   736
    "Created: / 17.11.1995 / 17:25:42 / cg"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   737
    "Modified: / 12.12.1997 / 16:51:38 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   738
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   739
714
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   740
writing16Bit
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   741
    "just an example, has never been tried (I also
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   742
     have no samples for this ... leave it as an exercise)"
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   743
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   744
    |newStream|
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   745
5403
7b72eccc4366 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5402
diff changeset
   746
    newStream := self new.
5422
44f59b02e13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5421
diff changeset
   747
    (newStream supportedAudioFormats includesAny:#(S16 U16)) ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   748
        OpenError raiseRequestErrorString:'sound system does not support 16bit audio'
5422
44f59b02e13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5421
diff changeset
   749
    ].
714
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   750
    newStream bitsPerSample:16.
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   751
    newStream openForWriting isNil ifTrue:[^nil].
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   752
    ^ newStream
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   753
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   754
    "SoundStream writing16Bit"
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   755
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   756
    "Modified: / 12.12.1997 / 16:51:49 / cg"
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   757
    "Created: / 21.12.1998 / 00:02:17 / cg"
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   758
!
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   759
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   760
writing16BitStereo
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   761
    "just an example, has never been tried (I also
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   762
     have no samples for this ... leave it as an exercise)"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   763
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   764
    |newStream|
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   765
5422
44f59b02e13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5421
diff changeset
   766
    newStream := self new.
44f59b02e13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5421
diff changeset
   767
    (newStream supportedAudioFormats includesAny:#(S16 U16)) ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   768
        OpenError raiseRequestErrorString:'sound system does not support 16bit audio'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   769
    ].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   770
    newStream bitsPerSample:16.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   771
    newStream numberOfChannels:2.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   772
    newStream openForWriting isNil ifTrue:[^nil].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   773
    ^ newStream
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   774
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   775
    "SoundStream writing16BitStereo"
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   776
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   777
    "Modified: / 12.12.1997 / 16:51:49 / cg"
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   778
!
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   779
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   780
writingFloat
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   781
    |newStream|
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   782
5422
44f59b02e13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5421
diff changeset
   783
    newStream := self new.
44f59b02e13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5421
diff changeset
   784
    (newStream supportedAudioFormats includes:#F32) ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   785
        OpenError raiseRequestErrorString:'sound system does not support float audio'
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   786
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   787
    newStream setAudioFormat:#F32.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   788
    newStream numberOfChannels:1.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   789
    newStream openForWriting isNil ifTrue:[^nil].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   790
    ^ newStream
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   791
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   792
    "SoundStream writingFloat"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   793
!
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   794
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   795
writingFloatStereo
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   796
    |newStream|
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   797
5422
44f59b02e13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5421
diff changeset
   798
    newStream := self new.
44f59b02e13f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5421
diff changeset
   799
    (newStream supportedAudioFormats includes:#F32) ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   800
        OpenError raiseRequestErrorString:'sound system does not support float audio'
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   801
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   802
    newStream setAudioFormat:#F32.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   803
    newStream numberOfChannels:2.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   804
    newStream openForWriting isNil ifTrue:[^nil].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   805
    ^ newStream
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   806
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
   807
    "SoundStream writingFloatStereo"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   808
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   809
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   810
!SoundStream class methodsFor:'Signal constants'!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   811
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   812
unsupportedOperationSignal
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   813
    ^ UnsupportedOperationSignal
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   814
! !
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   815
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   816
!SoundStream class methodsFor:'conversion helpers'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   817
5401
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   818
aLawToLinear16:aLawValue
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   819
    "given an aLaw byte, return the decoded signed 16bit value"
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   820
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   821
    "
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   822
     Linearer Input      Output
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   823
     s0000000wxyza...        n000wxyz
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   824
     s0000001wxyza...        n001wxyz
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   825
     s000001wxyzab...        n010wxyz
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   826
     s00001wxyzabc...        n011wxyz
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   827
     s0001wxyzabcd...        n100wxyz
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   828
     s001wxyzabcde...        n101wxyz
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   829
     s01wxyzabcdef...        n110wxyz
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   830
     s1wxyzabcdefg...        n111wxyz
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   831
    "
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   832
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   833
    |ix iexp mant|
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   834
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   835
    ix := aLawValue bitAnd:16r007F. "/ remove sign bit
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   836
    iexp := ix rightShift: 4.       "/ extract exponent
5401
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   837
    mant := ix bitAnd:16r000F.      "/ now get mantissa
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   838
    (iexp > 0) ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   839
        mant := mant + 16.          "/ add leading '1', if exponent > 0
5401
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   840
    ].
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   841
    mant := (mant bitShift: 4) + 16r0008.   "/ now mantissa left justified and
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   842
                                            "/ 1/2 quantization step added
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   843
    (iexp > 1) ifTrue:[                     "/ now left shift according exponent
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   844
        mant := mant bitShift: (iexp - 1).
5401
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   845
    ].
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   846
    "/ from 12 to 16bit
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   847
    mant := mant bitShift:4.
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
   848
    aLawValue > 127 ifTrue:[               "/ invert, if negative sample
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   849
        ^ mant
5401
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   850
    ] ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   851
        ^ mant negated
5401
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   852
    ].
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   853
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   854
    "
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   855
     self aLawToLinear16:2r00000000    -8
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   856
     self aLawToLinear16:2r00000001    -24
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   857
     self aLawToLinear16:2r00010000    -264
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   858
     self aLawToLinear16:2r00100000    -528
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   859
     self aLawToLinear16:2r01000000    -2112
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   860
     self aLawToLinear16:2r11000000    2112
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   861
    "
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   862
!
3f2bb4b5331f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5400
diff changeset
   863
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   864
linear16ToUlaw:a16bitSignedValue
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   865
    "given a 16it signed value, encode into uLaw byte"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   866
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   867
    |absVal sign exp mantissa byte|
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   868
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   869
%{
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   870
    /*
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   871
     * so heavily used when playing sounds ...
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   872
     * made it a primitive.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   873
     */
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   874
    if (__isSmallInteger(a16bitSignedValue)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   875
        int __sign = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   876
        int __absVal = __intVal(a16bitSignedValue);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   877
        int __exp, __mantissa, __byte;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   878
        static char __uLawExp[] =
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   879
                    {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   880
                        0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   881
                        5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   882
                        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   883
                        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   884
                        7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   885
                        7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   886
                        7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   887
                        7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   888
                    };
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   889
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   890
        if (__absVal < 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   891
            if (__absVal <= -32256) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   892
                RETURN (__MKSMALLINT(0));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   893
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   894
            __absVal = -__absVal;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   895
            __sign = 0x80;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   896
        } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   897
            if (__absVal >= 32256) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   898
                RETURN (__MKSMALLINT(128));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   899
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   900
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   901
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   902
        __exp = __uLawExp[__absVal >> 8];
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   903
        __mantissa = (__absVal >> (__exp+3)) & 0xF;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   904
        __byte = ~(__sign | (__exp<<4) | __mantissa) & 0xFF;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   905
        RETURN (__MKSMALLINT(__byte));
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   906
    }
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   907
%}.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   908
    "/
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   909
    "/ fallback for non-integral argument
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   910
    "/
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   911
    a16bitSignedValue isInteger ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   912
        ^ self uLawToLinear16:a16bitSignedValue asInteger
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   913
    ].
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   914
    ^ 0
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   915
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   916
    "
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   917
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:0)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   918
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32256)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   919
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32256)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   920
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32767)
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   921
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32767)
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   922
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:100)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   923
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-100)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   924
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:104)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   925
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-104)
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   926
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   927
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   928
    "Modified: / 9.12.1997 / 16:46:24 / cg"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   929
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   930
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   931
uLawToLinear16:uLawValue
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   932
    "given a uLaw byte, return the decoded signed 16bit value.
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   933
     Currently unused - but will be"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   934
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   935
    ^ #(
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   936
        "0  "     -32256
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   937
        "1  "     -31228
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   938
        "2  "     -30200
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   939
        "3  "     -29172
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   940
        "4  "     -28143
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   941
        "5  "     -27115
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   942
        "6  "     -26087
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   943
        "7  "     -25059
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   944
        "8  "     -24031
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   945
        "9  "     -23002
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   946
        "10 "     -21974
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   947
        "11 "     -20946
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   948
        "12 "     -19918
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   949
        "13 "     -18889
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   950
        "14 "     -17861
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   951
        "15 "     -16833
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   952
        "16 "     -16062
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   953
        "17 "     -15548
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   954
        "18 "     -15033
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   955
        "19 "     -14519
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   956
        "20 "     -14005
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   957
        "21 "     -13491
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   958
        "22 "     -12977
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   959
        "23 "     -12463
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   960
        "24 "     -11949
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   961
        "25 "     -11435
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   962
        "26 "     -10920
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   963
        "27 "     -10406
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   964
        "28 "     -9892
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   965
        "29 "     -9378
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   966
        "30 "     -8864
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   967
        "31 "     -8350
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   968
        "32 "     -7964
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   969
        "33 "     -7707
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   970
        "34 "     -7450
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   971
        "35 "     -7193
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   972
        "36 "     -6936
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   973
        "37 "     -6679
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   974
        "38 "     -6422
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   975
        "39 "     -6165
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   976
        "40 "     -5908
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   977
        "41 "     -5651
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   978
        "42 "     -5394
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   979
        "43 "     -5137
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   980
        "44 "     -4880
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   981
        "45 "     -4623
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   982
        "46 "     -4365
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   983
        "47 "     -4108
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   984
        "48 "     -3916
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   985
        "49 "     -3787
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   986
        "50 "     -3659
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   987
        "51 "     -3530
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   988
        "52 "     -3402
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   989
        "53 "     -3273
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   990
        "54 "     -3144
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   991
        "55 "     -3016
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   992
        "56 "     -2887
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   993
        "57 "     -2759
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   994
        "58 "     -2630
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   995
        "59 "     -2502
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   996
        "60 "     -2373
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   997
        "61 "     -2245
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   998
        "62 "     -2116
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
   999
        "63 "     -1988
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1000
        "64 "     -1891
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1001
        "65 "     -1827
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1002
        "66 "     -1763
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1003
        "67 "     -1698
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1004
        "68 "     -1634
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1005
        "69 "     -1570
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1006
        "70 "     -1506
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1007
        "71 "     -1441
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1008
        "72 "     -1377
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1009
        "73 "     -1313
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1010
        "74 "     -1249
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1011
        "75 "     -1184
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1012
        "76 "     -1120
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1013
        "77 "     -1056
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1014
        "78 "     -992
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1015
        "79 "     -927
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1016
        "80 "     -879
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1017
        "81 "     -847
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1018
        "82 "     -815
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1019
        "83 "     -783
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1020
        "84 "     -751
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1021
        "85 "     -718
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1022
        "86 "     -686
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1023
        "87 "     -654
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1024
        "88 "     -622
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1025
        "89 "     -590
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1026
        "90 "     -558
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1027
        "91 "     -526
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1028
        "92 "     -494
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1029
        "93 "     -461
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1030
        "94 "     -429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1031
        "95 "     -397
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1032
        "96 "     -373
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1033
        "97 "     -357
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1034
        "98 "     -341
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1035
        "99 "     -325
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1036
        "100"     -309
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1037
        "101"     -293
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1038
        "102"     -277
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1039
        "103"     -261
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1040
        "104"     -245
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1041
        "105"     -228
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1042
        "106"     -212
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1043
        "107"     -196
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1044
        "108"     -180
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1045
        "109"     -164
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1046
        "110"     -148
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1047
        "111"     -132
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1048
        "112"     -120
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1049
        "113"     -112
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1050
        "114"     -104
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1051
        "115"     -96
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1052
        "116"     -88
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1053
        "117"     -80
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1054
        "118"     -72
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1055
        "119"     -64
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1056
        "120"     -56
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1057
        "121"     -48
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1058
        "122"     -40
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1059
        "123"     -32
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1060
        "124"     -24
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1061
        "125"     -16
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1062
        "126"     -8
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1063
        "127"     0
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1064
        "128"     32256
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1065
        "129"     31228
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1066
        "130"     30200
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1067
        "131"     29172
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1068
        "132"     28143
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1069
        "133"     27115
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1070
        "134"     26087
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1071
        "135"     25059
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1072
        "136"     24031
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1073
        "137"     23002
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1074
        "138"     21974
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1075
        "139"     20946
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1076
        "140"     19918
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1077
        "141"     18889
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1078
        "142"     17861
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1079
        "143"     16833
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1080
        "144"     16062
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1081
        "145"     15548
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1082
        "146"     15033
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1083
        "147"     14519
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1084
        "148"     14005
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1085
        "149"     13491
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1086
        "150"     12977
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1087
        "151"     12463
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1088
        "152"     11949
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1089
        "153"     11435
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1090
        "154"     10920
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1091
        "155"     10406
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1092
        "156"     9892
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1093
        "157"     9378
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1094
        "158"     8864
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1095
        "159"     8350
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1096
        "160"     7964
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1097
        "161"     7707
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1098
        "162"     7450
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1099
        "163"     7193
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1100
        "164"     6936
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1101
        "165"     6679
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1102
        "166"     6422
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1103
        "167"     6165
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1104
        "168"     5908
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1105
        "169"     5651
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1106
        "170"     5394
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1107
        "171"     5137
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1108
        "172"     4880
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1109
        "173"     4623
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1110
        "174"     4365
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1111
        "175"     4108
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1112
        "176"     3916
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1113
        "177"     3787
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1114
        "178"     3659
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1115
        "179"     3530
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1116
        "180"     3402
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1117
        "181"     3273
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1118
        "182"     3144
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1119
        "183"     3016
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1120
        "184"     2887
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1121
        "185"     2759
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1122
        "186"     2630
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1123
        "187"     2502
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1124
        "188"     2373
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1125
        "189"     2245
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1126
        "190"     2116
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1127
        "191"     1988
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1128
        "192"     1891
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1129
        "193"     1827
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1130
        "194"     1763
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1131
        "195"     1698
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1132
        "196"     1634
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1133
        "197"     1570
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1134
        "198"     1506
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1135
        "199"     1441
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1136
        "200"     1377
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1137
        "201"     1313
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1138
        "202"     1249
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1139
        "203"     1184
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1140
        "204"     1120
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1141
        "205"     1056
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1142
        "206"     992
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1143
        "207"     927
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1144
        "208"     879
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1145
        "209"     847
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1146
        "210"     815
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1147
        "211"     783
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1148
        "212"     751
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1149
        "213"     718
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1150
        "214"     686
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1151
        "215"     654
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1152
        "216"     622
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1153
        "217"     590
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1154
        "218"     558
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1155
        "219"     526
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1156
        "220"     494
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1157
        "221"     461
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1158
        "222"     429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1159
        "223"     397
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1160
        "224"     373
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1161
        "225"     357
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1162
        "226"     341
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1163
        "227"     325
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1164
        "228"     309
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1165
        "229"     293
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1166
        "230"     277
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1167
        "231"     261
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1168
        "232"     245
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1169
        "233"     228
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1170
        "234"     212
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1171
        "235"     196
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1172
        "236"     180
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1173
        "237"     164
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1174
        "238"     148
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1175
        "239"     132
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1176
        "240"     120
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1177
        "241"     112
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1178
        "242"     104
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1179
        "243"     96
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1180
        "244"     88
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1181
        "245"     80
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1182
        "246"     72
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1183
        "247"     64
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1184
        "248"     56
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1185
        "249"     48
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1186
        "250"     40
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1187
        "251"     32
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1188
        "252"     24
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1189
        "253"     16
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1190
        "254"     8
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1191
        "255"     0
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1192
    ) at:(uLawValue + 1)
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1193
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1194
    "Modified: / 9.12.1997 / 16:34:17 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1195
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1196
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1197
!SoundStream class methodsFor:'default values'!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1198
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1199
defaultAudioFormat
2822
371789d0fe49 changed:
Stefan Vogel <sv@exept.de>
parents: 2818
diff changeset
  1200
    OperatingSystem isMSWINDOWSlike ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1201
        ^ #S16
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1202
    ].
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1203
    OperatingSystem isOSXlike ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1204
        ^ #S16
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1205
    ].
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1206
    ^ #U8
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1207
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1208
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1209
defaultBitsPerSample
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1210
    "minimum, supported by all audio systems"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1211
2822
371789d0fe49 changed:
Stefan Vogel <sv@exept.de>
parents: 2818
diff changeset
  1212
    OperatingSystem isMSWINDOWSlike ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1213
        ^ 16
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1214
    ].
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1215
    OperatingSystem isOSXlike ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1216
        ^ 16
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1217
    ].
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1218
    ^ 8
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1219
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1220
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1221
defaultNumberOfChannels
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1222
    "minimum, supported by all audio systems"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1223
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1224
    ^ 1
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1225
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1226
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1227
defaultSampleRate
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1228
    "minimum, supported by all audio systems"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1229
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1230
    ^ 8000
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1231
! !
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1232
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1233
!SoundStream class methodsFor:'playing'!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1234
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1235
playSoundFile:aFilename
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1236
    "play a soundFile"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1237
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1238
    |mime inStream soundStream count totalCount buffer startTime playTime delayedTime waitTime|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1239
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1240
    mime := aFilename asFilename mimeTypeFromName.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1241
    mime isAudioType ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1242
        self error:'not an audio file: ',aFilename asFilename baseName
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1243
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1244
    self halt.
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1245
    inStream := aFilename asFilename readStream.
1154
6158d4545b71 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1151
diff changeset
  1246
    inStream isNil ifTrue:[self error:'cannot open'].
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1247
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1248
    soundStream := self writing.
1154
6158d4545b71 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1151
diff changeset
  1249
    soundStream isNil ifTrue:[self error:'cannot open sound device'].
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1250
1432
077bf1bfc8c4 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
  1251
    startTime := Timestamp now.
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1252
    totalCount := 0.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1253
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1254
    buffer := ByteArray new:4096.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1255
    [(count := inStream nextBytesInto:buffer) > 0] whileTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1256
        totalCount := totalCount + count.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1257
        soundStream nextPutBytes:count from:buffer.
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1258
    ].
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1259
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1260
    inStream close.
4867
90b1bd57aeff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4668
diff changeset
  1261
    soundStream flush.
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1262
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1263
    "/
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1264
    "/ at least the linux audio driver behaves funny, if we close too early...
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1265
    "/
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1266
    playTime := totalCount / soundStream sampleRate.
3226
d439384d80bd class: SoundStream
Claus Gittinger <cg@exept.de>
parents: 3216
diff changeset
  1267
    delayedTime := Timestamp now secondDeltaFrom: startTime.
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1268
    waitTime := playTime - delayedTime + 0.1.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1269
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1270
    (Delay forSeconds:waitTime) wait.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1271
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1272
    soundStream close.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1273
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1274
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1275
     SoundStream playSoundFile:'/usr/local/lib/sounds/laugh.snd'
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1276
     SoundStream playSoundFile:'/usr/local/lib/sounds/spacemusic.snd'
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1277
     SoundStream playSoundFile:'../../goodies/not_ported/sound/sampleFiles/pluck-pcm16.aiff'
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1278
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1279
4867
90b1bd57aeff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4668
diff changeset
  1280
    "Created: / 17-11-1995 / 17:25:30 / cg"
90b1bd57aeff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4668
diff changeset
  1281
    "Modified: / 17-03-2019 / 15:02:57 / Claus Gittinger"
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1282
! !
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1283
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1284
!SoundStream class methodsFor:'queries'!
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1285
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1286
defaultClass
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1287
    ^ ConcreteClass
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1288
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1289
    "
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1290
     SoundStream defaultClass:(SoundStream::JackAudio)
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1291
    "
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1292
!
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1293
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1294
defaultClass:aClass
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1295
    self assert:(aClass isSupported).
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1296
    ConcreteClass := aClass.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1297
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1298
    "
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1299
     SoundStream defaultClass:(SoundStream::JackAudio)
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  1300
     SoundStream defaultClass:(SoundStream::PortAudio)
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1301
    "
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1302
!
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1303
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1304
isSupported
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1305
    ^ false.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1306
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1307
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1308
noteToHertz:noteName
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1309
    "notename is one of:
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1310
        a1, b2, f3, c#3 etc."
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1311
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1312
    |octave lastDigit note f sharp|
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1313
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1314
    octave := 4.
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1315
    (lastDigit := noteName last) isDigit ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1316
        octave := lastDigit digitValue
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1317
    ].
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1318
    note := noteName first.
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1319
    sharp := (noteName size > 1) and:[noteName second == $#].
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1320
    note = $a ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1321
        f := sharp ifTrue:[466.2] ifFalse:[440]
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1322
    ] ifFalse:[ note = $b ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1323
        f := 493.8
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1324
    ] ifFalse:[ note = $c ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1325
        f := sharp ifTrue:[277.2] ifFalse:[261.6]
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1326
    ] ifFalse:[ note = $d ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1327
        f := sharp ifTrue:[311.1] ifFalse:[293.6]
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1328
    ] ifFalse:[ note = $e ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1329
        f := 329.6
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1330
    ] ifFalse:[ note = $f ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1331
        f := sharp ifTrue:[370] ifFalse:[349.2]
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1332
    ] ifFalse:[ note = $g ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1333
        f := sharp ifTrue:[415.3] ifFalse:[392]
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1334
    ]]]]]]].
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1335
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1336
    f := f * (2 raisedTo:octave-4).
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1337
    ^ f.
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1338
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1339
    "
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1340
    SoundStream noteToHertz:'a'
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1341
    SoundStream noteToHertz:'g4'
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1342
    SoundStream noteToHertz:'e5'
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1343
    SoundStream noteToHertz:'b3'
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1344
    SoundStream noteToHertz:'c#3'
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1345
    "
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1346
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1347
    "Modified: / 31.1.1999 / 12:06:27 / cg"
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1348
!
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1349
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1350
usedAudio
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1351
    "returns a symbol describing which audio system is used;
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1352
     one of PORTAUDIO, DEV_AUDIO, WIN32_WAVESOUND, IRIS_AUDIO"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1353
5406
23d4715dbf4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5405
diff changeset
  1354
    ConcreteClass isNil ifTrue:[^ nil].
23d4715dbf4f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5405
diff changeset
  1355
    ^ ConcreteClass nameSymbol
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1356
! !
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1357
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1358
!SoundStream methodsFor:'catching invalid methods'!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1359
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1360
pathName:filename
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1361
    "catch pathname access - its fixed here"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1362
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1363
    self shouldNotImplement
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1364
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1365
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1366
pathName:filename in:aDirectory
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1367
    "catch pathname access - its fixed here"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1368
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1369
    self shouldNotImplement
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1370
! !
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1371
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1372
!SoundStream methodsFor:'error handling'!
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1373
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1374
lastErrorString
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1375
    "return a message string describing the last error"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1376
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1377
    lastErrorString notNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1378
        ^ lastErrorString
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1379
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1380
    ^ super lastErrorString
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1381
! !
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1382
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1383
!SoundStream methodsFor:'mode setting'!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1384
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1385
bitsPerSample
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1386
    "return the number of bits per sample - usually 8"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1387
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1388
    ^ bitsPerSample
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1389
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1390
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1391
bitsPerSample:aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1392
    "set the number of bits per sample"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1393
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1394
    |supported ok|
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1395
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1396
    ok := false.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1397
    supported := self supportedAudioFormats.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1398
    aNumber == 16 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1399
        #(S16 S16_LE S16_BE U16 U16_LE U16_BE) doWithExit:[:fmt :exit |
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1400
            (supported includes:fmt) ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1401
                self setAudioFormat:fmt.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1402
                ok := true.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1403
                exit value:nil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1404
            ]
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1405
        ]
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1406
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1407
    aNumber == 8 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1408
        #(S8 U8) doWithExit:[:fmt :exit |
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1409
            (supported includes:fmt) ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1410
                self setAudioFormat:fmt.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1411
                ok := true.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1412
                exit value:nil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1413
            ]
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1414
        ]
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1415
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1416
    aNumber == 24 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1417
        #(S24 S24_LE S24_BE U24 U24_LE U24_BE) doWithExit:[:fmt :exit |
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1418
            (supported includes:fmt) ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1419
                self setAudioFormat:fmt.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1420
                ok := true.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1421
                exit value:nil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1422
            ]
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1423
        ]
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1424
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1425
    aNumber == 32 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1426
        #(S32 S32_LE S32_BE U32 U32_LE U32_BE) doWithExit:[:fmt :exit |
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1427
            (supported includes:fmt) ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1428
                self setAudioFormat:fmt.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1429
                ok := true.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1430
                exit value:nil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1431
            ]
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1432
        ]
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1433
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1434
    ok ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1435
        UnsupportedOperationSignal raiseRequestErrorString:'unsupported format'.
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1436
    ].
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1437
    bitsPerSample := aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1438
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1439
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1440
numberOfChannels
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1441
    "return the number of channels (1 or 2; usually 1)"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1442
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1443
    ^ numberOfChannels
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1444
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1445
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1446
numberOfChannels:aNumber
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1447
    "set the number of channels
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1448
     - on some devices, this is a nop"
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1449
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1450
    numberOfChannels := aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1451
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1452
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1453
sampleRate
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1454
    "return the sample rate"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1455
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1456
    ^ sampleRate
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1457
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1458
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1459
sampleRate:aNumber
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1460
    "set the sample rate in hertz
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1461
     - on some devices, this is a nop"
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1462
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1463
    self setSampleRate:aNumber.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1464
! !
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1465
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1466
!SoundStream methodsFor:'private'!
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1467
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1468
dumpSettings
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1469
    "debugging interface - dump the current settings"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1470
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  1471
    audioFormat == #S16 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1472
        UninterpretedBytes isBigEndian ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1473
            audioFormat := #S16_BE
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1474
        ] ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1475
            audioFormat := #S16_LE
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1476
        ]
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  1477
    ].
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  1478
    audioFormat == #U16 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1479
        UninterpretedBytes isBigEndian ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1480
            audioFormat := #U16_BE
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1481
        ] ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1482
            audioFormat := #U16_LE
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1483
        ]
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  1484
    ].
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1485
    Transcript show:'sampleRate: '; showCR:sampleRate.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1486
    Transcript show:'format: '; showCR:audioFormat.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1487
    Transcript show:'fragmentSize: '; showCR:fragmentSize.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1488
    Transcript show:'channels: '; showCR:numberOfChannels.
920
1c8a18a7a7cf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
  1489
    Transcript show:'supported audioFormats: '; showCR:(self supportedAudioFormats).
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1490
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1491
    "
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1492
     self writing dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1493
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1494
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1495
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1496
fileDescriptorOrNil
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1497
    handle notNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1498
        ^ self fileDescriptor.
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1499
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1500
    ^ nil
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1501
!
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1502
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1503
initialize
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1504
    "initialize for least common mode"
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1505
3156
edeed9ecae5b initialize methods
Stefan Vogel <sv@exept.de>
parents: 3154
diff changeset
  1506
    super initialize.
3482
a78459c5bfaf class: SoundStream
Claus Gittinger <cg@exept.de>
parents: 3226
diff changeset
  1507
    "/ transparent
a78459c5bfaf class: SoundStream
Claus Gittinger <cg@exept.de>
parents: 3226
diff changeset
  1508
    eolMode := nil.
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1509
    buffered := false.
1269
17546758fc7a buffered:falsem to NonPositionableExternalStreams is already set.
Stefan Vogel <sv@exept.de>
parents: 1154
diff changeset
  1510
    binary := true.
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1511
    bitsPerSample := self class defaultBitsPerSample.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1512
    audioFormat := self class defaultAudioFormat.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1513
    numberOfChannels := self class defaultNumberOfChannels.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1514
    sampleRate := self class defaultSampleRate.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1515
    pathName := nil.
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1516
!
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1517
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1518
resetSoundCard
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1519
    "debugging interface - reset the soundCard"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1520
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1521
    ^ UnsupportedOperationSignal raise
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1522
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1523
    "
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1524
     self writing resetSoundCard; dumpSettings; close
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1525
    "
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1526
!
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1527
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1528
setAudioFormat:aSymbol
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1529
    "set the format of the audio data as specified by aSymbol.
4617
c3f514269170 #DOCUMENTATION by mawalch
mawalch
parents: 4193
diff changeset
  1530
     Returns true if sucessful - may fail with some formats on many sound devices."
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1531
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1532
    audioFormat := aSymbol.
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1533
    ((audioFormat == #U8) or:[audioFormat == #S8]) ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1534
        bitsPerSample := 8.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1535
        ^ self
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1536
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1537
    (#(U16 U16_LE U16_BE S16 S16_LE S16_BE) includes:audioFormat) ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1538
        bitsPerSample := 16.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1539
        ^ self
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1540
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1541
    (#(U24 U24_LE U24_BE S24 S24_LE S24_BE) includes:audioFormat) ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1542
        bitsPerSample := 24.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1543
        ^ self
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1544
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1545
    (#(U32 U32_LE U32_BE S32 S32_LE S32_BE) includes:audioFormat) ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1546
        bitsPerSample := 32.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1547
        ^ self
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1548
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1549
    (audioFormat == #F32) ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1550
        bitsPerSample := 32.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1551
        ^ self
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1552
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1553
    bitsPerSample := 8.
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1554
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1555
    "
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1556
     self writing dumpSettings; close
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1557
     self writing setAudioFormat:#'MU_LAW'; close
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1558
     self writing setAudioFormat:#'U8'; dumpSettings; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1559
     self writing setAudioFormat:#'MPEG'; dumpSettings; close
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1560
    "
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1561
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1562
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1563
setChannels:nChannels
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1564
    "set the number of channels (1 -> mono; 2 -> stereo).
4617
c3f514269170 #DOCUMENTATION by mawalch
mawalch
parents: 4193
diff changeset
  1565
     Returns true if sucessful - may fail with many sound devices."
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1566
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
  1567
    numberOfChannels := nChannels.
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1568
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1569
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1570
     self writing setChannels:2; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1571
     self writing setChannels:2; setSampleRate:10000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1572
     self writing setChannels:2; setSampleRate:40000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1573
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1574
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1575
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1576
setFragmentSize:blockSize
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1577
    "set the soundDriver's fragmentSize"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1578
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1579
    fragmentSize := blockSize.
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1580
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1581
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1582
setSampleRate:hz
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1583
    "set the sample rate"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1584
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1585
    sampleRate := hz.
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1586
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1587
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1588
     self writing setSampleRate:10000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1589
     self writing setSampleRate:1000; dumpSettings; close
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1590
     self writing setSampleRate:8000; dumpSettings; close
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1591
    "
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1592
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1593
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1594
supportedAudioFormats
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1595
    "return a collection of supported audio formats.
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1596
     possibly returned symbols are:
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1597
        U8        unsigned 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1598
        S8        signed 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1599
        U16       unsigned 16bit samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1600
        U16_LE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1601
        U16_BE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1602
        S16       signed 16bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1603
        S16_LE    signed 16bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1604
        S16_BE    signed 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1605
        S24       signed 24bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1606
        S24_LE    signed 24bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1607
        S24_BE    signed 24bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1608
        S32       signed 32bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1609
        S32_LE    signed 32bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1610
        S32_BE    signed 32bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1611
        F32       float samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1612
        MPEG      audio mpeg encoded
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1613
        MU_LAW    u-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1614
        A_LAW     a-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1615
        IMA_ADPCM adpcm encoded
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1616
     the set of returned symbols depends on the underlying sound hardware.
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1617
    "
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1618
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1619
    ^ #( U8)
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1620
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1621
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1622
     |s formats|
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1623
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1624
     s := self writing.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1625
     formats := s supportedAudioFormats.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1626
     s close.
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1627
     formats
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1628
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1629
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1630
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1631
!SoundStream methodsFor:'redefined'!
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1632
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1633
close
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1634
    self flush.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1635
    super close.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1636
! !
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1637
1474
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1446
diff changeset
  1638
!SoundStream protectedMethodsFor:'redefined'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1639
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1640
closeFile
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1641
    "a stream has been collected - close the file"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1642
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1643
    self subclassResponsibility
1474
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1446
diff changeset
  1644
! !
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1446
diff changeset
  1645
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1446
diff changeset
  1646
!SoundStream methodsFor:'redefined'!
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1647
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1648
flush
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1649
    "wait until all sound has been played"
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1650
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1651
    self subclassResponsibility
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1652
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1653
!
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1654
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1655
isOpen
4635
b135c0746fd5 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4617
diff changeset
  1656
    self isExecutor ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1657
        ^ false.
4635
b135c0746fd5 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4617
diff changeset
  1658
    ].
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1659
    handle1 notNil ifTrue:[^ true].
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1660
    handle2 notNil ifTrue:[^ true].
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1661
    ^ handle notNil
4635
b135c0746fd5 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4617
diff changeset
  1662
b135c0746fd5 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4617
diff changeset
  1663
    "Modified: / 23-04-2018 / 18:29:42 / stefan"
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1664
!
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1665
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1666
nextBytes:count into:anObject startingAt:start
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1667
    "read the next count bytes into an object and return the number of
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1668
     bytes read or nil on error.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1669
     Use with ByteArrays only."
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1670
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1671
    self subclassResponsibility
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1672
!
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1673
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1674
nextPutBytes:count from:anObject startingAt:start
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1675
    "write count bytes from an object starting at index start.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1676
     return the number of bytes written or nil on error.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1677
     Redefined, since IRIS audio library cannot be used with stdio.
4193
6d9eec6e6436 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3846
diff changeset
  1678
     (at least I don't know). Use with ByteArrays only."
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1679
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1680
    self subclassResponsibility
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1681
!
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1682
1480
dbfc64f5af59 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 1474
diff changeset
  1683
openWithMode:aMode attributes:attributeSpec
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  1684
    self subclassResponsibility
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1685
! !
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1686
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1687
!SoundStream methodsFor:'sine wave generation'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1688
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1689
pause:nSeconds
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1690
    "output noting for nSeconds"
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1691
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1692
    |buffer numSamples restSamples|
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1693
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1694
    "allocate memory for 1 sec playing time"
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1695
    numSamples := self sampleRate.
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1696
    audioFormat == #U16 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1697
        buffer := WordArray new:numSamples withAll:16r8000.
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1698
    ] ifFalse:[ audioFormat == #S16 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1699
        buffer := SignedWordArray new:numSamples withAll:0.
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1700
    ] ifFalse:[ audioFormat == #F32 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1701
        buffer := FloatArray new:numSamples withAll:0.0.
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  1702
    ] ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1703
        self halt
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1704
    ]]].
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1705
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1706
    1 to:nSeconds truncated do:[:s |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1707
        self nextPutBytes:(numSamples*2) from:buffer startingAt:1
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1708
    ].
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1709
    restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated.
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1710
    restSamples > 0 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1711
        self nextPutBytes:(restSamples*2) from:buffer startingAt:1
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1712
    ].
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1713
!
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1714
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1715
playSine16:freq forSeconds:nSeconds
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1716
    "output some tone for some time
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1717
     in S16 audioFormat - a test method"
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1718
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1719
    |buffer numSamples val scale isUnsigned restSamples|
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1720
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1721
    (audioFormat startsWith:#U16) ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1722
        (audioFormat startsWith:#S16) ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1723
            self error:'must be in 16bit mode' mayProceed:true.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1724
            ^ self
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1725
        ]
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1726
    ].
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1727
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1728
    numSamples := self sampleRate.
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1729
    buffer := WordArray new:numSamples.
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1730
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1731
    "fill it with a sine wave"
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1732
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1733
    isUnsigned := audioFormat startsWith:#U16.
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1734
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1735
    scale := freq * 2 * (Float pi).
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1736
    1 to:numSamples do:[:i |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1737
        val := (scale * i / self sampleRate) sin.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1738
        val := (val * 16r7FFF) rounded.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1739
        isUnsigned ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1740
            val := val + 32768
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1741
        ].
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1742
        buffer at:i put:(val bitAnd:16rFFFF)
714
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1743
    ].
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1744
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1745
    1 to:nSeconds truncated do:[:s |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1746
        self nextPutBytes:(numSamples*2) from:buffer startingAt:1
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1747
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1748
    restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1749
    restSamples > 0 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1750
        self nextPutBytes:(restSamples*2) from:buffer startingAt:1
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1751
    ].
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1752
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1753
    "
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1754
     SoundStream writing setAudioFormat:#S16; playSine16:440 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1755
     SoundStream writing setAudioFormat:#S16; playSine16:880 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1756
     SoundStream writing setAudioFormat:#S16; playSine16:1760 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1757
     SoundStream writing setAudioFormat:#S16; playSine16:3520 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1758
     SoundStream writing tuneTone:440; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1759
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1760
     SoundStream writing setAudioFormat:#U16; playSine16:880 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1761
     SoundStream writing setAudioFormat:#U16_LE; playSine16:880 forSeconds:2; close
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1762
    "
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1763
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1764
    "Modified: / 31.1.1999 / 12:12:41 / cg"
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1765
!
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1766
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1767
playSine:freq forSeconds:nSeconds
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1768
    "output some tone for some time - a test method"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1769
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1770
    audioFormat == #F32 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1771
        self playSineF32:freq forSeconds:nSeconds.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1772
        ^ self.
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1773
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1774
    self playSine16:freq forSeconds:nSeconds.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1775
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1776
    "
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1777
     SoundStream writing setAudioFormat:#F32; playSine:440 forSeconds:2; close
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1778
     SoundStream writing setAudioFormat:#F32; playSine:880 forSeconds:2; close
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1779
     SoundStream writing setAudioFormat:#F32; playSine:1760 forSeconds:2; close
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1780
     SoundStream writing setAudioFormat:#F32; playSine:3520 forSeconds:2; close
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1781
    "
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1782
!
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1783
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1784
playSineF32:freq forSeconds:nSeconds
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1785
    "output some tone for some time
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1786
     in F32 audioFormat - a test method"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1787
5407
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1788
    |buffer numSamples val scale restSamples numChannels|
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1789
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1790
    (audioFormat == #F32) ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1791
        self error:'must be in float mode' mayProceed:true.
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1792
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1793
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1794
    numSamples := self sampleRate.
5407
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1795
    numChannels := self numberOfChannels.
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1796
    buffer := FloatArray new:(numSamples * numChannels).
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1797
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1798
    "fill it with a sine wave"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1799
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1800
    scale := freq * 2 * (Float pi).
5407
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1801
    numChannels == 2 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1802
        1 to:numSamples do:[:i |
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1803
            val := (scale * i / self sampleRate) sin.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1804
            buffer at:(i-1)*2 put:val.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1805
            buffer at:(i-1)*2+1 put:0.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1806
        ].
5407
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1807
    ] ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1808
        1 to:numSamples do:[:i |
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1809
            val := (scale * i / self sampleRate) sin.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1810
            buffer at:i put:val
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1811
        ].
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1812
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1813
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1814
    1 to:nSeconds truncated do:[:s |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1815
        self nextPutBytes:(numSamples*4) from:buffer startingAt:1
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1816
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1817
    restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1818
    restSamples > 0 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1819
        self nextPutBytes:(restSamples*4) from:buffer startingAt:1
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1820
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1821
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1822
    "
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1823
     SoundStream writing setAudioFormat:#F32; playSineF32:440 forSeconds:2; close
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1824
     SoundStream writing setAudioFormat:#F32; playSineF32:880 forSeconds:2; close
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1825
     SoundStream writing setAudioFormat:#F32; playSineF32:1760 forSeconds:2; close
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1826
     SoundStream writing setAudioFormat:#F32; playSineF32:3520 forSeconds:2; close
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1827
    "
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1828
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1829
    "Modified: / 31.1.1999 / 12:12:41 / cg"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1830
!
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1831
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1832
testMelody
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1833
    #(g 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1834
      e 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1835
      e 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1836
      f 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1837
      d 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1838
      d 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1839
      c 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1840
      d 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1841
      e 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1842
      f 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1843
      g 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1844
      g 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1845
      g 0.5
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1846
    ) pairWiseDo:[:note :duration |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1847
        self playSine:(self class noteToHertz:note) forSeconds:duration.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1848
        self pause:0.05.
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1849
    ].
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1850
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1851
    "
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1852
     self writing testMelody; close
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1853
    "
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1854
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1855
    "Created: / 31.1.1999 / 12:07:45 / cg"
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1856
    "Modified: / 31.1.1999 / 12:16:09 / cg"
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1857
!
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1858
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1859
testOctaves
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1860
    3 timesRepeat:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1861
        self playSine:220 forSeconds:0.5.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1862
        self playSine:440 forSeconds:0.5.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1863
        self playSine:880 forSeconds:0.5.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1864
        self playSine:1760 forSeconds:0.5.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1865
        self playSine:3520 forSeconds:0.5.
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1866
    ]
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1867
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1868
    "
5418
793966b34e99 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5417
diff changeset
  1869
     self writing testOctaves; close
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1870
    "
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1871
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1872
    "Created: / 31.1.1999 / 12:07:45 / cg"
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1873
    "Modified: / 31.1.1999 / 12:16:09 / cg"
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1874
!
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  1875
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1876
tuneTone
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1877
    ^ self tuneTone:440
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1878
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1879
    "
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1880
    SoundStream debug:true
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1881
     SoundStream writing tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1882
     SoundStream writing setSampleRate:4000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1883
     SoundStream writing setSampleRate:8000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1884
     SoundStream writing setSampleRate:10000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1885
     SoundStream writing setSampleRate:20000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1886
     SoundStream writing setSampleRate:40000; tuneTone; close
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1887
     SoundStream writing setSampleRate:44000; tuneTone; close
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1888
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1889
     SoundStream writing setSampleRate:40000; dumpSettings; close
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1890
     SoundStream writing setSampleRate:20000; dumpSettings; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1891
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1892
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1893
    "Modified: / 31.1.1999 / 12:06:27 / cg"
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1894
!
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1895
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1896
tuneTone16:freq seconds:nSeconds
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1897
    "output some tone for nSeconds in S16 audioFormat - a test method"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1898
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1899
    |buffer numSamples val scale restSamples|
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1900
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1901
    (audioFormat startsWith:#U16) ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1902
        (audioFormat startsWith:#S16) ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1903
            self error:'must be in 16bit mode' mayProceed:true.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1904
            ^ self
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1905
        ]
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1906
    ].
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1907
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1908
    "allocate memory for 1 sec playing time"
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1909
    numSamples := self sampleRate.
5415
5605213d20c8 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5414
diff changeset
  1910
    audioFormat == #U16 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1911
        buffer := WordArray new:numSamples.
5415
5605213d20c8 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5414
diff changeset
  1912
    ] ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1913
        buffer := SignedWordArray new:numSamples.
5415
5605213d20c8 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5414
diff changeset
  1914
    ].
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1915
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1916
    "fill it with a sine wave"
5416
641bc1f8e62f *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5415
diff changeset
  1917
    "/ buffer is 1 second,
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1918
    "/ contains freq periods,
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1919
    "/ each of which is 0 .. 2pi
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1920
    scale := freq * 2 * (Float pi) / numSamples.
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1921
    1 to:numSamples do:[:i |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1922
        val := (scale * (i-1)) sin.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1923
        val := (val * 16r7FFF) rounded.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1924
        audioFormat == #U16 ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1925
            val := val + 16r8000
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1926
        ].
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1927
        buffer at:i put:val
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1928
    ].
5414
397dd1c5574f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5413
diff changeset
  1929
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1930
    1 to:nSeconds truncated do:[:s |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1931
        self nextPutBytes:(numSamples*2) from:buffer startingAt:1
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1932
    ].
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1933
    restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1934
    restSamples > 0 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1935
        self nextPutBytes:(restSamples*2) from:buffer startingAt:1
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1936
    ].
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1937
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1938
    "of course, the frequency should be below half the
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1939
     sampleRate - hear below ...
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1940
5415
5605213d20c8 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5414
diff changeset
  1941
     SoundStream writing setSampleRate:4000; tuneTone16:440 seconds:3; close
5417
510446ad5b9f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5416
diff changeset
  1942
     SoundStream writing setSampleRate:8000; tuneTone16:440 seconds:3; close
5407
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1943
     SoundStream writing setSampleRate:10000; tuneTone16:440 seconds:1; close
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1944
     SoundStream writing setSampleRate:20000; tuneTone16:440 seconds:1; close
5417
510446ad5b9f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5416
diff changeset
  1945
     SoundStream writing setSampleRate:40000; tuneTone16:440 seconds:3; close
5407
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  1946
     SoundStream writing tuneTone16:440 seconds:1; close
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1947
    "
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1948
714
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  1949
    "Modified: / 21.12.1998 / 09:11:30 / cg"
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1950
!
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1951
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1952
tuneTone8:freq seconds:nSeconds
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1953
    "output some tone for nSeconds in U8 audioFormat - a test method"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1954
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1955
    |buffer numSamples val scale restSamples|
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1956
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1957
    (audioFormat == #U8) ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1958
        (audioFormat == #S8) ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1959
            self error:'must be in 8bit mode' mayProceed:true.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1960
            ^ self
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1961
        ]
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1962
    ].
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1963
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1964
    "allocate memory for 1 sec playing time"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1965
    numSamples := self sampleRate.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1966
    buffer := ByteArray new:numSamples.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1967
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1968
    "fill it with a sine wave"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1969
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1970
    scale := freq * 2 * (Float pi) / numSamples.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1971
    1 to:numSamples do:[:i |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1972
        val := (scale * i) sin.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1973
        val := (val * 127) rounded.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1974
        audioFormat == #U8 ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1975
            val := val + 16r80.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1976
        ].
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1977
        buffer at:i put:(val bitAnd:16rFF)
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1978
    ].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1979
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1980
    1 to:nSeconds truncated do:[:s |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1981
        self nextPutBytes:numSamples from:buffer startingAt:1
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1982
    ].
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1983
    restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1984
    restSamples > 0 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  1985
        self nextPutBytes:restSamples from:buffer startingAt:1
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  1986
    ].
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1987
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1988
    "of course, the frequency should be below half the
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1989
     sampleRate - hear below ...
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1990
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1991
     SoundStream writing tuneTone; close
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1992
     SoundStream writing setSampleRate:4000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1993
     SoundStream writing setSampleRate:4000; tuneTone:2000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1994
     SoundStream writing setSampleRate:8000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1995
     SoundStream writing setSampleRate:8000; tuneTone:2000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1996
     SoundStream writing setSampleRate:8000; tuneTone:4000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1997
     SoundStream writing setSampleRate:10000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1998
     SoundStream writing setSampleRate:10000; tuneTone:2000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  1999
     SoundStream writing setSampleRate:10000; tuneTone:4000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2000
     SoundStream writing setSampleRate:20000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2001
     SoundStream writing setSampleRate:20000; tuneTone:2000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2002
     SoundStream writing setSampleRate:20000; tuneTone:4000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2003
     SoundStream writing setSampleRate:20000; tuneTone:8000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2004
     SoundStream writing setSampleRate:40000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2005
     SoundStream writing setSampleRate:40000; tuneTone:2000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2006
     SoundStream writing setSampleRate:40000; tuneTone:4000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2007
     SoundStream writing setSampleRate:40000; tuneTone:8000 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2008
     SoundStream writing setSampleRate:40000; tuneTone:10000 seconds:1; close
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2009
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2010
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2011
    "Modified: / 15.12.1997 / 13:43:05 / cg"
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2012
    "Created: / 31.1.1999 / 12:05:17 / cg"
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2013
!
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2014
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2015
tuneTone:freq
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2016
    self tuneTone:freq seconds:3
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2017
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2018
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2019
     SoundStream writing tuneTone:880; close
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2020
     SoundStream writing setSampleRate:4000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2021
     SoundStream writing setSampleRate:4000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2022
     SoundStream writing setSampleRate:8000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2023
     SoundStream writing setSampleRate:8000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2024
     SoundStream writing setSampleRate:10000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2025
     SoundStream writing setSampleRate:10000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2026
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2027
     SoundStream writing setSampleRate:20000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2028
     SoundStream writing setSampleRate:20000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2029
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2030
     SoundStream writing setSampleRate:40000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2031
     SoundStream writing setSampleRate:40000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2032
     SoundStream writing setSampleRate:40000; tuneTone:1760 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2033
     SoundStream writing setSampleRate:40000; tuneTone:3520 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2034
     SoundStream writing setSampleRate:40000; tuneTone:7020 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2035
     SoundStream writing setSampleRate:40000; tuneTone:14040 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2036
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2037
     SoundStream writing setSampleRate:44100; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2038
     SoundStream writing setSampleRate:44100; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2039
     SoundStream writing setSampleRate:44100; tuneTone:1760 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2040
     SoundStream writing setSampleRate:44100; tuneTone:3520 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2041
     SoundStream writing setSampleRate:44100; tuneTone:7020 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2042
     SoundStream writing setSampleRate:44100; tuneTone:14040 seconds:1; close
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2043
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2044
     SoundStream writing setSampleRate:20000; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2045
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2046
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2047
    "Modified: / 31.1.1999 / 12:07:14 / cg"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2048
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2049
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
  2050
tuneTone:freq seconds:nSeconds
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2051
    ((audioFormat startsWith:#S16) or:[audioFormat startsWith:#U16]) ifTrue:[
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2052
        ^ self tuneTone16:freq seconds:nSeconds
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2053
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2054
    audioFormat == #F32 ifTrue:[
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2055
        ^ self tuneToneF32:freq seconds:nSeconds
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2056
    ].
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2057
    audioFormat == #MU_LAW ifTrue:[
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2058
        ^ self tuneToneMU:freq seconds:nSeconds
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2059
    ].
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2060
    self tuneTone8:freq seconds:nSeconds
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2061
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2062
    "
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2063
     SoundStream writing tuneTone:880; close
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2064
     SoundStream writing setSampleRate:4000; tuneTone:440 seconds:1; close
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2065
     SoundStream writing setSampleRate:4000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2066
     SoundStream writing setSampleRate:8000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2067
     SoundStream writing setSampleRate:8000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2068
     SoundStream writing setSampleRate:10000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2069
     SoundStream writing setSampleRate:10000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2070
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2071
     SoundStream writing setSampleRate:20000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2072
     SoundStream writing setSampleRate:20000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2073
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2074
     SoundStream writing setSampleRate:40000; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2075
     SoundStream writing setSampleRate:40000; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2076
     SoundStream writing setSampleRate:40000; tuneTone:1760 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2077
     SoundStream writing setSampleRate:40000; tuneTone:3520 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2078
     SoundStream writing setSampleRate:40000; tuneTone:7020 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2079
     SoundStream writing setSampleRate:40000; tuneTone:14040 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2080
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2081
     SoundStream writing setSampleRate:44100; tuneTone:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2082
     SoundStream writing setSampleRate:44100; tuneTone:880 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2083
     SoundStream writing setSampleRate:44100; tuneTone:1760 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2084
     SoundStream writing setSampleRate:44100; tuneTone:3520 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2085
     SoundStream writing setSampleRate:44100; tuneTone:7020 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2086
     SoundStream writing setSampleRate:44100; tuneTone:14040 seconds:1; close
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2087
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2088
     SoundStream writing setSampleRate:20000; dumpSettings; close
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2089
    "
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2090
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2091
    "Modified: / 31.1.1999 / 12:07:14 / cg"
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2092
!
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2093
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2094
tuneToneF32:freq seconds:nSeconds
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2095
    "output some tone for nSeconds in F32 audioFormat - a test method"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2096
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2097
    |buffer numSamples val scale restSamples|
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2098
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2099
    (audioFormat == #F32) ifFalse:[
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2100
        self error:'must be in f32 mode' mayProceed:true.
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2101
        ^ self
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2102
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2103
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2104
    "allocate memory for 1sec playing time"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2105
    numSamples := self sampleRate.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2106
    buffer := FloatArray new:numSamples.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2107
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2108
    "fill it with a sine wave"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2109
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2110
    scale := freq * 2 * (Float pi) / numSamples.
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2111
    1 to:numSamples do:[:i |
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2112
        val := (scale * i) sin.
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2113
        buffer at:i put:val
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2114
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2115
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2116
    1 to:nSeconds truncated do:[:s |
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2117
        self nextPutBytes:(numSamples*4) from:buffer startingAt:1
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2118
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2119
    restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated.
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2120
    restSamples > 0 ifTrue:[
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2121
        self nextPutBytes:(restSamples*4) from:buffer startingAt:1
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2122
    ].
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2123
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2124
    "of course, the frequency should be below half the
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2125
     sampleRate - hear below ...
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2126
5412
661f897f6228 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5411
diff changeset
  2127
     SoundStream debug:true
661f897f6228 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5411
diff changeset
  2128
     SoundStream debug:false
661f897f6228 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5411
diff changeset
  2129
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2130
     SoundStream writing tuneTone; close
5417
510446ad5b9f #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5416
diff changeset
  2131
     SoundStream writing setAudioFormat:#F32; tuneTone; close
5428
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2132
     SoundStream writing setSampleRate:4000; tuneTone:440 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2133
     SoundStream writing setSampleRate:4000; tuneTone:2000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2134
     SoundStream writing setSampleRate:8000; tuneTone:440 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2135
     SoundStream writing setSampleRate:8000; tuneTone:2000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2136
     SoundStream writing setSampleRate:8000; tuneTone:4000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2137
     SoundStream writing setSampleRate:10000; tuneTone:440 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2138
     SoundStream writing setSampleRate:10000; tuneTone:2000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2139
     SoundStream writing setSampleRate:10000; tuneTone:4000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2140
     SoundStream writing setSampleRate:20000; tuneTone:440 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2141
     SoundStream writing setSampleRate:20000; tuneTone:2000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2142
     SoundStream writing setSampleRate:20000; tuneTone:4000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2143
     SoundStream writing setSampleRate:20000; tuneTone:8000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2144
     SoundStream writing setSampleRate:40000; tuneTone:440 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2145
     SoundStream writing setSampleRate:40000; tuneTone:2000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2146
     SoundStream writing setSampleRate:40000; tuneTone:4000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2147
     SoundStream writing setSampleRate:40000; tuneTone:8000 seconds:1; close
801ed31b6783 #DOCUMENTATION by exept
Claus Gittinger <cg@exept.de>
parents: 5426
diff changeset
  2148
     SoundStream writing setSampleRate:40000; tuneTone:10000 seconds:1; close
5400
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2149
    "
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2150
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2151
    "Modified: / 15.12.1997 / 13:43:05 / cg"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2152
    "Created: / 31.1.1999 / 12:05:17 / cg"
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2153
!
6f528d0cfba9 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 4867
diff changeset
  2154
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2155
tuneToneMU:freq seconds:nSeconds
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2156
    "output some tone for nSeconds in MU_LAW audioFormat - a test method"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2157
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2158
    |buffer numSamples val scale restSamples|
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2159
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2160
    "allocate memory for 1sec playing time"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2161
    numSamples := self sampleRate.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2162
    buffer := ByteArray new:numSamples.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2163
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2164
    "fill it with a sine wave"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2165
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2166
    scale := freq * 2 * (Float pi) / numSamples.
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2167
    1 to:numSamples do:[:i |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2168
        val := (scale * i) sin.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2169
        val := (val * 16r7FFF) rounded.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2170
        buffer at:i put:(self class linear16ToUlaw:val)
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2171
    ].
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2172
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2173
    1 to:nSeconds truncated do:[:s |
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2174
        self nextPutBytes:numSamples from:buffer startingAt:1
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2175
    ].
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2176
    restSamples := ((nSeconds - nSeconds truncated) * numSamples) truncated.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2177
    restSamples > 0 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2178
        self nextPutBytes:restSamples from:buffer startingAt:1
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2179
    ].
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2180
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2181
    "of course, the frequency should be below half the
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2182
     sampleRate - hear below ...
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2183
5413
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2184
     SoundStream writing setSampleRate:8000; tuneToneMU:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2185
     SoundStream writing setSampleRate:10000; tuneToneMU:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2186
     SoundStream writing setSampleRate:20000; tuneToneMU:440 seconds:1; close
48dfad58c335 #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5412
diff changeset
  2187
     SoundStream writing setSampleRate:40000; tuneToneMU:440 seconds:1; close
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2188
    "
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2189
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2190
    "Modified: / 15.12.1997 / 13:46:19 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2191
! !
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  2192
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2193
!SoundStream::DevAudio class methodsFor:'default values'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2194
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2195
defaultSampleRate
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2196
    "minimum, supported by all audio systems"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2197
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2198
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2199
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2200
    RETURN (__MKSMALLINT(DEV_AUDIO_DEFAULT_FREQ));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2201
#endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2202
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2203
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2204
    ^ 8000
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2205
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2206
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2207
!SoundStream::DevAudio class methodsFor:'documentation'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2208
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2209
documentation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2210
"
5424
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  2211
    interface to /dev/audio (sun, hpux, linux, ...)
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2212
"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2213
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2214
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2215
!SoundStream::DevAudio class methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2216
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2217
isSupported
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2218
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2219
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2220
    RETURN(true);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2221
#endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2222
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2223
    ^ false.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2224
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2225
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2226
!SoundStream::DevAudio methodsFor:'misc'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2227
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2228
dumpSettings
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2229
    "debugging interface - dump the current settings"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2230
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2231
    |fd blockSize speed channels stereo format|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2232
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2233
    fd := self fileDescriptorOrNil.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2234
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2235
    audioFormat == #S16 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2236
        UninterpretedBytes isBigEndian ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2237
            audioFormat := #S16_BE
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2238
        ] ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2239
            audioFormat := #S16_LE
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2240
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2241
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2242
    audioFormat == #U16 ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2243
        UninterpretedBytes isBigEndian ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2244
            audioFormat := #U16_BE
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2245
        ] ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2246
            audioFormat := #U16_LE
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2247
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2248
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2249
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2250
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2251
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2252
    if (fd != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2253
        int f = __intVal(fd);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2254
        int __blockSize = -1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2255
        int __speed = -1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2256
        int __channels = __intVal(__INST(numberOfChannels));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2257
        int __stereo = __channels > 1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2258
        int __format = -1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2259
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2260
        channels = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2261
        blockSize = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2262
        stereo = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2263
        speed = nil;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2264
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2265
# if defined(SNDCTL_DSP_GETBLKSIZE)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2266
        if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2267
            blockSize = __MKSMALLINT(__blockSize);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2268
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2269
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2270
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2271
# if defined(SNDCTL_DSP_CHANNELS)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2272
        if (ioctl(f, SNDCTL_DSP_CHANNELS, &__channels) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2273
            channels = __MKSMALLINT(__channels);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2274
            stereo = __MKSMALLINT(__channels > 1);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2275
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2276
# else
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2277
#  if defined(SNDCTL_DSP_STEREO)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2278
        if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2279
            stereo = __MKSMALLINT(__stereo);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2280
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2281
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2282
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2283
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2284
# if defined(SNDCTL_DSP_SPEED)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2285
        if (ioctl(f, SNDCTL_DSP_SPEED, &__speed) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2286
            speed = __MKSMALLINT(__speed);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2287
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2288
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2289
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2290
# if defined(SNDCTL_DSP_GETFMT)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2291
        if (ioctl(f, SNDCTL_DSP_GETFMT, &__format) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2292
            format = __MKSMALLINT(__format);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2293
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2294
# else
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2295
#  if defined(SNDCTL_DSP_SETFMT) && defined(AFMT_QUERY)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2296
        __format = AFMT_QUERY;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2297
        if (ioctl(f, SNDCTL_DSP_SETFMT, &__format) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2298
            switch (__format) {
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2299
#   ifdef AFMT_MU_LAW
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2300
                case AFMT_MU_LAW:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2301
                    format = @symbol(MU_LAW);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2302
                    break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2303
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2304
#   ifdef AFMT_A_LAW
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2305
                case AFMT_A_LAW:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2306
                    format = @symbol(A_LAW);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2307
                    break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2308
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2309
#   ifdef AFMT_U8
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2310
                case AFMT_U8:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2311
                    format = @symbol(U8);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2312
                    break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2313
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2314
#   ifdef AFMT_S8
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2315
                case AFMT_S8:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2316
                    format = @symbol(S8);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2317
                    break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2318
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2319
#   ifdef AFMT_S16_LE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2320
                case AFMT_S16_LE:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2321
                    format = @symbol(S16_LE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2322
                    break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2323
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2324
#   ifdef AFMT_S16_BE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2325
                case AFMT_S16_BE:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2326
                    format = @symbol(S16_BE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2327
                    break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2328
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2329
#   ifdef AFMT_U16_LE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2330
                case AFMT_U16_LE:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2331
                    format = @symbol(U16_LE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2332
                    break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2333
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2334
#   ifdef AFMT_U16_BE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2335
                case AFMT_U16_BE:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2336
                    format = @symbol(U16_BE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2337
                    break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2338
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2339
#   ifdef AFMT_MPEG
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2340
                case AFMT_MPEG:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2341
                    format = @symbol(MPEG);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2342
                    break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2343
#   endif
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2344
                default:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2345
                    format = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2346
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2347
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2348
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2349
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2350
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2351
#endif /* SUPPORT_DEV_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2352
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2353
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2354
    format notNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2355
        Transcript show:'format: '; showCR:format
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2356
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2357
    blockSize notNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2358
        Transcript show:'blockSize: '; showCR:blockSize
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2359
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2360
    speed notNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2361
        Transcript show:'speed: '; showCR:speed
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2362
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2363
    channels notNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2364
        Transcript show:'channels: '; showCR:channels
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2365
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2366
    stereo notNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2367
        Transcript show:'stereo: '; showCR:stereo
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2368
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2369
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2370
    Transcript show:'supported audioFormats: '; showCR:(self supportedAudioFormats).
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2371
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2372
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2373
     self writing dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2374
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2375
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2376
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2377
flush
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2378
    "wait until all sound has been played"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2379
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2380
    self fileDescriptorOrNil isNil ifTrue:[^ self].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2381
    super flush.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2382
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2383
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2384
!SoundStream::DevAudio methodsFor:'open & close'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2385
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2386
closeFile
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2387
    "a stream has been collected - close the file"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2388
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2389
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2390
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2391
    OBJ fp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2392
    int fd;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2393
    FILE *f;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2394
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2395
    if ((fp = __INST(handle)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2396
        f = __FILEVal(fp);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2397
        __INST(handle) = nil;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2398
# ifdef LINUX
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2399
        sigsetmask(~0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2400
# endif
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2401
        if (__INST(buffered) == true) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2402
            fflush(f);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2403
            fclose(f);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2404
        } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2405
            fd = fileno(f);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2406
            close(fd);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2407
            fclose(f);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2408
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2409
# ifdef LINUX
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2410
        sigsetmask(0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2411
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2412
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2413
    RETURN (self);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2414
#endif /* SUPPORT_DEV_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2415
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2416
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2417
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2418
openWithMode:aMode attributes:attributeSpec
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2419
    |ok error errorStringOrNil|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2420
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2421
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2422
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2423
      int __fd;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2424
      int __mode;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2425
      FILE *f;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2426
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2427
      ok = false;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2428
      if (strcmp(__stringVal(aMode), "w") == 0) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2429
          __mode = O_WRONLY;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2430
      } else if (strcmp(__stringVal(aMode), "r") == 0) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2431
          __mode = O_RDONLY;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2432
      } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2433
          __mode = O_RDWR;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2434
      }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2435
      do {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2436
          __BEGIN_INTERRUPTABLE__
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2437
          __fd = open((char *) __stringVal(__INST(pathName)), __mode /* |O_NDELAY */);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2438
          __END_INTERRUPTABLE__
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2439
      } while ((__fd < 0) && (errno == EINTR));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2440
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2441
      if (__fd >= 0) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2442
          /*
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2443
           * make it a FILE *
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2444
           */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2445
          f = fdopen(__fd, __stringVal(aMode));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2446
          if (! f) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2447
              error = __mkSmallInteger(errno);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2448
              __BEGIN_INTERRUPTABLE__
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2449
              close(__fd);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2450
              __END_INTERRUPTABLE__
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2451
              goto out;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2452
          }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2453
          setbuf(f, NULL);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2454
          __INST(buffered) = false;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2455
          __INST(handle) = __MKEXTERNALADDRESS(f);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2456
          __STORESELF(handle);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2457
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2458
#if defined(PCM_ENABLE_OUTPUT) && defined(PCM_ENABLE_INPUT)
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2459
# if defined(SNDCTL_DSP_SETTRIGGER)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2460
          if (__mode == O_RDWR) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2461
              int enable_bits = ~(PCM_ENABLE_OUTPUT|PCM_ENABLE_INPUT);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2462
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2463
              if (ioctl(__fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) == -1)
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2464
              {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2465
                  console_fprintf(stderr, "can't request synchronous start of fullduplex operation");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2466
              }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2467
          }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2468
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2469
#endif
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2470
          ok = true;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2471
      } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2472
          error = __mkSmallInteger(errno);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2473
      }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2474
out:;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2475
#endif /* SUPPORT_DEV_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2476
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2477
    ok == false ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2478
        lastErrorString := errorStringOrNil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2479
        lastErrorNumber := error ? -1.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2480
        self openError:error.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2481
        "normally not reached"
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2482
        ^ nil.
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2483
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2484
    self registerForFinalization.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2485
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2486
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2487
!SoundStream::DevAudio methodsFor:'private'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2488
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2489
initialize
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2490
    "initialize for least common mode"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2491
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2492
    super initialize.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2493
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2494
    OperatingSystem isUNIXlike ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2495
        '/dev/audio' asFilename exists ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2496
            "/
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2497
            "/ sunos or linux
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2498
            "/
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2499
            pathName := '/dev/audio'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2500
        ].
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2501
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2502
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2503
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2504
resetSoundCard
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2505
    "debugging interface - reset the soundCard"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2506
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2507
    |fd|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2508
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2509
    fd := self fileDescriptorOrNil.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2510
    fd isNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2511
        self errorNotOpen.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2512
        ^ nil
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2513
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2514
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2515
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2516
    int f = __intVal(fd);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2517
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2518
    if (__isSmallInteger(fd)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2519
        int __dummy;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2520
# if defined(SNDCTL_DSP_RESET)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2521
        if (ioctl(f, SNDCTL_DSP_RESET, &__dummy) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2522
            RETURN (self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2523
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2524
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2525
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2526
#endif /* SUPPORT_DEV_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2527
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2528
    ^ UnsupportedOperationSignal raise
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2529
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2530
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2531
     self writing resetSoundCard; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2532
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2533
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2534
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2535
setAudioFormat:aSymbol
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2536
    "set the format of the audio data as specified by aSymbol.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2537
     Returns true if sucessful - may fail with some formats on many sound devices."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2538
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2539
    |fd ok|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2540
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2541
    audioFormat == aSymbol ifTrue:[^ self].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2542
    super setAudioFormat:aSymbol.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2543
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2544
    fd := self fileDescriptor.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2545
    fd isNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2546
        ^ self
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2547
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2548
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2549
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2550
    OBJ sym = aSymbol;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2551
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2552
    if (__isSmallInteger(fd)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2553
        int f = __intVal(fd);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2554
        int __fmt = 0, __fmtWant;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2555
        union {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2556
            unsigned short us;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2557
            unsigned char ub[2];
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2558
        } u;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2559
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2560
        if (__isSymbol(sym)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2561
            if (sym == @symbol(U16)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2562
                u.us = 0x1234;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2563
                if (u.ub[0] == 0x34) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2564
                    /* printf("U16_LE\n"); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2565
                    sym = @symbol(U16_LE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2566
                } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2567
                    /* printf("U16_BE\n"); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2568
                    sym = @symbol(U16_BE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2569
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2570
            } else if (sym == @symbol(S16)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2571
                u.us = 0x1234;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2572
                if (u.ub[0] == 0x34) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2573
                    /* printf("S16_LE\n"); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2574
                   sym = @symbol(S16_LE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2575
                } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2576
                    /* printf("S16_BE\n"); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2577
                   sym = @symbol(S16_BE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2578
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2579
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2580
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2581
            if (0) {
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2582
# ifdef AFMT_MU_LAW
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2583
            } else if (sym == @symbol(MU_LAW)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2584
                __fmt = AFMT_MU_LAW;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2585
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2586
# ifdef AFMT_A_LAW
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2587
            } else if (sym == @symbol(A_LAW)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2588
                __fmt = AFMT_A_LAW;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2589
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2590
# ifdef AFMT_IMA_ADPCM
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2591
            } else if (sym == @symbol(IMA_ADPCM)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2592
                __fmt = AFMT_IMA_ADPCM;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2593
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2594
# ifdef AFMT_U8
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2595
            } else if (sym == @symbol(U8)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2596
                __fmt = AFMT_U8;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2597
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2598
# ifdef AFMT_S8
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2599
            } else if (sym == @symbol(S8)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2600
                __fmt = AFMT_S8;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2601
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2602
# ifdef AFMT_U16_LE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2603
            } else if (sym == @symbol(U16_LE)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2604
                __fmt = AFMT_U16_LE;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2605
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2606
# ifdef AFMT_U16_BE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2607
            } else if (sym == @symbol(U16_BE)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2608
                __fmt = AFMT_U16_BE;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2609
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2610
# ifdef AFMT_S16_LE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2611
            } else if (sym == @symbol(S16_LE)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2612
                __fmt = AFMT_S16_LE;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2613
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2614
# ifdef AFMT_S16_BE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2615
            } else if (sym == @symbol(S16_BE)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2616
                __fmt = AFMT_S16_BE;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2617
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2618
# ifdef AFMT_MPEG
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2619
            } else if (sym == @symbol(MPEG)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2620
                __fmt = AFMT_MPEG;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2621
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2622
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2623
# ifdef AUDIO_FORMAT_LINEAR16BIT
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2624
            } else if (sym == @symbol(S16)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2625
                __fmt = AUDIO_FORMAT_LINEAR16BIT;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2626
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2627
# ifdef AUDIO_FORMAT_ULAW
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2628
            } else if (sym == @symbol(MU_LAW)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2629
                __fmt = AUDIO_FORMAT_ULAW;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2630
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2631
# ifdef AUDIO_FORMAT_ALAW
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2632
            } else if (sym == @symbol(A_LAW)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2633
                __fmt = AUDIO_FORMAT_ALAW;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2634
# endif
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2635
            } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2636
                console_fprintf(stderr, "bad format: %s\n", __stringVal(sym));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2637
                ok = false;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2638
                goto bad;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2639
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2640
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2641
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2642
# ifdef SNDCTL_DSP_SETFMT
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2643
        __fmtWant = __fmt;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2644
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2645
        if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2646
            if (__fmt == __fmtWant) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2647
                __INST(audioFormat) = sym;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2648
            } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2649
                /* console_fprintf(stderr, "want: %x; got: %x\n", __fmtWant, __fmt); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2650
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2651
        } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2652
            /* console_fprintf(stderr, "got err-ret from setFmp %x\n", __fmt); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2653
            ok = false;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2654
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2655
# else
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2656
#  ifdef AUDIO_SET_DATA_FORMAT /* hpux */
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2657
        if (ioctl (f, AUDIO_SET_DATA_FORMAT, __fmt)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2658
            /* console_fprintf(stderr, "got err-ret from AUDIO_SET_DATA_FORMAT\n"); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2659
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2660
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2661
# endif /* SNDCTL_DSP_SETFMT */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2662
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2663
bad: ;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2664
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2665
#endif /* SUPPORT_DEV_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2666
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2667
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2668
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2669
     self writing dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2670
     self writing setAudioFormat:#'MU_LAW'; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2671
     self writing setAudioFormat:#'U8'; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2672
     self writing setAudioFormat:#'MPEG'; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2673
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2674
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2675
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2676
setChannels:nChannels
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2677
    "set the number of channels (1 -> mono; 2 -> stereo).
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2678
     Returns true if sucessful - may fail with many sound devices."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2679
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2680
    |fd|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2681
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2682
    numberOfChannels := nChannels.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2683
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2684
    fd := self fileDescriptorOrNil.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2685
    fd isNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2686
        ^ self
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2687
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2688
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2689
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2690
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2691
    if (__isSmallInteger(fd) && __isSmallInteger(nChannels)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2692
        int f = __intVal(fd);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2693
        int __nCh = __intVal(nChannels);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2694
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2695
# ifdef SNDCTL_DSP_STEREO
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2696
        if ((__nCh == 1) || (__nCh == 2)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2697
            int __stereo = (__nCh == 2) ? 1 : 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2698
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2699
            if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2700
                if (__stereo == 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2701
                    __INST(numberOfChannels) = __MKSMALLINT(1);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2702
                } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2703
                    __INST(numberOfChannels) = __MKSMALLINT(2);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2704
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2705
                RETURN (self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2706
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2707
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2708
# else
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2709
#  ifdef SOUND_PCM_WRITE_CHANNELS
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2710
        if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2711
            RETURN (self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2712
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2713
#  else
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2714
#   ifdef AUDIO_SET_CHANNELS /* hpux */
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2715
        if (ioctl (f, AUDIO_SET_CHANNELS, __nCh)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2716
            /* console_fprintf(stderr, "got err-ret from AUDIO_SET_CHANNELS\n"); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2717
            RETURN (self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2718
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2719
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2720
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2721
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2722
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2723
#endif /* SUPPORT_DEV_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2724
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2725
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2726
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2727
     self writing setChannels:2; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2728
     self writing setChannels:2; setSampleRate:10000; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2729
     self writing setChannels:2; setSampleRate:40000; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2730
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2731
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2732
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2733
setFragmentSize:blockSize
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2734
    "set the soundDriver's fragmentSize"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2735
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2736
    |fd|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2737
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2738
    fragmentSize := blockSize.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2739
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2740
    fd := self fileDescriptorOrNil.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2741
    fd isNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2742
        ^ self
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2743
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2744
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2745
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2746
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2747
    int f = __intVal(fd);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2748
    int __blockSize = __intVal(blockSize);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2749
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2750
    if (__isSmallInteger(fd) && __isSmallInteger(blockSize)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2751
        __blockSize = __intVal(blockSize);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2752
# if defined(SNDCTL_DSP_SETFRAGMENT)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2753
        if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2754
            RETURN (self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2755
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2756
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2757
# ifdef AUDIO_SET_CHANNELS /* hpux */
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2758
        if (ioctl (f, AUDIO_SET_TXBUFSIZE, __blockSize)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2759
            /* console_fprintf(stderr, "got err-ret from AUDIO_SET_TXBUFSIZE\n"); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2760
            RETURN (self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2761
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2762
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2763
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2764
#endif // SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2765
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2766
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2767
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2768
setSampleRate:hz
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2769
    "set the sample rate"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2770
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2771
    |fd|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2772
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2773
    sampleRate := hz.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2774
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2775
    fd := self fileDescriptorOrNil.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2776
    fd isNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2777
        ^ self
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2778
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2779
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2780
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2781
    int f = __intVal(fd);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2782
    int __rate = __intVal(hz);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2783
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2784
    if (__isSmallInteger(fd) && __isSmallInteger(hz)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2785
        int __rateWant = __rate;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2786
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2787
# if defined(SNDCTL_DSP_SPEED)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2788
        if (ioctl(f, SNDCTL_DSP_SPEED, &__rate) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2789
            if (__rate != __rateWant) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2790
                console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2791
                hz = __MKSMALLINT(__rate);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2792
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2793
            __INST(sampleRate) = hz;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2794
            RETURN (self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2795
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2796
# else
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2797
#  if defined(SOUND_PCM_WRITE_RATE)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2798
        if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2799
            if (__rate != __rateWant) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2800
                console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2801
                hz = __MKSMALLINT(__rate);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2802
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2803
            __INST(sampleRate) = hz;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2804
            RETURN (self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2805
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2806
#  else
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2807
#   ifdef AUDIO_SET_SAMPLE_RATE /* hpux */
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2808
        if (ioctl (f, AUDIO_SET_SAMPLE_RATE, __rate)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2809
            /* console_fprintf(stderr, "got err-ret from AUDIO_SET_SAMPLE_RATE\n"); */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2810
            __INST(sampleRate) = hz;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2811
            RETURN (self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2812
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2813
#   endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2814
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2815
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2816
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2817
#endif // SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2818
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2819
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2820
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2821
     self writing setSampleRate:10000; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2822
     self writing setSampleRate:1000; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2823
     self writing setSampleRate:8000; dumpSettings; close
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2824
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2825
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2826
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2827
!SoundStream::DevAudio methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2828
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2829
supportedAudioFormats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2830
    "return a collection of supported audio formats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2831
     possibly returned symbols are:
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2832
        U8        unsigned 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2833
        S8        signed 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2834
        U16       unsigned 16bit samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2835
        U16_LE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2836
        U16_BE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2837
        S16       signed 16bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2838
        S16_LE    signed 16bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2839
        S16_BE    signed 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2840
        S24       signed 24bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2841
        S24_LE    signed 24bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2842
        S24_BE    signed 24bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2843
        S32       signed 32bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2844
        S32_LE    signed 32bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2845
        S32_BE    signed 32bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2846
        F32       float samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2847
        MPEG      audio mpeg encoded
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2848
        MU_LAW    u-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2849
        A_LAW     a-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2850
        IMA_ADPCM adpcm encoded
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2851
     the set of returned symbols depends on the underlying sound hardware.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2852
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2853
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2854
    |fd audioFormatMask
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2855
     supportedFormats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2856
     supports_MU_LAW supports_A_LAW supports_MPEG
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2857
     supports_IMA_ADPCM
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2858
     supports_S8 supports_U8
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2859
     supports_S16_LE supports_S16_BE
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2860
     supports_U16_LE supports_U16_BE
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2861
     supports_U32_LE supports_U32_BE
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2862
     supports_S24_LE supports_S24_BE
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2863
     supports_S32_LE supports_S32_BE
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2864
     supports_F32
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2865
    |
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2866
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2867
    fd := self fileDescriptorOrNil.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2868
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2869
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2870
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2871
    supports_MU_LAW = true;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2872
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2873
    if (fd != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2874
        int f = __intVal(fd);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2875
        int __audioFormatMask = 0;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2876
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2877
# if defined(SNDCTL_DSP_GETFMTS)
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2878
        if (ioctl(f, SNDCTL_DSP_GETFMTS, &__audioFormatMask) >= 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2879
            audioFormatMask = __MKSMALLINT(__audioFormatMask);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2880
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2881
#  ifdef AFMT_MU_LAW
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2882
            supports_MU_LAW = (__audioFormatMask & AFMT_MU_LAW) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2883
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2884
#  ifdef AFMT_A_LAW
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2885
            supports_A_LAW = (__audioFormatMask & AFMT_A_LAW) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2886
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2887
#  ifdef AFMT_IMA_ADPCM
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2888
            supports_IMA_ADPCM = (__audioFormatMask & AFMT_IMA_ADPCM) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2889
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2890
#  ifdef AFMT_U8
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2891
            supports_U8 = (__audioFormatMask & AFMT_U8) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2892
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2893
#  ifdef AFMT_S16_LE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2894
            supports_S16_LE = (__audioFormatMask & AFMT_S16_LE) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2895
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2896
#  ifdef AFMT_S16_BE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2897
            supports_S16_BE = (__audioFormatMask & AFMT_S16_BE) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2898
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2899
#  ifdef AFMT_S8
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2900
            supports_S8 = (__audioFormatMask & AFMT_S8) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2901
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2902
#  ifdef AFMT_U16_LE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2903
            supports_U16_LE = (__audioFormatMask & AFMT_U16_LE) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2904
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2905
#  ifdef AFMT_U16_BE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2906
            supports_U16_BE = (__audioFormatMask & AFMT_U16_BE) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2907
#  endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2908
#  ifdef AFMT_MPEG
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2909
            supports_MPEG = (__audioFormatMask & AFMT_MPEG) ? true : false;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2910
#  endif
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2911
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2912
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2913
# endif // SNDCTL_DSP_GETFMTS
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2914
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2915
# ifdef hpux
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2916
    supports_A_LAW = true;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2917
    supports_S16_BE = true;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2918
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2919
#endif /* SUPPORT_DEV_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2920
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2921
    supportedFormats := IdentitySet new.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2922
    (supports_MU_LAW ? false) ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2923
        supportedFormats add:#'MU_LAW'
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2924
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2925
    (supports_A_LAW ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2926
        supportedFormats add:#'A_LAW'
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2927
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2928
    (supports_IMA_ADPCM ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2929
        supportedFormats add:#'IMA_ADPCM'
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2930
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2931
    (supports_MPEG ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2932
        supportedFormats add:#'MPEG'
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2933
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2934
    (supports_S8 ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2935
        supportedFormats add:#'S8'
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2936
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2937
    (supports_U8 ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2938
        supportedFormats add:#'U8'
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2939
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2940
    (supports_S16_LE ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2941
        supportedFormats add:#'S16_LE'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2942
        UninterpretedBytes isBigEndian ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2943
            supportedFormats add:#'S16'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2944
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2945
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2946
    (supports_S16_BE ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2947
        supportedFormats add:#'S16_BE'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2948
        UninterpretedBytes isBigEndian ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2949
            supportedFormats add:#'S16'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2950
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2951
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2952
    (supports_S24_LE ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2953
        supportedFormats add:#'S24_LE'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2954
        UninterpretedBytes isBigEndian ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2955
            supportedFormats add:#'S24'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2956
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2957
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2958
    (supports_S24_BE ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2959
        supportedFormats add:#'S24_BE'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2960
        UninterpretedBytes isBigEndian ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2961
            supportedFormats add:#'S24'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2962
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2963
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2964
    (supports_S32_LE ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2965
        supportedFormats add:#'S32_LE'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2966
        UninterpretedBytes isBigEndian ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2967
            supportedFormats add:#'S32'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2968
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2969
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2970
    (supports_S32_BE ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2971
        supportedFormats add:#'S32_BE'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2972
        UninterpretedBytes isBigEndian ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2973
            supportedFormats add:#'S32'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2974
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2975
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2976
    (supports_U16_LE ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2977
        supportedFormats add:#'U16_LE'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2978
        UninterpretedBytes isBigEndian ifFalse:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2979
            supportedFormats add:#'U16'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2980
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2981
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2982
    (supports_U16_BE ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2983
        supportedFormats add:#'U16_BE'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2984
        UninterpretedBytes isBigEndian ifTrue:[
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2985
            supportedFormats add:#'U16'.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2986
        ]
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2987
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2988
    (supports_F32 ? false)  ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  2989
        supportedFormats add:#'F32'
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2990
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2991
    ^ supportedFormats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2992
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2993
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2994
     |s formats|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2995
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2996
     s := self writing.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2997
     formats := s supportedAudioFormats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2998
     s close.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  2999
     formats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3000
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3001
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3002
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3003
!SoundStream::DevAudio methodsFor:'reading'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3004
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3005
nextBytes:count into:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3006
    "read the next count bytes into an object and return the number of
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3007
     bytes read or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3008
     Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3009
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3010
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3011
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3012
   /*
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3013
    * redefined to work around a bug in the linux sound driver;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3014
    * if a read is interrupted (EINTR), it is not defined, how many
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3015
    * bytes have been read from the device.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3016
    *
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3017
    * As a workaround, disable signals here to prevent being interrupted.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3018
    */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3019
    int cnt, offs, objSize, n;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3020
    char *cp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3021
    OBJ fp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3022
    FILE *f;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3023
    int fd;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3024
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3025
    if ((fp = __INST(handle)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3026
        f = __FILEVal(fp);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3027
        if (__INST(mode) != @symbol(writeonly)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3028
            if (__bothSmallInteger(count, start)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3029
                cnt = __intVal(count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3030
                offs = __intVal(start) - 1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3031
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3032
                objSize = _Size(anObject) - OHDR_SIZE;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3033
                if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3034
                    do {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3035
                        cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3036
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3037
                        n = cnt;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3038
# ifdef LINUX
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3039
                        sigsetmask(~0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3040
# endif
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3041
                        if (__INST(buffered) == true) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3042
                            n = fread(cp, 1, n, f);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3043
                        } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3044
                            fd = fileno(f);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3045
                            n = read(fd, cp, n);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3046
                        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3047
# ifdef LINUX
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3048
                        sigsetmask(0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3049
# endif
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3050
                        __BEGIN_INTERRUPTABLE__
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3051
                        __END_INTERRUPTABLE__
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3052
                        // console_fprintf(stderr, "SoundStream: read %d bytes\n", n);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3053
                        if (n > 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3054
                            offs += n;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3055
                            cnt -= n;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3056
                        } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3057
                            if (n < 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3058
                                console_fprintf(stderr, "read error: %d\n", __threadErrno);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3059
                                RETURN (count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3060
                            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3061
                        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3062
                    } while (cnt);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3063
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3064
                RETURN (count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3065
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3066
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3067
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3068
#endif /* SUPPORT_DEV_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3069
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3070
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3071
    self errorUnsupportedOperation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3072
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3073
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3074
!SoundStream::DevAudio methodsFor:'writing'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3075
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3076
nextPutBytes:count from:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3077
    "write count bytes from an object starting at index start.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3078
     return the number of bytes written or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3079
     Redefined, since IRIS audio library cannot be used with stdio.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3080
     (at least I don't know). Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3081
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3082
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3083
#ifdef SUPPORT_DEV_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3084
   /*
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3085
    * redefine to work around a bug in the linux sound driver;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3086
    * if a write is interrupted (EINTR), it is not defined, how many
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3087
    * bytes have been written to the device.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3088
    * I.e. a retry of the write may lead to ever-playing without ever
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3089
    * finishing.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3090
    *
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3091
    * As a workaround, disable signals here to prevent the write from
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3092
    * being interrupted.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3093
    */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3094
    int cnt, offs, objSize, n;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3095
    char *cp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3096
    OBJ fp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3097
    FILE *f;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3098
    int fd;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3099
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3100
    if ((fp = __INST(handle)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3101
        f = __FILEVal(fp);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3102
        if (__INST(mode) != @symbol(readonly)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3103
            if (__bothSmallInteger(count, start)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3104
                cnt = __intVal(count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3105
                offs = __intVal(start) - 1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3106
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3107
                objSize = _Size(anObject) - OHDR_SIZE;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3108
                if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3109
                    do {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3110
                        cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3111
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3112
                        n = cnt;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3113
# ifdef LINUX
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3114
                        sigsetmask(~0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3115
# endif
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3116
                        if (__INST(buffered) == true) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3117
                            n = fwrite(cp, 1, n, f);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3118
                        } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3119
                            fd = fileno(f);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3120
                            n = write(fd, cp, n);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3121
                        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3122
# ifdef LINUX
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3123
                        sigsetmask(0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3124
# endif
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3125
                        __BEGIN_INTERRUPTABLE__
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3126
                        __END_INTERRUPTABLE__
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3127
                        if (n > 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3128
                            offs += n;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3129
                            cnt -= n;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3130
                        } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3131
                            if (n < 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3132
                                console_fprintf(stderr, "write error: %d\n", __threadErrno);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3133
                                RETURN (count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3134
                            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3135
                        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3136
                    } while (cnt);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3137
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3138
                RETURN (count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3139
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3140
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3141
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3142
#endif /* SUPPORT_DEV_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3143
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3144
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3145
    ^ self errorUnsupportedOperation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3146
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3147
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3148
!SoundStream::IRISAudio class methodsFor:'documentation'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3149
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3150
documentation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3151
"
5424
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3152
    interface to the silicon graphics IRIX audio system
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3153
"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3154
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3155
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3156
!SoundStream::IRISAudio class methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3157
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3158
isSupported
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3159
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3160
#ifdef SUPPORT_IRIS_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3161
    RETURN(true);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3162
#endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3163
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3164
    ^ false.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3165
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3166
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3167
!SoundStream::IRISAudio methodsFor:'misc'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3168
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3169
flush
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3170
    "wait until all sound has been played"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3171
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3172
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3173
#ifdef SUPPORT_IRIS_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3174
    OPJ port;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3175
    ALport p;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3176
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3177
    if ((port = __INST(alPort)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3178
        p = __ALportVal(port);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3179
        while (ALgetfilled(p) > 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3180
            sginap(1);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3181
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3182
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3183
    RETURN(self);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3184
#endif /* SUPPORT_IRIS_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3185
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3186
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3187
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3188
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3189
!SoundStream::IRISAudio methodsFor:'open & close'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3190
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3191
closeFile
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3192
    "a stream has been collected - close the file"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3193
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3194
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3195
#ifdef SUPPORT_IRIS_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3196
    OBJ port;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3197
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3198
    if ((port = __INST(alPort)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3199
        __INST(alPort) = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3200
        ALcloseport(__ALportVal(port));
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3201
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3202
    RETURN (self);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3203
#endif /* SUPPORT_IRIS_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3204
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3205
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3206
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3207
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3208
openWithMode:aMode attributes:attributeSpec
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3209
    |ok error errorStringOrNil|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3210
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3211
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3212
#ifdef SUPPORT_IRIS_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3213
    ALconfig config;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3214
    ALport p;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3215
    long params[] = {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3216
        AL_INPUT_SOURCE, AL_INPUT_MIC,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3217
        AL_INPUT_RATE, 8000,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3218
        AL_OUTPUT_RATE, 8000,
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3219
    };
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3220
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3221
    ok = false.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3222
    config = ALnewconfig();
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3223
    if (__INST(numberOfChannels) == __MKSMALLINT(2))
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3224
        ALsetchannels(config, AL_STEREO);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3225
    else
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3226
        ALsetchannels(config, AL_MONO);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3227
    if (__INST(bitsPerSample) == __MKSMALLINT(16))
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3228
        ALsetwidth(config, AL_SAMPLE_16);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3229
    else
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3230
        ALsetwidth(config, AL_SAMPLE_8);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3231
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3232
    if (__isSmallInteger(__INST(sampleRate)))
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3233
        params[3] = params[5] = __intVal(__INST(sampleRate));
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3234
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3235
    ALsetparams(AL_DEFAULT_DEVICE, params, 6);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3236
    p = ALopenport("smallchat", (char *)_stringVal(aMode), config);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3237
    if (p) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3238
        OBJ t;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3239
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3240
        t = __MKEXTERNALADDRESS(p); __INST(alPort) = t; __STORE(self, t);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3241
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3242
        __INST(alPort) = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3243
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3244
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3245
    __INST(binary) = true;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3246
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3247
    ALfreeconfig(config);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3248
    /*
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3249
     * get the parameters actually installed
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3250
     */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3251
    config = ALgetconfig(p);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3252
    switch (ALgetchannels(config)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3253
        default:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3254
            /* cannot happen */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3255
        case AL_MONO:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3256
            __INST(numberOfChannels) = __MKSMALLINT(1);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3257
            break;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3258
        case AL_STEREO:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3259
            __INST(numberOfChannels) = __MKSMALLINT(2);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3260
            break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3261
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3262
    switch (ALgetwidth(config)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3263
        default:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3264
            /* cannot happen */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3265
        case AL_SAMPLE_8:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3266
            __INST(bitsPerSample) = __MKSMALLINT(8);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3267
            break;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3268
        case AL_SAMPLE_16:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3269
            __INST(bitsPerSample) = __MKSMALLINT(16);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3270
            break;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3271
        case AL_SAMPLE_24:
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3272
            __INST(bitsPerSample) = __MKSMALLINT(24);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3273
            break;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3274
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3275
    ALgetparams(AL_DEFAULT_DEVICE, params, 6);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3276
    __INST(sampleRate) = __MKSMALLINT(params[3]);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3277
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3278
    ALfreeconfig(config);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3279
    ok = true;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3280
out:;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3281
#endif /* SUPPORT_IRIS_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3282
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3283
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3284
    ok == false ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3285
        lastErrorString := errorStringOrNil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3286
        lastErrorNumber := error ? -1.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3287
        self openError:error.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3288
        "normally not reached"
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3289
        ^ nil.
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3290
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3291
    self registerForFinalization.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3292
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3293
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3294
!SoundStream::IRISAudio methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3295
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3296
supportedAudioFormats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3297
    "return a collection of supported audio formats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3298
     possibly returned symbols are:
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3299
        U8        unsigned 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3300
        S8        signed 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3301
        U16       unsigned 16bit samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3302
        U16_LE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3303
        U16_BE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3304
        S16       signed 16bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3305
        S16_LE    signed 16bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3306
        S16_BE    signed 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3307
        S24       signed 24bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3308
        S24_LE    signed 24bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3309
        S24_BE    signed 24bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3310
        S32       signed 32bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3311
        S32_LE    signed 32bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3312
        S32_BE    signed 32bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3313
        F32       float samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3314
        MPEG      audio mpeg encoded
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3315
        MU_LAW    u-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3316
        A_LAW     a-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3317
        IMA_ADPCM adpcm encoded
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3318
     the set of returned symbols depends on the underlying sound hardware.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3319
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3320
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3321
    ^ #( U8 U16_BE U16 )
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3322
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3323
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3324
     |s formats|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3325
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3326
     s := self writing.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3327
     formats := s supportedAudioFormats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3328
     s close.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3329
     formats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3330
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3331
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3332
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3333
!SoundStream::IRISAudio methodsFor:'reading'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3334
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3335
nextBytes:count into:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3336
    "read the next count bytes into an object and return the number of
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3337
     bytes read or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3338
     Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3339
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3340
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3341
#ifdef SUPPORT_IRIS_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3342
  {
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3343
    OBJ port;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3344
    ALport p;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3345
    int cnt, offs, nSamp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3346
    int objSize;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3347
    char *cp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3348
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3349
    if ((port = __INST(alPort)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3350
        if (__INST(mode) != _writeonly) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3351
            if (__bothSmallInteger(count, start)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3352
                cnt = __intVal(count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3353
                offs = __intVal(start) - 1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3354
                p = __ALportVal(port);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3355
                objSize = _Size(anObject) - OHDR_SIZE;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3356
                if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3357
                    cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3358
                    if (__INST(bitsPerSample) == __MKSMALLINT(16))
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3359
                        nSamp = cnt / 2;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3360
                    else
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3361
                        nSamp = cnt;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3362
                    ALreadsamps(p, cp, nSamp);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3363
                    RETURN ( __MKSMALLINT(cnt) );
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3364
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3365
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3366
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3367
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3368
  }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3369
#endif /* SUPPORT_IRIS_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3370
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3371
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3372
    self errorUnsupportedOperation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3373
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3374
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3375
!SoundStream::IRISAudio methodsFor:'writing'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3376
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3377
nextPutBytes:count from:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3378
    "write count bytes from an object starting at index start.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3379
     return the number of bytes written or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3380
     Redefined, since IRIS audio library cannot be used with stdio.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3381
     (at least I don't know). Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3382
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3383
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3384
#ifdef SUPPORT_IRIS_AUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3385
  {
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3386
    OBJ port;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3387
    ALport p;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3388
    int cnt, offs, nSamp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3389
    int objSize;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3390
    char *cp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3391
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3392
    if ((port = __INST(alPort)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3393
        if (__INST(mode) != @symbol(readonly)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3394
            if (__bothSmallInteger(count, start)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3395
                cnt = __intVal(count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3396
                offs = __intVal(start) - 1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3397
                p = __ALportVal(port);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3398
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3399
                /*
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3400
                 * compute number of samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3401
                 */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3402
                objSize = _Size(anObject) - OHDR_SIZE;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3403
                if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3404
                    cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3405
                    if (__INST(bitsPerSample) == __MKSMALLINT(16))
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3406
                        nSamp = cnt / 2;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3407
                    else
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3408
                        nSamp = cnt;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3409
                    ALwritesamps(p, cp, cnt);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3410
                    RETURN ( count );
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3411
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3412
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3413
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3414
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3415
  }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3416
#endif /* SUPPORT_IRIS_AUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3417
%}.
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
  3418
    self errorUnsupportedOperation
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3419
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3420
5424
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3421
!SoundStream::JackAudio class methodsFor:'documentation'!
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3422
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3423
documentation
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3424
"
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3425
    interface to the jack audio system
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3426
"
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3427
! !
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3428
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3429
!SoundStream::JackAudio class methodsFor:'queries'!
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3430
5423
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3431
defaultAudioFormat
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3432
    ^ #F32
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3433
!
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3434
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3435
isSupported
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3436
%{
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3437
#ifdef SUPPORT_JACKAUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3438
    RETURN(true);
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3439
#endif
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3440
%}.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3441
    ^ false.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3442
! !
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3443
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3444
!SoundStream::JackAudio methodsFor:'open & close'!
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3445
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3446
closeFile
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3447
    "a stream has been collected - close the file"
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3448
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3449
%{
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3450
#ifdef SUPPORT_JACKAUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3451
    OBJ str;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3452
    if ((str = __INST(handle1)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3453
        struct jackStreamData* streamData = (struct jackStreamData*)__externalAddressVal(str);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3454
        struct jackBuffer* buffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3455
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3456
        if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3457
            fprintf(stderr, "jack close\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3458
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3459
        __externalAddressVal(str) = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3460
        __INST(handle1) = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3461
        jack_client_close( streamData->jack_client );
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3462
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3463
        LOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3464
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3465
        buffer = streamData->currentBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3466
        streamData->currentBuffer = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3467
        streamData->lastBuffer = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3468
        while (buffer != NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3469
            struct jackBuffer* nextBuffer = buffer->nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3470
            free(buffer->sampleData);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3471
            free(buffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3472
            buffer = nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3473
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3474
        buffer = streamData->freeList;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3475
        streamData->freeList = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3476
        while (buffer != NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3477
            struct jackBuffer* nextBuffer = buffer->nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3478
            free(buffer->sampleData);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3479
            free(buffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3480
            buffer = nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3481
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3482
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3483
        UNLOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3484
        RELEASELOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3485
        free(streamData);
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3486
    }
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3487
    RETURN (self);
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3488
#endif // SUPPORT_JACKAUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3489
%}.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3490
!
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3491
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3492
openWithMode:aMode attributes:attributeSpec
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3493
    |ok error errorStringOrNil|
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3494
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3495
    openMode := aMode.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3496
    openAttributes := attributeSpec.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3497
%{
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3498
#ifdef SUPPORT_JACKAUDIO
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3499
    jack_options_t options = JackNullOption;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3500
    jack_client_t *client;
5425
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3501
    jack_port_t *output_port;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3502
    struct jackStreamData* streamData;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3503
    int nChannels, sampleRate, bytesPerSample;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3504
#   define FRAMES_PER_BUFFER 128
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3505
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3506
    ok = false;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3507
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3508
    if (__isSmallInteger(__INST(numberOfChannels))) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3509
        nChannels = __intVal(__INST(numberOfChannels));
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3510
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3511
        nChannels = 1;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3512
    }
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3513
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3514
    if (__INST(audioFormat) == @symbol(F32)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3515
        bytesPerSample = 4;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3516
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3517
        fprintf(stderr, "SoundStream [warning]: only f32 supported with jack\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3518
        errorStringOrNil = __MKSTRING("audioFormat must be f32 with jack");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3519
        goto out;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3520
    }
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3521
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3522
    streamData = (struct jackStreamData*)malloc(sizeof(struct jackStreamData));
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3523
    if (streamData == NULL) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3524
        fprintf(stderr, "SoundStream [warning]: failed to allocate jackStream\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3525
        errorStringOrNil = __MKSTRING("failed to allocate jackStream");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3526
        goto out;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3527
    }
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3528
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3529
    if ((client = jack_client_open ("stx", JackNullOption, NULL)) == 0) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3530
        fprintf(stderr, "SoundStream [warning]: JACK server not running?\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3531
        free(streamData);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3532
        errorStringOrNil = __MKSTRING("JACK server not running");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3533
        goto out;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3534
    }
5424
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3535
    jack_set_process_callback (client, jack_callback, 0);
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3536
5425
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3537
    output_port = jack_port_register (client, "stx_out", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3538
    sampleRate = jack_get_sample_rate (client);
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3539
    __INST(sampleRate) = __MKSMALLINT(sampleRate);
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3540
    // if (__isSmallInteger(__INST(sampleRate))) {
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3541
    //     sampleRate = __intVal(__INST(sampleRate));
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3542
    // } else {
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3543
    //     fprintf(stderr, "SoundStream [warning]: using default sampleRate 8000\n");
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3544
    //     sampleRate = 8000;
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3545
    // }
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3546
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3547
    streamData->jack_client = client;
5425
17cec979acdf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5424
diff changeset
  3548
    streamData->jack_output_port = output_port;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3549
    INITLOCK(streamData->lock);
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3550
    streamData->readOffset = 0;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3551
    streamData->bytesPerSample = bytesPerSample;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3552
    streamData->nChannels = nChannels;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3553
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3554
    streamData->currentBuffer = NULL;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3555
    streamData->lastBuffer = NULL;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3556
    streamData->freeList = NULL;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3557
    streamData->hasFinished = 0;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3558
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3559
    {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3560
        OBJ t;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3561
        t = __MKEXTERNALADDRESS(streamData); __INST(handle1) = t; __STORE(self, t);
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3562
    }
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3563
    __INST(binary) = true;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3564
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3565
//    paErr = Pa_SetStreamFinishedCallback( stream, &paStreamFinished );
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3566
//    if( paErr != paNoError ) {
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3567
//        fprintf(stderr, "SoundStream [warning]: setFinishedCallback: %s\n", Pa_GetErrorText( paErr ));
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3568
//        free(paStreamData);
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3569
//        errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr ));
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3570
//        goto out;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3571
//    };
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3572
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3573
    ok = true;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3574
out:;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3575
#endif /* SUPPORT_JACKAUDIO */
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3576
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3577
%}.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3578
    ok == false ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3579
        lastErrorString := errorStringOrNil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3580
        lastErrorNumber := error ? -1.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3581
        self openError:error.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3582
        "normally not reached"
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3583
        ^ nil.
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3584
    ].
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3585
    self registerForFinalization.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3586
!
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3587
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3588
reopenStream
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3589
    handle1 isNil ifTrue:[^ self].
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3590
    self closeFile.
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3591
    self openWithMode:openMode attributes:openAttributes
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3592
! !
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3593
5423
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3594
!SoundStream::JackAudio methodsFor:'queries'!
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3595
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3596
supportedAudioFormats
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3597
    "return a collection of supported audio formats.
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3598
     possibly returned symbols are:
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3599
        U8        unsigned 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3600
        S8        signed 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3601
        U16       unsigned 16bit samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3602
        U16_LE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3603
        U16_BE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3604
        S16       signed 16bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3605
        S16_LE    signed 16bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3606
        S16_BE    signed 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3607
        S24       signed 24bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3608
        S24_LE    signed 24bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3609
        S24_BE    signed 24bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3610
        S32       signed 32bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3611
        S32_LE    signed 32bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3612
        S32_BE    signed 32bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3613
        F32       float samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3614
        MPEG      audio mpeg encoded
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3615
        MU_LAW    u-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3616
        A_LAW     a-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3617
        IMA_ADPCM adpcm encoded
5423
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3618
     the set of returned symbols depends on the underlying sound hardware.
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3619
    "
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3620
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3621
    ^ #(F32)
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3622
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3623
    "
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3624
     |s formats|
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3625
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3626
     s := self writing.
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3627
     formats := s supportedAudioFormats.
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3628
     s close.
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3629
     formats
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3630
    "
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3631
! !
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3632
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3633
!SoundStream::PortAudio class methodsFor:'default values'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3634
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3635
defaultSampleRate
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3636
    "minimum, supported by all audio systems"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3637
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3638
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3639
#ifdef SUPPORT_PORTAUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3640
    RETURN (__MKSMALLINT(PORTAUDIO_DEFAULT_FREQ));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3641
#endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3642
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3643
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3644
    ^ 8000
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3645
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3646
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3647
!SoundStream::PortAudio class methodsFor:'documentation'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3648
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3649
documentation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3650
"
5424
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  3651
    interface to the portaudio library
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3652
"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3653
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3654
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3655
!SoundStream::PortAudio class methodsFor:'initialization'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3656
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3657
primitiveInitializeDevice
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3658
    |errorMessageOrNil|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3659
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3660
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3661
#ifdef SUPPORT_PORTAUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3662
    PaError paErr = 0;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3663
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3664
    if (DEBUGGING) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3665
        fprintf(stderr, "calling Pa_Initialize...\n");
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3666
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3667
    if ((paErr = Pa_Initialize()) != paNoError ) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3668
        errorMessageOrNil = __MKSTRING(Pa_GetErrorText( paErr ) );
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3669
        fprintf(stderr, "SoundStream [error]: Pa_Initialize failed\n");
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3670
    };
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3671
#endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3672
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3673
    errorMessageOrNil notNil ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3674
        self error:'failed to initialize audio device: ',errorMessageOrNil
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3675
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3676
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3677
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3678
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3679
!SoundStream::PortAudio class methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3680
5423
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3681
defaultAudioFormat
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3682
    ^ #S16
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3683
!
90f37d96ffb1 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5422
diff changeset
  3684
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3685
isSupported
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3686
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3687
#ifdef SUPPORT_PORTAUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3688
    RETURN(true);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3689
#endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3690
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3691
    ^ false.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3692
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3693
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3694
!SoundStream::PortAudio methodsFor:'misc'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3695
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3696
flush
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3697
    "wait until all sound has been played"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3698
5419
012b0bf375d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5418
diff changeset
  3699
    [self hasOutputPending] whileTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3700
        Delay waitForMilliseconds:20.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3701
        "/ Processor yield
5419
012b0bf375d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5418
diff changeset
  3702
    ]
012b0bf375d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5418
diff changeset
  3703
!
012b0bf375d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5418
diff changeset
  3704
012b0bf375d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5418
diff changeset
  3705
hasOutputPending
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3706
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3707
#ifdef SUPPORT_PORTAUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3708
    OBJ str;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3709
    if ((str = __INST(handle1)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3710
        struct paStreamData* streamData = (struct paStreamData*)__externalAddressVal(str);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3711
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3712
        RETURN ((streamData->currentBuffer != NULL) ? true : false);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3713
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3714
#endif /* SUPPORT_PORTAUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3715
%}.
5419
012b0bf375d0 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5418
diff changeset
  3716
    ^ false
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3717
!
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3718
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3719
outputBytesPending
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3720
%{
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3721
#ifdef SUPPORT_PORTAUDIO
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3722
    OBJ str;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3723
    int n = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3724
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3725
    if ((str = __INST(handle1)) != nil) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3726
        struct paStreamData* streamData = (struct paStreamData*)__externalAddressVal(str);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3727
        int offs;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3728
        struct paBuffer *buffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3729
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3730
        if (streamData != NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3731
            offs = streamData->readOffset;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3732
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3733
            buffer = streamData->currentBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3734
            if (buffer != NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3735
                n = buffer->bufferSize - offs;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3736
                while ((buffer = buffer->nextBuffer) != NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3737
                    n += buffer->bufferSize;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3738
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3739
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3740
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3741
    }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3742
    RETURN (__MKSMALLINT(n));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3743
#endif /* SUPPORT_PORTAUDIO */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3744
%}.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3745
    ^ 0
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3746
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3747
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3748
!SoundStream::PortAudio methodsFor:'open & close'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3749
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3750
closeFile
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3751
    "a stream has been collected - close the file"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3752
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3753
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3754
#ifdef SUPPORT_PORTAUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3755
    OBJ str;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3756
    if ((str = __INST(handle1)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3757
        struct paStreamData* streamData = (struct paStreamData*)__externalAddressVal(str);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3758
        struct paBuffer* buffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3759
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3760
        if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3761
            fprintf(stderr, "pa close\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3762
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3763
        __externalAddressVal(str) = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3764
        __INST(handle1) = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3765
        // Pa_StopStream( streamData->stream );
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3766
        Pa_CloseStream( streamData->stream );
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3767
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3768
        LOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3769
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3770
        buffer = streamData->currentBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3771
        streamData->currentBuffer = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3772
        streamData->lastBuffer = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3773
        while (buffer != NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3774
            struct paBuffer* nextBuffer = buffer->nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3775
            free(buffer->sampleData);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3776
            free(buffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3777
            buffer = nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3778
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3779
        buffer = streamData->freeList;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3780
        streamData->freeList = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3781
        while (buffer != NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3782
            struct paBuffer* nextBuffer = buffer->nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3783
            free(buffer->sampleData);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3784
            free(buffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3785
            buffer = nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3786
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3787
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3788
        UNLOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3789
        RELEASELOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3790
        free(streamData);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3791
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3792
    RETURN (self);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3793
#endif // SUPPORT_PORTAUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3794
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3795
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3796
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3797
openWithMode:aMode attributes:attributeSpec
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3798
    |ok error errorStringOrNil|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3799
5409
36e736c349b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5408
diff changeset
  3800
    openMode := aMode.
36e736c349b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5408
diff changeset
  3801
    openAttributes := attributeSpec.
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3802
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3803
#ifdef SUPPORT_PORTAUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3804
    static PaStreamParameters outputParameters;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3805
    PaStream *stream;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3806
    PaError paErr;
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3807
    struct paStreamData* streamData;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3808
    int nChannels, sampleRate, bytesPerSample;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3809
#   define FRAMES_PER_BUFFER 128
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3810
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3811
    ok = false;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3812
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3813
    /* default output device */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3814
    outputParameters.device = Pa_GetDefaultOutputDevice();
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3815
    if (outputParameters.device == paNoDevice) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3816
        fprintf(stderr, "SoundStream [warning]: No default output device.\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3817
        errorStringOrNil = __MKSTRING("No default output device");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3818
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3819
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3820
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3821
    if (__isSmallInteger(__INST(numberOfChannels))) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3822
        nChannels = __intVal(__INST(numberOfChannels));
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3823
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3824
        nChannels = 1;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3825
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3826
    outputParameters.channelCount = nChannels;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3827
    outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3828
    outputParameters.hostApiSpecificStreamInfo = NULL;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3829
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3830
    // The standard formats paFloat32, paInt16, paInt32, paInt24, paInt8
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3831
    // and aUInt8 are usually implemented by all implementations.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3832
    // The floating point representation (paFloat32) uses +1.0 and -1.0 as the
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3833
    // maximum and minimum respectively.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3834
    // paUInt8 is an unsigned 8 bit format where 128 is considered "ground"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3835
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3836
    if (__INST(audioFormat) == @symbol(S16)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3837
        outputParameters.sampleFormat = paInt16;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3838
        bytesPerSample = 2;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3839
    } else if (__INST(audioFormat) == @symbol(S32)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3840
        outputParameters.sampleFormat = paInt32;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3841
        bytesPerSample = 4;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3842
    } else if (__INST(audioFormat) == @symbol(S24)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3843
        outputParameters.sampleFormat = paInt24;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3844
        bytesPerSample = 3;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3845
    } else if (__INST(audioFormat) == @symbol(S8)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3846
        outputParameters.sampleFormat = paInt8;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3847
        bytesPerSample = 1;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3848
    } else if (__INST(audioFormat) == @symbol(F32)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3849
        outputParameters.sampleFormat = paFloat32;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3850
        bytesPerSample = 4;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3851
    } else if (__INST(audioFormat) == @symbol(U8)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3852
        outputParameters.sampleFormat = paUInt8;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3853
        bytesPerSample = 1;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3854
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3855
        fprintf(stderr, "SoundStream [warning]: unknown format - using U8\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3856
        outputParameters.sampleFormat = paUInt8;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3857
        bytesPerSample = 1;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3858
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3859
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3860
    if (__isSmallInteger(__INST(sampleRate))) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3861
        sampleRate = __intVal(__INST(sampleRate));
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3862
    } else {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3863
        fprintf(stderr, "SoundStream [warning]: using default sampleRate 8000\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3864
        sampleRate = 8000;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3865
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3866
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3867
    streamData = (struct paStreamData*)malloc(sizeof(struct paStreamData));
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3868
    if (streamData == NULL) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3869
        fprintf(stderr, "SoundStream [warning]: failed to allocate paStream\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3870
        errorStringOrNil = __MKSTRING("failed to allocate paStream");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3871
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3872
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3873
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3874
    paErr = Pa_OpenStream(
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3875
              &stream,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3876
              NULL, /* no input */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3877
              &outputParameters,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3878
              sampleRate,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3879
              FRAMES_PER_BUFFER,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3880
              paClipOff,      /* we won't output out of range samples so don't bother clipping them */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3881
              paCallback,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3882
              streamData );
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3883
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3884
    if (paErr != paNoError) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3885
        fprintf(stderr, "SoundStream [warning]: openStream: %s\n", Pa_GetErrorText( paErr ));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3886
        free(streamData);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3887
        errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr ));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3888
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3889
    }
5421
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3890
    streamData->stream = stream;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3891
    INITLOCK(streamData->lock);
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3892
    streamData->readOffset = 0;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3893
    streamData->bytesPerSample = bytesPerSample;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3894
    streamData->nChannels = nChannels;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3895
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3896
    streamData->currentBuffer = NULL;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3897
    streamData->lastBuffer = NULL;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3898
    streamData->freeList = NULL;
9249f574dc60 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5419
diff changeset
  3899
    streamData->hasFinished = 0;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3900
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3901
    {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3902
        OBJ t;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3903
        t = __MKEXTERNALADDRESS(streamData); __INST(handle1) = t; __STORE(self, t);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3904
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3905
    __INST(binary) = true;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3906
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3907
    paErr = Pa_SetStreamFinishedCallback( stream, &paStreamFinished );
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3908
    if( paErr != paNoError ) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3909
        fprintf(stderr, "SoundStream [warning]: setFinishedCallback: %s\n", Pa_GetErrorText( paErr ));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3910
        free(streamData);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3911
        errorStringOrNil = __MKSTRING(Pa_GetErrorText( paErr ));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3912
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3913
    };
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3914
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3915
    ok = true;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3916
out:;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3917
#endif /* SUPPORT_PORTAUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3918
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3919
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3920
    ok == false ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3921
        lastErrorString := errorStringOrNil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3922
        lastErrorNumber := error ? -1.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3923
        self openError:error.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3924
        "normally not reached"
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3925
        ^ nil.
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3926
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3927
    self registerForFinalization.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3928
5407
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3929
!
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3930
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3931
reopenStream
5408
909d03dd2329 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3932
    handle1 isNil ifTrue:[^ self].
5409
36e736c349b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5408
diff changeset
  3933
    self closeFile.
36e736c349b6 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5408
diff changeset
  3934
    self openWithMode:openMode attributes:openAttributes
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3935
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3936
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3937
!SoundStream::PortAudio methodsFor:'private'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3938
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3939
initialize
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3940
    "initialize for least common mode"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3941
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3942
    super initialize.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3943
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3944
    (IsInitialized ? false) ifFalse:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3945
        self class primitiveInitializeDevice
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3946
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3947
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3948
    "Created: 17.11.1995 / 17:28:14 / cg"
5407
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3949
!
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3950
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3951
setAudioFormat:aSymbol
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3952
    super setAudioFormat:aSymbol.
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3953
    self reopenStream
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3954
!
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3955
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3956
setChannels:numChannels
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3957
    super setChannels:numChannels.
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3958
    self reopenStream
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3959
!
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3960
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3961
setFragmentSize:blockSize
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3962
    super setFragmentSize:blockSize.
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3963
    self reopenStream
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3964
!
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3965
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3966
setSampleRate:hz
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3967
    super setSampleRate:hz.
7e6fb7096445 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5406
diff changeset
  3968
    self reopenStream
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3969
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3970
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3971
!SoundStream::PortAudio methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3972
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3973
supportedAudioFormats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3974
    "return a collection of supported audio formats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3975
     possibly returned symbols are:
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3976
        U8        unsigned 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3977
        S8        signed 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3978
        U16       unsigned 16bit samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3979
        U16_LE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3980
        U16_BE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3981
        S16       signed 16bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3982
        S16_LE    signed 16bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3983
        S16_BE    signed 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3984
        S24       signed 24bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3985
        S24_LE    signed 24bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3986
        S24_BE    signed 24bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3987
        S32       signed 32bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3988
        S32_LE    signed 32bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3989
        S32_BE    signed 32bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3990
        F32       float samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3991
        MPEG      audio mpeg encoded
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3992
        MU_LAW    u-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3993
        A_LAW     a-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  3994
        IMA_ADPCM adpcm encoded
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3995
     the set of returned symbols depends on the underlying sound hardware.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3996
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3997
5408
909d03dd2329 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 5407
diff changeset
  3998
    ^ #(U8 S8 S16_LE S16 S24_LE S24 S32_LE S32 F32)
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  3999
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4000
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4001
     |s formats|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4002
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4003
     s := self writing.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4004
     formats := s supportedAudioFormats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4005
     s close.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4006
     formats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4007
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4008
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4009
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4010
!SoundStream::PortAudio methodsFor:'reading'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4011
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4012
nextBytes:count into:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4013
    "read the next count bytes into an object and return the number of
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4014
     bytes read or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4015
     Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4016
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4017
    self errorUnsupportedOperation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4018
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4019
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4020
!SoundStream::PortAudio methodsFor:'writing'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4021
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4022
nextPutBytes:count from:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4023
    "write count bytes from an object starting at index start.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4024
     return the number of bytes written or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4025
     Redefined, since IRIS audio library cannot be used with stdio.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4026
     (at least I don't know). Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4027
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4028
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4029
#ifdef SUPPORT_PORTAUDIO
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4030
    OBJ str;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4031
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4032
    if ((str = __INST(handle1)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4033
        if (__INST(mode) != @symbol(readonly)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4034
            if (__bothSmallInteger(count, start)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4035
                // allocate a buffer
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4036
                struct paStreamData* streamData = (struct paStreamData*)__externalAddressVal(str);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4037
                int cnt = __intVal(count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4038
                int offs = __intVal(start) - 1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4039
                int objSize;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4040
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4041
                objSize = _Size(anObject) - OHDR_SIZE;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4042
                if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4043
                    struct paBuffer* newBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4044
                    struct paBuffer* toFree;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4045
                    int mustStart = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4046
                    unsigned char* newSampleData;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4047
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4048
                    // try freeList
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4049
                    LOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4050
                    if ((streamData->freeList != NULL)
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4051
                     && (streamData->freeList->bufferSize == cnt)) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4052
                        // reuse
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4053
                        newBuffer = streamData->freeList;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4054
                        streamData->freeList = newBuffer->nextBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4055
                        newSampleData = newBuffer->sampleData;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4056
                        toFree = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4057
                        if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4058
                            fprintf(stderr, "from free: %p (->%p)\n", newBuffer, newBuffer->sampleData);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4059
                        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4060
                    } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4061
                        // free them all
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4062
                        toFree = streamData->freeList;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4063
                        streamData->freeList = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4064
                        newBuffer = malloc(sizeof(struct paBuffer));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4065
                        newSampleData = malloc(cnt);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4066
                        newBuffer->sampleData = newSampleData;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4067
                        newBuffer->bufferSize = cnt;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4068
                        if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4069
                            fprintf(stderr, "alloc: %p (->%p)\n", newBuffer, newBuffer->sampleData);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4070
                        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4071
                    }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4072
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4073
                    memcpy(newSampleData, (__ByteArrayInstPtr(anObject)->ba_element)+offs, cnt);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4074
                    newBuffer->nextBuffer = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4075
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4076
                    if (streamData->lastBuffer == NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4077
                        // start stream's buffer list
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4078
                        streamData->currentBuffer = newBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4079
                        mustStart = 1;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4080
                    } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4081
                        // append to stream's buffer list
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4082
                        streamData->lastBuffer->nextBuffer = newBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4083
                    }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4084
                    streamData->lastBuffer = newBuffer;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4085
                    streamData->hasFinished = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4086
                    UNLOCK(streamData->lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4087
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4088
                    if (mustStart) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4089
                        PaError paErr = Pa_StartStream( streamData->stream );
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4090
                        if ( paErr != paNoError ) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4091
                            if (DEBUGGING) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4092
                                fprintf(stderr, "start error\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4093
                            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4094
                            RETURN (0);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4095
                        };
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4096
                    }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4097
                    RETURN (count);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4098
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4099
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4100
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4101
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4102
#endif /* SUPPORT_PORTAUDIO */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4103
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4104
%}.
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
  4105
    self errorUnsupportedOperation
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4106
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4107
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4108
!SoundStream::Win32DirectSound class methodsFor:'documentation'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4109
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4110
documentation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4111
"
5424
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  4112
    interface to the windows direct sound API
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4113
"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4114
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4115
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4116
!SoundStream::Win32DirectSound class methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4117
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4118
isSupported
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4119
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4120
#ifdef SUPPORT_WIN32_DIRECTSOUND
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4121
    RETURN(true);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4122
#endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4123
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4124
    ^ false.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4125
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4126
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4127
!SoundStream::Win32DirectSound methodsFor:'misc'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4128
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4129
flush
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4130
    "wait until all sound has been played"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4131
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4132
    "/ as yet unimplemented
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4133
    ^ self
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4134
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4135
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4136
!SoundStream::Win32DirectSound methodsFor:'open & close'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4137
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4138
closeFile
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4139
    "a stream has been collected - close the file"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4140
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4141
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4142
#ifdef SUPPORT_WIN32_DIRECTSOUND
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4143
    OBJ oDirectSound, oDSBuffer;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4144
    LPDIRECTSOUND       t_pDirectSound;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4145
    LPDIRECTSOUNDBUFFER t_pDSBuffer;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4146
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4147
    if ((oDSBuffer = __INST(pDSBuffer)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4148
        __INST(pDSBuffer) = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4149
        t_pDSBuffer = __DSBufferVal(oDSBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4150
        if (t_pDSBuffer) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4151
            IDirectSoundBuffer_Stop(t_pDSBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4152
            IDirectSoundBuffer_Release(t_pDSBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4153
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4154
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4155
    if ((oDirectSound = __INST(pDirectSound)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4156
        __INST(pDirectSound) = nil;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4157
        t_pDirectSound = __DirectSoundVal(oDirectSound);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4158
        if (t_pDirectSound) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4159
            IDirectSound_Release(t_pDirectSound);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4160
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4161
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4162
    RETURN (self);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4163
#endif /* SUPPORT_WIN32_DIRECTSOUND */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4164
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4165
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4166
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4167
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4168
openWithMode:aMode attributes:attributeSpec
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4169
    |ok error errorStringOrNil|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4170
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4171
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4172
#ifdef SUPPORT_WIN32_DIRECTSOUND
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4173
    HRESULT result;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4174
    LPDIRECTSOUND       t_pDirectSound;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4175
    LPDIRECTSOUNDBUFFER t_pDSBuffer, t_pDSPrimeBuffer;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4176
    WAVEFORMATEX        wfFormat;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4177
    DSBUFFERDESC        dsbdDesc, primarydsbDesc;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4178
    BYTE                *pDSBuffData;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4179
    int                 t_cbBufSize;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4180
    int                 dwDataLen;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4181
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4182
    ok = false;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4183
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4184
    /* Create the DS object */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4185
    if ((result = DirectSoundCreate(NULL, &t_pDirectSound, NULL)) != DS_OK) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4186
        console_fprintf(stderr,"SoundStream: Cannot open default sound device!!\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4187
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4188
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4189
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4190
    /* Define the wave format structure */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4191
    wfFormat.wFormatTag = WAVE_FORMAT_PCM;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4192
    wfFormat.nChannels = __intVal(__INST(numberOfChannels));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4193
    wfFormat.nSamplesPerSec = __intVal(__INST(sampleRate));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4194
    wfFormat.wBitsPerSample = __intVal(__INST(bitsPerSample));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4195
    wfFormat.nBlockAlign = wfFormat.nChannels * wfFormat.wBitsPerSample / 8;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4196
    wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4197
    wfFormat.cbSize = 0;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4198
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4199
#  if 0
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4200
    /* Setup the primary DS buffer description */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4201
    ZeroMemory(&primarydsbDesc, sizeof(DSBUFFERDESC));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4202
    primarydsbDesc.dwSize = sizeof(DSBUFFERDESC);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4203
    primarydsbDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4204
    primarydsbDesc.dwBufferBytes = 0;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4205
    primarydsbDesc.lpwfxFormat = NULL;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4206
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4207
    /* Create the primary DS buffer */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4208
    if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &primarydsbDesc,
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4209
                                                 &t_pDSPrimeBuffer, NULL)) != DS_OK) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4210
        console_fprintf(stderr,"SoundStream: Cannot get the primary DS buffer address!\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4211
        IDirectSound_Release(t_pDirectSound);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4212
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4213
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4214
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4215
    /* Set the primary DS buffer sound format.  We have to do this because
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4216
       the default primary buffer is 8-bit, 22kHz! */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4217
    if ((result = IDirectSoundBuffer_SetFormat(t_pDSPrimeBuffer, &wfFormat)) != DS_OK) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4218
        console_fprintf(stderr,"SoundStream: Cannot set the primary DS buffer to proper sound format (%x) (%d)!\n", result, result);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4219
        IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4220
        IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4221
        IDirectSound_Release(t_pDirectSound);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4222
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4223
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4224
#  endif /* 0 */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4225
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4226
    /* Setup the secondary DS buffer description */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4227
    t_cbBufSize = RT_BUFFER_SIZE * sizeof(short) * NBUFS;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4228
    __INST(bufferSize) = __MKSMALLINT(t_cbBufSize);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4229
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4230
    ZeroMemory(&dsbdDesc, sizeof(DSBUFFERDESC));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4231
    dsbdDesc.dwSize = sizeof(DSBUFFERDESC);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4232
    dsbdDesc.dwFlags = DSBCAPS_GLOBALFOCUS;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4233
    dsbdDesc.dwBufferBytes = t_cbBufSize;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4234
    dsbdDesc.lpwfxFormat = &wfFormat;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4235
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4236
    /* Create the secondary DS buffer */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4237
    if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &dsbdDesc, &t_pDSBuffer, NULL)) != DS_OK) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4238
        console_fprintf(stderr,"SoundStream: couldn't create sound buffer!\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4239
        IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4240
        IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4241
        IDirectSound_Release(t_pDirectSound);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4242
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4243
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4244
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4245
    /* Lock the DS buffer */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4246
    if ((result = IDirectSoundBuffer_Lock(t_pDSBuffer, 0, t_cbBufSize, (LPLPVOID)&pDSBuffData,
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4247
                                          &dwDataLen, NULL, NULL, 0)) != DS_OK) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4248
        console_fprintf(stderr,"SoundStream: couldn't lock sound buffer!\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4249
        goto errorAndOut;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4250
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4251
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4252
    /* Zero the DS buffer */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4253
    ZeroMemory(pDSBuffData, dwDataLen);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4254
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4255
    /* Unlock the DS buffer */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4256
    if ((result = IDirectSoundBuffer_Unlock(t_pDSBuffer, pDSBuffData, dwDataLen, NULL, 0)) != DS_OK) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4257
        console_fprintf(stderr,"SoundStream: couldn't unlock sound buffer!\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4258
        goto errorAndOut;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4259
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4260
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4261
    __INST(bufferOffset) = __MKSMALLINT(0);  // reset last write position to start of buffer
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4262
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4263
    /* Start the buffer playback */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4264
    if ((result = IDirectSoundBuffer_Play(t_pDSBuffer, 0, 0, DSBPLAY_LOOPING) != DS_OK)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4265
        console_fprintf(stderr,"SoundStream: couldn't play sound buffer!\n");
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4266
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4267
errorAndOut:
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4268
        IDirectSoundBuffer_Stop(t_pDSBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4269
        IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4270
        IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4271
        IDirectSound_Release(t_pDirectSound);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4272
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4273
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4274
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4275
    {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4276
        OBJ t;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4277
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4278
        t = __MKEXTERNALADDRESS(t_pDSBuffer); __INST(pDSBuffer) = t; __STORE(self, t);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4279
        t = __MKEXTERNALADDRESS(t_pDirectSound); __INST(pDirectSound) = t; __STORE(self, t);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4280
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4281
    ok = true;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4282
out:;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4283
#endif /* SUPPORT_WIN32_DIRECTSOUND */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4284
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4285
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4286
    ok == false ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4287
        lastErrorString := errorStringOrNil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4288
        lastErrorNumber := error ? -1.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4289
        self openError:error.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4290
        "normally not reached"
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4291
        ^ nil.
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4292
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4293
    self registerForFinalization.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4294
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4295
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4296
!SoundStream::Win32DirectSound methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4297
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4298
supportedAudioFormats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4299
    "return a collection of supported audio formats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4300
     possibly returned symbols are:
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4301
        U8        unsigned 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4302
        S8        signed 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4303
        U16       unsigned 16bit samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4304
        U16_LE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4305
        U16_BE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4306
        S16       signed 16bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4307
        S16_LE    signed 16bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4308
        S16_BE    signed 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4309
        S24       signed 24bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4310
        S24_LE    signed 24bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4311
        S24_BE    signed 24bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4312
        S32       signed 32bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4313
        S32_LE    signed 32bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4314
        S32_BE    signed 32bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4315
        F32       float samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4316
        MPEG      audio mpeg encoded
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4317
        MU_LAW    u-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4318
        A_LAW     a-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4319
        IMA_ADPCM adpcm encoded
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4320
     the set of returned symbols depends on the underlying sound hardware.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4321
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4322
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4323
    ^ #(S16_LE S16)
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4324
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4325
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4326
     |s formats|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4327
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4328
     s := self writing.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4329
     formats := s supportedAudioFormats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4330
     s close.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4331
     formats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4332
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4333
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4334
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4335
!SoundStream::Win32DirectSound methodsFor:'reading'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4336
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4337
nextBytes:count into:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4338
    "read the next count bytes into an object and return the number of
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4339
     bytes read or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4340
     Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4341
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4342
    self errorUnsupportedOperation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4343
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4344
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4345
!SoundStream::Win32DirectSound methodsFor:'writing'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4346
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4347
nextPutBytes:count from:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4348
    "write count bytes from an object starting at index start.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4349
     return the number of bytes written or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4350
     Redefined, since IRIS audio library cannot be used with stdio.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4351
     (at least I don't know). Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4352
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4353
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4354
#ifdef SUPPORT_WIN32_DIRECTSOUND
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4355
  {
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4356
    HRESULT hr;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4357
    DWORD status;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4358
    LPVOID lpbuf1 = NULL;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4359
    LPVOID lpbuf2 = NULL;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4360
    DWORD dwsize1 = 0;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4361
    DWORD dwsize2 = 0;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4362
    DWORD playPos, safePos, endWrite;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4363
    DWORD millis;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4364
    OBJ oDirectSound, oDSBuffer;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4365
    LPDIRECTSOUND       t_pDirectSound = (LPDIRECTSOUND)0;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4366
    LPDIRECTSOUNDBUFFER t_pDSBuffer = (LPDIRECTSOUNDBUFFER)0;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4367
    int t_cbBufOffset, t_cbBufSize;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4368
    short *buf;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4369
    int cnt, offs;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4370
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4371
    if ((oDSBuffer = __INST(pDSBuffer)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4372
        t_pDSBuffer = __DSBufferVal(oDSBuffer);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4373
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4374
    if ((oDirectSound = __INST(pDirectSound)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4375
        t_pDirectSound = __DirectSoundVal(oDirectSound);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4376
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4377
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4378
    if (!t_pDSBuffer || !t_pDirectSound) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4379
        console_fprintf(stderr, "SoundStream not open!\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4380
        RETURN (0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4381
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4382
    t_cbBufOffset = __intVal(__INST(bufferOffset));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4383
    t_cbBufSize = __intVal(__INST(bufferSize));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4384
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4385
    cnt = __intVal(count);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4386
    offs = __intVal(start) - 1;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4387
    buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4388
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4389
    // Should be playing, right?
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4390
    hr = IDirectSoundBuffer_GetStatus(t_pDSBuffer, &status );
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4391
    if (!(status && DSBSTATUS_PLAYING)) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4392
        console_fprintf(stderr, "Buffer not playing!\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4393
        RETURN (0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4394
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4395
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4396
    // Sleep until we have enough room in buffer.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4397
    hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos );
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4398
    if( hr != DS_OK ) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4399
        console_fprintf(stderr, "Cannot get position!\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4400
        RETURN (0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4401
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4402
    if( playPos < t_cbBufOffset ) playPos += t_cbBufSize;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4403
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4404
    endWrite = t_cbBufOffset + (cnt * sizeof(short));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4405
    while ( playPos < endWrite ) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4406
        // Calculate number of milliseconds until we will have room, as
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4407
        // time = distance * (milliseconds/second) / ((bytes/sample) * (samples/second)),
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4408
        // rounded up.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4409
        millis = (DWORD) (1.0 + ((endWrite - playPos) * 1000.0) / ( sizeof(short) * __intVal(__INST(sampleRate))));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4410
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4411
        // Sleep for that long
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4412
        Sleep( millis );
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4413
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4414
        // Wake up, find out where we are now
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4415
        hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos );
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4416
        if( hr != DS_OK ) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4417
            console_fprintf(stderr, "Cannot get position!\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4418
            RETURN (0);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4419
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4420
        if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; // unwrap offset
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4421
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4422
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4423
    // Lock free space in the DS
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4424
    hr = IDirectSoundBuffer_Lock(t_pDSBuffer, t_cbBufOffset, cnt * sizeof(short), &lpbuf1, &dwsize1, &lpbuf2, &dwsize2, 0);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4425
    if (hr == DS_OK) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4426
        // Copy the buffer into the DS
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4427
        CopyMemory(lpbuf1, buf, dwsize1);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4428
        if(NULL != lpbuf2) CopyMemory(lpbuf2, buf+dwsize1, dwsize2);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4430
        // Update our buffer offset and unlock sound buffer
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4431
        t_cbBufOffset = (t_cbBufOffset + dwsize1 + dwsize2) % t_cbBufSize;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4432
        IDirectSoundBuffer_Unlock(t_pDSBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4433
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4434
    __INST(buffferOffset) = __MKSMALLINT(t_cbBufOffset);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4435
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4436
    RETURN (count);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4437
  }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4438
#endif /* SUPPORT_WIN32_DIRECTSOUND */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4439
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4440
%}.
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
  4441
    self errorUnsupportedOperation
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4442
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4443
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4444
!SoundStream::Win32WaveSound class methodsFor:'documentation'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4445
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4446
documentation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4447
"
5424
9f874a72681c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5423
diff changeset
  4448
    interface to the windows wave sound API
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4449
"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4450
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4451
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4452
!SoundStream::Win32WaveSound class methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4453
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4454
isSupported
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4455
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4456
#ifdef SUPPORT_WIN32_WAVESOUND
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4457
    RETURN(true);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4458
#endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4459
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4460
    ^ false.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4461
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4462
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4463
!SoundStream::Win32WaveSound methodsFor:'misc'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4464
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4465
flush
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4466
    "wait until all sound has been played"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4467
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4468
    "/ as yet unimplemented
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4469
    ^ self
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4470
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4471
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4472
!SoundStream::Win32WaveSound methodsFor:'open & close'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4473
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4474
closeFile
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4475
    "a stream has been collected - close the file"
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4476
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4477
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4478
#ifdef SUPPORT_WIN32_WAVESOUND
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4479
    struct buf *bp, *next;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4480
    int r;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4481
    HWAVEOUT t_waveHandle;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4482
    OBJ oWaveHandle;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4483
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4484
    if ((oWaveHandle = __INST(waveHandle)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4485
        t_waveHandle = __WaveHandleVal(oWaveHandle);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4486
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4487
# ifdef NO_WAIT_IN_CLOSE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4488
        /* Force cancellation of any pending buffers */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4489
        (void)waveOutReset(t_waveHandle);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4490
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4491
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4492
        /* Wait until all pending buffers have been freed */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4493
        while (free_buffers < total_buffers) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4494
            WaitForSingleObject(free_buffer_event, INFINITE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4495
        }
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4496
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4497
# ifndef NO_WAIT_IN_CLOSE
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4498
        /* Force cancellation of any pending buffers */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4499
        (void)waveOutReset(t_waveHandle);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4500
# endif
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4501
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4502
        /* Close the device */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4503
        if ((r = waveOutClose(t_waveHandle)) != 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4504
            console_printf("waveOutClose\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4505
            RETURN(self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4506
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4507
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4508
        EnterCriticalSection(&free_list_lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4509
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4510
        /* Free allocated buffers */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4511
        for (bp = free_list; bp != NULL; bp = next) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4512
            next = bp->next;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4513
            (void)free(bp);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4514
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4515
        free_list = NULL;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4516
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4517
        LeaveCriticalSection(&free_list_lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4518
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4519
        __INST(waveHandle) = nil;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4520
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4521
    RETURN (self);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4522
#endif /* SUPPORT_WIN32_WAVESOUND */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4523
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4524
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4525
!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4526
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4527
openWithMode:aMode attributes:attributeSpec
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4528
    |ok error errorStringOrNil|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4529
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4530
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4531
#ifdef SUPPORT_WIN32_WAVESOUND
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4532
    PCMWAVEFORMAT waveFormat;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4533
    int r;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4534
    HWAVEOUT t_waveHandle;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4535
    OBJ oWaveHandle;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4536
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4537
    ok = false;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4538
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4539
    if ((oWaveHandle = __INST(waveHandle)) != nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4540
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4541
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4542
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4543
    waveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4544
    waveFormat.wf.nChannels = __intVal(__INST(numberOfChannels));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4545
    waveFormat.wf.nSamplesPerSec = __intVal(__INST(sampleRate));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4546
    waveFormat.wBitsPerSample = __intVal(__INST(bitsPerSample));
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4547
    waveFormat.wf.nBlockAlign = waveFormat.wf.nChannels * waveFormat.wBitsPerSample / 8;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4548
    waveFormat.wf.nAvgBytesPerSec = waveFormat.wf.nSamplesPerSec * waveFormat.wf.nBlockAlign;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4549
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4550
    r = waveOutOpen(&t_waveHandle,
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4551
                    WAVE_MAPPER,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4552
                    (WAVEFORMAT *)&waveFormat,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4553
                    (DWORD_PTR)waveCallBack,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4554
                    (DWORD_PTR)0,
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4555
                    CALLBACK_FUNCTION);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4556
    if (r != 0) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4557
        console_printf("waveOutOpen\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4558
        goto out;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4559
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4560
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4561
    (void)waveOutReset(t_waveHandle);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4562
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4563
    free_list = NULL;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4564
    InitializeCriticalSection(&free_list_lock);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4565
    free_buffers = 0;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4566
    free_buffer_event = CreateEvent(NULL, FALSE, FALSE, NULL);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4567
    total_buffers = 0;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4568
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4569
    {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4570
        OBJ t;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4571
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4572
        t = __MKEXTERNALADDRESS(t_waveHandle); __INST(waveHandle) = t; __STORE(self, t);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4573
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4574
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4575
# if 0
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4576
    /*
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4577
     * HACK: If we immediately start writing valid audio data to the device
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4578
     * then the sound is choppy in the beginning. Writing a null packet to
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4579
     * to the device first seems to fix this problem although I have no idea
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4580
     * why - DAC
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4581
     */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4582
    {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4583
        char null[DATALEN];
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4584
        int i;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4585
        for (i = 0; i < DATALEN; i++) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4586
            null[i] = 127;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4587
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4588
        audioWrite(null, DATALEN);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4589
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4590
# endif /* 0 */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4591
    ok = true;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4592
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4593
out:;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4594
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4595
#endif /* !SUPPORT_WIN32_DIRECTSOUND */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4596
%}.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4597
    ok == false ifTrue:[
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4598
        lastErrorString := errorStringOrNil.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4599
        lastErrorNumber := error ? -1.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4600
        self openError:error.
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4601
        "normally not reached"
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4602
        ^ nil.
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4603
    ].
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4604
    self registerForFinalization.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4605
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4606
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4607
!SoundStream::Win32WaveSound methodsFor:'queries'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4608
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4609
supportedAudioFormats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4610
    "return a collection of supported audio formats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4611
     possibly returned symbols are:
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4612
        U8        unsigned 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4613
        S8        signed 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4614
        U16       unsigned 16bit samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4615
        U16_LE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4616
        U16_BE    unsigned 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4617
        S16       signed 16bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4618
        S16_LE    signed 16bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4619
        S16_BE    signed 16bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4620
        S24       signed 24bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4621
        S24_LE    signed 24bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4622
        S24_BE    signed 24bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4623
        S32       signed 32bit little endian samples in native format
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4624
        S32_LE    signed 32bit little endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4625
        S32_BE    signed 32bit big endian samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4626
        F32       float samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4627
        MPEG      audio mpeg encoded
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4628
        MU_LAW    u-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4629
        A_LAW     a-law encoded 8bit samples
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4630
        IMA_ADPCM adpcm encoded
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4631
     the set of returned symbols depends on the underlying sound hardware.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4632
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4633
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4634
    ^ #(S16_LE S16)
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4635
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4636
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4637
     |s formats|
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4638
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4639
     s := self writing.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4640
     formats := s supportedAudioFormats.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4641
     s close.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4642
     formats
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4643
    "
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4644
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4645
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4646
!SoundStream::Win32WaveSound methodsFor:'reading'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4647
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4648
nextBytes:count into:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4649
    "read the next count bytes into an object and return the number of
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4650
     bytes read or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4651
     Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4652
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4653
    self errorUnsupportedOperation
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4654
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4655
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4656
!SoundStream::Win32WaveSound methodsFor:'writing'!
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4657
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4658
nextPutBytes:count from:anObject startingAt:start
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4659
    "write count bytes from an object starting at index start.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4660
     return the number of bytes written or nil on error.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4661
     Redefined, since IRIS audio library cannot be used with stdio.
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4662
     (at least I don't know). Use with ByteArrays only."
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4663
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4664
%{
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4665
#ifdef SUPPORT_WIN32_WAVESOUND
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4666
  {
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4667
    struct buf *bp;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4668
    int len, i, r;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4669
    int dataLen, offs;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4670
    short *buf;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4671
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4672
    HWAVEOUT t_waveHandle;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4673
    OBJ oWaveHandle;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4674
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4675
    if ((oWaveHandle = __INST(waveHandle)) == nil) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4676
        RETURN(0);
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4677
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4678
    t_waveHandle = __WaveHandleVal(oWaveHandle);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4679
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4680
    dataLen = __intVal(count);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4681
    offs = __intVal(start) - 1;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4682
    buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs;
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4683
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4684
    while (dataLen > 0) {
5429
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4685
        if (free_list == NULL && total_buffers < MAXBUF) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4686
            /* Expand available buffer space */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4687
            bp = (struct buf *)malloc(sizeof(struct buf));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4688
            total_buffers++;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4689
        } else {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4690
            if (free_list == NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4691
                /* We must wait for a free buffer */
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4692
                while (free_list == NULL) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4693
                    WaitForSingleObject(free_buffer_event, INFINITE);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4694
                }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4695
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4696
            EnterCriticalSection(&free_list_lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4697
            bp = free_list;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4698
            free_list = free_list->next;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4699
            --free_buffers;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4700
            LeaveCriticalSection(&free_list_lock);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4701
            r = waveOutUnprepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4702
            if (r != 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4703
                console_printf("waveOutUnprepareHeader\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4704
                RETURN(self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4705
            }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4706
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4707
        len = min(dataLen, DATALEN);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4708
        bp->hdr.lpData = (char *)bp->data;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4709
        bp->hdr.dwBufferLength = len;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4710
        bp->hdr.dwBytesRecorded = len;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4711
        bp->hdr.dwUser = (INT)(bp);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4712
        bp->hdr.dwFlags = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4713
        bp->hdr.dwLoops = 0;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4714
        r = waveOutPrepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4715
        if (r != 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4716
            console_printf("waveOutPrepareHeader\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4717
            RETURN(self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4718
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4719
        for (i = 0; i < len; i++) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4720
            bp->data[i] = buf[i];
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4721
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4722
        r = waveOutWrite(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4723
        if (r != 0) {
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4724
            console_printf("waveOutWrite\n");
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4725
            RETURN(self);
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4726
        }
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4727
        buf += len;
3aaffa1b052c #FEATURE by exept
Claus Gittinger <cg@exept.de>
parents: 5428
diff changeset
  4728
        dataLen -= len;
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4729
    }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4730
    RETURN (count);
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4731
  }
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4732
#endif /* SUPPORT_WIN32_WAVESOUND */
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4733
%}.
5405
d4a7ff6e2fe7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5403
diff changeset
  4734
    self errorUnsupportedOperation
5402
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4735
! !
a6ef442609cf #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 5401
diff changeset
  4736
152
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
  4737
!SoundStream class methodsFor:'documentation'!
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
  4738
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
  4739
version
3622
33c345c6d1d9 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3482
diff changeset
  4740
    ^ '$Header$'
2418
4ea40741b2b5 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2321
diff changeset
  4741
!
4ea40741b2b5 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2321
diff changeset
  4742
4ea40741b2b5 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2321
diff changeset
  4743
version_CVS
3622
33c345c6d1d9 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 3482
diff changeset
  4744
    ^ '$Header$'
918
c93d55269f9d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
  4745
! !
1151
5963256af171 do not depend on TimeStamp - TimeStamp to return seconds-integer
Claus Gittinger <cg@exept.de>
parents: 934
diff changeset
  4746
3154
23ac6f3e69b6 Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 3000
diff changeset
  4747
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  4748
SoundStream initialize!