Skip to contentSkip to conversation

pcm: use the same set of uint_XX types everywhere

PATCH In review John Spencer 4 participants 7 messages Oct 2, 2013 – Oct 11, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pcm: use the same set of uint_XX types everywhere

previously, pcm.h prototyped the functions snd_pcm_format_silence* with u_int_XX types (legacy BSD types from sys/types.h),
while the implementation in pcm_misc.c used the C99 stdint.h types uint_XX.

this caused compilation errors on systems where the typedef for u_int_XX and uint_XX is not exactly the same.

we fix it by using the C99 stdint.h types everywhere.

---
 include/pcm.h      |    9 +++++----
 src/pcm/pcm_misc.c |   42 +++++++++++++++++++++---------------------
 2 files changed, 26 insertions(+), 25 deletions(-)
include/pcm.h +5 -4
index 95b8aed..cd847e4 100644
@@ -33,6 +33,7 @@
 extern "C" {
 #endif
 
+#include <stdint.h>
 /**
  *  \defgroup PCM PCM Interface
  *  See the \ref pcm page for more details.
@@ -1048,10 +1049,10 @@ int snd_pcm_format_width(snd_pcm_format_t format);			/* in bits */
 int snd_pcm_format_physical_width(snd_pcm_format_t format);		/* in bits */
 snd_pcm_format_t snd_pcm_build_linear_format(int width, int pwidth, int unsignd, int big_endian);
 ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
-u_int8_t snd_pcm_format_silence(snd_pcm_format_t format);
-u_int16_t snd_pcm_format_silence_16(snd_pcm_format_t format);
-u_int32_t snd_pcm_format_silence_32(snd_pcm_format_t format);
-u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format);
+uint8_t snd_pcm_format_silence(snd_pcm_format_t format);
+uint16_t snd_pcm_format_silence_16(snd_pcm_format_t format);
+uint32_t snd_pcm_format_silence_32(snd_pcm_format_t format);
+uint64_t snd_pcm_format_silence_64(snd_pcm_format_t format);
 int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int samples);
 
 snd_pcm_sframes_t snd_pcm_bytes_to_frames(snd_pcm_t *pcm, ssize_t bytes);
src/pcm/pcm_misc.c +21 -21

130 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#1 lore raw

Hi Takashi,

do you think this could be merged ?

thanks,
--JS

Quoted 191 lines · John Spencer

previously, pcm.h prototyped the functions snd_pcm_format_silence* with u_int_XX types (legacy BSD types from sys/types.h),
while the implementation in pcm_misc.c used the C99 stdint.h types uint_XX.

this caused compilation errors on systems where the typedef for u_int_XX and uint_XX is not exactly the same.

we fix it by using the C99 stdint.h types everywhere.

---
  include/pcm.h      |    9 +++++----
  src/pcm/pcm_misc.c |   42 +++++++++++++++++++++---------------------
  2 files changed, 26 insertions(+), 25 deletions(-)
include/pcm.h +5 -4
index 95b8aed..cd847e4 100644
@@ -33,6 +33,7 @@
  extern "C" {
  #endif
 
+#include<stdint.h>
  /**
   *  \defgroup PCM PCM Interface
   *  See the \ref pcm page for more details.
@@ -1048,10 +1049,10 @@ int snd_pcm_format_width(snd_pcm_format_t format);			/* in bits */
  int snd_pcm_format_physical_width(snd_pcm_format_t format);		/* in bits */
  snd_pcm_format_t snd_pcm_build_linear_format(int width, int pwidth, int unsignd, int big_endian);
  ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
-u_int8_t snd_pcm_format_silence(snd_pcm_format_t format);
-u_int16_t snd_pcm_format_silence_16(snd_pcm_format_t format);
-u_int32_t snd_pcm_format_silence_32(snd_pcm_format_t format);
-u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format);
+uint8_t snd_pcm_format_silence(snd_pcm_format_t format);
+uint16_t snd_pcm_format_silence_16(snd_pcm_format_t format);
+uint32_t snd_pcm_format_silence_32(snd_pcm_format_t format);
+uint64_t snd_pcm_format_silence_64(snd_pcm_format_t format);
  int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int samples);
 
  snd_pcm_sframes_t snd_pcm_bytes_to_frames(snd_pcm_t *pcm, ssize_t bytes);
src/pcm/pcm_misc.c +21 -21
index d52160c..2a8be21 100644
@@ -363,7 +363,7 @@ ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples)
   * \param format Sample format
   * \return silence 64 bit word
   */
