SoundStream.st
author Stefan Vogel <sv@exept.de>
Wed, 29 Jan 2014 14:35:28 +0100
changeset 3156 edeed9ecae5b
parent 3154 23ac6f3e69b6
child 3216 fdbf3212c1e9
permissions -rw-r--r--
initialize methods
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
"
918
c93d55269f9d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
c93d55269f9d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
    13
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
    14
FileStream subclass:#SoundStream
2418
4ea40741b2b5 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2321
diff changeset
    15
	instanceVariableNames:'sampleRate numberOfChannels bitsPerSample audioFormat handle1
4ea40741b2b5 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2321
diff changeset
    16
		handle2 bufferOffset bufferSize'
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
%{
725
c18d8d084a17 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 724
diff changeset
    24
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
    25
#include "stxOSDefs.h"
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
    26
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    27
#ifdef WIN32
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
    28
# ifndef NO_SOUND
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
    29
#  define xxxUSE_WIN32_DIRECTSOUND
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
    30
#  define USE_WIN32_WAVESOUND
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
    31
# endif
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    32
#endif
725
c18d8d084a17 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 724
diff changeset
    33
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    34
#ifdef IRIS
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    35
# ifndef IRIX5
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    36
#  define USE_IRIS_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    37
# endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    38
#endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    39
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    40
#ifndef USE_IRIS_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    41
# ifndef USE_ALSA_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    42
#  ifdef LINUX
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    43
#   define USE_DEV_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    44
#  endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    45
# endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    46
#endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    47
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    48
#ifdef USE_IRIS_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    49
# define IRIS_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    50
# include <audio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    51
# define __ALportVal(o)  (ALport)(__externalAddressVal(o))
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    52
# define alPort handle1
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    53
#endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    54
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    55
#ifdef USE_ALSA_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    56
# ifdef LINUX
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    57
#  define ALSA_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    58
#  include <alsa/asoundlib.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    59
#  define MAX_NR_OF_CHANNELS 8
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    60
#  define DEBUG_SOUND
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    61
#  define readHandle handle1
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    62
#  define writeHandle handle2
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    63
# endif
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    64
#endif
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
    65
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    66
#ifdef USE_DEV_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    67
# ifdef LINUX
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    68
#  include <stdio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    69
#  include <sys/soundcard.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    70
#  define DEV_AUDIO_DEFAULT_FREQ (8000)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    71
#  define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    72
#  define DEV_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    73
# endif
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
    74
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    75
# ifdef FREEBSD
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    76
#  include <stdio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    77
#  include <sys/time.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    78
#  include <sys/ioctl.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    79
#  include <machine/pcaudioio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    80
#  define DEV_AUDIO_DEFAULT_FREQ (8000)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    81
#  define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    82
#  define DEV_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    83
# endif
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
    84
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    85
# if defined(sunos) || defined(solaris)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    86
#  include <stdio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    87
#  ifdef solaris
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    88
#   include <sys/audioio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    89
#  else
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    90
#   include <sun/audioio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    91
#  endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    92
#  define DEV_AUDIO_DEFAULT_FREQ (8000)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    93
#  define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    94
#  define DEV_AUDIO
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
    95
# endif
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
    96
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    97
# if defined(hpux)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    98
#  include <stdio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
    99
#  include <sys/ioctl.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   100
#  include <sys/inode.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   101
#  include <sys/audio.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   102
#  include <sys/time.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   103
#  include <unistd.h>
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   104
#  define DEV_AUDIO_DEFAULT_FREQ (22050)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   105
#  define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384)
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   106
#  define DEV_AUDIO
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   107
# endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   108
#endif /* USE_DEV_AUDIO */
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
   109
924
4d262097b161 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 923
diff changeset
   110
#ifndef WIN32
4d262097b161 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 923
diff changeset
   111
# ifndef O_WRONLY
4d262097b161 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 923
diff changeset
   112
#  include <sys/fcntl.h>
4d262097b161 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 923
diff changeset
   113
# endif
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   114
# include <errno.h>
924
4d262097b161 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 923
diff changeset
   115
#endif
720
967fad20a8f1 newest stdio uses __new
Claus Gittinger <cg@exept.de>
parents: 715
diff changeset
   116
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   117
#ifdef WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   118
# define _WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   119
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   120
# undef INT
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   121
# undef Array
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   122
# undef Number
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   123
# undef Method
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   124
# undef Point
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   125
# undef Rectangle
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   126
# undef Block
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   127
# undef String
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   128
# undef Message
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   129
# undef Object
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   130
# undef Context
753
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   131
# undef Time
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   132
# undef Date
1853
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   133
# undef Process
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   134
# undef Processor
861
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   135
# undef Set
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   136
# undef Signal
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   137
# undef Delay
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   138
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   139
/* # include <stdarg.h> /* */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   140
# include <stdio.h> /* */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   141
# include <windows.h>
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   142
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   143
# ifdef USE_WIN32_DIRECTSOUND
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   144
#  define WIN32_DIRECTSOUND
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   145
#  define CINTERFACE
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   146
#  include "dsound.h"
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   147
#  define __DirectSoundVal(o) (LPDIRECTSOUND)(__externalAddressVal(o))
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   148
#  define __DSBufferVal(o)    (LPDIRECTSOUNDBUFFER)(__externalAddressVal(o))
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   149
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   150
#  define RT_BUFFER_SIZE 4096
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   151
#  define NBUFS          4
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   152
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   153
#  define pDirectSound handle1
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   154
#  define pDSBuffer    handle2
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   155
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   156
# else /* USE WAVE... */
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   157
#  ifdef USE_WIN32_WAVESOUND
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   158
#   define WIN32_WAVE
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   159
#   define __WaveHandleVal(o)    (HWAVEOUT)(__externalAddressVal(o))
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   160
#   define MAXBUF      10        /* Maximum number of buffers */
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   161
#   define DATALEN     2048      /* Size of wave data buffer */
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   162
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   163
struct buf {
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   164
    WAVEHDR hdr;                /* Wave data header */
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   165
    char data[DATALEN];         /* Actual wave data */
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   166
    struct buf *next;           /* Next buffer in free list */
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   167
};
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   168
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   169
static struct buf *free_list = NULL;      /* List of available buffers */
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   170
static CRITICAL_SECTION free_list_lock;
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   171
static int free_buffers = 0;             /* Number of buffers in free list */
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   172
static int total_buffers = 0;            /* Total number of buffers allocated */
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
   173
static HANDLE free_buffer_event;         /* Automatic-reset event triggered whenever */
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   174
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   175
#   define waveHandle handle1
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   176
2818
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   177
#  endif /* USE_WIN32_WAVESOUND */
94d67df5c00d compilable with tcc
Claus Gittinger <cg@exept.de>
parents: 2418
diff changeset
   178
# endif /* USE_WIN32_DIRECTSOUND */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   179
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   180
# ifdef __DEF_Array
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   181
#  define Array __DEF_Array
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   182
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   183
# ifdef __DEF_Number
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   184
#  define Number __DEF_Number
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   185
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   186
# ifdef __DEF_Method
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   187
#  define Method __DEF_Method
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   188
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   189
# ifdef __DEF_Point
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   190
#  define Point __DEF_Point
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   191
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   192
# ifdef __DEF_Block
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   193
#  define Block __DEF_Block
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   194
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   195
# ifdef __DEF_String
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   196
#  define String __DEF_String
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   197
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   198
# ifdef __DEF_Message
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   199
#  define Message __DEF_Message
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   200
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   201
# ifdef __DEF_Object
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   202
#  define Object __DEF_Object
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   203
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   204
# ifdef __DEF_Context
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   205
#  define Context __DEF_Context
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   206
# endif
753
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   207
# ifdef __DEF_Time
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   208
#  define Time __DEF_Time
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   209
# endif
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   210
# ifdef __DEF_Date
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   211
#  define Date __DEF_Date
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   212
# endif
1853
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   213
#ifdef __DEF_Process
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   214
# define Process __DEF_Process
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   215
#endif
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   216
#ifdef __DEF_Processor
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   217
# define Processor __DEF_Processor
b9c4a09bfc6a Fix name clashes with windows header files
Stefan Vogel <sv@exept.de>
parents: 1839
diff changeset
   218
#endif
861
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   219
#ifdef __DEF_Set
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   220
# define Set __DEF_Set
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   221
#endif
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   222
#ifdef __DEF_Signal
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   223
# define Signal __DEF_Signal
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   224
#endif
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   225
#ifdef __DEF_Delay
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   226
# define Delay __DEF_Delay
af186a6b5139 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 788
diff changeset
   227
#endif
753
5a323ea4ba4d *** empty log message ***
ps
parents: 752
diff changeset
   228
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
   229
# define INT  STX_INT
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
   230
# define UINT STX_UINT
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   231
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   232
#endif /* WIN32 */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   233
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   234
#ifdef DEBUG_SOUND
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
   235
# define DPRINTF(x) console_printf x
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   236
#else
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   237
# define DPRINTF(x) /* as nothing */
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   238
#endif
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   239
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   240
%}
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   241
! !
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   242
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   243
!SoundStream primitiveFunctions!
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   244
%{
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   245
#ifdef WIN32_WAVE
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   246
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   247
static void CALLBACK
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
   248
waveCallBack(HWAVE waveHandle, UINT msg, DWORD_PTR inst, DWORD_PTR p1, DWORD_PTR p2)
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   249
{
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   250
    if (msg == MM_WOM_DONE) {
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   251
	struct buf *bp = (struct buf *)p1;
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
   252
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   253
	EnterCriticalSection(&free_list_lock);
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   254
	bp->next = free_list;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   255
	free_list = bp;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   256
	free_buffers++;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   257
	SetEvent(free_buffer_event);
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   258
	LeaveCriticalSection(&free_list_lock);
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   259
    }
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   260
}
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   261
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   262
#endif /* WIN32_WAVE */
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   263
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
   264
%}
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
   265
! !
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
   266
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   267
!SoundStream class methodsFor:'documentation'!
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   268
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   269
copyright
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   270
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   271
 COPYRIGHT (c) 1993 by Claus Gittinger
45
claus
parents: 36
diff changeset
   272
	      All Rights Reserved
31
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   273
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   274
 This software is furnished under a license and may be used
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   275
 only in accordance with the terms of that license and with the
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   276
 inclusion of the above copyright notice.   This software may not
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   277
 be provided or otherwise made available to, or used by, any
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   278
 other person.  No title to or ownership of the software is
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   279
 hereby transferred.
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   280
"
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   281
!
e223f3cf2995 *** empty log message ***
claus
parents: 28
diff changeset
   282
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   283
documentation
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   284
"
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   285
    Preliminary (unfinished) interface to audio device.
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   286
    Currently works with LINUXs or SUNs /dev/audio driver and
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   287
    IRIX (indy).
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   288
    On iris, the default setup is for 8 bit mono
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   289
    so I can play the standard sound files I have here.
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   290
    It needs much more work, for stereo, different sampling rates etc.
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   291
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   292
    This is an experimental class - its interface & implementation
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   293
    may change in the future.
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   294
259
6d36f3ac42a2 documentation
Claus Gittinger <cg@exept.de>
parents: 217
diff changeset
   295
    [author:]
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
   296
	Claus Gittinger
28
350f8e9493a4 *** empty log message ***
claus
parents: 15
diff changeset
   297
"
152
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
   298
! !
45
claus
parents: 36
diff changeset
   299
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   300
!SoundStream class methodsFor:'initialization'!
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   301
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   302
initialize
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   303
    UnsupportedOperationSignal isNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   304
	UnsupportedOperationSignal := StreamError newSignalMayProceed:true.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   305
	UnsupportedOperationSignal nameClass:self message:#unsupportedOperationSignal.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   306
	UnsupportedOperationSignal notifierString:'unsupported operation'.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   307
    ]
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   308
! !
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
   309
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   310
!SoundStream class methodsFor:'instance creation'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   311
932
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   312
readWrite
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   313
    "create and return a new soundStream for readWrite (i.e. filtering)"
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   314
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   315
    |newStream|
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   316
    newStream := (self basicNew) initialize.
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   317
    newStream openForReadWrite isNil ifTrue:[^nil].
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   318
    ^ newStream
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   319
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   320
    "SoundStream readWrite"
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   321
!
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
   322
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   323
reading
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   324
    "create and return a new soundStream for reading (i.e. recording)"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   325
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   326
    |newStream|
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   327
    newStream := (self basicNew) initialize.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   328
    newStream openForReading isNil ifTrue:[^nil].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   329
    ^ newStream
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   330
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   331
    "SoundStream reading"
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   332
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   333
    "Modified: / 12.12.1997 / 16:51:56 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   334
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   335
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   336
writing
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   337
    "create and return a new soundStream for writing (i.e. playback)"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   338
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   339
    |newStream|
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   340
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   341
    newStream := (self basicNew) initialize.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   342
    newStream openForWriting isNil ifTrue:[^nil].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   343
    ^ newStream
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   344
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   345
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   346
     SoundStream writing
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   347
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   348
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   349
    "Created: / 17.11.1995 / 17:25:42 / cg"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   350
    "Modified: / 12.12.1997 / 16:51:38 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   351
