${PC_FFTW3_LIBRARIES}
${PC_ALSA_LIBRARIES}
${PC_LIBCONFIG_LIBRARIES}
+ pulse
+ pulse-simple
m
pthread
)
interface_socket = 3,
interface_soundcard = 4,
interface_terminal = 5,
+ interface_pulseaudio = 6
} interface_type;
interface_obj * interface_construct_socket(const char * ip, const unsigned int port);
+ interface_obj * interface_construct_pulseaudio(const char * sourceName);
+
interface_obj * interface_construct_soundcard(const unsigned int card, const unsigned int device);
interface_obj * interface_construct_soundcard_by_name(char * deviceName);
#include <stdio.h>
#include <string.h>
#include <alsa/asoundlib.h>
+ #include <pulse/simple.h>
+ #include <pulse/error.h>
#include "../general/format.h"
#include "../general/interface.h"
FILE * fp;
snd_pcm_t * ch;
+ pa_simple * pa;
+ pa_sample_spec ss;
char * buffer;
unsigned int bufferSize;
void src_hops_open_interface_soundcard(src_hops_obj * obj);
+ void src_hops_open_interface_pulseaudio(src_hops_obj * obj);
+
void src_hops_close(src_hops_obj * obj);
void src_hops_close_interface_file(src_hops_obj * obj);
void src_hops_close_interface_soundcard(src_hops_obj * obj);
+ void src_hops_close_interface_pulseaudio(src_hops_obj * obj);
+
int src_hops_process(src_hops_obj * obj);
int src_hops_process_interface_file(src_hops_obj * obj);
int src_hops_process_interface_soundcard(src_hops_obj * obj);
+ int src_hops_process_interface_pulseaudio(src_hops_obj * obj);
+
void src_hops_process_format_binary_int08(src_hops_obj * obj);
void src_hops_process_format_binary_int16(src_hops_obj * obj);
}
+ interface_obj * interface_construct_pulseaudio(const char * sourceName) {
+
+ interface_obj * obj;
+
+ obj = (interface_obj *) malloc(sizeof(interface_obj));
+
+ // +----------------------------------------------------------+
+ // | Type |
+ // +----------------------------------------------------------+
+
+ obj->type = interface_pulseaudio;
+
+ // +----------------------------------------------------------+
+ // | Blackhole |
+ // +----------------------------------------------------------+
+
+ // (Empty)
+
+ // +----------------------------------------------------------+
+ // | File |
+ // +----------------------------------------------------------+
+
+ obj->fileName = (char *) NULL;
+
+ // +----------------------------------------------------------+
+ // | Socket |
+ // +----------------------------------------------------------+
+
+ obj->ip = (char *) NULL;
+ obj->port = 0;
+
+ // +----------------------------------------------------------+
+ // | Soundcard |
+ // +----------------------------------------------------------+
+
+ obj->deviceName = (char *) malloc(sizeof(char) * (strlen(sourceName)+1));
+ strcpy(obj->deviceName, sourceName);
+
+ // +----------------------------------------------------------+
+ // | Terminal |
+ // +----------------------------------------------------------+
+
+ // (Empty)
+
+ return obj;
+
+ }
+
interface_obj * interface_construct_soundcard(const unsigned int card, const unsigned int device) {
char * deviceName = (char *) malloc(sizeof(char) * 1024);
clone->deviceName = obj->deviceName;
}
+ // +----------------------------------------------------------+
+ // | Pulseaudio |
+ // +----------------------------------------------------------+
+
+ if (obj->type == interface_pulseaudio) {
+ clone->deviceName = obj->deviceName;
+ }
+
+
// +----------------------------------------------------------+
// | Terminal |
// +----------------------------------------------------------+
break;
+ case interface_pulseaudio:
+
+ printf("type = pulseaudio, devicename = %s\n", obj->deviceName);
+
+ break;
+
case interface_terminal:
printf("type = terminal\n");
((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int08)) ||
((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int16)) ||
((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int24)) ||
- ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int32)))) {
+ ((obj->interface->type == interface_soundcard) && (obj->format->type == format_binary_int32)) ||
+ ((obj->interface->type == interface_pulseaudio) && (obj->format->type == format_binary_int08)) ||
+ ((obj->interface->type == interface_pulseaudio) && (obj->format->type == format_binary_int16)) ||
+ ((obj->interface->type == interface_pulseaudio) && (obj->format->type == format_binary_int24)) ||
+ ((obj->interface->type == interface_pulseaudio) && (obj->format->type == format_binary_int32)))) {
printf("Source hops: Invalid interface and/or format.\n");
exit(EXIT_FAILURE);
break;
+ case interface_pulseaudio:
+
+ src_hops_open_interface_pulseaudio(obj);
+
+ break;
+
default:
printf("Source hops: Invalid interface type.\n");
}
+ void src_hops_open_interface_pulseaudio(src_hops_obj * obj) {
+
+ pa_sample_format_t format;
+
+ switch (obj->format->type) {
+
+ case format_binary_int08:
+
+ format = PA_SAMPLE_U8;
+
+ break;
+
+ case format_binary_int16:
+
+ format = PA_SAMPLE_S16LE;
+
+ break;
+
+ case format_binary_int24:
+
+ format = PA_SAMPLE_S24LE;
+
+ break;
+
+ case format_binary_int32:
+
+ format = PA_SAMPLE_S32LE;
+
+ break;
+
+ default:
+
+ printf("Source hops: Invalid format.\n");
+ exit(EXIT_FAILURE);
+
+ break;
+
+ }
+
+ obj->ss.format = format;
+ obj->ss.rate = obj->fS;
+ obj->ss.channels = obj->nChannels;
+
+ int err;
+ if (!(obj->pa = pa_simple_new(NULL, "Odas", PA_STREAM_RECORD, obj->interface->deviceName, "record", &obj->ss, NULL, NULL, &err))) {
+ printf("Source hops: Cannot open pulseaudio device %s: %s\n", obj->interface->deviceName, pa_strerror(err));
+ exit(EXIT_FAILURE);
+ }
+
+ }
+
void src_hops_open_interface_soundcard(src_hops_obj * obj) {
snd_pcm_hw_params_t * hw_params;
break;
+ case interface_pulseaudio:
+
+ src_hops_close_interface_pulseaudio(obj);
+
+ break;
+
default:
printf("Source hops: Invalid interface type.\n");
}
+ void src_hops_close_interface_pulseaudio(src_hops_obj * obj) {
+
+ if (obj->pa != NULL)
+ pa_simple_free(obj->pa);
+
+ }
+
int src_hops_process(src_hops_obj * obj) {
int rtnValue;
break;
+ case interface_pulseaudio:
+
+ rtnValue = src_hops_process_interface_pulseaudio(obj);
+
+ break;
+
default:
printf("Source hops: Invalid interface type.\n");
}
+ int src_hops_process_interface_pulseaudio(src_hops_obj * obj) {
+
+ int rtnValue;
+ int err;
+
+ if (pa_simple_read(obj->pa, obj->buffer, obj->bufferSize, &err) < 0) {
+
+ rtnValue = -1;
+
+ }
+ else {
+
+ rtnValue = 0;
+
+ }
+
+ return rtnValue;
+
+ }
+
void src_hops_process_format_binary_int08(src_hops_obj * obj) {
unsigned int iSample;