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
void Source::setSound( const SoundHandle& soundHandle )
{
	sound = soundHandle;

	Sound* sound = soundHandle.Resolve();
	if( !sound ) return;

	if( sound->getStreamed() )
		mode = SourceMode::Streaming;

	if( !audioSource )
	{
		AudioDevice* device = GetAudioDevice();
		AudioContext* context = device->getMainContext();
		audioSource = AllocateThis(AudioSource, context);
	}

	audioSource->setSound(soundHandle);

	setVolume(volume);
	setPitch(pitch);
	setRolloff(rolloff);
	setMode(mode);
	setState(state);
}
Exemple #3
0
AudioDevice::AudioDevice(const AudioDevice &dev):
    Device(dev.getId(), dev.getName(), dev.getType())
{
    // Copy the instruments
    //
    InstrumentList insList = dev.getAllInstruments();
    InstrumentList::iterator iIt = insList.begin();
    for (; iIt != insList.end(); ++iIt)
        m_instruments.push_back(new Instrument(**iIt));
}
Exemple #4
0
int main()
{
	AudioDevice *device = new AudioDevice();

	IMusic *music = device->CreateMusic();
	if (!music->LoadFromFile("music1.wav"))
	{
		printf("Failed to load sound file!");
	}
	
	IMusic *music2 = device->CreateMusic();
	if (!music2->LoadFromFile("music2.wav"))
	{

	}
	float seconds = 0;
	while (true)
	{
		char c = getchar();

		if (c == 'r')
		{
			music->Rewind();
			printf("Rewind\n");
		}
		if (c == 's')
		{
			music->Stop();
			printf("Stop\n");
		}
		if (c == 'l')
		{
			music->SetLooping(!music->IsLooping());
			printf("SetLooping: %d\n", music->IsLooping());
		}
		if (c == 'p')
		{
			if (!music->IsPlaying())
			{
				music->Play();
				music2->Play();
				printf("Play\n");
			}
			else{
				music->Pause();
				music2->Pause();
				printf("Pause\n");
			}
		}
		device->IsError();
	}
	return 0;
}
Exemple #5
0
void AudioIO::deviceOut(const AudioDevice& v){
	if(v.valid() && v.hasOutput()){
		mImpl->outDevice(v.id());
		const PaDeviceInfo * dInfo = Pa_GetDeviceInfo(mImpl->mOutParams.device);
		if(dInfo) mImpl->mOutParams.suggestedLatency = dInfo->defaultLowOutputLatency; // for RT
		mImpl->mOutParams.sampleFormat = paFloat32;// | paNonInterleaved;
		mImpl->mOutParams.hostApiSpecificStreamInfo = NULL;
	}
	else{
		warn("attempt to set output device to a device without outputs", "io::AudioIO");
	}
}
Exemple #6
0
void QtWizardAudio::saveConfig() {
	Config & config = ConfigManager::getInstance().getCurrentConfig();

	AudioDevice device = getAudioDeviceFromComboBox(_ui->inputDeviceComboBox, AudioDeviceManager::getInstance().getInputDeviceList());
	config.set(Config::AUDIO_INPUT_DEVICEID_KEY, device.getData());

	device = getAudioDeviceFromComboBox(_ui->outputDeviceComboBox, AudioDeviceManager::getInstance().getOutputDeviceList());
	config.set(Config::AUDIO_OUTPUT_DEVICEID_KEY, device.getData());

	device = getAudioDeviceFromComboBox(_ui->ringingDeviceComboBox, AudioDeviceManager::getInstance().getOutputDeviceList());
	config.set(Config::AUDIO_RINGER_DEVICEID_KEY, device.getData());

}
Exemple #7
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;
}
static int callbackByLambda(const void *inputBuffer,
                            void *outputBuffer,
                            unsigned long framesPerBuffer,
                            const PaStreamCallbackTimeInfo* timeInfo,
                            PaStreamCallbackFlags statusFlags,
                            void *userData)
{
    AudioDevice* audioDevice = (AudioDevice*)userData;
    float** output = (float**)outputBuffer;
    float** input = (float**)inputBuffer;
    
    audioDevice->getLambda()(input, audioDevice->getNumInputs() ,output, audioDevice->getNumOutputs() ,framesPerBuffer);
    
    return 0;
}
OSStatus CAPlayThrough::SetOutputDeviceAsCurrent(AudioDeviceID out)
{
    UInt32 size = sizeof(AudioDeviceID);;
    OSStatus err = noErr;
    
//        UInt32 propsize = sizeof(Float32);
    
    //AudioObjectPropertyScope theScope = mIsInput ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
    
    AudioObjectPropertyAddress theAddress = { kAudioHardwarePropertyDefaultOutputDevice,
                                              kAudioObjectPropertyScopeGlobal,
                                              kAudioObjectPropertyElementMaster };
	
	if(out == kAudioDeviceUnknown) //Retrieve the default output device
	{
		err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &size, &out);
        checkErr(err);
	}
	mOutputDevice.Init(out, false);
	
	//Set the Current Device to the Default Output Unit.
    err = AudioUnitSetProperty(mOutputUnit,
							  kAudioOutputUnitProperty_CurrentDevice, 
							  kAudioUnitScope_Global, 
							  0, 
							  &mOutputDevice.mID, 
							  sizeof(mOutputDevice.mID));
							
	return err;
}
Exemple #10
0
OSStatus CAPlayThrough::SetInputDeviceAsCurrent(AudioDeviceID in)
{
    UInt32 size = sizeof(AudioDeviceID);
    OSStatus err = noErr;
	
	if(in == kAudioDeviceUnknown) //get the default input device if device is unknown
	{  
		err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultInputDevice,
									   &size,  
									   &in);
		checkErr(err);
	}
	
	mInputDevice.Init(in, true);
	
	//Set the Current Device to the AUHAL.
	//this should be done only after IO has been enabled on the AUHAL.
    err = AudioUnitSetProperty(mInputUnit,
							  kAudioOutputUnitProperty_CurrentDevice, 
							  kAudioUnitScope_Global, 
							  0, 
							  &mInputDevice.mID, 
							  sizeof(mInputDevice.mID));
	checkErr(err);
	return err;
}
Exemple #11
0
void AudioIO::deviceIn(const AudioDevice& v) {

    if(v.valid() && v.hasInput()) {
//		printf("deviceIn: %s, %d\n", v.name(), v.id());
        mInDevice = v;
        mImpl->inDevice(v.id());
        const PaDeviceInfo * dInfo = Pa_GetDeviceInfo(mImpl->mInParams.device);
        if(dInfo) mImpl->mInParams.suggestedLatency = dInfo->defaultLowInputLatency; // for RT
        mImpl->mInParams.sampleFormat = paFloat32;// | paNonInterleaved;
        //mInParams.sampleFormat = paInt16;
        mImpl->mInParams.hostApiSpecificStreamInfo = NULL;
    }
    else {
        warn("attempt to set input device to a device without inputs", "AudioIO");
    }
}
Exemple #12
0
InstrumentId
Studio::getAudioPreviewInstrument()
{
    AudioDevice *audioDevice;
    std::vector<Device*>::iterator it;

    for (it = m_devices.begin(); it != m_devices.end(); ++it)
    {
        audioDevice = dynamic_cast<AudioDevice*>(*it);

        // Just the first one will do - we can make this more
        // subtle if we need to later.
        //
        if (audioDevice)
            return audioDevice->getPreviewInstrument();
    }

    // system instrument -  won't accept audio
    return 0;
}
static OSStatus inputRenderCallback(void* inRefCon,
                                    AudioUnitRenderActionFlags *ioActionFlags,
                                    const AudioTimeStamp *inTimeStamp,
                                    UInt32 inBusNumber,
                                    UInt32 inNumberFrames,
                                    AudioBufferList *ioData)
{
    OSStatus result = noErr;
    
    AudioDevice* thisDevice = (AudioDevice*)inRefCon;
    
    SInt16* left = (SInt16*) ioData->mBuffers[0].mData;
    SInt16* right = (SInt16*) ioData->mBuffers[1].mData;
    
    thisDevice->getLambda()(thisDevice->buffer, thisDevice->buffer, inNumberFrames);
    
    floatToInt16(thisDevice->buffer[0], left, inNumberFrames);
    floatToInt16(thisDevice->buffer[1], right, inNumberFrames);
    
    return result;
}
Exemple #14
0
static void soundcard(unsigned index)
{
	AudioDevice *soundcard = Audio::getDevice(index);
	Audio::Info *info;

	if(!Audio::hasDevice(index) && !soundcard)
		cout << "Sound device inaccessible or unsupported" << endl;
	else if(!soundcard)
		cout << "Sound device unavailable" << endl;
	else {
		info = soundcard->getInfo();
		cout << "Soundcard Driver: " << info->annotation << endl;
		if(Audio::isStereo(info->encoding))
			cout << "Default Channels: 2" << endl;
		else
			cout << "Default Channels: 1" << endl;
		cout << "Default Encoding: " << Audio::getName(info->encoding) << endl;
		cout << "Default Buffers: " << info->framecount << endl;
		cout << "Default Framing: " << info->framing << "ms" << endl;
		cout << "Default Rate: " << info->rate << " samples per second" << endl;
	}
	exit(0);
}
Exemple #15
0
OSStatus CAPlayThrough::SetOutputDeviceAsCurrent(AudioDeviceID out)
{
    UInt32 size = sizeof(AudioDeviceID);;
    OSStatus err = noErr;
	
	if(out == kAudioDeviceUnknown) //Retrieve the default output device
	{
		err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
									   &size,  
									   &out);
	}
	mOutputDevice.Init(out, false);
	checkErr(err);
	
	//Set the Current Device to the Default Output Unit.
    err = AudioUnitSetProperty(mOutputUnit,
							  kAudioOutputUnitProperty_CurrentDevice, 
							  kAudioUnitScope_Global, 
							  0, 
							  &mOutputDevice.mID, 
							  sizeof(mOutputDevice.mID));
							
	return err;
}
Exemple #16
0
int main()
{
	AudioDevice *device = new AudioDevice();

	ISound *wave1 = device->CreateSound();
	ISound *wave2 = device->CreateSound();
	ISound *wave3 = device->CreateSound();

	if (!wave1->LoadFromFile("wave1.wav"))
	{
		printf("Failed to load sound file!");
	}
	if (!wave2->LoadFromFile("wave2.wav"))
	{
		printf("Failed to load sound file!");
	}
	if (!wave3->LoadFromFile("wave3.wav"))
	{
		printf("Failed to load sound file!");
	}


	IListener *listener = device->GetListener();
	wave1->SetLooping(true);
	wave1->SetLocation(-1.0, 1.0, 1);
	wave1->Play();

	wave2->SetLooping(true);
	wave2->SetLocation(0, 1, 1);
	wave2->Play();

	wave3->SetLooping(true);
	wave3->SetLocation(-1, 0, 1);
	wave3->Play();

	float x = 0;
	float y = 0;
	while (true)
	{
		char c = getchar();
		if (c == 'w')
		{
			y += 0.1f;
			printf("%f, %f\n", x, y);
		}
		if (c == 's')
		{
			y -= 0.1f;
			printf("%f, %f\n", x, y);

		}
		if (c == 'a')
		{
			x += 0.1f;
			printf("%f, %f\n", x, y);
		}

		if (c == 'd')
		{
			x -= 0.1f;
			printf("%f, %f\n", x, y);
		}

		listener->SetLocation(x, y, 1);
		device->IsError();
	}
}
Exemple #17
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);
}
Exemple #18
0
bool LinuxSound::setWaveOutDevice(const AudioDevice & device) {
	_alsaDevice = String(device.getData()[1]);
	return true;
}
bool AudioDeviceManager::setDefaultInputDevice(const AudioDevice & audioDevice) {
	RecursiveMutex::ScopedLock scopedLock(_mutex);

	return setDefaultDeviceToRegistry(audioDevice.getName(), RECORD_DEVICE_REGISTRY_KEY);
}