<commit_before>#include <stdlib.h>
#include <stdio.h>
#include <string.h>		/* memset() */
#include <strings.h>
#include <math.h>

#include "portaudio.h"
#include "allocore/io/al_AudioIO.hpp"

namespace al{

/*
static void err(const char * msg, const char * src, bool exits){
	fprintf(stderr, "%s%serror: %s\n", src, src[0]?" ":"", msg);
	if(exits) exit(EXIT_FAILURE);
}
*/

static void warn(const char * msg, const char * src){
	fprintf(stderr, "%s%swarning: %s\n", src, src[0]?" ":"", msg);
}

template <class T>
static void deleteBuf(T *& buf){ delete[] buf; buf=0; }

static inline int min(int x, int y){ return x<y?x:y; }

template <class T>
static int resize(T *& buf, int n){
	deleteBuf(buf);
	buf = new T[n];
	return n;
}

template <class T>
static inline void zero(T * buf, int n){ bzero(buf, n*sizeof(T)); }

template <class T>
static void deinterleave(T * dst, const T * src, int numFrames, int numChannels){
	int numSamples = numFrames * numChannels;
	for(int c=0; c < numChannels; c++){
		for(int i=c; i < numSamples; i+=numChannels){
			*dst++ = src[i];
		}
	}
}

template <class T>
static void interleave(T * dst, const T * src, int numFrames, int numChannels){
	int numSamples = numFrames * numChannels;
	for(int c=0; c < numChannels; c++){
		for(int i=c; i < numSamples; i+=numChannels){
			dst[i] = *src++;
		}
	}
}


//==============================================================================
AudioDevice::AudioDevice(int deviceNum)
:	mID(-1), mImpl(0)
{
	setImpl(deviceNum);
}

AudioDevice::AudioDevice(const std::string& nameKeyword, bool input, bool output)
:	mID(-1), mImpl(0)
{
	for(int i=0; i<numDevices(); ++i){
		AudioDevice d(i);
		std::string n = d.name();
		if(	((input & d.hasInput()) || (output & d.hasOutput())) &&
			n.find(nameKeyword) != std::string::npos
		){
			setImpl(i);
			break;
		}
	}
}

AudioDevice::~AudioDevice(){}

const char * AudioDevice::name() const { return ((const PaDeviceInfo*)mImpl)->name; }
int AudioDevice::channelsInMax() const { return ((const PaDeviceInfo*)mImpl)->maxInputChannels; }
int AudioDevice::channelsOutMax() const { return ((const PaDeviceInfo*)mImpl)->maxOutputChannels; }
double AudioDevice::defaultSampleRate() const { return ((const PaDeviceInfo*)mImpl)->defaultSampleRate; }
bool AudioDevice::hasInput() const { return channelsInMax()>0; }
bool AudioDevice::hasOutput() const { return channelsOutMax()>0; }
void AudioDevice::setImpl(int deviceNum){ initDevices(); mImpl = Pa_GetDeviceInfo(deviceNum); mID=deviceNum; }
AudioDevice AudioDevice::defaultInput(){ return AudioDevice(Pa_GetDefaultInputDevice()); }
AudioDevice AudioDevice::defaultOutput(){ return AudioDevice(Pa_GetDefaultOutputDevice()); }

struct InitSingleton{
	InitSingleton(): mCleanUp(paNoError == Pa_Initialize()){}
	~InitSingleton(){ if(mCleanUp){ Pa_Terminate(); } }
	bool mCleanUp;
};

void AudioDevice::initDevices(){
	static InitSingleton dummy;
}

int AudioDevice::numDevices(){ initDevices(); return Pa_GetDeviceCount(); }

void AudioDevice::print() const{

	//if(deviceNum == paNoDevice){ printf("No device\n"); return; }

	//const AudioDevice dev(deviceNum);<commit_msg>fixed AudioIO defaultInput and defaultOutput<commit_after>#include <stdlib.h>
#include <stdio.h>
#include <string.h>		/* memset() */
#include <strings.h>
#include <math.h>

#include "portaudio.h"
#include "allocore/io/al_AudioIO.hpp"

namespace al{

/*
static void err(const char * msg, const char * src, bool exits){
	fprintf(stderr, "%s%serror: %s\n", src, src[0]?" ":"", msg);
	if(exits) exit(EXIT_FAILURE);
}
*/

static void warn(const char * msg, const char * src){
	fprintf(stderr, "%s%swarning: %s\n", src, src[0]?" ":"", msg);
}

template <class T>
static void deleteBuf(T *& buf){ delete[] buf; buf=0; }

static inline int min(int x, int y){ return x<y?x:y; }

template <class T>
static int resize(T *& buf, int n){
	deleteBuf(buf);
	buf = new T[n];
	return n;
}

template <class T>
static inline void zero(T * buf, int n){ bzero(buf, n*sizeof(T)); }

template <class T>
static void deinterleave(T * dst, const T * src, int numFrames, int numChannels){
	int numSamples = numFrames * numChannels;
	for(int c=0; c < numChannels; c++){
		for(int i=c; i < numSamples; i+=numChannels){
			*dst++ = src[i];
		}
	}
}

template <class T>
static void interleave(T * dst, const T * src, int numFrames, int numChannels){
	int numSamples = numFrames * numChannels;
	for(int c=0; c < numChannels; c++){
		for(int i=c; i < numSamples; i+=numChannels){
			dst[i] = *src++;
		}
	}
}


//==============================================================================
AudioDevice::AudioDevice(int deviceNum)
:	mID(-1), mImpl(0)
{
	setImpl(deviceNum);
}

AudioDevice::AudioDevice(const std::string& nameKeyword, bool input, bool output)
:	mID(-1), mImpl(0)
{
	for(int i=0; i<numDevices(); ++i){
		AudioDevice d(i);
		std::string n = d.name();
		if(	((input & d.hasInput()) || (output & d.hasOutput())) &&
			n.find(nameKeyword) != std::string::npos
		){
			setImpl(i);
			break;
		}
	}
}

AudioDevice::~AudioDevice(){}

const char * AudioDevice::name() const { return ((const PaDeviceInfo*)mImpl)->name; }
int AudioDevice::channelsInMax() const { return ((const PaDeviceInfo*)mImpl)->maxInputChannels; }
int AudioDevice::channelsOutMax() const { return ((const PaDeviceInfo*)mImpl)->maxOutputChannels; }
double AudioDevice::defaultSampleRate() const { return ((const PaDeviceInfo*)mImpl)->defaultSampleRate; }
bool AudioDevice::hasInput() const { return channelsInMax()>0; }
bool AudioDevice::hasOutput() const { return channelsOutMax()>0; }
void AudioDevice::setImpl(int deviceNum){ initDevices(); mImpl = Pa_GetDeviceInfo(deviceNum); mID=deviceNum; }
AudioDevice AudioDevice::defaultInput(){ initDevices(); return AudioDevice(Pa_GetDefaultInputDevice()); }
AudioDevice AudioDevice::defaultOutput(){ initDevices(); return AudioDevice(Pa_GetDefaultOutputDevice()); }

struct InitSingleton{
	InitSingleton(): mCleanUp(paNoError == Pa_Initialize()){}
	~InitSingleton(){ if(mCleanUp){ Pa_Terminate(); } }
	bool mCleanUp;
};

void AudioDevice::initDevices(){
	static InitSingleton dummy;
}

int AudioDevice::numDevices(){ initDevices(); return Pa_GetDeviceCount(); }

void AudioDevice::print() const{

	//if(deviceNum == paNoDevice){ printf("No device\n"); return; }

	//const AudioDevice dev(deviceNum);
{'fraction_non_alphanumeric': 0.1930685235005539, 'fraction_numerical': 0.0037980693147649943, 'mean_word_length': 5.862106406080348, 'pattern_counts': {'":': 4, '<': 35, '<?xml version=': 0, '>': 35, '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': '7519237', 'n_tokens_mistral': 2232, 'n_tokens_neox': 2169, 'n_words': 543}