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;
}
Example #2
0
void print_card_list(void) {
    int status;
    int card = -1;  // use -1 to prime the pump of iterating through card list
    char* longname  = NULL;
    char* shortname = NULL;

    if ((status = snd_card_next(&card)) < 0) {
        error("cannot determine card number: %s", snd_strerror(status));
        return;
    }
    if (card < 0) {
        error("no sound cards found");
        return;
    }
    while (card >= 0) {
        printf("Card %d:", card);
        if ((status = snd_card_get_name(card, &shortname)) < 0) {
            error("cannot determine card shortname: %s", snd_strerror(status));
            break;
        }
        if ((status = snd_card_get_longname(card, &longname)) < 0) {
            error("cannot determine card longname: %s", snd_strerror(status));
            break;
        }
        printf("\tLONG NAME:  %s\n", longname);
        printf("\tSHORT NAME: %s\n", shortname);
        if ((status = snd_card_next(&card)) < 0) {
            error("cannot determine card number: %s", snd_strerror(status));
            break;
        }
    }
}
static
audio_device_name *
alsa_enumerate_capture_devices(void)
{
    int     rcard;

    // count cards
    size_t cnt = 0;
    rcard = -1;
    while (1) {
        int err = snd_card_next(&rcard);
        if (err != 0)
            break;
        if (rcard == -1)
            break;
        cnt ++;
    }

    if (cnt == 0)
        return NULL;

    audio_device_name *list = calloc(sizeof(audio_device_name), cnt + 1);
    if (!list)
        return NULL;

    // fill the list
    uintptr_t idx = 0;
    rcard = -1;
    while (1) {
        int err = snd_card_next(&rcard);
        if (err != 0)
            break;
        if (rcard == -1)
            break;

        char *name;
        if (snd_card_get_name(rcard, &name) == 0 && name != NULL) {
            list[idx].name = name;

            char *longname;
            if (snd_card_get_longname(rcard, &longname) == 0 && longname != NULL)
                list[idx].longname = longname;

            idx ++;
            if (idx >= cnt)
                break;
        }
    }

    // terminate list
    list[idx].name = NULL;
    list[idx].longname = NULL;

    return list;
}
Example #4
0
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.
}
Example #5
0
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;
}
Example #6
0
int main(int argc, char **argv)
{
   register int  err;
   int           cardNum, totalCards;

   // No cards found yet
   totalCards = 0;

   // Start with first card
   cardNum = -1;

   for (;;)
   {
      // 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;

      // Another card found, so bump the count
      ++totalCards;
   }

   printf("ALSA found %i cards\n", totalCards);

   // ALSA allocates some mem to load its config file when we call
   // snd_card_next. 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();
}
Example #7
0
/**
 * 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
}
Example #8
0
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;
    }
}
Example #9
0
static SCM alsa_cards(void) {
	// compile list of available cards
	int card;
	char buf[32];
	char *pt;
	SCM list, alist;
	snd_ctl_card_info_t *info;
	snd_ctl_card_info_alloca(&info);
	card = -1;
	list = SCM_EOL;
	while (1) {
		if ((snd_card_next(&card) < 0) || (card < 0)) break;
		sprintf(buf, "hw:%d", card);
		alist = SCM_EOL;
		alist = scm_assq_set_x(alist, SYM("dev"),
					scm_from_locale_string(buf));
		snd_card_get_name(card, &pt);
		alist = scm_assq_set_x(alist, SYM("name"),
					scm_take_locale_string(pt));
		list = scm_cons(alist, list);
		scm_remember_upto_here_1(alist);
		}
	scm_remember_upto_here_1(list);
	return list;
	}
Example #10
0
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;
	}
Example #11
0
void populateDeviceList() {
  int                  card;
  char                *cardname;
  int                  numcards, row;

  gdk_threads_enter();
  gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(gui.combo_card), "default");
  gdk_threads_leave();

  numcards = 0;
  card     = -1;
  row      = 0;
  do {
    snd_card_next(&card);
    if (card != -1) {
      row++;
      snd_card_get_name(card,&cardname);
      gdk_threads_enter();
      gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(gui.combo_card), cardname);
      char *dev = g_key_file_get_string(config,"slowrx","device",NULL);
      if (dev == NULL || strcmp(cardname, dev) == 0)
        gtk_combo_box_set_active(GTK_COMBO_BOX(gui.combo_card), row);

      gdk_threads_leave();
      numcards++;
    }
  } while (card != -1);

  if (numcards == 0) {
    perror("No sound devices found!\n");
    exit(EXIT_FAILURE);
  }
  
}
Example #12
0
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;
}
    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;
    }
Example #14
0
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();
}
Example #15
0
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;
}
static
char *
find_pcm_name(const char *device_longname)
{
    char *pcm_name = NULL;
    int   card = -1;
    int   done = 0;

    if (!device_longname)
        return strdup("default");

    while (!done) {
        int err = snd_card_next(&card);
        if (err != 0)
            break;
        if (card == -1)
            break;

        char *longname = NULL;
        if (snd_card_get_longname(card, &longname) != 0)
            goto next_0;

        if (!longname)
            goto next_0;

        if (strcmp(device_longname, longname) != 0)
            goto next_2;

        void **hints;
        if (snd_device_name_hint(card, "pcm", &hints) != 0)
            goto next_2;

        for (int k = 0; hints[k] != NULL; k ++) {
            pcm_name = snd_device_name_get_hint(hints[k], "NAME");
            if (strncmp(pcm_name, "default:", strlen("default:")) == 0) {
                done = 1;
                goto next_3;
            }
            free(pcm_name);
            pcm_name = NULL;
        }

    next_3:
        snd_device_name_free_hint(hints);
    next_2:
        free(longname);
    next_0:
        continue;
    }

    if (!pcm_name)
        pcm_name = strdup("default");

    return pcm_name;
}
Example #17
0
static void GetDevices( module_config_t *p_item )
{
    int i_card = -1;
    int i_err = 0;

    if( ( i_err = snd_card_next( &i_card ) ) != 0 )
    {
        /*printf( "snd_card_next() failed: %s", snd_strerror( -i_err ) );*/
        return;
    }

    while( i_card > -1 )
    {
        GetDevicesForCard( p_item, i_card );
        if( ( i_err = snd_card_next( &i_card ) ) != 0 )
        {
            /*printf( "snd_card_next() failed: %s", snd_strerror( -i_err ) );*/
            break;
        }
    }
}
Example #18
0
int AlsaWork::getTotalCards()
{
	int cards = 0;
	int index = -1;
	while (true) {
		checkError(snd_card_next(&index));
		if (index < 0) {
			break;
		}
		++cards;
	}
	return cards;
}
Example #19
0
/**
 * ags_devout_list_cards:
 * @soundcard: the #AgsSoundcard
 * @card_id: alsa identifier
 * @card_name: card name
 *
 * List available soundcards.
 *
 * Since: 0.4
 */
