summaryrefslogtreecommitdiff
path: root/tests/test5/capture.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test5/capture.c')
-rw-r--r--tests/test5/capture.c40
1 files changed, 11 insertions, 29 deletions
diff --git a/tests/test5/capture.c b/tests/test5/capture.c
index 441a6ac..00d9c54 100644
--- a/tests/test5/capture.c
+++ b/tests/test5/capture.c
@@ -5,7 +5,7 @@
#define APP_TITLE "Test 5 lpo"
#define BUFSIZE 1024
-extern void my_process(gint sound_level, void *userdata);
+extern void my_process(float *data, size_t nsamples, size_t nchan);
capture_sound_level_cb_t *capture_sound_level_cb=NULL;
@@ -16,7 +16,6 @@ void context_get_source_info_callback(pa_context *c, const pa_source_info *si, i
pa_stream * create_stream(pa_context *c, const pa_source_info *si);
void stream_state_callback(pa_stream *s, void *userdata);
void stream_read_callback(pa_stream *s, size_t nbytes, void *userdata);
-gint compute_level(const void *data, size_t nbytes);
char *device_name=NULL;
@@ -106,7 +105,6 @@ void context_get_server_info_callback(pa_context *c, const pa_server_info*si, vo
}
void context_get_source_info_callback(pa_context *c, const pa_source_info *si, int is_last, void *userdata) {
- static pa_stream* pa_st=NULL;
if (is_last < 0) {
printf("Failed to get sink information\n");
@@ -117,18 +115,10 @@ void context_get_source_info_callback(pa_context *c, const pa_source_info *si, i
return;
}
- pa_st=create_stream(c,si);
- g_assert(pa_st);
+ create_stream(c,si);
}
pa_stream *create_stream(pa_context *c, const pa_source_info *si) {
- /* The sample type to use
- static const pa_sample_spec nss = {
- .format = PA_SAMPLE_S16LE,
- .rate = 44100,
- .channels = 1
- };
-*/
static const pa_buffer_attr ba={
.maxlength=-1,
.tlength=1024,
@@ -137,6 +127,12 @@ pa_stream *create_stream(pa_context *c, const pa_source_info *si) {
.fragsize=512
};
+ pa_sample_spec nss = {
+ .format = PA_SAMPLE_FLOAT32LE,
+ .rate = si->sample_spec.rate,
+ .channels = si->sample_spec.channels
+ };
+
pa_stream *stream=NULL;
//pa_proplist *pl=NULL;
char t[256];
@@ -148,7 +144,7 @@ pa_stream *create_stream(pa_context *c, const pa_source_info *si) {
*/
printf("Source : %s (%s)\n", si->name, si->description);
- printf("Using sample format: %s\n", pa_sample_spec_snprint(t, sizeof(t), &(si->sample_spec)));
+ printf("Using sample format: %s\n", pa_sample_spec_snprint(t, sizeof(t), &nss));
printf("Using channel map: %s\n", pa_channel_map_snprint(t, sizeof(t), &(si->channel_map)));
/*
pl=pa_proplist_new();
@@ -156,7 +152,7 @@ pa_stream *create_stream(pa_context *c, const pa_source_info *si) {
pa_proplist_set(pl, "tlength", &pl_tlength, sizeof(pl_tlength));
pa_proplist_set(pl, "fragsize", &pl_fragsize, sizeof(pl_fragsize));
*/
- stream=pa_stream_new(c, APP_TITLE, &(si->sample_spec), &(si->channel_map));
+ stream=pa_stream_new(c, APP_TITLE, &nss, &(si->channel_map));
//stream=pa_stream_new_with_proplist(c, APP_TITLE, &(si->sample_spec), &(si->channel_map), pl);
pa_stream_set_state_callback(stream, stream_state_callback, NULL);
pa_stream_set_read_callback(stream, stream_read_callback, NULL);
@@ -196,11 +192,9 @@ void stream_read_callback(pa_stream *s, size_t nbytes, void *userdata) {
printf("pa_stream_peek() failed\n");//: %s", pa_strerror(pa_context_errno(context)));
return;
}
- //printf("level : %i\n", compute_level(p,nbytes));
//printf("debug : before call capture_sound_level_cb==%p\n", capture_sound_level_cb);
-
- my_process(compute_level(p,nbytes), NULL);
+ my_process((float *)p,nbytes/sizeof(float), pa_stream_get_sample_spec(s)->channels);
// (*capture_sound_level_cb)(compute_level(p,nbytes), NULL);
//printf("debug : after call capture_sound_level_cb==%p\n", capture_sound_level_cb);
@@ -208,15 +202,3 @@ void stream_read_callback(pa_stream *s, size_t nbytes, void *userdata) {
pa_stream_drop(s);
}
-gint compute_level(const void *data, size_t nbytes) {
- size_t i;
- gint val, level=0;
- for (i=0;i<nbytes/2;i++) {
- val=((int16_t *)data)[i];
- //printf("val==%i\n", val);
- if (val<0) val=-val;
- if (level<val) level=val;
- }
- return level;
-}
-