SoundStr.st
author Claus Gittinger <cg@exept.de>
Mon, 21 Dec 1998 12:43:58 +0100
changeset 712 9e853d04f52b
parent 614 565ea4308322
child 713 85912db3ad19
permissions -rw-r--r--
first attempt in win32 audio
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     1
"
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
45
claus
parents: 36
diff changeset
     3
	      All Rights Reserved
4
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     4
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     5
 This software is furnished under a license and may be used
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     6
 only in accordance with the terms of that license and with the
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     8
 be provided or otherwise made available to, or used by, any
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
     9
 other person.  No title to or ownership of the software is
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
    10
 hereby transferred.
1f66800df351 *** empty log message ***
claus
parents: 3
diff changeset
    11
"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    12
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    13
FileStream subclass:#SoundStream
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    14
	instanceVariableNames:'sampleRate numberOfChannels bitsPerSample audioFormat
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    15
			       alPort 
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    16
			       pDirectSound pDSBuffer cbBufOffset cbBufSize'
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
    17
	classVariableNames:'UnsupportedOperationSignal'
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    18
	poolDictionaries:''
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
    19
	category:'Streams-External'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    20
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    21
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    22
!SoundStream primitiveDefinitions!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    23
%{
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    24
#ifdef IRIS
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    25
# ifndef IRIX5
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    26
#  define IRIS_AUDIO
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    27
# endif
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    28
#endif
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    29
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    30
#ifdef IRIS_AUDIO
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    31
# include <audio.h>
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    32
# define __ALportVal(o)  (ALport)(__externalAddressVal(o))
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    33
#endif
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
    34
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
    35
#ifdef LINUX
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    36
# define DEV_AUDIO
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    37
# include <sys/soundcard.h>
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    38
#endif
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    39
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    40
#if defined(sunos) || defined(solaris)
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    41
# define DEV_AUDIO
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    42
#endif
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    43
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    44
#ifdef DEV_AUDIO
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
    45
# include <stdio.h>
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
    46
#endif
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    47
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    48
#ifdef WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    49
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    50
# define _WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    51
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    52
# undef INT
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    53
# undef Array
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    54
# undef Number
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    55
# undef Method
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    56
# undef Point
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    57
# undef Rectangle
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    58
# undef Block
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    59
# undef String
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    60
# undef Message
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    61
# undef Object
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    62
# undef Context
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    63
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    64
/* # include <stdarg.h> /* */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    65
# include <stdio.h> /* */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    66
# include <windows.h>
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    67
# define CINTERFACE
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    68
# include "dsound.h"
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    69
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    70
# ifdef __DEF_Array
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    71
#  define Array __DEF_Array
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    72
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    73
# ifdef __DEF_Number
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    74
#  define Number __DEF_Number
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    75
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    76
# ifdef __DEF_Method
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    77
#  define Method __DEF_Method
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    78
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    79
# ifdef __DEF_Point
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    80
#  define Point __DEF_Point
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    81
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    82
# ifdef __DEF_Block
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    83
#  define Block __DEF_Block
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    84
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    85
# ifdef __DEF_String
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    86
#  define String __DEF_String
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    87
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    88
# ifdef __DEF_Message
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    89
#  define Message __DEF_Message
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    90
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    91
# ifdef __DEF_Object
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    92
#  define Object __DEF_Object
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    93
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    94
# ifdef __DEF_Context
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    95
#  define Context __DEF_Context
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    96
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    97
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    98
# define INT int
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
    99
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   100
# define __DirectSoundVal(o) (LPDIRECTSOUND)(__externalAddressVal(o))
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   101
# define __DSBufferVal(o)    (LPDIRECTSOUNDBUFFER)(__externalAddressVal(o))
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   102
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   103
# define RT_BUFFER_SIZE 4096
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   104
# define NBUFS          4
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   105
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   106
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   107
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   108
%}
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   109
! !
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   110
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   111
!SoundStream class methodsFor:'documentation'!
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   112
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   113
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   114
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   115
 COPYRIGHT (c) 1993 by Claus Gittinger
45
claus
parents: 36
diff changeset
   116
	      All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   117
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   118
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   119
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   120
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   121
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   122
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   123
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   124
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   125
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   126
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   127
documentation
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   128
"
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   129
    Preliminary (unfinished) interface to audio device.
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   130
    Currently works with LINUXs or SUNs /dev/audio driver and
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   131
    IRIX (indy). 
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   132
    On iris, the default setup is for 8 bit mono
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   133
    so I can play the standard sound files I have here.
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   134
    It needs much more work, for stereo, different sampling rates etc.
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   135
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   136
    This is an experimental class - its interface & implementation
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   137
    may change in the future.
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   138
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   139
    [author:]
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
   140
	Claus Gittinger
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   141
"
152
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
   142
! !
45
claus
parents: 36
diff changeset
   143
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   144
!SoundStream class methodsFor:'initialization'!
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   145
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   146
initialize
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   147
    UnsupportedOperationSignal isNil ifTrue:[
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   148
	UnsupportedOperationSignal := StreamErrorSignal newSignalMayProceed:false.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   149
	UnsupportedOperationSignal nameClass:self message:#unsupportedOperationSignal.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   150
	UnsupportedOperationSignal notifierString:'unsupported operation'.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   151
    ]
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   152
! !
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   153
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   154
!SoundStream class methodsFor:'instance creation'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   155
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   156
reading
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   157
    "create and return a new soundStream for reading (i.e. recording)"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   158
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   159
    |newStream|
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   160
    newStream := (self basicNew) initialize.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   161
    newStream openForReading isNil ifTrue:[^nil].
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   162
    newStream buffered:false.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   163
    newStream binary.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   164
    ^ newStream
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   165
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   166
    "SoundStream reading"
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   167
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   168
    "Modified: / 12.12.1997 / 16:51:56 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   169
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   170
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   171
writing
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   172
    "create and return a new soundStream for writing (i.e. playback)"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   173
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   174
    |newStream|
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   175
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   176
    newStream := (self basicNew) initialize.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   177
    newStream openForWriting isNil ifTrue:[^nil].
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   178
    newStream buffered:false.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   179
    newStream binary.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   180
    ^ newStream
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   181
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   182
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   183
     SoundStream writing
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   184
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   185
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   186
    "Created: / 17.11.1995 / 17:25:42 / cg"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   187
    "Modified: / 12.12.1997 / 16:51:38 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   188
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   189
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   190
writing16BitStereo
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   191
    "just an example, has never been tried (I also
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   192
     have no samples for this ... leave it as an exercise)"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   193
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   194
    |newStream|
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   195
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   196
    OperatingSystem getCPUType ~= 'irix' ifTrue:[
45
claus
parents: 36
diff changeset
   197
	self error:'unsupported audio mode'.
claus
parents: 36
diff changeset
   198
	^ nil
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   199
    ].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   200
    newStream := (self basicNew) initialize.
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   201
    newStream buffered:false.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   202
    newStream binary.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   203
    newStream bitsPerSample:16.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   204
    newStream numberOfChannels:2.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   205
    newStream openForWriting isNil ifTrue:[^nil].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   206
    ^ newStream
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   207
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   208
    "SoundStream writing16BitStereo"
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   209
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   210
    "Modified: / 12.12.1997 / 16:51:49 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   211
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   212
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   213
!SoundStream class methodsFor:'Signal constants'!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   214
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   215
unsupportedOperationSignal
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   216
    ^ UnsupportedOperationSignal
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   217
! !
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   218
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   219
!SoundStream class methodsFor:'conversion helpers'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   220
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   221
linear16ToUlaw:a16bitSignedValue
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   222
    "given a 16it signed value, encode into uLaw byte"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   223
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   224
    |absVal sign exp mantissa byte|
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   225
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   226
%{
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   227
    /*
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   228
     * so heavily used when playing sounds ...
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   229
     * made it a primitive.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   230
     */
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   231
    if (__isSmallInteger(a16bitSignedValue)) {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   232
	int __sign = 0;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   233
	int __absVal = __intVal(a16bitSignedValue);
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   234
	int __exp, __mantissa, __byte;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   235
	static char __uLawExp[] = 
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   236
		    {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   237
			0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   238
			5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   239
			6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   240
			6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   241
			7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   242
			7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   243
			7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   244
			7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   245
		    };
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   246
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   247
	if (__absVal < 0) {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   248
	    if (__absVal <= -32256) {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   249
		RETURN (__MKSMALLINT(0));
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   250
	    }
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   251
	    __absVal = -__absVal;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   252
	    __sign = 0x80;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   253
	} else {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   254
	    if (__absVal >= 32256) {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   255
		RETURN (__MKSMALLINT(128));
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   256
	    }
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   257
	}
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   258
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   259
	__exp = __uLawExp[__absVal >> 8];
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   260
	__mantissa = (__absVal >> (__exp+3)) & 0xF;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   261
	__byte = ~(__sign | (__exp<<4) | __mantissa) & 0xFF;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   262
	RETURN (__MKSMALLINT(__byte));
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   263
    }
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   264
%}.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   265
    "/
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   266
    "/ fallback for non-integral argument
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   267
    "/
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   268
    a16bitSignedValue isInteger ifFalse:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   269
	^ self uLawToLinear16:a16bitSignedValue asInteger
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   270
    ].
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   271
    ^ 0
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   272
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   273
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   274
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:0)    
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   275
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32256)   
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   276
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32256)  
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   277
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32767) 
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   278
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32767)
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   279
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:100)   
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   280
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-100)  
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   281
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:104)   
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   282
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-104)  
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   283
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   284
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   285
    "Modified: / 9.12.1997 / 16:46:24 / cg"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   286
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   287
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   288
uLawToLinear16:uLawValue
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   289
    "given a uLaw byte, return the decoded signed 16bit value.
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   290
     Currently unused - but will be"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   291
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   292
    ^ #(
