summaryrefslogtreecommitdiff
path: root/src/audiobackend-pulse.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/audiobackend-pulse.cc')
-rw-r--r--src/audiobackend-pulse.cc57
1 files changed, 42 insertions, 15 deletions
diff --git a/src/audiobackend-pulse.cc b/src/audiobackend-pulse.cc
index 57d1a5c..63013af 100644
--- a/src/audiobackend-pulse.cc
+++ b/src/audiobackend-pulse.cc
@@ -25,6 +25,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "audiobackend-pulse.h"
+#include "mediaconfig.h"
+
+#include <pulse/simple.h>
+#include <pulse/error.h>
#ifdef WITH_PULSE
@@ -40,34 +44,57 @@ http://freedesktop.org/software/pulseaudio/doxygen/parec-simple_8c-example.html
AudioBackendPulse::AudioBackendPulse(const char *device)
{
- // Initialise pulse here
-
- //s = pa_simple_new(...);
+ // Initialize PulseAudio
+ pa_sample_spec ss;
+ ss.format = PA_SAMPLE_S16NE;
+ ss.channels = 1;
+ ss.rate = SAMPLERATE;
+
+ sIn = pa_simple_new(NULL, // Use the default server.
+ "SimpleRTP", // Our application's name.
+ PA_STREAM_RECORD,
+ NULL, // Use the default device.
+ "SimpleRTP", // Description of our stream.
+ &ss, // Our sample format.
+ NULL, // Use default channel map
+ NULL, // Use default buffering attributes.
+ NULL // Ignore error code.
+ );
+
+ sOut = pa_simple_new(NULL, // Use the default server.
+ "SimpleRTP", // Our application's name.
+ PA_STREAM_PLAYBACK,
+ NULL, // Use the default device.
+ "SimpleRTP", // Description of our stream.
+ &ss, // Our sample format.
+ NULL, // Use default channel map
+ NULL, // Use default buffering attributes.
+ NULL // Ignore error code.
+ );
}
AudioBackendPulse::~AudioBackendPulse()
{
- // Shut down pulse here
-
- //pa_simple_free(s);
+ // Freeeeedoooooom! Set the PulseAudio instance free again, we're done
+ pa_simple_free(sIn);
+ pa_simple_free(sOut);
}
int AudioBackendPulse::read(char *pcm, size_t maxsize)
{
// read maximum 'maxsize' bytes into pcm and return number of bytes read.
-
- //pa_simple_read(...)
-
- return 0;
+ return pa_simple_read(sIn,
+ pcm,
+ maxsize,
+ NULL);
}
int AudioBackendPulse::write(const char *pcm, size_t size)
{
- // write pcm to pulse
-
- //pa_simple_write(...)
-
- return 0;
+ return pa_simple_write(sOut,
+ pcm,
+ size,
+ NULL);
}
#endif/*WITH_PULSE*/