Exemple #1
0
static bool
ao_play_chunk(struct audio_output *ao, const struct music_chunk *chunk)
{
    GError *error = NULL;

    assert(ao != NULL);
    assert(ao->filter != NULL);

    if (chunk->tag != NULL) {
        g_mutex_unlock(ao->mutex);
        ao_plugin_send_tag(ao->plugin, ao->data, chunk->tag);
        g_mutex_lock(ao->mutex);
    }

    size_t size;
    const char *data = ao_filter_chunk(ao, chunk, &size);
    if (data == NULL) {
        ao_close(ao, false);

        /* don't automatically reopen this device for 10
           seconds */
        ao->fail_timer = g_timer_new();
        return false;
    }

    while (size > 0 && ao->command == AO_COMMAND_NONE) {
        size_t nbytes;

        if (!ao_wait(ao))
            break;

        g_mutex_unlock(ao->mutex);
        nbytes = ao_plugin_play(ao->plugin, ao->data, data, size,
                                &error);
        g_mutex_lock(ao->mutex);
        if (nbytes == 0) {
            /* play()==0 means failure */
            g_warning("\"%s\" [%s] failed to play: %s",
                      ao->name, ao->plugin->name, error->message);
            g_error_free(error);

            ao_close(ao, false);

            /* don't automatically reopen this device for
               10 seconds */
            assert(ao->fail_timer == NULL);
            ao->fail_timer = g_timer_new();

            return false;
        }

        assert(nbytes <= size);
        assert(nbytes % audio_format_frame_size(&ao->out_audio_format) == 0);

        data += nbytes;
        size -= nbytes;
    }

    return true;
}
Exemple #2
0
static void
ao_output_close(void *data)
{
	struct ao_data *ad = (struct ao_data *)data;

	ao_close(ad->device);
}
Exemple #3
0
static int detect(void)
{
  int driver_id, result = 0;
  ao_sample_format ao_sample_format_ctx;
  ao_device *ao_device_ctx;

  ao_initialize();

  /* Only succeed in autodetect mode when pulseaudio is available! */
  driver_id = ao_driver_id("pulse");

  ao_sample_format_ctx.rate = 44100;
  ao_sample_format_ctx.bits = 16;
  ao_sample_format_ctx.channels = 2;
  ao_sample_format_ctx.byte_format = AO_FMT_NATIVE;
  ao_sample_format_ctx.matrix = NULL;

  if ((ao_device_ctx = ao_open_live(driver_id, &ao_sample_format_ctx, NULL))) {
    result = 1;
    ao_close(ao_device_ctx);
  }

  ao_shutdown();

  return result;
}
Exemple #4
0
static void ao_pause(struct audio_output *ao)
{
    bool ret;

    g_mutex_unlock(ao->mutex);
    ao_plugin_cancel(ao->plugin, ao->data);
    g_mutex_lock(ao->mutex);

    ao->pause = true;
    ao_command_finished(ao);

    do {
        if (!ao_wait(ao))
            break;

        g_mutex_unlock(ao->mutex);
        ret = ao_plugin_pause(ao->plugin, ao->data);
        g_mutex_lock(ao->mutex);

        if (!ret) {
            ao_close(ao, false);
            break;
        }
    } while (ao->command == AO_COMMAND_NONE);

    ao->pause = false;
}
int muroard_driver_free(void) {
 if ( muroard_state_member(driver_vp) != NULL )
  ao_close(muroard_state_member(driver_vp));

 ao_shutdown();
 return 0;
}
void sal_AudioClose(void)
{
        if (ao_dev)
          ao_close(ao_dev);
        ao_dev = NULL;
        ao_shutdown();
}
Exemple #7
0
static void
ao_output_close(struct audio_output *ao)
{
	struct ao_data *ad = (struct ao_data *)ao;

	ao_close(ad->device);
}
Exemple #8
0
BOOL
wave_out_set_format(WAVEFORMATEX * pwfx)
{
	ao_sample_format format;

	format.bits = pwfx->wBitsPerSample;
	format.channels = pwfx->nChannels;
	g_channels = pwfx->nChannels;
	format.rate = 44100;
	g_samplerate = pwfx->nSamplesPerSec;
	format.byte_format = AO_FMT_LITTLE;

	g_samplewidth = pwfx->wBitsPerSample / 8;

	if (o_device != NULL)
		ao_close(o_device);

	o_device = ao_open_live(default_driver, &format, NULL);
	if (o_device == NULL)
	{
		return False;
	}

	g_reopened = True;

	return True;
}
Exemple #9
0
static void
ao_reopen(struct audio_output *ao)
{
    if (!audio_format_fully_defined(&ao->config_audio_format)) {
        if (ao->open) {
            const struct music_pipe *mp = ao->pipe;
            ao_close(ao, true);
            ao->pipe = mp;
        }

        /* no audio format is configured: copy in->out, let
           the output's open() method determine the effective
           out_audio_format */
        ao->out_audio_format = ao->in_audio_format;
        audio_format_mask_apply(&ao->out_audio_format,
                                &ao->config_audio_format);
    }

    if (ao->open)
        /* the audio format has changed, and all filters have
           to be reconfigured */
        ao_reopen_filter(ao);
    else
        ao_open(ao);
}
Exemple #10
0
void play_stream(char *stream_uri) {

  ch = curl_easy_init();
  if (ch) {
    curl_easy_setopt(ch, CURLOPT_URL, stream_uri);
    curl_easy_setopt(ch, CURLOPT_FOLLOWLOCATION, 1L);
    curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, write_callback);
    curl_easy_setopt(ch, CURLOPT_PROGRESSFUNCTION, progress_callback);
    curl_easy_setopt(ch, CURLOPT_NOPROGRESS,
                     0L); // make curl use the progress_callback

    mh = mpg123_new(NULL, NULL);
    if (mh) {
      mpg123_open_feed(mh);

      curl_easy_perform(ch);
      curl_easy_cleanup(ch);

      mpg123_close(mh);
      mpg123_delete(mh);

      ao_close(device);

      playback_stop = 0;
    }
  }
}
Exemple #11
0
/* Stop Sound Core */
void RemoveSound(void)
{
#ifndef NOSOUND
 	ao_close(ao_dev);
	ao_shutdown();
#endif
}
int cAudio::PrepareClipPlay(int ch, int srate, int bits, int le)
{
	lt_debug("%s ch %d srate %d bits %d le %d adevice %p\n", __func__, ch, srate, bits, le, adevice);;
	int driver;
	int byte_format = le ? AO_FMT_LITTLE : AO_FMT_BIG;
	if (sformat.bits != bits || sformat.channels != ch || sformat.rate != srate ||
	    sformat.byte_format != byte_format || adevice == NULL)
	{
		driver = ao_default_driver_id();
		sformat.bits = bits;
		sformat.channels = ch;
		sformat.rate = srate;
		sformat.byte_format = byte_format;
		sformat.matrix = 0;
		if (adevice)
			ao_close(adevice);
		adevice = ao_open_live(driver, &sformat, NULL);
		ao_info *ai = ao_driver_info(driver);
		lt_info("%s: changed params ch %d srate %d bits %d le %d adevice %p\n",
			__func__, ch, srate, bits, le, adevice);;
		lt_info("libao driver: %d name '%s' short '%s' author '%s'\n",
				driver, ai->name, ai->short_name, ai->author);
	}
	return 0;
};
Exemple #13
0
// De-initialize the libPOLY environment.
void poly_shutdown()
{
	if(poly_playback == 1)
	{
		poly_stop();
	}
	if(poly_card != NULL)
	{
		ao_close(poly_card);
		poly_card = NULL;
	}
	if(poly_format != NULL)
	{
		free(poly_format);
		poly_format = NULL;
	}
	if(poly_ao_init == 1)
	{
		ao_shutdown();
	}
	if(poly_generators != NULL)
	{
		free(poly_generators);
		poly_generators = NULL;
	}
	return;
}
Exemple #14
0
RD_BOOL
libao_set_format(RD_WAVEFORMATEX * pwfx)
{
	ao_sample_format format;

	memset(&format, 0, sizeof(format));
	format.bits = pwfx->wBitsPerSample;
	format.channels = pwfx->nChannels;
	format.rate = 44100;
	format.byte_format = AO_FMT_NATIVE;

	if (o_device != NULL)
		ao_close(o_device);

	o_device = ao_open_live(default_driver, &format, NULL);
	if (o_device == NULL)
	{
		return False;
	}

	if (rdpsnd_dsp_resample_set(44100, pwfx->wBitsPerSample, pwfx->nChannels) == False)
	{
		return False;
	}

	reopened = True;

	return True;
}
Exemple #15
0
void mpeg_close(int fd)
{
    if((handle != NULL) && (fd != -1))
    {
        if(handle->buf != NULL)
        {
            free(handle->buf);
            handle->buf = NULL;
        }

        if(handle->device != NULL)
        {
            ao_close(handle->device);
            handle->device = NULL;
        }

        if(handle->mh != NULL)
        {
            mpg123_close(handle->mh);
            mpg123_delete(handle->mh);
            handle->mh = NULL;
        }

        free(handle);
        handle = NULL;
    }
}
Exemple #16
0
int main(int argc, char *argv[]){

	if(argc < 2)
		return 0;

	ao_initialize();

	mpg123_init();
	mh = mpg123_new(NULL, NULL);
	mpg123_open_feed(mh);

	CURL *curl = curl_easy_init();
	curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, play_stream);
	curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
	curl_easy_perform(curl);
	curl_easy_cleanup(curl);

	mpg123_close(mh);
	mpg123_delete(mh);
	mpg123_exit();

	ao_close(dev);
	ao_shutdown();

	return 0;
}
Exemple #17
0
int main(int argc, char *argv[])
{
	ao_device *device;
	ao_sample_format fmt;
	double duration = NOTE_LENGTH;
	float octave_mult = 1.0f;

	if (argc == 2);  // do nothing
	else if (argc == 3)
	{
		sscanf(argv[2], "%lf", &duration);
		if (duration < 0)
		{
			printf("Note length can't be negative!\n");
			return 1;
		}
	}
	else
	{
		printf("Usage: %s notes [length]\n", argv[0]);
		return 3;
	}
	
	fmt.bits = 16;
	fmt.rate = SAMPLE_RATE;
	fmt.channels = 1;
	fmt.byte_format = AO_FMT_NATIVE;
	fmt.matrix = NULL;
	
	ao_initialize();
	
	device = ao_open_live(ao_default_driver_id(), &fmt, NULL);
	if (!device) {
		printf("Error %d opening audio device!\n", errno);
		return 2;
	}
	
	int i; for (i=0; i<strlen(argv[1]); i++)
	{
		char ch = argv[1][i];
		char capital;
		switch (ch)
		{
			case '-': octave_mult *= 0.5f; break;
			case '+': octave_mult *= 2.0f; break;
			default:
				capital = ('A' <= ch && ch <= 'G');
				if (capital) octave_mult *= 2.0f;
				play_note(device, tofreq(ch) * octave_mult, duration);
				if (capital) octave_mult *= 0.5f;
				break; //not needed, but good practice
		}
	}
	
	ao_close(device);
	ao_shutdown();
	
	return 0;
}
Exemple #18
0
static void close_output(void)
{
  if (ao_device_ctx != NULL) {
    ao_close(ao_device_ctx);
    ao_device_ctx = NULL;
    ao_shutdown();
  }
}
Exemple #19
0
void output_ao::close()
{
  if (device != NULL) {
    ao_close(device);
    free(device);
    device = NULL;
  }
}
void AoEngine::uninit() {
	if (aoDevice) {
		ao_close(aoDevice);
		aoDevice = NULL;
		
		ao_shutdown();
	}
}
Exemple #21
0
static void
audio_destroy(void *cls, void *opaque)
{
	shairplay_session_t *session = opaque;

	ao_close(session->device);
	free(session);
}
Exemple #22
0
/* SNDDMA_Shutdown: shutdown the DMA xfer
 */
