#ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #define BUFSIZE 1024 int main(int argc, char*argv[]) { /* The Sample format to use */ static const pa_sample_spec ss = { .format = PA_SAMPLE_S16LE, // .rate = 44100, .rate = 44100, .channels = 2 }; pa_simple *s = NULL; int ret = 1; int error; if (!(s = pa_simple_new(NULL, argv[0], PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) { fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); goto finish; } SF_INFO sinfo; sinfo.format = 0; //prepare SNDFILE* sf = sf_open( argv[1], SFM_READ, &sinfo ); uint8_t buf[BUFSIZE]; ssize_t r; int i; for (;;) { /* Read some data ... */ if ((r = sf_read_raw(sf, (void*)buf, BUFSIZE)) <= 0){ if (r == 0) /* EOF */ break; fprintf(stderr, __FILE__": read() failed: %s\n", strerror(errno)); goto finish; } /* ... and play it */ if (pa_simple_write(s, buf, (size_t) r, &error) < 0) { fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", pa_strerror(error)); goto finish; } /* for(i=0;i