コード例 #1
0
/*
 * Returns the appropriate cache pointer.
 */
static CgsCache *
myCache(XtermWidget xw, VTwin *cgsWin, CgsEnum cgsId)
{
    CgsCache *result = 0;

    if ((int) cgsId >= 0 && cgsId < gcMAX) {
#ifdef NO_ACTIVE_ICON
        (void) xw;
        (void) cgsWin;
#else
        if (cgsWin == &(TScreenOf(xw)->iconVwin))
            result = allocCache(&(TScreenOf(xw)->icon_cgs_cache));
        else
#endif
        result = allocCache(&(TScreenOf(xw)->main_cgs_cache));

        result += cgsId;
        if (result->data == 0) {
            result->data = result->list;
        }
    }

    return result;
}
コード例 #2
0
int DecodeOgg(FILE* stream, DecodedSound* Sound){
	
	// Passing filestream to libogg
	int eof=0;
	OggVorbis_File* vf = (OggVorbis_File*)malloc(sizeof(OggVorbis_File));
	static int current_section;
	fseek(stream, 0, SEEK_SET);
	if(ov_open(stream, vf, NULL, 0) != 0)
	{
		fclose(stream);
		Output::Warning("Corrupt ogg file");
		return -1;
	}
	
	// Grabbing info from the header
	vorbis_info* my_info = ov_info(vf,-1);
	Sound->samplerate = my_info->rate;
	Sound->format = CSND_ENCODING_PCM16;
	u16 audiotype = my_info->channels;
	Sound->audiobuf_size = ov_time_total(vf,-1) * (my_info->rate<<1);
	if (audiotype == 2) Sound->isStereo = true;
	else Sound->isStereo = false;
	Sound->bytepersample = audiotype<<1;
	
	// Preparing PCM16 audiobuffer
	#ifdef USE_CACHE
	allocCache(Sound);
	#else
	Sound->audiobuf = (u8*)linearAlloc(Sound->audiobuf_size);
	#endif
	
	if (Player::use_dsp) audiotype = 1; // We trick the decoder since DSP supports native stereo playback
	
	// Decoding Vorbis buffer
	int i = 0;
	if (audiotype == 1){ // Mono file
		while(!eof){
			long ret=ov_read(vf,(char*)&Sound->audiobuf[i],OGG_BUFSIZE,&current_section);
			if (ret == 0) eof=1;
			else i = i + ret;
		}
	}else{ // Stereo file
		char pcmout[OGG_BUFSIZE];
		int z = 0;
		u32 chn_size = Sound->audiobuf_size>>1;
		u8* left_channel = Sound->audiobuf;
		u8* right_channel = &Sound->audiobuf[chn_size];
		while(!eof){
			long ret=ov_read(vf,pcmout,OGG_BUFSIZE,&current_section);
			if (ret == 0) eof=1;
			else{
				for (u32 i=0;i<ret;i=i+4){
					memcpy(&left_channel[z],&pcmout[i],2);
					memcpy(&right_channel[z],&pcmout[i+2],2);
					z = z + 2;
				}
			}
		}
	}
	
	ov_clear(vf);
	#ifdef USE_CACHE
	return LAST_ENTRY;
	#else
	return 0;
	#endif
	
}
コード例 #3
0
int DecodeWav(FILE* stream, DecodedSound* Sound){
	
	// Grabbing info from the header
	u16 audiotype;
	u32 chunk;
	u32 jump;
	u16 bytepersample;
	fseek(stream, 16, SEEK_SET);
	fread(&jump, 4, 1, stream);
	fread(&Sound->format, 2, 1, stream);
	fread(&audiotype, 2, 1, stream);
	fread(&Sound->samplerate, 4, 1, stream);	
	if (audiotype == 2) Sound->isStereo = true;
	else Sound->isStereo = false;
	fseek(stream, 32, SEEK_SET);
	fread(&bytepersample, 2, 1, stream);
	Sound->bytepersample = bytepersample;
	fseek(stream, 20, SEEK_SET);
	
	// Check for file audiocodec
	if (Sound->format == 0x11) Sound->format = CSND_ENCODING_ADPCM;
	else if (bytepersample == 4 || (bytepersample == 2 && audiotype == 1)) Sound->format = CSND_ENCODING_PCM16;
	else Sound->format = CSND_ENCODING_PCM8;
	
	// Skipping to audiobuffer start
	while (chunk != 0x61746164){
		fseek(stream, jump, SEEK_CUR);
		fread(&chunk, 4, 1, stream);
		fread(&jump, 4, 1, stream);
	}
	
	// Getting audiobuffer size
	int start = ftell(stream);
	fseek(stream, 0, SEEK_END);
	int end = ftell(stream);
	Sound->audiobuf_size = end - start;
	fseek(stream, start, SEEK_SET);
	#ifdef USE_CACHE
	allocCache(Sound);
	#else
	Sound->audiobuf = (u8*)linearAlloc(Sound->audiobuf_size);
	#endif
	
	if (Player::use_dsp) audiotype = 1; // We trick the decoder since DSP supports native stereo playback
	
	// Mono file
	if (audiotype == 1) fread(Sound->audiobuf, Sound->audiobuf_size, 1, stream);	
	
	// Stereo file
	else{
		u32 chn_size = Sound->audiobuf_size>>1;
		u16 byteperchannel = bytepersample>>1;
		u8* tmp_buf = (u8*)linearAlloc(Sound->audiobuf_size);
		fread(tmp_buf, Sound->audiobuf_size, 1, stream);
		int z = 0;
		for (u32 i=0;i<chn_size;i=i+bytepersample){
			memcpy(&Sound->audiobuf[z], &tmp_buf[i], byteperchannel);
			memcpy(&Sound->audiobuf[z+chn_size], &tmp_buf[i+2], byteperchannel);
			z=z+2;
		}
		linearFree(tmp_buf);
	}
	
	fclose(stream);
	#ifdef USE_CACHE
	return LAST_ENTRY;
	#else
	return 0;
	#endif
}