!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   352
714
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   353
writing16Bit
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   354
    "just an example, has never been tried (I also
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   355
     have no samples for this ... leave it as an exercise)"
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   356
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   357
    |newStream|
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   358
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   359
    newStream := (self basicNew) initialize.
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   360
    newStream bitsPerSample:16.
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   361
    newStream openForWriting isNil ifTrue:[^nil].
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   362
    ^ newStream
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   363
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   364
    "SoundStream writing16Bit"
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   365
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   366
    "Modified: / 12.12.1997 / 16:51:49 / cg"
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   367
    "Created: / 21.12.1998 / 00:02:17 / cg"
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   368
!
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
   369
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   370
writing16BitStereo
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   371
    "just an example, has never been tried (I also
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   372
     have no samples for this ... leave it as an exercise)"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   373
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   374
    |newStream|
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   375
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   376
    OperatingSystem getCPUType ~= 'irix' ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   377
	self error:'unsupported audio mode'.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   378
    ].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   379
    newStream := (self basicNew) initialize.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   380
    newStream bitsPerSample:16.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   381
    newStream numberOfChannels:2.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   382
    newStream openForWriting isNil ifTrue:[^nil].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   383
    ^ newStream
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   384
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   385
    "SoundStream writing16BitStereo"
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   386
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   387
    "Modified: / 12.12.1997 / 16:51:49 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   388
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   389
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   390
!SoundStream class methodsFor:'Signal constants'!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   391
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   392
unsupportedOperationSignal
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   393
    ^ UnsupportedOperationSignal
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   394
! !
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   395
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   396
!SoundStream class methodsFor:'conversion helpers'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   397
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   398
linear16ToUlaw:a16bitSignedValue
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   399
    "given a 16it signed value, encode into uLaw byte"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   400
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   401
    |absVal sign exp mantissa byte|
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   402
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   403
%{
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   404
    /*
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   405
     * so heavily used when playing sounds ...
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   406
     * made it a primitive.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   407
     */
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   408
    if (__isSmallInteger(a16bitSignedValue)) {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   409
	int __sign = 0;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   410
	int __absVal = __intVal(a16bitSignedValue);
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   411
	int __exp, __mantissa, __byte;
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   412
	static char __uLawExp[] =
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   413
		    {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   414
			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
   415
			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
   416
			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
   417
			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
   418
			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
   419
			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
   420
			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
   421
			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
   422
		    };
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   423
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   424
	if (__absVal < 0) {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   425
	    if (__absVal <= -32256) {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   426
		RETURN (__MKSMALLINT(0));
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   427
	    }
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   428
	    __absVal = -__absVal;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   429
	    __sign = 0x80;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   430
	} else {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   431
	    if (__absVal >= 32256) {
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   432
		RETURN (__MKSMALLINT(128));
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   433
	    }
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   434
	}
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   435
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   436
	__exp = __uLawExp[__absVal >> 8];
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   437
	__mantissa = (__absVal >> (__exp+3)) & 0xF;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   438
	__byte = ~(__sign | (__exp<<4) | __mantissa) & 0xFF;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   439
	RETURN (__MKSMALLINT(__byte));
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   440
    }
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   441
%}.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   442
    "/
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   443
    "/ fallback for non-integral argument
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   444
    "/
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   445
    a16bitSignedValue isInteger ifFalse:[
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   446
	^ self uLawToLinear16:a16bitSignedValue asInteger
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   447
    ].
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   448
    ^ 0
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   449
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   450
    "
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   451
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:0)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   452
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32256)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   453
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32256)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   454
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:32767)
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   455
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-32767)
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   456
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:100)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   457
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-100)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   458
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:104)
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   459
     SoundStream uLawToLinear16:(SoundStream linear16ToUlaw:-104)
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   460
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   461
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   462
    "Modified: / 9.12.1997 / 16:46:24 / cg"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   463
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   464
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   465
uLawToLinear16:uLawValue
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   466
    "given a uLaw byte, return the decoded signed 16bit value.
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   467
     Currently unused - but will be"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   468
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   469
    ^ #(
45
claus
parents: 36
diff changeset
   470
	"0  "     -32256
claus
parents: 36
diff changeset
   471
	"1  "     -31228
claus
parents: 36
diff changeset
   472
	"2  "     -30200
claus
parents: 36
diff changeset
   473
	"3  "     -29172
claus
parents: 36
diff changeset
   474
	"4  "     -28143
claus
parents: 36
diff changeset
   475
	"5  "     -27115
claus
parents: 36
diff changeset
   476
	"6  "     -26087
claus
parents: 36
diff changeset
   477
	"7  "     -25059
claus
parents: 36
diff changeset
   478
	"8  "     -24031
claus
parents: 36
diff changeset
   479
	"9  "     -23002
claus
parents: 36
diff changeset
   480
	"10 "     -21974
claus
parents: 36
diff changeset
   481
	"11 "     -20946
claus
parents: 36
diff changeset
   482
	"12 "     -19918
claus
parents: 36
diff changeset
   483
	"13 "     -18889
claus
parents: 36
diff changeset
   484
	"14 "     -17861
claus
parents: 36
diff changeset
   485
	"15 "     -16833
claus
parents: 36
diff changeset
   486
	"16 "     -16062
claus
parents: 36
diff changeset
   487
	"17 "     -15548
claus
parents: 36
diff changeset
   488
	"18 "     -15033
claus
parents: 36
diff changeset
   489
	"19 "     -14519
claus
parents: 36
diff changeset
   490
	"20 "     -14005
claus
parents: 36
diff changeset
   491
	"21 "     -13491
claus
parents: 36
diff changeset
   492
	"22 "     -12977
claus
parents: 36
diff changeset
   493
	"23 "     -12463
claus
parents: 36
diff changeset
   494
	"24 "     -11949
claus
parents: 36
diff changeset
   495
	"25 "     -11435
claus
parents: 36
diff changeset
   496
	"26 "     -10920
claus
parents: 36
diff changeset
   497
	"27 "     -10406
claus
parents: 36
diff changeset
   498
	"28 "     -9892
claus
parents: 36
diff changeset
   499
	"29 "     -9378
claus
parents: 36
diff changeset
   500
	"30 "     -8864
claus
parents: 36
diff changeset
   501
	"31 "     -8350
claus
parents: 36
diff changeset
   502
	"32 "     -7964
claus
parents: 36
diff changeset
   503
	"33 "     -7707
claus
parents: 36
diff changeset
   504
	"34 "     -7450
claus
parents: 36
diff changeset
   505
	"35 "     -7193
claus
parents: 36
diff changeset
   506
	"36 "     -6936
claus
parents: 36
diff changeset
   507
	"37 "     -6679
claus
parents: 36
diff changeset
   508
	"38 "     -6422
claus
parents: 36
diff changeset
   509
	"39 "     -6165
claus
parents: 36
diff changeset
   510
	"40 "     -5908
claus
parents: 36
diff changeset
   511
	"41 "     -5651
claus
parents: 36
diff changeset
   512
	"42 "     -5394
claus
parents: 36
diff changeset
   513
	"43 "     -5137
claus
parents: 36
diff changeset
   514
	"44 "     -4880
claus
parents: 36
diff changeset
   515
	"45 "     -4623
claus
parents: 36
diff changeset
   516
	"46 "     -4365
claus
parents: 36
diff changeset
   517
	"47 "     -4108
claus
parents: 36
diff changeset
   518
	"48 "     -3916
claus
parents: 36
diff changeset
   519
	"49 "     -3787
claus
parents: 36
diff changeset
   520
	"50 "     -3659
claus
parents: 36
diff changeset
   521
	"51 "     -3530
claus
parents: 36
diff changeset
   522
	"52 "     -3402
claus
parents: 36
diff changeset
   523
	"53 "     -3273
claus
parents: 36
diff changeset
   524
	"54 "     -3144
claus
parents: 36
diff changeset
   525
	"55 "     -3016
claus
parents: 36
diff changeset
   526
	"56 "     -2887
claus
parents: 36
diff changeset
   527
	"57 "     -2759
claus
parents: 36
diff changeset
   528
	"58 "     -2630
claus
parents: 36
diff changeset
   529
	"59 "     -2502
claus
parents: 36
diff changeset
   530
	"60 "     -2373
claus
parents: 36
diff changeset
   531
	"61 "     -2245
claus
parents: 36
diff changeset
   532
	"62 "     -2116
claus
parents: 36
diff changeset
   533
	"63 "     -1988
claus
parents: 36
diff changeset
   534
	"64 "     -1891
claus
parents: 36
diff changeset
   535
	"65 "     -1827
claus
parents: 36
diff changeset
   536
	"66 "     -1763
claus
parents: 36
diff changeset
   537
	"67 "     -1698
claus
parents: 36
diff changeset
   538
	"68 "     -1634
claus
parents: 36
diff changeset
   539
	"69 "     -1570
claus
parents: 36
diff changeset
   540
	"70 "     -1506
claus
parents: 36
diff changeset
   541
	"71 "     -1441
claus
parents: 36
diff changeset
   542
	"72 "     -1377
claus
parents: 36
diff changeset
   543
	"73 "     -1313
claus
parents: 36
diff changeset
   544
	"74 "     -1249
claus
parents: 36
diff changeset
   545
	"75 "     -1184
claus
parents: 36
diff changeset
   546
	"76 "     -1120
claus
parents: 36
diff changeset
   547
	"77 "     -1056
claus
parents: 36
diff changeset
   548
	"78 "     -992
claus
parents: 36
diff changeset
   549
	"79 "     -927
claus
parents: 36
diff changeset
   550
	"80 "     -879
claus
parents: 36
diff changeset
   551
	"81 "     -847
claus
parents: 36
diff changeset
   552
	"82 "     -815
claus
parents: 36
diff changeset
   553
	"83 "     -783
claus
parents: 36
diff changeset
   554
	"84 "     -751
claus
parents: 36
diff changeset
   555
	"85 "     -718
claus
parents: 36
diff changeset
   556
	"86 "     -686
claus
parents: 36
diff changeset
   557
	"87 "     -654
claus
parents: 36
diff changeset
   558
	"88 "     -622
claus
parents: 36
diff changeset
   559
	"89 "     -590
claus
parents: 36
diff changeset
   560
	"90 "     -558
claus
parents: 36
diff changeset
   561
	"91 "     -526
claus
parents: 36
diff changeset
   562
	"92 "     -494
claus
parents: 36
diff changeset
   563
	"93 "     -461
claus
parents: 36
diff changeset
   564
	"94 "     -429
claus
parents: 36
diff changeset
   565
	"95 "     -397
claus
parents: 36
diff changeset
   566
	"96 "     -373
claus
parents: 36
diff changeset
   567
	"97 "     -357
claus
parents: 36
diff changeset
   568
	"98 "     -341
claus
parents: 36
diff changeset
   569
	"99 "     -325
claus
parents: 36
diff changeset
   570
	"100"     -309
claus
parents: 36
diff changeset
   571
	"101"     -293
claus
parents: 36
diff changeset
   572
	"102"     -277
claus
parents: 36
diff changeset
   573
	"103"     -261
claus
parents: 36
diff changeset
   574
	"104"     -245
claus
parents: 36
diff changeset
   575
	"105"     -228
claus
parents: 36
diff changeset
   576
	"106"     -212
claus
parents: 36
diff changeset
   577
	"107"     -196
claus
parents: 36
diff changeset
   578
	"108"     -180
claus
parents: 36
diff changeset
   579
	"109"     -164
claus
parents: 36
diff changeset
   580
	"110"     -148
claus
parents: 36
diff changeset
   581
	"111"     -132
claus
parents: 36
diff changeset
   582
	"112"     -120
claus
parents: 36
diff changeset
   583
	"113"     -112
claus
parents: 36
diff changeset
   584
	"114"     -104
claus
parents: 36
diff changeset
   585
	"115"     -96
claus
parents: 36
diff changeset
   586
	"116"     -88
claus
parents: 36
diff changeset
   587
	"117"     -80
claus
parents: 36
diff changeset
   588
	"118"     -72
claus
parents: 36
diff changeset
   589
	"119"     -64
claus
parents: 36
diff changeset
   590
	"120"     -56
claus
parents: 36
diff changeset
   591
	"121"     -48
claus
parents: 36
diff changeset
   592
	"122"     -40
claus
parents: 36
diff changeset
   593
	"123"     -32
claus
parents: 36
diff changeset
   594
	"124"     -24
claus
parents: 36
diff changeset
   595
	"125"     -16
claus
parents: 36
diff changeset
   596
	"126"     -8
claus
parents: 36
diff changeset
   597
	"127"     0
claus
parents: 36
diff changeset
   598
	"128"     32256
claus
parents: 36
diff changeset
   599
	"129"     31228
claus
parents: 36
diff changeset
   600
	"130"     30200
claus
parents: 36
diff changeset
   601
	"131"     29172
claus
parents: 36
diff changeset
   602
	"132"     28143
claus
parents: 36
diff changeset
   603
	"133"     27115
claus
parents: 36
diff changeset
   604
	"134"     26087
claus
parents: 36
diff changeset
   605
	"135"     25059
claus
parents: 36
diff changeset
   606
	"136"     24031
claus
parents: 36
diff changeset
   607
	"137"     23002
claus
parents: 36
diff changeset
   608
	"138"     21974
claus
parents: 36
diff changeset
   609
	"139"     20946
claus
parents: 36
diff changeset
   610
	"140"     19918
claus
parents: 36
diff changeset
   611
	"141"     18889
claus
parents: 36
diff changeset
   612
	"142"     17861
claus
parents: 36
diff changeset
   613
	"143"     16833
claus
parents: 36
diff changeset
   614
	"144"     16062
claus
parents: 36
diff changeset
   615
	"145"     15548
claus
parents: 36
diff changeset
   616
	"146"     15033
claus
parents: 36
diff changeset
   617
	"147"     14519
claus
parents: 36
diff changeset
   618
	"148"     14005
claus
parents: 36
diff changeset
   619
	"149"     13491
claus
parents: 36
diff changeset
   620
	"150"     12977
claus
parents: 36
diff changeset
   621
	"151"     12463
claus
parents: 36
diff changeset
   622
	"152"     11949
claus
parents: 36
diff changeset
   623
	"153"     11435
claus
parents: 36
diff changeset
   624
	"154"     10920
claus
parents: 36
diff changeset
   625
	"155"     10406
claus
parents: 36
diff changeset
   626
	"156"     9892
claus
parents: 36
diff changeset
   627
	"157"     9378
claus
parents: 36
diff changeset
   628
	"158"     8864
claus
parents: 36
diff changeset
   629
	"159"     8350
claus
parents: 36
diff changeset
   630
	"160"     7964
claus
parents: 36
diff changeset
   631
	"161"     7707
claus
parents: 36
diff changeset
   632
	"162"     7450
claus
parents: 36
diff changeset
   633
	"163"     7193
claus
parents: 36
diff changeset
   634
	"164"     6936
claus
parents: 36
diff changeset
   635
	"165"     6679
claus
parents: 36
diff changeset
   636
	"166"     6422
claus
parents: 36
diff changeset
   637
	"167"     6165
claus
parents: 36
diff changeset
   638
	"168"     5908
claus
parents: 36
diff changeset
   639
	"169"     5651
claus
parents: 36
diff changeset
   640
	"170"     5394
claus
parents: 36
diff changeset
   641
	"171"     5137
claus
parents: 36
diff changeset
   642
	"172"     4880
claus
parents: 36
diff changeset
   643
	"173"     4623
claus
parents: 36
diff changeset
   644
	"174"     4365
claus
parents: 36
diff changeset
   645
	"175"     4108
claus
parents: 36
diff changeset
   646
	"176"     3916
claus
parents: 36
diff changeset
   647
	"177"     3787
claus
parents: 36
diff changeset
   648
	"178"     3659
claus
parents: 36
diff changeset
   649
	"179"     3530
claus
parents: 36
diff changeset
   650
	"180"     3402
claus
parents: 36
diff changeset
   651
	"181"     3273
