本文整理汇总了C++中AudioDevice类的典型用法代码示例。如果您正苦于以下问题:C++ AudioDevice类的具体用法?C++ AudioDevice怎么用?C++ AudioDevice使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AudioDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: snprintf
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;
}
示例2: GetAudioDevice
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);
}
示例3: Device
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));
}
示例4: main
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;
}
示例5: deviceOut
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");
}
}
示例6: W32AudioDevice
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;
}
示例7: callbackByLambda
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;
}
示例8: sizeof
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;
}
示例9: sizeof
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;
}
示例10: deviceIn
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");
}
}
示例11:
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;
}
示例12: inputRenderCallback
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;
}
示例13: soundcard
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);
}
示例14: main
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();
}
}
示例15: play
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);
}