History

crude openbsd+openal port

Sigrid Solveig Haflínudóttir committed 3 years ago

Commit 3ce12951 parent 37c074716 files · +731 −101Browse files

Showing the changes to src (16 of 16 files). Show all

Unified · Split

16 files
  1. src/core/chuck_errmsg.h +1 −0
  2. src/core/chuck_shell.cpp +1 −1
  3. src/core/lo/config.h +1 −1
  4. src/core/lo/server.c +1 −1
  5. src/core/makefile +9 −5
  6. src/core/makefile.x/makefile.openal +10 −0
  7. src/core/rtmidi.cpp +1 −1
  8. src/core/ugen_stk.cpp +70 −70
  9. src/core/ugen_stk.h +3 −3
  10. src/core/util_hid.cpp +160 −0
  11. src/core/util_string.cpp +13 −0
  12. src/core/util_thread.cpp +10 −10
  13. src/core/util_thread.h +2 −2
  14. src/host/chuck_audio.h +3 −0
  15. src/host/chuck_audio_openal.cpp +430 −0
  16. src/makefile +16 −7
src/core/chuck_errmsg.h+1−0
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636
3737 #include "chuck_def.h"
3838 #include <stdio.h>
39+#include <stdarg.h>
3940
4041 #if defined(_cplusplus) || defined(__cplusplus)
4142 extern "C" {
src/core/chuck_shell.cpp+1−1
@@ -600,7 +600,7 @@ void Chuck_Shell::continue_code( string & in ) · 599 unmodified lines
600600 void Chuck_Shell::do_code( string & code, string & out, string command )
601601 {
602602 // open a temporary file
603−#if defined(__PLATFORM_LINUX__) || defined(__MACOSX_CORE__)
603+#if defined(__PLATFORM_LINUX__) || defined(__MACOSX_CORE__) || defined(__PLATFORM_OPENBSD__)
604604 char tmp_dir[] = "/tmp";
605605 char * tmp_filepath = new char [32];
606606 // 1.4.1.0: changed chuck_file.XXXXXX to chuck_shell.XXXXXX
src/core/lo/config.h+1−1
@@ -1,6 +1,6 @@
11
22
3−#if defined(__MACOSX_CORE__) || defined(__PLATFORM_LINUX__)
3+#if defined(__MACOSX_CORE__) || defined(__PLATFORM_LINUX__) || defined(__PLATFORM_OPENBSD__)
44
55 /* config.h. Generated from config.h.in by configure. */
66 /* config.h.in. Generated from configure.ac by autoheader. */
src/core/lo/server.c+1−1
@@ -268,7 +268,7 @@ lo_server lo_server_new_with_proto_internal(const char *group, · 267 unmodified lines
268268 if (!port) {
269269 /* not a good way to get random numbers, but its not critical */
270270 snprintf(pnum, 15, "%ld", 10000 + ((unsigned int)rand() +
271− time(NULL)) % 10000);
271+ (long)time(NULL)) % 10000);
272272 }
273273
274274 if ((ret = getaddrinfo(NULL, service, &hints, &ai))) {
src/core/makefile+9−5
@@ -2,19 +2,19 @@ · 1 unmodified line
22 current:
33 @echo "[chuck build]: please use one of the following configurations:"
44 @echo " make linux-alsa, make linux-jack, make linux-pulse, linux-all,"
5− @echo " make mac, make mac-ub, make cygwin, or make win32"
5+ @echo " openbsd-openal, make mac, make mac-ub, make cygwin, or make win32"
66
77 .PHONY: mac mac-ub osx linux-all linux linux-pulse linux-jack linux-alsa cygwin osx-rl test
8−mac mac-ub osx linux-all linux linux-pulse linux-jack linux-alsa cygwin osx-rl: chuck-core
8+mac mac-ub osx linux-all linux linux-pulse linux-jack linux-alsa cygwin osx-rl openbsd-openal: chuck-core
99
1010 win32:
1111 make -f makefile.win32
1212
1313 LEX=flex
1414 YACC=bison
15−CC=gcc
16−CXX=g++
17−LD=g++
15+CC?=gcc
16+CXX?=g++
17+LD?=g++
1818
1919 CFLAGS+=-I. -Ilo
2020
@@ -64,6 +64,10 @@ ifneq (,$(strip $(filter linux-alsa,$(MAKECMDGOALS)))) · 43 unmodified lines
6464 include makefile.x/makefile.alsa
6565 endif
6666
67+ifneq (,$(strip $(filter openbsd-openal,$(MAKECMDGOALS))))
68+include makefile.x/makefile.openal
69+endif
70+
6771 ifneq (,$(strip $(filter cygwin,$(MAKECMDGOALS))))
6872 include makefile.x/makefile.cygwin
6973 endif
src/core/makefile.x/makefile.openal+10−0
@@ -0,0 +1,10 @@
1+CFLAGS+=-D__OPENBSD_OPENAL__ -D__PLATFORM_OPENBSD__ -fno-strict-aliasing -D__CK_SNDFILE_NATIVE__ -DMAX_PATH=4096 -D_DEFAULT_SOURCE $(shell pkg-config --cflags openal)
2+
3+ifneq ($(CHUCK_DEBUG),)
4+CFLAGS+= -ggdb
5+else
6+CFLAGS+= -O3
7+endif
8+
9+LDFLAGS+=$(shell pkg-config --libs openal) -lm -lsndfile -lpthread
10+LD=$(CXX)
src/core/rtmidi.cpp+1−1
@@ -2235,7 +2235,7 @@ void RtMidiOut :: sendMessage( std::vector<unsigned char> *message ) · 2234 unmodified lines
22352235 #endif // __WINDOWS_MM__
22362236
22372237
2238−#if defined(__LINUX_OSS__) // dummy
2238+#if defined(__LINUX_OSS__) || defined(__OPENBSD_OPENAL__) // dummy
22392239
22402240 /*void midiInputCallback( const MIDIPacketList *list, void *procRef, void *srcRef )
22412241 {
src/core/ugen_stk.cpp+70−70
@@ -16163,7 +16163,7 @@ void Stk :: setRawwavePath(std::string newPath) · 16162 unmodified lines
1616316163 rawwavepath += "/";
1616416164 }
1616516165
16166−void Stk :: swap16(unsigned char *ptr)
16166+void Stk :: swapb16(unsigned char *ptr)
1616716167 {
1616816168 /* register */ unsigned char val;
1616916169
@@ -16173,7 +16173,7 @@ void Stk :: swap16(unsigned char *ptr) · 3 unmodified lines
1617316173 *(ptr+1) = val;
1617416174 }
1617516175
16176−void Stk :: swap32(unsigned char *ptr)
16176+void Stk :: swapb32(unsigned char *ptr)
1617716177 {
1617816178 /* register */ unsigned char val;
1617916179
@@ -16189,7 +16189,7 @@ void Stk :: swap32(unsigned char *ptr) · 9 unmodified lines
1618916189 *(ptr+1) = val;
1619016190 }
1619116191
16192−void Stk :: swap64(unsigned char *ptr)
16192+void Stk :: swapb64(unsigned char *ptr)
1619316193 {
1619416194 /* register */ unsigned char val;
1619516195
@@ -16367,7 +16367,7 @@ Table :: Table(char *fileName) · 171 unmodified lines
1636716367 double temp;
1636816368 while ( fread(&temp, 8, 1, fd) ) {
1636916369 if( little_endian )
16370− swap64((unsigned char *)&temp);
16370+ swapb64((unsigned char *)&temp);
1637116371
1637216372 data[i++] = (MY_FLOAT) temp;
1637316373 }
@@ -18307,7 +18307,7 @@ bool WvIn :: getWavInfo( const char *fileName ) · 1933 unmodified lines
1830718307 while ( strncmp(id, "fmt ", 4) ) {
1830818308 if ( fread(&chunkSize, 4, 1, fd) != 1 ) goto error;
1830918309 if( !little_endian )
18310− swap32((unsigned char *)&chunkSize);
18310+ swapb32((unsigned char *)&chunkSize);
1831118311
1831218312 if ( fseek(fd, chunkSize, SEEK_CUR) == -1 ) goto error;
1831318313 if ( fread(&id, 4, 1, fd) != 1 ) goto error;
@@ -18319,8 +18319,8 @@ if( !little_endian ) · 5 unmodified lines
1831918319 if ( fread(&format_tag, 2, 1, fd) != 1 ) goto error;
1832018320 if( !little_endian )
1832118321 {
18322− swap16((unsigned char *)&format_tag);
18323− swap32((unsigned char *)&chunkSize);
18322+ swapb16((unsigned char *)&format_tag);
18323+ swapb32((unsigned char *)&chunkSize);
1832418324 }
1832518325 if (format_tag != 1 && format_tag != 3 ) { // PCM = 1, FLOAT = 3
1832618326 snprintf(msg, STK_MSG_BUF_LENGTH, "[chuck](via WvIn): %s contains an unsupported data format type (%d).", fileName, format_tag);
@@ -18331,7 +18331,7 @@ if( !little_endian ) · 4 unmodified lines
1833118331 SINT16 temp;
1833218332 if ( fread(&temp, 2, 1, fd) != 1 ) goto error;
1833318333 if( !little_endian )
18334− swap16((unsigned char *)&temp);
18334+ swapb16((unsigned char *)&temp);
1833518335
1833618336 channels = (unsigned int ) temp;
1833718337
@@ -18339,7 +18339,7 @@ if( !little_endian ) · 1 unmodified line
1833918339 SINT32 theSrate;
1834018340 if ( fread(&theSrate, 4, 1, fd) != 1 ) goto error;
1834118341 if( !little_endian )
18342− swap32((unsigned char *)&theSrate);
18342+ swapb32((unsigned char *)&theSrate);
1834318343
1834418344 fileRate = (MY_FLOAT)theSrate;
1834518345
@@ -18351,7 +18351,7 @@ if( !little_endian ) · 5 unmodified lines
1835118351 if ( fseek(fd, 6, SEEK_CUR) == -1 ) goto error; // Locate bits_per_sample info.
1835218352 if ( fread(&temp, 2, 1, fd) != 1 ) goto error;
1835318353 if( !little_endian )
18354− swap16((unsigned char *)&temp);
18354+ swapb16((unsigned char *)&temp);
1835518355
1835618356 if ( format_tag == 1 ) {
1835718357 if (temp == 8)
@@ -18383,7 +18383,7 @@ if( !little_endian ) · 25 unmodified lines
1838318383 while ( strncmp(id, "data", 4) ) {
1838418384 if ( fread(&chunkSize, 4, 1, fd) != 1 ) goto error;
1838518385 if( !little_endian )
18386− swap32((unsigned char *)&chunkSize);
18386+ swapb32((unsigned char *)&chunkSize);
1838718387
1838818388 if ( fseek(fd, chunkSize, SEEK_CUR) == -1 ) goto error;
1838918389 if ( fread(&id, 4, 1, fd) != 1 ) goto error;
@@ -18393,7 +18393,7 @@ if( !little_endian ) · 3 unmodified lines
1839318393 SINT32 bytes;
1839418394 if ( fread(&bytes, 4, 1, fd) != 1 ) goto error;
1839518395 if( !little_endian )
18396− swap32((unsigned char *)&bytes);
18396+ swapb32((unsigned char *)&bytes);
1839718397
1839818398 fileSize = 8 * bytes / temp / channels; // sample frames
1839918399 bufferSize = fileSize;
@@ -18421,7 +18421,7 @@ bool WvIn :: getSndInfo( const char *fileName ) · 21 unmodified lines
1842118421 if ( fseek(fd, 12, SEEK_SET) == -1 ) goto error; // Locate format
1842218422 if ( fread(&format, 4, 1, fd) != 1 ) goto error;
1842318423 if( little_endian )
18424− swap32((unsigned char *)&format);
18424+ swapb32((unsigned char *)&format);
1842518425
1842618426 if (format == 2) dataType = STK_SINT8;
1842718427 else if (format == 3) dataType = STK_SINT16;
@@ -18438,7 +18438,7 @@ if( little_endian ) · 10 unmodified lines
1843818438 SINT32 theSrate;
1843918439 if ( fread(&theSrate, 4, 1, fd) != 1 ) goto error;
1844018440 if( little_endian )
18441− swap32((unsigned char *)&theSrate);
18441+ swapb32((unsigned char *)&theSrate);
1844218442
1844318443 fileRate = (MY_FLOAT)theSrate;
1844418444
@@ -18449,19 +18449,19 @@ if( little_endian ) · 4 unmodified lines
1844918449 SINT32 chans;
1845018450 if ( fread(&chans, 4, 1, fd) != 1 ) goto error;
1845118451 if( little_endian )
18452− swap32((unsigned char *)&chans);
18452+ swapb32((unsigned char *)&chans);
1845318453
1845418454 channels = chans;
1845518455
1845618456 if ( fseek(fd, 4, SEEK_SET) == -1 ) goto error;
1845718457 if ( fread(&dataOffset, 4, 1, fd) != 1 ) goto error;
1845818458 if( little_endian )
18459− swap32((unsigned char *)&dataOffset);
18459+ swapb32((unsigned char *)&dataOffset);
1846018460
1846118461 // Get length of data from the header.
1846218462 if ( fread(&fileSize, 4, 1, fd) != 1 ) goto error;
1846318463 if( little_endian )
18464− swap32((unsigned char *)&fileSize);
18464+ swapb32((unsigned char *)&fileSize);
1846518465
1846618466 fileSize /= 2 * channels; // Convert to sample frames.
1846718467 bufferSize = fileSize;
@@ -18497,7 +18497,7 @@ bool WvIn :: getAifInfo( const char *fileName ) · 29 unmodified lines
1849718497 while ( strncmp(id, "COMM", 4) ) {
1849818498 if ( fread(&chunkSize, 4, 1, fd) != 1 ) goto error;
1849918499 if( little_endian )
18500− swap32((unsigned char *)&chunkSize);
18500+ swapb32((unsigned char *)&chunkSize);
1850118501
1850218502 if ( fseek(fd, chunkSize, SEEK_CUR) == -1 ) goto error;
1850318503 if ( fread(&id, 4, 1, fd) != 1 ) goto error;
@@ -18508,7 +18508,7 @@ if( little_endian ) · 4 unmodified lines
1850818508 if ( fseek(fd, 4, SEEK_CUR) == -1 ) goto error; // Jump over chunk size
1850918509 if ( fread(&temp, 2, 1, fd) != 1 ) goto error;
1851018510 if( little_endian )
18511− swap16((unsigned char *)&temp);
18511+ swapb16((unsigned char *)&temp);
1851218512
1851318513 channels = temp;
1851418514
@@ -18516,7 +18516,7 @@ if( little_endian ) · 1 unmodified line
1851618516 SINT32 frames;
1851718517 if ( fread(&frames, 4, 1, fd) != 1 ) goto error;
1851818518 if( little_endian )
18519− swap32((unsigned char *)&frames);
18519+ swapb32((unsigned char *)&frames);
1852018520
1852118521 fileSize = frames; // sample frames
1852218522 bufferSize = fileSize;
@@ -18528,7 +18528,7 @@ if( little_endian ) · 5 unmodified lines
1852818528 // Read the number of bits per sample.
1852918529 if ( fread(&temp, 2, 1, fd) != 1 ) goto error;
1853018530 if( little_endian )
18531− swap16((unsigned char *)&temp);
18531+ swapb16((unsigned char *)&temp);
1853218532
1853318533 // Get file sample rate from the header. For AIFF files, this value
1853418534 // is stored in a 10-byte, IEEE Standard 754 floating point number,
@@ -18540,7 +18540,7 @@ if( little_endian ) · 5 unmodified lines
1854018540 if ( fread(&theSrate, 10, 1, fd) != 1 ) goto error;
1854118541 mantissa = (unsigned long) *(unsigned long *)(theSrate+2);
1854218542 if( little_endian )
18543− swap32((unsigned char *)&mantissa);
18543+ swapb32((unsigned char *)&mantissa);
1854418544
1854518545 exp = 30 - *(theSrate+1);
1854618546 last = 0;
@@ -18580,7 +18580,7 @@ if( little_endian ) · 33 unmodified lines
1858018580 while ( strncmp(id, "SSND", 4) ) {
1858118581 if ( fread(&chunkSize, 4, 1, fd) != 1 ) goto error;
1858218582 if( little_endian )
18583− swap32((unsigned char *)&chunkSize);
18583+ swapb32((unsigned char *)&chunkSize);
1858418584
1858518585 if ( fseek(fd, chunkSize, SEEK_CUR) == -1 ) goto error;
1858618586 if ( fread(&id, 4, 1, fd) != 1 ) goto error;
@@ -18637,7 +18637,7 @@ else · 50 unmodified lines
1863718637 // Check the data element type
1863818638 SINT32 datatype;
1863918639 if ( fread(&datatype, 4, 1, fd) != 1 ) goto error;
18640− if ( byteswap ) swap32((unsigned char *)&datatype);
18640+ if ( byteswap ) swapb32((unsigned char *)&datatype);
1864118641 if (datatype != 14) {
1864218642 snprintf(msg, STK_MSG_BUF_LENGTH, "[chuck](via WvIn): The file does not contain a single Matlab array (or matrix) data element.");
1864318643 return false;
@@ -18648,10 +18648,10 @@ else · 4 unmodified lines
1864818648 SINT32 size;
1864918649 if ( fseek(fd, 168, SEEK_SET) == -1 ) goto error;
1865018650 if ( fread(&tmp, 4, 1, fd) != 1 ) goto error;
18651− if (byteswap) swap32((unsigned char *)&tmp);
18651+ if (byteswap) swapb32((unsigned char *)&tmp);
1865218652 if (tmp == 1) { // array name > 4 characters
1865318653 if ( fread(&tmp, 4, 1, fd) != 1 ) goto error; // get array name length
18654− if (byteswap) swap32((unsigned char *)&tmp);
18654+ if (byteswap) swapb32((unsigned char *)&tmp);
1865518655 size = (SINT32) ceil((float)tmp / 8);
1865618656 if ( fseek(fd, size*8, SEEK_CUR) == -1 ) goto error; // jump over array name
1865718657 }
@@ -18659,7 +18659,7 @@ else · 1 unmodified line
1865918659 if ( fseek(fd, 4, SEEK_CUR) == -1 ) goto error;
1866018660 }
1866118661 if ( fread(&tmp, 4, 1, fd) != 1 ) goto error;
18662− if (byteswap) swap32((unsigned char *)&tmp);
18662+ if (byteswap) swapb32((unsigned char *)&tmp);
1866318663 if ( tmp == 1 ) dataType = STK_SINT8;
1866418664 else if ( tmp == 3 ) dataType = STK_SINT16;
1866518665 // NOTE: MAT file format does not appear to support 24-bit | 1.5.0.1 (ge)
@@ -18675,12 +18675,12 @@ else · 9 unmodified lines
1867518675 SINT32 rows;
1867618676 if ( fseek(fd, 160, SEEK_SET) == -1 ) goto error;
1867718677 if ( fread(&rows, 4, 1, fd) != 1 ) goto error;
18678− if (byteswap) swap32((unsigned char *)&rows);
18678+ if (byteswap) swapb32((unsigned char *)&rows);
1867918679
1868018680 // Get number of columns from the header.
1868118681 SINT32 columns;
1868218682 if ( fread(&columns,4, 1, fd) != 1 ) goto error;
18683− if (byteswap) swap32((unsigned char *)&columns);
18683+ if (byteswap) swapb32((unsigned char *)&columns);
1868418684
1868518685 // Assume channels = smaller of rows or columns.
1868618686 if (rows < columns) {
@@ -18701,7 +18701,7 @@ else · 14 unmodified lines
1870118701 SINT32 headsize;
1870218702 if ( fseek(fd, 132, SEEK_SET) == -1 ) goto error;
1870318703 if ( fread(&headsize, 4, 1, fd) != 1 ) goto error; // file size from 132nd byte
18704− if (byteswap) swap32((unsigned char *)&headsize);
18704+ if (byteswap) swapb32((unsigned char *)&headsize);
1870518705 headsize -= fileSize * 8 * channels;
1870618706 if ( fseek(fd, headsize, SEEK_CUR) == -1 ) goto error;
1870718707 dataOffset = ftell(fd);
@@ -18756,7 +18756,7 @@ void WvIn :: readData( unsigned long index ) · 48 unmodified lines
1875618756 if ( byteswap ) {
1875718757 SINT16 *ptr = buf;
1875818758 for (i=length*channels-1; i>=0; i--)
18759− swap16((unsigned char *)(ptr++));
18759+ swapb16((unsigned char *)(ptr++));
1876018760 }
1876118761 for (i=length*channels-1; i>=0; i--)
1876218762 data[i] = buf[i];
@@ -18780,7 +18780,7 @@ void WvIn :: readData( unsigned long index ) · 17 unmodified lines
1878018780 if ( byteswap ) {
1878118781 SINT32 *ptr = buf;
1878218782 for (i=length*channels-1; i>=0; i--)
18783− swap32((unsigned char *)(ptr++));
18783+ swapb32((unsigned char *)(ptr++));
1878418784 }
1878518785 for (i=length*channels-1; i>=0; i--)
1878618786 data[i] = buf[i];
@@ -18792,7 +18792,7 @@ void WvIn :: readData( unsigned long index ) · 5 unmodified lines
1879218792 if ( byteswap ) {
1879318793 FLOAT32 *ptr = buf;
1879418794 for (i=length*channels-1; i>=0; i--)
18795− swap32((unsigned char *)(ptr++));
18795+ swapb32((unsigned char *)(ptr++));
1879618796 }
1879718797 for (i=length*channels-1; i>=0; i--)
1879818798 data[i] = buf[i];
@@ -18804,7 +18804,7 @@ void WvIn :: readData( unsigned long index ) · 5 unmodified lines
1880418804 if ( byteswap ) {
1880518805 FLOAT64 *ptr = buf;
1880618806 for (i=length*channels-1; i>=0; i--)
18807− swap64((unsigned char *)(ptr++));
18807+ swapb64((unsigned char *)(ptr++));
1880818808 }
1880918809 for (i=length*channels-1; i>=0; i--)
1881018810 data[i] = buf[i];
@@ -19392,14 +19392,14 @@ bool WvOut :: setWavFile( const char *fileName ) · 581 unmodified lines
1939219392 if( !little_endian )
1939319393 {
1939419394 byteswap = true;
19395− swap32((unsigned char *)&hdr.file_size);
19396− swap32((unsigned char *)&hdr.chunk_size);
19397− swap16((unsigned char *)&hdr.format_tag);
19398− swap16((unsigned char *)&hdr.num_chans);
19399− swap32((unsigned char *)&hdr.sample_rate);
19400− swap32((unsigned char *)&hdr.bytes_per_sec);
19401− swap16((unsigned char *)&hdr.bytes_per_samp);
19402− swap16((unsigned char *)&hdr.bits_per_samp);
19395+ swapb32((unsigned char *)&hdr.file_size);
19396+ swapb32((unsigned char *)&hdr.chunk_size);
19397+ swapb16((unsigned char *)&hdr.format_tag);
19398+ swapb16((unsigned char *)&hdr.num_chans);
19399+ swapb32((unsigned char *)&hdr.sample_rate);
19400+ swapb32((unsigned char *)&hdr.bytes_per_sec);
19401+ swapb16((unsigned char *)&hdr.bytes_per_samp);
19402+ swapb16((unsigned char *)&hdr.bits_per_samp);
1940319403 }
1940419404
1940519405 if ( fwrite(&hdr, 4, 11, fd) != 11 ) {
@@ -19425,14 +19425,14 @@ void WvOut :: closeWavFile( void ) · 19 unmodified lines
1942519425
1942619426 SINT32 bytes = (SINT32)(totalCount * channels * bytes_per_sample);
1942719427 if( !little_endian )
19428− swap32((unsigned char *)&bytes);
19428+ swapb32((unsigned char *)&bytes);
1942919429
1943019430 fseek(fd, 40, SEEK_SET); // jump to data length
1943119431 fwrite(&bytes, 4, 1, fd);
1943219432
1943319433 bytes = (SINT32)(totalCount * channels * bytes_per_sample + 44);
1943419434 if( !little_endian )
19435− swap32((unsigned char *)&bytes);
19435+ swapb32((unsigned char *)&bytes);
1943619436
1943719437 fseek(fd, 4, SEEK_SET); // jump to file size
1943819438 fwrite(&bytes, 4, 1, fd);
@@ -19470,10 +19470,10 @@ bool WvOut :: setSndFile( const char *fileName ) · 31 unmodified lines
1947019470 if( little_endian )
1947119471 {
1947219472 byteswap = true;
19473− swap32 ((unsigned char *)&hdr.hdr_length);
19474− swap32 ((unsigned char *)&hdr.format);
19475− swap32 ((unsigned char *)&hdr.sample_rate);
19476− swap32 ((unsigned char *)&hdr.num_channels);
19473+ swapb32 ((unsigned char *)&hdr.hdr_length);
19474+ swapb32 ((unsigned char *)&hdr.format);
19475+ swapb32 ((unsigned char *)&hdr.sample_rate);
19476+ swapb32 ((unsigned char *)&hdr.num_channels);
1947719477 }
1947819478
1947919479 if ( fwrite(&hdr, 4, 10, fd) != 10 ) {
@@ -19499,7 +19499,7 @@ void WvOut :: closeSndFile( void ) · 19 unmodified lines
1949919499
1950019500 SINT32 bytes = (SINT32)(totalCount * bytes_per_sample * channels);
1950119501 if( little_endian )
19502− swap32 ((unsigned char *)&bytes);
19502+ swapb32 ((unsigned char *)&bytes);
1950319503
1950419504 fseek(fd, 8, SEEK_SET); // jump to data size
1950519505 fwrite(&bytes, 4, 1, fd);
@@ -19558,7 +19558,7 @@ bool WvOut :: setAifFile( const char *fileName ) · 52 unmodified lines
1955819558 }
1955919559 i += 16383;
1956019560 if( little_endian )
19561− swap16((unsigned char *)&i);
19561+ swapb16((unsigned char *)&i);
1956219562
1956319563 *(SINT16 *)(hdr.srate) = (SINT16) i;
1956419564
@@ -19568,7 +19568,7 @@ if( little_endian ) · 3 unmodified lines
1956819568 }
1956919569
1957019570 if( little_endian )
19571− swap32((unsigned char *)&rate);
19571+ swapb32((unsigned char *)&rate);
1957219572
1957319573 *(unsigned long *)(hdr.srate+2) = (unsigned long) rate;
1957419574
@@ -19576,13 +19576,13 @@ if( little_endian ) · 1 unmodified line
1957619576 if( little_endian )
1957719577 {
1957819578 byteswap = true;
19579− swap32((unsigned char *)&hdr.form_size);
19580− swap32((unsigned char *)&hdr.comm_size);
19581− swap16((unsigned char *)&hdr.num_chans);
19582− swap16((unsigned char *)&hdr.sample_size);
19583− swap32((unsigned char *)&ssnd.ssnd_size);
19584− swap32((unsigned char *)&ssnd.offset);
19585− swap32((unsigned char *)&ssnd.block_size);
19579+ swapb32((unsigned char *)&hdr.form_size);
19580+ swapb32((unsigned char *)&hdr.comm_size);
19581+ swapb16((unsigned char *)&hdr.num_chans);
19582+ swapb16((unsigned char *)&hdr.sample_size);
19583+ swapb32((unsigned char *)&ssnd.ssnd_size);
19584+ swapb32((unsigned char *)&ssnd.offset);
19585+ swapb32((unsigned char *)&ssnd.block_size);
1958619586 }
1958719587
1958819588 // The structure boundaries don't allow a single write of 54 bytes.
@@ -19619,7 +19619,7 @@ void WvOut :: closeAifFile( void ) · 30 unmodified lines
1961919619 {
1962019620 unsigned long frames = (unsigned long) totalCount;
1962119621 if( little_endian )
19622− swap32((unsigned char *)&frames);
19622+ swapb32((unsigned char *)&frames);
1962319623
1962419624 fseek(fd, 22, SEEK_SET); // jump to "COMM" sample_frames
1962519625 fwrite(&frames, 4, 1, fd);
@@ -19637,7 +19637,7 @@ if( little_endian ) · 11 unmodified lines
1963719637 unsigned long bytes = totalCount * bytes_per_sample * channels + 46;
1963819638 if ( dataType == MY_FLOAT32 || dataType == MY_FLOAT64 ) bytes += 6;
1963919639 if( little_endian )
19640− swap32((unsigned char *)&bytes);
19640+ swapb32((unsigned char *)&bytes);
1964119641
1964219642 fseek(fd, 4, SEEK_SET); // jump to file size
1964319643 fwrite(&bytes, 4, 1, fd);
@@ -19645,7 +19645,7 @@ if( little_endian ) · 1 unmodified line
1964519645 bytes = totalCount * bytes_per_sample * channels + 8;
1964619646 if ( dataType == MY_FLOAT32 || dataType == MY_FLOAT64 ) bytes += 6;
1964719647 if( little_endian )
19648− swap32((unsigned char *)&bytes);
19648+ swapb32((unsigned char *)&bytes);
1964919649
1965019650 if ( dataType == MY_FLOAT32 || dataType == MY_FLOAT64 )
1965119651 fseek(fd, 48, SEEK_SET); // jump to "SSND" chunk size
@@ -19830,7 +19830,7 @@ void WvOut :: writeData( unsigned long frames ) · 178 unmodified lines
1983019830 if(float_sample > 32767) float_sample = 32767;
1983119831 SINT16 sample = (SINT16) float_sample;
1983219832
19833− if ( byteswap ) swap16( (unsigned char *)&sample );
19833+ if ( byteswap ) swapb16( (unsigned char *)&sample );
1983419834 if ( fwrite(&sample, 2, 1, fd) != 1 ) goto error;
1983519835 }
1983619836 }
@@ -19851,7 +19851,7 @@ void WvOut :: writeData( unsigned long frames ) · 14 unmodified lines
1985119851 if(float_sample > 2147483647.0 ) float_sample = 2147483647.0; // 1.4.2.0 (ge) | using float literal, instead of conversion from int
1985219852 SINT32 sample = (SINT32) float_sample;
1985319853
19854− if ( byteswap ) swap32( (unsigned char *)&sample );
19854+ if ( byteswap ) swapb32( (unsigned char *)&sample );
1985519855 if ( fwrite(&sample, 4, 1, fd) != 1 ) goto error;
1985619856 }
1985719857 }
@@ -19860,7 +19860,7 @@ void WvOut :: writeData( unsigned long frames ) · 2 unmodified lines
1986019860 for ( unsigned long k=0; k<frames*channels; k++ ) {
1986119861 sample = (FLOAT32) (data[k]);
1986219862
19863− if ( byteswap ) swap32( (unsigned char *)&sample );
19863+ if ( byteswap ) swapb32( (unsigned char *)&sample );
1986419864 if ( fwrite(&sample, 4, 1, fd) != 1 ) goto error;
1986519865 }
1986619866 }
@@ -19869,7 +19869,7 @@ void WvOut :: writeData( unsigned long frames ) · 2 unmodified lines
1986919869 for ( unsigned long k=0; k<frames*channels; k++ ) {
1987019870 sample = (FLOAT64) (data[k]);
1987119871
19872− if ( byteswap ) swap64( (unsigned char *)&sample );
19872+ if ( byteswap ) swapb64( (unsigned char *)&sample );
1987319873 if ( fwrite(&sample, 8, 1, fd) != 1 ) goto error;
1987419874 }
1987519875 }
@@ -19982,7 +19982,7 @@ MidiFileIn :: MidiFileIn( std::string fileName ) · 106 unmodified lines
1998219982 if ( !file_.read( chunkType, 4 ) ) goto error;
1998319983 if ( !file_.read( buffer, 4 ) ) goto error;
1998419984 #ifdef __LITTLE_ENDIAN__
19985− swap32((unsigned char *)&buffer);
19985+ swapb32((unsigned char *)&buffer);
1998619986 #endif
1998719987 length = (SINT32 *) &buffer;
1998819988 if ( strncmp( chunkType, "MThd", 4 ) || ( *length != 6 ) ) {
@@ -19994,7 +19994,7 @@ MidiFileIn :: MidiFileIn( std::string fileName ) · 5 unmodified lines
1999419994 SINT16 *data;
1999519995 if ( !file_.read( buffer, 2 ) ) goto error;
1999619996 #ifdef __LITTLE_ENDIAN__
19997− swap16((unsigned char *)&buffer);
19997+ swapb16((unsigned char *)&buffer);
1999819998 #endif
1999919999 data = (SINT16 *) &buffer;
2000020000 if ( *data < 0 || *data > 2 ) {
@@ -20006,7 +20006,7 @@ MidiFileIn :: MidiFileIn( std::string fileName ) · 5 unmodified lines
2000620006 // Read the number of tracks.
2000720007 if ( !file_.read( buffer, 2 ) ) goto error;
2000820008 #ifdef __LITTLE_ENDIAN__
20009− swap16((unsigned char *)&buffer);
20009+ swapb16((unsigned char *)&buffer);
2001020010 #endif
2001120011 if ( format_ == 0 && *data != 1 ) {
2001220012 msg << "MidiFileIn: invalid number of tracks (>1) for a file format = 0!";
@@ -20017,7 +20017,7 @@ MidiFileIn :: MidiFileIn( std::string fileName ) · 4 unmodified lines
2001720017 // Read the beat division.
2001820018 if ( !file_.read( buffer, 2 ) ) goto error;
2001920019 #ifdef __LITTLE_ENDIAN__
20020− swap16((unsigned char *)&buffer);
20020+ swapb16((unsigned char *)&buffer);
2002120021 #endif
2002220022 division_ = (int) *data;
2002320023 double tickrate;
@@ -20044,7 +20044,7 @@ MidiFileIn :: MidiFileIn( std::string fileName ) · 20 unmodified lines
2004420044 if ( strncmp( chunkType, "MTrk", 4 ) ) goto error;
2004520045 if ( !file_.read( buffer, 4 ) ) goto error;
2004620046 #ifdef __LITTLE_ENDIAN__
20047− swap32((unsigned char *)&buffer);
20047+ swapb32((unsigned char *)&buffer);
2004820048 #endif
2004920049 length = (SINT32 *) &buffer;
2005020050 trackLengths_.push_back( *length );
src/core/ugen_stk.h+3−3
@@ -181,13 +181,13 @@ public: · 180 unmodified lines
181181 static void setRawwavePath(std::string newPath);
182182
183183 //! Static method which byte-swaps a 16-bit data type.
184− static void swap16(unsigned char *ptr);
184+ static void swapb16(unsigned char *ptr);
185185
186186 //! Static method which byte-swaps a 32-bit data type.
187− static void swap32(unsigned char *ptr);
187+ static void swapb32(unsigned char *ptr);
188188
189189 //! Static method which byte-swaps a 64-bit data type.
190− static void swap64(unsigned char *ptr);
190+ static void swapb64(unsigned char *ptr);
191191
192192 //! Static cross-platform method to sleep for a number of milliseconds.
193193 static void sleep(unsigned long milliseconds);
src/core/util_hid.cpp+160−0
@@ -8121,3 +8121,163 @@ const char * MultiTouchDevice_name( int ts ) { return NULL; } · 8120 unmodified lines
81218121
81228122 #endif // __CHIP_MODE__
81238123
8124+#ifdef __PLATFORM_OPENBSD__
8125+
8126+void Hid_init(){}
8127+void Hid_poll(){}
8128+void Hid_quit(){}
8129+
8130+void Keyboard_init(){}
8131+void Keyboard_poll(){}
8132+void Keyboard_quit(){}
8133+void Keyboard_probe(){}
8134+
8135+int Keyboard_count()
8136+{
8137+ return 0;
8138+}
8139+
8140+int Keyboard_open( int kb )
8141+{
8142+ return -1;
8143+}
8144+
8145+int Keyboard_open( const char * name )
8146+{
8147+ return -1;
8148+}
8149+
8150+int Keyboard_close( int kb )
8151+{
8152+ return -1;
8153+}
8154+
8155+const char * Keyboard_name( int kb )
8156+{
8157+ return NULL;
8158+}
8159+
8160+void start_hid_multi_touch() { }
8161+void stop_hid_multi_touch() { }
8162+
8163+void Mouse_init(){}
8164+void Mouse_poll(){}
8165+void Mouse_quit(){}
8166+void Mouse_probe(){}
8167+
8168+int Mouse_count()
8169+{
8170+ return 1;
8171+}
8172+
8173+int Mouse_open( int m )
8174+{
8175+ if(m >= 0 && m < 1)
8176+ {
8177+ start_hid_multi_touch();
8178+ return 0;
8179+ }
8180+ else
8181+ return -1;
8182+}
8183+
8184+int Mouse_open( const char * name )
8185+{
8186+ return -1;
8187+}
8188+
8189+int Mouse_close( int m )
8190+{
8191+ if(m >= 0 && m < 1)
8192+ {
8193+ stop_hid_multi_touch();
8194+ return 0;
8195+ }
8196+ else
8197+ return -1;
8198+}
8199+
8200+int Mouse_send( int m, const HidMsg * msg )
8201+{
8202+ return -1;
8203+}
8204+
8205+const char * Mouse_name( int m )
8206+{
8207+ if(m == 0)
8208+ return "iPhone Multitouch";
8209+ else
8210+ return NULL;
8211+}
8212+
8213+// ge: SMS multi-thread poll rate
8214+t_CKINT TiltSensor_setPollRate( t_CKINT usec )
8215+{
8216+ return -1;
8217+}
8218+
8219+t_CKINT TiltSensor_getPollRate( )
8220+{
8221+ return -1;
8222+}
8223+
8224+void Joystick_init(){}
8225+
8226+void Joystick_poll(){}
8227+
8228+void Joystick_quit(){}
8229+
8230+void Joystick_probe(){}
8231+
8232+int Joystick_count()
8233+{
8234+ return 0;
8235+}
8236+
8237+int Joystick_open( int js )
8238+{
8239+ return -1;
8240+}
8241+
8242+int Joystick_open_async( int js )
8243+{
8244+ return -1;
8245+}
8246+
8247+int Joystick_open( const char * name )
8248+{
8249+ return -1;
8250+}
8251+
8252+int Joystick_close( int js )
8253+{
8254+ return -1;
8255+}
8256+
8257+int Joystick_send( int js, const HidMsg * msg )
8258+{
8259+ return -1;
8260+}
8261+
8262+
8263+const char * Joystick_name( int js )
8264+{
8265+ return NULL;
8266+}
8267+
8268+int Joystick_axes( int js )
8269+{
8270+ return -1;
8271+}
8272+
8273+int Joystick_buttons( int js )
8274+{
8275+ return -1;
8276+}
8277+
8278+int Joystick_hats( int js )
8279+{
8280+ return -1;
8281+}
8282+
8283+#endif // __PLATFORM_OPENBSD__
src/core/util_string.cpp+13−0
@@ -390,6 +390,8 @@ done: · 389 unmodified lines
390390 /* from http://developer.apple.com/library/mac/#qa/qa1549/_index.html */
391391 #if !defined(__PLATFORM_WIN32__) && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !defined(__CHIP_MODE__)
392392
393+#if !defined(__PLATFORM_OPENBSD__)
394+
393395 #include <wordexp.h>
394396 //-----------------------------------------------------------------------------
395397 // name: expandTildePath()
@@ -418,6 +420,17 @@ std::string expandTildePath( const std::string & path ) · 22 unmodified lines
418420 return result;
419421 }
420422
423+#else
424+
425+//FIXME
426+std::string expandTildePath( const std::string & path )
427+{
428+ // default is the original path
429+ std::string result = path;
430+ return result;
431+}
432+#endif
433+
421434 #include <glob.h>
422435 //-----------------------------------------------------------------------------
423436 // name: globTildePath()
src/core/util_thread.cpp+10−10
@@ -67,7 +67,7 @@ XThread::XThread( ) · 66 unmodified lines
6767 //-----------------------------------------------------------------------------
6868 XThread::~XThread( )
6969 {
70−#if defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__)
70+#if defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__)
7171 // can't self-terminate (much like the Terminator)
7272 bool is_self_thread = (thread == pthread_self());
7373 #elif defined(__PLATFORM_WIN32__)
@@ -79,7 +79,7 @@ XThread::~XThread( ) · 5 unmodified lines
7979 if( thread != 0 && !is_self_thread )
8080 {
8181 // TODO: find an alternative for Android?
82−#if defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__)
82+#if defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__)
8383 // log
8484 EM_log( CK_LOG_FINER, "cancelling XThread: %u on thread: %u", (t_CKUINT)thread, (t_CKUINT)pthread_self() );
8585 pthread_cancel(thread);
@@ -103,7 +103,7 @@ bool XThread::start( THREAD_FUNCTION routine, void * ptr ) · 17 unmodified lines
103103 {
104104 bool result = false;
105105
106−#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) )
106+#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__) )
107107 if( pthread_create( &thread, NULL, *routine, ptr ) == 0 )
108108 result = true;
109109 #elif defined(__PLATFORM_WIN32__)
@@ -126,7 +126,7 @@ bool XThread::wait( long milliseconds, bool cancel ) · 16 unmodified lines
126126 bool result = false;
127127
128128 // TODO: find an alternative for Android?
129−#if( defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) )
129+#if( defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__) )
130130 // cancel the thread?
131131 if( cancel ) pthread_cancel( thread );
132132 // wait for the thread to terminate
@@ -156,7 +156,7 @@ bool XThread::wait( long milliseconds, bool cancel ) · 23 unmodified lines
156156 void XThread :: test( )
157157 {
158158 // TODO: find an alternative for Android?
159−#if ( defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) )
159+#if ( defined(__PLATFORM_MACOSX__) || ( defined(__PLATFORM_LINUX__) && !defined(__ANDROID__) ) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__) )
160160 pthread_testcancel();
161161 #endif
162162 }
@@ -170,7 +170,7 @@ void XThread :: test( ) · 7 unmodified lines
170170 //-----------------------------------------------------------------------------
171171 XMutex::XMutex( )
172172 {
173−#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) )
173+#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__) )
174174 pthread_mutex_init(&mutex, NULL);
175175 #elif defined(__PLATFORM_WIN32__)
176176 InitializeCriticalSection(&mutex);
@@ -186,7 +186,7 @@ XMutex::XMutex( ) · 9 unmodified lines
186186 //-----------------------------------------------------------------------------
187187 XMutex::~XMutex( )
188188 {
189−#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) )
189+#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__) )
190190 pthread_mutex_destroy( &mutex );
191191 #elif defined(__PLATFORM_WIN32__)
192192 DeleteCriticalSection(&mutex);
@@ -202,7 +202,7 @@ XMutex::~XMutex( ) · 9 unmodified lines
202202 //-----------------------------------------------------------------------------
203203 void XMutex::acquire( )
204204 {
205−#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) )
205+#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__) )
206206 pthread_mutex_lock(&mutex);
207207 #elif defined(__PLATFORM_WIN32__)
208208 EnterCriticalSection(&mutex);
@@ -218,7 +218,7 @@ void XMutex::acquire( ) · 9 unmodified lines
218218 //-----------------------------------------------------------------------------
219219 void XMutex::release( )
220220 {
221−#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) )
221+#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__) )
222222 pthread_mutex_unlock(&mutex);
223223 #elif defined(__PLATFORM_WIN32__)
224224 LeaveCriticalSection(&mutex);
@@ -416,7 +416,7 @@ void XWriteThread::flush_data_buffer() · 191 unmodified lines
416416 // name: write_cb()
417417 // desc: thread function
418418 //-----------------------------------------------------------------------------
419−#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) )
419+#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__) )
420420 void * XWriteThread::write_cb(void * _thiss)
421421 #elif defined(__PLATFORM_WIN32__)
422422 unsigned XWriteThread::write_cb(void * _thiss)
src/core/util_thread.h+2−2
@@ -43,7 +43,7 @@ class FastCircularBuffer; · 42 unmodified lines
4343 template<typename T> class CircularBuffer;
4444
4545
46−#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) )
46+#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__PLATFORM_OPENBSD__) || defined(__WINDOWS_PTHREAD__) )
4747 #include <pthread.h>
4848 #define THREAD_TYPE
4949 typedef pthread_t THREAD_HANDLE;
@@ -181,7 +181,7 @@ private: · 131 unmodified lines
181181 void flush_data_buffer();
182182
183183 // callback
184−#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) )
184+#if ( defined(__PLATFORM_MACOSX__) || defined(__PLATFORM_LINUX__) || defined(__WINDOWS_PTHREAD__) || defined(__PLATFORM_OPENBSD__) )
185185 static void * write_cb( void * _thiss );
186186 #elif defined(__PLATFORM_WIN32__)
187187 static unsigned THREAD_TYPE write_cb( void * _thiss );
src/host/chuck_audio.h+3−0
@@ -171,6 +171,9 @@ public: · 170 unmodified lines
171171 { m_extern_in = in; m_extern_out = out; }
172172 static int cb( void * output_buffer, void * input_buffer, unsigned int buffer_size,
173173 double streamTime, RtAudioStreamStatus status, void * user_data );
174+#ifdef __OPENBSD_OPENAL__
175+ static int alcb(void *userptr, void *output_buffer, int len);
176+#endif
174177
175178 public: // data
176179 static t_CKBOOL m_init;
src/host/chuck_audio_openal.cpp+430−0
@@ -0,0 +1,430 @@
1+/*----------------------------------------------------------------------------
2+ ChucK Concurrent, On-the-fly Audio Programming Language
3+ Compiler and Virtual Machine
4+
5+ Copyright (c) 2004 Ge Wang and Perry R. Cook. All rights reserved.
6+ http://chuck.stanford.edu/
7+ http://chuck.cs.princeton.edu/
8+
9+ This program is free software; you can redistribute it and/or modify
10+ it under the terms of the GNU General Public License as published by
11+ the Free Software Foundation; either version 2 of the License, or
12+ (at your option) any later version.
13+
14+ This program is distributed in the hope that it will be useful,
15+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+ GNU General Public License for more details.
18+
19+ You should have received a copy of the GNU General Public License
20+ along with this program; if not, write to the Free Software
21+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22+ U.S.A.
23+-----------------------------------------------------------------------------*/
24+
25+#include "chuck_audio.h"
26+#include "chuck_errmsg.h"
27+#include "util_thread.h"
28+#include <unistd.h>
29+#include <al.h>
30+#include <alc.h>
31+#define AL_ALEXT_PROTOTYPES
32+#include <alext.h>
33+
34+// sample
35+#if defined(__CHUCK_USE_64_BIT_SAMPLE__)
36+#define AUDIO_FORMAT AL_FORMAT_STEREO_DOUBLE_EXT
37+#else
38+#define AUDIO_FORMAT AL_FORMAT_STEREO_FLOAT32
39+#endif
40+
41+// real-time watch dog
42+t_CKBOOL g_do_watchdog = FALSE;
43+// countermeasure
44+#ifdef __MACOSX_CORE__
45+t_CKUINT g_watchdog_countermeasure_priority = 10;
46+#elif defined(__PLATFORM_WIN32__) && !defined(__WINDOWS_PTHREAD__)
47+t_CKUINT g_watchdog_countermeasure_priority = THREAD_PRIORITY_LOWEST;
48+#else
49+t_CKUINT g_watchdog_countermeasure_priority = 0;
50+#endif
51+// watchdog timeout
52+t_CKFLOAT g_watchdog_timeout = 0.5;
53+
54+// static initialization
55+t_CKBOOL ChuckAudio::m_init = FALSE;
56+t_CKBOOL ChuckAudio::m_start = FALSE;
57+t_CKBOOL ChuckAudio::m_go = FALSE;
58+t_CKBOOL ChuckAudio::m_silent = FALSE;
59+t_CKBOOL ChuckAudio::m_expand_in_mono2stereo= FALSE;
60+t_CKUINT ChuckAudio::m_num_channels_out = NUM_CHANNELS_DEFAULT;
61+t_CKUINT ChuckAudio::m_num_channels_in = NUM_CHANNELS_DEFAULT;
62+t_CKUINT ChuckAudio::m_num_channels_max = NUM_CHANNELS_DEFAULT;
63+t_CKUINT ChuckAudio::m_sample_rate = SAMPLE_RATE_DEFAULT;
64+t_CKUINT ChuckAudio::m_buffer_size = BUFFER_SIZE_DEFAULT;
65+t_CKUINT ChuckAudio::m_num_buffers = NUM_BUFFERS_DEFAULT;
66+SAMPLE * ChuckAudio::m_buffer_out = NULL;
67+SAMPLE * ChuckAudio::m_buffer_in = NULL;
68+SAMPLE * ChuckAudio::m_extern_in = NULL;
69+SAMPLE * ChuckAudio::m_extern_out = NULL;
70+t_CKUINT ChuckAudio::m_dac_n = 0;
71+t_CKUINT ChuckAudio::m_adc_n = 0;
72+f_audio_cb ChuckAudio::m_audio_cb = NULL;
73+void * ChuckAudio::m_cb_user_data = NULL;
74+
75+static ALCdevice *aldev = NULL;
76+static ALCcontext *alc = NULL;
77+static ALuint albuf;
78+static ALuint alsrc;
79+static pthread_t althread;
80+
81+void ChuckAudio::probe()
82+{
83+}
84+
85+t_CKINT ChuckAudio::device_named( const std::string & name, t_CKBOOL needs_dac,
86+ t_CKBOOL needs_adc )
87+{
88+ if(needs_adc || !needs_dac)
89+ return -1;
90+ const char *dev = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
91+ if(dev == NULL)
92+ return -1;
93+ const char *s = dev;
94+ for(int i = 1; *s; i++){
95+ if(strcmp(s, name.c_str()) == 0)
96+ return i;
97+ s += strlen(s) + 1;
98+ }
99+
100+ for(int i = 1; *s; i++){
101+ if(strncmp(s, name.c_str(), name.length()) == 0)
102+ return i;
103+ s += strlen(s) + 1;
104+ }
105+
106+ return -1;
107+}
108+
109+static t_CKFLOAT get_current_time( t_CKBOOL fresh = TRUE )
110+{
111+#ifdef __PLATFORM_WIN32__
112+ struct _timeb t;
113+ _ftime(&t);
114+ return t.time + t.millitm/1000.0;
115+#else
116+ static struct timeval t;
117+ if( fresh ) gettimeofday(&t,NULL);
118+ return t.tv_sec + (t_CKFLOAT)t.tv_usec/1000000;
119+#endif
120+}
121+
122+// watch dog globals
123+static CHUCK_THREAD g_tid_synthesis = 0;
124+static XThread * g_watchdog_thread = NULL;
125+static t_CKBOOL g_watchdog_state = FALSE;
126+static t_CKFLOAT g_watchdog_time = 0;
127+
128+#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
129+static void * watch_dog( void * )
130+#else
131+static unsigned int __stdcall watch_dog( void * )
132+#endif
133+{
134+ // time
135+ t_CKFLOAT time = 0;
136+
137+ // boost priority?
138+ t_CKUINT priority = XThreadUtil::our_priority;
139+
140+ // log
141+ EM_log( CK_LOG_SEVERE, "starting real-time watch dog process..." );
142+ // push log
143+ EM_pushlog();
144+ EM_log( CK_LOG_INFO, "watchdog timeout: %f::second", g_watchdog_timeout );
145+ EM_log( CK_LOG_INFO, "watchdog thread priority: %d", priority );
146+ EM_log( CK_LOG_INFO, "watchdog countermeasure priority: %d", g_watchdog_countermeasure_priority );
147+ // pop log
148+ EM_poplog();
149+
150+ // boost watchdog by same priority
151+ if( XThreadUtil::our_priority != 0x7fffffff )
152+ XThreadUtil::set_priority( priority );
153+
154+ // while going
155+ while( g_do_watchdog )
156+ {
157+ // get
158+ time = get_current_time( TRUE );
159+ // CK_FPRINTF_STDERR( "last: %f now: %f\n", g_watchdog_time, time );
160+
161+ // resting
162+ if( g_watchdog_state == FALSE )
163+ {
164+ // check time vs timeout
165+ if( time - g_watchdog_time > g_watchdog_timeout )
166+ {
167+ // log
168+ EM_log( CK_LOG_SEVERE, "real-time watchdog counter-measure activating..." );
169+ // lowering priority
170+ if( g_tid_synthesis && XThreadUtil::our_priority != 0x7fffffff )
171+ XThreadUtil::set_priority( g_tid_synthesis, g_watchdog_countermeasure_priority );
172+ // set state
173+ g_watchdog_state = TRUE;
174+ }
175+ }
176+ else
177+ {
178+ // check time vs timeout
179+ if( time - g_watchdog_time < g_watchdog_timeout )
180+ {
181+ // log
182+ EM_log( CK_LOG_SEVERE, "real-time watchdog resting..." );
183+ // raise priority
184+ if( g_tid_synthesis && XThreadUtil::our_priority != 0x7fffffff )
185+ XThreadUtil::set_priority( g_tid_synthesis, XThreadUtil::our_priority );
186+ // set state
187+ g_watchdog_state = FALSE;
188+ }
189+ }
190+
191+ // advance time
192+ usleep( 40000 );
193+ }
194+
195+ // log
196+ EM_log( CK_LOG_SEVERE, "stopping real-time watch dog process..." );
197+
198+ return 0;
199+}
200+
201+t_CKBOOL ChuckAudio::watchdog_start()
202+{
203+ // already
204+ if( g_watchdog_thread )
205+ return FALSE;
206+
207+ // flag
208+ g_do_watchdog = TRUE;
209+ // allocate it
210+ g_watchdog_thread = new XThread;
211+ // start it
212+ g_watchdog_thread->start( watch_dog, NULL );
213+
214+ return TRUE;
215+}
216+
217+t_CKBOOL ChuckAudio::watchdog_stop()
218+{
219+ // already
220+ if( !g_watchdog_thread )
221+ return FALSE;
222+
223+ // stop things
224+ g_do_watchdog = FALSE;
225+ // wait a bit | TODO: is this needed?
226+ usleep( 100000 );
227+ // delete watchdog thread | TODO: is this safe?
228+ SAFE_DELETE( g_watchdog_thread );
229+
230+ return TRUE;
231+}
232+
233+ALsizei ChuckAudio::alcb(ALvoid *userptr, ALvoid *output_buffer, ALsizei len)
234+{
235+ // priority boost
236+ if( !m_go && XThreadUtil::our_priority != 0x7fffffff )
237+ {
238+#if !defined(__PLATFORM_WIN32__) || defined(__WINDOWS_PTHREAD__)
239+ g_tid_synthesis = pthread_self();
240+#else
241+ // must duplicate for handle to be usable by other threads
242+ g_tid_synthesis = NULL;
243+ DuplicateHandle(
244+ GetCurrentProcess(),
245+ GetCurrentThread(),
246+ GetCurrentProcess(),
247+ &g_tid_synthesis,
248+ 0,
249+ FALSE,
250+ DUPLICATE_SAME_ACCESS
251+ );
252+
253+ // TODO: close the duplicate handle?
254+#endif
255+ XThreadUtil::set_priority( XThreadUtil::our_priority );
256+ memset( output_buffer, 0, len );
257+ m_go = TRUE;
258+
259+ // start watchdog
260+ if( g_do_watchdog )
261+ {
262+ // timestamp
263+ g_watchdog_time = get_current_time( TRUE );
264+ // start watchdog
265+ watchdog_start();
266+ }
267+
268+ // let it go the first time
269+ return len;
270+ }
271+
272+ // timestamp
273+ if( g_do_watchdog ) g_watchdog_time = get_current_time( TRUE );
274+ // call the audio cb
275+ m_audio_cb( m_buffer_in, m_buffer_out, len/(sizeof(SAMPLE) * m_num_channels_out),
276+ m_num_channels_in, m_num_channels_out, m_cb_user_data );
277+
278+ // copy local buffer to be rendered
279+ // REFACTOR-2017: TODO: m_end was the signal to end, what should it be now?
280+ if( m_start ) // REFACTOR-2017: now using m_start to gate this
281+ {
282+ memcpy( output_buffer, m_buffer_out, len );
283+ }
284+ // set all elements of local buffer to silence
285+ else
286+ {
287+ memset( output_buffer, 0, len );
288+ }
289+
290+ // copy to extern
291+ if( m_extern_out ) memcpy( m_extern_out, output_buffer, len );
292+
293+ return len;
294+}
295+
296+
297+t_CKBOOL ChuckAudio::initialize( t_CKUINT num_dac_channels,
298+ t_CKUINT num_adc_channels,
299+ t_CKUINT sample_rate,
300+ t_CKUINT buffer_size,
301+ t_CKUINT num_buffers,
302+ f_audio_cb callback,
303+ void * data,
304+ t_CKBOOL force_srate )
305+{
306+ if( m_init )
307+ return FALSE;
308+
309+ m_num_channels_out = num_dac_channels;
310+ m_num_channels_in = num_adc_channels;
311+ m_sample_rate = sample_rate;
312+ m_buffer_size = buffer_size;
313+ m_num_buffers = num_buffers;
314+ m_start = 0;
315+ m_go = 0;
316+ m_silent = 0;
317+
318+ // remember callback
319+ m_audio_cb = callback;
320+ // remember user data to pass to callback
321+ m_cb_user_data = data;
322+
323+ // variable to pass by reference into OpenAL
324+ unsigned int bufsize = (unsigned int)m_buffer_size;
325+
326+ // log
327+ EM_log( CK_LOG_FINE, "initializing OpenAL..." );
328+ // push indent
329+ EM_pushlog();
330+
331+ const char *dev = NULL;
332+ if(m_dac_n > 0){
333+ const char *s = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
334+ for(int i = 1; *s; i++){
335+ if(i == m_dac_n){
336+ dev = s;
337+ break;
338+ }
339+ s += strlen(s) + 1;
340+ }
341+ }
342+
343+ const ALCint attrlist[] = {ALC_FREQUENCY, (ALCint)sample_rate, 0, 0};
344+
345+ althread = pthread_self();
346+ if((aldev = alcOpenDevice(dev)) == NULL)
347+ goto error;
348+ if((alc = alcCreateContext(aldev, attrlist)) == NULL)
349+ goto error;
350+ alcMakeContextCurrent(alc);
351+
352+ alGenSources(1, &alsrc);
353+ alGenBuffers(1, &albuf);
354+ alBufferCallbackSOFT(albuf, AUDIO_FORMAT, sample_rate, alcb, NULL);
355+ alSourcei(alsrc, AL_SOURCE_SPATIALIZE_SOFT, AL_FALSE);
356+ alSourcei(alsrc, AL_BUFFER, albuf);
357+ alSourcePlay(alsrc);
358+
359+ // pop indent
360+ EM_poplog();
361+
362+ // allocate buffers
363+ m_buffer_in = new SAMPLE[m_buffer_size * m_num_channels_max];
364+ m_buffer_out = new SAMPLE[m_buffer_size * m_num_channels_max];
365+ memset( m_buffer_in, 0, m_buffer_size * sizeof(SAMPLE) * m_num_channels_max );
366+ memset( m_buffer_out, 0, m_buffer_size * sizeof(SAMPLE) * m_num_channels_max );
367+
368+ // set flag and return
369+ return m_init = TRUE;
370+
371+// handle common error case (added 1.4.1.0)
372+error:
373+ if(alc != NULL){
374+ alcDestroyContext(alc);
375+ alc = NULL;
376+ }
377+ if(aldev != NULL){
378+ alcCloseDevice(aldev);
379+ aldev = NULL;
380+ }
381+ // pop log indent (added 1.4.1.0)
382+ EM_poplog();
383+ // set flag and return
384+ return m_init = FALSE;
385+}
386+
387+t_CKBOOL ChuckAudio::start( )
388+{
389+ if( !m_start )
390+ alcDeviceResumeSOFT(aldev);
391+ m_start = TRUE;
392+
393+ return m_start;
394+}
395+
396+t_CKBOOL ChuckAudio::stop( )
397+{
398+ if( m_start )
399+ alcDevicePauseSOFT(aldev);
400+ m_start = FALSE;
401+
402+ // REFACTOR-2017: set end flag
403+ m_silent = TRUE;
404+
405+ return !m_start;
406+}
407+
408+void ChuckAudio::shutdown()
409+{
410+ // check flag
411+ if( !m_init ) return;
412+
413+ // stop watchdog | REFACTOR-2017: moved this earlier to give watchdog
414+ // a head start in stopping, to avoid unneeded countermeasure deployment
415+ watchdog_stop();
416+
417+ if(althread == pthread_self() && alc != NULL){
418+ alSourceStop(alsrc);
419+ alDeleteSources(1, &alsrc);
420+ alDeleteBuffers(1, &albuf);
421+ alcDestroyContext(alc);
422+ alc = NULL;
423+ alcCloseDevice(aldev);
424+ aldev = NULL;
425+ }
426+
427+ // unflag
428+ m_init = FALSE;
429+ m_start = FALSE;
430+}
src/makefile+16−7
@@ -9,7 +9,7 @@ CK_VERSION=1.5.0.4-dev · 8 unmodified lines
99 current:
1010 @echo "[chuck build]: please use the following configurations:"
1111 @echo " make linux-alsa, make linux-jack, make linux-pulse, linux-all,"
12− @echo " make mac, make mac-ub, make web, make cygwin, make win32"
12+ @echo " make openbsd-openal, make mac, make mac-ub, make web, make cygwin, make win32"
1313
1414
1515 ############################## MAKE INSTALL ####################################
@@ -75,7 +75,7 @@ host_web/webchuck/js/webchuck.js: $(EMSCRIPTENSRCS) · 59 unmodified lines
7575 ## > make linux-pulse linux-alsa linux-jack
7676
7777 .PHONY: mac mac-ub osx linux-all linux linux-pulse linux-jack linux-alsa cygwin osx-rl test
78−mac mac-ub osx linux-all linux linux-pulse linux-jack linux-alsa cygwin osx-rl: chuck
78+mac mac-ub osx linux-all linux linux-pulse linux-jack linux-alsa cygwin osx-rl openbsd-openal: chuck
7979
8080 win32:
8181 make -f $(COREDIR)/makefile.x/makefile.win32
@@ -84,9 +84,9 @@ win32: · 2 unmodified lines
8484 ########################### COMPILATION TOOLS ##################################
8585 LEX=flex
8686 YACC=bison
87−CC=gcc
88−CXX=g++
89−LD=g++
87+CC?=gcc
88+CXX?=g++
89+LD?=g++
9090
9191
9292 ############################# COMPILER FLAGS ###################################
@@ -142,6 +142,10 @@ ifneq (,$(strip $(filter linux-alsa,$(MAKECMDGOALS)))) · 49 unmodified lines
142142 include $(COREDIR)/makefile.x/makefile.alsa
143143 endif
144144
145+ifneq (,$(strip $(filter openbsd-openal,$(MAKECMDGOALS))))
146+include $(COREDIR)/makefile.x/makefile.openal
147+endif
148+
145149 ifneq (,$(strip $(filter cygwin,$(MAKECMDGOALS))))
146150 include $(COREDIR)/makefile.x/makefile.cygwin
147151 endif
@@ -170,12 +174,17 @@ LO_COBJS_CORE+= lo/address.o lo/blob.o lo/bundle.o lo/message.o lo/method.o \ · 22 unmodified lines
170174
171175
172176 ############################ CHUCK HOST TARGETS ################################
177+ifneq (,$(strip $(filter openbsd-openal,$(MAKECMDGOALS))))
178+CXXSRCS_HOST+= chuck_audio_openal.cpp
179+else
173180 CXXINC_HOST+= -I${RTAUDIODIR} -I${RTAUDIODIR}/include
174−CXXSRCS_HOST+= chuck_main.cpp chuck_audio.cpp chuck_console.cpp \
175− ${RTAUDIODIR}/RtAudio.cpp
181+CXXSRCS_HOST+= chuck_audio.cpp ${RTAUDIODIR}/RtAudio.cpp
182+endif
176183 # NB: on some windows builds, the ASIO src in RTAUDIODIR/include
177184 # should be added.
178185
186+CXXSRCS_HOST+= chuck_console.cpp chuck_main.cpp
187+
179188
180189 ############################ OBJECT FILE TARGETS ###############################
181190 CXXOBJS_HOST=$(addprefix $(HOSTDIR)/,$(CXXSRCS_HOST:.cpp=.o))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t