claus
parents: 36
diff changeset
   652
	"182"     3144
claus
parents: 36
diff changeset
   653
	"183"     3016
claus
parents: 36
diff changeset
   654
	"184"     2887
claus
parents: 36
diff changeset
   655
	"185"     2759
claus
parents: 36
diff changeset
   656
	"186"     2630
claus
parents: 36
diff changeset
   657
	"187"     2502
claus
parents: 36
diff changeset
   658
	"188"     2373
claus
parents: 36
diff changeset
   659
	"189"     2245
claus
parents: 36
diff changeset
   660
	"190"     2116
claus
parents: 36
diff changeset
   661
	"191"     1988
claus
parents: 36
diff changeset
   662
	"192"     1891
claus
parents: 36
diff changeset
   663
	"193"     1827
claus
parents: 36
diff changeset
   664
	"194"     1763
claus
parents: 36
diff changeset
   665
	"195"     1698
claus
parents: 36
diff changeset
   666
	"196"     1634
claus
parents: 36
diff changeset
   667
	"197"     1570
claus
parents: 36
diff changeset
   668
	"198"     1506
claus
parents: 36
diff changeset
   669
	"199"     1441
claus
parents: 36
diff changeset
   670
	"200"     1377
claus
parents: 36
diff changeset
   671
	"201"     1313
claus
parents: 36
diff changeset
   672
	"202"     1249
claus
parents: 36
diff changeset
   673
	"203"     1184
claus
parents: 36
diff changeset
   674
	"204"     1120
claus
parents: 36
diff changeset
   675
	"205"     1056
claus
parents: 36
diff changeset
   676
	"206"     992
claus
parents: 36
diff changeset
   677
	"207"     927
claus
parents: 36
diff changeset
   678
	"208"     879
claus
parents: 36
diff changeset
   679
	"209"     847
claus
parents: 36
diff changeset
   680
	"210"     815
claus
parents: 36
diff changeset
   681
	"211"     783
claus
parents: 36
diff changeset
   682
	"212"     751
claus
parents: 36
diff changeset
   683
	"213"     718
claus
parents: 36
diff changeset
   684
	"214"     686
claus
parents: 36
diff changeset
   685
	"215"     654
claus
parents: 36
diff changeset
   686
	"216"     622
claus
parents: 36
diff changeset
   687
	"217"     590
claus
parents: 36
diff changeset
   688
	"218"     558
claus
parents: 36
diff changeset
   689
	"219"     526
claus
parents: 36
diff changeset
   690
	"220"     494
claus
parents: 36
diff changeset
   691
	"221"     461
claus
parents: 36
diff changeset
   692
	"222"     429
claus
parents: 36
diff changeset
   693
	"223"     397
claus
parents: 36
diff changeset
   694
	"224"     373
claus
parents: 36
diff changeset
   695
	"225"     357
claus
parents: 36
diff changeset
   696
	"226"     341
claus
parents: 36
diff changeset
   697
	"227"     325
claus
parents: 36
diff changeset
   698
	"228"     309
claus
parents: 36
diff changeset
   699
	"229"     293
claus
parents: 36
diff changeset
   700
	"230"     277
claus
parents: 36
diff changeset
   701
	"231"     261
claus
parents: 36
diff changeset
   702
	"232"     245
claus
parents: 36
diff changeset
   703
	"233"     228
claus
parents: 36
diff changeset
   704
	"234"     212
claus
parents: 36
diff changeset
   705
	"235"     196
claus
parents: 36
diff changeset
   706
	"236"     180
claus
parents: 36
diff changeset
   707
	"237"     164
claus
parents: 36
diff changeset
   708
	"238"     148
claus
parents: 36
diff changeset
   709
	"239"     132
claus
parents: 36
diff changeset
   710
	"240"     120
claus
parents: 36
diff changeset
   711
	"241"     112
claus
parents: 36
diff changeset
   712
	"242"     104
claus
parents: 36
diff changeset
   713
	"243"     96
claus
parents: 36
diff changeset
   714
	"244"     88
claus
parents: 36
diff changeset
   715
	"245"     80
claus
parents: 36
diff changeset
   716
	"246"     72
claus
parents: 36
diff changeset
   717
	"247"     64
claus
parents: 36
diff changeset
   718
	"248"     56
claus
parents: 36
diff changeset
   719
	"249"     48
claus
parents: 36
diff changeset
   720
	"250"     40
claus
parents: 36
diff changeset
   721
	"251"     32
claus
parents: 36
diff changeset
   722
	"252"     24
claus
parents: 36
diff changeset
   723
	"253"     16
claus
parents: 36
diff changeset
   724
	"254"     8
claus
parents: 36
diff changeset
   725
	"255"     0
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   726
    ) at:(uLawValue + 1)
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   727
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   728
    "Modified: / 9.12.1997 / 16:34:17 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   729
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
   730
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   731
!SoundStream class methodsFor:'default values'!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   732
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   733
defaultAudioFormat
2822
371789d0fe49 changed:
Stefan Vogel <sv@exept.de>
parents: 2818
diff changeset
   734
    OperatingSystem isMSWINDOWSlike ifTrue:[
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
   735
	^ #S16
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   736
    ].
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   737
    ^ #U8
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   738
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   739
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   740
defaultBitsPerSample
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   741
    "minimum, supported by all audio systems"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   742
2822
371789d0fe49 changed:
Stefan Vogel <sv@exept.de>
parents: 2818
diff changeset
   743
    OperatingSystem isMSWINDOWSlike ifTrue:[
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
   744
	^ 16
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   745
    ].
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   746
    ^ 8
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   747
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   748
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   749
defaultNumberOfChannels
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   750
    "minimum, supported by all audio systems"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   751
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   752
    ^ 1
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   753
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   754
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   755
defaultSampleRate
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   756
    "minimum, supported by all audio systems"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   757
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
   758
%{
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
   759
#ifdef DEV_AUDIO
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
   760
    RETURN (__MKSMALLINT(DEV_AUDIO_DEFAULT_FREQ));
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
   761
#endif
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
   762
%}.
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
   763
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   764
    ^ 8000
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   765
! !
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   766
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   767
!SoundStream class methodsFor:'playing'!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   768
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   769
playSoundFile:aFilename
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   770
    "play a soundFile"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   771
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   772
    |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
   773
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   774
    inStream := aFilename asFilename readStream.
1154
6158d4545b71 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1151
diff changeset
   775
    inStream isNil ifTrue:[self error:'cannot open'].
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   776
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   777
    soundStream := self writing.
1154
6158d4545b71 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1151
diff changeset
   778
    soundStream isNil ifTrue:[self error:'cannot open sound device'].
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   779
1432
077bf1bfc8c4 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   780
    startTime := Timestamp now.
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   781
    totalCount := 0.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   782
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   783
    buffer := ByteArray new:4096.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   784
    [(count := inStream nextBytesInto:buffer) > 0] whileTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   785
	totalCount := totalCount + count.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   786
	soundStream nextPutBytes:count from:buffer.
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   787
    ].
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   788
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   789
    inStream close.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   790
    soundStream commit.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   791
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   792
    "/
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   793
    "/ 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
   794
    "/
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   795
    playTime := totalCount / soundStream sampleRate.
1432
077bf1bfc8c4 Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents: 1422
diff changeset
   796
    delayedTime := (Timestamp now getSeconds - startTime getSeconds).
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   797
    waitTime := playTime - delayedTime + 0.1.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   798
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   799
    (Delay forSeconds:waitTime) wait.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   800
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   801
    soundStream close.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   802
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   803
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   804
     SoundStream playSoundFile:'/usr/local/lib/sounds/laugh.snd'
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   805
     SoundStream playSoundFile:'/usr/local/lib/sounds/spacemusic.snd'
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   806
    "
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   807
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   808
    "Created: 17.11.1995 / 17:25:30 / cg"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   809
    "Modified: 17.11.1995 / 17:45:40 / cg"
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   810
! !
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
   811
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   812
!SoundStream methodsFor:'catching invalid methods'!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   813
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   814
pathName:filename
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   815
    "catch pathname access - its fixed here"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   816
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   817
    self shouldNotImplement
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   818
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   819
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   820
pathName:filename in:aDirectory
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   821
    "catch pathname access - its fixed here"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   822
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   823
    self shouldNotImplement
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   824
! !
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   825
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   826
!SoundStream methodsFor:'mode setting'!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   827
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   828
bitsPerSample
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   829
    "return the number of bits per sample - usually 8"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   830
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   831
    ^ bitsPerSample
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   832
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   833
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   834
bitsPerSample:aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   835
    "set the number of bits per sample"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   836
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   837
    bitsPerSample := aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   838
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   839
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   840
numberOfChannels
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   841
    "return the number of channels (1 or 2; usually 1)"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   842
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   843
    ^ numberOfChannels
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   844
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   845
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   846
numberOfChannels:aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   847
    "set the number of channels"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   848
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   849
    numberOfChannels := aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   850
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   851
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   852
sampleRate
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   853
    "return the sample rate"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   854
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   855
    ^ sampleRate
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   856
!
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   857
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   858
sampleRate:aNumber
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   859
    "set the sample rate in hertz - on some
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   860
     devices, this is a nop"
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   861
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   862
    self setSampleRate:aNumber.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   863
