cubehub / demod

Command line utility based on liquid-dsp for realtime SDR IQ stream demodulation
MIT License
39 stars 17 forks source link

Writing i16 data to stdout is slow #1

Closed andresv closed 9 years ago

andresv commented 9 years ago

It is slow because only 2 byes are written with one stdout.write(..).

let mut demod_out = vec![0_f32; resampler_output_len as usize];

match args.outputtype.unwrap() {
                    I16 => {
                        for i in 0 .. resampler_output_count as usize {
                            if demod_out[i] > 1.0 {
                                demod_out[i] = 1.0;
                            }
                            if demod_out[i] < -1.0 {
                                demod_out[i] = -1.0;
                            }

                            let sample: [i16; 1] = [(demod_out[i] * 32767_f32) as i16];
                            let slice = unsafe {slice::from_raw_parts(sample.as_ptr() as *const _, 2)};
                            stdout.write(&slice).map_err(|e|{println_stderr!("stdout.write error: {:?}", e); exit(1);});
                            stdout.flush().map_err(|e|{println_stderr!("stdout.write error: {:?}", e); exit(1);});
                        }
                    }
                    F32 => {
                        let slice = unsafe {slice::from_raw_parts(demod_out.as_ptr() as *const _, (resampler_output_count * 4) as usize)};
                        stdout.write(&slice).map_err(|e|{println_stderr!("stdout.write error: {:?}", e); exit(1);});
                        stdout.flush().map_err(|e|{println_stderr!("stdout.write error: {:?}", e); exit(1);});
                    }
                }