예제 #1
0
void DRV_AviSoundUpdate(void* soundData, int soundLen)
{
	if(!AVI_IsRecording() || !avi_file->sound_added)
		return;

	const int audioSegmentSize = avi_audiosegment_size(avi_file);
	const int samplesPerSegment = audioSegmentSize / avi_file->wave_format.nBlockAlign;
	const int soundSize = soundLen * avi_file->wave_format.nBlockAlign;
	int nBytes = soundSize;
	while (avi_file->audio_buffer_pos + nBytes > audioSegmentSize) {
		const int bytesToTransfer = audioSegmentSize - avi_file->audio_buffer_pos;
		memcpy(&avi_file->audio_buffer[avi_file->audio_buffer_pos], &((u8*)soundData)[soundSize - nBytes], bytesToTransfer);
		nBytes -= bytesToTransfer;

		if(FAILED(AVIStreamWrite(avi_file->compressed_streams[AUDIO_STREAM],
		                         avi_file->sound_samples, samplesPerSegment,
		                         avi_file->audio_buffer, audioSegmentSize, 0, NULL, &avi_file->ByteBuffer)))
		{
			avi_file->valid = 0;
			return;
		}
		avi_file->sound_samples += samplesPerSegment;
		avi_file->tBytes += avi_file->ByteBuffer;
		avi_file->audio_buffer_pos = 0;
	}
	memcpy(&avi_file->audio_buffer[avi_file->audio_buffer_pos], &((u8*)soundData)[soundSize - nBytes], nBytes);
	avi_file->audio_buffer_pos += nBytes;
}
예제 #2
0
void AVIAddSoundSamples(void* sound_data, const int num_samples, struct AVIFile* avi_out)
{
	if(!avi_out->valid ||
		!avi_out->sound_added)
	{
		return;
	}

	const int audioSegmentSize = avi_audiosegment_size(avi_out);
	const int samplesPerSegment = audioSegmentSize / avi_out->wave_format.nBlockAlign;
	const int soundSize = num_samples * avi_out->wave_format.nBlockAlign;
	int nBytes = soundSize;
	while (avi_out->audio_buffer_pos + nBytes > audioSegmentSize) {
		const int bytesToTransfer = audioSegmentSize - avi_out->audio_buffer_pos;
		memcpy(&avi_out->audio_buffer[avi_out->audio_buffer_pos], &((BYTE*)sound_data)[soundSize - nBytes], bytesToTransfer);
		nBytes -= bytesToTransfer;

		if(FAILED(AVIStreamWrite(avi_out->compressed_streams[AUDIO_STREAM],
		                         avi_out->sound_samples, samplesPerSegment,
		                         avi_out->audio_buffer, audioSegmentSize, 0, NULL, &avi_out->ByteBuffer)))
		{
			avi_out->valid = false;
			return;
		}
		avi_out->sound_samples += samplesPerSegment;
		avi_out->tBytes += avi_out->ByteBuffer;
		avi_out->audio_buffer_pos = 0;
	}
	memcpy(&avi_out->audio_buffer[avi_out->audio_buffer_pos], &((BYTE*)sound_data)[soundSize - nBytes], nBytes);
	avi_out->audio_buffer_pos += nBytes;
}