<commit_before>/*
 * libao.c -- The libao backend for the spd_audio library.
 *
 * Author: <NAME> <<EMAIL>>
 * Date:  2009-12-15
 *
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Leser General Public License as published by the Free
 * Software Foundation; either version 2.1, or (at your option) any later
 * version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this package; see the file COPYING.  If not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <sys/time.h>
#include <time.h>
#include <string.h>
#include <ao/ao.h>
#include <glib.h>

#define SPD_AUDIO_PLUGIN_ENTRY otts_libao_LTX_spd_audio_plugin_get
#include "spd_audio_plugin.h"

/* send a packet of XXX bytes to the sound device */
#define AO_SEND_BYTES 256
/* Put a message into the logfile (stderr) */
#define MSG(level, arg...) \
 if(level <= libao_log_level){ \
     time_t t; \
     struct timeval tv; \
     char *tstr; \
     t = time(NULL); \
     tstr = g_strdup(ctime(&t)); \
     tstr[strlen(tstr)-1] = 0; \
     gettimeofday(&tv,NULL); \
     fprintf(stderr," %s [%d]",tstr, (int) tv.tv_usec); \
     fprintf(stderr," libao:: "); \
     fprintf(stderr,arg); \
     fprintf(stderr,"\n"); \
     fflush(stderr); \
     g_free(tstr); \
  }

#define ERR(arg...) \
 { \
     time_t t; \
     struct timeval tv; \
     char *tstr; \
     t = time(NULL); \
     tstr = g_strdup(ctime(&t)); \
     tstr[strlen(tstr)-1] = 0; \
     gettimeofday(&tv,NULL); \
     fprintf(stderr," %s [%d]",tstr, (int) tv.tv_usec); \
     fprintf(stderr," libao ERROR: "); \
     fprintf(stderr,arg); \
     fprintf(stderr,"\n"); \
     fflush(stderr); \
     g_free(tstr); \
  }

static volatile int ao_stop_playback = 0;

static int default_driver;
static int libao_log_level;

ao_device *device = NULL;

static AudioID *libao_open(void **pars)
{
	AudioID *id;

	id = (AudioID *) g_malloc(sizeof(AudioID));

	ao_initialize();
	default_driver = ao_default_driver_id();
	return id;
}

static int libao_play(AudioID * id, AudioTrack track)
{
	int bytes_per_sample;

	int num_bytes;

	int outcnt = 0;

	signed short *output_samples;

	int i;

	ao_sample_format format;

	if (id == NULL)
		return -1;
	if (track.samples == NULL || track.num_samples <= 0)
		return 0;

	/* Choose the correct format */
	format.bits = track.bits;
	if (track.bits == 16)
		bytes_per_sample = 2;
	else if (track.bits == 8)
		bytes_per_sample = 1;
	else {
		ERR("Audio: Unrecognized sound data format.\n");
		return -10;
	}
	format.channels = track.num_channels;
	format.rate = track.sample_rate;<commit_msg>Fix segfault when compiled against libao 1.0.0.<commit_after>/*
 * libao.c -- The libao backend for the spd_audio library.
 *
 * Author: <NAME> <<EMAIL>>
 * Date:  2009-12-15
 *
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU Leser General Public License as published by the Free
 * Software Foundation; either version 2.1, or (at your option) any later
 * version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this package; see the file COPYING.  If not, write to the Free
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <sys/time.h>
#include <time.h>
#include <string.h>
#include <ao/ao.h>
#include <glib.h>

#define SPD_AUDIO_PLUGIN_ENTRY otts_libao_LTX_spd_audio_plugin_get
#include "spd_audio_plugin.h"

/* send a packet of XXX bytes to the sound device */
#define AO_SEND_BYTES 256
/* Put a message into the logfile (stderr) */
#define MSG(level, arg...) \
 if(level <= libao_log_level){ \
     time_t t; \
     struct timeval tv; \
     char *tstr; \
     t = time(NULL); \
     tstr = g_strdup(ctime(&t)); \
     tstr[strlen(tstr)-1] = 0; \
     gettimeofday(&tv,NULL); \
     fprintf(stderr," %s [%d]",tstr, (int) tv.tv_usec); \
     fprintf(stderr," libao:: "); \
     fprintf(stderr,arg); \
     fprintf(stderr,"\n"); \
     fflush(stderr); \
     g_free(tstr); \
  }

#define ERR(arg...) \
 { \
     time_t t; \
     struct timeval tv; \
     char *tstr; \
     t = time(NULL); \
     tstr = g_strdup(ctime(&t)); \
     tstr[strlen(tstr)-1] = 0; \
     gettimeofday(&tv,NULL); \
     fprintf(stderr," %s [%d]",tstr, (int) tv.tv_usec); \
     fprintf(stderr," libao ERROR: "); \
     fprintf(stderr,arg); \
     fprintf(stderr,"\n"); \
     fflush(stderr); \
     g_free(tstr); \
  }

static volatile int ao_stop_playback = 0;

static int default_driver;
static int libao_log_level;

ao_device *device = NULL;

static AudioID *libao_open(void **pars)
{
	AudioID *id;

	id = (AudioID *) g_malloc(sizeof(AudioID));

	ao_initialize();
	default_driver = ao_default_driver_id();
	return id;
}

static int libao_play(AudioID * id, AudioTrack track)
{
	int bytes_per_sample;

	int num_bytes;

	int outcnt = 0;

	signed short *output_samples;

	int i;

	ao_sample_format format;

	if (id == NULL)
		return -1;
	if (track.samples == NULL || track.num_samples <= 0)
		return 0;

	/* Zero the whole ao_sample_format structure. */
	memset(&format, '\0', sizeof(ao_sample_format));

	/* Choose the correct format */
	format.bits = track.bits;
	if (track.bits == 16)
		bytes_per_sample = 2;
	else if (track.bits == 8)
		bytes_per_sample = 1;
	else {
		ERR("Audio: Unrecognized sound data format.\n");
		return -10;
	}
	format.channels = track.num_channels;
	format.rate = track.sample_rate;
{'fraction_non_alphanumeric': 0.13236966054896865, 'fraction_numerical': 0.01364300795842131, 'mean_word_length': 3.2674982674982673, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4356406', 'n_tokens_mistral': 2237, 'n_tokens_neox': 2165, 'n_words': 645}