! !
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
   864
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   865
!SoundStream methodsFor:'private'!
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   866
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   867
dumpSettings
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   868
    "debugging interface - dump the current settings"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
   869
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   870
    |fd blockSize speed channels stereo format|
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   871
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   872
    fd := self fileDescriptor.
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   873
    fd isNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   874
	self errorNotOpen.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   875
	^ nil
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   876
    ].
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   877
    audioFormat == #S16 ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   878
	UninterpretedBytes isBigEndian ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   879
	    audioFormat := #S16_BE
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   880
	] ifFalse:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   881
	    audioFormat := #S16_LE
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   882
	]
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   883
    ].
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   884
    audioFormat == #U16 ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   885
	UninterpretedBytes isBigEndian ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   886
	    audioFormat := #U16_BE
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   887
	] ifFalse:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   888
	    audioFormat := #U16_LE
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   889
	]
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   890
    ].
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   891
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   892
%{
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   893
    int f = __intVal(fd);
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   894
    int __blockSize = -1;
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   895
    int __speed = -1;
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   896
    int __channels = __intVal(__INST(numberOfChannels));
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   897
    int __stereo = __channels > 1;
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   898
    int __format = -1;
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   899
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   900
    if (0) {
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   901
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   902
    else if (__INST(audioFormat) == @symbol(MU_LAW)) {
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   903
#  ifdef AFMT_MU_LAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   904
	__format = AFMT_MU_LAW;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   905
#  endif
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   906
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   907
    else if (__INST(audioFormat) == @symbol(A_LAW)) {
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   908
#  ifdef AFMT_A_LAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   909
	__format = AFMT_A_LAW;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   910
#  endif
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   911
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   912
    else if (__INST(audioFormat) == @symbol(IMA_ADPCM)) {
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   913
#  ifdef AFMT_IMA_ADPCM
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   914
	__format = AFMT_IMA_ADPCM;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   915
#  endif
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   916
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   917
    else if (__INST(audioFormat) == @symbol(U8)) {
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   918
#  ifdef AFMT_U8
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   919
	__format = AFMT_U8;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   920
#  endif
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   921
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   922
    else if (__INST(audioFormat) == @symbol(S16_LE)) {
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   923
#  ifdef AFMT_S16_LE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   924
	__format = AFMT_S16_LE;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   925
#  endif
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   926
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   927
    else if (__INST(audioFormat) == @symbol(S16_BE)) {
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   928
#  ifdef AFMT_S16_BE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   929
	__format = AFMT_S16_BE;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   930
#  endif
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   931
    }
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   932
    else if (__INST(audioFormat) == @symbol(S8)) {
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   933
#  ifdef AFMT_S8
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   934
	__format = AFMT_S8;
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   935
#  endif
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   936
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   937
    else if (__INST(audioFormat) == @symbol(U16_LE)) {
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   938
#  ifdef AFMT_U16_LE
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   939
	__format = AFMT_U16_LE;
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   940
#  endif
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   941
    }
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   942
    else if (__INST(audioFormat) == @symbol(U16_BE)) {
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   943
#  ifdef AFMT_U16_BE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   944
	__format = AFMT_U16_BE;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   945
#  endif
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   946
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
   947
    else if (__INST(audioFormat) == @symbol(MPEG)) {
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   948
#  ifdef AFMT_MPEG
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   949
	__format = AFMT_MPEG;
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   950
#  endif
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   951
    }
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
   952
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   953
#if defined(DEV_AUDIO)
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   954
    channels = nil;
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   955
    blockSize = nil;
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   956
    stereo = nil;
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   957
    speed = nil;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   958
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   959
# if defined(SNDCTL_DSP_GETBLKSIZE)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   960
    if (ioctl(f, SNDCTL_DSP_GETBLKSIZE, &__blockSize) >= 0) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   961
	blockSize = __MKSMALLINT(__blockSize);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   962
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   963
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   964
# if defined(SNDCTL_DSP_CHANNELS)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   965
    if (ioctl(f, SNDCTL_DSP_CHANNELS, &__channels) >= 0) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   966
	channels = __MKSMALLINT(__channels);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   967
	stereo = __MKSMALLINT(__channels > 1);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   968
    }
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   969
# else
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   970
#  if defined(SNDCTL_DSP_STEREO)
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   971
    if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   972
	stereo = __MKSMALLINT(__stereo);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   973
    }
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
   974
#  endif
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   975
# endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   976
# if defined(SNDCTL_DSP_SPEED)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   977
    if (ioctl(f, SNDCTL_DSP_SPEED, &__speed) >= 0) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   978
	speed = __MKSMALLINT(__speed);
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   979
    }
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   980
# endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   981
# if defined(SNDCTL_DSP_GETFMT)
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   982
    if (ioctl(f, SNDCTL_DSP_GETFMT, &__format) >= 0) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   983
	format = __MKSMALLINT(__format);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
   984
    }
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   985
# else
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   986
#  if defined(SNDCTL_DSP_SETFMT) && defined(AFMT_QUERY)
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   987
    __format = AFMT_QUERY;
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   988
    if (ioctl(f, SNDCTL_DSP_SETFMT, &__format) >= 0) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   989
	switch (__format) {
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   990
#ifdef AFMT_MU_LAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   991
	    case AFMT_MU_LAW:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   992
		format = @symbol(MU_LAW);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   993
		break;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   994
#endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   995
#ifdef AFMT_A_LAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   996
	    case AFMT_A_LAW:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   997
		format = @symbol(A_LAW);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
   998
		break;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
   999
#endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1000
#ifdef AFMT_U8
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1001
	    case AFMT_U8:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1002
		format = @symbol(U8);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1003
		break;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1004
#endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1005
#ifdef AFMT_S8
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1006
	    case AFMT_S8:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1007
		format = @symbol(S8);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1008
		break;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1009
#endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1010
#ifdef AFMT_S16_LE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1011
	    case AFMT_S16_LE:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1012
		format = @symbol(S16_LE);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1013
		break;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1014
#endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1015
#ifdef AFMT_S16_BE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1016
	    case AFMT_S16_BE:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1017
		format = @symbol(S16_BE);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1018
		break;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1019
#endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1020
#ifdef AFMT_U16_LE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1021
	    case AFMT_U16_LE:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1022
		format = @symbol(U16_LE);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1023
		break;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1024
#endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1025
#ifdef AFMT_U16_BE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1026
	    case AFMT_U16_BE:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1027
		format = @symbol(U16_BE);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1028
		break;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1029
#endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1030
#ifdef AFMT_MPEG
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1031
	    case AFMT_MPEG:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1032
		format = @symbol(MPEG);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1033
		break;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1034
#endif
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1035
	    default:
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1036
		format = nil;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1037
	}
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1038
    }
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1039
#  endif
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1040
# endif
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1041
#endif /* DEV_AUDIO */
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1042
%}.
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1043
    format notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1044
	Transcript show:'format: '; showCR:format
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1045
    ].
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1046
    blockSize notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1047
	Transcript show:'blockSize: '; showCR:blockSize
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1048
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1049
    speed notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1050
	Transcript show:'speed: '; showCR:speed
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1051
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1052
    channels notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1053
	Transcript show:'channels: '; showCR:channels
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1054
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1055
    stereo notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1056
	Transcript show:'stereo: '; showCR:stereo
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1057
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1058
920
1c8a18a7a7cf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
  1059
    Transcript show:'supported audioFormats: '; showCR:(self supportedAudioFormats).
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1060
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1061
    "
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1062
     self writing dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1063
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1064
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1065
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1066
initialize
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1067
    "initialize for least common mode"
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1068
3156
edeed9ecae5b initialize methods
Stefan Vogel <sv@exept.de>
parents: 3154
diff changeset
  1069
    super initialize.
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1070
    buffered := false.
1269
17546758fc7a buffered:falsem to NonPositionableExternalStreams is already set.
Stefan Vogel <sv@exept.de>
parents: 1154
diff changeset
  1071
    binary := true.
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1072
    bitsPerSample := self class defaultBitsPerSample.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1073
    audioFormat := self class defaultAudioFormat.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1074
    numberOfChannels := self class defaultNumberOfChannels.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1075
    sampleRate := self class defaultSampleRate.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1076
    pathName := nil.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1077
2822
371789d0fe49 changed:
Stefan Vogel <sv@exept.de>
parents: 2818
diff changeset
  1078
    OperatingSystem isUNIXlike ifTrue:[
3154
23ac6f3e69b6 Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 3000
diff changeset
  1079
        '/dev/audio' asFilename exists ifTrue:[
23ac6f3e69b6 Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 3000
diff changeset
  1080
            "/
23ac6f3e69b6 Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 3000
diff changeset
  1081
            "/ sunos or linux
23ac6f3e69b6 Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 3000
diff changeset
  1082
            "/
23ac6f3e69b6 Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 3000
diff changeset
  1083
            pathName := '/dev/audio'.
23ac6f3e69b6 Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 3000
diff changeset
  1084
        ].
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1085
    ].
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1086
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1087
    "Created: 17.11.1995 / 17:28:14 / cg"
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1088
!
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1089
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1090
resetSoundCard
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1091
    "debugging interface - reset the soundCard"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1092
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1093
    |fd|
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1094
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1095
    handle notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1096
	fd := self fileDescriptor.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1097
	fd isNil ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1098
	self errorNotOpen.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1099
	    ^ nil
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1100
	]
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1101
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1102
%{
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1103
    int f = __intVal(fd);
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1104
    int __dummy;
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1105
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1106
#if defined(DEV_AUDIO)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1107
    if (__isSmallInteger(fd)) {
614
565ea4308322 make it compilable on elder linux's
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
  1108
# if defined(SNDCTL_DSP_RESET)
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1109
	if (ioctl(f, SNDCTL_DSP_RESET, &__dummy) >= 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1110
	    RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1111
	}
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1112
# endif
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1113
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1114
#endif /* DEV_AUDIO */
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1115
%}.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1116
    ^ UnsupportedOperationSignal raise
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1117
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1118
    "
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1119
     self writing resetSoundCard; dumpSettings; close
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1120
    "
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1121
!
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1122
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1123
setAudioFormat:aSymbol
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1124
    "set the format of the audio data as specified by aSymbol.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1125
     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
  1126
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1127
    |fd|
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1128
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1129
    handle notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1130
	fd := self fileDescriptor.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1131
	fd isNil ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1132
	    self errorNotOpen.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1133
	    ^ nil
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1134
	]
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1135
    ].
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1136
%{
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1137
    OBJ sym = aSymbol;
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1138
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1139
    if (__INST(audioFormat) == sym) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1140
	RETURN (self);
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1141
    }
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1142
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1143
#if defined(DEV_AUDIO)
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1144
    if (__isSmallInteger(fd)) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1145
	int f = __intVal(fd);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1146
	int __fmt = 0, __fmtWant;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1147
	union {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1148
	    unsigned short us;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1149
	    unsigned char ub[2];
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1150
	} u;
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  1151
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1152
	if (__isSymbol(sym)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1153
	    if (sym == @symbol(U16)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1154
		u.us = 0x1234;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1155
		if (u.ub[0] == 0x34) {
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1156
/* printf("U16_LE\n"); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1157
		    sym = @symbol(U16_LE);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1158
		} else {
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1159
/* printf("U16_BE\n"); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1160
		    sym = @symbol(U16_BE);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1161
		}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1162
	    } else if (sym == @symbol(S16)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1163
		u.us = 0x1234;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1164
		if (u.ub[0] == 0x34) {
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1165
/* printf("S16_LE\n"); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1166
		   sym = @symbol(S16_LE);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1167
		} else {
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1168
/* printf("S16_BE\n"); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1169
		   sym = @symbol(S16_BE);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1170
		}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1171
	    }
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1172
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1173
	    if (0) {
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1174
# ifdef AFMT_MU_LAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1175
	    } else if (sym == @symbol(MU_LAW)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1176
		__fmt = AFMT_MU_LAW;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1177
# endif
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1178
# ifdef AFMT_A_LAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1179
	    } else if (sym == @symbol(A_LAW)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1180
		__fmt = AFMT_A_LAW;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1181
# endif
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1182
# ifdef AFMT_IMA_ADPCM
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1183
	    } else if (sym == @symbol(IMA_ADPCM)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1184
		__fmt = AFMT_IMA_ADPCM;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1185
# endif
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1186
# ifdef AFMT_U8
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1187
	    } else if (sym == @symbol(U8)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1188
		__fmt = AFMT_U8;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1189
# endif
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1190
# ifdef AFMT_S8
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1191
	    } else if (sym == @symbol(S8)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1192
		__fmt = AFMT_S8;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1193
# endif
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1194
# ifdef AFMT_U16_LE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1195
	    } else if (sym == @symbol(U16_LE)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1196
		__fmt = AFMT_U16_LE;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1197
# endif
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1198
# ifdef AFMT_U16_BE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1199
	    } else if (sym == @symbol(U16_BE)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1200
		__fmt = AFMT_U16_BE;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1201
# endif
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1202
# ifdef AFMT_S16_LE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1203
	    } else if (sym == @symbol(S16_LE)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1204
		__fmt = AFMT_S16_LE;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1205
# endif
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1206
# ifdef AFMT_S16_BE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1207
	    } else if (sym == @symbol(S16_BE)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1208
		__fmt = AFMT_S16_BE;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1209
# endif
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1210
# ifdef AFMT_MPEG
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1211
	    } else if (sym == @symbol(MPEG)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1212
		__fmt = AFMT_MPEG;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1213
# endif
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1214
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1215
# ifdef AUDIO_FORMAT_LINEAR16BIT
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1216
	    } else if (sym == @symbol(S16)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1217
		__fmt = AUDIO_FORMAT_LINEAR16BIT;
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1218
# endif
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1219
# ifdef AUDIO_FORMAT_ULAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1220
	    } else if (sym == @symbol(MU_LAW)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1221
		__fmt = AUDIO_FORMAT_ULAW;
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1222
# endif
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1223
# ifdef AUDIO_FORMAT_ALAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1224
	    } else if (sym == @symbol(A_LAW)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1225
		__fmt = AUDIO_FORMAT_ALAW;
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1226
# endif
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1227
	    } else {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1228
		console_fprintf(stderr, "bad format: %s\n", __stringVal(sym));
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1229
		goto bad;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1230
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1231
	}
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1232
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1233
# ifdef SNDCTL_DSP_SETFMT
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1234
	__fmtWant = __fmt;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1235
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1236
	if (ioctl(f, SNDCTL_DSP_SETFMT, &__fmt) >= 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1237
	    if (__fmt == __fmtWant) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1238
		__INST(audioFormat) = sym;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1239
		RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1240
	    } else {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1241
		/* console_fprintf(stderr, "want: %x; got: %x\n", __fmtWant, __fmt); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1242
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1243
	} else {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1244
		/* console_fprintf(stderr, "got err-ret from setFmp %x\n", __fmt); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1245
	}
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1246
# else
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1247
#  ifdef AUDIO_SET_DATA_FORMAT /* hpux */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1248
	if (ioctl (f, AUDIO_SET_DATA_FORMAT, __fmt)) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1249
	    /* console_fprintf(stderr, "got err-ret from AUDIO_SET_DATA_FORMAT\n"); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1250
	}
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1251
#  endif
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1252
# endif /* SNDCTL_DSP_SETFMT */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1253
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1254
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1255
bad: ;
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1256
    }
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1257
#endif /* DEV_AUDIO */
614
565ea4308322 make it compilable on elder linux's
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
  1258
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1259
%}.
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1260
    ^ UnsupportedOperationSignal raise
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1261
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1262
    "
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1263
     self writing dumpSettings; close
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1264
     self writing setAudioFormat:#'MU_LAW'; close
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1265
     self writing setAudioFormat:#'U8'; dumpSettings; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  1266
     self writing setAudioFormat:#'MPEG'; dumpSettings; close
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1267
    "
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1268
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1269
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1270
setChannels:nChannels
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1271
    "set the number of channels (1 -> mono; 2 -> stereo).
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1272
     Returns true if sucessfull - may fail with many sound devices."
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1273
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1274
    |fd|
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1275
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1276
    handle notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1277
	fd := self fileDescriptor.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1278
	fd isNil ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1279
	    self errorNotOpen.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1280
	    ^ nil
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1281
	]
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1282
    ].
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1283
%{
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1284
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1285
#if defined(DEV_AUDIO)
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1286
    if (__isSmallInteger(fd) && __isSmallInteger(nChannels)) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1287
	int f = __intVal(fd);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1288
	int __nCh = __intVal(nChannels);
920
1c8a18a7a7cf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
  1289
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  1290
# if defined(SNDCTL_DSP_STEREO)
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1291
	if ((__nCh == 1) || (__nCh == 2)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1292
	    int __stereo = (__nCh == 2) ? 1 : 0;
920
1c8a18a7a7cf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
  1293
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1294
	    if (ioctl(f, SNDCTL_DSP_STEREO, &__stereo) >= 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1295
		if (__stereo == 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1296
		    __INST(numberOfChannels) = __MKSMALLINT(1);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1297
		} else {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1298
		    __INST(numberOfChannels) = __MKSMALLINT(2);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1299
		}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1300
		RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1301
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1302
	}
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  1303
# else
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  1304
#  if defined(SOUND_PCM_WRITE_CHANNELS)
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1305
	if (ioctl(f, SOUND_PCM_WRITE_CHANNELS, &__nCh) >= 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1306
	    __INST(numberOfChannels) = nChannels;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1307
	    RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1308
	}
920
1c8a18a7a7cf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
  1309
#  else
1c8a18a7a7cf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
  1310
#   ifdef AUDIO_SET_CHANNELS /* hpux */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1311
	if (ioctl (f, AUDIO_SET_CHANNELS, __nCh)) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1312
	    /* console_fprintf(stderr, "got err-ret from AUDIO_SET_CHANNELS\n"); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1313
	    __INST(numberOfChannels) = nChannels;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1314
	    RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1315
	}
920
1c8a18a7a7cf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 919
diff changeset
  1316
#   endif
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  1317
#  endif
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1318
# endif
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1319
    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1320
#endif
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1321
%}.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1322
    ^ UnsupportedOperationSignal raise
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1323
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1324
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1325
     self writing setChannels:2; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1326
     self writing setChannels:2; setSampleRate:10000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1327
     self writing setChannels:2; setSampleRate:40000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1328
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1329
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1330
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1331
setFragmentSize:blockSize
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1332
    "set the soundDrivers fragmentSize.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1333
     Returns true if sucessfull - may fail with many sound devices."
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1334
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1335
    |fd|
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1336
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1337
    handle notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1338
	fd := self fileDescriptor.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1339
	fd isNil ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1340
	    self errorNotOpen.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1341
	    ^ nil
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1342
	]
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1343
    ].
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1344
%{
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1345
    int f = __intVal(fd);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1346
    int __blockSize = 0;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1347
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1348
#if defined(DEV_AUDIO)
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1349
    if (__isSmallInteger(fd) && __isSmallInteger(blockSize)) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1350
	__blockSize = __intVal(blockSize);
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1351
# if defined(SNDCTL_DSP_SETFRAGMENT)
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1352
	if (ioctl(f, SNDCTL_DSP_SETFRAGMENT, &__blockSize) >= 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1353
	    /* __INST(blockSize) = blockSize; */
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1354
	    RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1355
	}
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1356
# endif
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1357
# ifdef AUDIO_SET_CHANNELS /* hpux */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1358
	if (ioctl (f, AUDIO_SET_TXBUFSIZE, __blockSize)) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1359
	    /* console_fprintf(stderr, "got err-ret from AUDIO_SET_TXBUFSIZE\n"); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1360
	    /* __INST(blockSize) = blockSize; */
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1361
	    RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1362
	}
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1363
# endif
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1364
    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1365
