示例#1
0
文件: alsa.c 项目: aarizkuren/pnmixer
/**
 * 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
}
示例#2
0
static void
sig_complete_command_channels(GList **list, WINDOW_REC *window,
    const char *word, const char *args, int *want_space)
{
	XMPP_SERVER_REC *server;

	g_return_if_fail(list != NULL);
	g_return_if_fail(window != NULL);
	g_return_if_fail(word != NULL);
	server = XMPP_SERVER(window->active_server);
	if (server == NULL)
		return;
	*list = get_channels(server, word);
	if (*list != NULL)
		signal_stop();
}
static int decode_data(char *target, int max_size)
{
	int      bps, channels;
	uint32_t samples_unpacked = 0;

	channels = get_channels();
	bps = WavpackGetBytesPerSample(wpc);
	if (max_size >= 1024) {
		samples_unpacked = WavpackUnpackSamples(wpc, temp_buffer, 256 / channels);
		total_unpacked_samples += samples_unpacked;
		if (samples_unpacked)
            format_samples(bps, (uchar *)target, temp_buffer, samples_unpacked * channels);
	} else {
		printf("vorbis: Target buffer too small: %d < 1024\n", max_size);
	}
	return samples_unpacked * (WavpackGetBitsPerSample(wpc) / 4);
}
示例#4
0
::FLAC__StreamDecoderWriteStatus
OurDecoder::write_callback(const ::FLAC__Frame *frame, const FLAC__int32 * const buffer[])
{
	if(_buffers != NULL)
	{
		// for surround channels
		// Premiere uses Left, Right, Left Rear, Right Rear, Center, LFE
		// FLAC uses Left, Right, Center, LFE, Left Rear, Right Rear
		// http://xiph.org/flac/format.html#frame_header
		static const int swizzle[] = {0, 1, 4, 5, 2, 3};
		
		
		assert(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
		
		int buffer_offset = 0;
		
		if(_start_sample > frame->header.number.sample_number)
			buffer_offset = _start_sample - frame->header.number.sample_number;
		
		assert(buffer_offset == 0); // I think I would sometimes get a non-zero offset, but haven't seen it yet
		
		assert(_start_sample + buffer_offset + _pos == frame->header.number.sample_number);
		
		int samples = _buf_len - _pos;
		
		if(samples > frame->header.blocksize - buffer_offset)
			samples = frame->header.blocksize - buffer_offset;
		
		double divisor = (1L << (frame->header.bits_per_sample - 1));
		
		for(int i = 0; i < samples; i++)
		{
			for(int c=0; c < get_channels(); c++)
			{
				_buffers[swizzle[c]][_pos] = (double)buffer[c][i + buffer_offset] / divisor;
			}
			
			_pos++;
		}
	}
	
	return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
示例#5
0
static void
sig_complete_command_invite(GList **list, WINDOW_REC *window,
    const char *word, const char *args, int *want_space)
{
	XMPP_SERVER_REC *server;
	char **tmp;

	g_return_if_fail(list != NULL);
	g_return_if_fail(window != NULL);
	g_return_if_fail(word != NULL);
	server = XMPP_SERVER(window->active_server);
	if (server == NULL)
		return;
	/* complete channels */
	tmp = g_strsplit(args, " ", 2);
	if (tmp[0] != NULL && tmp[1] == NULL)
		*list = get_channels(server, word);
	g_strfreev(tmp);
	if (*list != NULL)
		signal_stop();
}
示例#6
0
OpenALBackend::OpenALBackend()
	: m_sampling_rate(get_sampling_rate())
	, m_sample_size(get_sample_size())
{
	ALCdevice* m_device = alcOpenDevice(nullptr);
	checkForAlcError("OpenALBackend->alcOpenDevice");

	ALCcontext* m_context = alcCreateContext(m_device, nullptr);
	checkForAlcError("OpenALBackend->alcCreateContext");

	alcMakeContextCurrent(m_context);
	checkForAlcError("OpenALBackend->alcMakeContextCurrent");

	if (get_channels() == 2)
	{
		m_format = (m_sample_size == 2) ? AL_FORMAT_STEREO16 : AL_FORMAT_STEREO_FLOAT32;
	}
	else
	{
		m_format = (m_sample_size == 2) ? AL_FORMAT_71CHN16 : AL_FORMAT_71CHN32;
	}
}
示例#7
0
void get_doubles_from_data(double * out, VALUE in){
  VALUE data;
  long size, channels, count;
  int i;

  check_type_cowboy_data(in);

  data = rb_iv_get(in, "@data");
  size = get_size(in);
  channels = get_channels(in);
  count = get_count_of_data(in);

  memset(out, 0, sizeof(double) * count);

  if (TYPE(data) == T_STRING){
    get_doubles_from_string_data(out, RSTRING_PTR(RSTRING(data)),
                                 count, size, channels);
  } else if (TYPE(data) == T_ARRAY) {
    get_doubles_from_array_data(out, data, count, channels);
  } else {
    rb_raise(rb_eException, "Something went awry");
  }
}
示例#8
0
	int Image::get_cols() const {		
		return get_width() * get_channels();
	}
