This commit is contained in:
Xavier Belanche Alonso 2026-02-17 02:35:06 +05:30 committed by GitHub
commit a86a162bc1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 14 deletions

View File

@ -159,7 +159,7 @@ int fm_mpx_open(char *filename, size_t len) {
// samples provided by this function are in 0..10: they need to be divided by // samples provided by this function are in 0..10: they need to be divided by
// 10 after. // 10 after.
int fm_mpx_get_samples(float *mpx_buffer) { int fm_mpx_get_samples(float *mpx_buffer, uint8_t no_loop) {
get_rds_samples(mpx_buffer, length); get_rds_samples(mpx_buffer, length);
if(inf == NULL) return 0; // if there is no audio, stop here if(inf == NULL) return 0; // if there is no audio, stop here
@ -176,10 +176,15 @@ int fm_mpx_get_samples(float *mpx_buffer) {
return -1; return -1;
} }
if(audio_len == 0) { if(audio_len == 0) {
if (no_loop) {
fprintf(stderr, "End of file reached, stopping.\n");
return -1;
} else {
if( sf_seek(inf, 0, SEEK_SET) < 0 ) { if( sf_seek(inf, 0, SEEK_SET) < 0 ) {
fprintf(stderr, "Could not rewind in audio file, terminating\n"); fprintf(stderr, "Could not rewind in audio file, terminating\n");
return -1; return -1;
} }
}
} else { } else {
break; break;
} }

View File

@ -22,5 +22,5 @@
*/ */
extern int fm_mpx_open(char *filename, size_t len); extern int fm_mpx_open(char *filename, size_t len);
extern int fm_mpx_get_samples(float *mpx_buffer); extern int fm_mpx_get_samples(float *mpx_buffer, uint8_t no_loop);
extern int fm_mpx_close(); extern int fm_mpx_close();

View File

@ -144,7 +144,6 @@
#define BCM2708_DMA_END (1<<1) #define BCM2708_DMA_END (1<<1)
#define BCM2708_DMA_RESET (1<<31) #define BCM2708_DMA_RESET (1<<31)
#define BCM2708_DMA_INT (1<<2) #define BCM2708_DMA_INT (1<<2)
#define DMA_CS (0x00/4) #define DMA_CS (0x00/4)
#define DMA_CONBLK_AD (0x04/4) #define DMA_CONBLK_AD (0x04/4)
#define DMA_DEBUG (0x20/4) #define DMA_DEBUG (0x20/4)
@ -318,7 +317,7 @@ map_peripheral(uint32_t base, uint32_t len)
#define DATA_SIZE 5000 #define DATA_SIZE 5000
int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, float ppm, char *control_pipe) { int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt, float ppm, char *control_pipe, uint8_t no_loop) {
// Catch all signals possible - it is vital we kill the DMA engine // Catch all signals possible - it is vital we kill the DMA engine
// on process exit! // on process exit!
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
@ -519,7 +518,7 @@ int tx(uint32_t carrier_freq, char *audio_file, uint16_t pi, char *ps, char *rt,
while (free_slots >= SUBSIZE) { while (free_slots >= SUBSIZE) {
// get more baseband samples if necessary // get more baseband samples if necessary
if(data_len == 0) { if(data_len == 0) {
if( fm_mpx_get_samples(data) < 0 ) { if( fm_mpx_get_samples(data, no_loop) < 0 ) {
terminate(0); terminate(0);
} }
data_len = DATA_SIZE; data_len = DATA_SIZE;
@ -555,6 +554,7 @@ int main(int argc, char **argv) {
char *rt = "PiFmRds: live FM-RDS transmission from the RaspberryPi"; char *rt = "PiFmRds: live FM-RDS transmission from the RaspberryPi";
uint16_t pi = 0x1234; uint16_t pi = 0x1234;
float ppm = 0; float ppm = 0;
uint8_t no_loop = 0;
// Parse command-line arguments // Parse command-line arguments
@ -587,10 +587,13 @@ int main(int argc, char **argv) {
} else if(strcmp("-ctl", arg)==0 && param != NULL) { } else if(strcmp("-ctl", arg)==0 && param != NULL) {
i++; i++;
control_pipe = param; control_pipe = param;
} else if(strcmp("-no-loop", arg)==0 && param == NULL) {
i++;
no_loop = 1;
} else { } else {
fatal("Unrecognised argument: %s.\n" fatal("Unrecognised argument: %s.\n"
"Syntax: pi_fm_rds [-freq freq] [-audio file] [-ppm ppm_error] [-pi pi_code]\n" "Syntax: pi_fm_rds [-freq freq] [-audio file] [-ppm ppm_error] [-pi pi_code]\n"
" [-ps ps_text] [-rt rt_text] [-ctl control_pipe]\n", arg); " [-ps ps_text] [-rt rt_text] [-ctl control_pipe] [-no-loop]\n", arg);
} }
} }
@ -599,7 +602,7 @@ int main(int argc, char **argv) {
char* locale = setlocale(LC_ALL, ""); char* locale = setlocale(LC_ALL, "");
printf("Locale set to %s.\n", locale); printf("Locale set to %s.\n", locale);
int errcode = tx(carrier_freq, audio_file, pi, ps, rt, ppm, control_pipe); int errcode = tx(carrier_freq, audio_file, pi, ps, rt, ppm, control_pipe, no_loop);
terminate(errcode); terminate(errcode);
} }