#endif
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1366
%}.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1367
    ^ UnsupportedOperationSignal raise
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1368
!
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1369
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1370
setSampleRate:hz
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1371
    "set the sample rate.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1372
     Returns true if sucessfull - may fail with many sound devices."
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1373
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1374
    |fd|
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1375
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1376
    handle notNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1377
	fd := self fileDescriptor.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1378
	fd isNil ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1379
	    self errorNotOpen.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1380
	    ^ nil
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1381
	]
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1382
    ].
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1383
%{
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1384
#if defined(DEV_AUDIO)
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1385
    if (__isSmallInteger(fd) && __isSmallInteger(hz)) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1386
	int f = __intVal(fd);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1387
	int __rate = __intVal(hz);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1388
	int __rateWant = __rate;
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1389
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1390
# if defined(SNDCTL_DSP_SPEED)
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1391
	if (ioctl(f, SNDCTL_DSP_SPEED, &__rate) >= 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1392
	    if (__rate != __rateWant) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1393
		console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1394
		hz = __MKSMALLINT(__rate);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1395
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1396
	    __INST(sampleRate) = hz;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1397
	    RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1398
	}
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1399
# else
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1400
#  if defined(SOUND_PCM_WRITE_RATE)
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1401
	if (ioctl(f, SOUND_PCM_WRITE_RATE, &__rate) >= 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1402
	    if (__rate != __rateWant) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1403
		console_fprintf(stderr, "SoundStream [warning]: actual rate is %d\n", __rate);
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1404
		hz = __MKSMALLINT(__rate);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1405
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1406
	    __INST(sampleRate) = hz;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1407
	    RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1408
	}
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1409
#  else
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1410
#   ifdef AUDIO_SET_SAMPLE_RATE /* hpux */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1411
	if (ioctl (f, AUDIO_SET_SAMPLE_RATE, __rate)) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1412
	    /* console_fprintf(stderr, "got err-ret from AUDIO_SET_SAMPLE_RATE\n"); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1413
	    __INST(sampleRate) = hz;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1414
	    RETURN (self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1415
	}
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1416
#   endif
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1417
#  endif
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1418
# endif
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1419
    }
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1420
#endif
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1421
%}.
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1422
    ^ UnsupportedOperationSignal raise
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1423
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1424
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1425
     self writing setSampleRate:10000; dumpSettings; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1426
     self writing setSampleRate:1000; dumpSettings; close
919
5adc0bfa511d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 918
diff changeset
  1427
     self writing setSampleRate:8000; dumpSettings; close
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1428
    "
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1429
!
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1430
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1431
supportedAudioFormats
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1432
    "return a collection of supported audio formats.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1433
     returned symbols are:
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1434
	U8        unsigned 8bit samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1435
	S8        signed 8bit samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1436
	MU_LAW    u-law encoded 8bit samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1437
	A_LAW     a-law encoded 8bit samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1438
	IMA_ADPCM adpcm encoded
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1439
	U16       unsigned 16bit samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1440
	U16_LE    unsigned 16bit big endian samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1441
	U16_BE    unsigned 16bit big endian samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1442
	S16       signed 16bit little endian samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1443
	S16_LE    signed 16bit little endian samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1444
	S16_BE    signed 16bit big endian samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1445
	MPEG      audio mpeg encoded
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1446
    "
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1447
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1448
    |fd audioFormatMask
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1449
     supportedFormats
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1450
     supports_MU_LAW supports_A_LAW
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1451
     supports_IMA_ADPCM supports_U8
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1452
     supports_S16_LE supports_S16_BE
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1453
     supports_S8 supports_U16_LE
713
85912db3ad19 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 712
diff changeset
  1454
     supports_U16_BE supports_MPEG|
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1455
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1456
    fd := self fileDescriptor.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1457
    fd isNil ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1458
	self errorNotOpen.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1459
	^ nil
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1460
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1461
%{
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1462
    int f = __intVal(fd);
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1463
    int __audioFormatMask = 0;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1464
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1465
#if defined(DEV_AUDIO)
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1466
    supports_MU_LAW = true;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1467
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1468
# if defined(SNDCTL_DSP_GETFMTS)
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1469
    if (ioctl(f, SNDCTL_DSP_GETFMTS, &__audioFormatMask) >= 0) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1470
	audioFormatMask = __MKSMALLINT(__audioFormatMask);
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1471
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1472
#  ifdef AFMT_MU_LAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1473
	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
  1474
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1475
#  ifdef AFMT_A_LAW
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1476
	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
  1477
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1478
#  ifdef AFMT_IMA_ADPCM
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1479
	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
  1480
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1481
#  ifdef AFMT_U8
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1482
	supports_U8 = (__audioFormatMask & AFMT_U8) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1483
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1484
#  ifdef AFMT_S16_LE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1485
	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
  1486
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1487
#  ifdef AFMT_S16_BE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1488
	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
  1489
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1490
#  ifdef AFMT_S8
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1491
	supports_S8 = (__audioFormatMask & AFMT_S8) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1492
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1493
#  ifdef AFMT_U16_LE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1494
	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
  1495
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1496
#  ifdef AFMT_U16_BE
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1497
	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
  1498
#  endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1499
#  ifdef AFMT_MPEG
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1500
	supports_MPEG = (__audioFormatMask & AFMT_MPEG) ? true : false;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1501
#  endif
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1502
    }
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1503
# endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1504
724
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1505
# ifdef hpux
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1506
    supports_MU_LAW = true;
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1507
    supports_A_LAW = true;
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1508
    supports_S16_BE = true;
2b22b88165ec *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1509
# endif
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1510
#endif /* DEV_AUDIO */
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1511
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1512
#ifdef IRIS_AUDIO
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1513
    supports_U8 = true;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1514
    supports_U16_BE = true;
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1515
#endif
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1516
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1517
#ifdef WIN32
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1518
    supports_S16_LE = true;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1519
#endif
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1520
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1521
%}.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1522
    supportedFormats := IdentitySet new.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1523
    supports_MU_LAW ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1524
	supportedFormats add:#'MU_LAW'
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1525
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1526
    supports_A_LAW ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1527
	supportedFormats add:#'A_LAW'
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1528
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1529
    supports_IMA_ADPCM ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1530
	supportedFormats add:#'IMA_ADPCM'
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1531
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1532
    supports_S8 ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1533
	supportedFormats add:#'S8'
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1534
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1535
    supports_U8 ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1536
	supportedFormats add:#'U8'
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1537
    ].
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1538
    supports_S16_LE ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1539
	supportedFormats add:#'S16_LE'.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1540
	UninterpretedBytes isBigEndian ifFalse:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1541
	    supportedFormats add:#'S16'.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1542
	]
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1543
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1544
    supports_S16_BE ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1545
	supportedFormats add:#'S16_BE'.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1546
	UninterpretedBytes isBigEndian ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1547
	    supportedFormats add:#'S16'.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1548
	]
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1549
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1550
    supports_U16_LE ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1551
	supportedFormats add:#'U16_LE'.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1552
	UninterpretedBytes isBigEndian ifFalse:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1553
	    supportedFormats add:#'U16'.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1554
	]
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1555
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1556
    supports_U16_BE ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1557
	supportedFormats add:#'U16_BE'.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1558
	UninterpretedBytes isBigEndian ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1559
	    supportedFormats add:#'U16'.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1560
	]
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1561
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1562
    supports_MPEG ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1563
	supportedFormats add:#'MPEG'
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1564
    ].
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1565
    ^ supportedFormats.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1566
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1567
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1568
     |s formats|
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1569
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1570
     s := self writing.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1571
     formats := s supportedAudioFormats.
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1572
     s close.
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1573
     formats
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  1574
    "
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1575
! !
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1576
1474
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1446
diff changeset
  1577
