Beispiel #1
0
void CPSampleManager::copy_to(CPSample_ID p_from,CPSample_ID &p_to) {
	
	ERR_FAIL_COND(!check( p_from ));

	
	if (p_to.is_null()) {
		
		p_to=create( is_16bits( p_from), is_stereo( p_from), get_size(p_from));
	} else {
		
		recreate( p_to, is_16bits( p_from), is_stereo( p_from), get_size(p_from));
		
	}
	
	int len=get_size( p_from );
	int ch=is_stereo( p_from ) ? 2 : 1;
	
	for (int c=0;c<ch;c++) {
		
		for (int i=0;i<len;i++) {
			
			int16_t s=get_data( p_from, i, c );
			set_data( p_to, i, s, c );
		}
	}
	
	set_loop_type( p_to, get_loop_type( p_from ) );
	set_loop_begin( p_to, get_loop_begin( p_from ) );
	set_loop_end( p_to, get_loop_end( p_from ) );
	set_c5_freq( p_to, get_c5_freq( p_from ) );
	
		
	
}
Beispiel #2
0
CPLoader::Error CPLoader_S3M::load_sample(CPSample *p_sample) {

	int type = file->get_byte();

	char filename[13];
	file->get_byte_array((uint8_t *)filename, 12);
	filename[12] = 0;

	uint32_t samplepos = (uint32_t)file->get_byte() << 16;
	samplepos |= file->get_word();
	samplepos *= 16;
	//		printf("sample at %i\n",samplepos);
	/**/
	int sample_size = file->get_dword();

	int loop_begin = file->get_dword();
	int loop_end = file->get_dword();

	int def_volume = file->get_byte();
	;
	int dsk = file->get_byte();
	int pack = file->get_byte();

	int flags = file->get_byte();
	int c2speed = file->get_dword();

	file->get_dword(); //useless crap
	file->get_dword();
	file->get_dword();

	char name[29];
	file->get_byte_array((uint8_t *)name, 28);
	name[28] = 0;

	p_sample->set_default_volume(def_volume);
	p_sample->set_name(name);

	char scrs[5];
	file->get_byte_array((uint8_t *)scrs, 4);
	scrs[4] = 0;

	bool data_is_16bits = flags & 4;
	bool data_is_stereo = flags & 2;

	if (type == 0) {
		//empty sample
		return FILE_OK;
	}

	if ((type != 1) || scrs[0] != 'S' || scrs[1] != 'C' || scrs[2] != 'R' || scrs[3] != 'S') {
		//			printf("type: %i, %c%c%c%c\n",type,scrs[0],scrs[1],scrs[2],scrs[3]);
		CP_PRINTERR("Not an S3M CPSample!");
		return FILE_CORRUPTED;
	}

	//p_sample->data.set_c5_freq(p_sample->c2spd<<1);

	file->seek(samplepos);

	int real_sample_size = sample_size << BITBOOL(data_is_16bits);
	real_sample_size <<= BITBOOL(data_is_stereo);

	CPSampleManager *sm = CPSampleManager::get_singleton();

	CPSample_ID id = sm->create(data_is_16bits, data_is_stereo, sample_size);

	if (id.is_null())
		return FILE_OUT_OF_MEMORY;

	sm->lock_data(id);
	void *dataptr = sm->get_data(id);

	int chans = (data_is_stereo ? 2 : 1);
	for (int c = 0; c < chans; c++) {
		for (int i = 0; i < sample_size; i++) {

			if (data_is_16bits) {

				uint16_t s = file->get_word();
				s -= 32768; //toggle sign

				int16_t *v = (int16_t *)&s;
				((int16_t *)dataptr)[i * chans + c] = *v;
			} else {

				int8_t *v;
				uint8_t s = file->get_byte();
				s -= 128; //toggle sign
				v = (int8_t *)&s;
				((int8_t *)dataptr)[i * chans + c] = *v;
			}
		}
	}

	sm->unlock_data(id);

	sm->set_loop_begin(id, loop_begin);
	sm->set_loop_end(id, loop_end);
	sm->set_loop_type(id, (flags & 1) ? CP_LOOP_FORWARD : CP_LOOP_NONE);
	sm->set_c5_freq(id, c2speed << 1);
	p_sample->set_sample_data(id);

	/* Scream tracker previous to 3.10 seems to be buggy, as in, wont save what is after the sample loop, including the loop end point. Because of this I must fix it by habd */
	if (flags & 1) {

		for (int c = 0; c < (data_is_stereo ? 2 : 1); c++) {
			sm->set_data(id, loop_end, sm->get_data(id, loop_begin, c), c);
		}
	}

	return FILE_OK;
}
CPSample_ID CPLoader_IT::load_sample_data(AuxSampleData& p_sample_data) {


	int aux_sample_properties = (p_sample_data.is16bit?IT_SAMPLE_16BITS:0)|(p_sample_data.compressed?IT_SAMPLE_COMPRESSED:0)|(p_sample_data.stereo?IT_SAMPLE_STEREO:0);

	file->seek(p_sample_data.fileofs);
	
	CPSampleManager *sm=CPSampleManager::get_singleton();

	CPSample_ID id;
	
	switch (aux_sample_properties) {

		case (0):  // 8 bits, mono
		case (IT_SAMPLE_16BITS):  // 16 bits mono
		case (IT_SAMPLE_STEREO):  // 8 bits stereo
		case (IT_SAMPLE_16BITS|IT_SAMPLE_STEREO): { // 16 bits mono

			id=sm->create(p_sample_data.is16bit,p_sample_data.stereo,p_sample_data.length); 
			if (id.is_null())
				break;

			sm->lock_data(id);

			int16_t *ptr16 = (int16_t*)sm->get_data(id);
			int8_t *ptr8=(int8_t*)ptr16;

			int chans=p_sample_data.stereo?2:1;

			if (p_sample_data.is16bit) {

				for (int c=0;c<chans;c++) {

					for (int i=0;i<p_sample_data.length;i++) {

						ptr16[i*chans+c]=file->get_word();
					}
				}
			} else {

				for (int c=0;c<chans;c++) {

					for (int i=0;i<p_sample_data.length;i++) {

						ptr8[i*chans+c]=file->get_byte();
					}
				}

			}

			sm->unlock_data(id);

		} break;
		case (IT_SAMPLE_COMPRESSED): { // 8 bits compressed


			id=sm->create(false,false,p_sample_data.length); 
			if (id.is_null())
				break;
			sm->lock_data(id);
			
			if ( load_sample_8bits_IT_compressed((void*)sm->get_data( id),p_sample_data.length) ) {

				sm->unlock_data(id);
				sm->destroy(id);
				
				break;
			}

			sm->unlock_data(id);


		} break;
		case (IT_SAMPLE_16BITS|IT_SAMPLE_COMPRESSED): { // 16 bits compressed


			id=sm->create(true,false,p_sample_data.length); 
			if (id.is_null())
				break;
			sm->lock_data(id);
			
			if ( load_sample_16bits_IT_compressed((void*)sm->get_data(id),p_sample_data.length) ) {

				sm->unlock_data(id);
				sm->destroy(id);
				break;
			}

			sm->unlock_data(id);

		} break;
		default: {
			
			// I dont know how to handle stereo compressed, does that exist?
		} break;

	}


	return id;
}