mirror of
https://github.com/radio95-rnt/fm95.git
synced 2026-02-27 03:23:54 +01:00
add alsa output to pstcode, scamod
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
#define INPUT_DEVICE "real_real_tx_audio_input.monitor"
|
||||
#define OUTPUT_DEVICE "alsa_output.platform-soc_sound.stereo-fallback"
|
||||
// #define ALSA_OUTPUT // Output, not input or both
|
||||
#define BUFFER_SIZE 512
|
||||
#define CLIPPER_THRESHOLD 0.525 // Adjust this as needed
|
||||
|
||||
@@ -75,11 +76,13 @@ int main() {
|
||||
.maxlength = buffer_maxlength,
|
||||
.fragsize = buffer_tlength_fragsize
|
||||
};
|
||||
#ifndef ALSA_OUTPUT
|
||||
pa_buffer_attr output_buffer_atr = {
|
||||
.maxlength = buffer_maxlength,
|
||||
.tlength = buffer_tlength_fragsize,
|
||||
.prebuf = buffer_prebuf
|
||||
};
|
||||
#endif
|
||||
|
||||
printf("Connecting to input device... (%s)\n", INPUT_DEVICE);
|
||||
|
||||
@@ -101,6 +104,7 @@ int main() {
|
||||
|
||||
printf("Connecting to output device... (%s)\n", OUTPUT_DEVICE);
|
||||
|
||||
#ifndef ALSA_OUTPUT
|
||||
pa_simple *output_device = pa_simple_new(
|
||||
NULL,
|
||||
"PolarStereoEncoder",
|
||||
@@ -117,6 +121,33 @@ int main() {
|
||||
pa_simple_free(input_device);
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
snd_pcm_hw_params_t *output_params;
|
||||
snd_pcm_t *output_handle;
|
||||
int output_error = snd_pcm_open(&output_handle, OUTPUT_DEVICE, SND_PCM_STREAM_PLAYBACK, 0);
|
||||
if(output_error < 0) {
|
||||
fprintf(stderr, "Error: cannot open output device: %s\n", snd_strerror(output_error));
|
||||
pa_simple_free(input_device);
|
||||
return 1;
|
||||
}
|
||||
snd_pcm_hw_params_malloc(&output_params);
|
||||
snd_pcm_hw_params_any(output_handle, output_params);
|
||||
snd_pcm_hw_params_set_access(output_handle, output_params, SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||
snd_pcm_hw_params_set_format(output_handle, output_params, SND_PCM_FORMAT_FLOAT); // Same as pulse's Float32NE
|
||||
snd_pcm_hw_params_set_channels(output_handle, output_params, 1);
|
||||
unsigned int rate = SAMPLE_RATE;
|
||||
int dir;
|
||||
snd_pcm_hw_params_set_rate_near(output_handle, output_params, &rate, &dir);
|
||||
snd_pcm_uframes_t frames = BUFFER_SIZE;
|
||||
snd_pcm_hw_params_set_period_size_near(output_handle, output_params, &frames, &dir); // i don't have a clue why like this
|
||||
output_error = snd_pcm_hw_params(output_handle, output_params);
|
||||
if(output_error < 0) {
|
||||
fprintf(stderr, "Error: cannot open output device: %s\n", snd_strerror(output_error));
|
||||
snd_pcm_close(output_handle);
|
||||
pa_simple_free(input_device);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
Oscillator stereo_osc;
|
||||
init_oscillator(&stereo_osc, 31250.0, SAMPLE_RATE);
|
||||
@@ -186,14 +217,22 @@ int main() {
|
||||
((stereo+0.2) * stereo_carrier)*STEREO_VOLUME; // the 0.2 add DC, you know what happens then? Carrier wave
|
||||
}
|
||||
|
||||
#ifndef ALSA_OUTPUT
|
||||
if (pa_simple_write(output_device, mpx, sizeof(mpx), &pulse_error) < 0) {
|
||||
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
||||
to_run = 0;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
snd_pcm_writei(output_handle, mpx, sizeof(mpx));
|
||||
#endif
|
||||
}
|
||||
printf("Cleaning up...\n");
|
||||
pa_simple_free(input_device);
|
||||
#ifndef ALSA_OUTPUT
|
||||
pa_simple_free(output_device);
|
||||
#else
|
||||
snd_pcm_drain(output_handle);
|
||||
snd_pcm_free(output_handle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#include <stdio.h>
|
||||
#include <pulse/simple.h>
|
||||
#include <pulse/error.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
@@ -18,9 +16,16 @@
|
||||
|
||||
#define INPUT_DEVICE "SCA.monitor"
|
||||
#define OUTPUT_DEVICE "alsa_output.platform-soc_sound.stereo-fallback"
|
||||
// #define ALSA_OUTPUT // Output, not input or both
|
||||
#define BUFFER_SIZE 512
|
||||
#define CLIPPER_THRESHOLD 1 // Adjust this as needed, this also limits deviation, so if you set this to 0.5 then the deviation will be limited to half
|
||||
|
||||
#include <pulse/simple.h>
|
||||
#include <pulse/error.h>
|
||||
#ifdef ALSA_OUTPUT
|
||||
#include <alsa/asoundlib.h>
|
||||
#endif
|
||||
|
||||
#define VOLUME 0.1f // SCA Volume
|
||||
#define VOLUME_AUDIO 1.0f // SCA Audio volume
|
||||
#define FREQUENCY 67000 // SCA Frequency
|
||||
@@ -66,11 +71,13 @@ int main() {
|
||||
.maxlength = buffer_maxlength,
|
||||
.fragsize = buffer_tlength_fragsize
|
||||
};
|
||||
#ifndef ALSA_OUTPUT
|
||||
pa_buffer_attr output_buffer_atr = {
|
||||
.maxlength = buffer_maxlength,
|
||||
.tlength = buffer_tlength_fragsize,
|
||||
.prebuf = buffer_prebuf
|
||||
};
|
||||
#endif
|
||||
|
||||
printf("Connecting to input device... (%s)\n", INPUT_DEVICE);
|
||||
|
||||
@@ -91,7 +98,7 @@ int main() {
|
||||
}
|
||||
|
||||
printf("Connecting to output device... (%s)\n", OUTPUT_DEVICE);
|
||||
|
||||
#ifndef ALSA_OUTPUT
|
||||
pa_simple *output_device = pa_simple_new(
|
||||
NULL,
|
||||
"SCAMod",
|
||||
@@ -108,6 +115,33 @@ int main() {
|
||||
pa_simple_free(input_device);
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
snd_pcm_hw_params_t *output_params;
|
||||
snd_pcm_t *output_handle;
|
||||
int output_error = snd_pcm_open(&output_handle, OUTPUT_DEVICE, SND_PCM_STREAM_PLAYBACK, 0);
|
||||
if(output_error < 0) {
|
||||
fprintf(stderr, "Error: cannot open output device: %s\n", snd_strerror(output_error));
|
||||
pa_simple_free(input_device);
|
||||
return 1;
|
||||
}
|
||||
snd_pcm_hw_params_malloc(&output_params);
|
||||
snd_pcm_hw_params_any(output_handle, output_params);
|
||||
snd_pcm_hw_params_set_access(output_handle, output_params, SND_PCM_ACCESS_RW_INTERLEAVED);
|
||||
snd_pcm_hw_params_set_format(output_handle, output_params, SND_PCM_FORMAT_FLOAT); // Same as pulse's Float32NE
|
||||
snd_pcm_hw_params_set_channels(output_handle, output_params, 1);
|
||||
unsigned int rate = SAMPLE_RATE;
|
||||
int dir;
|
||||
snd_pcm_hw_params_set_rate_near(output_handle, output_params, &rate, &dir);
|
||||
snd_pcm_uframes_t frames = BUFFER_SIZE;
|
||||
snd_pcm_hw_params_set_period_size_near(output_handle, output_params, &frames, &dir); // i don't have a clue why like this
|
||||
output_error = snd_pcm_hw_params(output_handle, output_params);
|
||||
if(output_error < 0) {
|
||||
fprintf(stderr, "Error: cannot open output device: %s\n", snd_strerror(output_error));
|
||||
snd_pcm_close(output_handle);
|
||||
pa_simple_free(input_device);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
FMModulator mod;
|
||||
init_fm_modulator(&mod, FREQUENCY, DEVIATION, SAMPLE_RATE);
|
||||
@@ -157,14 +191,23 @@ int main() {
|
||||
signal[i] = modulate_fm(&mod, current_input)*VOLUME;
|
||||
}
|
||||
|
||||
#ifndef ALSA_OUTPUT
|
||||
if (pa_simple_write(output_device, signal, sizeof(signal), &pulse_error) < 0) {
|
||||
fprintf(stderr, "Error writing to output device: %s\n", pa_strerror(pulse_error));
|
||||
to_run = 0;
|
||||
break;
|
||||
}
|
||||
#else
|
||||
snd_pcm_writei(output_handle, signal, sizeof(signal));
|
||||
#endif
|
||||
}
|
||||
printf("Cleaning up...\n");
|
||||
pa_simple_free(input_device);
|
||||
#ifndef ALSA_OUTPUT
|
||||
pa_simple_free(output_device);
|
||||
#else
|
||||
snd_pcm_drain(output_handle);
|
||||
snd_pcm_free(output_handle);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#define INPUT_DEVICE "real_real_tx_audio_input.monitor"
|
||||
#define OUTPUT_DEVICE "alsa_output.platform-soc_sound.stereo-fallback"
|
||||
#define ALSA_OUTPUT // Output, not input or both
|
||||
// #define ALSA_OUTPUT // Output, not input or both
|
||||
#define BUFFER_SIZE 512
|
||||
#define CLIPPER_THRESHOLD 0.525 // Adjust this as needed
|
||||
|
||||
@@ -89,11 +89,13 @@ int main() {
|
||||
.maxlength = buffer_maxlength,
|
||||
.fragsize = buffer_tlength_fragsize
|
||||
};
|
||||
#ifndef ALSA_OUTPUT
|
||||
pa_buffer_attr output_buffer_atr = {
|
||||
.maxlength = buffer_maxlength,
|
||||
.tlength = buffer_tlength_fragsize,
|
||||
.prebuf = buffer_prebuf
|
||||
};
|
||||
#endif
|
||||
|
||||
int open_pulse_error;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user