Exemple #1
0
void
MixerCore::ApplyOutputFormat()
{
	ASSERT_LOCKED();

	media_multi_audio_format format = fOutput->MediaOutput().format.u.raw_audio;

	if (fMixBuffer != NULL)
		rtm_free(fMixBuffer);

	delete fMixBufferChannelTypes;

	fMixBufferFrameRate = (int32)(0.5 + format.frame_rate);
	fMixBufferFrameCount = frames_per_buffer(format);
	if (fDoubleRateMixing) {
		fMixBufferFrameRate *= 2;
		fMixBufferFrameCount *= 2;
	}
	fMixBufferChannelCount = format.channel_count;
	ASSERT(fMixBufferChannelCount == fOutput->GetOutputChannelCount());
	fMixBufferChannelTypes = new int32 [format.channel_count];

	for (int i = 0; i < fMixBufferChannelCount; i++) {
		 fMixBufferChannelTypes[i]
		 	= ChannelMaskToChannelType(GetChannelMask(i, format.channel_mask));
	}

	fMixBuffer = (float *)rtm_alloc(NULL, sizeof(float) * fMixBufferFrameCount * fMixBufferChannelCount);
	ASSERT(fMixBuffer);

	if (fResampler) {
		for (int i = 0; i < fMixBufferChannelCount; i++)
			delete fResampler[i];
		delete [] fResampler;
	}

	fResampler = new Resampler * [fMixBufferChannelCount];
	for (int i = 0; i < fMixBufferChannelCount; i++) {
		fResampler[i] = new Resampler(media_raw_audio_format::B_AUDIO_FLOAT,
			format.format);
	}

	TRACE("MixerCore::OutputFormatChanged:\n");
	TRACE("  fMixBufferFrameRate %ld\n", fMixBufferFrameRate);
	TRACE("  fMixBufferFrameCount %ld\n", fMixBufferFrameCount);
	TRACE("  fMixBufferChannelCount %ld\n", fMixBufferChannelCount);
	for (int i = 0; i < fMixBufferChannelCount; i++)
		TRACE("  fMixBufferChannelTypes[%i] %ld\n", i, fMixBufferChannelTypes[i]);

	MixerInput *input;
	for (int i = 0; (input = Input(i)); i++)
		input->SetMixBufferFormat(fMixBufferFrameRate, fMixBufferFrameCount);
}
void
MixerInput::_UpdateInputChannelDestinations()
{
	int channel_count;
	uint32 all_bits;
	uint32 mask;

	TRACE("_UpdateInputChannelDestinations: enter\n");
	for (int i = 0; i < fInputChannelCount; i++) {
		TRACE("_UpdateInputChannelDestinations: input channel %d, "
			"destination_mask 0x%08lX, base %p, gain %.3f\n", i,
			fInputChannelInfo[i].destination_mask,
			fInputChannelInfo[i].buffer_base, fInputChannelInfo[i].gain);
	}

	all_bits = 0;
	for (int i = 0; i < fInputChannelCount; i++)
		all_bits |= fInputChannelInfo[i].destination_mask;

	TRACE("_UpdateInputChannelDestinations: all_bits = %08lx\n", all_bits);

	channel_count = count_nonzero_bits(all_bits);
	TRACE("_UpdateInputChannelDestinations: %d input channels, %d mixer "
		"channels (%d old)\n", fInputChannelCount, channel_count,
		fMixerChannelCount);
	if (channel_count != fMixerChannelCount) {
		delete [] fMixerChannelInfo;
		fMixerChannelInfo = new mixer_chan_info[channel_count];
		fMixerChannelCount = channel_count;
	}

	// assign each mixer channel one type
	// and the gain from the fChannelTypeGain[]
	mask = 1;
	for (int i = 0; i < fMixerChannelCount; i++) {
		while (mask != 0 && (all_bits & mask) == 0)
			mask <<= 1;
		fMixerChannelInfo[i].destination_type = ChannelMaskToChannelType(mask);
		fMixerChannelInfo[i].destination_gain
			= fChannelTypeGain[fMixerChannelInfo[i].destination_type];
		mask <<= 1;
	}

	// assign buffer_base pointer for each mixer channel
	for (int i = 0; i < fMixerChannelCount; i++) {
		int j;
		for (j = 0; j < fInputChannelCount; j++) {
			if (fInputChannelInfo[j].destination_mask
					& ChannelTypeToChannelMask(
						fMixerChannelInfo[i].destination_type)) {
				fMixerChannelInfo[i].buffer_base = fMixBuffer ? &fMixBuffer[j]
					: 0;
				break;
			}
		}
		if (j == fInputChannelCount) {
			ERROR("buffer assignment failed for mixer chan %d\n", i);
			fMixerChannelInfo[i].buffer_base = fMixBuffer;
		}
	}

	for (int i = 0; i < fMixerChannelCount; i++) {
		TRACE("_UpdateInputChannelDestinations: mixer channel %d, type %2d, "
			"base %p, gain %.3f\n", i, fMixerChannelInfo[i].destination_type,
			fMixerChannelInfo[i].buffer_base,
			fMixerChannelInfo[i].destination_gain);
	}

	TRACE("_UpdateInputChannelDestinations: leave\n");
}