Exemple #1
0
AudioDevice *Audio::getDevice(unsigned index, DeviceMode mode)
{
	int dsp, mixer;
	char fname[33];
	AudioDevice *dev;

	if(index)
		snprintf(fname, sizeof(fname), "/dev/dsp%d", index);
	else
		snprintf(fname, sizeof(fname), "/dev/dsp");

	dsp = ::open(fname, O_RDWR | O_NDELAY);
	if(dsp < 0)
		return NULL;

	if(index)
		snprintf(fname, sizeof(fname), "/dev/mixer%d", index);
	else
		snprintf(fname, sizeof(fname), "/dev/mixer");

	mixer = ::open(fname, O_RDWR | O_NONBLOCK);
	if(mixer < 0) {
		::close(dsp);
		return NULL;
	}

	dev = new OSSAudioDevice(dsp, mixer, mode);
	if(!dev->setAudio(rate8khz, false))
		dev->setAudio(rate44khz, true);
	return dev;
}
Exemple #2
0
AudioDevice *Audio::getDevice(unsigned index, DeviceMode mode)
{
	AudioDevice *dev;

	if(index > MAX_DEVICES)
		return NULL;

	if(mode != PLAY)
		return NULL;

	dev = new W32AudioDevice(index);
	dev->setAudio(rate8khz, false);
	return dev;
}
Exemple #3
0
void Tool::play(char **argv)
{
	AudioDevice *dev;
	PlayStream playfile;
	const char *path = *argv;
	Linear buffer;
	Info info;
	unsigned bufcount, pages;
	
	dev = getDevice();

	if(!hasDevice() && !dev)
	{
		cerr << "no device supported" << endl;
		exit(-1);
	}
	else if(!dev)
	{
		cerr << "device unavailable" << endl;
		exit(-1);
	}

	playfile.open(argv);

	if(!playfile.isOpen())
	{
		cerr << "audiotool: " << path << ": unable to access" << endl;
		exit(-1);
	}

	if(!playfile.isStreamable())
	{
		cerr << "audiotool: " << path << ": missing needed codec" << endl;
		exit(-1);
	}

	playfile.getInfo(&info);
	if(!dev->setAudio((Rate)info.rate, isStereo(info.encoding), 10))
	{
		cerr << "audiotool: sound device does not support rate" << endl;
		exit(-1);
	}

	bufcount = playfile.getCount();
	if(isStereo(info.encoding))
		buffer = new Sample[bufcount * 2];
	else
		buffer = new Sample[bufcount];

	for(;;)
	{
		if(isStereo(info.encoding))
			pages = playfile.getStereo(buffer, 1);
		else
			pages = playfile.getMono(buffer, 1);

		if(!pages)
			break;

		dev->putSamples(buffer, bufcount);
	}

	dev->sync();
	delete dev;
	playfile.close();		
	exit(0);
}