!SoundStream protectedMethodsFor:'redefined'!
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  1578
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1579
closeFile
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1580
    "a stream has been collected - close the file"
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1581
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1582
%{
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1583
#ifdef IRIS_AUDIO
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1584
    OBJ port;
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1585
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1586
    if ((port = __INST(alPort)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1587
	__INST(alPort) = nil;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1588
	ALcloseport(__ALportVal(port));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1589
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1590
    RETURN (self);
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1591
#endif /* IRIS_AUDIO */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1592
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1593
#ifdef WIN32_DIRECTSOUND
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1594
    OBJ oDirectSound, oDSBuffer;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1595
    LPDIRECTSOUND       t_pDirectSound;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1596
    LPDIRECTSOUNDBUFFER t_pDSBuffer;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1597
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1598
    if ((oDSBuffer = __INST(pDSBuffer)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1599
	__INST(pDSBuffer) = nil;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1600
	t_pDSBuffer = __DSBufferVal(oDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1601
	if (t_pDSBuffer) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1602
	    IDirectSoundBuffer_Stop(t_pDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1603
	    IDirectSoundBuffer_Release(t_pDSBuffer);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1604
	}
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1605
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1606
    if ((oDirectSound = __INST(pDirectSound)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1607
	__INST(pDirectSound) = nil;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1608
	t_pDirectSound = __DirectSoundVal(oDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1609
	if (t_pDirectSound) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1610
	    IDirectSound_Release(t_pDirectSound);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1611
	}
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1612
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1613
    RETURN (self);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1614
#endif /* WIN32_DIRECTSOUND */
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1615
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1616
#ifdef WIN32_WAVE
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1617
    struct buf *bp, *next;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1618
    int r;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1619
    HWAVEOUT t_waveHandle;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1620
    OBJ oWaveHandle;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1621
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1622
    if ((oWaveHandle = __INST(waveHandle)) != nil) {
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1623
	t_waveHandle = __WaveHandleVal(oWaveHandle);
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1624
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1625
# ifdef NO_WAIT_IN_CLOSE
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1626
	/* Force cancellation of any pending buffers */
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1627
	(void)waveOutReset(t_waveHandle);
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1628
# endif
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1629
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1630
	/* Wait until all pending buffers have been freed */
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1631
	while (free_buffers < total_buffers) {
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1632
	    WaitForSingleObject(free_buffer_event, INFINITE);
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1633
	}
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1634
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1635
# ifndef NO_WAIT_IN_CLOSE
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1636
	/* Force cancellation of any pending buffers */
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1637
	(void)waveOutReset(t_waveHandle);
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1638
# endif
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1639
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1640
	/* Close the device */
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1641
	if ((r = waveOutClose(t_waveHandle)) != 0) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1642
	    console_printf("waveOutClose\n");
922
2439a81a0530 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 921
diff changeset
  1643
	    RETURN(self);
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1644
	}
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1645
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1646
	EnterCriticalSection(&free_list_lock);
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1647
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1648
	/* Free allocated buffers */
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1649
	for (bp = free_list; bp != NULL; bp = next) {
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1650
	    next = bp->next;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1651
	    (void)free(bp);
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1652
	}
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1653
	free_list = NULL;
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1654
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1655
	LeaveCriticalSection(&free_list_lock);
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1656
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1657
	__INST(waveHandle) = nil;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1658
    }
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1659
    RETURN (self);
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1660
# endif /* WIN32_WAVE */
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1661
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1662
#if defined(DEV_AUDIO)
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1663
    OBJ fp;
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1664
    int fd;
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1665
    FILE *f;
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1666
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1667
    if ((fp = __INST(handle)) != nil) {
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1668
	f = __FILEVal(fp);
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1669
	__INST(handle) = nil;
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1670
# ifdef LINUX
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1671
	sigsetmask(~0);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1672
# endif
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1673
	if (__INST(buffered) == true) {
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1674
	    fflush(f);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1675
	    fclose(f);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1676
	} else {
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1677
	    fd = fileno(f);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1678
	    close(fd);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1679
	    fclose(f);
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1680
	}
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1681
# ifdef LINUX
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1682
	sigsetmask(0);
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1683
# endif
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1684
    }
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1685
    RETURN (self);
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  1686
#endif /* DEV_AUDIO */
595
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1687
%}.
fcff6c911d4a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 594
diff changeset
  1688
    ^ super closeFile
1474
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1446
diff changeset
  1689
! !
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1446
diff changeset
  1690
1ad407692b0b Protect #closeFile.
Stefan Vogel <sv@exept.de>
parents: 1446
diff changeset
  1691
!SoundStream methodsFor:'redefined'!
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1692
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1693
flush
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1694
    "wait until all sound has been played"
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1695
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1696
    |fd|
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1697
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1698
    fd := self fileDescriptor.
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1699
%{
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1700
#ifdef IRIS_AUDIO
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1701
    OPJ port;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1702
    ALport p;
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1703
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1704
    if ((port = __INST(alPort)) != nil) {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1705
	p = __ALportVal(port);
592
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1706
	while (ALgetfilled(p) > 0) {
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1707
	    sginap(1);
7daa4b2db7eb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 575
diff changeset
  1708
	}
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1709
    }
353
d1b7f731a331 Avoid callong of getOStype.
Stefan Vogel <sv@exept.de>
parents: 277
diff changeset
  1710
    RETURN(self);
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1711
#endif /* IRIS_AUDIO */
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1712
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1713
#if defined(DEV_AUDIO)
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1714
    if (__isSmallInteger(fd)) {
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1715
	int f = __intVal(fd);
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1716
	/* ... */
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1717
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1718
#endif /* DEV_AUDIO */
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1719
%}.
353
d1b7f731a331 Avoid callong of getOStype.
Stefan Vogel <sv@exept.de>
parents: 277
diff changeset
  1720
    "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
  1721
    ^ self
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1722
!
274
f45bd0d6ea31 Rename synchronizeOutput --> flush.
Stefan Vogel <sv@exept.de>
parents: 259
diff changeset
  1723
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1724
isOpen
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1725
    handle1 notNil ifTrue:[^ true].
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1726
    handle2 notNil ifTrue:[^ true].
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1727
    ^ handle notNil
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1728
!
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1729
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1730
nextBytes:count into:anObject startingAt:start
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1731
    "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
  1732
     bytes read or nil on error.
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1733
     Use with ByteArrays only."
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1734
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1735
%{
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1736
#ifdef IRIS_AUDIO
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1737
  {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1738
    OBJ port;
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1739
    ALport p;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1740
    int cnt, offs, nSamp;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1741
    int objSize;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1742
    char *cp;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1743
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1744
    if ((port = __INST(alPort)) != nil) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1745
	if (__INST(mode) != _writeonly) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1746
	    if (__bothSmallInteger(count, start)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1747
		cnt = __intVal(count);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1748
		offs = __intVal(start) - 1;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1749
		p = __ALportVal(port);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1750
		objSize = _Size(anObject) - OHDR_SIZE;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1751
		if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1752
		    cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1753
		    if (__INST(bitsPerSample) == __MKSMALLINT(16))
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1754
			nSamp = cnt / 2;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1755
		    else
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1756
			nSamp = cnt;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1757
		    ALreadsamps(p, cp, nSamp);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1758
		    RETURN ( __MKSMALLINT(cnt) );
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1759
		}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1760
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1761
	}
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1762
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1763
  }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1764
#endif /* IRIS_AUDIO */
926
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1765
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1766
#if defined(DEV_AUDIO)
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1767
   /*
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1768
    * redefine to work around a bug in the linux sound driver;
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1769
    * if a write is interrupted (EINTR), it is not defined, how many
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1770
    * bytes have been read from the device.
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1771
    *
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1772
    * As a workaround, disable signals here to prevent the write from
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1773
    * being interrupted.
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1774
    */
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1775
    int cnt, offs, objSize, n;
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1776
    char *cp;
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1777
    OBJ fp;
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1778
    FILE *f;
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1779
    int fd;
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1780
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1781
    if ((fp = __INST(handle)) != nil) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1782
	f = __FILEVal(fp);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1783
	if (__INST(mode) != @symbol(writeonly)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1784
	    if (__bothSmallInteger(count, start)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1785
		cnt = __intVal(count);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1786
		offs = __intVal(start) - 1;
926
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1787
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1788
		objSize = _Size(anObject) - OHDR_SIZE;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1789
		if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1790
		    do {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1791
			cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
926
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1792
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1793
			n = cnt;
927
6793d8aecaa7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 926
diff changeset
  1794
/*                        if (n > 4096) n = 4096; */
926
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1795
# ifdef LINUX
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1796
			sigsetmask(~0);
926
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1797
# endif
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1798
			if (__INST(buffered) == true) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1799
			    n = fread(cp, 1, n, f);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1800
			} else {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1801
			    fd = fileno(f);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1802
			    n = read(fd, cp, n);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1803
			}
926
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1804
# ifdef LINUX
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1805
			sigsetmask(0);
926
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1806
# endif
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1807
			__BEGIN_INTERRUPTABLE__
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1808
			__END_INTERRUPTABLE__
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1809
/* console_printf("SoundStream: read %d bytes\n", n); */
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1810
			if (n > 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1811
			    offs += n;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1812
			    cnt -= n;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1813
			} else {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1814
			    if (n < 0) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1815
				console_fprintf(stderr, "read error: %d\n", __threadErrno);
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1816
				RETURN (count);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1817
			    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1818
			}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1819
		    } while (cnt);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1820
		}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1821
		RETURN (count);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1822
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1823
	}
926
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1824
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1825
#endif /* DEV_AUDIO */
926
2f6d4a59e063 reading
Claus Gittinger <cg@exept.de>
parents: 924
diff changeset
  1826
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  1827
%}.
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1828
    OperatingSystem getOSType = 'irix' ifFalse:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1829
	OperatingSystem getOSType = 'win32' ifFalse:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1830
	    ^ super nextPutBytes:count from:anObject startingAt:start
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1831
	].
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1832
    ].
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  1833
    handle isNil ifTrue:[^ self errorNotOpen].
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1834
    (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1835
    self primitiveFailed
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1836
!
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1837
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1838
nextPutBytes:count from:anObject startingAt:start
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  1839
    "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
  1840
     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
  1841
     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
  1842
     (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
  1843
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1844
%{
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1845
#ifdef IRIS_AUDIO
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1846
  {
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1847
    OBJ port;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1848
    ALport p;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1849
    int cnt, offs, nSamp;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1850
    int objSize;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1851
    char *cp;
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1852
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1853
    if ((port = __INST(alPort)) != nil) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1854
	if (__INST(mode) != @symbol(readonly)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1855
	    if (__bothSmallInteger(count, start)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1856
		cnt = __intVal(count);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1857
		offs = __intVal(start) - 1;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1858
		p = __ALportVal(port);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1859
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1860
		/*
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1861
		 * compute number of samples
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1862
		 */
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1863
		objSize = _Size(anObject) - OHDR_SIZE;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1864
		if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1865
		    cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1866
		    if (__INST(bitsPerSample) == __MKSMALLINT(16))
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1867
			nSamp = cnt / 2;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1868
		    else
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1869
			nSamp = cnt;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1870
		    ALwritesamps(p, cp, cnt);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1871
		    RETURN ( count );
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1872
		}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1873
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1874
	}
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1875
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  1876
  }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1877
#endif /* IRIS_AUDIO */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1878
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1879
#ifdef WIN32_DIRECTSOUND
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1880
  {
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1881
    HRESULT hr;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1882
    DWORD status;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1883
    LPVOID lpbuf1 = NULL;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1884
    LPVOID lpbuf2 = NULL;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1885
    DWORD dwsize1 = 0;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1886
    DWORD dwsize2 = 0;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1887
    DWORD playPos, safePos, endWrite;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1888
    DWORD millis;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1889
    OBJ oDirectSound, oDSBuffer;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1890
    LPDIRECTSOUND       t_pDirectSound = (LPDIRECTSOUND)0;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1891
    LPDIRECTSOUNDBUFFER t_pDSBuffer = (LPDIRECTSOUNDBUFFER)0;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1892
    int t_cbBufOffset, t_cbBufSize;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1893
    short *buf;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1894
    int cnt, offs;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1895
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1896
    if ((oDSBuffer = __INST(pDSBuffer)) != nil) {
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1897
	t_pDSBuffer = __DSBufferVal(oDSBuffer);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1898
    }
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1899
    if ((oDirectSound = __INST(pDirectSound)) != nil) {
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1900
	t_pDirectSound = __DirectSoundVal(oDirectSound);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1901
    }
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1902
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1903
    if (!t_pDSBuffer || !t_pDirectSound) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1904
	console_fprintf(stderr, "SoundStream not open!\n");
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1905
	RETURN (0);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1906
    }
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1907
    t_cbBufOffset = __intVal(__INST(bufferOffset));
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1908
    t_cbBufSize = __intVal(__INST(bufferSize));
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1909
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1910
    cnt = __intVal(count);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1911
    offs = __intVal(start) - 1;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1912
    buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1913
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1914
    // Should be playing, right?
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1915
    hr = IDirectSoundBuffer_GetStatus(t_pDSBuffer, &status );
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1916
    if (!(status && DSBSTATUS_PLAYING)) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1917
	console_fprintf(stderr, "Buffer not playing!\n");
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1918
	RETURN (0);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1919
    }
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1920
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1921
    // Sleep until we have enough room in buffer.
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1922
    hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos );
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1923
    if( hr != DS_OK ) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1924
	console_fprintf(stderr, "Cannot get position!\n");
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1925
	RETURN (0);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1926
    }
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1927
    if( playPos < t_cbBufOffset ) playPos += t_cbBufSize;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1928
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1929
    endWrite = t_cbBufOffset + (cnt * sizeof(short));
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1930
    while ( playPos < endWrite ) {
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1931
	// Calculate number of milliseconds until we will have room, as
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1932
	// time = distance * (milliseconds/second) / ((bytes/sample) * (samples/second)),
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1933
	// rounded up.
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1934
	millis = (DWORD) (1.0 + ((endWrite - playPos) * 1000.0) / ( sizeof(short) * __intVal(__INST(sampleRate))));
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1935
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1936
	// Sleep for that long
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1937
	Sleep( millis );
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1938
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1939
	// Wake up, find out where we are now
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1940
	hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos );
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1941
	if( hr != DS_OK ) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  1942
	    console_fprintf(stderr, "Cannot get position!\n");
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1943
	    RETURN (0);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1944
	}
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1945
	if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; // unwrap offset
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1946
    }
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1947
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1948
    // Lock free space in the DS
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1949
    hr = IDirectSoundBuffer_Lock(t_pDSBuffer, t_cbBufOffset, cnt * sizeof(short), &lpbuf1, &dwsize1, &lpbuf2, &dwsize2, 0);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1950
    if (hr == DS_OK) {
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1951
	// Copy the buffer into the DS
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1952
	CopyMemory(lpbuf1, buf, dwsize1);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1953
	if(NULL != lpbuf2) CopyMemory(lpbuf2, buf+dwsize1, dwsize2);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1954
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1955
	// Update our buffer offset and unlock sound buffer
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1956
	t_cbBufOffset = (t_cbBufOffset + dwsize1 + dwsize2) % t_cbBufSize;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1957
	IDirectSoundBuffer_Unlock(t_pDSBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2);
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1958
    }
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1959
    __INST(buffferOffset) = __MKSMALLINT(t_cbBufOffset);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1960
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1961
    RETURN (count);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  1962
  }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1963
#endif /* WIN32_DIRECTSOUND */
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1964
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  1965
#ifdef WIN32_WAVE
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1966
  {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1967
    struct buf *bp;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1968
    int len, i, r;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1969
    int dataLen, offs;
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  1970
    short *buf;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1971
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1972
    HWAVEOUT t_waveHandle;
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1973
    OBJ oWaveHandle;
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1974
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1975
    if ((oWaveHandle = __INST(waveHandle)) == nil) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1976
	RETURN(0);
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1977
    }
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1978
    t_waveHandle = __WaveHandleVal(oWaveHandle);
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1979
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1980
    dataLen = __intVal(count);
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1981
    offs = __intVal(start) - 1;
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  1982
    buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1983
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  1984
    while (dataLen > 0) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1985
	if (free_list == NULL && total_buffers < MAXBUF) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1986
	    /* Expand available buffer space */
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1987
	    bp = (struct buf *)malloc(sizeof(struct buf));
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1988
	    total_buffers++;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1989
	} else {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1990
	    if (free_list == NULL) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1991
		/* We must wait for a free buffer */
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1992
		while (free_list == NULL) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1993
		    WaitForSingleObject(free_buffer_event, INFINITE);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1994
		}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1995
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1996
	    EnterCriticalSection(&free_list_lock);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1997
	    bp = free_list;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1998
	    free_list = free_list->next;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  1999
	    --free_buffers;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2000
	    LeaveCriticalSection(&free_list_lock);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2001
	    r = waveOutUnprepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2002
	    if (r != 0) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  2003
		console_printf("waveOutUnprepareHeader\n");
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2004
		RETURN(self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2005
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2006
	}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2007
	len = min(dataLen, DATALEN);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2008
	bp->hdr.lpData = (char *)bp->data;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2009
	bp->hdr.dwBufferLength = len;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2010
	bp->hdr.dwBytesRecorded = len;
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2011
	bp->hdr.dwUser = (INT)(bp);
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2012
	bp->hdr.dwFlags = 0;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2013
	bp->hdr.dwLoops = 0;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2014
	r = waveOutPrepareHeader(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2015
	if (r != 0) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  2016
	    console_printf("waveOutPrepareHeader\n");
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2017
	    RETURN(self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2018
	}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2019
	for (i = 0; i < len; i++) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2020
	    bp->data[i] = buf[i];
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2021
	}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2022
	r = waveOutWrite(t_waveHandle, &bp->hdr, sizeof(WAVEHDR));
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2023
	if (r != 0) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  2024
	    console_printf("waveOutWrite\n");
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2025
	    RETURN(self);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2026
	}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2027
	buf += len;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2028
	dataLen -= len;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2029
    }
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2030
    RETURN (count);
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2031
  }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2032
#endif /* WIN32_WAVE */
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2033
594
0d62900b49c8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 593
diff changeset
  2034
#if defined(DEV_AUDIO)
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2035
   /*
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2036
    * redefine to work around a bug in the linux sound driver;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2037
    * 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
  2038
    * bytes have been written to the device.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2039
    * 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
  2040
    * finishing.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2041
    *
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2042
    * As a workaround, disable signals here to prevent the write from
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2043
    * being interrupted.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2044
    */
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2045
    int cnt, offs, objSize, n;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2046
    char *cp;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2047
    OBJ fp;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2048
    FILE *f;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2049
    int fd;
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2050
2321
6f4cc7b644db filePointer -> handle migration
Claus Gittinger <cg@exept.de>
parents: 1853
diff changeset
  2051
    if ((fp = __INST(handle)) != nil) {
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2052
	f = __FILEVal(fp);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2053
	if (__INST(mode) != @symbol(readonly)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2054
	    if (__bothSmallInteger(count, start)) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2055
		cnt = __intVal(count);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2056
		offs = __intVal(start) - 1;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2057
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2058
		objSize = _Size(anObject) - OHDR_SIZE;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2059
		if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2060
		    do {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2061
			cp = (char *)__InstPtr(anObject) + OHDR_SIZE + offs;
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2062
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2063
			n = cnt;
927
6793d8aecaa7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 926
diff changeset
  2064
/*                        if (n > 4096) n = 4096; */
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  2065
# ifdef LINUX
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2066
			sigsetmask(~0);
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  2067
# endif
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2068
			if (__INST(buffered) == true) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2069
			    n = fwrite(cp, 1, n, f);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2070
			} else {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2071
			    fd = fileno(f);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2072
			    n = write(fd, cp, n);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2073
			}
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  2074
# ifdef LINUX
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2075
			sigsetmask(0);
598
1e8d7e905a0c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 597
diff changeset
  2076
# endif
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2077
			__BEGIN_INTERRUPTABLE__
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2078
			__END_INTERRUPTABLE__
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2079
			if (n > 0) {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2080
			    offs += n;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2081
			    cnt -= n;
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2082
			} else {
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2083
			    if (n < 0) {
1839
c10cd58ec334 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1583
diff changeset
  2084
				console_fprintf(stderr, "write error: %d\n", __threadErrno);
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2085
				RETURN (count);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2086
			    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2087
			}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2088
		    } while (cnt);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2089
		}
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2090
		RETURN (count);
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2091
	    }
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2092
	}
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2093
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2094
#endif /* DEV_AUDIO */
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2095
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2096
%}.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2097
    ^ super nextPutBytes:count from:anObject startingAt:start
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2098
!
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  2099
1480
dbfc64f5af59 Fix #reOpen handling:
Stefan Vogel <sv@exept.de>
parents: 1474
diff changeset
  2100