45
claus
parents: 36
diff changeset
   293
	"0  "     -32256
claus
parents: 36
diff changeset
   294
	"1  "     -31228
claus
parents: 36
diff changeset
   295
	"2  "     -30200
claus
parents: 36
diff changeset
   296
	"3  "     -29172
claus
parents: 36
diff changeset
   297
	"4  "     -28143
claus
parents: 36
diff changeset
   298
	"5  "     -27115
claus
parents: 36
diff changeset
   299
	"6  "     -26087
claus
parents: 36
diff changeset
   300
	"7  "     -25059
claus
parents: 36
diff changeset
   301
	"8  "     -24031
claus
parents: 36
diff changeset
   302
	"9  "     -23002
claus
parents: 36
diff changeset
   303
	"10 "     -21974
claus
parents: 36
diff changeset
   304
	"11 "     -20946
claus
parents: 36
diff changeset
   305
	"12 "     -19918
claus
parents: 36
diff changeset
   306
	"13 "     -18889
claus
parents: 36
diff changeset
   307
	"14 "     -17861
claus
parents: 36
diff changeset
   308
	"15 "     -16833
claus
parents: 36
diff changeset
   309
	"16 "     -16062
claus
parents: 36
diff changeset
   310
	"17 "     -15548
claus
parents: 36
diff changeset
   311
	"18 "     -15033
claus
parents: 36
diff changeset
   312
	"19 "     -14519
claus
parents: 36
diff changeset
   313
	"20 "     -14005
claus
parents: 36
diff changeset
   314
	"21 "     -13491
claus
parents: 36
diff changeset
   315
	"22 "     -12977
claus
parents: 36
diff changeset
   316
	"23 "     -12463
claus
parents: 36
diff changeset
   317
	"24 "     -11949
claus
parents: 36
diff changeset
   318
	"25 "     -11435
claus
parents: 36
diff changeset
   319
	"26 "     -10920
claus
parents: 36
diff changeset
   320
	"27 "     -10406
claus
parents: 36
diff changeset
   321
	"28 "     -9892
claus
parents: 36
diff changeset
   322
	"29 "     -9378
claus
parents: 36
diff changeset
   323
	"30 "     -8864
claus
parents: 36
diff changeset
   324
	"31 "     -8350
claus
parents: 36
diff changeset
   325
	"32 "     -7964
claus
parents: 36
diff changeset
   326
	"33 "     -7707
claus
parents: 36
diff changeset
   327
	"34 "     -7450
claus
parents: 36
diff changeset
   328
	"35 "     -7193
claus
parents: 36
diff changeset
   329
	"36 "     -6936
claus
parents: 36
diff changeset
   330
	"37 "     -6679
claus
parents: 36
diff changeset
   331
	"38 "     -6422
claus
parents: 36
diff changeset
   332
	"39 "     -6165
claus
parents: 36
diff changeset
   333
	"40 "     -5908
claus
parents: 36
diff changeset
   334
	"41 "     -5651
claus
parents: 36
diff changeset
   335
	"42 "     -5394
claus
parents: 36
diff changeset
   336
	"43 "     -5137
claus
parents: 36
diff changeset
   337
	"44 "     -4880
claus
parents: 36
diff changeset
   338
	"45 "     -4623
claus
parents: 36
diff changeset
   339
	"46 "     -4365
claus
parents: 36
diff changeset
   340
	"47 "     -4108
claus
parents: 36
diff changeset
   341
	"48 "     -3916
claus
parents: 36
diff changeset
   342
	"49 "     -3787
claus
parents: 36
diff changeset
   343
	"50 "     -3659
claus
parents: 36
diff changeset
   344
	"51 "     -3530
claus
parents: 36
diff changeset
   345
	"52 "     -3402
claus
parents: 36
diff changeset
   346
	"53 "     -3273
claus
parents: 36
diff changeset
   347
	"54 "     -3144
claus
parents: 36
diff changeset
   348
	"55 "     -3016
claus
parents: 36
diff changeset
   349
	"56 "     -2887
claus
parents: 36
diff changeset
   350
	"57 "     -2759
claus
parents: 36
diff changeset
   351
	"58 "     -2630
claus
parents: 36
diff changeset
   352
	"59 "     -2502
claus
parents: 36
diff changeset
   353
	"60 "     -2373
claus
parents: 36
diff changeset
   354
	"61 "     -2245
claus
parents: 36
diff changeset
   355
	"62 "     -2116
claus
parents: 36
diff changeset
   356
	"63 "     -1988
claus
parents: 36
diff changeset
   357
	"64 "     -1891
claus
parents: 36
diff changeset
   358
	"65 "     -1827
claus
parents: 36
diff changeset
   359
	"66 "     -1763
claus
parents: 36
diff changeset
   360
	"67 "     -1698
claus
parents: 36
diff changeset
   361
	"68 "     -1634
claus
parents: 36
diff changeset
   362
	"69 "     -1570
claus
parents: 36
diff changeset
   363
	"70 "     -1506
claus
parents: 36
diff changeset
   364
	"71 "     -1441
claus
parents: 36
diff changeset
   365
	"72 "     -1377
claus
parents: 36
diff changeset
   366
	"73 "     -1313
claus
parents: 36
diff changeset
   367
	"74 "     -1249
claus
parents: 36
diff changeset
   368
	"75 "     -1184
claus
parents: 36
diff changeset
   369
	"76 "     -1120
claus
parents: 36
diff changeset
   370
	"77 "     -1056
claus
parents: 36
diff changeset
   371
	"78 "     -992
claus
parents: 36
diff changeset
   372
	"79 "     -927
claus
parents: 36
diff changeset
   373
	"80 "     -879
claus
parents: 36
diff changeset
   374
	"81 "     -847
claus
parents: 36
diff changeset
   375
	"82 "     -815
claus
parents: 36
diff changeset
   376
	"83 "     -783
claus
parents: 36
diff changeset
   377
	"84 "     -751
claus
parents: 36
diff changeset
   378
	"85 "     -718
claus
parents: 36
diff changeset
   379
	"86 "     -686
claus
parents: 36
diff changeset
   380
	"87 "     -654
claus
parents: 36
diff changeset
   381
	"88 "     -622
claus
parents: 36
diff changeset
   382
	"89 "     -590
claus
parents: 36
diff changeset
   383
	"90 "     -558
claus
parents: 36
diff changeset
   384
	"91 "     -526
claus
parents: 36
diff changeset
   385
	"92 "     -494
claus
parents: 36
diff changeset
   386
	"93 "     -461
claus
parents: 36
diff changeset
   387
	"94 "     -429
claus
parents: 36
diff changeset
   388
	"95 "     -397
claus
parents: 36
diff changeset
   389
	"96 "     -373
claus
parents: 36
diff changeset
   390
	"97 "     -357
claus
parents: 36
diff changeset
   391
	"98 "     -341
claus
parents: 36
diff changeset
   392
	"99 "     -325
claus
parents: 36
diff changeset
   393
	"100"     -309
claus
parents: 36
diff changeset
   394
	"101"     -293
claus
parents: 36
diff changeset
   395
	"102"     -277
claus
parents: 36
diff changeset
   396
	"103"     -261
claus
parents: 36
diff changeset
   397
	"104"     -245
claus
parents: 36
diff changeset
   398
	"105"     -228
claus
parents: 36
diff changeset
   399
	"106"     -212
claus
parents: 36
diff changeset
   400
	"107"     -196
claus
parents: 36
diff changeset
   401
	"108"     -180
claus
parents: 36
diff changeset
   402
	"109"     -164
claus
parents: 36
diff changeset
   403
	"110"     -148
claus
parents: 36
diff changeset
   404
	"111"     -132
claus
parents: 36
diff changeset
   405
	"112"     -120
claus
parents: 36
diff changeset
   406
	"113"     -112
claus
parents: 36
diff changeset
   407
	"114"     -104
claus
parents: 36
diff changeset
   408
	"115"     -96
claus
parents: 36
diff changeset
   409
	"116"     -88
claus
parents: 36
diff changeset
   410
	"117"     -80
claus
parents: 36
diff changeset
   411
	"118"     -72
claus
parents: 36
diff changeset
   412
	"119"     -64
claus
parents: 36
diff changeset
   413
	"120"     -56
claus
parents: 36
diff changeset
   414
	"121"     -48
claus
parents: 36
diff changeset
   415
	"122"     -40
claus
parents: 36
diff changeset
   416
	"123"     -32
claus
parents: 36
diff changeset
   417
	"124"     -24
claus
parents: 36
diff changeset
   418
	"125"     -16
claus
parents: 36
diff changeset
   419
	"126"     -8
claus
parents: 36
diff changeset
   420
	"127"     0
claus
parents: 36
diff changeset
   421
	"128"     32256
claus
parents: 36
diff changeset
   422
	"129"     31228
claus
parents: 36
diff changeset
   423
	"130"     30200
claus
parents: 36
diff changeset
   424
	"131"     29172
claus
parents: 36
diff changeset
   425
	"132"     28143
claus
parents: 36
diff changeset
   426
	"133"     27115
claus
parents: 36
diff changeset
   427
	"134"     26087
claus
parents: 36
diff changeset
   428
	"135"     25059
claus
parents: 36
diff changeset
   429
	"136"     24031
claus
parents: 36
diff changeset
   430
	"137"     23002
claus
parents: 36
diff changeset
   431
	"138"     21974
claus
parents: 36
diff changeset
   432
	"139"     20946
claus
parents: 36
diff changeset
   433
	"140"     19918
