mirror of
				https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
				synced 2025-11-03 09:01:50 -05:00 
			
		
		
		
	add new function pa_sample_clamp()
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/glitch-free@2318 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
		
							parent
							
								
									264385aae4
								
							
						
					
					
						commit
						9dd8f6ceb7
					
				
					 2 changed files with 33 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -1000,3 +1000,34 @@ pa_memchunk* pa_silence_memchunk_get(pa_silence_cache *cache, pa_mempool *pool,
 | 
			
		|||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void pa_sample_clamp(pa_sample_format_t format, void *dst, size_t dstr, const void *src, size_t sstr, unsigned n) {
 | 
			
		||||
 | 
			
		||||
    const float *s;
 | 
			
		||||
    float *d;
 | 
			
		||||
 | 
			
		||||
    if (format != PA_SAMPLE_FLOAT32BE && format != PA_SAMPLE_FLOAT32LE)
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    s = src;
 | 
			
		||||
    d = dst;
 | 
			
		||||
 | 
			
		||||
    if (format == PA_SAMPLE_FLOAT32NE) {
 | 
			
		||||
        for (; n > 0; n--) {
 | 
			
		||||
            *d = PA_CLAMP_UNLIKELY(*s, -1.0, 1.0);
 | 
			
		||||
 | 
			
		||||
            s = (const float*) ((const uint8_t*) s + sstr);
 | 
			
		||||
            d = (float*) ((uint8_t*) d + dstr);
 | 
			
		||||
        }
 | 
			
		||||
    } else
 | 
			
		||||
        for (; n > 0; n--) {
 | 
			
		||||
            float f;
 | 
			
		||||
 | 
			
		||||
            f = PA_FLOAT32_SWAP(*s);
 | 
			
		||||
            f = PA_CLAMP_UNLIKELY(f, -1.0, 1.0);
 | 
			
		||||
            *d = PA_FLOAT32_SWAP(f);
 | 
			
		||||
 | 
			
		||||
            s = (const float*) ((const uint8_t*) s + sstr);
 | 
			
		||||
            d = (float*) ((uint8_t*) d + dstr);
 | 
			
		||||
        }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -78,4 +78,6 @@ int pa_frame_aligned(size_t l, const pa_sample_spec *ss) PA_GCC_PURE;
 | 
			
		|||
void pa_interleave(const void *src[], unsigned channels, void *dst, size_t ss, unsigned n);
 | 
			
		||||
void pa_deinterleave(const void *src, void *dst[], unsigned channels, size_t ss, unsigned n);
 | 
			
		||||
 | 
			
		||||
void pa_sample_clamp(pa_sample_format_t format, void *dst, size_t dstr, const void *src, size_t sstr, unsigned n);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue