Advertisement
sbaldovi

fuse_pulseaudio_simple.diff

Aug 20th, 2012
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.06 KB | None | 0 0
  1. Index: configure.in
  2. ===================================================================
  3. --- configure.in    (revision 4729)
  4. +++ configure.in    (working copy)
  5. @@ -472,6 +472,25 @@
  6.    AC_SUBST(PNG_LIBS)
  7.  fi
  8.  
  9. +dnl Check if pulseaudio is available
  10. +AC_MSG_CHECKING(whether pulseaudio requested)
  11. +AC_ARG_WITH(pulseaudio,
  12. +[  --without-pulseaudio          don't use libpulse (pulseaudio)],
  13. +if test "$withval" = no; then libpulse=no; else libpulse=yes; fi,
  14. +libpulse=yes)
  15. +AC_MSG_RESULT($libpulse)
  16. +if test "$libpulse" = yes; then
  17. +  AC_CHECK_LIB( pulse-simple, pa_simple_new,
  18. +    [AC_CHECK_HEADER(
  19. +      pulse/simple.h,
  20. +      [pulse_available=yes],
  21. +      [AC_MSG_WARN(pulse/simple.h not found - no pulseaudio output)]
  22. +    )],
  23. +    [AC_MSG_WARN(pa_simple_new not found - no pulseaudio output)]
  24. +  )
  25. +fi
  26. +
  27. +
  28.  dnl Check if a version of libasound which supplies pcm is available
  29.  AC_MSG_CHECKING(whether ALSA requested)
  30.  AC_ARG_WITH(alsa,
  31. @@ -546,6 +565,9 @@
  32.  elif test "$win32sound_available" = yes; then
  33.    SOUND_LIBADD='win32sound.$(OBJEXT)' SOUND_LIBS='-lwinmm'
  34.    AC_MSG_RESULT(win32sound)
  35. +elif test "$pulse_available" = yes; then
  36. +  SOUND_LIBADD='pulsesound.$(OBJEXT)' SOUND_LIBS='-lpulse-simple'
  37. +  AC_MSG_RESULT(pulseaudio)
  38.  elif test "$alsa_available" = yes; then
  39.    SOUND_LIBADD='alsasound.$(OBJEXT)' SOUND_LIBS='-lasound'
  40.    AC_MSG_RESULT(ALSA)
  41. Index: sound/pulsesound.c
  42. ===================================================================
  43. --- sound/pulsesound.c  (revision 0)
  44. +++ sound/pulsesound.c  (revision 0)
  45. @@ -0,0 +1,143 @@
  46. +/* pulsesound.c: pulseaudio (Linux) sound I/O
  47. +   Copyright (c) 2010 Grzegorz Jablonski
  48. +
  49. +   $Id$
  50. +
  51. +   This program is free software; you can redistribute it and/or modify
  52. +   it under the terms of the GNU General Public License as published by
  53. +   the Free Software Foundation; either version 2 of the License, or
  54. +   (at your option) any later version.
  55. +
  56. +   This program is distributed in the hope that it will be useful,
  57. +   but WITHOUT ANY WARRANTY; without even the implied warranty of
  58. +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  59. +   GNU General Public License for more details.
  60. +
  61. +   You should have received a copy of the GNU General Public License along
  62. +   with this program; if not, write to the Free Software Foundation, Inc.,
  63. +   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  64. +
  65. +*/
  66. +
  67. +#include <config.h>
  68. +
  69. +#include <stdio.h>
  70. +#include <string.h>
  71. +
  72. +#include <libspectrum.h>
  73. +#include <pulse/error.h>
  74. +#include <pulse/simple.h>
  75. +#include <pulse/timeval.h>
  76. +
  77. +#include "sound.h"
  78. +
  79. +static pa_simple *pulse_s;
  80. +static int verbose = 0;
  81. +
  82. +void
  83. +sound_lowlevel_end( void )
  84. +{
  85. +  pa_simple_free( pulse_s );
  86. +}
  87. +
  88. +int
  89. +sound_lowlevel_init( const char *device, int *freqptr, int *stereoptr )
  90. +{
  91. +  pa_sample_spec ss;
  92. +  pa_buffer_attr buf;
  93. +  unsigned int n;
  94. +  unsigned int val;
  95. +  const char *option;
  96. +  char tmp;
  97. +  int err;
  98. +  int bsize = 0;
  99. +  int bdelay = 30;
  100. +
  101. +  /* scan explicitly given parameters */
  102. +  option = device;
  103. +  while( option && *option ) {
  104. +    tmp = '*';
  105. +    if( ( err = sscanf( option, " tlength=%ims %n%c", &val, &n, &tmp ) > 0 ) &&
  106. +        ( tmp == ',' || strlen( option ) == n ) ) {
  107. +      if( val < 1 ) {
  108. +        fprintf( stderr, "Bad value for PULSEAUDIO tlength, using default\n" );
  109. +      } else {
  110. +        bdelay = val;
  111. +      }
  112. +    } else if( ( err = sscanf( option, " tlength=%i %n%c", &val, &n, &tmp ) > 0 ) &&
  113. +        ( tmp == ',' || strlen( option ) == n ) ) {
  114. +      if( val < 1 ) {
  115. +        fprintf( stderr, "Bad value for PULSEAUDIO tlength, using default\n" );
  116. +      } else {
  117. +        bsize = val;
  118. +      }
  119. +    } else if( ( err = sscanf( option, " verbose %n%c", &n, &tmp ) == 1 ) &&
  120. +              ( tmp == ',' || ( strlen( option ) == n ) ) ) {
  121. +      verbose = 1;
  122. +    }
  123. +
  124. +    option += n + ( tmp == ',' );
  125. +  }
  126. +
  127. +#if defined WORDS_BIGENDIAN
  128. +  ss.format = PA_SAMPLE_S16BE;
  129. +#else
  130. +  ss.format = PA_SAMPLE_S16LE;
  131. +#endif
  132. +
  133. +  ss.channels = ( *stereoptr )? 2 : 1;
  134. +  ss.rate = *freqptr;
  135. +
  136. +  /* Reduce latency to 30ms or the user-defined value. pulseaudio does
  137. +     not guarantee that. */
  138. +  buf.tlength = (bsize)? bsize :
  139. +                         pa_usec_to_bytes( bdelay * PA_USEC_PER_MSEC, &ss );
  140. +
  141. +  buf.maxlength = buf.tlength * 4;
  142. +  buf.minreq = buf.tlength / 4;
  143. +  buf.prebuf = (uint32_t) -1;
  144. +  buf.fragsize = (uint32_t) -1;
  145. +
  146. +  if( verbose ) {
  147. +    fprintf( stdout, "buffer requested: maxlength=%lu, tlength=%lu, prebuf=%lu,"
  148. +             " minreq=%lu\n",
  149. +             (unsigned long) buf.maxlength,
  150. +             (unsigned long) buf.tlength,
  151. +             (unsigned long) buf.prebuf,
  152. +             (unsigned long) buf.minreq );
  153. +  }
  154. +
  155. +  pulse_s = pa_simple_new( NULL, PACKAGE, PA_STREAM_PLAYBACK, NULL,
  156. +                           "Spectrum", &ss, NULL, &buf, &err );
  157. +  if( pulse_s == NULL ) {
  158. +    fprintf( stderr, "pulseaudio: pa_simple_new() failed: %s\n",
  159. +             pa_strerror( err ) );
  160. +    return 1;
  161. +  }
  162. +
  163. +  return 0;
  164. +}
  165. +
  166. +void
  167. +sound_lowlevel_frame( libspectrum_signed_word *data, int len )
  168. +{
  169. +  int retval, error;
  170. +
  171. +  /*   to measure sound lag
  172. +  pa_usec_t latency;
  173. +  latency = pa_simple_get_latency( pulse_s, &error );
  174. +  if( latency == (pa_usec_t) - 1 ) {
  175. +    fprintf( stderr, "pulseaudio: pa_simple_get_latency() failed: %s\n",
  176. +             pa_strerror( error ) );
  177. +  } else {
  178. +    fprintf( stderr, "%0.0f ", (float)latency / PA_USEC_PER_MSEC );
  179. +  }
  180. +  */
  181. +
  182. +  retval = pa_simple_write( pulse_s, data, 2*len, &error );
  183. +
  184. +  if( verbose && retval < 0 ) {
  185. +    fprintf( stderr, "pulseaudio: pa_simple_write() failed: %s\n",
  186. +             pa_strerror( error ) );
  187. +  }
  188. +}
  189. Index: sound/Makefile.am
  190. ===================================================================
  191. --- sound/Makefile.am   (revision 4729)
  192. +++ sound/Makefile.am   (working copy)
  193. @@ -38,6 +38,7 @@
  194.                    hpsound.c \
  195.                    nullsound.c \
  196.                    osssound.c \
  197. +                  pulsesound.c \
  198.                    sdlsound.c \
  199.                    sfifo.c \
  200.                    sunsound.c \
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement