Exemple #1
0
/**
 * @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) {