本文整理汇总了C++中snd_ctl_open函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_ctl_open函数的具体用法?C++ snd_ctl_open怎么用?C++ snd_ctl_open使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_ctl_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PORT_GetPortMixerCount
INT32 PORT_GetPortMixerCount() {
INT32 mixerCount;
int card;
char devname[16];
int err;
snd_ctl_t *handle;
snd_ctl_card_info_t* info;
TRACE0("> PORT_GetPortMixerCount\n");
initAlsaSupport();
snd_ctl_card_info_malloc(&info);
card = -1;
mixerCount = 0;
if (snd_card_next(&card) >= 0) {
while (card >= 0) {
sprintf(devname, ALSA_HARDWARE_CARD, card);
TRACE1("PORT_GetPortMixerCount: Opening alsa device \"%s\"...\n", devname);
err = snd_ctl_open(&handle, devname, 0);
if (err < 0) {
ERROR2("ERROR: snd_ctl_open, card=%d: %s\n", card, snd_strerror(err));
} else {
mixerCount++;
snd_ctl_close(handle);
}
if (snd_card_next(&card) < 0) {
break;
}
}
}
snd_ctl_card_info_free(info);
TRACE0("< PORT_GetPortMixerCount\n");
return mixerCount;
}
示例2: PORT_GetPortMixerDescription
INT32 PORT_GetPortMixerDescription(INT32 mixerIndex, PortMixerDescription* description) {
snd_ctl_t* handle;
snd_ctl_card_info_t* card_info;
char devname[16];
int err;
char buffer[100];
TRACE0("> PORT_GetPortMixerDescription\n");
snd_ctl_card_info_malloc(&card_info);
sprintf(devname, ALSA_HARDWARE_CARD, (int) mixerIndex);
TRACE1("Opening alsa device \"%s\"...\n", devname);
err = snd_ctl_open(&handle, devname, 0);
if (err < 0) {
ERROR2("ERROR: snd_ctl_open, card=%d: %s\n", (int) mixerIndex, snd_strerror(err));
return FALSE;
}
err = snd_ctl_card_info(handle, card_info);
if (err < 0) {
ERROR2("ERROR: snd_ctl_card_info, card=%d: %s\n", (int) mixerIndex, snd_strerror(err));
}
strncpy(description->name, snd_ctl_card_info_get_id(card_info), PORT_STRING_LENGTH - 1);
sprintf(buffer, " [%s]", devname);
strncat(description->name, buffer, PORT_STRING_LENGTH - 1 - strlen(description->name));
strncpy(description->vendor, "ALSA (http://www.alsa-project.org)", PORT_STRING_LENGTH - 1);
strncpy(description->description, snd_ctl_card_info_get_name(card_info), PORT_STRING_LENGTH - 1);
strncat(description->description, ", ", PORT_STRING_LENGTH - 1 - strlen(description->description));
strncat(description->description, snd_ctl_card_info_get_mixername(card_info), PORT_STRING_LENGTH - 1 - strlen(description->description));
getALSAVersion(description->version, PORT_STRING_LENGTH - 1);
snd_ctl_close(handle);
snd_ctl_card_info_free(card_info);
TRACE0("< PORT_GetPortMixerDescription\n");
return TRUE;
}
示例3: ALSA_AddUserSpecifiedDevice
/*----------------------------------------------------------------------------
** ALSA_AddUserSpecifiedDevice
** Add a device given from the registry
*/
static int ALSA_AddUserSpecifiedDevice(const char *ctlname, const char *pcmname)
{
int rc;
int okay = 0;
snd_ctl_t *ctl = NULL;
snd_pcm_t *pcm = NULL;
if (ctlname)
{
rc = snd_ctl_open(&ctl, ctlname, SND_CTL_NONBLOCK);
if (rc < 0)
ctl = NULL;
}
rc = snd_pcm_open(&pcm, pcmname, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
if (rc >= 0)
{
ALSA_AddPlaybackDevice(ctl, pcm, pcmname, FALSE);
okay++;
snd_pcm_close(pcm);
}
rc = snd_pcm_open(&pcm, pcmname, SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
if (rc >= 0)
{
ALSA_AddCaptureDevice(ctl, pcm, pcmname, FALSE);
okay++;
snd_pcm_close(pcm);
}
if (ctl)
snd_ctl_close(ctl);
return (okay == 0);
}
示例4: while
std::vector<String> AudioOutputDeviceAlsa::ParameterCard::PossibilitiesAsString(std::map<String,String> Parameters) {
int err;
std::vector<String> CardNames;
// iterate through all cards
int card_index = -1;
while (snd_card_next(&card_index) >= 0 && card_index >= 0) {
String hw_name = "hw:" + ToString(card_index);
snd_ctl_t* hCardCtrl;
if ((err = snd_ctl_open(&hCardCtrl, hw_name.c_str(), 0)) < 0) {
std::cerr << "AudioOutputDeviceAlsa: Cannot open sound control for card " << card_index << " - " << snd_strerror(err) << std::endl;
continue;
}
// iterate through all devices of that card
int device_index = -1;
while (!snd_ctl_pcm_next_device(hCardCtrl, &device_index) && device_index >= 0) {
String name = ToString(card_index) + "," + ToString(device_index);
//dmsg(1,("[possibility:%s]", name.c_str()));
CardNames.push_back(name);
}
snd_ctl_close(hCardCtrl);
}
return CardNames;
}
示例5: search_device
static const char* search_device(void)
{
int card, err;
snd_hwdep_info_t* info;
snd_hwdep_info_alloca(&info);
card = -1;
while (snd_card_next(&card) >= 0 && card >= 0) {
char ctl_name[20];
snd_ctl_t* ctl;
int device;
sprintf(ctl_name, "hw:CARD=%d", card);
err = snd_ctl_open(&ctl, ctl_name, SND_CTL_NONBLOCK);
if (err < 0)
continue;
device = -1;
while (snd_ctl_hwdep_next_device(ctl, &device) >= 0 && device >= 0) {
snd_hwdep_info_set_device(info, device);
err = snd_ctl_hwdep_info(ctl, info);
if (err >= 0 && snd_hwdep_info_get_iface(info) == SND_HWDEP_IFACE_SB_RC) {
static char name[36];
sprintf(name, "hw:CARD=%d,DEV=%d", card, device);
snd_ctl_close(ctl);
return name;
}
}
snd_ctl_close(ctl);
}
return NULL;
}
示例6: scan_cycle
void scan_cycle(alsa_rawmidi_t *midi)
{
int card = -1, err;
scan_t scan;
midi_port_t **ports;
//debug_log("scan: cleanup");
scan_cleanup(midi);
scan.midi = midi;
scan.iterator = &midi->scan.ports;
snd_rawmidi_info_alloca(&scan.info);
//debug_log("scan: rescan");
while ((err = snd_card_next(&card))>=0 && card>=0) {
char name[32];
snprintf(name, sizeof(name), "hw:%d", card);
if ((err = snd_ctl_open(&scan.ctl, name, SND_CTL_NONBLOCK))>=0) {
scan_card(&scan);
snd_ctl_close(scan.ctl);
} else
alsa_error("scan: snd_ctl_open", err);
}
// delayed open to workaround alsa<1.0.14 bug (can't open more than 1 subdevice if ctl is opened).
ports = &midi->scan.ports;
while (*ports) {
midi_port_t *port = *ports;
if (port->state == PORT_CREATED)
ports = scan_port_open(midi, ports);
else
ports = &port->next;
}
}
示例7: open_ctl
static int open_ctl(snd_use_case_mgr_t *uc_mgr,
snd_ctl_t **ctl,
const char *ctl_dev)
{
int err;
/* FIXME: add a list of ctl devices to uc_mgr structure and
cache accesses for multiple opened ctl devices */
if (uc_mgr->ctl_dev != NULL && strcmp(ctl_dev, uc_mgr->ctl_dev) == 0) {
*ctl = uc_mgr->ctl;
return 0;
}
if (uc_mgr->ctl_dev) {
free(uc_mgr->ctl_dev);
uc_mgr->ctl_dev = NULL;
snd_ctl_close(uc_mgr->ctl);
uc_mgr->ctl = NULL;
}
err = snd_ctl_open(ctl, ctl_dev, 0);
if (err < 0)
return err;
uc_mgr->ctl_dev = strdup(ctl_dev);
if (uc_mgr->ctl_dev == NULL) {
snd_ctl_close(*ctl);
return -ENOMEM;
}
uc_mgr->ctl = *ctl;
return 0;
}
示例8: cards
static int cards(lua_State *lstate) {
snd_ctl_t *handle;
int ret, card, ord;
char buf[32];
snd_ctl_card_info_t *info;
snd_ctl_card_info_alloca(&info);
ord = 1;
card = -1;
lua_newtable(lstate);
while (1) {
if ((snd_card_next(&card) < 0) || (card < 0)) break;
sprintf(buf, "hw:%d", card);
if ((ret = snd_ctl_open(&handle, buf, 0)) < 0) {
logmsg("control open: %s\n", snd_strerror(ret));
continue;
}
if ((ret = snd_ctl_card_info(handle, info)) < 0) {
logmsg("control info: %s\n", snd_strerror(ret));
continue;
}
lua_pushinteger(lstate, ord++);
lua_newtable(lstate);
set_string(lstate, "dev", buf);
set_string(lstate, "name",
snd_ctl_card_info_get_name(info));
lua_settable(lstate, -3);
snd_ctl_close(handle);
//view_card(buf);
}
return 1;
}
示例9: get_cards
/**
* Partly based on get_cards function in alsamixer.
* This gets all alsa cards and fills the global
* GSList 'cards'.
* The list always starts with the 'default' card.
*/
static void
get_cards(void)
{
int err, num;
snd_ctl_card_info_t *info;
snd_ctl_t *ctl;
char buf[10];
struct acard *cur_card, *default_card;
if (cards != NULL)
g_slist_free_full(cards, card_free);
cards = NULL;
default_card = g_malloc(sizeof(struct acard));
default_card->name = g_strdup("(default)");
default_card->dev = g_strdup("default");
default_card->channels = get_channels("default");
cards = g_slist_append(cards, default_card);
// don't need to free this as it's alloca'd
snd_ctl_card_info_alloca(&info);
num = -1;
for (;;) {
err = snd_card_next(&num);
if (err < 0) {
report_error("Can't get sounds cards: %s", snd_strerror(err));
return;
}
if (num < 0)
break;
sprintf(buf, "hw:%d", num);
if (snd_ctl_open(&ctl, buf, 0) < 0)
continue;
err = snd_ctl_card_info(ctl, info);
snd_ctl_close(ctl);
if (err < 0)
continue;
cur_card = g_malloc(sizeof(struct acard));
cur_card->name = g_strdup(snd_ctl_card_info_get_name(info));
sprintf(buf, "hw:%d", num);
cur_card->dev = g_strdup(buf);
cur_card->channels = get_channels(buf);
cards = g_slist_append(cards, cur_card);
}
#ifdef DEBUG
GSList *tmp = cards;
if (tmp) {
printf("------ Card list ------\n");
while (tmp) {
struct acard *c = tmp->data;
printf("\t%s\t%s\t%s\n", c->dev, c->name,
c->channels ? "" : "No chann");
tmp = tmp->next;
}
printf("-----------------------\n");
}
#endif
}
示例10: audio_set_default_levels
void audio_set_default_levels() {
int err;
snd_ctl_t *ctl;
snd_ctl_elem_value_t *val;
snd_ctl_elem_value_alloca(&val);
if (snd_ctl_open(&ctl, ALSA_DEVICE, 0)) {
fprintf(stderr, "can't open audio device");
return;
}
/* unmute microphone */
snd_ctl_elem_value_set_interface(val, SND_CTL_ELEM_IFACE_MIXER);
snd_ctl_elem_value_set_name(val, "Mic Capture Switch");
snd_ctl_elem_value_set_integer(val, 0, 1);
err = snd_ctl_elem_write(ctl, val);
if (err)
fprintf(stderr, "can't unmute microphone: %s\n", snd_strerror(err));
/* unmute speaker */
snd_ctl_elem_value_clear(val);
snd_ctl_elem_value_set_interface(val, SND_CTL_ELEM_IFACE_MIXER);
snd_ctl_elem_value_set_name(val, "Speaker Playback Switch");
snd_ctl_elem_value_set_integer(val, 0, 1);
err = snd_ctl_elem_write(ctl, val);
if (err)
fprintf(stderr, "can't unmute speaker: %s\n", snd_strerror(err));
/* set mic volume */
snd_ctl_elem_value_clear(val);
snd_ctl_elem_value_set_interface(val, SND_CTL_ELEM_IFACE_MIXER);
snd_ctl_elem_value_set_name(val, "Mic Capture Volume");
snd_ctl_elem_value_set_integer(val, 0, DEFAULT_MIC_VOL);
err = snd_ctl_elem_write(ctl, val);
if (err)
fprintf(stderr, "can't set microphone volume: %s\n", snd_strerror(err));
/* set speaker volume */
snd_ctl_elem_value_clear(val);
snd_ctl_elem_value_set_interface(val, SND_CTL_ELEM_IFACE_MIXER);
snd_ctl_elem_value_set_name(val, "Speaker Playback Volume");
snd_ctl_elem_value_set_integer(val, 0, DEFAULT_SPKR_VOL);
snd_ctl_elem_value_set_integer(val, 1, DEFAULT_SPKR_VOL);
err = snd_ctl_elem_write(ctl, val);
if (err)
fprintf(stderr, "can't set speaker volume: %s\n", snd_strerror(err));
/* set capture source */
snd_ctl_elem_value_clear(val);
snd_ctl_elem_value_set_interface(val, SND_CTL_ELEM_IFACE_MIXER);
snd_ctl_elem_value_set_name(val, "PCM Capture Source");
snd_ctl_elem_value_set_integer(val, 0, 0);
err = snd_ctl_elem_write(ctl, val);
if (err)
fprintf(stderr, "can't set capture source: %s\n", snd_strerror(err));
snd_ctl_close(ctl);
}
示例11: main
int main(int argc, char **argv)
{
register int err;
int cardNum;
// Start with first card
cardNum = -1;
for (;;)
{
snd_ctl_t *cardHandle;
// Get next sound card's card number. When "cardNum" == -1, then ALSA
// fetches the first card
if ((err = snd_card_next(&cardNum)) < 0)
{
printf("Can't get the next card number: %s\n", snd_strerror(err));
break;
}
// No more cards? ALSA sets "cardNum" to -1 if so
if (cardNum < 0) break;
// Open this card's control interface. We specify only the card number -- not
// any device nor sub-device too
{
char str[64];
sprintf(str, "hw:%i", cardNum);
if ((err = snd_ctl_open(&cardHandle, str, 0)) < 0)
{
printf("Can't open card %i: %s\n", cardNum, snd_strerror(err));
continue;
}
}
{
snd_ctl_card_info_t *cardInfo;
// We need to get a snd_ctl_card_info_t. Just alloc it on the stack
snd_ctl_card_info_alloca(&cardInfo);
// Tell ALSA to fill in our snd_ctl_card_info_t with info about this card
if ((err = snd_ctl_card_info(cardHandle, cardInfo)) < 0)
printf("Can't get info for card %i: %s\n", cardNum, snd_strerror(err));
else
printf("Card %i = %s\n", cardNum, snd_ctl_card_info_get_name(cardInfo));
}
// Close the card's control interface after we're done with it
snd_ctl_close(cardHandle);
}
// ALSA allocates some mem to load its config file when we call some of the
// above functions. Now that we're done getting the info, let's tell ALSA
// to unload the info and free up that mem
snd_config_update_free_global();
}
示例12: snd_ctl_card_info_alloca
static char *ListAvailableDevices( demux_t *p_demux, bool b_probe )
{
snd_ctl_card_info_t *p_info = NULL;
snd_ctl_card_info_alloca( &p_info );
snd_pcm_info_t *p_pcminfo = NULL;
snd_pcm_info_alloca( &p_pcminfo );
if( !b_probe )
msg_Dbg( p_demux, "Available alsa capture devices:" );
int i_card = -1;
while( !snd_card_next( &i_card ) && i_card >= 0 )
{
char psz_devname[10];
snprintf( psz_devname, 10, "hw:%d", i_card );
snd_ctl_t *p_ctl = NULL;
if( snd_ctl_open( &p_ctl, psz_devname, 0 ) < 0 ) continue;
snd_ctl_card_info( p_ctl, p_info );
if( !b_probe )
msg_Dbg( p_demux, " %s (%s)",
snd_ctl_card_info_get_id( p_info ),
snd_ctl_card_info_get_name( p_info ) );
int i_dev = -1;
while( !snd_ctl_pcm_next_device( p_ctl, &i_dev ) && i_dev >= 0 )
{
snd_pcm_info_set_device( p_pcminfo, i_dev );
snd_pcm_info_set_subdevice( p_pcminfo, 0 );
snd_pcm_info_set_stream( p_pcminfo, SND_PCM_STREAM_CAPTURE );
if( snd_ctl_pcm_info( p_ctl, p_pcminfo ) < 0 ) continue;
if( !b_probe )
msg_Dbg( p_demux, " hw:%d,%d : %s (%s)", i_card, i_dev,
snd_pcm_info_get_id( p_pcminfo ),
snd_pcm_info_get_name( p_pcminfo ) );
else
{
char *psz_device;
if( asprintf( &psz_device, "hw:%d,%d", i_card, i_dev ) > 0 )
{
if( ProbeAudioDevAlsa( p_demux, psz_device ) )
{
snd_ctl_close( p_ctl );
return psz_device;
}
else
free( psz_device );
}
}
}
snd_ctl_close( p_ctl );
}
return NULL;
}
示例13: snd_ctl_card_info_alloca
bool MainWindowImpl::FindRadioshark(string& device)
{
int card = -1;
int dev = -1;
snd_ctl_t *handle = NULL;
snd_ctl_card_info_t *info = NULL;
snd_pcm_info_t *pcminfo = NULL;
snd_pcm_stream_t stream = SND_PCM_STREAM_CAPTURE;
char card_id[32];
char *name = NULL;
snd_ctl_card_info_alloca (&info);
snd_pcm_info_alloca (&pcminfo);
if (snd_card_next (&card) < 0 || card < 0)
{
return false;
}
while(card >= 0)
{
snprintf (card_id, 32, "hw:%d", card);
if (snd_ctl_open (&handle, card_id, 0) == 0)
{
snd_ctl_card_info (handle, info);
while (1)
{
snd_ctl_pcm_next_device (handle, &dev);
if (dev < 0){
break;
}
snd_pcm_info_set_device (pcminfo, dev);
snd_pcm_info_set_subdevice (pcminfo, 0);
snd_pcm_info_set_stream (pcminfo, stream);
if (snd_ctl_pcm_info (handle, pcminfo) >= 0)
{
snd_card_get_name (card, &name);
if(strncmp(name,"radioSHARK",32) == 0)
{void PokeScreensaver(void);
snd_ctl_close(handle);
free (name);
snprintf (card_id, 32, "hw:%d,%d", card,dev);
device = string(card_id);
return true;
}
free (name);
}
}
snd_ctl_close(handle);
}
snd_card_next (&card);
}
return false;//didn't find the proper Radioshark card.
}
示例14: deviceList
static void deviceList(int type, vector_DevMap *devmap)
{
snd_ctl_t* handle;
snd_pcm_info_t pcminfo;
int max_cards, card, err, dev;
DevMap entry;
char name[1024];
struct snd_ctl_hw_info info;
void* temp;
max_cards = snd_cards();
if(max_cards < 0)
return;
VECTOR_RESERVE(*devmap, max_cards+1);
VECTOR_RESIZE(*devmap, 0);
entry.name = strdup(qsaDevice);
entry.card = 0;
entry.dev = 0;
VECTOR_PUSH_BACK(*devmap, entry);
for(card = 0;card < max_cards;card++)
{
if((err=snd_ctl_open(&handle, card)) < 0)
continue;
if((err=snd_ctl_hw_info(handle, &info)) < 0)
{
snd_ctl_close(handle);
continue;
}
for(dev = 0;dev < (int)info.pcmdevs;dev++)
{
if((err=snd_ctl_pcm_info(handle, dev, &pcminfo)) < 0)
continue;
if((type==SND_PCM_CHANNEL_PLAYBACK && (pcminfo.flags&SND_PCM_INFO_PLAYBACK)) ||
(type==SND_PCM_CHANNEL_CAPTURE && (pcminfo.flags&SND_PCM_INFO_CAPTURE)))
{
snprintf(name, sizeof(name), "%s [%s] (hw:%d,%d)", info.name, pcminfo.name, card, dev);
entry.name = strdup(name);
entry.card = card;
entry.dev = dev;
VECTOR_PUSH_BACK(*devmap, entry);
TRACE("Got device \"%s\", card %d, dev %d\n", name, card, dev);
}
}
snd_ctl_close(handle);
}
}
示例15: snd_ctl_card_info_alloca
std::vector<HwIDPair>
AlsaLayer::getAudioDeviceIndexMap(bool getCapture) const
{
snd_ctl_t* handle;
snd_ctl_card_info_t *info;
snd_pcm_info_t* pcminfo;
snd_ctl_card_info_alloca(&info);
snd_pcm_info_alloca(&pcminfo);
int numCard = -1;
std::vector<HwIDPair> audioDevice;
if (snd_card_next(&numCard) < 0 || numCard < 0)
return audioDevice;
do {
std::stringstream ss;
ss << numCard;
std::string name = "hw:" + ss.str();
if (snd_ctl_open(&handle, name.c_str(), 0) == 0) {
if (snd_ctl_card_info(handle, info) == 0) {
snd_pcm_info_set_device(pcminfo, 0);
snd_pcm_info_set_stream(pcminfo, getCapture ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK);
int err;
if ((err = snd_ctl_pcm_info(handle, pcminfo)) < 0) {
WARN("Cannot get info for %s %s: %s", getCapture ?
"capture device" : "playback device", name.c_str(),
snd_strerror(err));
} else {
DEBUG("card %i : %s [%s]",
numCard,
snd_ctl_card_info_get_id(info),
snd_ctl_card_info_get_name(info));
std::string description = snd_ctl_card_info_get_name(info);
description.append(" - ");
description.append(snd_pcm_info_get_name(pcminfo));
// The number of the sound card is associated with a string description
audioDevice.push_back(HwIDPair(numCard, description));
}
}
snd_ctl_close(handle);
}
} while (snd_card_next(&numCard) >= 0 && numCard >= 0);
return audioDevice;
}