sad

simple audio daemon
git clone git@git.2f30.org/sad.git
Log | Files | Refs | LICENSE

pcm.c (667B)


      1 #include <sys/select.h>
      2 
      3 #include <limits.h>
      4 #include <stdio.h>
      5 
      6 #include "sad.h"
      7 
      8 void
      9 s16monotostereo(short *in, short *out, size_t nsamples)
     10 {
     11 	size_t i;
     12 
     13 	for (i = 0; i < nsamples; i++) {
     14 		out[i * 2] = in[i];
     15 		out[i * 2 + 1] = in[i];
     16 	}
     17 }
     18 
     19 void
     20 s16stereotomono(short *in, short *out, size_t nsamples)
     21 {
     22 	size_t i;
     23 
     24 	for (i = 0; i < nsamples; i++)
     25 		out[i] = in[i * 2] / 2 + in[i * 2 + 1] / 2;
     26 }
     27 
     28 void
     29 s16tofloat(short *in, float *out, size_t nsamples)
     30 {
     31 	size_t i;
     32 
     33 	for (i = 0; i < nsamples; i++)
     34 		out[i] = in[i] / 32768.f;
     35 }
     36 
     37 void
     38 floattos16(float *in, short *out, size_t nsamples)
     39 {
     40 	size_t i;
     41 
     42 	for (i = 0; i < nsamples; i++)
     43 		out[i] = in[i] * 32768.f;
     44 }