claus
parents: 36
diff changeset
   434
	"141"     18889
claus
parents: 36
diff changeset
   435
	"142"     17861
claus
parents: 36
diff changeset
   436
	"143"     16833
claus
parents: 36
diff changeset
   437
	"144"     16062
claus
parents: 36
diff changeset
   438
	"145"     15548
claus
parents: 36
diff changeset
   439
	"146"     15033
claus
parents: 36
diff changeset
   440
	"147"     14519
claus
parents: 36
diff changeset
   441
	"148"     14005
claus
parents: 36
diff changeset
   442
	"149"     13491
claus
parents: 36
diff changeset
   443
	"150"     12977
claus
parents: 36
diff changeset
   444
	"151"     12463
claus
parents: 36
diff changeset
   445
	"152"     11949
claus
parents: 36
diff changeset
   446
	"153"     11435
claus
parents: 36
diff changeset
   447
	"154"     10920
claus
parents: 36
diff changeset
   448
	"155"     10406
claus
parents: 36
diff changeset
   449
	"156"     9892
claus
parents: 36
diff changeset
   450
	"157"     9378
claus
parents: 36
diff changeset
   451
	"158"     8864
claus
parents: 36
diff changeset
   452
	"159"     8350
claus
parents: 36
diff changeset
   453
	"160"     7964
claus
parents: 36
diff changeset
   454
	"161"     7707
claus
parents: 36
diff changeset
   455
	"162"     7450
claus
parents: 36
diff changeset
   456
	"163"     7193
claus
parents: 36
diff changeset
   457
	"164"     6936
claus
parents: 36
diff changeset
   458
	"165"     6679
claus
parents: 36
diff changeset
   459
	"166"     6422
claus
parents: 36
diff changeset
   460
	"167"     6165
claus
parents: 36
diff changeset
   461
	"168"     5908
claus
parents: 36
diff changeset
   462
	"169"     5651
claus
parents: 36
diff changeset
   463
	"170"     5394
claus
parents: 36
diff changeset
   464
	"171"     5137
claus
parents: 36
diff changeset
   465
	"172"     4880
claus
parents: 36
diff changeset
   466
	"173"     4623
claus
parents: 36
diff changeset
   467
	"174"     4365
claus
parents: 36
diff changeset
   468
	"175"     4108
claus
parents: 36
diff changeset
   469
	"176"     3916
claus
parents: 36
diff changeset
   470
	"177"     3787
claus
parents: 36
diff changeset
   471
	"178"     3659
claus
parents: 36
diff changeset
   472
	"179"     3530
claus
parents: 36
diff changeset
   473
	"180"     3402
claus
parents: 36
diff changeset
   474
	"181"     3273
claus
parents: 36
diff changeset
   475
	"182"     3144
claus
parents: 36
diff changeset
   476
	"183"     3016
claus
parents: 36
diff changeset
   477
	"184"     2887
claus
parents: 36
diff changeset
   478
	"185"     2759
claus
parents: 36
diff changeset
   479
	"186"     2630
claus
parents: 36
diff changeset
   480
	"187"     2502
claus
parents: 36
diff changeset
   481
	"188"     2373
claus
parents: 36
diff changeset
   482
	"189"     2245
claus
parents: 36
diff changeset
   483
	"190"     2116
claus
parents: 36
diff changeset
   484
	"191"     1988
claus
parents: 36
diff changeset
   485
	"192"     1891
claus
parents: 36
diff changeset
   486
	"193"     1827
claus
parents: 36
diff changeset
   487
	"194"     1763
claus
parents: 36
diff changeset
   488
	"195"     1698
claus
parents: 36
diff changeset
   489
	"196"     1634
claus
parents: 36
diff changeset
   490
	"197"     1570
claus
parents: 36
diff changeset
   491
	"198"     1506
claus
parents: 36
diff changeset
   492
	"199"     1441
claus
parents: 36
diff changeset
   493
	"200"     1377
claus
parents: 36
diff changeset
   494
	"201"     1313
claus
parents: 36
diff changeset
   495
	"202"     1249
claus
parents: 36
diff changeset
   496
	"203"     1184
claus
parents: 36
diff changeset
   497
	"204"     1120
claus
parents: 36
diff changeset
   498
	"205"     1056
claus
parents: 36
diff changeset
   499
	"206"     992
claus
parents: 36
diff changeset
   500
	"207"     927
claus
parents: 36
diff changeset
   501
	"208"     879
claus
parents: 36
diff changeset
   502
	"209"     847
claus
parents: 36
diff changeset
   503
	"210"     815
claus
parents: 36
diff changeset
   504
	"211"     783
claus
parents: 36
diff changeset
   505
	"212"     751
claus
parents: 36
diff changeset
   506
	"213"     718
claus
parents: 36
diff changeset
   507
	"214"     686
claus
parents: 36
diff changeset
   508
	"215"     654
claus
parents: 36
diff changeset
   509
	"216"     622
claus
parents: 36
diff changeset
   510
	"217"     590
claus
parents: 36
diff changeset
   511
	"218"     558
claus
parents: 36
diff changeset
   512
	"219"     526
claus
parents: 36
diff changeset
   513
	"220"     494
claus
parents: 36
diff changeset
   514
	"221"     461
claus
parents: 36
diff changeset
   515
	"222"     429
claus
parents: 36
diff changeset
   516
	"223"     397
claus
parents: 36
diff changeset
   517
	"224"     373
claus
parents: 36
diff changeset
   518
	"225"     357
claus
parents: 36
diff changeset
   519
	"226"     341
claus
parents: 36
diff changeset
   520
	"227"     325
claus
parents: 36
diff changeset
   521
	"228"     309
claus
parents: 36
diff changeset
   522
	"229"     293
claus
parents: 36
diff changeset
   523
	"230"     277
claus
parents: 36
diff changeset
   524
	"231"     261
claus
parents: 36
diff changeset
   525
	"232"     245
claus
parents: 36
diff changeset
   526
	"233"     228
claus
parents: 36
diff changeset
   527
	"234"     212
claus
parents: 36
diff changeset
   528
	"235"     196
claus
parents: 36
diff changeset
   529
	"236"     180
claus
parents: 36
diff changeset
   530
	"237"     164
claus
parents: 36
diff changeset
   531
	"238"     148
claus
parents: 36
diff changeset
   532
	"239"     132
claus
parents: 36
diff changeset
   533
	"240"     120
claus
parents: 36
diff changeset
   534
	"241"     112
claus
parents: 36
diff changeset
   535
	"242"     104
claus
parents: 36
diff changeset
   536
	"243"     96
claus
parents: 36
diff changeset
   537
	"244"     88
claus
parents: 36
diff changeset
   538
	"245"     80
claus
parents: 36
diff changeset
   539
	"246"     72
claus
parents: 36
diff changeset
   540
	"247"     64
claus
parents: 36
diff changeset
   541
	"248"     56
claus
parents: 36
diff changeset
   542
	"249"     48
claus
parents: 36
diff changeset
   543
	"250"     40
claus
parents: 36
diff changeset
   544
	"251"     32
claus
parents: 36
diff changeset
   545
	"252"     24
claus
parents: 36
diff changeset
   546
	"253"     16
claus
parents: 36
diff changeset
   547
	"254"     8
claus
parents: 36
diff changeset
   548
	"255"     0
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   549
    ) at:(uLawValue + 1)
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   550
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   551
    "Modified: / 9.12.1997 / 16:34:17 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   552
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   553
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   554
!SoundStream class methodsFor:'default values'!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   555
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   556
defaultAudioFormat
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   557
    OperatingSystem getOSType = 'win32' ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   558
	^ #S16 
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   559
    ].
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   560
    ^ #U8 
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   561
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   562
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   563
defaultBitsPerSample
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   564
    "minimum, supported by all audio systems"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   565
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   566
    OperatingSystem getOSType = 'win32' ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   567
	^ 16 
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   568
    ].
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   569
    ^ 8
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   570
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   571
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   572
defaultNumberOfChannels
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   573
    "minimum, supported by all audio systems"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   574
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   575
    ^ 1
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   576
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   577
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   578
defaultSampleRate
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   579
    "minimum, supported by all audio systems"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   580
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   581
    ^ 8000
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   582
! !
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   583
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   584
!SoundStream class methodsFor:'playing'!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   585
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   586
playSoundFile:aFilename
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   587
    "play a soundFile"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   588
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   589
    |inStream soundStream count totalCount buffer startTime playTime delayedTime waitTime|
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   590
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   591
    inStream := aFilename asFilename readStream.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   592
    inStream isNil ifTrue:[^ self].
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   593
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   594
    soundStream := self writing.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   595
    soundStream isNil ifTrue:[^ self].
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   596
    soundStream buffered:false.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   597
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   598
    startTime := AbsoluteTime now.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   599
    totalCount := 0.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   600
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   601
    buffer := ByteArray new:4096.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   602
    [(count := inStream nextBytesInto:buffer) > 0] whileTrue:[
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
   603
	totalCount := totalCount + count.
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
   604
	soundStream nextPutBytes:count from:buffer.
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   605
    ].
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   606
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   607
    inStream close.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   608
    soundStream commit.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   609
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   610
    "/
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   611
    "/ at least the linux audio driver behaves funny, if we close too early ...
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   612
    "/
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   613
    playTime := totalCount / soundStream sampleRate.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   614
    delayedTime := (AbsoluteTime now - startTime).
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   615
    waitTime := playTime - delayedTime + 0.1.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   616
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   617
    (Delay forSeconds:waitTime) wait.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   618
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   619
    soundStream close.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   620
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   621
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   622
     SoundStream playSoundFile:'/usr/local/lib/sounds/laugh.snd'
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   623
     SoundStream playSoundFile:'/usr/local/lib/sounds/spacemusic.snd'
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   624
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   625
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   626
    "Created: 17.11.1995 / 17:25:30 / cg"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   627
    "Modified: 17.11.1995 / 17:45:40 / cg"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   628
