Skip to content

Commit

Permalink
bgm_xyscope: add 24 bit support (because @vifino asked nicely)
Browse files Browse the repository at this point in the history
  • Loading branch information
fridtjof committed Jan 1, 2025
1 parent 75eb5e3 commit 8d06b9e
Showing 1 changed file with 53 additions and 28 deletions.
81 changes: 53 additions & 28 deletions src/modules/bgm_xyscope.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define PLOSSFAC ((BUFFER_FRAMES) / 64)

enum samplesize {
SIZE_8, SIZE_16, SIZE_32
SIZE_8, SIZE_16, SIZE_24, SIZE_32
};

static snd_pcm_t * scope_pcm;
Expand Down Expand Up @@ -108,7 +108,19 @@ static void * thread_func(void * ign) {
frames = snd_pcm_recover(scope_pcm, frames, 0);
if (frames < 0)
printf("Warning: reading totally failed: %i, %s\n", frames, snd_strerror(frames));
if (sf_sampsize == SIZE_16) {
if (sf_sampsize == SIZE_32) {
if (sf_us) {
LD_ALGORITHM(unsigned int, 24, 0);
} else {
LD_ALGORITHM(unsigned int, 24, 0x80);
}
} else if (sf_sampsize == SIZE_24) {
if (sf_us) {
LD_ALGORITHM(unsigned int, 16, 0);
} else {
LD_ALGORITHM(unsigned int, 16, 0x80);
}
} else if (sf_sampsize == SIZE_16) {
if (sf_us) {
LD_ALGORITHM(unsigned short, 8, 0);
} else {
Expand All @@ -120,12 +132,6 @@ static void * thread_func(void * ign) {
} else {
LD_ALGORITHM(byte, 0, 0x80);
}
} else if (sf_sampsize == SIZE_32) {
if (sf_us) {
LD_ALGORITHM(unsigned int, 24, 0);
} else {
LD_ALGORITHM(unsigned int, 24, 0x80);
}
}
// This actually connects it all together
for (int i = 0; i < frames; i++) {
Expand Down Expand Up @@ -248,10 +254,14 @@ int init(int modulen, char* argstr) {
printf("Got BS8C2\n");
sf_2c = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S16, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
printf("Got BS16C2\n");
sf_sampsize = SIZE_16;
sf_2c = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S32, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
printf("Got BS16C2\n");
sf_sampsize = SIZE_16;
sf_2c = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S24, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
printf("Got BS24C2\n");
sf_sampsize = SIZE_24;
sf_2c = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S32, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
printf("Got BS32C2\n");
sf_sampsize = SIZE_32;
sf_2c = 1;
Expand All @@ -260,11 +270,16 @@ int init(int modulen, char* argstr) {
sf_2c = 1;
sf_us = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U16, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
printf("Got BU16C2\n");
sf_sampsize = SIZE_16;
sf_2c = 1;
sf_us = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U32, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
printf("Got BU16C2\n");
sf_sampsize = SIZE_16;
sf_2c = 1;
sf_us = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U24, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
printf("Got BU24C2\n");
sf_sampsize = SIZE_24;
sf_2c = 1;
sf_us = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U32, SND_PCM_ACCESS_RW_INTERLEAVED, 2, SAMPLE_RATE, 1, 1000))) {
printf("Got BU32C2\n");
sf_sampsize = SIZE_32;
sf_2c = 1;
Expand All @@ -276,17 +291,24 @@ int init(int modulen, char* argstr) {
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S16, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
printf("Got BS16C1\n");
sf_sampsize = SIZE_16;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S32, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
printf("Got BS32C1\n");
sf_sampsize = SIZE_32;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U8, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S24, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
printf("Got BS24C1\n");
sf_sampsize = SIZE_24;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_S32, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
printf("Got BS32C1\n");
sf_sampsize = SIZE_32;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U8, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
printf("Got BU8C1\n");
sf_us = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U16, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
printf("Got BU16C1\n");
sf_sampsize = SIZE_16;
sf_us = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U32, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
printf("Got BU16C1\n");
sf_sampsize = SIZE_16;
sf_us = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U24, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
printf("Got BU24C1\n");
sf_sampsize = SIZE_24;
sf_us = 1;
} else if (!(code = snd_pcm_set_params(scope_pcm, SND_PCM_FORMAT_U32, SND_PCM_ACCESS_RW_INTERLEAVED, 1, SAMPLE_RATE, 1, 1000))) {
printf("Got BU32C1\n");
sf_sampsize = SIZE_32;
sf_us = 1;
Expand All @@ -303,9 +325,12 @@ int init(int modulen, char* argstr) {
case SIZE_8:
bytesPerSample = 1;
break;
case SIZE_16:
bytesPerSample = 2;
break;
case SIZE_16:
bytesPerSample = 2;
break;
case SIZE_24:
bytesPerSample = 3;
break;
case SIZE_32:
bytesPerSample = 4;
break;
Expand Down

0 comments on commit 8d06b9e

Please sign in to comment.