New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add OpenBSD support #51
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
657327f
Add OpenBSD section, don't use linux_glimp on openbsd and
ryan-sg 60740f4
add __OpenBSD__
ryan-sg b05399a
add DEFAULT_CURL_LIB define for OpenBSD
ryan-sg 540dc33
add __OpenBSD__ in a couple places
ryan-sg 4289a51
check for __amd64__ as well, defined ARCH_STRING accordingly
ryan-sg 9ed87ab
OpenBSD mmap(2) requires PROT_READ with PROT_WRITE
ryan-sg b7519b8
OpenBSD mmap(2) requires PROT_READ before PROT_WRITE
ryan-sg 734a1eb
adds __OpenBSD__ to various existing ifdefs
ryan-sg 9baff12
define dummy 3dfx value for OpenBSD to not break build
ryan-sg 6ca023d
adds __OpenBSD__ to ifdef
ryan-sg fe3d797
adds __OpenBSD__ to a couple ifdefs
ryan-sg e278579
add snd_sndio.c for OpenBSD sndio support
ryan-sg File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* Copyright (c) 2010 Jacob Meuser <jakemsr@sdf.lonestar.org> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include <sys/types.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <fcntl.h> | ||
#include <poll.h> | ||
#include <errno.h> | ||
|
||
#include <sndio.h> | ||
|
||
#include "../qcommon/q_shared.h" | ||
#include "../client/snd_local.h" | ||
|
||
static struct sio_hdl *hdl; | ||
static int snd_inited; | ||
|
||
unsigned char *dma_buffer; | ||
size_t dma_buffer_size, dma_ptr; | ||
|
||
|
||
qboolean | ||
SNDDMA_Init(void) | ||
{ | ||
struct sio_par par; | ||
int i; | ||
|
||
if (snd_inited) | ||
return qtrue; | ||
|
||
hdl = sio_open(NULL, SIO_PLAY, 1); | ||
if (hdl == NULL) { | ||
Com_Printf("Could not open sndio device\n"); | ||
return qfalse; | ||
} | ||
|
||
sio_initpar(&par); | ||
|
||
par.bits = 16; | ||
par.sig = 1; | ||
par.pchan = 2; | ||
par.rate = 44100; | ||
par.le = SIO_LE_NATIVE; | ||
par.appbufsz = par.rate / 10; /* 1/10 second latency */ | ||
|
||
if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) { | ||
Com_Printf("Error setting audio parameters\n"); | ||
sio_close(hdl); | ||
return qfalse; | ||
} | ||
if ((par.pchan != 1 && par.pchan != 2) || | ||
!((par.bits == 16 && par.sig == 1) || | ||
(par.bits == 8 && par.sig == 0))) { | ||
Com_Printf("Could not set appropriate audio parameters\n"); | ||
sio_close(hdl); | ||
return qfalse; | ||
} | ||
dma.speed = par.rate; | ||
dma.channels = par.pchan; | ||
dma.samplebits = par.bits; | ||
dma.submission_chunk = 1; | ||
|
||
/* | ||
* find the smallest power of two larger than the buffer size | ||
* and use it as the internal buffer's size | ||
*/ | ||
for (i = 1; i < par.appbufsz; i <<= 2) | ||
; /* nothing */ | ||
dma.samples = i * par.pchan; | ||
|
||
dma_buffer_size = dma.samples * dma.samplebits / 8; | ||
dma_buffer = calloc(1, dma_buffer_size); | ||
if (dma_buffer == NULL) { | ||
Com_Printf("Could not allocate audio ring buffer\n"); | ||
return qfalse; | ||
} | ||
dma_ptr = 0; | ||
dma.buffer = dma_buffer; | ||
if (!sio_start(hdl)) { | ||
Com_Printf("Could not start audio\n"); | ||
sio_close(hdl); | ||
return qfalse; | ||
} | ||
|
||
snd_inited = qtrue; | ||
return qtrue; | ||
} | ||
|
||
void | ||
SNDDMA_Shutdown(void) | ||
{ | ||
if (snd_inited == qtrue) { | ||
sio_close(hdl); | ||
snd_inited = qfalse; | ||
} | ||
free(dma_buffer); | ||
} | ||
|
||
int | ||
SNDDMA_GetDMAPos(void) | ||
{ | ||
if (!snd_inited) | ||
return (0); | ||
|
||
return (dma_ptr / (dma.samplebits / 8)); | ||
} | ||
|
||
void | ||
SNDDMA_Submit(void) | ||
{ | ||
struct pollfd pfd; | ||
size_t count, todo, avail; | ||
int n; | ||
|
||
n = sio_pollfd(hdl, &pfd, POLLOUT); | ||
while (poll(&pfd, n, 0) < 0 && errno == EINTR) | ||
; | ||
if (!(sio_revents(hdl, &pfd) & POLLOUT)) | ||
return; | ||
avail = dma_buffer_size; | ||
while (avail > 0) { | ||
todo = dma_buffer_size - dma_ptr; | ||
if (todo > avail) | ||
todo = avail; | ||
count = sio_write(hdl, dma_buffer + dma_ptr, todo); | ||
if (count == 0) | ||
break; | ||
dma_ptr += count; | ||
if (dma_ptr >= dma_buffer_size) | ||
dma_ptr -= dma_buffer_size; | ||
avail -= count; | ||
} | ||
} | ||
|
||
void | ||
SNDDMA_BeginPainting(void) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can confirm the asm register fix is also needed for x86_64 on Mac OS X and FreeBSD, AFAIK it should be escaped, i'm guessing the only reason it worked at all on other platforms is because the compiler is more relaxed and coerced invalid operand references into a literal %