11 " |
11 " |
12 |
12 |
13 "{ Package: 'stx:libbasic2' }" |
13 "{ Package: 'stx:libbasic2' }" |
14 |
14 |
15 FileStream subclass:#SoundStream |
15 FileStream subclass:#SoundStream |
16 instanceVariableNames:'sampleRate numberOfChannels bitsPerSample audioFormat alPort |
16 instanceVariableNames:'sampleRate numberOfChannels bitsPerSample audioFormat |
17 handle1 handle2 bufferOffset bufferSize' |
17 handle1 handle2 bufferOffset bufferSize' |
18 classVariableNames:'UnsupportedOperationSignal' |
18 classVariableNames:'UnsupportedOperationSignal' |
19 poolDictionaries:'' |
19 poolDictionaries:'' |
20 category:'Streams-External' |
20 category:'Streams-External' |
21 ! |
21 ! |
22 |
22 |
23 !SoundStream primitiveDefinitions! |
23 !SoundStream primitiveDefinitions! |
24 %{ |
24 %{ |
25 |
25 |
|
26 #ifdef WIN32 |
|
27 # define xxxUSE_WIN32_DIRECTSOUND |
|
28 #endif |
26 |
29 |
27 #ifdef IRIS |
30 #ifdef IRIS |
28 # ifndef IRIX5 |
31 # ifndef IRIX5 |
29 # define IRIS_AUDIO |
32 # define USE_IRIS_AUDIO |
30 # endif |
33 # endif |
31 #endif |
34 #endif |
32 |
35 |
33 #ifdef IRIS_AUDIO |
36 #ifndef USE_IRIS_AUDIO |
|
37 # ifndef USE_ALSA_AUDIO |
|
38 # ifdef LINUX |
|
39 # define USE_DEV_AUDIO |
|
40 # endif |
|
41 # endif |
|
42 #endif |
|
43 |
|
44 #ifdef USE_IRIS_AUDIO |
|
45 # define IRIS_AUDIO |
34 # include <audio.h> |
46 # include <audio.h> |
35 # define __ALportVal(o) (ALport)(__externalAddressVal(o)) |
47 # define __ALportVal(o) (ALport)(__externalAddressVal(o)) |
|
48 # define alPort handle1 |
36 #endif |
49 #endif |
37 |
50 |
38 #ifdef LINUX |
51 #ifdef USE_ALSA_AUDIO |
39 # include <stdio.h> |
52 # ifdef LINUX |
40 # include <sys/soundcard.h> |
53 # define ALSA_AUDIO |
41 # define DEV_AUDIO_DEFAULT_FREQ (8000) |
54 # include <alsa/asoundlib.h> |
42 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
55 # define MAX_NR_OF_CHANNELS 8 |
43 # define DEV_AUDIO |
56 # define DEBUG_SOUND |
|
57 # define readHandle handle1 |
|
58 # define writeHandle handle2 |
|
59 # endif |
44 #endif |
60 #endif |
45 |
61 |
46 #ifdef FREEBSD |
62 #ifdef USE_DEV_AUDIO |
47 # include <stdio.h> |
63 # ifdef LINUX |
48 # include <sys/time.h> |
64 # include <stdio.h> |
49 # include <sys/ioctl.h> |
65 # include <sys/soundcard.h> |
50 # include <machine/pcaudioio.h> |
66 # define DEV_AUDIO_DEFAULT_FREQ (8000) |
51 # define DEV_AUDIO_DEFAULT_FREQ (8000) |
67 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
52 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
68 # define DEV_AUDIO |
53 # define DEV_AUDIO |
69 # endif |
54 #endif |
70 |
55 |
71 # ifdef FREEBSD |
56 #if defined(sunos) || defined(solaris) |
72 # include <stdio.h> |
57 # include <stdio.h> |
73 # include <sys/time.h> |
58 # ifdef solaris |
74 # include <sys/ioctl.h> |
59 # include <sys/audioio.h> |
75 # include <machine/pcaudioio.h> |
60 # else |
76 # define DEV_AUDIO_DEFAULT_FREQ (8000) |
61 # include <sun/audioio.h> |
77 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
62 # endif |
78 # define DEV_AUDIO |
63 # define DEV_AUDIO_DEFAULT_FREQ (8000) |
79 # endif |
64 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
80 |
65 # define DEV_AUDIO |
81 # if defined(sunos) || defined(solaris) |
66 #endif |
82 # include <stdio.h> |
67 |
83 # ifdef solaris |
68 #if defined(hpux) |
84 # include <sys/audioio.h> |
69 # include <stdio.h> |
85 # else |
70 # include <sys/ioctl.h> |
86 # include <sun/audioio.h> |
71 # include <sys/inode.h> |
87 # endif |
72 # include <sys/audio.h> |
88 # define DEV_AUDIO_DEFAULT_FREQ (8000) |
73 # include <sys/time.h> |
89 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
74 # include <unistd.h> |
90 # define DEV_AUDIO |
75 # define DEV_AUDIO_DEFAULT_FREQ (22050) |
91 # endif |
76 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
92 |
77 # define DEV_AUDIO |
93 # if defined(hpux) |
78 #endif |
94 # include <stdio.h> |
|
95 # include <sys/ioctl.h> |
|
96 # include <sys/inode.h> |
|
97 # include <sys/audio.h> |
|
98 # include <sys/time.h> |
|
99 # include <unistd.h> |
|
100 # define DEV_AUDIO_DEFAULT_FREQ (22050) |
|
101 # define DEV_AUDIO_DEFAULT_BUFFERSIZE (16384) |
|
102 # define DEV_AUDIO |
|
103 # endif |
|
104 #endif /* USE_DEV_AUDIO */ |
79 |
105 |
80 #ifndef WIN32 |
106 #ifndef WIN32 |
81 # ifndef O_WRONLY |
107 # ifndef O_WRONLY |
82 # include <sys/fcntl.h> |
108 # include <sys/fcntl.h> |
83 # endif |
109 # endif |
84 |
110 |
85 # ifndef EINTR |
111 # include <errno.h> |
86 # include <errno.h> |
|
87 # endif |
|
88 #endif |
112 #endif |
89 |
113 |
90 #ifdef WIN32 |
114 #ifdef WIN32 |
91 |
115 |
92 # define _WIN32 |
116 # define _WIN32 |
854 int __stereo = __channels > 1; |
884 int __stereo = __channels > 1; |
855 int __format = -1; |
885 int __format = -1; |
856 |
886 |
857 if (0) { |
887 if (0) { |
858 } |
888 } |
|
889 else if (__INST(audioFormat) == @symbol(MU_LAW)) { |
859 # ifdef AFMT_MU_LAW |
890 # ifdef AFMT_MU_LAW |
860 else if (__INST(audioFormat) == @symbol(MU_LAW)) { |
|
861 __format = AFMT_MU_LAW; |
891 __format = AFMT_MU_LAW; |
862 } |
|
863 # endif |
892 # endif |
|
893 } |
|
894 else if (__INST(audioFormat) == @symbol(A_LAW)) { |
864 # ifdef AFMT_A_LAW |
895 # ifdef AFMT_A_LAW |
865 else if (__INST(audioFormat) == @symbol(A_LAW)) { |
|
866 __format = AFMT_A_LAW; |
896 __format = AFMT_A_LAW; |
867 } |
|
868 # endif |
897 # endif |
|
898 } |
|
899 else if (__INST(audioFormat) == @symbol(IMA_ADPCM)) { |
869 # ifdef AFMT_IMA_ADPCM |
900 # ifdef AFMT_IMA_ADPCM |
870 else if (__INST(audioFormat) == @symbol(IMA_ADPCM)) { |
|
871 __format = AFMT_IMA_ADPCM; |
901 __format = AFMT_IMA_ADPCM; |
872 } |
|
873 # endif |
902 # endif |
|
903 } |
|
904 else if (__INST(audioFormat) == @symbol(U8)) { |
874 # ifdef AFMT_U8 |
905 # ifdef AFMT_U8 |
875 else if (__INST(audioFormat) == @symbol(U8)) { |
|
876 __format = AFMT_U8; |
906 __format = AFMT_U8; |
877 } |
|
878 # endif |
907 # endif |
|
908 } |
|
909 else if (__INST(audioFormat) == @symbol(S16_LE)) { |
879 # ifdef AFMT_S16_LE |
910 # ifdef AFMT_S16_LE |
880 else if (__INST(audioFormat) == @symbol(S16_LE)) { |
|
881 __format = AFMT_S16_LE; |
911 __format = AFMT_S16_LE; |
882 } |
|
883 # endif |
912 # endif |
|
913 } |
|
914 else if (__INST(audioFormat) == @symbol(S16_BE)) { |
884 # ifdef AFMT_S16_BE |
915 # ifdef AFMT_S16_BE |
885 else if (__INST(audioFormat) == @symbol(S16_BE)) { |
|
886 __format = AFMT_S16_BE; |
916 __format = AFMT_S16_BE; |
887 } |
|
888 # endif |
917 # endif |
|
918 } |
|
919 else if (__INST(audioFormat) == @symbol(S8)) { |
889 # ifdef AFMT_S8 |
920 # ifdef AFMT_S8 |
890 else if (__INST(audioFormat) == @symbol(S8)) { |
|
891 __format = AFMT_S8; |
921 __format = AFMT_S8; |
892 } |
|
893 # endif |
922 # endif |
|
923 } |
|
924 else if (__INST(audioFormat) == @symbol(U16_LE)) { |
894 # ifdef AFMT_U16_LE |
925 # ifdef AFMT_U16_LE |
895 else if (__INST(audioFormat) == @symbol(U16_LE)) { |
|
896 __format = AFMT_U16_LE; |
926 __format = AFMT_U16_LE; |
897 } |
|
898 # endif |
927 # endif |
|
928 } |
|
929 else if (__INST(audioFormat) == @symbol(U16_BE)) { |
899 # ifdef AFMT_U16_BE |
930 # ifdef AFMT_U16_BE |
900 else if (__INST(audioFormat) == @symbol(U16_BE)) { |
|
901 __format = AFMT_U16_BE; |
931 __format = AFMT_U16_BE; |
902 } |
|
903 # endif |
932 # endif |
|
933 } |
|
934 else if (__INST(audioFormat) == @symbol(MPEG)) { |
904 # ifdef AFMT_MPEG |
935 # ifdef AFMT_MPEG |
905 else if (__INST(audioFormat) == @symbol(MPEG)) { |
|
906 __format = AFMT_MPEG; |
936 __format = AFMT_MPEG; |
907 } |
|
908 # endif |
937 # endif |
909 else { |
|
910 __format = -1; |
|
911 } |
938 } |
912 |
939 |
913 #if defined(DEV_AUDIO) |
940 #if defined(DEV_AUDIO) |
914 channels = nil; |
941 channels = nil; |
915 blockSize = nil; |
942 blockSize = nil; |
1569 t_pDirectSound = __DirectSoundVal(oDirectSound); |
1594 t_pDirectSound = __DirectSoundVal(oDirectSound); |
1570 if (t_pDirectSound) { |
1595 if (t_pDirectSound) { |
1571 IDirectSound_Release(t_pDirectSound); |
1596 IDirectSound_Release(t_pDirectSound); |
1572 } |
1597 } |
1573 } |
1598 } |
1574 # else |
1599 RETURN (self); |
|
1600 #endif /* WIN32_DIRECTSOUND */ |
|
1601 |
|
1602 #ifdef WIN32_WAVE |
1575 struct buf *bp, *next; |
1603 struct buf *bp, *next; |
1576 int r; |
1604 int r; |
1577 HWAVEOUT t_waveHandle; |
1605 HWAVEOUT t_waveHandle; |
1578 OBJ oWaveHandle; |
1606 OBJ oWaveHandle; |
1579 |
1607 |
1580 if ((oWaveHandle = __INST(waveHandle)) != nil) { |
1608 if ((oWaveHandle = __INST(waveHandle)) != nil) { |
1581 t_waveHandle = __WaveHandleVal(oWaveHandle); |
1609 t_waveHandle = __WaveHandleVal(oWaveHandle); |
1582 |
1610 |
1583 # ifdef NO_WAIT_IN_CLOSE |
1611 # ifdef NO_WAIT_IN_CLOSE |
1584 /* Force cancellation of any pending buffers */ |
1612 /* Force cancellation of any pending buffers */ |
1585 (void)waveOutReset(t_waveHandle); |
1613 (void)waveOutReset(t_waveHandle); |
1586 # endif |
1614 # endif |
1587 |
1615 |
1588 /* Wait until all pending buffers have been freed */ |
1616 /* Wait until all pending buffers have been freed */ |
1589 while (free_buffers < total_buffers) { |
1617 while (free_buffers < total_buffers) { |
1590 WaitForSingleObject(free_buffer_event, INFINITE); |
1618 WaitForSingleObject(free_buffer_event, INFINITE); |
1591 } |
1619 } |
1592 |
1620 |
1593 # ifndef NO_WAIT_IN_CLOSE |
1621 # ifndef NO_WAIT_IN_CLOSE |
1594 /* Force cancellation of any pending buffers */ |
1622 /* Force cancellation of any pending buffers */ |
1595 (void)waveOutReset(t_waveHandle); |
1623 (void)waveOutReset(t_waveHandle); |
1596 # endif |
1624 # endif |
1597 |
1625 |
1598 /* Close the device */ |
1626 /* Close the device */ |
1599 if ((r = waveOutClose(t_waveHandle)) != 0) { |
1627 if ((r = waveOutClose(t_waveHandle)) != 0) { |
1600 printf("waveOutClose\n"); |
1628 printf("waveOutClose\n"); |
1601 RETURN(self); |
1629 RETURN(self); |
1832 } |
1858 } |
1833 } |
1859 } |
1834 } |
1860 } |
1835 } |
1861 } |
1836 } |
1862 } |
1837 #endif /* SGI_AUDIO */ |
1863 #endif /* IRIS_AUDIO */ |
1838 |
1864 |
1839 #ifdef WIN32 |
1865 #ifdef WIN32_DIRECTSOUND |
1840 # ifdef USE_DIRECTSOUND |
|
1841 { |
1866 { |
1842 HRESULT hr; |
1867 HRESULT hr; |
1843 DWORD status; |
1868 DWORD status; |
1844 LPVOID lpbuf1 = NULL; |
1869 LPVOID lpbuf1 = NULL; |
1845 LPVOID lpbuf2 = NULL; |
1870 LPVOID lpbuf2 = NULL; |
1846 DWORD dwsize1 = 0; |
1871 DWORD dwsize1 = 0; |
1847 DWORD dwsize2 = 0; |
1872 DWORD dwsize2 = 0; |
1848 DWORD playPos, safePos, endWrite; |
1873 DWORD playPos, safePos, endWrite; |
1849 DWORD millis; |
1874 DWORD millis; |
1850 OBJ oDirectSound, oDSBuffer; |
1875 OBJ oDirectSound, oDSBuffer; |
1851 LPDIRECTSOUND t_pDirectSound = (LPDIRECTSOUND)0; |
1876 LPDIRECTSOUND t_pDirectSound = (LPDIRECTSOUND)0; |
1852 LPDIRECTSOUNDBUFFER t_pDSBuffer = (LPDIRECTSOUNDBUFFER)0; |
1877 LPDIRECTSOUNDBUFFER t_pDSBuffer = (LPDIRECTSOUNDBUFFER)0; |
1853 int t_cbBufOffset, t_cbBufSize; |
1878 int t_cbBufOffset, t_cbBufSize; |
1854 short *buf; |
1879 short *buf; |
1855 int cnt, offs; |
1880 int cnt, offs; |
1856 |
1881 |
1857 if ((oDSBuffer = __INST(pDSBuffer)) != nil) { |
1882 if ((oDSBuffer = __INST(pDSBuffer)) != nil) { |
1858 t_pDSBuffer = __DSBufferVal(oDSBuffer); |
1883 t_pDSBuffer = __DSBufferVal(oDSBuffer); |
1859 } |
1884 } |
1860 if ((oDirectSound = __INST(pDirectSound)) != nil) { |
1885 if ((oDirectSound = __INST(pDirectSound)) != nil) { |
1861 t_pDirectSound = __DirectSoundVal(oDirectSound); |
1886 t_pDirectSound = __DirectSoundVal(oDirectSound); |
1862 } |
1887 } |
1863 |
1888 |
1864 if (!t_pDSBuffer || !t_pDirectSound) { |
1889 if (!t_pDSBuffer || !t_pDirectSound) { |
1865 fprintf(stderr, "SoundStream not open!\n"); |
1890 fprintf(stderr, "SoundStream not open!\n"); |
1866 RETURN (0); |
1891 RETURN (0); |
1867 } |
1892 } |
1868 t_cbBufOffset = __intVal(__INST(bufferOffset)); |
1893 t_cbBufOffset = __intVal(__INST(bufferOffset)); |
1869 t_cbBufSize = __intVal(__INST(bufferSize)); |
1894 t_cbBufSize = __intVal(__INST(bufferSize)); |
1870 |
1895 |
1871 cnt = __intVal(count); |
1896 cnt = __intVal(count); |
1872 offs = __intVal(start) - 1; |
1897 offs = __intVal(start) - 1; |
1873 buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs; |
1898 buf = (short *)__InstPtr(anObject) + OHDR_SIZE + offs; |
1874 |
1899 |
1875 // Should be playing, right? |
1900 // Should be playing, right? |
1876 hr = IDirectSoundBuffer_GetStatus(t_pDSBuffer, &status ); |
1901 hr = IDirectSoundBuffer_GetStatus(t_pDSBuffer, &status ); |
1877 if (!(status && DSBSTATUS_PLAYING)) { |
1902 if (!(status && DSBSTATUS_PLAYING)) { |
1878 fprintf(stderr, "Buffer not playing!\n"); |
1903 fprintf(stderr, "Buffer not playing!\n"); |
1879 RETURN (0); |
1904 RETURN (0); |
1880 } |
1905 } |
1881 |
1906 |
1882 // Sleep until we have enough room in buffer. |
1907 // Sleep until we have enough room in buffer. |
1883 hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos ); |
1908 hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos ); |
1884 if( hr != DS_OK ) { |
1909 if( hr != DS_OK ) { |
1885 fprintf(stderr, "Cannot get position!\n"); |
1910 fprintf(stderr, "Cannot get position!\n"); |
1886 RETURN (0); |
1911 RETURN (0); |
1887 } |
1912 } |
1888 if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; |
1913 if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; |
1889 |
1914 |
1890 endWrite = t_cbBufOffset + (cnt * sizeof(short)); |
1915 endWrite = t_cbBufOffset + (cnt * sizeof(short)); |
1891 while ( playPos < endWrite ) { |
1916 while ( playPos < endWrite ) { |
1892 // Calculate number of milliseconds until we will have room, as |
1917 // Calculate number of milliseconds until we will have room, as |
1893 // time = distance * (milliseconds/second) / ((bytes/sample) * (samples/second)), |
1918 // time = distance * (milliseconds/second) / ((bytes/sample) * (samples/second)), |
1894 // rounded up. |
1919 // rounded up. |
1895 millis = (DWORD) (1.0 + ((endWrite - playPos) * 1000.0) / ( sizeof(short) * __intVal(__INST(sampleRate)))); |
1920 millis = (DWORD) (1.0 + ((endWrite - playPos) * 1000.0) / ( sizeof(short) * __intVal(__INST(sampleRate)))); |
1896 |
1921 |
1897 // Sleep for that long |
1922 // Sleep for that long |
1898 Sleep( millis ); |
1923 Sleep( millis ); |
1899 |
1924 |
1900 // Wake up, find out where we are now |
1925 // Wake up, find out where we are now |
1901 hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos ); |
1926 hr = IDirectSoundBuffer_GetCurrentPosition(t_pDSBuffer, &playPos, &safePos ); |
1902 if( hr != DS_OK ) { |
1927 if( hr != DS_OK ) { |
1903 fprintf(stderr, "Cannot get position!\n"); |
1928 fprintf(stderr, "Cannot get position!\n"); |
1904 RETURN (0); |
1929 RETURN (0); |
1905 } |
1930 } |
1906 if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; // unwrap offset |
1931 if( playPos < t_cbBufOffset ) playPos += t_cbBufSize; // unwrap offset |
1907 } |
1932 } |
1908 |
1933 |
1909 // Lock free space in the DS |
1934 // Lock free space in the DS |
1910 hr = IDirectSoundBuffer_Lock(t_pDSBuffer, t_cbBufOffset, cnt * sizeof(short), &lpbuf1, &dwsize1, &lpbuf2, &dwsize2, 0); |
1935 hr = IDirectSoundBuffer_Lock(t_pDSBuffer, t_cbBufOffset, cnt * sizeof(short), &lpbuf1, &dwsize1, &lpbuf2, &dwsize2, 0); |
1911 if (hr == DS_OK) { |
1936 if (hr == DS_OK) { |
1912 // Copy the buffer into the DS |
1937 // Copy the buffer into the DS |
1913 CopyMemory(lpbuf1, buf, dwsize1); |
1938 CopyMemory(lpbuf1, buf, dwsize1); |
1914 if(NULL != lpbuf2) CopyMemory(lpbuf2, buf+dwsize1, dwsize2); |
1939 if(NULL != lpbuf2) CopyMemory(lpbuf2, buf+dwsize1, dwsize2); |
1915 |
1940 |
1916 // Update our buffer offset and unlock sound buffer |
1941 // Update our buffer offset and unlock sound buffer |
1917 t_cbBufOffset = (t_cbBufOffset + dwsize1 + dwsize2) % t_cbBufSize; |
1942 t_cbBufOffset = (t_cbBufOffset + dwsize1 + dwsize2) % t_cbBufSize; |
1918 IDirectSoundBuffer_Unlock(t_pDSBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2); |
1943 IDirectSoundBuffer_Unlock(t_pDSBuffer, lpbuf1, dwsize1, lpbuf2, dwsize2); |
1919 } |
1944 } |
1920 __INST(buffferOffset) = __MKSMALLINT(t_cbBufOffset); |
1945 __INST(buffferOffset) = __MKSMALLINT(t_cbBufOffset); |
1921 |
1946 |
1922 RETURN (count); |
1947 RETURN (count); |
1923 } |
1948 } |
1924 # else |
1949 #endif /* WIN32_DIRECTSOUND */ |
|
1950 |
|
1951 #ifdef WIN32_WAVE |
1925 { |
1952 { |
1926 struct buf *bp; |
1953 struct buf *bp; |
1927 int len, i, r; |
1954 int len, i, r; |
1928 int dataLen, offs; |
1955 int dataLen, offs; |
1929 char *buf; |
1956 char *buf; |
2310 for (i = 0; i < DATALEN; i++) { |
2336 for (i = 0; i < DATALEN; i++) { |
2311 null[i] = 127; |
2337 null[i] = 127; |
2312 } |
2338 } |
2313 audioWrite(null, DATALEN); |
2339 audioWrite(null, DATALEN); |
2314 } |
2340 } |
2315 #endif /* 0 */ |
2341 # endif /* 0 */ |
2316 ok = true; |
2342 ok = true; |
2317 goto out; |
2343 goto out; |
2318 } |
2344 } |
2319 # endif /* !USE_DIRECTSOUND */ |
2345 #endif /* !WIN32_DIRECTSOUND */ |
2320 #endif /* WIN32 */ |
|
2321 |
2346 |
2322 #ifdef DEV_AUDIO |
2347 #ifdef DEV_AUDIO |
2323 { |
2348 { |
2324 int __fd; |
2349 int __fd; |
2325 int __mode; |
2350 int __mode; |
2326 FILE *f; |
2351 FILE *f; |
2327 |
2352 |
2328 if (strcmp(__stringVal(aMode), "w") == 0) { |
2353 if (strcmp(__stringVal(aMode), "w") == 0) { |
2329 __mode = O_WRONLY; |
2354 __mode = O_WRONLY; |
2330 } else if (strcmp(__stringVal(aMode), "r") == 0) { |
2355 } else if (strcmp(__stringVal(aMode), "r") == 0) { |
2331 __mode = O_RDONLY; |
2356 __mode = O_RDONLY; |
2332 } else { |
2357 } else { |
2333 __mode = O_RDWR; |
2358 __mode = O_RDWR; |
2334 } |
2359 } |
2335 do { |
2360 do { |
2336 __BEGIN_INTERRUPTABLE__ |
2361 __BEGIN_INTERRUPTABLE__ |
2337 __fd = open((char *) __stringVal(__INST(pathName)), __mode /* |O_NDELAY */); |
2362 __fd = open((char *) __stringVal(__INST(pathName)), __mode /* |O_NDELAY */); |
2338 __END_INTERRUPTABLE__ |
2363 __END_INTERRUPTABLE__ |
2339 } while ((__fd < 0) && (__threadErrno == EINTR)); |
2364 } while ((__fd < 0) && (__threadErrno == EINTR)); |
2340 |
2365 |
2341 if (__fd >= 0) { |
2366 if (__fd >= 0) { |
2342 /* |
2367 /* |
2343 * make it a FILE * |
2368 * make it a FILE * |
2344 */ |
2369 */ |
2345 f = fdopen(__fd, __stringVal(aMode)); |
2370 f = fdopen(__fd, __stringVal(aMode)); |
2346 if (! f) { |
2371 if (! f) { |
2347 __BEGIN_INTERRUPTABLE__ |
2372 __BEGIN_INTERRUPTABLE__ |
2348 close(__fd); |
2373 close(__fd); |
2349 __END_INTERRUPTABLE__ |
2374 __END_INTERRUPTABLE__ |
2350 ok = false; |
2375 ok = false; |
2351 goto out; |
2376 goto out; |
2352 } |
2377 } |
2353 setbuf(f, NULL); |
2378 setbuf(f, NULL); |
2354 __INST(buffered) = false; |
2379 __INST(buffered) = false; |
2355 __INST(filePointer) = __MKOBJ(f); |
2380 __INST(filePointer) = __MKOBJ(f); |
2356 __STORESELF(filePointer); |
2381 __STORESELF(filePointer); |
2357 |
2382 |
2358 #if defined(PCM_ENABLE_OUTPUT) && defined(PCM_ENABLE_INPUT) |
2383 #if defined(PCM_ENABLE_OUTPUT) && defined(PCM_ENABLE_INPUT) |
2359 # if defined(SNDCTL_DSP_SETTRIGGER) |
2384 # if defined(SNDCTL_DSP_SETTRIGGER) |
2360 if (__mode == O_RDWR) { |
2385 if (__mode == O_RDWR) { |
2361 int enable_bits = ~(PCM_ENABLE_OUTPUT|PCM_ENABLE_INPUT); |
2386 int enable_bits = ~(PCM_ENABLE_OUTPUT|PCM_ENABLE_INPUT); |
2362 |
2387 |
2363 if (ioctl(__fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) == -1) |
2388 if (ioctl(__fd, SNDCTL_DSP_SETTRIGGER, &enable_bits) == -1) |
2364 { |
2389 { |
2365 fprintf(stderr, "can't request synchronous start of fullduplex operation"); |
2390 fprintf(stderr, "can't request synchronous start of fullduplex operation"); |
2366 } |
2391 } |
2367 } |
2392 } |
2368 # endif |
2393 # endif |
2369 #endif |
2394 #endif |
2370 ok = true; |
2395 ok = true; |
2371 goto out; |
2396 goto out; |
2372 } |
2397 } |
2373 } |
2398 } |
2374 |
|
2375 #endif /* DEV_AUDIO */ |
2399 #endif /* DEV_AUDIO */ |
|
2400 |
2376 out:; |
2401 out:; |
2377 %}. |
2402 %}. |
2378 ok == false ifTrue:[ |
2403 ok == false ifTrue:[ |
2379 self openError. |
2404 self openError. |
2380 "not reached" |
2405 "not reached" |