Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- #include <errno.h>
- #include <fcntl.h>
- #include <pulse/simple.h>
- #include <pulse/error.h>
- #include <pulse/gccmacro.h>
- #include <pulse/pulseaudio.h>
- #define BUFSIZE 1024
- #define UINT32_MAX (0xffffffff)
- struct pa_simple {
- pa_threaded_mainloop *mainloop;
- pa_context *context;
- pa_stream *stream;
- pa_stream_direction_t direction;
- const void *read_data;
- size_t read_index, read_length;
- int operation_success;
- };
- int indexV = -1;
- static void pm_default_sink_info_callback (pa_context *c,const pa_sink_info *info,int eol,void *userdata) {
- if (eol > 0)
- return;
- else {
- indexV = info->index;
- printf("# set default sink to %d\n",indexV);
- }
- }
- static void pm_server_info_callback (pa_context *c,const pa_server_info *info,void *userdata) {
- printf("# server info \n");
- pa_operation *operation;
- if (info == NULL) {
- printf("No PulseAudio Server\n");
- return;
- }
- if (!(operation = pa_context_get_sink_info_by_name (c,info->default_sink_name,pm_default_sink_info_callback,userdata) )) {
- }
- }
- int setVolume(float volume){
- static pa_sample_spec ss;
- ss.format = PA_SAMPLE_S16LE;
- ss.rate = 44100;
- ss.channels = 2;
- int error;
- pa_simple *s = NULL;
- if (!(s = pa_simple_new(NULL, "thinta", PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) {
- fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error));
- exit(-1);
- }
- printf("* connected to server\n");
- printf("* requesting server info\n");
- pa_context_get_server_info (s->context, pm_server_info_callback, NULL);
- printf("* waiting for response\n");
- while(indexV == -1){usleep(100);} //waiting for callback to set default-sink-index
- pa_cvolume vol;
- printf("* Linear Volume: %f\n",volume);
- pa_cvolume_set(&vol, ss.channels,pa_sw_volume_from_linear(volume));
- printf("-> got default sink.. changing volume!\n");
- pa_context_set_sink_volume_by_index(s->context, indexV, &vol, NULL, NULL);
- indexV = -1;
- pa_simple_free(s);
- return 0;
- }
- int main(){ setVolume(0.1); }
Add Comment
Please, Sign In to add comment