Changeset 2931:b35c453d35e9 in roaraudio for libroardsp/mixer.c
- Timestamp:
- 10/16/09 21:10:17 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libroardsp/mixer.c
r2930 r2931 25 25 #include "libroardsp.h" 26 26 27 int roar_mix_pcm (void * output, int bits, void ** input, int samples) { 28 switch (bits) { 29 case 8: return roar_mix_pcm_8bit (output, (int8_t **)input, samples); break; 30 case 16: return roar_mix_pcm_16bit(output, (int16_t **)input, samples); break; 31 case 24: return roar_mix_pcm_24bit(output, input, samples); break; 32 case 32: return roar_mix_pcm_32bit(output, (int32_t **)input, samples); break; 33 default: return -1; 34 } 35 } 36 37 int roar_mix_pcm_8bit (int8_t * output, int8_t ** input, int samples) { 38 int i, s; 39 register int c; 40 41 for (s = 0; s < samples; s++) { 42 c = 0; 43 44 for (i = 0; input[i] != NULL; i++) 45 c += input[i][s]; 46 47 if ( c > 127 ) 48 c = 127; 49 else if ( c < -128 ) 50 c = -128; 51 output[s] = (char)c; 52 } 53 54 return 0; 55 } 56 57 int roar_mix_pcm_16bit (int16_t * output, int16_t ** input, int samples) { 58 int i, s; 59 register int_least32_t c; 60 61 #ifdef DEBUG 62 for (i = 0; input[i] != NULL; i++) 63 ROAR_DBG("mix_clients_16bit(*): input[%i] = %p", i, input[i]); 64 #endif 65 66 for (s = 0; s < samples; s++) { 67 c = 0; 68 for (i = 0; input[i] != NULL; i++) { 69 c += input[i][s]; 70 } 71 72 if ( c > 32767 ) 73 c = 32767; 74 else if ( c < -32768 ) 75 c = -32768; 76 77 output[s] = c; 78 } 79 80 return 0; 81 } 82 83 int roar_mix_pcm_24bit (void * output, void ** input, int samples) { 84 return -1; 85 } 86 87 int roar_mix_pcm_32bit (int32_t * output, int32_t ** input, int samples) { 88 #ifdef ROAR_NATIVE_INT64 89 int i, s; 90 ROAR_NATIVE_INT64 c; 91 92 for (s = 0; s < samples; s++) { 93 c = 0; 94 95 for (i = 0; input[i]; i++) 96 c += input[i][s]; 97 98 if ( c > 21474836487LL ) 99 c = 2147483647LL; 100 else if ( c < -2147483648LL ) 101 c = -2147483648LL; 102 output[s] = (int32_t)c; 103 } 104 105 return 0; 106 #else 107 return -1; 108 #endif 109 } 110 27 111 28 112 //ll
Note: See TracChangeset
for help on using the changeset viewer.