! !
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   629
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   630
!SoundStream methodsFor:'catching invalid methods'!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   631
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   632
pathName:filename
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   633
    "catch pathname access - its fixed here"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   634
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   635
    self shouldNotImplement
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   636
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   637
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   638
pathName:filename in:aDirectory
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   639
    "catch pathname access - its fixed here"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   640
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   641
    self shouldNotImplement
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   642
! !
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   643
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   644
!SoundStream methodsFor:'mode setting'!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   645
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   646
bitsPerSample
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   647
    "return the number of bits per sample - usually 8"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   648
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   649
    ^ bitsPerSample
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   650
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   651
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   652
bitsPerSample:aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   653
    "set the number of bits per sample"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   654
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   655
    bitsPerSample := aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   656
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   657
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   658
numberOfChannels
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   659
    "return the number of channels (1 or 2; usually 1)"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   660
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   661
    ^ numberOfChannels
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   662
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   663
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   664
numberOfChannels:aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   665
    "set the number of channels"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   666
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   667
    numberOfChannels := aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   668
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   669
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   670
sampleRate
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   671
    "return the sample rate"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   672
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   673
    ^ sampleRate
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   674
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   675
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   676
sampleRate:aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   677
    "set the sample rate in hertz - on some
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   678
     devices, this is a nop"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   679
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   680
    self setSampleRate:aNumber.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   681