openWithMode:aMode attributes:attributeSpec
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2101
    |ok|
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2102
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2103
%{
36
d046fe84ea67 *** empty log message ***
claus
parents: 31
diff changeset
  2104
#ifdef IRIS_AUDIO
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2105
  {
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2106
    ALconfig config;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2107
    ALport p;
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2108
    long params[] = {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2109
	AL_INPUT_SOURCE, AL_INPUT_MIC,
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2110
	AL_INPUT_RATE, 8000,
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2111
	AL_OUTPUT_RATE, 8000,
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2112
    };
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2113
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2114
    config = ALnewconfig();
217
fcfbc9f71048 underscore cleanup
Claus Gittinger <cg@exept.de>
parents: 152
diff changeset
  2115
    if (__INST(numberOfChannels) == __MKSMALLINT(2))
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2116
	ALsetchannels(config, AL_STEREO);
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2117
    else
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2118
	ALsetchannels(config, AL_MONO);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2119
    if (__INST(bitsPerSample) == __MKSMALLINT(16))
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2120
	ALsetwidth(config, AL_SAMPLE_16);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2121
    else
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2122
	ALsetwidth(config, AL_SAMPLE_8);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2123
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2124
    if (__isSmallInteger(__INST(sampleRate)))
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2125
	params[3] = params[5] = __intVal(__INST(sampleRate));
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2126
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2127
    ALsetparams(AL_DEFAULT_DEVICE, params, 6);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2128
    p = ALopenport("smallchat", (char *)_stringVal(aMode), config);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2129
    if (p) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2130
	OBJ t;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2131
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2132
	t = __MKEXTERNALADDRESS(p); __INST(alPort) = t; __STORE(self, t);
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2133
    } else {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2134
	__INST(alPort) = nil;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2135
	goto out;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2136
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2137
    __INST(binary) = true;
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2138
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2139
    ALfreeconfig(config);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2140
    /*
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2141
     * get the parameters actually installed
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2142
     */
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2143
    config = ALgetconfig(p);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2144
    switch (ALgetchannels(config)) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2145
	default:
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2146
	    /* cannot happen */
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2147
	case AL_MONO:
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2148
	    __INST(numberOfChannels) = __MKSMALLINT(1);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2149
	    break;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2150
	case AL_STEREO:
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2151
	    __INST(numberOfChannels) = __MKSMALLINT(2);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2152
	    break;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2153
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2154
    switch (ALgetwidth(config)) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2155
	default:
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2156
	    /* cannot happen */
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2157
	case AL_SAMPLE_8:
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2158
	    __INST(bitsPerSample) = __MKSMALLINT(8);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2159
	    break;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2160
	case AL_SAMPLE_16:
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2161
	    __INST(bitsPerSample) = __MKSMALLINT(16);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2162
	    break;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2163
	case AL_SAMPLE_24:
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2164
	    __INST(bitsPerSample) = __MKSMALLINT(24);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2165
	    break;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2166
    }
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2167
    ALgetparams(AL_DEFAULT_DEVICE, params, 6);
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2168
    __INST(sampleRate) = __MKSMALLINT(params[3]);
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2169
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2170
    ALfreeconfig(config);
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2171
    ok = true;
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2172
    goto out;
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2173
  }
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2174
#endif /* IRIS_AUDIO */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2175
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2176
#ifdef WIN32_DIRECTSOUND
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2177
  {
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2178
    HRESULT result;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2179
    LPDIRECTSOUND       t_pDirectSound;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2180
    LPDIRECTSOUNDBUFFER t_pDSBuffer, t_pDSPrimeBuffer;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2181
    WAVEFORMATEX        wfFormat;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2182
    DSBUFFERDESC        dsbdDesc, primarydsbDesc;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2183
    BYTE                *pDSBuffData;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2184
    int                 t_cbBufSize;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2185
    int                 dwDataLen;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2186
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2187
    /* Create the DS object */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2188
    if ((result = DirectSoundCreate(NULL, &t_pDirectSound, NULL)) != DS_OK) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2189
	console_fprintf(stderr,"SoundStream: Cannot open default sound device!!\n");
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2190
	goto out;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2191
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2192
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2193
    /* Define the wave format structure */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2194
    wfFormat.wFormatTag = WAVE_FORMAT_PCM;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2195
    wfFormat.nChannels = __intVal(__INST(numberOfChannels));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2196
    wfFormat.nSamplesPerSec = __intVal(__INST(sampleRate));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2197
    wfFormat.wBitsPerSample = __intVal(__INST(bitsPerSample));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2198
    wfFormat.nBlockAlign = wfFormat.nChannels * wfFormat.wBitsPerSample / 8;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2199
    wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2200
    wfFormat.cbSize = 0;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2201
#  if 0
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2202
    /* Setup the primary DS buffer description */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2203
    ZeroMemory(&primarydsbDesc, sizeof(DSBUFFERDESC));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2204
    primarydsbDesc.dwSize = sizeof(DSBUFFERDESC);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2205
    primarydsbDesc.dwFlags = DSBCAPS_PRIMARYBUFFER;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2206
    primarydsbDesc.dwBufferBytes = 0;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2207
    primarydsbDesc.lpwfxFormat = NULL;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2208
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2209
    /* Create the primary DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2210
    if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &primarydsbDesc,
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2211
						 &t_pDSPrimeBuffer, NULL)) != DS_OK) {
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2212
	console_fprintf(stderr,"SoundStream: Cannot get the primary DS buffer address!\n");
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2213
	IDirectSound_Release(t_pDirectSound);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2214
	goto out;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2215
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2216
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2217
    /* 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
  2218
       the default primary buffer is 8-bit, 22kHz! */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2219
    if ((result = IDirectSoundBuffer_SetFormat(t_pDSPrimeBuffer, &wfFormat)) != DS_OK) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2220
	console_fprintf(stderr,"SoundStream: Cannot set the primary DS buffer to proper sound format (%x) (%d)!\n", result, result);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2221
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2222
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2223
	IDirectSound_Release(t_pDirectSound);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2224
	goto out;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2225
    }
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2226
#  endif /* 0 */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2227
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2228
    /* Setup the secondary DS buffer description */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2229
    t_cbBufSize = RT_BUFFER_SIZE * sizeof(short) * NBUFS;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2230
    __INST(bufferSize) = __MKSMALLINT(t_cbBufSize);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2231
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2232
    ZeroMemory(&dsbdDesc, sizeof(DSBUFFERDESC));
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2233
    dsbdDesc.dwSize = sizeof(DSBUFFERDESC);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2234
    dsbdDesc.dwFlags = DSBCAPS_GLOBALFOCUS;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2235
    dsbdDesc.dwBufferBytes = t_cbBufSize;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2236
    dsbdDesc.lpwfxFormat = &wfFormat;
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2237
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2238
    /* Create the secondary DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2239
    if ((result = IDirectSound_CreateSoundBuffer(t_pDirectSound, &dsbdDesc, &t_pDSBuffer, NULL)) != DS_OK) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2240
	console_fprintf(stderr,"SoundStream: couldn't create sound buffer!\n");
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2241
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2242
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2243
	IDirectSound_Release(t_pDirectSound);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2244
	goto out;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2245
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2246
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2247
    /* Lock the DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2248
    if ((result = IDirectSoundBuffer_Lock(t_pDSBuffer, 0, t_cbBufSize, (LPLPVOID)&pDSBuffData,
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2249
					  &dwDataLen, NULL, NULL, 0)) != DS_OK) {
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2250
	console_fprintf(stderr,"SoundStream: couldn't lock sound buffer!\n");
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2251
	IDirectSoundBuffer_Stop(t_pDSBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2252
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2253
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2254
	IDirectSound_Release(t_pDirectSound);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2255
	goto out;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2256
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2257
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2258
    /* Zero the DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2259
    ZeroMemory(pDSBuffData, dwDataLen);
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2260
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2261
    /* Unlock the DS buffer */
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2262
    if ((result = IDirectSoundBuffer_Unlock(t_pDSBuffer, pDSBuffData, dwDataLen, NULL, 0)) != DS_OK) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2263
	console_fprintf(stderr,"SoundStream: couldn't unlock sound buffer!\n");
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2264
	IDirectSoundBuffer_Stop(t_pDSBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2265
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2266
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2267
	IDirectSound_Release(t_pDirectSound);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2268
	goto out;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2269
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2270
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2271
    __INST(bufferOffset) = __MKSMALLINT(0);  // reset last write position to start of buffer
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2272
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2273
    /* Start the buffer playback */
715
b2950d207977 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 714
diff changeset
  2274
    if ((result = IDirectSoundBuffer_Play(t_pDSBuffer, 0, 0, DSBPLAY_LOOPING) != DS_OK)) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2275
	console_fprintf(stderr,"SoundStream: couldn't play sound buffer!\n");
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2276
	IDirectSoundBuffer_Stop(t_pDSBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2277
	IDirectSoundBuffer_Stop(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2278
	IDirectSoundBuffer_Release(t_pDSPrimeBuffer);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2279
	IDirectSound_Release(t_pDirectSound);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2280
	ok = false;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2281
	goto out;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2282
    }
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2283
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2284
    {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2285
	OBJ t;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2286
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2287
	t = __MKEXTERNALADDRESS(t_pDSBuffer); __INST(pDSBuffer) = t; __STORE(self, t);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2288
	t = __MKEXTERNALADDRESS(t_pDirectSound); __INST(pDirectSound) = t; __STORE(self, t);
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2289
    }
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2290
    ok = true;
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2291
    goto out;
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2292
  }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2293
#endif /* WIN32_DIRECTSOUND */
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2294
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2295
#ifdef WIN32_WAVE
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2296
  {
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2297
    PCMWAVEFORMAT waveFormat;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2298
    int r;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2299
    HWAVEOUT t_waveHandle;
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2300
    OBJ oWaveHandle;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2301
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2302
    if ((oWaveHandle = __INST(waveHandle)) != nil) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2303
	ok = false;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2304
	goto out;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2305
    }
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2306
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2307
    waveFormat.wf.wFormatTag = WAVE_FORMAT_PCM;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2308
    waveFormat.wf.nChannels = __intVal(__INST(numberOfChannels));
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2309
    waveFormat.wf.nSamplesPerSec = __intVal(__INST(sampleRate));
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2310
    waveFormat.wBitsPerSample = __intVal(__INST(bitsPerSample));
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2311
    waveFormat.wf.nBlockAlign = waveFormat.wf.nChannels * waveFormat.wBitsPerSample / 8;
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2312
    waveFormat.wf.nAvgBytesPerSec = waveFormat.wf.nSamplesPerSec * waveFormat.wf.nBlockAlign;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2313
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2314
    r = waveOutOpen(&t_waveHandle,
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2315
		    WAVE_MAPPER,
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2316
		    (WAVEFORMAT *)&waveFormat,
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2317
		    (DWORD_PTR)waveCallBack,
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2318
		    (DWORD_PTR)0,
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2319
		    CALLBACK_FUNCTION);
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2320
    if (r != 0) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2321
	console_printf("waveOutOpen\n");
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2322
	ok = false;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2323
	goto out;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2324
    }
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2325
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2326
    (void)waveOutReset(t_waveHandle);
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2327
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2328
    free_list = NULL;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2329
    InitializeCriticalSection(&free_list_lock);
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2330
    free_buffers = 0;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2331
    free_buffer_event = CreateEvent(NULL, FALSE, FALSE, NULL);
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2332
    total_buffers = 0;
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2333
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2334
    {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2335
	OBJ t;
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2336
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2337
	t = __MKEXTERNALADDRESS(t_waveHandle); __INST(waveHandle) = t; __STORE(self, t);
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2338
    }
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2339
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2340
# if 0
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2341
    /*
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2342
     * HACK: If we immediately start writing valid audio data to the device
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2343
     * then the sound is choppy in the beginning. Writing a null packet to
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2344
     * to the device first seems to fix this problem although I have no idea
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2345
     * why - DAC
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2346
     */
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2347
    {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2348
	char null[DATALEN];
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2349
	int i;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2350
	for (i = 0; i < DATALEN; i++) {
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2351
	    null[i] = 127;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2352
	}
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2353
	audioWrite(null, DATALEN);
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2354
    }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2355
# endif /* 0 */
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2356
    ok = true;
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2357
    goto out;
721
99f4c93ca492 preps for WaveOut (WIN32)
Claus Gittinger <cg@exept.de>
parents: 720
diff changeset
  2358
  }
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2359
#endif /* !WIN32_DIRECTSOUND */
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2360
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  2361
#ifdef DEV_AUDIO
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2362
  {
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2363
      int __fd;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2364
      int __mode;
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2365
      FILE *f;
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  2366
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2367
      if (strcmp(__stringVal(aMode), "w") == 0) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2368
	  __mode = O_WRONLY;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2369
      } else if (strcmp(__stringVal(aMode), "r") == 0) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2370
	  __mode = O_RDONLY;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2371
      } else {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2372
	  __mode = O_RDWR;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2373
      }
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2374
      do {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2375
	  __BEGIN_INTERRUPTABLE__
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2376
	  __fd = open((char *) __stringVal(__INST(pathName)), __mode /* |O_NDELAY */);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2377
	  __END_INTERRUPTABLE__
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2378
      } while ((__fd < 0) && (__threadErrno == EINTR));
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  2379
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2380
      if (__fd >= 0) {
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2381
	  /*
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2382
	   * make it a FILE *
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2383
	   */
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2384
	  f = fdopen(__fd, __stringVal(aMode));
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2385
	  if (! f) {
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2386
	      __BEGIN_INTERRUPTABLE__
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2387
	      close(__fd);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2388
	      __END_INTERRUPTABLE__
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2389
	      ok = false;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2390
	      goto out;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2391
	  }
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2392
	  setbuf(f, NULL);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2393
	  __INST(buffered) = false;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2394
	  __INST(handle) = __MKEXTERNALADDRESS(f);
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2395
	  __STORESELF(handle);
932
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  2396
934
157a7640c5cb *** empty log message ***
ps
parents: 932
diff changeset
  2397
#if defined(PCM_ENABLE_OUTPUT) && defined(PCM_ENABLE_INPUT)
157a7640c5cb *** empty log message ***
ps
parents: 932
diff changeset
  2398
# if defined(SNDCTL_DSP_SETTRIGGER)
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2399
	  if (__mode == O_RDWR) {
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2400
	      int enable_bits = ~(PCM_ENABLE_OUTPUT|PCM_ENABLE_INPUT);
932
1c9375cf97fc *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 927
diff changeset
  2401
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2402
	      if (ioctl(__fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) == -1)
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2403
	      {
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2404
		  console_fprintf(stderr, "can't request synchronous start of fullduplex operation");
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2405
	      }
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2406
	  }
934
157a7640c5cb *** empty log message ***
ps
parents: 932
diff changeset
  2407
# endif
157a7640c5cb *** empty log message ***
ps
parents: 932
diff changeset
  2408
#endif
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2409
	  ok = true;
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2410
	  goto out;
1583
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2411
      }
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2412
  }
a45ac92afbc8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1556
diff changeset
  2413
