From 6144d741eb795979bacc4e8ea6058ad2af966b48 Mon Sep 17 00:00:00 2001 From: w1z7ard Date: Mon, 12 Nov 2007 05:33:10 +0000 Subject: [PATCH] hackorama to get better sound data. close bug still exists git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@706 6778bc44-b910-0410-a7a0-be141de4315d --- .../QPulseAudioThread.cpp | 98 +------------------ .../QPulseAudioThread.hpp | 5 - 2 files changed, 5 insertions(+), 98 deletions(-) diff --git a/src/qprojectM-pulseaudio/QPulseAudioThread.cpp b/src/qprojectM-pulseaudio/QPulseAudioThread.cpp index d7d58ab4d..507dd722b 100644 --- a/src/qprojectM-pulseaudio/QPulseAudioThread.cpp +++ b/src/qprojectM-pulseaudio/QPulseAudioThread.cpp @@ -77,19 +77,12 @@ static enum { RECORD } mode = RECORD; static pa_sample_spec sample_spec ; -QPulseAudioThread::QPulseAudioThread(int _argc, char **_argv, projectM * _projectM, QObject * parent) : QThread(parent), argc(_argc), argv(_argv), m_projectM(_projectM), m_timer(0) { +QPulseAudioThread::QPulseAudioThread(int _argc, char **_argv, projectM * _projectM, QObject * parent) : QThread(parent), argc(_argc), argv(_argv), m_projectM(_projectM) { - m_timer = new QTimer(this); -} - - -void QPulseAudioThread::init() { - } - QPulseAudioThread::~QPulseAudioThread() { cleanup(); @@ -147,34 +140,6 @@ if (mainloop_api) mainloop_api->quit(mainloop_api, ret); } - /* Write some data to the stream */ - static void do_stream_write(size_t length) { - size_t l; - assert(length); - - if (!buffer || !buffer_length) - return; - - l = length; - if (l > buffer_length) - l = buffer_length; - - if (pa_stream_write(stream, (uint8_t*) buffer + buffer_index, l, NULL, 0, PA_SEEK_RELATIVE) < 0) { - fprintf(stderr, "pa_stream_write() failed: %s\n", pa_strerror(pa_context_errno(context))); - quit(1); - return; - } - - buffer_length -= l; - buffer_index += l; - - if (!buffer_length) { - pa_xfree(buffer); - buffer = NULL; - buffer_index = buffer_length = 0; - } - } - /* This is called whenever new data may is available */ static void stream_read_callback(pa_stream *s, size_t length, void *userdata) { @@ -323,57 +288,6 @@ static void stream_state_callback(pa_stream *s, void *userdata) { } } - /* New data on STDIN **/ - static void stdin_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) { - size_t l, w = 0; - ssize_t r; - assert(a == mainloop_api && e && stdio_event == e); - - if (buffer) { - mainloop_api->io_enable(stdio_event, PA_IO_EVENT_NULL); - return; - } - - if (!stream || pa_stream_get_state(stream) != PA_STREAM_READY || !(l = w = pa_stream_writable_size(stream))) - l = 4096; - - buffer = (float*)pa_xmalloc(l); - - if ((r = read(fd, buffer, l)) <= 0) { - if (r == 0) { - if (verbose) - fprintf(stderr, "Got EOF.\n"); - - if (stream) { - pa_operation *o; - - if (!(o = pa_stream_drain(stream, stream_drain_complete, NULL))) { - fprintf(stderr, "pa_stream_drain(): %s\n", pa_strerror(pa_context_errno(context))); - quit(1); - return; - } - - pa_operation_unref(o); - } else - quit(0); - - } else { - fprintf(stderr, "read() failed: %s\n", strerror(errno)); - quit(1); - } - - mainloop_api->io_free(stdio_event); - stdio_event = NULL; - return; - } - - buffer_length = r; - buffer_index = 0; - - if (w) - do_stream_write(w); - } - /* Some data may be written to STDOUT */ static void stdout_callback(pa_mainloop_api*a, pa_io_event *e, int fd, pa_io_event_flags_t f, void *userdata) { ssize_t r; @@ -384,15 +298,13 @@ static void stream_state_callback(pa_stream *s, void *userdata) { return; } else { projectM * prjm = static_cast(userdata); - prjm->pcm->addPCMfloat(buffer+buffer_index, sizeof(buffer)); - } - - assert(buffer_length); + prjm->pcm->addPCMfloat(buffer+buffer_index, buffer_length/(sizeof(float))); + assert(buffer_length); pa_xfree(buffer); buffer = NULL; buffer_length = buffer_index = 0; - +} } /* UNIX signal to quit recieved */ @@ -451,7 +363,7 @@ static void stream_state_callback(pa_stream *s, void *userdata) { void QPulseAudioThread::run() { int ret = 1, r, c; - char *bn = "pulse"; + char *bn = "QPulseAudioThread"; sample_spec.format = PA_SAMPLE_FLOAT32LE; sample_spec.rate = 44100; diff --git a/src/qprojectM-pulseaudio/QPulseAudioThread.hpp b/src/qprojectM-pulseaudio/QPulseAudioThread.hpp index 5fb14c901..c7be4de28 100644 --- a/src/qprojectM-pulseaudio/QPulseAudioThread.hpp +++ b/src/qprojectM-pulseaudio/QPulseAudioThread.hpp @@ -4,8 +4,6 @@ #include class projectM; -#include -#include class QPulseAudioThread : public QThread { @@ -18,12 +16,9 @@ class QPulseAudioThread : public QThread void cleanup(); private: - void init(); int argc; char ** argv; QTimer * m_timer; - pa_sample_spec ss ; - pa_simple * s ; projectM * m_projectM; };