| @@ -1,65 +1,69 @@ | | | @@ -1,65 +1,69 @@ |
1 | $NetBSD: patch-src_audio_netbsd_SDL__netbsdaudio.c,v 1.5 2020/04/08 14:41:33 nia Exp $ | | 1 | $NetBSD: patch-src_audio_netbsd_SDL__netbsdaudio.c,v 1.6 2020/04/16 04:12:39 nia Exp $ |
2 | | | 2 | |
3 | Use the preferred hardware sample rate | | 3 | Use the preferred hardware sample rate |
4 | https://bugzilla.libsdl.org/show_bug.cgi?id=5080 | | 4 | https://bugzilla.libsdl.org/show_bug.cgi?id=5080 |
5 | | | 5 | |
6 | Support 32-bit LPCM | | 6 | Support 32-bit LPCM |
7 | https://bugzilla.libsdl.org/show_bug.cgi?id=5076 | | 7 | https://bugzilla.libsdl.org/show_bug.cgi?id=5076 |
8 | | | 8 | |
9 | --- src/audio/netbsd/SDL_netbsdaudio.c.orig 2020-03-11 01:36:18.000000000 +0000 | | 9 | --- src/audio/netbsd/SDL_netbsdaudio.c.orig 2020-03-11 01:36:18.000000000 +0000 |
10 | +++ src/audio/netbsd/SDL_netbsdaudio.c | | 10 | +++ src/audio/netbsd/SDL_netbsdaudio.c |
11 | @@ -205,7 +205,7 @@ static int | | 11 | @@ -205,7 +205,7 @@ static int |
12 | NETBSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) | | 12 | NETBSDAUDIO_OpenDevice(_THIS, void *handle, const char *devname, int iscapture) |
13 | { | | 13 | { |
14 | SDL_AudioFormat format = 0; | | 14 | SDL_AudioFormat format = 0; |
15 | - audio_info_t info; | | 15 | - audio_info_t info; |
16 | + audio_info_t info, hwinfo; | | 16 | + audio_info_t info, hwinfo; |
17 | struct audio_prinfo *prinfo = iscapture ? &info.record : &info.play; | | 17 | struct audio_prinfo *prinfo = iscapture ? &info.record : &info.play; |
18 | | | 18 | |
19 | /* We don't care what the devname is...we'll try to open anything. */ | | 19 | /* We don't care what the devname is...we'll try to open anything. */ |
20 | @@ -232,8 +232,16 @@ NETBSDAUDIO_OpenDevice(_THIS, void *hand | | 20 | @@ -232,8 +232,20 @@ NETBSDAUDIO_OpenDevice(_THIS, void *hand |
21 | } | | 21 | } |
22 | | | 22 | |
23 | AUDIO_INITINFO(&info); | | 23 | AUDIO_INITINFO(&info); |
24 | + AUDIO_INITINFO(&hwinfo); | | 24 | + AUDIO_INITINFO(&hwinfo); |
25 | + | | 25 | + |
| | | 26 | +#ifdef AUDIO_GETFORMAT |
26 | + if (ioctl(this->hidden->audio_fd, AUDIO_GETFORMAT, &hwinfo) == -1) { | | 27 | + if (ioctl(this->hidden->audio_fd, AUDIO_GETFORMAT, &hwinfo) == -1) { |
27 | + return SDL_SetError("Couldn't get device format %s: %s", devname, strerror(errno)); | | 28 | + return SDL_SetError("Couldn't get device format %s: %s", devname, strerror(errno)); |
28 | + } | | 29 | + } |
| | | 30 | +#else |
| | | 31 | + hwinfo.record.sample_rate = hwinfo.play.sample_rate = 48000; |
| | | 32 | +#endif |
29 | | | 33 | |
30 | prinfo->encoding = AUDIO_ENCODING_NONE; | | 34 | prinfo->encoding = AUDIO_ENCODING_NONE; |
31 | + prinfo->channels = this->spec.channels; | | 35 | + prinfo->channels = this->spec.channels; |
32 | + prinfo->sample_rate = this->spec.freq = iscapture ? | | 36 | + prinfo->sample_rate = this->spec.freq = iscapture ? |
33 | + hwinfo.record.sample_rate : hwinfo.play.sample_rate; | | 37 | + hwinfo.record.sample_rate : hwinfo.play.sample_rate; |
34 | | | 38 | |
35 | for (format = SDL_FirstAudioFormat(this->spec.format); format;) { | | 39 | for (format = SDL_FirstAudioFormat(this->spec.format); format;) { |
36 | switch (format) { | | 40 | switch (format) { |
37 | @@ -261,6 +269,14 @@ NETBSDAUDIO_OpenDevice(_THIS, void *hand | | 41 | @@ -261,6 +273,14 @@ NETBSDAUDIO_OpenDevice(_THIS, void *hand |
38 | prinfo->encoding = AUDIO_ENCODING_ULINEAR_BE; | | 42 | prinfo->encoding = AUDIO_ENCODING_ULINEAR_BE; |
39 | prinfo->precision = 16; | | 43 | prinfo->precision = 16; |
40 | break; | | 44 | break; |
41 | + case AUDIO_S32LSB: | | 45 | + case AUDIO_S32LSB: |
42 | + prinfo->encoding = AUDIO_ENCODING_SLINEAR_LE; | | 46 | + prinfo->encoding = AUDIO_ENCODING_SLINEAR_LE; |
43 | + prinfo->precision = 32; | | 47 | + prinfo->precision = 32; |
44 | + break; | | 48 | + break; |
45 | + case AUDIO_S32MSB: | | 49 | + case AUDIO_S32MSB: |
46 | + prinfo->encoding = AUDIO_ENCODING_SLINEAR_BE; | | 50 | + prinfo->encoding = AUDIO_ENCODING_SLINEAR_BE; |
47 | + prinfo->precision = 32; | | 51 | + prinfo->precision = 32; |
48 | + break; | | 52 | + break; |
49 | } | | 53 | } |
50 | if (prinfo->encoding != AUDIO_ENCODING_NONE) { | | 54 | if (prinfo->encoding != AUDIO_ENCODING_NONE) { |
51 | break; | | 55 | break; |
52 | @@ -274,21 +290,18 @@ NETBSDAUDIO_OpenDevice(_THIS, void *hand | | 56 | @@ -274,21 +294,18 @@ NETBSDAUDIO_OpenDevice(_THIS, void *hand |
53 | | | 57 | |
54 | this->spec.format = format; | | 58 | this->spec.format = format; |
55 | | | 59 | |
56 | - /* Calculate spec parameters based on our chosen format */ | | 60 | - /* Calculate spec parameters based on our chosen format */ |
57 | - SDL_CalculateAudioSpec(&this->spec); | | 61 | - SDL_CalculateAudioSpec(&this->spec); |
58 | - | | 62 | - |
59 | info.mode = iscapture ? AUMODE_RECORD : AUMODE_PLAY; | | 63 | info.mode = iscapture ? AUMODE_RECORD : AUMODE_PLAY; |
60 | - info.blocksize = this->spec.size; | | 64 | - info.blocksize = this->spec.size; |
61 | info.hiwat = 5; | | 65 | info.hiwat = 5; |
62 | info.lowat = 3; | | 66 | info.lowat = 3; |
63 | - prinfo->sample_rate = this->spec.freq; | | 67 | - prinfo->sample_rate = this->spec.freq; |
64 | - prinfo->channels = this->spec.channels; | | 68 | - prinfo->channels = this->spec.channels; |
65 | (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info); | | 69 | (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info); |