void SNDDMA_Shutdown(void){
	if(snd_inited){
		ao_close(device);
		ao_shutdown();
		free(si->dma->buffer);
		si->dma->buffer = 0;
		snd_inited = 0;
	}
}
Exemple #23
0
void au_playWait(int snd){
  if(!mute || effects){
    //need to repeat this code because au_deinitEach() calls exit();
    default_driver = ao_default_driver_id();
    device = ao_open_live(default_driver, &format, NULL);
    ao_play(device, sounds[snd], sz[snd]);
    ao_close(device);
  }
}
cAudio::~cAudio(void)
{
	closeDevice();
	free(dmxbuf);
	if (adevice)
		ao_close(adevice);
	adevice = NULL;
	ao_shutdown();
}
Exemple #25
0
void audio_close(void)
{
	if (libao_device) {
		/* Work-around libao/alsa, sleep 10ms to drain audio stream. */
		usleep(10000);

		ao_close(libao_device);
	}
}
Exemple #26
0
void cleanup()
{
	mpg123_close(mh);
	mpg123_delete(mh);
	mpg123_exit();

	ao_close(dev);
	ao_shutdown();
}
Exemple #27
0
void close_sound(void)
{
    free(buffer);
    ao_close(dev);
    mpg123_close(mh);
    mpg123_delete(mh);
    mpg123_exit();
    ao_shutdown();
}
Exemple #28
0
static enum mad_flow output(
		void * data,
		const struct mad_header * head,
		struct mad_pcm * pcm) {
	struct stream * ptr = (struct stream *) data;

	unsigned nchan = pcm->channels, rate = pcm->samplerate;
	register unsigned nsample = pcm->length;
	mad_fixed_t * left = pcm->samples[0], * right = pcm->samples[1];
	char *stream, *stream_ptr;

	head = NULL;

	if((signed) rate != ptr->fmt.rate || (signed) nchan != ptr->fmt.channels) {
		ptr->fmt.rate = rate;
		ptr->fmt.channels = nchan;
		if(ptr->device != NULL)
			ao_close(ptr->device);
		ptr->device = ao_open_live(ptr->driver_id, & ptr->fmt, NULL);

		if(NULL == ptr->device) {
			fprintf(stderr, "Unable to open device. %s.\n", strerror(errno));
			return MAD_FLOW_BREAK;
		}
	}

	stream_ptr = stream = malloc(pcm->length * (pcm->channels == 2 ? 4 : 2));

	assert(stream != NULL);
	read_from_pipe(ptr->pipefd);
	
	while(nsample--) {
		signed int sample;

		sample = scale(* left++);
		/* to byteswap or not to byteswap? */
#ifdef WORDS_BIGENDIAN
		*stream_ptr++ = (sample >> 8) & 0xFF;
		*stream_ptr++ = (sample & 0xFF);
#else
		*stream_ptr++ = (sample & 0xFF);
		*stream_ptr++ = (sample >> 8) & 0xFF;
#endif

		if(nchan == 2) {
			sample = scale(* right++);
#ifdef WORDS_BIGENDIAN
			*stream_ptr++ = (sample >> 8) & 0xFF;
			*stream_ptr++ = (sample & 0xFF);
#else
			*stream_ptr++ = (sample & 0xFF);
			*stream_ptr++ = (sample >> 8) & 0xFF;
#endif
		}
	}
Exemple #29
0
void close_audio_devices (audio_device_t *devices)
{
  audio_device_t *current = devices;

  while (current != NULL) {
    if (current->device)
      ao_close(current->device);
    current->device = NULL;
    current = current->next_device;
  }
}
Exemple #30
0
void beep_shutdown(void)
{
  if (!initialized)
    return;
  free(g_beep.buffer.data);
  if (g_beep.device != NULL)
    ao_close(g_beep.device);
  ao_shutdown();
  memset(&g_beep, 0, sizeof(g_beep));
  initialized = 0;
}