Skip to content

Commit fc11028

Browse files
committed
bgm_xyscope: add 24 bit support (because @vifino asked nicely)
1 parent 7156705 commit fc11028

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

src/modules/bgm_xyscope.c

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#define PLOSSFAC ((BUFFER_FRAMES) / 64)
2626

2727
enum samplesize {
28-
SIZE_8, SIZE_16, SIZE_32
28+
SIZE_8, SIZE_16, SIZE_24, SIZE_32
2929
};
3030

3131
static snd_pcm_t * scope_pcm;
@@ -108,7 +108,19 @@ static void * thread_func(void * ign) {
108108
frames = snd_pcm_recover(scope_pcm, frames, 0);
109109
if (frames < 0)
110110
printf("Warning: reading totally failed: %i, %s\n", frames, snd_strerror(frames));
111-
if (sf_sampsize == SIZE_16) {
111+
if (sf_sampsize == SIZE_32) {
112+
if (sf_us) {
113+
LD_ALGORITHM(unsigned int, 24, 0);
114+
} else {
115+
LD_ALGORITHM(unsigned int, 24, 0x80);
116+
}
117+
} else if (sf_sampsize == SIZE_24) {
118+
if (sf_us) {
119+
LD_ALGORITHM(unsigned int, 16, 0);
120+
} else {
121+
LD_ALGORITHM(unsigned int, 16, 0x80);
122+
}
123+
} else if (sf_sampsize == SIZE_16) {
112124
if (sf_us) {
113125
LD_ALGORITHM(unsigned short, 8, 0);
114126
} else {
@@ -120,12 +132,6 @@ static void * thread_func(void * ign) {
120132
} else {
121133
LD_ALGORITHM(byte, 0, 0x80);
122134
}
123-
} else if (sf_sampsize == SIZE_32) {
124-
if (sf_us) {
125-
LD_ALGORITHM(unsigned int, 24, 0);
126-
} else {
127-
LD_ALGORITHM(unsigned int, 24, 0x80);
128-
}
129135
}
130136
// This actually connects it all together
131137
for (int i = 0; i < frames; i++) {
@@ -251,6 +257,10 @@ int init(int modulen, char* argstr) {
251257
printf("Got BS16C2\n");
252258
sf_sampsize = SIZE_16;
253259
sf_2c = 1;
260+
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S24, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
261+
printf("Got BS24C2\n");
262+
sf_sampsize = SIZE_24;
263+
sf_2c = 1;
254264
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S32, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
255265
printf("Got BS32C2\n");
256266
sf_sampsize = SIZE_32;
@@ -264,6 +274,11 @@ int init(int modulen, char* argstr) {
264274
sf_sampsize = SIZE_16;
265275
sf_2c = 1;
266276
sf_us = 1;
277+
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U24, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
278+
printf("Got BU24C2\n");
279+
sf_sampsize = SIZE_24;
280+
sf_2c = 1;
281+
sf_us = 1;
267282
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U32, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
268283
printf("Got BU32C2\n");
269284
sf_sampsize = SIZE_32;
@@ -276,6 +291,9 @@ int init(int modulen, char* argstr) {
276291
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S16, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
277292
printf("Got BS16C1\n");
278293
sf_sampsize = SIZE_16;
294+
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S24, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
295+
printf("Got BS24C1\n");
296+
sf_sampsize = SIZE_24;
279297
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S32, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
280298
printf("Got BS32C1\n");
281299
sf_sampsize = SIZE_32;
@@ -286,6 +304,10 @@ int init(int modulen, char* argstr) {
286304
printf("Got BU16C1\n");
287305
sf_sampsize = SIZE_16;
288306
sf_us = 1;
307+
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U24, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
308+
printf("Got BU24C1\n");
309+
sf_sampsize = SIZE_24;
310+
sf_us = 1;
289311
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U32, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
290312
printf("Got BU32C1\n");
291313
sf_sampsize = SIZE_32;
@@ -305,7 +327,10 @@ int init(int modulen, char* argstr) {
305327
break;
306328
case SIZE_16:
307329
bytesPerSample = 2;
308-
break;
330+
break;
331+
case SIZE_24:
332+
bytesPerSample = 3;
333+
break;
309334
case SIZE_32:
310335
bytesPerSample = 4;
311336
break;

0 commit comments

Comments
 (0)