Share memory between fm buffer and temporary buffer

The temporary buffer and the fm buffer are not used at the same
time, so the allocated memory can be shared between the two buffers.

This reduces memory usage by 8MB (~30 %)
This commit is contained in:
Robert Högberg 2015-10-16 20:09:14 +02:00
parent 89564cde17
commit 5b4ec0e1fe

View file

@ -46,8 +46,11 @@ struct dm_state {
FILE *out_file;
int32_t level_limit;
int16_t am_buf[MAXIMAL_BUF_LENGTH]; // AM demodulated signal (for OOK decoding)
int16_t fm_buf[MAXIMAL_BUF_LENGTH]; // FM demodulated signal (for FSK decoding)
uint16_t temp_buf[MAXIMAL_BUF_LENGTH]; // Temporary buffer (to be optimized out..)
union {
// These buffers aren't used at the same time, so let's use a union to save some memory
int16_t fm_buf[MAXIMAL_BUF_LENGTH]; // FM demodulated signal (for FSK decoding)
uint16_t temp_buf[MAXIMAL_BUF_LENGTH]; // Temporary buffer (to be optimized out..)
};
FilterState lowpass_filter_state;
DemodFM_State demod_FM_state;
int enable_FM_demod;
@ -640,13 +643,14 @@ static void rtlsdr_callback(unsigned char *iq_buf, uint32_t len, void *ctx) {
demod->sg_index = 0;
}
// AM demodulation
envelope_detect(iq_buf, demod->temp_buf, len/2);
baseband_low_pass_filter(demod->temp_buf, demod->am_buf, len/2, &demod->lowpass_filter_state);
// FM demodulation
if (demod->enable_FM_demod) {
baseband_demod_FM(iq_buf, demod->fm_buf, len/2, &demod->demod_FM_state);
}
// AM demodulation
envelope_detect(iq_buf, demod->temp_buf, len/2);
baseband_low_pass_filter(demod->temp_buf, demod->am_buf, len/2, &demod->lowpass_filter_state);
// Handle special input formats
if(!demod->out_file) { // If output file is specified we always assume I/Q input