void TIM3_IRQHandler() { // Checks whether the TIM3 interrupt has occurred or not if (TIM_GetITStatus(TIM3, TIM_IT_Update)) { // Read ADC value (10-bit PWM) adcValue = ADC_Read() >> 2; // Add audio effect if (effect & LOW_PASS) { adcValue = low_pass(adcValue); } if (effect & PITCH_UP) { adcValue = pitch_up(adcValue); } if (effect & PITCH_DOWN) { adcValue = pitch_down(adcValue); } // Write to PWM PWM_Write(adcValue); // Clears the TIM3 interrupt pending bit TIM_ClearITPendingBit(TIM3, TIM_IT_Update); } }
void full_demod(struct fm_state *fm) { int i, sr, freq_next, hop = 0; // pthread_mutex_lock(&data_ready); static unsigned char tmpBuf[DEFAULT_BUF_LENGTH]; while(ringbuffer_is_empty((ringbuffer*)fm->buf)) { usleep(100000); } ringbuffer_read((ringbuffer*)fm->buf, tmpBuf); //fprintf(stderr, "data!\n"); rotate_90(tmpBuf, sizeof(tmpBuf)); if (fm->fir_enable) { low_pass_fir(fm, tmpBuf, sizeof(tmpBuf)); } else { low_pass(fm, tmpBuf, sizeof(tmpBuf)); } // pthread_mutex_unlock(&data_write); fm->mode_demod(fm); if (fm->mode_demod == &raw_demod) { fwrite(fm->signal2, 2, fm->signal2_len, fm->file); return; } sr = post_squelch(fm); if (!sr && fm->squelch_hits > fm->conseq_squelch) { if (fm->terminate_on_squelch) { fm->exit_flag = 1;} if (fm->freq_len == 1) { /* mute */ for (i=0; i<fm->signal_len; i++) { fm->signal2[i] = 0;} } else { hop = 1;} } if (fm->post_downsample > 1) { fm->signal2_len = low_pass_simple(fm->signal2, fm->signal2_len, fm->post_downsample);} if (fm->output_rate > 0) { low_pass_real(fm); } if (fm->deemph) { deemph_filter(fm);} if (fm->dc_block) { dc_block_filter(fm);} /* ignore under runs for now */ fwrite(fm->signal2, 2, fm->signal2_len, fm->file); if (hop && ringbuffer_is_empty((ringbuffer*)fm->buf)) { // Making sure the buffer is empty before tuning freq_next = (fm->freq_now + 1) % fm->freq_len; optimal_settings(fm, freq_next, 1); fm->squelch_hits = fm->conseq_squelch + 1; /* hair trigger */ /* wait for settling and flush buffer */ usleep(5000); rtlsdr_read_sync(dev, NULL, 4096, NULL); } }
void full_demod(struct fm_state *fm) { uint8_t dump[BUFFER_DUMP]; int i, sr, freq_next, n_read, hop = 0; pthread_rwlock_wrlock(&data_rw); rotate_90(fm->buf, fm->buf_len); if (fm->fir_enable) { low_pass_fir(fm, fm->buf, fm->buf_len); } else { low_pass(fm, fm->buf, fm->buf_len); } pthread_rwlock_unlock(&data_rw); fm->mode_demod(fm); if (fm->mode_demod == &raw_demod) { fwrite(fm->signal2, 2, fm->signal2_len, fm->file); return; } sr = post_squelch(fm); if (!sr && fm->squelch_hits > fm->conseq_squelch) { if (fm->terminate_on_squelch) { fm->exit_flag = 1;} if (fm->freq_len == 1) { /* mute */ for (i=0; i<fm->signal_len; i++) { fm->signal2[i] = 0;} } else { hop = 1;} } if (fm->post_downsample > 1) { fm->signal2_len = low_pass_simple(fm->signal2, fm->signal2_len, fm->post_downsample);} if (fm->output_rate > 0) { low_pass_real(fm); } if (fm->deemph) { deemph_filter(fm);} if (fm->dc_block) { dc_block_filter(fm);} /* ignore under runs for now */ fwrite(fm->signal2, 2, fm->signal2_len, fm->file); if (hop) { freq_next = (fm->freq_now + 1) % fm->freq_len; optimal_settings(fm, freq_next, 1); fm->squelch_hits = fm->conseq_squelch + 1; /* hair trigger */ /* wait for settling and flush buffer */ usleep(5000); rtlsdr_read_sync(dev, &dump, BUFFER_DUMP, &n_read); if (n_read != BUFFER_DUMP) { fprintf(stderr, "Error: bad retune.\n");} } }
static sample_t diff_resampled(const SRCParams ¶ms, sample_t *buf1, sample_t *buf2, size_t size) { ///////////////////////////////////////////////////////////////////////////// // After resample only q*nyquist of the bandwidth is preserved. Therefore, // to compare output of the resampler with the original signal we must feed // the resampler with the bandlimited signal. Bandlimiting filter has a // transition band and we must guarantee: // passband + transition_band <= q*nyquist. // // It looks reasonable to make the transition band of the bandlimiting filter // to be equal to the transition band of the resampler. In this case we have: // passband + (1-q)*nyquist <= q*nyquist // passband <= (2q - 1)*nyquist // // In normalized form nyquist = 0.5, so we have following parameters of the // bandlimiting filter: passband = q-0.5, transition band = 0.5*(1-q) ParamFIR low_pass(ParamFIR::low_pass, params.q-0.5, 0, 0.5*(1-params.q), params.a + 10, true); const FIRInstance *fir = low_pass.make(params.fs); BOOST_REQUIRE(fir != 0); int trans_len = fir->length * 2; delete fir; Speakers spk(FORMAT_LINEAR, MODE_MONO, params.fs); samples_t s1, s2; s1.zero(); s1[0] = buf1; s2.zero(); s2[0] = buf2; ChunkSource src1(spk, Chunk(s1, size)); ChunkSource src2(spk, Chunk(s2, size)); Convolver conv1(&low_pass); Convolver conv2(&low_pass); SliceFilter slice1(trans_len, size - trans_len); SliceFilter slice2(trans_len, size - trans_len); FilterChain chain1(&conv1, &slice1); FilterChain chain2(&conv2, &slice2); return calc_diff(&src1, &chain1, &src2, &chain2); }
void full_demod(unsigned char *buf, uint32_t len, struct fm_state *fm) { int sr, freq_next; rotate_90(buf, len); if (fm->fir_enable) { low_pass_fir(fm, buf, len); } else { low_pass(fm, buf, len); } fm_demod(fm); sr = post_squelch(fm); if (fm->post_downsample > 1) { fm->signal_len = low_pass_simple(fm->signal2, fm->signal_len/2, fm->post_downsample)*2;} /* ignore under runs for now */ fwrite(fm->signal2, 2, fm->signal_len/2, fm->file); if (fm->freq_len > 1 && !sr && fm->squelch_hits > CONSEQ_SQUELCH) { freq_next = (fm->freq_now + 1) % fm->freq_len; optimal_settings(fm, freq_next, 1); fm->squelch_hits = CONSEQ_SQUELCH + 1; /* hair trigger */ /* wait for settling and dump buffer */ usleep(5000); rtlsdr_read_sync(dev, NULL, 4096, NULL); } }
void process(char* ims_name, char* imd_name, char* filter, int d0, int n, int w, int u0, int v0) { /* Selection du filtre */ /*float (*function_pointer) (double, double, double, double, int, int, int); if(strcmp(filter,"lp") == 0){ printf("low pass filter\n"); function_pointer = lp; } else if(strcmp(filter,"hp") == 0){ printf("high pass filter\n"); function_pointer = hp; } else if(strcmp(filter,"br") == 0){ printf("band reject filter\n"); function_pointer = br; } else if(strcmp(filter,"bp") == 0){ printf("band pass filter\n"); function_pointer = br; } else if(strcmp(filter,"no") == 0){ printf("rejet d'encoche \n"); function_pointer = no; } else { printf("unknown filter,\n filters avalaible: lp, hp, br, bp, no"); assert(false); }*/ pnm ims = pnm_load(ims_name); int width = pnm_get_width(ims); int height = pnm_get_height(ims); pnm imd = pnm_new(width, height, PnmRawPpm); unsigned short * image = (unsigned short *) malloc(height * width * sizeof(unsigned short)); fftw_complex * freq_repr = (fftw_complex *) fftw_malloc(height* width * sizeof(fftw_complex)); image = pnm_get_channel(ims, image, PnmRed); freq_repr = fft_forward(height, width, image); float * as = (float *) malloc(sizeof(float) * height * width); float * ps = (float *) malloc(sizeof(float) * height * width); fft_fr_to_spectra(width, height, freq_repr, as, ps); pnm imd2 = pnm_new(width, height, PnmRawPpm); for(int y = 0; y < height; y++) for(int x = 0; x < width; x++) for(int z = 0; z < 3; z++) pnm_set_component(imd2,y,x,z,as[x+y*height]); pnm_save(imd2, PnmRawPpm, "toto.ppm"); //float d_u_v; for(int j=0; j<height; j++){ for(int i=0; i<width; i++){ //d_u_v = sqrt((float)(j-height/2)*(j-height/2)+(float)(i-width/2)*(i-width/2)); //as[i+j*width] = function_pointer(i, j, u0, v0, n, w, d0) * as[i+j*width]; as[i+j*width] = low_pass(d0, n, d((float) i-width/2,(float) j-height/2)) * as[i+j*width]; //printf("%f \n", hp(i, j, u0, v0, n, w, d0)); //printf("%d \n", function_pointer(i, j, u0, v0, n, w, d0)); } } pnm imd3 = pnm_new(width, height, PnmRawPpm); for(int y = 0; y < height; y++) for(int x = 0; x < width; x++) for(int z = 0; z < 3; z++) pnm_set_component(imd3,y,x,z,as[x+y*height]); pnm_save(imd3, PnmRawPpm, "toto2.ppm"); fft_spectra_to_fr(height,width,as,ps, freq_repr); image = fft_backward(height, width, freq_repr); for(int y = 0; y < height; y++) for(int x = 0; x < width; x++) for(int z = 0; z < 3; z++) pnm_set_component(imd,y,x,z,image[x+y*height]); pnm_save(imd, PnmRawPpm, imd_name); free(image); }