! !
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   682
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   683
!SoundStream methodsFor:'private'!
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   684
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   685
dumpSettings
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   686
    "debugging interface - dump the current settings"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   687
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   688
    |fd blockSize speed channels stereo|
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   689
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   690
    fd := self fileDescriptor.
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   691
    fd isNil ifTrue:[
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   692
	self error.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   693
	^ nil
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   694
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   695
%{
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   696
    int f = __intVal(fd);
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   697
    int __blockSize = -1;
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   698
    int __speed = 0;
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   699
    int __stereo = 0;
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   700
    int __channels = 0;
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   701
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   702
#if defined(DEV_AUDIO) 
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   703
    channels = __MKSMALLINT(1);
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   704
    stereo = __MKSMALLINT(0);
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   705
    speed = __MKSMALLINT(8000);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   706
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   707
# if defined(SNDCTL_DSP_GETBLKSIZE)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   708
    if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   709
	blockSize = __MKSMALLINT(__blockSize);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   710
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   711
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   712
# if defined(SNDCTL_DSP_CHANNELS)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   713
    if (ioctl(f, SNDCTL_DSP_CHANNELS, &__channels) >= 0) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   714
	channels = __MKSMALLINT(__channels);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   715
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   716
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   717
# if defined(SNDCTL_DSP_STEREO)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   718
    if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   719
	stereo = __MKSMALLINT(__stereo);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   720
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   721
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   722
# if defined(SNDCTL_DSP_SPEED)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   723
    if (ioctl(f, SNDCTL_DSP_SPEED, &__speed) >= 0) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   724
	speed = __MKSMALLINT(__speed);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   725
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   726
# endif
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   727
#endif /* DEV_AUDIO */
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   728
%}.
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   729
    blockSize notNil ifTrue:[
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   730
	Transcript show:'blockSize: '; showCR:blockSize
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   731
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   732
    speed notNil ifTrue:[
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   733
	Transcript show:'speed: '; showCR:speed
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   734
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   735
    channels notNil ifTrue:[
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   736
	Transcript show:'channels: '; showCR:channels
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   737
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   738
    stereo notNil ifTrue:[
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   739
	Transcript show:'stereo: '; showCR:stereo
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   740
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   741
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   742
    Transcript show:'audioFormats: '; showCR:(self supportedAudioFormats).
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   743
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   744
    "
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   745
     self writing dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   746
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   747
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   748
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   749
initialize 
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   750
    "initialize for least common mode"
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   751
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   752
    buffered := false.
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   753
    bitsPerSample := self class defaultBitsPerSample.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   754
    audioFormat := self class defaultAudioFormat.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   755
    numberOfChannels := self class defaultNumberOfChannels.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   756
    sampleRate := self class defaultSampleRate.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   757
    pathName := nil.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   758
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   759
    OperatingSystem getOSType ~= 'win32' ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   760
	'/dev/audio' asFilename exists ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   761
	    "/
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   762
	    "/ sunos or linux
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   763
	    "/
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   764
	    pathName := '/dev/audio'.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   765
	].
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   766
    ].
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   767
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   768
    "Created: 17.11.1995 / 17:28:14 / cg"
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   769
!
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   770
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   771
resetSoundCard
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   772
    "debugging interface - reset the soundCard"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   773
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   774
    |fd|
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   775
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   776
    filePointer notNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   777
	fd := self fileDescriptor.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   778
	fd isNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   779
	    self error.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   780
	    ^ nil
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   781
	]
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   782
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   783
%{
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   784
    int f = __intVal(fd);
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   785
    int __dummy;
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   786
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   787
#if defined(DEV_AUDIO)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   788
    if (__isSmallInteger(fd)) {
614
565ea4308322 make it compilable on elder linux's
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
   789
# if defined(SNDCTL_DSP_RESET)
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   790
	if (ioctl(f, SNDCTL_DSP_RESET, &__dummy) >= 0) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   791
	    RETURN (self);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   792
	}
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   793
# endif
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   794
    }
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   795
#endif
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   796
%}.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   797
    ^ UnsupportedOperationSignal raise
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   798
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   799
    "
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   800
     self writing resetSoundCard; dumpSettings; close
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   801
    "
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   802
!
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   803
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   804
setAudioFormat:aSymbol
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   805
    "set the format of the audio data as specified by aSymbol.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   806
     Returns true if sucessfull - may fail with some formats on many sound devices."
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   807
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   808
    |fd|
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   809
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   810
    filePointer notNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   811
	fd := self fileDescriptor.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   812
	fd isNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   813
	    self error.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   814
	    ^ nil
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   815
	]
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   816
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   817
%{
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   818
    int f = __intVal(fd);
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
   819
    int __fmt = 0, __fmtWant;
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   820
    union {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   821
	unsigned short us;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   822
	unsigned char ub[2];
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   823
    } u;
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
   824
    OBJ sym = aSymbol;
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   825
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   826
#if defined(DEV_AUDIO)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   827
    if (__isSmallInteger(fd)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   828
	if (__isSymbol(sym)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   829
	    if (sym == @symbol(U16)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   830
		u.us = 0x1234;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   831
		if (u.ub[0] == 0x34) {
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
   832
/* printf("U16_LE\n"); */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   833
		    sym = @symbol(U16_LE);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   834
		} else {
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
   835
/* printf("U16_BE\n"); */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   836
		    sym = @symbol(U16_BE);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   837
		}
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   838
	    } else if (sym == @symbol(S16)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   839
		u.us = 0x1234;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   840
		if (u.ub[0] == 0x34) {
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
   841
/* printf("S16_LE\n"); */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   842
		   sym = @symbol(S16_LE);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   843
		} else {
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
   844
/* printf("S16_BE\n"); */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   845
		   sym = @symbol(S16_BE);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   846
		}
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   847
	    }
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   848
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   849
	    if (0) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   850
#ifdef AFMT_MU_LAW
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   851
	    } else if (sym == @symbol(MU_LAW)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   852
		__fmt = AFMT_MU_LAW;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   853
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   854
#ifdef AFMT_A_LAW
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   855
	    } else if (sym == @symbol(A_LAW)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   856
		__fmt = AFMT_A_LAW;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   857
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   858
#ifdef AFMT_IMA_ADPCM
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   859
	    } else if (sym == @symbol(IMA_ADPCM)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   860
		__fmt = AFMT_IMA_ADPCM;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   861
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   862
#ifdef AFMT_U8
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   863
	    } else if (sym == @symbol(U8)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   864
		__fmt = AFMT_U8;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   865
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   866
#ifdef AFMT_S8
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   867
	    } else if (sym == @symbol(S8)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   868
		__fmt = AFMT_S8;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   869
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   870
#ifdef AFMT_U16_LE
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   871
	    } else if (sym == @symbol(U16_LE)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   872
		__fmt = AFMT_U16_LE;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   873
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   874
#ifdef AFMT_U16_BE
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   875
	    } else if (sym == @symbol(U16_BE)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   876
		__fmt = AFMT_U16_BE;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   877
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   878
#ifdef AFMT_S16_LE
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   879
	    } else if (sym == @symbol(S16_LE)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   880
		__fmt = AFMT_S16_LE;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   881
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   882
#ifdef AFMT_S16_BE
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   883
	    } else if (sym == @symbol(S16_BE)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   884
		__fmt = AFMT_S16_BE;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   885
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   886
#ifdef AFMT_MPEG
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   887
	    } else if (sym == @symbol(MPEG)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   888
		__fmt = AFMT_MPEG;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   889
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   890
	    } else {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   891
		fprintf(stderr, "bad format: %s\n", __stringVal(sym));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   892
		goto bad;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   893
	    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   894
	}
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   895
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   896
	__fmtWant = __fmt;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   897
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   898
#ifdef SNDCTL_DSP_SETFMT
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   899
	if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   900
	    if (__fmt == __fmtWant) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   901
		__INST(audioFormat) = sym;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   902
		RETURN (self);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   903
	    } else {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   904
		/* fprintf(stderr, "want: %x; got: %x\n", __fmtWant, __fmt); */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   905
	    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   906
	} else {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   907
		/* fprintf(stderr, "got err-return from setFmp %x\n", __fmt); */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   908
	}
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   909
#endif /* SNDCTL_DSP_SETFMT */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   910
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   911
bad: ;
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   912
    }
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   913
#endif /* DEV_AUDIO */
614
565ea4308322 make it compilable on elder linux's
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
   914
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   915
%}.
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
   916
    ^ UnsupportedOperationSignal raise
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   917
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   918
    "
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   919
     self writing setAudioFormat:#'MU_LAW'; close
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
   920
     self writing setAudioFormat:#'U8'; dumpSettings; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
   921
     self writing setAudioFormat:#'MPEG'; dumpSettings; close
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   922
    "
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   923
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   924
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   925
setChannels:nChannels
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   926
    "set the number of channels (1 -> mono; 2 -> stereo).
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   927
     Returns true if sucessfull - may fail with many sound devices."
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   928
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   929
    |fd|
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   930
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   931
    filePointer notNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   932
	fd := self fileDescriptor.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   933
	fd isNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   934
	    self error.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   935
	    ^ nil
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   936
	]
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   937
    ].
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   938
%{
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   939
    int f = __intVal(fd);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   940
    int __nCh = 0;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   941
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   942
#if defined(DEV_AUDIO) && defined(SOUND_PCM_WRITE_CHANNELS)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   943
    if (__isSmallInteger(fd) && __isSmallInteger(nChannels)) {
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   944
	__nCh = __intVal(nChannels);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   945
	if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   946
	    __INST(numberOfChannels) = nChannels;
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   947
	    RETURN (self);
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   948
	}
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   949
    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   950
#endif
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   951
%}.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   952
    ^ UnsupportedOperationSignal raise
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   953
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   954
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   955
     self writing setChannels:2; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   956
     self writing setChannels:2; setSampleRate:10000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   957
     self writing setChannels:2; setSampleRate:40000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   958
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   959
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   960
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   961
setFragmentSize:blockSize
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   962
    "set the soundDrivers fragmentSize.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   963
     Returns true if sucessfull - may fail with many sound devices."
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   964
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   965
    |fd|
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   966
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   967
    filePointer notNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   968
	fd := self fileDescriptor.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   969
	fd isNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   970
	    self error.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   971
	    ^ nil
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   972
	]
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   973
    ].
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   974
%{
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   975
    int f = __intVal(fd);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   976
    int __blockSize = 0;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   977
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   978
#if defined(DEV_AUDIO) && defined(SNDCTL_DSP_SETFRAGMENT)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   979
    if (__isSmallInteger(fd) && __isSmallInteger(blockSize)) {
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   980
	__blockSize = __intVal(blockSize);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   981
	if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   982
	    /* __INST(blockSize) = blockSize; */
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   983
	    RETURN (self);
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   984
	}
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   985
    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   986
#endif
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   987
%}.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   988
    ^ UnsupportedOperationSignal raise
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   989
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   990
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   991
setSampleRate:hz
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   992
    "set the sample rate.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   993
     Returns true if sucessfull - may fail with many sound devices."
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   994
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   995
    |fd|
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   996
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   997
    filePointer notNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   998
	fd := self fileDescriptor.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   999
	fd isNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1000
	    self error.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1001
	    ^ nil
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1002
	]
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1003
    ].
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1004
%{
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1005
    int f = __intVal(fd);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1006
    int __rate = 0;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1007
    int __rateWant;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1008
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1009
#if defined(DEV_AUDIO) && defined(SOUND_PCM_WRITE_RATE)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1010
    if (__isSmallInteger(fd) && __isSmallInteger(hz)) {
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1011
	__rate = __rateWant = __intVal(hz);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1012
	if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1013
	    if (__rate != __rateWant) {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1014
		fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1015
		hz = __MKSMALLINT(__rate);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1016
	    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1017
	    __INST(sampleRate) = hz;
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1018
	    RETURN (self);
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1019
	}
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1020
    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1021
#endif
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1022
%}.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1023
    ^ UnsupportedOperationSignal raise
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1024
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1025
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1026
     self writing setSampleRate:10000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1027
     self writing setSampleRate:1000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1028
    "
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1029
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1030
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1031
supportedAudioFormats
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1032
    "return a collection of supported audio formats.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1033
     returned symbols are:
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1034
	U8        unsigned 8bit samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1035
	S8        signed 8bit samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1036
	MU_LAW    u-law encoded 8bit samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1037
	A_LAW     a-law encoded 8bit samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1038
	IMA_ADPCM adpcm encoded
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1039
	U16       unsigned 16bit samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1040
	U16_LE    unsigned 16bit big endian samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1041
	U16_BE    unsigned 16bit big endian samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1042
	S16       signed 16bit little endian samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1043
	S16_LE    signed 16bit little endian samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1044
	S16_BE    signed 16bit big endian samples
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1045
	MPEG      audio mpeg encoded
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1046
	PCM       pcm
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1047
    "
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1048
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1049
    |fd audioFormatMask
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1050
     supportedFormats
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1051
     supports_MU_LAW supports_A_LAW
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1052
     supports_IMA_ADPCM supports_U8
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1053
     supports_S16_LE supports_S16_BE
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1054
     supports_S8 supports_U16_LE
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1055
     supports_U16_BE supports_MPEG supports_PCM|
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1056
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1057
    fd := self fileDescriptor.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1058
    fd isNil ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1059
	self error.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1060
	^ nil
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1061
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1062
%{
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1063
    int f = __intVal(fd);
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1064
    int __audioFormatMask = 0;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1065
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1066
#if defined(DEV_AUDIO)
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1067
    supports_MU_LAW = true;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1068
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1069
# if defined(SNDCTL_DSP_GETFMTS)
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1070
    if (ioctl(f, SNDCTL_DSP_GETFMTS, &__audioFormatMask) >= 0) {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1071
	audioFormatMask = __MKSMALLINT(__audioFormatMask);
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1072
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1073
#  ifdef AFMT_MU_LAW
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1074
	supports_MU_LAW = (__audioFormatMask & AFMT_MU_LAW) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1075
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1076
#  ifdef AFMT_A_LAW
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1077
	supports_A_LAW = (__audioFormatMask & AFMT_A_LAW) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1078
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1079
#  ifdef AFMT_IMA_ADPCM
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1080
	supports_IMA_ADPCM = (__audioFormatMask & AFMT_IMA_ADPCM) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1081
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1082
#  ifdef AFMT_U8
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1083
	supports_U8 = (__audioFormatMask & AFMT_U8) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1084
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1085
#  ifdef AFMT_S16_LE
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1086
	supports_S16_LE = (__audioFormatMask & AFMT_S16_LE) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1087
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1088
#  ifdef AFMT_S16_BE
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1089
	supports_S16_BE = (__audioFormatMask & AFMT_S16_BE) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1090
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1091
#  ifdef AFMT_S8
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1092
	supports_S8 = (__audioFormatMask & AFMT_S8) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1093
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1094
#  ifdef AFMT_U16_LE
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1095
	supports_U16_LE = (__audioFormatMask & AFMT_U16_LE) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1096
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1097
#  ifdef AFMT_U16_BE
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1098
	supports_U16_BE = (__audioFormatMask & AFMT_U16_BE) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1099
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1100
#  ifdef AFMT_MPEG
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1101
	supports_MPEG = (__audioFormatMask & AFMT_MPEG) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1102
#  endif
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1103
    }
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1104
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1105
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1106
#endif /* DEV_AUDIO */
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1107
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1108
#ifdef IRIS_AUDIO
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1109
    supports_U8 = true;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1110
    supports_U16_BE = true;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1111
#endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1112
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1113
#ifdef WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1114
    supports_S16_LE = true;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1115
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1116
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1117
%}.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1118
    supportedFormats := IdentitySet new.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1119
    supports_MU_LAW ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1120
	supportedFormats add:#'MU_LAW'
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1121
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1122
    supports_A_LAW ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1123
	supportedFormats add:#'A_LAW'
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1124
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1125
    supports_IMA_ADPCM ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1126
	supportedFormats add:#'IMA_ADPCM'
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1127
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1128
    supports_S8 ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1129
	supportedFormats add:#'S8'
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1130
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1131
    supports_U8 ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1132
	supportedFormats add:#'U8'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1133
    ].
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1134
    supports_S16_LE ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1135
	supportedFormats add:#'S16_LE'.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1136
	supportedFormats add:#'S16'.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1137
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1138
    supports_S16_BE ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1139
	supportedFormats add:#'S16_BE'.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1140
	supportedFormats add:#'S16'.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1141
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1142
    supports_U16_LE ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1143
	supportedFormats add:#'U16_LE'.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1144
	supportedFormats add:#'U16'.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1145
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1146
    supports_U16_BE ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1147
	supportedFormats add:#'U16_BE'.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1148
	supportedFormats add:#'U16'.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1149
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1150
    supports_MPEG ifTrue:[
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1151
	supportedFormats add:#'MPEG'
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1152
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1153
    ^ supportedFormats.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1154
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1155
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1156
     |s formats|
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1157
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1158
     s := self writing.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1159
     formats := s supportedAudioFormats.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1160
     s close.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1161
     formats 
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1162
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1163
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1164
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1165
!SoundStream methodsFor:'redefined'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1166
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1167
XXclose
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1168
    OperatingSystem getOSType = 'irix' ifTrue:[
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1169
	^ self closeFile
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1170
    ].
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1171
    OperatingSystem getOSType = 'win32' ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1172
	^ self closeFile
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1173
    ].
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1174
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1175
    super close
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1176
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1177
    "Created: 17.11.1995 / 17:27:26 / cg"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1178
    "Modified: 17.11.1995 / 17:47:13 / cg"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1179
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1180
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1181
closeFile
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1182
    "a stream has been collected - close the file"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1183
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1184
%{
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1185
#ifdef IRIS_AUDIO
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1186
    OBJ port;
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1187
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1188
    if ((port = __INST(alPort)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1189
	__INST(alPort) = nil;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1190
	ALcloseport(__ALportVal(port));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1191
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1192
    RETURN (self);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1193
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1194
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1195
#ifdef WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1196
    OBJ oDirectSound, oDSBuffer;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1197
    LPDIRECTSOUND       t_pDirectSound;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1198
    LPDIRECTSOUNDBUFFER t_pDSBuffer;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1199
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1200
    if ((oDSBuffer = __INST(pDSBuffer)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1201
	__INST(pDSBuffer) = nil;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1202
	t_pDSBuffer = __DSBufferVal(oDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1203
	if (t_pDSBuffer) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1204
	    IDirectSoundBuffer_Stop(t_pDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1205
	    IDirectSoundBuffer_Release(t_pDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1206
	}
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1207
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1208
    if ((oDirectSound = __INST(pDirectSound)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1209
	__INST(pDirectSound) = nil;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1210
	t_pDirectSound = __DirectSoundVal(oDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1211
	if (t_pDirectSound) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1212
	    IDirectSound_Release(t_pDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1213
	}
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1214
    }
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1215
    RETURN (self);
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1216
#endif
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1217
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1218
#if defined(DEV_AUDIO)
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1219
    OBJ fp;
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1220
    int fd;
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1221
    FILE *f;
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1222
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1223
    if ((fp = __INST(filePointer)) != nil) {
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1224
	f = __FILEVal(fp);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1225
	__INST(filePointer) = nil;
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1226
# ifdef LINUX
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1227
	sigsetmask(~0);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1228
# endif
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1229
	if (__INST(buffered) == true) {
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1230
	    fflush(f);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1231
	    fclose(f);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1232
	} else {
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1233
	    fd = fileno(f);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1234
	    close(fd);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1235
	    fclose(f);
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1236
	}
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1237
# ifdef LINUX
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1238
	sigsetmask(0);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1239
# endif
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1240
    }
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1241
    RETURN (self);
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1242
#endif /* DEV_AUDIO */
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1243
%}.
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1244
    ^ super closeFile
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1245
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1246
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1247
flush
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1248
    "wait until all sound has been played"
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1249
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1250
    |fd|
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1251
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1252
    fd := self fileDescriptor.
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1253
%{ 
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1254
#ifdef IRIS_AUDIO
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1255
    OPJ port;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1256
    ALport p;
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1257
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1258
    if ((port = __INST(alPort)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1259
	p = __ALportVal(port);
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1260
	while (ALgetfilled(p) > 0) {
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1261
	    sginap(1);
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1262
	}
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1263
    }
353
d1b7f731a331 Avoid callong of getOStype.
Stefan Vogel <sv@exept.de>
parents: 277
diff changeset
  1264
    RETURN(self);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1265
#endif
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1266
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1267
#if defined(DEV_AUDIO)
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1268
    if (__isSmallInteger(fd)) {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1269
	int f = __intVal(fd);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1270
	/* ... */
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1271
    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1272
#endif
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1273
%}.
353
d1b7f731a331 Avoid callong of getOStype.
Stefan Vogel <sv@exept.de>
parents: 277
diff changeset
  1274
    "dont know how to wait on non-iris systems"
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1275
    ^ self
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1276
!
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1277
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1278
isOpen
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1279
    alPort notNil ifTrue:[^ true].
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1280
    pDirectSound notNil ifTrue:[^ true].
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1281
    ^ filePointer notNil
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1282
!
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1283
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1284
nextBytes:count into:anObject startingAt:start
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1285
    "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
  1286
     bytes read or nil on error.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1287
     Use with ByteArrays only."
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1288
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1289
%{
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1290
#ifdef IRIS_AUDIO
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1291
  {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1292
    OBJ port;
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1293
    ALport p;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1294
    int cnt, offs, nSamp;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1295
    int objSize;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1296
    char *cp;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1297
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1298
    if ((port = __INST(alPort)) != nil) {
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1299
	if (__INST(mode) != _writeonly) {
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1300
	    if (__bothSmallInteger(count, start)) {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1301
		cnt = __intVal(count);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1302
		offs = __intVal(start) - 1;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1303
		p = __ALportVal(port);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1304
		objSize = _Size(anObject) - OHDR_SIZE;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1305
		if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1306
		    cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1307
		    if (__INST(bitsPerSample) == __MKSMALLINT(16))
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1308
			nSamp = cnt / 2;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1309
		    else
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1310
			nSamp = cnt;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1311
		    ALreadsamps(p, cp, nSamp);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1312
		    RETURN ( __MKSMALLINT(cnt) );
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1313
		}
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1314
	    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1315
	}
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1316
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1317
  }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1318
#endif
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1319
%}.
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1320
    OperatingSystem getOSType = 'irix' ifFalse:[
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1321
	OperatingSystem getOSType = 'win32' ifFalse:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1322
	    ^ super nextPutBytes:count from:anObject startingAt:start
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1323
	].
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1324
    ].
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1325
    filePointer isNil ifTrue:[^ self errorNotOpen].
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1326
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1327
    self primitiveFailed
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1328
!
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1329
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1330
nextPutBytes:count from:anObject startingAt:start
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1331
    "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
  1332
     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
  1333
     Redefined, since IRIS audio library cannot be used with stdio.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1334
     (at least I dont know). Use with ByteArrays only."
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1335
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1336
%{
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1337
#ifdef IRIS_AUDIO
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1338
  {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1339
    OBJ port;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1340
    ALport p;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1341
    int cnt, offs, nSamp;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1342
    int objSize;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1343
    char *cp;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1344
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1345
    if ((port = __INST(alPort)) != nil) {
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1346
	if (__INST(mode) != @symbol(readonly)) {
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1347
	    if (__bothSmallInteger(count, start)) {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1348
		cnt = __intVal(count);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1349
		offs = __intVal(start) - 1;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1350
		p = __ALportVal(port);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1351
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1352
		/*
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1353
		 * compute number of samples
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1354
		 */
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1355
		objSize = _Size(anObject) - OHDR_SIZE;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1356
		if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1357
		    cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1358
		    if (__INST(bitsPerSample) == __MKSMALLINT(16))
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1359
			nSamp = cnt / 2;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1360
		    else
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1361
			nSamp = cnt;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1362
		    ALwritesamps(p, cp, cnt);
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1363
		    RETURN ( count );
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1364
		}
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1365
	    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1366
	}
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1367
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1368
  }
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1369
#endif /* SGI_AUDIO */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1370
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1371
#ifdef WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1372
  {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1373
      HRESULT hr;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1374
      DWORD status;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1375
      LPVOID lpbuf1 = NULL;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1376
      LPVOID lpbuf2 = NULL;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1377
      DWORD dwsize1 = 0;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1378
      DWORD dwsize2 = 0;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1379
      DWORD playPos, safePos, endWrite;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1380
      DWORD millis;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1381
      OBJ oDirectSound, oDSBuffer;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1382
      LPDIRECTSOUND       t_pDirectSound = (LPDIRECTSOUND)0;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1383
      LPDIRECTSOUNDBUFFER t_pDSBuffer = (LPDIRECTSOUNDBUFFER)0;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1384
      int t_cbBufOffset, t_cbBufSize;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1385
      short *buf;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1386
      int cnt, offs;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1387
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1388
      if ((oDSBuffer = __INST(pDSBuffer)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1389
	  t_pDSBuffer = __DSBufferVal(oDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1390
      }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1391
      if ((oDirectSound = __INST(pDirectSound)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1392
	  t_pDirectSound = __DirectSoundVal(oDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1393
      }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1394
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1395
      if (!t_pDSBuffer || !t_pDirectSound) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1396
	  RETURN (0);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1397
      }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1398
      t_cbBufOffset = __intVal(__INST(cbBufOffset));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1399
      t_cbBufSize = __intVal(__INST(cbBufSize));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1400
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1401
      cnt = __intVal(count);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1402
      offs = __intVal(start) - 1;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1403
      buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1404
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1405
      // Should be playing, right?
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1406
      hr = IDirectSoundBuffer_GetStatus(t_pDSBuffer, &status );
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1407
      if (!(status && DSBSTATUS_PLAYING)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1408
	  printf("Buffer not playing!\n");
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1409
      }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1410
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1411
      // Sleep until we have enough room in buffer.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1412
      hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos );
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1413
      if( hr != DS_OK ) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1414
	  RETURN (0);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1415
      }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1416
      if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; 
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1417
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1418
      endWrite = t_cbBufOffset + RT_BUFFER_SIZE * sizeof(short);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1419
      while ( playPos < endWrite ) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1420
	  // Calculate number of milliseconds until we will have room, as
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1421
	  // time = distance * (milliseconds/second) / ((bytes/sample) * (samples/second)),
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1422
	  // rounded up.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1423
	  millis = (DWORD) (1.0 + ((endWrite - playPos) * 1000.0) / ( sizeof(short) * __intVal(__INST(sampleRate))));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1424
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1425
	  // Sleep for that long
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1426
	  Sleep( millis );
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1427
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1428
	  // Wake up, find out where we are now
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1429
	  hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos );
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1430
	  if( hr != DS_OK ) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1431
	      RETURN (0);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1432
	  }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1433
	  if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; // unwrap offset
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1434
      }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1435
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1436
      // Lock free space in the DS
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1437
      hr = IDirectSoundBuffer_Lock(t_pDSBuffer, t_cbBufOffset, RT_BUFFER_SIZE * sizeof(short), &lpbuf1, &dwsize1, &lpbuf2, &dwsize2, 0);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1438
      if (hr == DS_OK) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1439
	  // Copy the buffer into the DS
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1440
	  CopyMemory(lpbuf1, buf, dwsize1);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1441
	  if(NULL != lpbuf2) CopyMemory(lpbuf2, buf+dwsize1, dwsize2);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1442
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1443
	  // Update our buffer offset and unlock sound buffer
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1444
	  t_cbBufOffset = (t_cbBufOffset + dwsize1 + dwsize2) % t_cbBufSize;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1445
	  IDirectSoundBuffer_Unlock(t_pDSBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1446
      }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1447
      __INST(cbBufOffset) = __MKSMALLINT(t_cbBufOffset);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1448
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1449
      RETURN (0);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1450
  }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1451
#endif /* WIN32 */
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1452
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1453
#if defined(DEV_AUDIO)
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1454
   /*
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1455
    * redefine to work around a bug in the linux sound driver;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1456
    * if a write is interrupted (EINTR), it is not defined, how many
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1457
    * bytes have been written to the device.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1458
    * I.e. a retry of the write may lead to ever-playing without ever
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1459
    * finishing.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1460
    *
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1461
    * As a workaround, disable signals here to prevent the write from
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1462
    * being interrupted.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1463
    */
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1464
    int cnt, offs, objSize, n;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1465
    char *cp;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1466
    OBJ fp;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1467
    FILE *f;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1468
    int fd;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1469
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1470
    if ((fp = __INST(filePointer)) != nil) {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1471
	f = __FILEVal(fp);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1472
	if (__INST(mode) != @symbol(readonly)) {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1473
	    if (__bothSmallInteger(count, start)) {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1474
		cnt = __intVal(count);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1475
		offs = __intVal(start) - 1;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1476
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1477
		objSize = _Size(anObject) - OHDR_SIZE;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1478
		if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  1479
		    do {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1480
			cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1481
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1482
			n = cnt;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1483
			if (n > 4096) n = 4096;
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  1484
# ifdef LINUX
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1485
			sigsetmask(~0);
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  1486
# endif
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1487
			if (__INST(buffered) == true) {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1488
			    n = fwrite(cp, 1, n, f);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1489
			} else {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1490
			    fd = fileno(f);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1491
			    n = write(fd, cp, n);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1492
			}
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  1493
# ifdef LINUX
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1494
			sigsetmask(0);
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  1495
# endif
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  1496
			__BEGIN_INTERRUPTABLE__
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  1497
			__END_INTERRUPTABLE__
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1498
			if (n > 0) {
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  1499
			    offs += n;
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1500
			    cnt -= n;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1501
			}
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1502
		    } while (cnt);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1503
		}
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1504
		RETURN (count);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1505
	    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1506
	}
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1507
    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1508
#endif
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1509
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1510
%}.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1511
    ^ super nextPutBytes:count from:anObject startingAt:start
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1512
!
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1513
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1514
openForReading
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1515
    |rslt|
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1516
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1517
    mode := #readonly.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1518
    didWrite := false.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1519
    (rslt :=  self openWithMode:ReadMode) notNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1520
	Lobby register:self
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1521
    ].
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1522
    ^ rslt
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1523
!
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1524
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1525
openForWriting
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1526
    "open the file writeonly.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1527
     If the file does not exist its an error, return nil; 
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1528
     otherwise return the receiver."
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1529
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1530
    |rslt|
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1531
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1532
    mode := #writeonly.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1533
    didWrite := true.
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1534
    (rslt := self openWithMode:WriteMode) notNil ifTrue:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1535
	Lobby register:self
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1536
    ].
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1537
    ^ rslt
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1538
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1539
    "Created: / 15.12.1997 / 13:13:56 / cg"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1540
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1541
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1542
openWithMode:aMode
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1543
%{
36
d046fe84ea67 *** empty log message ***
claus
parents: 31
diff changeset
  1544
#ifdef IRIS_AUDIO
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1545
  {
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1546
    ALconfig config;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1547
    ALport p;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1548
    long params[] = {
45
claus
parents: 36
diff changeset
  1549
	AL_INPUT_SOURCE, AL_INPUT_MIC,
claus
parents: 36
diff changeset
  1550
	AL_INPUT_RATE, 8000,
claus
parents: 36
diff changeset
  1551
	AL_OUTPUT_RATE, 8000,
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1552
    };
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1553
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1554
    config = ALnewconfig();
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
  1555
    if (__INST(numberOfChannels) == __MKSMALLINT(2))
45
claus
parents: 36
diff changeset
  1556
	ALsetchannels(config, AL_STEREO);
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1557
    else
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1558
	ALsetchannels(config, AL_MONO);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1559
    if (__INST(bitsPerSample) == __MKSMALLINT(16))
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1560
	ALsetwidth(config, AL_SAMPLE_16);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1561
    else
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1562
	ALsetwidth(config, AL_SAMPLE_8);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1563
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1564
    if (__isSmallInteger(__INST(sampleRate)))
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1565
	params[3] = params[5] = __intVal(__INST(sampleRate));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1566
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1567
    ALsetparams(AL_DEFAULT_DEVICE, params, 6);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1568
    p = ALopenport("smallchat", (char *)_stringVal(aMode), config);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1569
    if (p) {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1570
	OBJ t;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1571
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1572
	__INST(alPort) = t = __MKEXTERNALADDRESS(p); __STORE(self, t);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1573
    } else {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1574
	__INST(alPort) = nil;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1575
	RETURN (nil);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1576
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1577
    __INST(binary) = true;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1578
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1579
    ALfreeconfig(config);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1580
    /*
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1581
     * get the parameters actually installed
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1582
     */
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1583
    config = ALgetconfig(p);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1584
    switch (ALgetchannels(config)) {
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1585
	default:
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1586
	    /* cannot happen */
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1587
	case AL_MONO:
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1588
	    __INST(numberOfChannels) = __MKSMALLINT(1);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1589
	    break;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1590
	case AL_STEREO:
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1591
	    __INST(numberOfChannels) = __MKSMALLINT(2);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1592
	    break;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1593
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1594
    switch (ALgetwidth(config)) {
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1595
	default:
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1596
	    /* cannot happen */
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1597
	case AL_SAMPLE_8:
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1598
	    __INST(bitsPerSample) = __MKSMALLINT(8);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1599
	    break;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1600
	case AL_SAMPLE_16:
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1601
	    __INST(bitsPerSample) = __MKSMALLINT(16);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1602
	    break;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1603
	case AL_SAMPLE_24:
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1604
	    __INST(bitsPerSample) = __MKSMALLINT(24);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1605
	    break;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1606
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1607
    ALgetparams(AL_DEFAULT_DEVICE, params, 6);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1608
    __INST(sampleRate) = __MKSMALLINT(params[3]);
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1609
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1610
    ALfreeconfig(config);
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1611
    RETURN (self);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1612
  }
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1613
#endif /* SGI_AUDIO */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1614
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1615
#ifdef WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1616
  {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1617
    HRESULT result;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1618
    LPDIRECTSOUND       t_pDirectSound;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1619
    LPDIRECTSOUNDBUFFER t_pDSBuffer, t_pDSPrimeBuffer;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1620
    WAVEFORMATEX        wfFormat;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1621
    DSBUFFERDESC        dsbdDesc, primarydsbDesc;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1622
    BYTE                *pDSBuffData;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1623
    int                 t_cbBufSize;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1624
    int                 dwDataLen;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1625
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1626
    /* Create the DS object */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1627
    if ((result = DirectSoundCreate(NULL, &t_pDirectSound, NULL)) != DS_OK) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1628
	fprintf(stderr,"SoundStream: Cannot open default sound device!!\n");
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1629
	RETURN (nil);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1630
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1631
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1632
    /* Define the wave format structure */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1633
    wfFormat.wFormatTag = WAVE_FORMAT_PCM;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1634
    wfFormat.nChannels = __intVal(__INST(numberOfChannels));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1635
    wfFormat.nSamplesPerSec = __intVal(__INST(sampleRate));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1636
    wfFormat.wBitsPerSample = __intVal(__INST(bitsPerSample));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1637
    wfFormat.nBlockAlign = wfFormat.nChannels * wfFormat.wBitsPerSample / 8;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1638
    wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1639
    wfFormat.cbSize = 0;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1640
#if 0
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1641
    /* Setup the primary DS buffer description */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1642
    ZeroMemory(&primarydsbDesc, sizeof(DSBUFFERDESC));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1643
    primarydsbDesc.dwSize = sizeof(DSBUFFERDESC);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1644
    primarydsbDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1645
    primarydsbDesc.dwBufferBytes = 0;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1646
    primarydsbDesc.lpwfxFormat = NULL;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1647
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1648
    /* Create the primary DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1649
    if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &primarydsbDesc,
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1650
						 &t_pDSPrimeBuffer, NULL)) != DS_OK) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1651
	fprintf(stderr,"SoundStream: Cannot get the primary DS buffer address!\n");
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1652
	IDirectSound_Release(t_pDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1653
	RETURN (nil);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1654
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1655
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1656
    /* Set the primary DS buffer sound format.  We have to do this because
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1657
       the default primary buffer is 8-bit, 22kHz! */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1658
    if ((result = IDirectSoundBuffer_SetFormat(t_pDSPrimeBuffer, &wfFormat)) != DS_OK) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1659
	fprintf(stderr,"SoundStream: Cannot set the primary DS buffer to proper sound format (%x) (%d)!\n", result, result);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1660
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1661
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1662
	IDirectSound_Release(t_pDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1663
	RETURN (nil);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1664
    }
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1665
#endif
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1666
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1667
    /* Setup the secondary DS buffer description */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1668
    t_cbBufSize = RT_BUFFER_SIZE * sizeof(short) * NBUFS;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1669
    __INST(cbBufSize) = __MKSMALLINT(t_cbBufSize);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1670
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1671
    ZeroMemory(&dsbdDesc, sizeof(DSBUFFERDESC));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1672
    dsbdDesc.dwSize = sizeof(DSBUFFERDESC);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1673
    dsbdDesc.dwFlags = DSBCAPS_GLOBALFOCUS;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1674
    dsbdDesc.dwBufferBytes = t_cbBufSize;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1675
    dsbdDesc.lpwfxFormat = &wfFormat;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1676
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1677
    /* Create the secondary DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1678
    if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &dsbdDesc, &t_pDSBuffer, NULL)) != DS_OK) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1679
	fprintf(stderr,"SoundStream: couldn't create sound buffer!\n");
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1680
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1681
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1682
	IDirectSound_Release(t_pDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1683
	RETURN (nil);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1684
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1685
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1686
    /* Lock the DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1687
    if ((result = IDirectSoundBuffer_Lock(t_pDSBuffer, 0, t_cbBufSize, (LPLPVOID)&pDSBuffData,
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1688
					  &dwDataLen, NULL, NULL, 0)) != DS_OK) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1689
	fprintf(stderr,"SoundStream: couldn't lock sound buffer!\n");
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1690
	IDirectSoundBuffer_Stop(t_pDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1691
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1692
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1693
	IDirectSound_Release(t_pDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1694
	RETURN (nil);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1695
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1696
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1697
    /* Zero the DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1698
    ZeroMemory(pDSBuffData, dwDataLen);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1699
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1700
    /* Unlock the DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1701
    if ((result = IDirectSoundBuffer_Unlock(t_pDSBuffer, pDSBuffData, dwDataLen, NULL, 0)) != DS_OK) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1702
	fprintf(stderr,"SoundStream: couldn't unlock sound buffer!\n");
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1703
	IDirectSoundBuffer_Stop(t_pDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1704
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1705
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1706
	IDirectSound_Release(t_pDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1707
	RETURN (nil);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1708
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1709
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1710
    __INST(cbBufOffset) = __MKSMALLINT(0);  // reset last write position to start of buffer
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1711
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1712
    /* Start the buffer playback */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1713
    if ((result = IDirectSoundBuffer_Play(t_pDSBuffer, 0, 0, DSBPLAY_LOOPING ) != DS_OK)) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1714
	fprintf(stderr,"SoundStream: couldn't play sound buffer!\n");
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1715
	IDirectSoundBuffer_Stop(t_pDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1716
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1717
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1718
	IDirectSound_Release(t_pDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1719
	RETURN (nil);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1720
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1721
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1722
    {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1723
	OBJ t;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1724
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1725
	__INST(pDSBuffer) = t = __MKEXTERNALADDRESS(t_pDSBuffer); __STORE(self, t);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1726
	__INST(pDirectSound) = t = __MKEXTERNALADDRESS(t_pDirectSound); __STORE(self, t);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1727
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1728
    RETURN (self);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1729
  }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1730
#endif /* WIN32 */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1731
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1732
%}.
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1733
    "its a regular file open (i.e. /dev/audio) "
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1734
    ^ super openWithMode:aMode
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1735
! !
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1736
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1737
!SoundStream methodsFor:'sine wave generation'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1738
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1739
tuneTone
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1740
    self tuneTone:440
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1741
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1742
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1743
     SoundStream writing tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1744
     SoundStream writing setSampleRate:4000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1745
     SoundStream writing setSampleRate:8000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1746
     SoundStream writing setSampleRate:10000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1747
     SoundStream writing setSampleRate:20000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1748
     SoundStream writing setSampleRate:40000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1749
     SoundStream writing setSampleRate:20000; dumpSettings; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1750
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1751
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1752
    "Modified: / 12.12.1997 / 20:34:42 / cg"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1753
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1754
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1755
tuneTone16:freq
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1756
    "output some tone for 3 seconds in S16 audioFormat - a test method"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1757
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1758
    |buffer numSamples val scale oldFormat|
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1759
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1760
    "allocate memory for 1sec playing time"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1761
    numSamples := self sampleRate.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1762
    buffer := WordArray new:numSamples.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1763
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1764
    "fill it with a sine wave"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1765
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1766
    scale := freq * 2 * (Float pi).
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1767
    1 to:numSamples do:[:i |
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1768
	val := (scale * i / numSamples) sin.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1769
	val := (val * 16r7FFF) rounded bitAnd:16rFFFF.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1770
	buffer at:i put:val
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1771
    ].
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1772
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1773
    oldFormat := audioFormat.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1774
    self setAudioFormat:#S16.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1775
    1 to:3 do:[:s |
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1776
	self nextPutBytes:(numSamples*2) from:buffer startingAt:1
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1777
    ].
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1778
    self setAudioFormat:oldFormat.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1779
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1780
    "of course, the frequency should be below half the
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1781
     sampleRate - hear below ...
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1782
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1783
     SoundStream writing setSampleRate:4000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1784
     SoundStream writing setSampleRate:8000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1785
     SoundStream writing setSampleRate:10000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1786
     SoundStream writing setSampleRate:20000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1787
     SoundStream writing setSampleRate:40000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1788
    "
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1789
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1790
    "Modified: / 15.12.1997 / 13:46:57 / cg"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1791
!
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1792
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1793
tuneTone:freq
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1794
    "output some tone for 3 seconds in U8 audioFormat - a test method"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1795
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1796
    |buffer numSamples val scale oldFormat|
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1797
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1798
    "allocate memory for 1sec playing time"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1799
    numSamples := self sampleRate.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1800
    buffer := ByteArray new:numSamples.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1801
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1802
    "fill it with a sine wave"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1803
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1804
    scale := freq * 2 * (Float pi).
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1805
    1 to:numSamples do:[:i |
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1806
	val := (scale * i / numSamples) sin.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1807
	val := (val * 127 + 128) rounded.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1808
	buffer at:i put:val
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1809
    ].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1810
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1811
    oldFormat := audioFormat.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1812
    self setAudioFormat:#U8.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1813
    1 to:3 do:[:s |
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1814
	self nextPutBytes:numSamples from:buffer startingAt:1
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1815
    ].
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1816
    self setAudioFormat:oldFormat.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1817
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1818
    "of course, the frequency should be below half the
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1819
     sampleRate - hear below ...
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1820
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1821
     SoundStream writing tuneTone; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1822
     SoundStream writing setSampleRate:4000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1823
     SoundStream writing setSampleRate:4000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1824
     SoundStream writing setSampleRate:8000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1825
     SoundStream writing setSampleRate:8000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1826
     SoundStream writing setSampleRate:8000; tuneTone:4000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1827
     SoundStream writing setSampleRate:10000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1828
     SoundStream writing setSampleRate:10000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1829
     SoundStream writing setSampleRate:10000; tuneTone:4000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1830
     SoundStream writing setSampleRate:20000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1831
     SoundStream writing setSampleRate:20000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1832
     SoundStream writing setSampleRate:20000; tuneTone:4000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1833
     SoundStream writing setSampleRate:20000; tuneTone:8000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1834
     SoundStream writing setSampleRate:40000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1835
     SoundStream writing setSampleRate:40000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1836
     SoundStream writing setSampleRate:40000; tuneTone:4000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1837
     SoundStream writing setSampleRate:40000; tuneTone:8000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1838
     SoundStream writing setSampleRate:40000; tuneTone:10000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1839
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1840
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1841
    "Modified: / 15.12.1997 / 13:43:05 / cg"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1842
!
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1843
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1844
tuneToneMU:freq
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1845
    "output some tone for 3 seconds in MU_LAW audioFormat - a test method"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1846
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1847
    |buffer numSamples val scale oldFormat|
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1848
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1849
    "allocate memory for 1sec playing time"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1850
    numSamples := self sampleRate.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1851
    buffer := ByteArray new:numSamples.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1852
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1853
    "fill it with a sine wave"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1854
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1855
    scale := freq * 2 * (Float pi).
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1856
    1 to:numSamples do:[:i |
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1857
	val := (scale * i / numSamples) sin.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1858
	val := (val * 16r7FFF) rounded.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1859
	buffer at:i put:(self class linear16ToUlaw:val)
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1860
    ].
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1861
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1862
    oldFormat := audioFormat.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1863
    self setAudioFormat:#MU_LAW.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1864
    1 to:3 do:[:s |
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1865
	self nextPutBytes:numSamples from:buffer startingAt:1
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1866
    ].
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1867
    self setAudioFormat:oldFormat.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1868
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1869
    "of course, the frequency should be below half the
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1870
     sampleRate - hear below ...
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1871
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1872
     SoundStream writing setSampleRate:8000; tuneToneMU:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1873
     SoundStream writing setSampleRate:10000; tuneToneMU:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1874
     SoundStream writing setSampleRate:20000; tuneToneMU:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1875
     SoundStream writing setSampleRate:40000; tuneToneMU:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1876
    "
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1877
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1878
    "Modified: / 15.12.1997 / 13:46:19 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1879
! !
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1880
152
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
  1881
!SoundStream class methodsFor:'documentation'!
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
  1882
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
  1883
version
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1884
^ '$Header: /cvs/stx/stx/libbasic2/Attic/SoundStr.st,v 1.34 1998-12-21 11:43:58 cg Exp $'! !
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1885
SoundStream initialize!