diff mbox

[1/1] dmix: Add support for S24_3BE format.

Message ID 1392483271-20453-2-git-send-email-v.vinel@gmail.com (mailing list archive)
State Rejected
Delegated to: Takashi Iwai
Headers show

Commit Message

Vincent Vinel Feb. 15, 2014, 4:54 p.m. UTC
Add swapped versions of generic_mix_areas_24() and
generic_remix_areas_24().

Signed-off-by: Vincent Vinel <v.vinel@gmail.com>

Comments

Clemens Ladisch Feb. 16, 2014, 1:26 p.m. UTC | #1
Vincent Vinel wrote:
> Add swapped versions of generic_mix_areas_24() and
> generic_remix_areas_24().

What for?


Regards,
Clemens
Vincent Vinel Feb. 16, 2014, 7:51 p.m. UTC | #2
On 02/16/14 14:26, Clemens Ladisch wrote:
> Vincent Vinel wrote:
>> Add swapped versions of generic_mix_areas_24() and
>> generic_remix_areas_24().
> What for?
>

To use dmix with soundcards only supporting S24_3BE format, i.e. those 
using snd-usb-caiaq driver.
Takashi Iwai Feb. 17, 2014, 9:10 a.m. UTC | #3
At Sat, 15 Feb 2014 17:54:31 +0100,
Vincent Vinel wrote:
> 
> Add swapped versions of generic_mix_areas_24() and
> generic_remix_areas_24().
> 
> Signed-off-by: Vincent Vinel <v.vinel@gmail.com>
> 
> diff --git a/include/pcm.h b/include/pcm.h
> index 95b8aed..9be595c 100644
> --- a/include/pcm.h
> +++ b/include/pcm.h
> @@ -222,6 +222,8 @@ typedef enum _snd_pcm_format {
>  	SND_PCM_FORMAT_S24 = SND_PCM_FORMAT_S24_LE,
>  	/** Unsigned 24 bit CPU endian */
>  	SND_PCM_FORMAT_U24 = SND_PCM_FORMAT_U24_LE,
> +	/** Signed 24 bit CPU endian in 3bytes format */
> +	SND_PCM_FORMAT_S24_3 = SND_PCM_FORMAT_S24_3LE,
>  	/** Signed 32 bit CPU endian */
>  	SND_PCM_FORMAT_S32 = SND_PCM_FORMAT_S32_LE,
>  	/** Unsigned 32 bit CPU endian */
> @@ -241,6 +243,8 @@ typedef enum _snd_pcm_format {
>  	SND_PCM_FORMAT_S24 = SND_PCM_FORMAT_S24_BE,
>  	/** Unsigned 24 bit CPU endian */
>  	SND_PCM_FORMAT_U24 = SND_PCM_FORMAT_U24_BE,
> +	/** Signed 24 bit CPU endian in 3bytes format */
> +	SND_PCM_FORMAT_S24_3 = SND_PCM_FORMAT_S24_3BE,
>  	/** Signed 32 bit CPU endian */
>  	SND_PCM_FORMAT_S32 = SND_PCM_FORMAT_S32_BE,
>  	/** Unsigned 32 bit CPU endian */

Please split this as a separate patch.


> diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c
> index 5416cf7..1a98d8f 100644
> --- a/src/pcm/pcm_direct.c
> +++ b/src/pcm/pcm_direct.c
> @@ -909,7 +909,8 @@ int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
>  			SND_PCM_FORMAT_S16,
>  			SND_PCM_FORMAT_S16 ^ SND_PCM_FORMAT_S16_LE ^ SND_PCM_FORMAT_S16_BE,
>  			SND_PCM_FORMAT_S24_LE,
> -			SND_PCM_FORMAT_S24_3LE,
> +			SND_PCM_FORMAT_S24_3,
> +			SND_PCM_FORMAT_S24_3 ^ SND_PCM_FORMAT_S24_3LE ^ SND_PCM_FORMAT_S24_3BE,
>  			SND_PCM_FORMAT_U8,
>  		};
>  		snd_pcm_format_t format;
> diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
> index 4aa6d4e..46ca289 100644
> --- a/src/pcm/pcm_dmix.c
> +++ b/src/pcm/pcm_dmix.c
> @@ -179,6 +179,7 @@ static void mix_areas(snd_pcm_direct_t *dmix,
>  		do_mix_areas = (mix_areas_t *)dmix->u.dmix.mix_areas_24;
>  		break;
>  	case SND_PCM_FORMAT_S24_3LE:
> +	case SND_PCM_FORMAT_S24_3BE:
>  		sample_size = 3;
>  		do_mix_areas = (mix_areas_t *)dmix->u.dmix.mix_areas_24;
>  		break;
> @@ -247,6 +248,7 @@ static void remix_areas(snd_pcm_direct_t *dmix,
>  		do_remix_areas = (mix_areas_t *)dmix->u.dmix.remix_areas_24;
>  		break;
>  	case SND_PCM_FORMAT_S24_3LE:
> +	case SND_PCM_FORMAT_S24_3BE:
>  		sample_size = 3;
>  		do_remix_areas = (mix_areas_t *)dmix->u.dmix.remix_areas_24;
>  		break;
> diff --git a/src/pcm/pcm_dmix_generic.c b/src/pcm/pcm_dmix_generic.c
> index 9e9d3c3..91abd88 100644
> --- a/src/pcm/pcm_dmix_generic.c
> +++ b/src/pcm/pcm_dmix_generic.c
> @@ -123,6 +123,7 @@ static void mix_select_callbacks(snd_pcm_direct_t *dmix)
>  	((1ULL << SND_PCM_FORMAT_S16_LE) | (1ULL << SND_PCM_FORMAT_S32_LE) |\
>  	 (1ULL << SND_PCM_FORMAT_S16_BE) | (1ULL << SND_PCM_FORMAT_S32_BE) |\
>  	 (1ULL << SND_PCM_FORMAT_S24_LE) | (1ULL << SND_PCM_FORMAT_S24_3LE) | \
> +	 (1ULL << SND_PCM_FORMAT_S24_3BE) |\
>  	 (1ULL << SND_PCM_FORMAT_U8))
>  
>  #include <byteswap.h>
> @@ -387,8 +388,7 @@ static void generic_remix_areas_32_swap(unsigned int size,
>  	}
>  }
>  
> -/* always little endian */
> -static void generic_mix_areas_24(unsigned int size,
> +static void generic_mix_areas_24_native(unsigned int size,
>  				 volatile unsigned char *dst,
>  				 unsigned char *src,
>  				 volatile signed int *sum,
> @@ -421,7 +421,40 @@ static void generic_mix_areas_24(unsigned int size,
>  	}
>  }
>  
> -static void generic_remix_areas_24(unsigned int size,
> +static void generic_mix_areas_24_swap(unsigned int size,
> +				 volatile unsigned char *dst,
> +				 unsigned char *src,
> +				 volatile signed int *sum,
> +				 size_t dst_step,
> +				 size_t src_step,
> +				 size_t sum_step)
> +{
> +	register signed int sample;
> +
> +	for (;;) {
> +		sample = src[2] | (src[1] << 8) | (((signed char *)src)[0] << 16);
> +		if (!(dst[0] | dst[1] | dst[2])) {
> +			*sum = sample;
> +		} else {
> +			sample += *sum;
> +			*sum = sample;
> +			if (sample > 0x7fffff)
> +				sample = 0x7fffff;
> +			else if (sample < -0x800000)
> +				sample = -0x800000;
> +		}
> +		dst[2] = sample;
> +		dst[1] = sample >> 8;
> +		dst[0] = sample >> 16;
> +		if (!--size)
> +			return;
> +		dst += dst_step;
> +		src += src_step;
> +		sum = (signed int *) ((char *)sum + sum_step);
> +	}
> +}
> +
> +static void generic_remix_areas_24_native(unsigned int size,
>  				   volatile unsigned char *dst,
>  				   unsigned char *src,
>  				   volatile signed int *sum,
> @@ -454,6 +487,38 @@ static void generic_remix_areas_24(unsigned int size,
>  	}
>  }
>  
> +static void generic_remix_areas_24_swap(unsigned int size,
> +				   volatile unsigned char *dst,
> +				   unsigned char *src,
> +				   volatile signed int *sum,
> +				   size_t dst_step,
> +				   size_t src_step,
> +				   size_t sum_step)
> +{
> +	register signed int sample;
> +
> +	for (;;) {
> +		sample = src[2] | (src[1] << 8) | (((signed char *)src)[0] << 16);
> +		if (!(dst[0] | dst[1] | dst[2])) {
> +			sample = -sample;
> +			*sum = sample;
> +		} else {
> +			*sum = sample = *sum - sample;
> +			if (sample > 0x7fffff)
> +				sample = 0x7fffff;
> +			else if (sample < -0x800000)
> +				sample = -0x800000;
> +		}
> +		dst[2] = sample;
> +		dst[1] = sample >> 8;
> +		dst[0] = sample >> 16;
> +		if (!--size)
> +			return;
> +		dst += dst_step;
> +		src += src_step;
> +		sum = (signed int *) ((char *)sum + sum_step);
> +	}
> +}
>  static void generic_mix_areas_u8(unsigned int size,
>  				 volatile unsigned char *dst,
>  				 unsigned char *src,
> @@ -518,17 +583,19 @@ static void generic_mix_select_callbacks(snd_pcm_direct_t *dmix)
>  	if (snd_pcm_format_cpu_endian(dmix->shmptr->s.format)) {
>  		dmix->u.dmix.mix_areas_16 = generic_mix_areas_16_native;
>  		dmix->u.dmix.mix_areas_32 = generic_mix_areas_32_native;
> +		dmix->u.dmix.mix_areas_24 = generic_mix_areas_24_native;
>  		dmix->u.dmix.remix_areas_16 = generic_remix_areas_16_native;
>  		dmix->u.dmix.remix_areas_32 = generic_remix_areas_32_native;
> +		dmix->u.dmix.remix_areas_24 = generic_remix_areas_24_native;
>  	} else {
>  		dmix->u.dmix.mix_areas_16 = generic_mix_areas_16_swap;
>  		dmix->u.dmix.mix_areas_32 = generic_mix_areas_32_swap;
> +		dmix->u.dmix.mix_areas_24 = generic_mix_areas_24_swap;
>  		dmix->u.dmix.remix_areas_16 = generic_remix_areas_16_swap;
>  		dmix->u.dmix.remix_areas_32 = generic_remix_areas_32_swap;
> +		dmix->u.dmix.remix_areas_24 = generic_remix_areas_24_swap;
>  	}
> -	dmix->u.dmix.mix_areas_24 = generic_mix_areas_24;
>  	dmix->u.dmix.mix_areas_u8 = generic_mix_areas_u8;
> -	dmix->u.dmix.remix_areas_24 = generic_remix_areas_24;
>  	dmix->u.dmix.remix_areas_u8 = generic_remix_areas_u8;
>  }

S24_BE can be added very similarly.  Please either merge into the
patch or create another patch.


thanks,

Takashi
diff mbox

Patch

diff --git a/include/pcm.h b/include/pcm.h
index 95b8aed..9be595c 100644
--- a/include/pcm.h
+++ b/include/pcm.h
@@ -222,6 +222,8 @@  typedef enum _snd_pcm_format {
 	SND_PCM_FORMAT_S24 = SND_PCM_FORMAT_S24_LE,
 	/** Unsigned 24 bit CPU endian */
 	SND_PCM_FORMAT_U24 = SND_PCM_FORMAT_U24_LE,
+	/** Signed 24 bit CPU endian in 3bytes format */
+	SND_PCM_FORMAT_S24_3 = SND_PCM_FORMAT_S24_3LE,
 	/** Signed 32 bit CPU endian */
 	SND_PCM_FORMAT_S32 = SND_PCM_FORMAT_S32_LE,
 	/** Unsigned 32 bit CPU endian */
@@ -241,6 +243,8 @@  typedef enum _snd_pcm_format {
 	SND_PCM_FORMAT_S24 = SND_PCM_FORMAT_S24_BE,
 	/** Unsigned 24 bit CPU endian */
 	SND_PCM_FORMAT_U24 = SND_PCM_FORMAT_U24_BE,
+	/** Signed 24 bit CPU endian in 3bytes format */
+	SND_PCM_FORMAT_S24_3 = SND_PCM_FORMAT_S24_3BE,
 	/** Signed 32 bit CPU endian */
 	SND_PCM_FORMAT_S32 = SND_PCM_FORMAT_S32_BE,
 	/** Unsigned 32 bit CPU endian */
diff --git a/src/pcm/pcm_direct.c b/src/pcm/pcm_direct.c
index 5416cf7..1a98d8f 100644
--- a/src/pcm/pcm_direct.c
+++ b/src/pcm/pcm_direct.c
@@ -909,7 +909,8 @@  int snd_pcm_direct_initialize_slave(snd_pcm_direct_t *dmix, snd_pcm_t *spcm, str
 			SND_PCM_FORMAT_S16,
 			SND_PCM_FORMAT_S16 ^ SND_PCM_FORMAT_S16_LE ^ SND_PCM_FORMAT_S16_BE,
 			SND_PCM_FORMAT_S24_LE,
-			SND_PCM_FORMAT_S24_3LE,
+			SND_PCM_FORMAT_S24_3,
+			SND_PCM_FORMAT_S24_3 ^ SND_PCM_FORMAT_S24_3LE ^ SND_PCM_FORMAT_S24_3BE,
 			SND_PCM_FORMAT_U8,
 		};
 		snd_pcm_format_t format;
diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c
index 4aa6d4e..46ca289 100644
--- a/src/pcm/pcm_dmix.c
+++ b/src/pcm/pcm_dmix.c
@@ -179,6 +179,7 @@  static void mix_areas(snd_pcm_direct_t *dmix,
 		do_mix_areas = (mix_areas_t *)dmix->u.dmix.mix_areas_24;
 		break;
 	case SND_PCM_FORMAT_S24_3LE:
+	case SND_PCM_FORMAT_S24_3BE:
 		sample_size = 3;
 		do_mix_areas = (mix_areas_t *)dmix->u.dmix.mix_areas_24;
 		break;
@@ -247,6 +248,7 @@  static void remix_areas(snd_pcm_direct_t *dmix,
 		do_remix_areas = (mix_areas_t *)dmix->u.dmix.remix_areas_24;
 		break;
 	case SND_PCM_FORMAT_S24_3LE:
+	case SND_PCM_FORMAT_S24_3BE:
 		sample_size = 3;
 		do_remix_areas = (mix_areas_t *)dmix->u.dmix.remix_areas_24;
 		break;
diff --git a/src/pcm/pcm_dmix_generic.c b/src/pcm/pcm_dmix_generic.c
index 9e9d3c3..91abd88 100644
--- a/src/pcm/pcm_dmix_generic.c
+++ b/src/pcm/pcm_dmix_generic.c
@@ -123,6 +123,7 @@  static void mix_select_callbacks(snd_pcm_direct_t *dmix)
 	((1ULL << SND_PCM_FORMAT_S16_LE) | (1ULL << SND_PCM_FORMAT_S32_LE) |\
 	 (1ULL << SND_PCM_FORMAT_S16_BE) | (1ULL << SND_PCM_FORMAT_S32_BE) |\
 	 (1ULL << SND_PCM_FORMAT_S24_LE) | (1ULL << SND_PCM_FORMAT_S24_3LE) | \
+	 (1ULL << SND_PCM_FORMAT_S24_3BE) |\
 	 (1ULL << SND_PCM_FORMAT_U8))
 
 #include <byteswap.h>
@@ -387,8 +388,7 @@  static void generic_remix_areas_32_swap(unsigned int size,
 	}
 }
 
-/* always little endian */
-static void generic_mix_areas_24(unsigned int size,
+static void generic_mix_areas_24_native(unsigned int size,
 				 volatile unsigned char *dst,
 				 unsigned char *src,
 				 volatile signed int *sum,
@@ -421,7 +421,40 @@  static void generic_mix_areas_24(unsigned int size,
 	}
 }
 
-static void generic_remix_areas_24(unsigned int size,
+static void generic_mix_areas_24_swap(unsigned int size,
+				 volatile unsigned char *dst,
+				 unsigned char *src,
+				 volatile signed int *sum,
+				 size_t dst_step,
+				 size_t src_step,
+				 size_t sum_step)
+{
+	register signed int sample;
+
+	for (;;) {
+		sample = src[2] | (src[1] << 8) | (((signed char *)src)[0] << 16);
+		if (!(dst[0] | dst[1] | dst[2])) {
+			*sum = sample;
+		} else {
+			sample += *sum;
+			*sum = sample;
+			if (sample > 0x7fffff)
+				sample = 0x7fffff;
+			else if (sample < -0x800000)
+				sample = -0x800000;
+		}
+		dst[2] = sample;
+		dst[1] = sample >> 8;
+		dst[0] = sample >> 16;
+		if (!--size)
+			return;
+		dst += dst_step;
+		src += src_step;
+		sum = (signed int *) ((char *)sum + sum_step);
+	}
+}
+
+static void generic_remix_areas_24_native(unsigned int size,
 				   volatile unsigned char *dst,
 				   unsigned char *src,
 				   volatile signed int *sum,
@@ -454,6 +487,38 @@  static void generic_remix_areas_24(unsigned int size,
 	}
 }
 
+static void generic_remix_areas_24_swap(unsigned int size,
+				   volatile unsigned char *dst,
+				   unsigned char *src,
+				   volatile signed int *sum,
+				   size_t dst_step,
+				   size_t src_step,
+				   size_t sum_step)
+{
+	register signed int sample;
+
+	for (;;) {
+		sample = src[2] | (src[1] << 8) | (((signed char *)src)[0] << 16);
+		if (!(dst[0] | dst[1] | dst[2])) {
+			sample = -sample;
+			*sum = sample;
+		} else {
+			*sum = sample = *sum - sample;
+			if (sample > 0x7fffff)
+				sample = 0x7fffff;
+			else if (sample < -0x800000)
+				sample = -0x800000;
+		}
+		dst[2] = sample;
+		dst[1] = sample >> 8;
+		dst[0] = sample >> 16;
+		if (!--size)
+			return;
+		dst += dst_step;
+		src += src_step;
+		sum = (signed int *) ((char *)sum + sum_step);
+	}
+}
 static void generic_mix_areas_u8(unsigned int size,
 				 volatile unsigned char *dst,
 				 unsigned char *src,
@@ -518,17 +583,19 @@  static void generic_mix_select_callbacks(snd_pcm_direct_t *dmix)
 	if (snd_pcm_format_cpu_endian(dmix->shmptr->s.format)) {
 		dmix->u.dmix.mix_areas_16 = generic_mix_areas_16_native;
 		dmix->u.dmix.mix_areas_32 = generic_mix_areas_32_native;
+		dmix->u.dmix.mix_areas_24 = generic_mix_areas_24_native;
 		dmix->u.dmix.remix_areas_16 = generic_remix_areas_16_native;
 		dmix->u.dmix.remix_areas_32 = generic_remix_areas_32_native;
+		dmix->u.dmix.remix_areas_24 = generic_remix_areas_24_native;
 	} else {
 		dmix->u.dmix.mix_areas_16 = generic_mix_areas_16_swap;
 		dmix->u.dmix.mix_areas_32 = generic_mix_areas_32_swap;
+		dmix->u.dmix.mix_areas_24 = generic_mix_areas_24_swap;
 		dmix->u.dmix.remix_areas_16 = generic_remix_areas_16_swap;
 		dmix->u.dmix.remix_areas_32 = generic_remix_areas_32_swap;
+		dmix->u.dmix.remix_areas_24 = generic_remix_areas_24_swap;
 	}
-	dmix->u.dmix.mix_areas_24 = generic_mix_areas_24;
 	dmix->u.dmix.mix_areas_u8 = generic_mix_areas_u8;
-	dmix->u.dmix.remix_areas_24 = generic_remix_areas_24;
 	dmix->u.dmix.remix_areas_u8 = generic_remix_areas_u8;
 }