-u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
+uint64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  {
  	switch (format) {
  	case SNDRV_PCM_FORMAT_S8:
@@ -437,7 +437,7 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  	{
  		union {
  			float f[2];
-			u_int64_t i;
+			uint64_t i;
  		} u;
  		u.f[0] = u.f[1] = 0.0;
  #ifdef SNDRV_LITTLE_ENDIAN
@@ -450,7 +450,7 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  	{
  		union {
  			double f;
-			u_int64_t i;
+			uint64_t i;
  		} u;
  		u.f = 0.0;
  #ifdef SNDRV_LITTLE_ENDIAN
@@ -463,7 +463,7 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  	{
  		union {
  			float f[2];
-			u_int64_t i;
+			uint64_t i;
  		} u;
  		u.f[0] = u.f[1] = 0.0;
  #ifdef SNDRV_LITTLE_ENDIAN
@@ -476,7 +476,7 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  	{
  		union {
  			double f;
-			u_int64_t i;
+			uint64_t i;
  		} u;
  		u.f = 0.0;
  #ifdef SNDRV_LITTLE_ENDIAN
@@ -509,10 +509,10 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
   * \param format Sample format
   * \return silence 32 bit word
   */
-u_int32_t snd_pcm_format_silence_32(snd_pcm_format_t format)
+uint32_t snd_pcm_format_silence_32(snd_pcm_format_t format)
  {
  	assert(snd_pcm_format_physical_width(format)<= 32);
-	return (u_int32_t)snd_pcm_format_silence_64(format);
+	return (uint32_t)snd_pcm_format_silence_64(format);
  }
 
  /**
@@ -520,10 +520,10 @@ u_int32_t snd_pcm_format_silence_32(snd_pcm_format_t format)
   * \param format Sample format
   * \return silence 16 bit word
   */
-u_int16_t snd_pcm_format_silence_16(snd_pcm_format_t format)
+uint16_t snd_pcm_format_silence_16(snd_pcm_format_t format)
  {
  	assert(snd_pcm_format_physical_width(format)<= 16);
-	return (u_int16_t)snd_pcm_format_silence_64(format);
+	return (uint16_t)snd_pcm_format_silence_64(format);
  }
 
  /**
@@ -531,10 +531,10 @@ u_int16_t snd_pcm_format_silence_16(snd_pcm_format_t format)
   * \param format Sample format
   * \return silence 8 bit word
   */
-u_int8_t snd_pcm_format_silence(snd_pcm_format_t format)
+uint8_t snd_pcm_format_silence(snd_pcm_format_t format)
  {
  	assert(snd_pcm_format_physical_width(format)<= 8);
-	return (u_int8_t)snd_pcm_format_silence_64(format);
+	return (uint8_t)snd_pcm_format_silence_64(format);
  }
 
  /**
@@ -550,7 +550,7 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		return 0;
  	switch (snd_pcm_format_physical_width(format)) {
  	case 4: {
-		u_int8_t silence = snd_pcm_format_silence_64(format);
+		uint8_t silence = snd_pcm_format_silence_64(format);
  		unsigned int samples1;
  		if (samples % 2 != 0)
  			return -EINVAL;
@@ -559,13 +559,13 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		break;
  	}
  	case 8: {
-		u_int8_t silence = snd_pcm_format_silence_64(format);
+		uint8_t silence = snd_pcm_format_silence_64(format);
  		memset(data, silence, samples);
  		break;
  	}
  	case 16: {
-		u_int16_t silence = snd_pcm_format_silence_64(format);
-		u_int16_t *pdata = (u_int16_t *)data;
+		uint16_t silence = snd_pcm_format_silence_64(format);
+		uint16_t *pdata = (uint16_t *)data;
  		if (! silence)
  			memset(data, 0, samples * 2);
  		else {
@@ -575,8 +575,8 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		break;
  	}
  	case 24: {
-		u_int32_t silence = snd_pcm_format_silence_64(format);
-		u_int8_t *pdata = (u_int8_t *)data;
+		uint32_t silence = snd_pcm_format_silence_64(format);
+		uint8_t *pdata = (uint8_t *)data;
  		if (! silence)
  			memset(data, 0, samples * 3);
  		else {
@@ -595,8 +595,8 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		break;
  	}
  	case 32: {
-		u_int32_t silence = snd_pcm_format_silence_64(format);
-		u_int32_t *pdata = (u_int32_t *)data;
+		uint32_t silence = snd_pcm_format_silence_64(format);
+		uint32_t *pdata = (uint32_t *)data;
  		if (! silence)
  			memset(data, 0, samples * 4);
  		else {
@@ -606,8 +606,8 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		break;
  	}
  	case 64: {
-		u_int64_t silence = snd_pcm_format_silence_64(format);
-		u_int64_t *pdata = (u_int64_t *)data;
+		uint64_t silence = snd_pcm_format_silence_64(format);
+		uint64_t *pdata = (uint64_t *)data;
  		if (! silence)
  			memset(data, 0, samples * 8);
  		else {
#2 lore raw

At Thu, 10 Oct 2013 13:48:32 +0200,

Quoted 4 lines · John Spencer

Hi Takashi,

do you think this could be merged ?

I don't think changing the format in the API header is good at this point, even if it has the same effect in the end. The API has been solid over years. For fixing the build issue, other way round, I'd suggest rather to change to u_int_xx in pcm_misc.c

thanks,

Takashi

Quoted 198 lines

thanks,
--JS

Quoted 191 lines · John Spencer

previously, pcm.h prototyped the functions snd_pcm_format_silence* with u_int_XX types (legacy BSD types from sys/types.h),
while the implementation in pcm_misc.c used the C99 stdint.h types uint_XX.

this caused compilation errors on systems where the typedef for u_int_XX and uint_XX is not exactly the same.

we fix it by using the C99 stdint.h types everywhere.

---
  include/pcm.h      |    9 +++++----
  src/pcm/pcm_misc.c |   42 +++++++++++++++++++++---------------------
  2 files changed, 26 insertions(+), 25 deletions(-)
include/pcm.h +5 -4
index 95b8aed..cd847e4 100644
@@ -33,6 +33,7 @@
  extern "C" {
  #endif
 
+#include<stdint.h>
  /**
   *  \defgroup PCM PCM Interface
   *  See the \ref pcm page for more details.
@@ -1048,10 +1049,10 @@ int snd_pcm_format_width(snd_pcm_format_t format);			/* in bits */
  int snd_pcm_format_physical_width(snd_pcm_format_t format);		/* in bits */
  snd_pcm_format_t snd_pcm_build_linear_format(int width, int pwidth, int unsignd, int big_endian);
  ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
-u_int8_t snd_pcm_format_silence(snd_pcm_format_t format);
-u_int16_t snd_pcm_format_silence_16(snd_pcm_format_t format);
-u_int32_t snd_pcm_format_silence_32(snd_pcm_format_t format);
-u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format);
+uint8_t snd_pcm_format_silence(snd_pcm_format_t format);
+uint16_t snd_pcm_format_silence_16(snd_pcm_format_t format);
+uint32_t snd_pcm_format_silence_32(snd_pcm_format_t format);
+uint64_t snd_pcm_format_silence_64(snd_pcm_format_t format);
  int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int samples);
 
  snd_pcm_sframes_t snd_pcm_bytes_to_frames(snd_pcm_t *pcm, ssize_t bytes);
src/pcm/pcm_misc.c +21 -21
index d52160c..2a8be21 100644
@@ -363,7 +363,7 @@ ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples)
   * \param format Sample format
   * \return silence 64 bit word
   */
-u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
+uint64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  {
  	switch (format) {
  	case SNDRV_PCM_FORMAT_S8:
@@ -437,7 +437,7 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  	{
  		union {
  			float f[2];
-			u_int64_t i;
+			uint64_t i;
  		} u;
  		u.f[0] = u.f[1] = 0.0;
  #ifdef SNDRV_LITTLE_ENDIAN
@@ -450,7 +450,7 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  	{
  		union {
  			double f;
-			u_int64_t i;
+			uint64_t i;
  		} u;
  		u.f = 0.0;
  #ifdef SNDRV_LITTLE_ENDIAN
@@ -463,7 +463,7 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  	{
  		union {
  			float f[2];
-			u_int64_t i;
+			uint64_t i;
  		} u;
  		u.f[0] = u.f[1] = 0.0;
  #ifdef SNDRV_LITTLE_ENDIAN
@@ -476,7 +476,7 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
  	{
  		union {
  			double f;
-			u_int64_t i;
+			uint64_t i;
  		} u;
  		u.f = 0.0;
  #ifdef SNDRV_LITTLE_ENDIAN
@@ -509,10 +509,10 @@ u_int64_t snd_pcm_format_silence_64(snd_pcm_format_t format)
   * \param format Sample format
   * \return silence 32 bit word
   */
-u_int32_t snd_pcm_format_silence_32(snd_pcm_format_t format)
+uint32_t snd_pcm_format_silence_32(snd_pcm_format_t format)
  {
  	assert(snd_pcm_format_physical_width(format)<= 32);
-	return (u_int32_t)snd_pcm_format_silence_64(format);
+	return (uint32_t)snd_pcm_format_silence_64(format);
  }
 
  /**
@@ -520,10 +520,10 @@ u_int32_t snd_pcm_format_silence_32(snd_pcm_format_t format)
   * \param format Sample format
   * \return silence 16 bit word
   */
-u_int16_t snd_pcm_format_silence_16(snd_pcm_format_t format)
+uint16_t snd_pcm_format_silence_16(snd_pcm_format_t format)
  {
  	assert(snd_pcm_format_physical_width(format)<= 16);
-	return (u_int16_t)snd_pcm_format_silence_64(format);
+	return (uint16_t)snd_pcm_format_silence_64(format);
  }
 
  /**
@@ -531,10 +531,10 @@ u_int16_t snd_pcm_format_silence_16(snd_pcm_format_t format)
   * \param format Sample format
   * \return silence 8 bit word
   */
-u_int8_t snd_pcm_format_silence(snd_pcm_format_t format)
+uint8_t snd_pcm_format_silence(snd_pcm_format_t format)
  {
  	assert(snd_pcm_format_physical_width(format)<= 8);
-	return (u_int8_t)snd_pcm_format_silence_64(format);
+	return (uint8_t)snd_pcm_format_silence_64(format);
  }
 
  /**
@@ -550,7 +550,7 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		return 0;
  	switch (snd_pcm_format_physical_width(format)) {
  	case 4: {
-		u_int8_t silence = snd_pcm_format_silence_64(format);
+		uint8_t silence = snd_pcm_format_silence_64(format);
  		unsigned int samples1;
  		if (samples % 2 != 0)
  			return -EINVAL;
@@ -559,13 +559,13 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		break;
  	}
  	case 8: {
-		u_int8_t silence = snd_pcm_format_silence_64(format);
+		uint8_t silence = snd_pcm_format_silence_64(format);
  		memset(data, silence, samples);
  		break;
  	}
  	case 16: {
-		u_int16_t silence = snd_pcm_format_silence_64(format);
-		u_int16_t *pdata = (u_int16_t *)data;
+		uint16_t silence = snd_pcm_format_silence_64(format);
+		uint16_t *pdata = (uint16_t *)data;
  		if (! silence)
  			memset(data, 0, samples * 2);
  		else {
@@ -575,8 +575,8 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		break;
  	}
  	case 24: {
-		u_int32_t silence = snd_pcm_format_silence_64(format);
-		u_int8_t *pdata = (u_int8_t *)data;
+		uint32_t silence = snd_pcm_format_silence_64(format);
+		uint8_t *pdata = (uint8_t *)data;
  		if (! silence)
  			memset(data, 0, samples * 3);
  		else {
@@ -595,8 +595,8 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		break;
  	}
  	case 32: {
-		u_int32_t silence = snd_pcm_format_silence_64(format);
-		u_int32_t *pdata = (u_int32_t *)data;
+		uint32_t silence = snd_pcm_format_silence_64(format);
+		uint32_t *pdata = (uint32_t *)data;
  		if (! silence)
  			memset(data, 0, samples * 4);
  		else {
@@ -606,8 +606,8 @@ int snd_pcm_format_set_silence(snd_pcm_format_t format, void *data, unsigned int
  		break;
  	}
  	case 64: {
-		u_int64_t silence = snd_pcm_format_silence_64(format);
-		u_int64_t *pdata = (u_int64_t *)data;
+		uint64_t silence = snd_pcm_format_silence_64(format);
+		uint64_t *pdata = (uint64_t *)data;
  		if (! silence)
  			memset(data, 0, samples * 8);
  		else {
#3 lore raw

Default volume set to maximum

Dear all,

I would like to have a default volume set to maximum for my DAC/device. Is there a way to tell alsa that my default volume is a certain value ? Best regards.

Stéphane

#4 lore raw

Re: Default volume set to maximum

Quoted 1 line · stéphane cerveau

Dear all,

Please do not reply to another message if you want to start a new thread.

Quoted 2 lines

I would like to have a default volume set to maximum for my DAC/device. Is there a way to tell alsa that my default volume is a certain value ?

The default value is whatever volume the device uses when it is powered up, and typically cannot be changed.

It is possible to change the value later. Many distributions save/ restore mixer settings when the computer is shut down/started up.

What exactly is your problem?

Regards,
Clemens

#5 lore raw

Re: Default volume set to maximum

Thx for your reply
I just wanted to know if it was possible to put some default value overriding the default alsa mixer value. Best regards.

Steph

Quoted 18 lines · Clemens Ladisch
Quoted 1 line · stéphane cerveau

Dear all,

Please do not reply to another message if you want to start a new thread.

Quoted 2 lines

I would like to have a default volume set to maximum for my DAC/device. Is there a way to tell alsa that my default volume is a certain value ?

The default value is whatever volume the device uses when it is powered up, and typically cannot be changed.

It is possible to change the value later. Many distributions save/ restore mixer settings when the computer is shut down/started up.

What exactly is your problem?

Regards,
Clemens

#6 lore raw

Re: Default volume set to maximum

Quoted 1 line · stéphane cerveau

I just wanted to know if it was possible to put some default value overriding the default alsa mixer value.

alsamixer has no default value; it always shows the current value.

Regards,
Clemens