#endif /* DEV_AUDIO */
921
c15fe619a1be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 920
diff changeset
  2414
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2415
out:;
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2416
%}.
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2417
    ok == false ifTrue:[
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2418
	self openError:lastErrorNumber.
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2419
	"normally not reached"
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2420
	^ nil.
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2421
    ].
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2422
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2423
    ok isNil ifTrue:[
3000
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2424
	"its a regular file open (i.e. /dev/audio) "
Claus Gittinger <cg@exept.de>
parents: 2833
diff changeset
  2425
	^ super openWithMode:aMode attributes:attributeSpec.
1422
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2426
    ].
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2427
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2428
    Lobby register:self.
59ad87529b94 Raise openError on open failure
Stefan Vogel <sv@exept.de>
parents: 1269
diff changeset
  2429
    ^ self.
277
ab17540f022a oops - your last checkin was garbage
Claus Gittinger <cg@exept.de>
parents: 274
diff changeset
  2430
! !
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2431
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2432
!SoundStream methodsFor:'sine wave generation'!
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2433
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2434
playSine16:freq forSeconds:seconds
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2435
    "output some tone for some time
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2436
     in S16 audioFormat - a test method"
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2437
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2438
    |buffer numSamples val scale isUnsigned|
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2439
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2440
    (audioFormat startsWith:#U16) ifFalse:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2441
	(audioFormat startsWith:#S16) ifFalse:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2442
	    self error:'must be in 16bit mode' mayProceed:true.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2443
	    ^ self
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2444
	]
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2445
    ].
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2446
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2447
    numSamples := (self sampleRate * seconds) truncated.
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2448
    buffer := WordArray new:numSamples.
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2449
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2450
    "fill it with a sine wave"
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2451
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2452
    isUnsigned := audioFormat startsWith:#U16.
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2453
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2454
    scale := freq * 2 * (Float pi).
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2455
    1 to:numSamples do:[:i |
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2456
	val := (scale * i / self sampleRate) sin.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2457
	val := (val * 16r7FFF) rounded bitAnd:16rFFFF.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2458
	isUnsigned ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2459
	    val := val + 32768
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2460
	].
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2461
	buffer at:i put:val
714
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  2462
    ].
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2463
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2464
    self nextPutBytes:(numSamples*2) from:buffer startingAt:1
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2465
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2466
    "
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2467
     SoundStream writing setAudioFormat:#S16; playSine16:440 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2468
     SoundStream writing setAudioFormat:#S16; playSine16:880 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2469
     SoundStream writing setAudioFormat:#S16; playSine16:1760 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2470
     SoundStream writing setAudioFormat:#S16; playSine16:3520 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2471
     SoundStream writing tuneTone:440; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2472
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2473
     SoundStream writing setAudioFormat:#U16; playSine16:880 forSeconds:2; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2474
     SoundStream writing setAudioFormat:#U16_LE; playSine16:880 forSeconds:2; close
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2475
    "
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2476
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2477
    "Modified: / 31.1.1999 / 12:12:41 / cg"
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2478
!
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2479
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2480
testMelody
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2481
    3 timesRepeat:[
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2482
	self playSine16:220 forSeconds:0.5.
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2483
	self playSine16:440 forSeconds:0.5.
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2484
	self playSine16:880 forSeconds:0.5.
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2485
	self playSine16:1760 forSeconds:0.5.
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2486
	self playSine16:3520 forSeconds:0.5.
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2487
    ]
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2488
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2489
    "
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2490
     self writing testMelody; close
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2491
    "
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2492
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2493
    "Created: / 31.1.1999 / 12:07:45 / cg"
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2494
    "Modified: / 31.1.1999 / 12:16:09 / cg"
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2495
!
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2496
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2497
tuneTone
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2498
    ^ self tuneTone:440
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2499
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2500
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2501
     SoundStream writing tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2502
     SoundStream writing setSampleRate:4000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2503
     SoundStream writing setSampleRate:8000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2504
     SoundStream writing setSampleRate:10000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2505
     SoundStream writing setSampleRate:20000; tuneTone; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2506
     SoundStream writing setSampleRate:40000; tuneTone; close
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2507
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2508
     SoundStream writing setSampleRate:40000; dumpSettings; close
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2509
     SoundStream writing setSampleRate:20000; dumpSettings; close
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2510
    "
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2511
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2512
    "Modified: / 31.1.1999 / 12:06:27 / cg"
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2513
!
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2514
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2515
tuneTone16:freq
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2516
    "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
  2517
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2518
    |buffer numSamples val scale oldFormat|
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2519
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2520
    (audioFormat startsWith:#U16) ifFalse:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2521
	(audioFormat startsWith:#S16) ifFalse:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2522
	    self error:'must be in 16bit mode' mayProceed:true.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2523
	    ^ self
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2524
	]
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2525
    ].
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2526
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2527
    "allocate memory for 1sec playing time"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2528
    numSamples := self sampleRate.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2529
    buffer := WordArray new:numSamples.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2530
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2531
    "fill it with a sine wave"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2532
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2533
    scale := freq * 2 * (Float pi).
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2534
    1 to:numSamples do:[:i |
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2535
	val := (scale * i / numSamples) sin.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2536
	val := (val * 16r7FFF) rounded bitAnd:16rFFFF.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2537
	audioFormat == #U16 ifTrue:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2538
	    val := val + 32768
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2539
	].
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2540
	buffer at:i put:val
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2541
    ].
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2542
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2543
    oldFormat := audioFormat.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2544
    self setAudioFormat:#S16.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2545
    1 to:3 do:[:s |
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2546
	self nextPutBytes:(numSamples*2) from:buffer startingAt:1
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2547
    ].
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2548
    self setAudioFormat:oldFormat.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2549
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2550
    "of course, the frequency should be below half the
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2551
     sampleRate - hear below ...
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2552
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2553
     SoundStream writing setSampleRate:4000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2554
     SoundStream writing setSampleRate:8000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2555
     SoundStream writing setSampleRate:10000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2556
     SoundStream writing setSampleRate:20000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2557
     SoundStream writing setSampleRate:40000; tuneTone16:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2558
    "
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2559
714
ebeacc2e07bc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 713
diff changeset
  2560
    "Modified: / 21.12.1998 / 09:11:30 / cg"
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2561
!
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2562
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2563
tuneTone8:freq
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2564
    "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
  2565
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2566
    |buffer numSamples val scale oldFormat|
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2567
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2568
    (audioFormat == #U8) ifFalse:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2569
	(audioFormat == #S8) ifFalse:[
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2570
	    self error:'must be in 8bit mode' mayProceed:true.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2571
	    ^ self
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2572
	]
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2573
    ].
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2574
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2575
    "allocate memory for 1sec playing time"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2576
    numSamples := self sampleRate.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2577
    buffer := ByteArray new:numSamples.
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2578
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2579
    "fill it with a sine wave"
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2580
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2581
    scale := freq * 2 * (Float pi).
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2582
    1 to:numSamples do:[:i |
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2583
	val := (scale * i / numSamples) sin.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2584
	val := (val * 127 + 128) rounded.
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2585
	buffer at:i put:val
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2586
    ].
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2587
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2588
    oldFormat := audioFormat.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2589
    self setAudioFormat:#U8.
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2590
    1 to:3 do:[:s |
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2591
	self nextPutBytes:numSamples from:buffer startingAt:1
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2592
    ].
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2593
    self setAudioFormat:oldFormat.
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2594
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2595
    "of course, the frequency should be below half the
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2596
     sampleRate - hear below ...
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2597
593
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2598
     SoundStream writing tuneTone; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2599
     SoundStream writing setSampleRate:4000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2600
     SoundStream writing setSampleRate:4000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2601
     SoundStream writing setSampleRate:8000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2602
     SoundStream writing setSampleRate:8000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2603
     SoundStream writing setSampleRate:8000; tuneTone:4000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2604
     SoundStream writing setSampleRate:10000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2605
     SoundStream writing setSampleRate:10000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2606
     SoundStream writing setSampleRate:10000; tuneTone:4000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2607
     SoundStream writing setSampleRate:20000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2608
     SoundStream writing setSampleRate:20000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2609
     SoundStream writing setSampleRate:20000; tuneTone:4000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2610
     SoundStream writing setSampleRate:20000; tuneTone:8000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2611
     SoundStream writing setSampleRate:40000; tuneTone:440; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2612
     SoundStream writing setSampleRate:40000; tuneTone:2000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2613
     SoundStream writing setSampleRate:40000; tuneTone:4000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2614
     SoundStream writing setSampleRate:40000; tuneTone:8000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2615
     SoundStream writing setSampleRate:40000; tuneTone:10000; close
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2616
    "
719f9d1c7bbb *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 592
diff changeset
  2617
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2618
    "Modified: / 15.12.1997 / 13:43:05 / cg"
722
0c3c1f866eb4 support waveOut
Claus Gittinger <cg@exept.de>
parents: 721
diff changeset
  2619
    "Created: / 31.1.1999 / 12:05:17 / cg"
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2620
!
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2621
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2622
tuneTone:freq
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2623
    ((audioFormat startsWith:#S16)
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2624
    or:[audioFormat startsWith:#U16]) ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2625
	^ self tuneTone16:freq
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2626
    ].
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2627
    audioFormat == #MU_LAW ifTrue:[
1556
8a78c9a5a8f7 STORE macro (gcc 3.4 bug workaround)
Claus Gittinger <cg@exept.de>
parents: 1480
diff changeset
  2628
	^ self tuneToneMU:freq
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2629
    ].
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2630
    self tuneTone8:freq
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2631
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2632
    "
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2633
     SoundStream writing tuneTone:880; close
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2634
     SoundStream writing setSampleRate:4000; tuneTone:440; close
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2635
     SoundStream writing setSampleRate:4000; tuneTone:880; close
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2636
     SoundStream writing setSampleRate:8000; tuneTone:440; close
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2637
     SoundStream writing setSampleRate:8000; tuneTone:880; close
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2638
     SoundStream writing setSampleRate:10000; tuneTone:440; close
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2639
     SoundStream writing setSampleRate:10000; tuneTone:880; close
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2640
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2641
     SoundStream writing setSampleRate:20000; tuneTone:440; close
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2642
     SoundStream writing setSampleRate:20000; tuneTone:880; close
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2643
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2644
     SoundStream writing setSampleRate:40000; tuneTone:440; close
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2645
     SoundStream writing setSampleRate:40000; tuneTone:880; close
923
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2646
     SoundStream writing setSampleRate:40000; tuneTone:1760; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2647
     SoundStream writing setSampleRate:40000; tuneTone:3520; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2648
     SoundStream writing setSampleRate:40000; tuneTone:7020; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2649
     SoundStream writing setSampleRate:40000; tuneTone:14040; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2650
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2651
     SoundStream writing setSampleRate:44100; tuneTone:440; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2652
     SoundStream writing setSampleRate:44100; tuneTone:880; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2653
     SoundStream writing setSampleRate:44100; tuneTone:1760; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2654
     SoundStream writing setSampleRate:44100; tuneTone:3520; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2655
     SoundStream writing setSampleRate:44100; tuneTone:7020; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2656
     SoundStream writing setSampleRate:44100; tuneTone:14040; close
cfb86334aebf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 922
diff changeset
  2657
788
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2658
     SoundStream writing setSampleRate:20000; dumpSettings; close
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2659
    "
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2660
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2661
    "Modified: / 31.1.1999 / 12:07:14 / cg"
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2662
!
5cf69ceb1166 error: vs. error:mayProceed:
Claus Gittinger <cg@exept.de>
parents: 753
diff changeset
  2663
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2664
tuneToneMU:freq
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2665
    "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
  2666
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2667
    |buffer numSamples val scale oldFormat|
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2668
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2669
    "allocate memory for 1sec playing time"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2670
    numSamples := self sampleRate.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2671
    buffer := ByteArray new:numSamples.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2672
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2673
    "fill it with a sine wave"
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2674
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2675
    scale := freq * 2 * (Float pi).
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2676
    1 to:numSamples do:[:i |
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2677
	val := (scale * i / numSamples) sin.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2678
	val := (val * 16r7FFF) rounded.
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2679
	buffer at:i put:(self class linear16ToUlaw:val)
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2680
    ].
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2681
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2682
    oldFormat := audioFormat.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2683
    self setAudioFormat:#MU_LAW.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2684
    1 to:3 do:[:s |
712
9e853d04f52b first attempt in win32 audio
Claus Gittinger <cg@exept.de>
parents: 614
diff changeset
  2685
	self nextPutBytes:numSamples from:buffer startingAt:1
597
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2686
    ].
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2687
    self setAudioFormat:oldFormat.
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2688
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2689
    "of course, the frequency should be below half the
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2690
     sampleRate - hear below ...
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2691
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2692
     SoundStream writing setSampleRate:8000; tuneToneMU:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2693
     SoundStream writing setSampleRate:10000; tuneToneMU:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2694
     SoundStream writing setSampleRate:20000; tuneToneMU:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2695
     SoundStream writing setSampleRate:40000; tuneToneMU:440; close
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2696
    "
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2697
42dafea485d3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 596
diff changeset
  2698
    "Modified: / 15.12.1997 / 13:46:19 / cg"
0
1cf8d1747859 Initial revision
claus
parents:
diff changeset
  2699
! !
121
606a3ccd3682 linux fixes (cut off when closing)
Claus Gittinger <cg@exept.de>
parents: 112
diff changeset
  2700
152
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
  2701
!SoundStream class methodsFor:'documentation'!
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
  2702
89d93f115cb8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 121
diff changeset
  2703
version
3156
edeed9ecae5b initialize methods
Stefan Vogel <sv@exept.de>
parents: 3154
diff changeset
  2704
    ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.78 2014-01-29 13:35:28 stefan Exp $'
2418
4ea40741b2b5 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2321
diff changeset
  2705
!
4ea40741b2b5 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2321
diff changeset
  2706
4ea40741b2b5 Use __MKEXTERNALADDRESS() instead of __MKOBJ()
Stefan Vogel <sv@exept.de>
parents: 2321
diff changeset
  2707
version_CVS
3156
edeed9ecae5b initialize methods
Stefan Vogel <sv@exept.de>
parents: 3154
diff changeset
  2708
    ^ '$Header: /cvs/stx/stx/libbasic2/SoundStream.st,v 1.78 2014-01-29 13:35:28 stefan Exp $'
918
c93d55269f9d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 861
diff changeset
  2709
! !
1151
5963256af171 do not depend on TimeStamp - TimeStamp to return seconds-integer
Claus Gittinger <cg@exept.de>
parents: 934
diff changeset
  2710
3154
23ac6f3e69b6 Initialize in instance initialize method insted in #new
Stefan Vogel <sv@exept.de>
parents: 3000
diff changeset
  2711
596
8d0920f791f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 595
diff changeset
  2712
SoundStream initialize!