Changeset 3459:d5eff217fea2 in roaraudio
 Timestamp:
 02/13/10 21:56:57 (10 years ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libroarpulse/volume.c
r3458 r3459 40 40 41 41 /** Return nonzero when *a == *b */ 42 int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b); 42 int pa_cvolume_equal(const pa_cvolume *a, const pa_cvolume *b) { 43 int i; 44 45 if ( a == b ) 46 return 1; 47 48 if ( a == NULL  b == NULL ) 49 return 0; 50 51 if ( a>channels != b>channels ) 52 return 0; 53 54 for (i = 0; i < a>channels; i++) 55 if ( a>values[i] != b>values[i] ) 56 return 0; 57 58 return 1; 59 } 43 60 44 61 /** Set the volume of all channels to the specified parameter */ 45 pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v); 62 pa_cvolume* pa_cvolume_set(pa_cvolume *a, unsigned channels, pa_volume_t v) { 63 int i; 64 65 if ( a == NULL ) 66 return NULL; 67 68 if ( channels > PA_CHANNELS_MAX ) 69 return NULL; 70 71 a>channels = channels; 72 73 for (i = 0; i < channels; i++) { 74 a>values[i] = v; 75 } 76 77 return a; 78 } 46 79 47 80 /** Pretty print a volume structure */ … … 49 82 50 83 /** Return the average volume of all channels */ 51 pa_volume_t pa_cvolume_avg(const pa_cvolume *a); 84 pa_volume_t pa_cvolume_avg(const pa_cvolume *a) { 85 int64_t sum = 0; 86 int i; 87 88 #ifndef PA_VOLUME_INVALID 89 #define PA_VOLUME_INVALID ((pa_volume_t) UINT32_MAX) 90 #endif 91 92 if ( a == NULL ) 93 return PA_VOLUME_INVALID; 94 95 for (i = 0; i < a>channels; i++) 96 sum += a>values[i]; 97 98 return sum/a>channels; 99 } 52 100 53 101 /** Return TRUE when the passed cvolume structure is valid, FALSE otherwise */ 54 int pa_cvolume_valid(const pa_cvolume *v); 102 int pa_cvolume_valid(const pa_cvolume *v) { 103 if ( v == NULL ) 104 return 0; 105 106 if ( v>channels <= 0 ) 107 return 0; 108 109 if ( v>channels > PA_CHANNELS_MAX ) 110 return 0; 111 112 return 1; 113 } 55 114 56 115 /** Return nonzero if the volume of all channels is equal to the specified value */ 57 int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v); 116 int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) { 117 int i; 118 119 if ( a == NULL ) 120 return 0; 121 122 for (i = 0; i < a>channels; i++) 123 if ( a>values[i] != v ) 124 return 0; 125 126 return 1; 127 } 58 128 59 129 /** Multiply two volumes specifications, return the result. This uses PA_VOLUME_NORM as neutral element of multiplication. This is only valid for software volumes! */
Note: See TracChangeset
for help on using the changeset viewer.