/** * @brief Process a single stereo audio sample. * * Operates only on as_conf_cache, and requires no synchronization as * long as the calling thread is always iq_thread. */ void audio_stream_put_samples(short left_sample,short right_sample) { int audio_buffer_length; sdr_thread_assert_id(&audiostream_tid); /* FIXME: This really only applies once, at startup */ if (!audio_buffer) allocate_audio_buffer(); // samples are delivered at 48K // output to stream at 8K (1 in 6) or 48K (1 in 1) // codec2 encoding works only for 8K if(sample_count==0) { int offset; // use this sample and convert to a-law or PCM or codec2 if(as_conf_cache.channels==1) { switch (as_conf_cache.encoding) { default: /* ALAW */ case ENCODING_ALAW: offset = audio_stream_buffer_insert + AUDIO_BUFFER_HEADER_SIZE; audio_buffer[offset] = alaw((left_sample + right_sample) / 2); break; case ENCODING_PCM: offset = audio_stream_buffer_insert * 2 + AUDIO_BUFFER_HEADER_SIZE; /* PCM on the wire is always LE? */ audio_buffer[offset] = (left_sample/2 + right_sample/2) & 0xff; audio_buffer[offset + 1] = (left_sample/2 + right_sample/2) >> 8; break; case ENCODING_CODEC2: codec2_buffer[audio_stream_buffer_insert] = left_sample/2 + right_sample/2; break; } } else { switch (as_conf_cache.encoding) {
/** * @brief Process a single stereo audio sample. * * Operates only on as_conf_cache, and requires no synchronization as * long as the calling thread is always iq_thread. */ void audio_stream_put_samples(short left_sample,short right_sample) { int audio_buffer_length; sdr_thread_assert_id(&audiostream_tid); /* FIXME: This really only applies once, at startup */ if (!audio_buffer) { allocate_audio_buffer(); samples_per_frame = codec2_samples_per_frame( codec2 ); bits_per_frame = codec2_bits_per_frame( codec2 ); codec2_buffer = (short *) malloc( sizeof( short ) * samples_per_frame ); bits = (unsigned char *) malloc( sizeof( unsigned char ) * BITS_SIZE ); } // samples are delivered at 48K or 8K depending on audiostream_conf.samplerate // codec2 encoding works only for 8K int offset; // use this sample and convert to a-law or PCM or codec2 if(as_conf_cache.channels==1) { switch (as_conf_cache.encoding) { default: /* ALAW */ case ENCODING_ALAW: offset = audio_stream_buffer_insert + AUDIO_BUFFER_HEADER_SIZE; audio_buffer[offset] = alaw((left_sample + right_sample) / 2); break; case ENCODING_PCM: offset = audio_stream_buffer_insert * 2 + AUDIO_BUFFER_HEADER_SIZE; /* PCM on the wire is always LE? */ audio_buffer[offset] = (left_sample/2 + right_sample/2) & 0xff; audio_buffer[offset + 1] = (left_sample/2 + right_sample/2) >> 8; break; case ENCODING_CODEC2: codec2_buffer[audio_stream_buffer_insert] = left_sample/2 + right_sample/2; break; } } else { switch (as_conf_cache.encoding) {
void allocate_audio_buffer(){ int samplesize; sdr_thread_assert_id(&audiostream_tid); sem_wait(&audiostream_sem); if (audiostream_conf.age > 0) { /* The stream configuration has changed, and we need to update * our copy to reflect that. */ memcpy(&as_conf_cache, &audiostream_conf, sizeof(as_conf_cache)); audiostream_conf.age = 0; } sem_post(&audiostream_sem); /* From this point until the buffer allocated here is handed to the * client or discarded, all iq_thread operations are on * as_conf_cache, NOT audiostream_conf. */ switch (as_conf_cache.encoding) { case ENCODING_ALAW: /* 8 bits per sample */ samplesize = as_conf_cache.bufsize * as_conf_cache.channels; break; case ENCODING_PCM: /* 16 bit per sample */ samplesize = as_conf_cache.bufsize * as_conf_cache.channels * 2; break; case ENCODING_CODEC2: /* FIXME: This seems like the wrong place for this? */ codec2_count = 0; /* Force buffer size */ as_conf_cache.bufsize = BITS_SIZE * NO_CODEC2_FRAMES; samplesize = as_conf_cache.bufsize * as_conf_cache.channels; break; default: /* No ENCODING_ALAW2! */ samplesize = 0; } audio_buffer = malloc(samplesize + AUDIO_BUFFER_HEADER_SIZE); }