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