void
ags_devout_list_cards(AgsSoundcard *soundcard,
		      GList **card_id, GList **card_name)
{
  snd_ctl_t *card_handle;
  snd_ctl_card_info_t *card_info;
  char *name;
  gchar *str;
  int card_num;
  int error;

  *card_id = NULL;
  *card_name = NULL;
  card_num = -1;

  while(TRUE){
    error = snd_card_next(&card_num);

    if(card_num < 0){
      break;
    }

    if(error < 0){
      continue;
    }

    str = g_strdup_printf("hw:%i\0", card_num);
    error = snd_ctl_open(&card_handle, str, 0);

    if(error < 0){
      continue;
    }

    snd_ctl_card_info_alloca(&card_info);
    error = snd_ctl_card_info(card_handle, card_info);

    if(error < 0){
      continue;
    }

    *card_id = g_list_prepend(*card_id, str);
    *card_name = g_list_prepend(*card_name, g_strdup(snd_ctl_card_info_get_name(card_info)));

    snd_ctl_close(card_handle);
  }

  snd_config_update_free_global();

  *card_id = g_list_reverse(*card_id);
  *card_name = g_list_reverse(*card_name);
}
Example #20
0
void print_midi_ports(void) {
    int status;
    int card = -1;  // use -1 to prime the pump of iterating through card list

    if ((status = snd_card_next(&card)) < 0) {
        error("cannot determine card number: %s", snd_strerror(status));
        return;
    }
    if (card < 0) {
        error("no sound cards found");
        return;
    }
    printf("\nDir Device    Name\n");
    printf("====================================\n");
    while (card >= 0) {
        list_midi_devices_on_card(card);
        if ((status = snd_card_next(&card)) < 0) {
            error("cannot determine card number: %s", snd_strerror(status));
            break;
        }
    }
    printf("\n");
}
Example #21
0
void ALSAInit::initialize() {
	pairALSA = NULL;
	paorALSA = NULL;
	cards = NULL;

	int card = -1;
	snd_card_next(&card);
	if (card != -1) {
		pairALSA = new ALSAAudioInputRegistrar();
		paorALSA = new ALSAAudioOutputRegistrar();
		cards = new ALSAEnumerator();
	} else {
		qWarning("ALSAInit: No cards found, not initializing");
	}
}
Example #22
0
void lamixer_enum_cards()
{
	int card_index = -1;

	while(!snd_card_next(&card_index))
	{
		if(card_index > -1) {
			char* card_name;
			if(!snd_card_get_name(card_index, &card_name)) {
				SoundCards = g_list_append(SoundCards, card_name);
			}
		}
		else
			break;
	}
}
Example #23
0
UInt32 AudioComponentCount(AudioComponentDescription *inDesc)
{
	UInt32 count = 0;
	int index = -1;
	
	// Is there a better way?
	do
	{
		snd_card_next(&index);
		if (index != -1)
			count++;
	}
	while (index != -1);
	
	return count;
}
Example #24
0
AudioComponent AudioComponentFindNext(AudioComponent inAComponent, AudioComponentDescription *inDesc)
{
	TRACE2(inAComponent, inDesc);

	int index = -1;

	if (inDesc->componentType != kAudioUnitType_Output && inDesc->componentType != kAudioUnitType_Mixer)
		return nullptr;

	if (inAComponent != nullptr)
		index = GetComponentIndex(inAComponent);

	if (snd_card_next(&index) || index == -1)
		return nullptr;

	return CreateComponent(kComponentTypeAudioUnit, index);
}
Example #25
0
void
moko_alsa_volume_control_set_device_from_name (MokoAlsaVolumeControl *control,
					      const gchar *name)
{
	gint i = -1;
	
	if (!name) {
		moko_alsa_volume_control_set_device (control, NULL);
		return;
	}

	while (snd_card_next (&i) == 0) {
		void **hints;
		
		if (i == -1) break;
	
		if (snd_device_name_hint (i, "pcm", &hints) == 0) {
			gchar *separator;
			gchar *device = strdup (snd_device_name_get_hint (
				hints[0], "DESC"));
			
			if ((separator = strchr (device, ',')))
			  *separator = '\0';
			
			if (strcmp (device, name) == 0) {
				g_free (device);
				
				device = strdup (snd_device_name_get_hint (
					hints[0], "NAME"));
				snd_device_name_free_hint (hints);
				strchr (device, ':')[0] = '\0';
				
				moko_alsa_volume_control_set_device (
					control, device);
				return;
			}
			snd_device_name_free_hint (hints);
			g_free (device);
		}
	}
	
	g_debug ("Card '%s' not found", name);
}
Example #26
0
void list_cards(void)
{
    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);

    printf("Availible alsa capture devices:\n");

    int i_card = -1;
    while (!snd_card_next(&i_card) && i_card >= 0)
    {
        char devname[10];
        snprintf( devname, 10, "hw:%d", i_card );

        snd_ctl_t *p_ctl = NULL;
        if ( snd_ctl_open( &p_ctl, devname, 0 ) < 0) continue;

        snd_ctl_card_info( p_ctl, p_info);
        printf("\t%s (%s)\n", 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;

            printf("\t\thw:%d,%d : %s (%s)\n", i_card, i_dev, 
                    snd_pcm_info_get_id(p_pcminfo), 
                    snd_pcm_info_get_name(p_pcminfo));
        }

        snd_ctl_close(p_ctl);
    }

}
Example #27
0
static void
as_setup_card_combo (GtkWidget *combo , SoundParams *sparams)
{
   int card;
   int i ;
   int err;
   snd_ctl_t *handle;
   snd_ctl_card_info_t *info;
   char name[32];
   
   gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "- default");
   
   snd_ctl_card_info_alloca(&info);
   sparams->firstcard = -1;
   card = -1;
   for( i = 0 ;   ; i++ ){
      if (snd_card_next(&card) < 0 || card < 0) {
	 if ( i == 0 ) {
	    msg_error(_("no soundcards found..."));
	 }
	 return;
      }
      if ( sparams->firstcard < 0 ) {
	  sparams->firstcard = card;
      }
      sprintf(name, "hw:%d", card);
      if ((err = snd_ctl_open(&handle, name, 0)) < 0) {
	 msg_error(_("control open (%i): %s"), card, snd_strerror(err));
	 continue;
      }
      if ((err = snd_ctl_card_info(handle, info)) < 0) {
	 msg_error(_("control hardware info (%i): %s"), card, snd_strerror(err));
	 snd_ctl_close(handle);
	 continue;
      }
      sprintf(name, "%d %s", card,  snd_ctl_card_info_get_name(info) );
      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), name );
      snd_ctl_close(handle);
   }
}
Example #28
0
static int hdspm_mixer_find_cards(t_hdspm_mixer *x)
{
  int i;
  char *name;
  int card = HDSPMM_ERROR_NO_CARD;
  int n = 0;
  
  while (snd_card_next(&card) >= 0) // searching mixer for hdspm ...
  {
    if(card < 0)
    {
      break;
    }
    else
    {
      snd_card_get_name(card, &name);
      if(strncmp(name, "HDSPM MADI", 9) == 0)
      {
        snprintf(x->x_card_name[n], 6, "hw:%i", n); // printf("HDSP MADI as card %d (%s) found !\n", n, card_name[n]);
        n++;
	      if(n >= HDSPMM_MAX_CARDS)
	        break;
      } 
    }
  }
  
  if(!n)
    return HDSPMM_ERROR_NO_CARD;
  
  for(i = n; i < HDSPMM_MAX_CARDS; i++)
  {
    x->card_name[i][0] = '\0';
  }
  
  return n;
}
Example #29
0
MixerHandler alsaMixerAlloc() {
	int card = -1;
	int result = 0;
	MixerSystem* mixer = commonMixerAlloc();

	// setup functions
	mixer->mixerChangeVolume = alsaMixerChangeVolume;
	mixer->mixerSelectCard = alsaMixerSelectCard;
	mixer->mixerCardClose = alsaMixerCardClose;
	// setup card information
	while ( !result ) {
		result = snd_card_next( &card );
		if ( result || card == -1 ) {
			break;
		}
		struct AlsaMixerCard* mixerCard = createMixerCard( card );
		if ( mixerCard ) {
			mixer->mixerCard = goc_arrayAdd( mixer->mixerCard, mixerCard );
		}

	}

	return (MixerHandler)mixer;
}
void ProjectOptions::InitDevInfo()
{
	snd_config_update();

	int ctlNum = -1;
	SoundDevInfo *inf = waveList.AddItem();
	inf->name = "default";
	inf->id = -1;
	inf->sub = -1;
	inf->type = 0;
	inf->info = NULL;

	while (snd_card_next(&ctlNum) == 0 && ctlNum >= 0 )
	{
#if SND_LIB_VERSION >= 0x1000E
		void **hints = 0;
		void **hh;
		if (snd_device_name_hint(ctlNum, "pcm", &hints) == 0)
		{
			hh = hints;
			while (*hh)
			{
				char *name = snd_device_name_get_hint(*hh, "NAME");
				char *desc = snd_device_name_get_hint(*hh, "DESC");
				for (char *cp = desc; *cp; cp++)
				{
					if (*cp < 0x20)
						*cp = ' ';
				}
				SoundDevInfo *inf = waveList.AddItem();
				inf->id = ctlNum;
				inf->sub = 0;
				inf->type = 0;
				inf->name = desc;
				inf->info = name;
				if (desc)
					free(desc);
				hh++;
			}
			snd_device_name_free_hint(hints);
		}
		if (snd_device_name_hint(ctlNum, "rawmidi", &hints) == 0)
		{
			hh = hints;
			while (*hh)
			{
				char *name = snd_device_name_get_hint(*hh, "NAME");
				char *desc = snd_device_name_get_hint(*hh, "DESC");
				for (char *cp = desc; *cp; cp++)
				{
					if (*cp < 0x20)
						*cp = ' ';
				}
				SoundDevInfo *inf = midiList.AddItem();
				inf->id = ctlNum;
				inf->sub = 0;
				inf->type = 0;
				inf->name = desc;
				inf->info = name;
				if (desc)
					free(desc);
				hh++;
			}
			snd_device_name_free_hint(hints);
		}
#endif
		/*
        snd_ctl_card_info_t *devInfo;
        snd_pcm_t *pcmHandle;
        snd_pcm_info_t *pcmInfo;
        snd_rawmidi_t *midiHandle;
        snd_rawmidi_info_t *midiInfo;

        char hw[128];

        snprintf(hw, sizeof(hw), "hw:%d", ctlNum);

        int devNum;
        snd_ctl_t *ctl;
        if (snd_ctl_open(&ctl, hw, 0) >= 0)
        {
        	devNum = -1;
			while (snd_ctl_pcm_next_device(ctl, &devNum) == 0 && devNum >= 0)
			{

				snprintf(hw, sizeof(hw), "hw:%d,%d", ctlNum, devNum);
				if (snd_pcm_open(&pcmHandle, hw, SND_PCM_STREAM_PLAYBACK, 0) >= 0)
				{
					snd_pcm_info_malloc(&pcmInfo);
					snd_pcm_info(pcmHandle, pcmInfo);
					SoundDevInfo *inf = waveList.AddItem();
					inf->id = ctlNum;
					inf->sub = devNum;
					inf->type = 0;
					inf->info = (void*)pcmInfo;
					inf->name = snd_pcm_info_get_name(pcmInfo);
					//inf->name += " - ";
					//inf->name += snd_pcm_info_get_subdevice_name(pcmInfo);
					snd_pcm_close(pcmHandle);
					pcmHandle = 0;
				}
			}
			devNum = -1;
			while (snd_ctl_rawmidi_next_device(ctl, &devNum) == 0 && devNum >= 0)
			{
				snprintf(hw, sizeof(hw), "hw:%d,%d", ctlNum, devNum);
				if (snd_rawmidi_open(&midiHandle, NULL, hw, 0) >= 0)
				{
					snd_rawmidi_info_malloc(&midiInfo);
					snd_rawmidi_info(midiHandle, midiInfo);
					SoundDevInfo *inf = midiList.AddItem();
					inf->id = ctlNum;
					inf->sub = devNum;
					inf->type = 1;
					inf->info = (void*)midiInfo;
					inf->name = snd_rawmidi_info_get_name(midiInfo);
					//inf->name += " - ";
					//inf->name += snd_rawmidi_info_get_subdevice_name(midiInfo);
					snd_rawmidi_close(midiHandle);
				}
			}
//			SoundDevInfo *inf = waveList.AddItem();
//			snd_ctl_card_info_alloca(&devInfo);
//	        snd_ctl_card_info(ctl, devInfo);
//			inf->name = snd_ctl_card_info_get_name(devInfo);
//			inf->info = reinterpret_cast<void*>(devInfo);
//			inf->id = (long)devNum;
			snd_ctl_close(ctl);
		}*/
	}
	// TODO:
	//snd_lib_error_set_handler(alsa_error_handler);
}