static void* pulse_thread(void* context)
{
	sem_t* init = (sem_t*)context;

	pa_sample_spec ss;
	ss.format = PA_SAMPLE_S16LE;
	ss.channels = 2;
	ss.rate = g_sample_rate;

	int err;
	g_pulse = pa_simple_new(NULL, g_appname, PA_STREAM_PLAYBACK, NULL, g_appname, &ss, NULL, NULL, &err);
	if (!g_pulse) {
		snprintf(g_lasterror, c_nlasterror, "failed to connect to pulse server: %d", err);
	}

	sem_post(init);
	if (!g_pulse)
		return 0;

	pa_simple* s = g_pulse;
	short samples[c_nsamples*2];

	g_running = true;
	while (g_running) {
		g_callback(samples, c_nsamples);
		if (0 > pa_simple_write(s, samples, sizeof(samples), NULL))
			break;
	}

	pa_simple_flush(s, NULL);
	pa_simple_free(s);
	g_pulse = 0;
	return 0;
}
Example #2
0
static int pulsedrv_suspend(void)
{
    int error = 0;
    if (pa_simple_flush(s, &error)) {
        log_error(LOG_DEFAULT, "pa_simple_flush(): %s", pa_strerror(error));
        return 1;
    }
    return 0;
}
uint8_t  pulseSimpleAudioDevice::stop(void) 
{
int er;
    ADM_assert(instance);
    pa_simple_flush(INSTANCE,&er);
    pa_simple_free(INSTANCE);
    instance=NULL;
    printf("[PulseAudio] Stopped\n");
    return 1;
}
Example #4
0
static void pulsedrv_close(void)
{
    int error = 0;
    if (pa_simple_flush(s, &error)) {
        log_error(LOG_DEFAULT, "pa_simple_flush(): %s", pa_strerror(error));
        /* don't stop */
    }
    pa_simple_free(s);
    s = NULL;
}
Example #5
0
static void
pulse_flush (sw_handle * handle)
{
  struct pa_simple * pa ;
  int error;

  if ((pa = (struct pa_simple *)handle->custom_data) == NULL)
    return;

  if (pa_simple_flush(pa, &error) < 0) {
    fprintf(stderr, __FILE__": pa_simple_flush() failed: %s\n", pa_strerror(error));
  }
}
Example #6
0
void m1sdr_PlayStop(void)
{
	#if 0
	pa_operation *op;
	#endif

	#ifdef USE_SDL
	if (lnxdrv_apimode == 0) 
	{
		SDL_PauseAudio(1);
	}
	#endif

	if (lnxdrv_apimode == 1)
	{
//		snd_pcm_pause(pHandle, 1);
		snd_pcm_drop(pHandle);
	}

	#if PULSE_USE_SIMPLE
	if ((lnxdrv_apimode == 3) && (my_simple))
	{
		pa_simple_flush(my_simple, NULL);
		pa_simple_free(my_simple);
		my_simple = NULL;
	}
	#else
#if 0
	if (lnxdrv_apimode == 3)
	{
		op = pa_stream_drain(my_pa_stream, &pa_stream_drain_complete, NULL);
		if (op)
		{
			while (pa_operation_get_state(op) != PA_OPERATION_DONE)
			{
				if (pa_context_get_state(my_pa_context) != PA_CONTEXT_READY ||
				    pa_stream_get_state(my_pa_stream) != PA_STREAM_READY ||
				    pa_mainloop_iterate(my_pa_mainloop, 0, NULL) < 0)
				    {
				    	pa_operation_cancel(op);
					break;
				    }
			}
		}
	}
#endif
	#endif

	waveLogStop();
	oss_playing = 0;
}
Example #7
0
static void *pulseaudio_update(ALLEGRO_THREAD *self, void *data)
{
   ALLEGRO_VOICE *voice = data;
   PULSEAUDIO_VOICE *pv = voice->extra;

   while (!al_get_thread_should_stop(self)) {
      if (pv->status == PV_PLAYING) {
         unsigned int frames = 4096;
         if (voice->is_streaming) { 
            // streaming audio           
            const void *data = _al_voice_update(voice, &frames);
            if (data) {
               pa_simple_write(pv->s, data, frames * pv->frame_size, NULL);
            }
         }
         else {
            // direct buffer audio
            al_lock_mutex(pv->buffer_mutex);
            const char *data = pv->buffer;
            unsigned int len = frames * pv->frame_size;
            pv->buffer += frames * pv->frame_size;
            if (pv->buffer > pv->buffer_end) {
               len = pv->buffer_end - data;
               pv->buffer = voice->attached_stream->spl_data.buffer.ptr;
               voice->attached_stream->pos = 0;
               if (voice->attached_stream->loop == ALLEGRO_PLAYMODE_ONCE) {
                  pv->status = PV_STOPPING;
               }
            }
            else {
               voice->attached_stream->pos += frames;
            }
            al_unlock_mutex(pv->buffer_mutex);

            pa_simple_write(pv->s, data, len, NULL);
         }
      }
      else if (pv->status == PV_STOPPING) {
         pa_simple_flush(pv->s, NULL);
         pv->status = PV_STOPPED;
      }
      else if (pv->status == PV_STOPPED) {
         al_rest(0.001);
      }
   }

   return NULL;
}
Example #8
0
static int pulse_destroy(struct iaxc_audio_driver *d)
{
  
  if (d->priv)
  {
    pa_simple *p = (pa_simple*)(d->priv);
    pa_simple_flush(p,NULL);
  }

  
  if (d->priv)
  {
    pa_simple *p = (pa_simple*)(d->priv);
    pa_simple_free(p);
  }

  return 0;
}
Example #9
0
static int pulse_play(void)
{
    trace ("pulse_play\n");
    deadbeef->mutex_lock (mutex);
    if (!pulse_tid)
    {
        if (pulse_init () < 0)
        {
            deadbeef->mutex_unlock (mutex);
            return -1;
        }
    }

    pa_simple_flush (s, NULL);
    state = OUTPUT_STATE_PLAYING;
    deadbeef->mutex_unlock (mutex);

    return 0;
}
Example #10
0
static gpointer
player_av_audio_loop (PlayerAV *self)
{
    pa_simple *s;
    pa_sample_spec ss;

    ss.format = PA_SAMPLE_S16LE;
    ss.rate = self->priv->actx->sample_rate;
    ss.channels = self->priv->actx->channels;

    s = pa_simple_new (NULL, "GMediaMP", PA_STREAM_PLAYBACK, NULL, "Music", &ss,
        NULL, NULL, NULL);

    int64_t pts;

    gint len, lcv;
    short *abuffer = (short*) av_malloc (AVCODEC_MAX_AUDIO_FRAME_SIZE * self->priv->actx->channels * sizeof (uint8_t));

    double atime, ctime;

    while ((len = player_av_get_audio_frame (self, abuffer, &pts)) > 0) {
        if (pts != AV_NOPTS_VALUE) {
            atime = pts * av_q2d (self->priv->fctx->streams[self->priv->astream]->time_base);
            ctime = (av_gettime () - self->priv->start_time) / 1000000.0;

            self->priv->start_time += (1000000 * (ctime - atime));
        }

        if (len > 0) {
            gint i;
            for (i = 0; i < len / sizeof (short); i++) {
                gdouble val = self->priv->volume * abuffer[i];
                if (val > 32767) {
                    abuffer[i] = 32767;
                } else if (val < -32768) {
                    abuffer[i] = -32768;
                } else {
                    abuffer[i] = val;
                }
            }

            pa_simple_write (s, abuffer, len, NULL);
        }

        if (atime >= self->priv->fctx->duration) {
            break;
        }

        if (self->priv->state != PLAYER_STATE_PLAYING) {
            break;
        }
    }

    if (self->priv->state == PLAYER_STATE_PLAYING) {
        self->priv->state = PLAYER_STATE_STOPPED;
        _player_emit_eos (PLAYER (self));
    }

    av_free (abuffer);

    pa_simple_flush (s, NULL);
    pa_simple_free (s);
}
Example #11
0
void m1sdr_Exit(void)
{	
	int i;

	if (!hw_present) return;

	switch (lnxdrv_apimode)
	{
	case 0:	// SDL
		#ifdef USE_SDL
		SDL_QuitSubSystem(SDL_INIT_AUDIO);

		for (i = 0; i < kMaxBuffers; i++)
		{
			if (buffer[i])
			{
				free((void *)buffer[i]);
				buffer[i] = (volatile INT16 *)NULL;
			}
		}
		#endif
		break;	

	case 1:	// ALSA
//		printf("ALSA kill handle %x\n", pHandle);
		if (pHandle > 0)
		{
			snd_pcm_close(pHandle);
		}
		break;	

	case 2:	// OSS
		close(audiofd);
		break;	

	case 3:	// PulseAudio
		if (my_pa_stream)
		{
			pa_stream_disconnect(my_pa_stream);
			pa_stream_unref(my_pa_stream);
		}

		if (my_pa_context)
		{
			pa_context_disconnect(my_pa_context);
			pa_context_unref(my_pa_context);
		}

//		pa_signal_done();

		if (my_pa_mainloop)
		{
			pa_mainloop_free(my_pa_mainloop);
		}

		#if PULSE_USE_SIMPLE
		if (my_simple)
		{
			pa_simple_flush(my_simple, NULL);
			pa_simple_free(my_simple);
		}
	
		my_simple = NULL;
		#endif

		my_pa_context = NULL;
		my_pa_stream = NULL;
		my_pa_mainloop = NULL;
		my_pa_mainloop_api = NULL;
		break;
	}
}
Example #12
0
void OutputPulseAudio::reset()
{
    int error;
    if (m_connection)
        pa_simple_flush(m_connection, &error);
}