示例#9
0
文件: flac.c 项目: diorcety/mazda3
int mc_flac_read_metadata(metadata_parser_arg *arg) {
	debug_printf("---->mc_flac_read_metadata %p\n", arg);

	int ret;

	metadata_audio_parse_data data;
	os_memset(&data, '\0', sizeof(metadata_audio_parse_data));

	mc_audio_info_artwork_init(&data.artwork);

	void *block;

	ret = file_blk_read(arg->file, NULL, 0, 0x8000, &block);
	if (ret != 0) {
		debug_printf("-----mc_flac_read_metadata error reading %p ret %d\n", arg, ret);
		goto mc_flac_read_metadata_end;
	}

	/* Check header */
	ret = os_memcmp(block, flac_header_magic, sizeof(flac_header_magic));
	block += sizeof(flac_header_magic);
	if (ret != 0) {
		debug_printf("-----mc_flac_read_metadata not flac %p ret %d\n", arg, ret);
		goto mc_flac_read_metadata_end;
	}

	data.status |= 0x80; // Ok mask

	uint8_t last = 0;
	uint8_t streaminfo = 0;
	uint8_t vorbis_comment = 0;
	do {
		flac_metadata_block_header *block_header = (flac_metadata_block_header *)(block);
		block += sizeof(flac_metadata_block_header);
		last = get_last(block_header->data);
		uint8_t type = get_type(block_header->data);
		uint32_t block_length = uint24touint32(be24toh(block_header->length));
		debug_printf("-----mc_flac_read_metadata last %d type %d length %d\n", last, type, block_length);

		if (type == FLAC_STREAMINFO_BLOCK) {
			flac_metadata_block_streaminfo *stream = (flac_metadata_block_streaminfo *)(block);
			debug_printf("-----mc_flac_read_metadata minimum_block_size %d maximum_block_size %d minimum_frame_size %d maximum_frame_size %d sample_rate %x channels %d bit_depth %d total_samples %llu\n",
				be16toh(stream->minimum_block_size), be16toh(stream->maximum_block_size), uint24touint32(be24toh(stream->minimum_frame_size)), uint24touint32(be24toh(stream->maximum_frame_size)),
				get_sample_rate(stream->data), get_channels(stream->data), get_bit_depth(stream->data), get_total_samples(stream->data)
			);
			data.bit_depth = get_bit_depth(stream->data) / 8;
			data.samplerate = get_sample_rate(stream->data);
			data.channels = get_channels(stream->data);
			data.bitrate = data.bit_depth * data.samplerate * data.channels;
			data.duration = __aeabi_uldivmod(get_total_samples(stream->data), data.samplerate);
			data.status |= 0x10; // Duration mask
			streaminfo = 1;
		} else if(type == FLAC_VORBIS_COMMENT) {
			void *comment_block = block;

			char *vendor;
			comment_block = get_vorbis_comment(comment_block, &vendor);
			debug_printf("-----mc_flac_read_metadata vendor %s\n", vendor);
			os_free(vendor);

			uint32_t list_size = *((uint32_t*) comment_block);
			comment_block += sizeof(uint32_t);
			debug_printf("-----mc_flac_read_metadata size %d\n", list_size);
			while(list_size > 0) {
				char *c;
				comment_block = get_vorbis_comment(comment_block, &c);
				debug_printf("-----mc_flac_read_metadata vendor %s\n", c);
				const char *value = get_vorbis_comment_value(c);
				flac_metadata_info *infos = flac_infos;
				while(value != NULL && infos != NULL && infos->metadata != NULL) {
					int r = j_strncasecmp(infos->metadata, c, os_strlen(infos->metadata));
					if (r == 0) {
						if(infos->fct(value, (void*)&data + infos->offset) == 0) {
							data.status |= infos->mask;
						}
					}
					infos++;
				}
				os_free(c);
				list_size--;
			}

			vorbis_comment = 1;
		}
		block += block_length;
	} while(!last && (!streaminfo || !vorbis_comment));

	ret = arg->fct(arg, &data);

mc_flac_read_metadata_end:

	mc_audio_info_clean(&data);

	debug_printf("<----mc_flac_read_metadata %p ret %d\n", arg, ret);
	return ret;
}
示例#10
0
/**
 * Return a `std::vector` of the channel numbers and names, sorted by number.
 */
Dvb::VirtualChannelList Dvb::VirtualChannels::get_channels_sorted_by_number() const {
	auto data = get_channels();
	std::sort(std::begin(data), std::end(data), [](VirtualChannelSpecification a, VirtualChannelSpecification b){ return a.first < b.first; });
	return data;
};
示例#11
0
 inline void UNSAFE_retrieve_channel(size_t channel_index, const ScalarType*& channel_ptr, size_t& size) const
 {
     LB_ASSERT(channel_index<get_channels(), "Tried to retrieve a non existing channel (index exceeding array dimensions).");
     channel_ptr = reinterpret_cast<const ScalarType*>(&(_payload[channel_index][0]));
     size = get_samples();
 }