Пример #1
0
/*
 * real initialization.
 */
int callc fennec_plugin_initialize(void)
{
	unsigned long i;

	if(pstreams_count)return 0;

	if(REXLoadDLL() != kREXError_NoError)
	{
		pstreams_count = 0;
		plugin_busy = 0;
		plugin_error = 1;
		return 0;
	}

	plugin_busy = 1;

	pstreams_count = plugin_player_base;
	pstreams       = (struct plugin_stream*) sys_mem_alloc(pstreams_count * sizeof(struct plugin_stream));
	
	if(pstreams == v_error_sys_mem_alloc)
	{
		pstreams_count = 0;
		plugin_busy = 0;
		return 0;
	}

	for(i=0; i<pstreams_count; i++) /* free everything */
	{
		pstreams[i].initialized = 0;
	}

	plugin_busy = 0;
	return 1;
}
Пример #2
0
int callc encoder_fennec_plugin_initialize(void)
{
	unsigned long i;

	if(pestreams_count)return 0;

	encoder_plugin_busy = 1;

	pestreams_count = plugin_player_base;
	pestreams       = (struct plugin_encoder_stream*) sys_mem_alloc(pestreams_count * sizeof(struct plugin_encoder_stream));
	
	if(pestreams == v_error_sys_mem_alloc)
	{
		pestreams_count = 0;
		encoder_plugin_busy = 0;
		return 0;
	}

	for(i=0; i<pestreams_count; i++) /* free everything */
	{
		pestreams[i].initialized = 0;
	}

	encoder_plugin_busy = 0;
	return 1;
}
Пример #3
0
int callc fennec_plugin_initialize(void)
{
	unsigned long i;

	if(pstreams_count)return 0;

	plugin_busy = 1;

	pstreams_count = plugin_player_base;
	pstreams       = (struct plugin_stream*) sys_mem_alloc(pstreams_count * sizeof(struct plugin_stream));
	
	if(pstreams == v_error_sys_mem_alloc)
	{
		pstreams_count = 0;
		plugin_busy = 0;
		return 0;
	}

	for(i=0; i<pstreams_count; i++)
	{
		pstreams[i].initialized = 0;
	}

	plugin_busy = 0;
	return 1;
}
Пример #4
0
/*
 * bands[channels][bands]
 * preamps[channels]
 */
void* equalize_buffer_variable_init(void *eqp, int channels, int frequency)
{
	int                     cfs[] = {31, 63, 125, 250, 500, 1000, 2000, 4000, 8000, 16000};
	unsigned int            i, j;
	struct equalizer_state *eqs;
	equalizer_preset       *eqpp = (equalizer_preset*) eqp;

	eqs = (struct equalizer_state *) sys_mem_alloc(sizeof(struct equalizer_state));

	if(!eqs)return 0;
	
	memset(eqs, 0, sizeof(struct equalizer_state));

	eqs->frequency = frequency;
	eqs->nbands    = 10;
	
	for(i=0; i<(unsigned int)channels; i++)
		eqs->preamp[i] = (double)eqpp->preamp[i];

	for(i=0; i<eqs->nbands; i++)
	{
		eqs->b[i].center_frequency = cfs[i];
		eqs->b[i].Q                = 1.2;
	}	


	for(i=0; i<(unsigned int)channels; i++)
		for(j=0; j<eqs->nbands; j++)
		{
			eqs->b[j].c[i].boost = (double)eqpp->boost[i][j];
			equalizer_calculate(j, i, 1, eqs);
		}

	return eqs;
}
Пример #5
0
void AddSong(struct SongDef **songList, const char *path)
{
	struct SongDef *s;

	s = sys_mem_alloc(sizeof(struct SongDef));
	strcpy(s->path, path);
	s->next = *songList;
	*songList = s;
}
Пример #6
0
int plugin_settings_load(const string fname)
{
	t_sys_file_handle      fhandle;

	if(plugin_settings_init)return 1; /* warning: already initialized */

	fhandle = sys_file_openshare(fname, v_sys_file_forread);

	if(fhandle == v_error_sys_file_open)
	{
point_load_anyway:

		plugin_settings_mem = (char*) sys_mem_alloc(256);
		
		strcpy(plugin_settings_mem, "fennec player 1.0 (fennec 7.1) plug-in settings file\r\n");
		plugin_settings_size = (unsigned int)strlen(plugin_settings_mem);

		plugin_settings_save(fname);

		plugin_settings_init = 1;
		return 1;
	}

	plugin_settings_size = sys_file_getsize(fhandle);

	if(!plugin_settings_size)
	{
		sys_file_close(fhandle);
		goto point_load_anyway;
	}

	plugin_settings_mem = (char*) sys_mem_alloc(plugin_settings_size + 1);
	

	sys_file_read(fhandle, plugin_settings_mem, plugin_settings_size);
	
	plugin_settings_mem[plugin_settings_size] = 0;

	sys_file_close(fhandle);

	plugin_settings_init = 1;
	return 0;
}
Пример #7
0
TWatch *AddWatch(int conditionCount, int actionCount)
{
	TWatch *t = sys_mem_alloc(sizeof(TWatch));

	memset(t, 0, sizeof(TWatch));
	t->index = watchIndex++;
	t->next = inactiveWatches;
	inactiveWatches = t;
	t->actions = AddActions(actionCount);
	t->conditions = AddConditions(conditionCount);
	return t;
}
Пример #8
0
/*
 * initialize internal output engine.
 */
int internal_output_initialize(void)
{
	int i;

	if(internal_output_initialized)return 0;

	player.initialized   = 1;
	player.state         = v_audio_playerstate_notinit;
	player.input_plugin  = (unsigned long)fennec_invalid_index;
	player.stream_handle = (unsigned long)fennec_invalid_index;
	player.loaded        = 0;

	/* mute all */

	for(i=0; i<16; i++)
		player.volume[i] = settings.player.volume[i];

	/* allocate dsp prebuffer */

	player.dsp_prebuffer_length  = dsp_prebuffer_size;
	player.dsp_prebuffer_clength = 0;
	player.dsp_prebuffer         = (char*)sys_mem_alloc(player.dsp_prebuffer_length);

	/* however, the thread's going to call sharing routines */

	sys_thread_share_create(&internal_output_share);

	/* the thread should run! */

	thread_audio_terminate = 0;

	internal_output_thread_audio_engine = sys_thread_call((t_sys_thread_function) thread_audio_engine);

	/* set priority of the thread just created */

	sys_thread_setpriority(internal_output_thread_audio_engine, setting_priority_to_sys(settings.general.threads_priority));


	if(internal_output_thread_audio_engine == v_error_sys_thread_call)
	{
		/* multithreading is not supported, use the same thread (would this work?) */
		sys_thread_function_caller(thread_audio_engine);
	}

	/* well... */

	internal_output_initialized = 1;
	return 1;
}
Пример #9
0
void
duppage(u_int dstenv, u_int addr)
{
	int r;
	u_char *tmp;

	tmp = (u_char*)(UTEXT-BY2PG);	// should be available!

	// This is NOT what you should do in your fork.
	if ((r=sys_mem_alloc(dstenv, addr, PTE_P|PTE_U|PTE_W)) < 0)
		panic("sys_mem_alloc: %e", r);
	if ((r=sys_mem_map(dstenv, addr, 0, (u_int)tmp, PTE_P|PTE_U|PTE_W)) < 0)
		panic("sys_mem_map: %e", r);
	memcpy(tmp, (u_char*)addr, BY2PG);
	if ((r=sys_mem_unmap(0, (u_int)tmp)) < 0)
		panic("sys_mem_unmap: %e", r);
}
Пример #10
0
TTrigger *AddTrigger(int x, int y, int actionCount)
{
	TTrigger *t = sys_mem_alloc(sizeof(TTrigger));
	TTrigger **h;

	memset(t, 0, sizeof(TTrigger));
	t->x = x;
	t->y = y;

	h = &root;
	while (*h) {
		if ((*h)->y < y || ((*h)->y == y && (*h)->x < x))
			h = &((*h)->right);
		else
			h = &((*h)->left);
	}
	*h = t;
	t->actions = AddActions(actionCount);
	return t;
}
Пример #11
0
// Allocate an open file.
int
open_alloc(struct Open **o)
{
	int i, r;

	// Find an available open-file table entry
	for (i = 0; i < MAXOPEN; i++) {
		switch (pageref(opentab[i].o_ff)) {
		case 0:
			if ((r = sys_mem_alloc(0, (u_int)opentab[i].o_ff, PTE_P|PTE_U|PTE_W)) < 0)
				return r;
			/* fall through */
		case 1:
			opentab[i].o_fileid += MAXOPEN;
			*o = &opentab[i];
			memset((void*)opentab[i].o_ff, 0, BY2PG);
			return (*o)->o_fileid;
		}
	}
	return -E_MAX_OPEN;
}
Пример #12
0
int ReadPics(const char *filename, void **pics, int maxPics,
	     color * palette)
{
	FILE *f;
	int eof = 0;
	unsigned short int size;
	int i = 0;

	f = fopen(filename, "rb");
	if (f != NULL) {
		if (palette)
			fread(palette, sizeof(TPalette), 1, f);
		else
			fseek(f, sizeof(TPalette), SEEK_CUR);
			
		while (!eof && i < maxPics) {
			fread(&size, sizeof(size), 1, f);
			swap16(&size);
			if (size) {
				Pic *p = sys_mem_alloc(size);
				
				f_read16(f, &p->w, 2);
				f_read16(f, &p->h, 2);

				f_read(f, &p->data, size - 4);

				pics[i] = p;

				if (ferror(f) || feof(f))
					eof = 1;
			} else {
				pics[i] = NULL;
			}
			i++;
		}
		fclose(f);
	}
	return i;
}
Пример #13
0
/*
 * This function simply converts a file ('infile') to another file ('outfile').
 *
 * read the input stream from 'audio' interface and send it to 'encoder-file'
 * interface.
 *
 * eid      - encoder id.
 * bsize    - buffer size (in bytes, will be padded if necessary).
 * cancelop - set to 1 to stop the operation and return 1 if it was sucessful.
 * pauseop  - set to 1 to pause the operation (till you set it back to 0).
 * (uses the same system in 'internal output')
 * trans    - transcoder settings (new!).
 *
 * use a thread to call this function, or just put this into a thread.
 */
int audioconvert_convertfile_ex(const string infile, string outfile, unsigned long eid, unsigned int bsize, int* cancelop, int* pauseop, audioconvert_file_pfunc cfunc, transcoder_settings *trans)
{
	unsigned long converter_playerhandle;
	unsigned long converter_streamhandle;
	unsigned long encoder_playerhandle    = eid;
	unsigned long encoder_streamhandle;
	unsigned long converter_format_freq;         /* frequency */
	unsigned long converter_format_bps;          /* bits per sample, not bits per second */
	unsigned long converter_format_chan;         /* channels */
	unsigned long converter_format_blocksize;    /* (bits per sample / 8) * channels */
	unsigned int  rbuffsize;                     /* real buffer size (after padding) */
	char*         cbuffer;                       /* buffer (current buffer?) */
	unsigned int  rsize;                         /* return size */
	int           readreturn;
	unsigned long ssize = 0;                     /* data size (sum size?) */
	unsigned long csize = 0;                     /* bytes converted (current size) */
	void*         ehandle;                       /* equalizer handle */


	/* what kinda file we got?? */

	converter_playerhandle = audio_input_selectinput(infile);
	if(converter_playerhandle == -1)return -1; /* not supported,  -1? (maybe.. 'invalid player id') :) */
	
	/*
	   we've selected a player (decoder plugin), so initialize it first 
	   remember, we don't need to uninitialize it, cuz the 'internal input'
	   would do it for us :)
	*/

	audio_input_plugin_initialize(converter_playerhandle);

	/* 
	   load the input file,
	   anyhow, fennec ain't just designed to listen something and stop that,
	   it can gather input from more than one streams at once (?), so we gotta use a
	   handle to identify the file <- it can be any value between 0 and infinity.
	   (ok, 0xffffffff... :) ).
	*/

	if(!audio_input_plugin_loadfile(converter_playerhandle, infile, &converter_streamhandle))return -2;

	/* get the ....... format first (we'll need some padding) */

	audio_input_plugin_getformat(converter_playerhandle, converter_streamhandle, &converter_format_freq, &converter_format_bps, &converter_format_chan);

	/* calculate block size for padding */

	converter_format_blocksize = (converter_format_bps / 8) * converter_format_chan;

	/* allocate the buffer */

	if(bsize % converter_format_blocksize) /* add padding if necessary */
		rbuffsize = bsize + (converter_format_blocksize - (bsize % converter_format_blocksize));
	else
		rbuffsize = bsize;

	cbuffer = sys_mem_alloc(rbuffsize);

	if(!cbuffer)
	{
		/* not enough memory!, turn off the computer and add another core
		   (>1MB) and restart the routine. :) 4 nw v unld d fy1 */

		audio_input_plugin_unloadfile(converter_playerhandle, converter_streamhandle);
		return -3;
	}

	/*
	   calc the raw size of the input stream (stream?... return -1 or 0?)
	   we don't need a real 'ssize' value, it's just a progress notification.
	*/

	ssize = audio_input_plugin_getduration_ms(converter_playerhandle, converter_streamhandle) * /* bytes per ms */ ((converter_format_freq / 1000) * (converter_format_bps / 8) * converter_format_chan);

	/* we need an encoder too */

	if(!encoder_initialize())
	{
		sys_mem_free(cbuffer);
		audio_input_plugin_unloadfile(converter_playerhandle, converter_streamhandle);
		return -4;
	}

	encoder_plugin_initialize(encoder_playerhandle);

	/* create a file */

	encoder_streamhandle = encoder_plugin_file_create(encoder_playerhandle, outfile);

	if(converter_streamhandle == -1)
	{
		sys_mem_free(cbuffer);
		audio_input_plugin_unloadfile(converter_playerhandle, converter_streamhandle);
		encoder_uninitialize();
		return -5;
	}

	/* initialize the equalizer, all we need is an array of bands */

	ehandle = equalize_buffer_variable_init(&trans->eq.eq, converter_format_chan, converter_format_freq);

	/* well... hummm..... start conversion */

	for(;;)
	{
		
		/* first of all, we gotta check those pause/cancel flags */

		if(*cancelop)goto point_end;
		if(*pauseop) goto point_continue;

		/* 'rsize' actually != just 'return size' */

		rsize = rbuffsize;

		/*
		   read data, on eof, error; 'read data' returns zero .
		   and we can also determine it using 'rsize'.
		*/

		readreturn = audio_input_plugin_readdata(converter_playerhandle, converter_streamhandle, (unsigned long*)&rsize, cbuffer);

		if(!readreturn)goto point_end;

		/* set volume/gain */

		if(trans->volume.enable_vol)
		{
			if(trans->volume.vol < 0.98f)
			{
				convert_setblock_volume((fennec_sample*) cbuffer, converter_format_freq, converter_format_chan, converter_format_bps, rsize, (float)trans->volume.vol);
			}else if(trans->volume.gain > 0.02f){
				convert_setblock_volume((fennec_sample*)cbuffer, converter_format_freq, converter_format_chan, converter_format_bps, rsize, (float)(trans->volume.gain * 4.0) + 1.0f);
			}
		}

		/* set equalizer */

		if(trans->eq.enable_eq)
		{
			equalize_buffer_variable(cbuffer, 0, converter_format_chan, converter_format_freq, converter_format_bps, rsize, ehandle);
		}

		sys_sleep(2);

		
		/* copy data to the output file */

		encoder_plugin_file_write(encoder_playerhandle, encoder_streamhandle, cbuffer,
			                      converter_format_freq,
								  converter_format_bps,
								  converter_format_chan, rsize);

		/* call set position to dispaly some info */

		csize += rsize;
		if(cfunc && ssize)cfunc((double)csize / (double)ssize);
		sys_pass();
		
		/* now check for eof */

		if(rsize < rbuffsize)goto point_end;

		/* continue if paused */

		goto point_continue_fast;

point_continue:
		sys_sleep(100);

point_continue_fast:;

	}

point_end:

	/* finish! */

	if(cfunc)cfunc(1.0f);

	/* you should clean your ... by yourself :o) */

	sys_mem_free(cbuffer);
	audio_input_plugin_unloadfile(converter_playerhandle, converter_streamhandle);
	encoder_plugin_file_close(encoder_playerhandle, encoder_streamhandle);
	equalize_buffer_variable_uninit(ehandle);

	/* encoder_plugin_uninitialize(encoder_playerhandle);
	   encoder_uninitialize(); */
	return 0;
}
Пример #14
0
static TCondition *AddConditions(int count)
{
	TCondition *a = sys_mem_alloc(sizeof(TCondition) * (count + 1));
	memset(a, 0, sizeof(TCondition) * (count + 1));
	return a;
}
Пример #15
0
void list_sort_column(int cid, int smode)
{
	struct fennec_audiotag       *atag;
	struct fennec_audiotag_item  *ati;
	unsigned long  i, j, s, c = ml_cache_getcount();
	double        *smem;
	double         fv;
	
	smem = (double*) sys_mem_alloc(c * sizeof(double));
	if(!smem) return;

	if(smode < 2)
	{
		skin_settings.ml_sorted_column = cid;
		skin_settings.ml_sorted_mode   = smode;

		for(i=0; i<c; i++)
		{
			atag = ml_cache_get(i);

			switch(cid)
			{
			case header_tag_title          : ati = &atag->tag_title       ; break;
			case header_tag_album		   : ati = &atag->tag_album		  ; break;
			case header_tag_artist		   : ati = &atag->tag_artist      ; break;
			case header_tag_origartist	   : ati = &atag->tag_origartist  ; break;
			case header_tag_composer	   : ati = &atag->tag_composer	  ; break;
			case header_tag_lyricist	   : ati = &atag->tag_lyricist	  ; break;
			case header_tag_band		   : ati = &atag->tag_band		  ; break;
			case header_tag_copyright	   : ati = &atag->tag_copyright	  ; break;
			case header_tag_publish		   : ati = &atag->tag_publish	  ; break;
			case header_tag_encodedby      : ati = &atag->tag_encodedby   ; break;
			case header_tag_genre		   : ati = &atag->tag_genre		  ; break;
			case header_tag_year		   : ati = &atag->tag_year		  ; break;
			case header_tag_url			   : ati = &atag->tag_url		  ; break;
			case header_tag_offiartisturl  : ati = &atag->tag_offiartisturl; break;
			case header_tag_filepath	   : ati = &atag->tag_filepath	  ; break;
			case header_tag_filename	   : ati = &atag->tag_filename	  ; break;
			case header_tag_comments	   : ati = &atag->tag_comments	  ; break;
			case header_tag_lyric		   : ati = &atag->tag_lyric		  ; break;
			case header_tag_bpm            : ati = &atag->tag_bpm         ; break;
			case header_tag_tracknum	   : ati = &atag->tag_tracknum	  ; break;
			default: return;
			}

			if(ati->tdata && ati->tsize)

				if(cid == header_tag_tracknum || cid == header_tag_year)
				{

					smem[i] = str_stoi(ati->tdata);
					
				}else{

					smem[i] = list_sort_score(ati->tdata);
				}

			else
				smem[i] = sort_score_max;
		}

	}else{ /* directories */

		if(cid == media_library_dir_years)
		{
			for(i=0; i<c; i++)
			{
				if(cached_tags[i].dname)
					smem[i] = str_stoi(cached_tags[i].dname);
				else
					smem[i] = sort_score_max;
			}

		}else{
			for(i=0; i<c; i++)
			{
				if(cached_tags[i].dname)
					smem[i] = list_sort_score(cached_tags[i].dname);
				else
					smem[i] = sort_score_max;
			}
		}
	}

	/* second run */

	if(smode & 1) /* descending (1, 3) */
	{
		for(i=0; i<c; i++)
		{
			fv = 0;
			s  = (unsigned long)-1;

			for(j=0; j<c; j++)
			{
				if((smem[j] > 0.0) && (smem[j] > fv))
				{
					fv = smem[j];
					s  = j;
				}
			}

			if(s != (unsigned long)-1)
			{
				ml_cache_exchange(i, s);
				skin.shared->audio.output.playlist.move(i, s, 1);
				
				smem[s] = smem[i];
				smem[i] = -1.0;
			}
		}
	}else{
		for(i=0; i<c; i++)
		{
			fv = (sort_score_max * 2.0);
			s  = (unsigned long)-1;

			for(j=0; j<c; j++)
			{
				if((smem[j] > 0.0) && (smem[j] < fv))
				{
					fv = smem[j];
					s  = j;
				}
			}

			if(s != (unsigned long)-1)
			{
				ml_cache_exchange(i, s);
				skin.shared->audio.output.playlist.move(i, s, 1);
				
				smem[s] = smem[i];
				smem[i] = -1.0;
			}
		}
	}

	sys_mem_free(smem);
}
Пример #16
0
int encoder_write(unsigned long id, void* rbuffer, unsigned long bsize)
{	
	int             bytesencoded = 0;
	double         *sbuffer = (double*) rbuffer;
	unsigned char  *bbuffer = (unsigned char*) rbuffer;
	unsigned int    framesize = 0;

	if(pestreams[id].firstwrite)
	{
		int v = 0;

		pestreams[id].enchandle = faacEncOpen(pestreams[id].cfrequency, pestreams[id].cchannels,
											  &pestreams[id].samplesin, &pestreams[id].maxbytesout);

		pestreams[id].obuffer     = (unsigned char*)sys_mem_alloc(pestreams[id].maxbytesout);
		pestreams[id].cachebuffer = (unsigned char*)sys_mem_alloc(pestreams[id].samplesin * 10);
		pestreams[id].fb_size     = 0;
		pestreams[id].floatbuffer = 0;

		pestreams[id].econfig = faacEncGetCurrentConfiguration(pestreams[id].enchandle);

		pestreams[id].econfig->inputFormat = FAAC_INPUT_FLOAT;

		pestreams[id].econfig->aacObjectType = LOW; //objectType;

		if(pestreams[id].ismp4)
		{
			pestreams[id].econfig->mpegVersion   = MPEG4;
			pestreams[id].econfig->outputFormat  = 0;
			pestreams[id].econfig->allowMidside  = 1;
			pestreams[id].econfig->shortctl      = SHORTCTL_NORMAL;

			if(fsettings.plugin_settings_getnum("aac", "bitrate", &v, 0, 0))v = 0xa;
			pestreams[id].econfig->bitRate       = (ibitrates[v] * 1000) / pestreams[id].cchannels;

			v = 0x2;
			if(fsettings.plugin_settings_getnum("aac", "quality", &v, 0, 0))v = 0x2;
			pestreams[id].econfig->quantqual     = iqualities[v];

			pestreams[id].econfig->bandWidth     = pestreams[id].cfrequency / 2;

		}else{

			pestreams[id].econfig->mpegVersion   = MPEG2;

			pestreams[id].econfig->useTns        = 0;
			pestreams[id].econfig->shortctl      = SHORTCTL_NORMAL;
			pestreams[id].econfig->useLfe        = 0;
			pestreams[id].econfig->allowMidside  = 1;

			if(fsettings.plugin_settings_getnum("aac", "bitrate", &v, 0, 0))v = 0xa;
			pestreams[id].econfig->bitRate       = (ibitrates[v] * 1000) / pestreams[id].cchannels;

			v = 0x2;
			if(fsettings.plugin_settings_getnum("aac", "quality", &v, 0, 0))v = 0x2;
			pestreams[id].econfig->quantqual     = iqualities[v];

			pestreams[id].econfig->bandWidth     = 0;
		}


		faacEncSetConfiguration(pestreams[id].enchandle, pestreams[id].econfig);

		/* mp4 stuff */

		if(pestreams[id].ismp4)
		{
			unsigned char *ASC       = 0;
			unsigned long  ASCLength = 0;
			char           afname[v_sys_maxpath];
			BOOL           usedef = 1;

			WideCharToMultiByte(CP_ACP, 0, pestreams[id].filepath, -1, afname, sizeof(afname), "?", &usedef);

#			ifdef MP4_CREATE_EXTENSIBLE_FORMAT

				pestreams[id].mp4file = MP4Create(afname, 0, 0);
#			else

				pestreams[id].mp4file = MP4Create(afname, 0, 0, 0);
#			endif


			MP4SetTimeScale(pestreams[id].mp4file, 90000);
			pestreams[id].mp4track = MP4AddAudioTrack(pestreams[id].mp4file, pestreams[id].cfrequency, MP4_INVALID_DURATION, MP4_MPEG4_AUDIO_TYPE);
			MP4SetAudioProfileLevel(pestreams[id].mp4file, 0x0F);

			faacEncGetDecoderSpecificInfo(pestreams[id].enchandle, &ASC, &ASCLength);

			MP4SetTrackESConfiguration(pestreams[id].mp4file, pestreams[id].mp4track, ASC, ASCLength);


			free(ASC);

			MP4SetMetadataTool(pestreams[id].mp4file, "Fennec Player 1.1 (libfaac)");
			
		}



		pestreams[id].totalsamples   = 0;
		pestreams[id].encodedsamples = 0;
		pestreams[id].cachesize      = 0;
		pestreams[id].firstwrite     = 0;
	}

	
	/* if(pestreams[id].cbitspersample == 64) standard */
	{
		unsigned int i = 0;
		unsigned int sbytes = pestreams[id].cbitspersample / 8;


		framesize = pestreams[id].samplesin / pestreams[id].cchannels;

		if(pestreams[id].ismp4)
			pestreams[id].totalsamples += bsize / sbytes;

		while(1)
		{
			if((int)(bsize / sbytes) - (int)i < (int)pestreams[id].samplesin)
			{
				if((int)(bsize / sbytes) - (int)i > 0)
				{
					memcpy(pestreams[id].cachebuffer + pestreams[id].cachesize, sbuffer + i, (bsize / sbytes) - i);
					pestreams[id].cachesize += (bsize / sbytes) - i;
				}
				break;
			}

			if(pestreams[id].cachesize)
			{
				memcpy(pestreams[id].cachebuffer + pestreams[id].cachesize, sbuffer + i, (pestreams[id].samplesin * sbytes) - pestreams[id].cachesize);
				
				local_write_doublebuffer(id, (double*)pestreams[id].cachebuffer, pestreams[id].samplesin, bytesencoded, framesize);


				pestreams[id].cachesize = 0;

				i += pestreams[id].samplesin - pestreams[id].cachesize;

			}else{

				local_write_doublebuffer(id, (double*)(sbuffer + i), pestreams[id].samplesin, bytesencoded, framesize);

				i += pestreams[id].samplesin;
			}
		}
	}

	return 1;
}
Пример #17
0
int tags_translate(string mem, struct fennec_audiotag* tags, string fpath)
{
	letter        *mtxt, fstr[64], fname[v_sys_maxpath];
	unsigned int  i, fstrz, mz = 1024;
	struct fennec_audiotag_item* ct, ft_path, ft_name; /* current tag, fake tag */

	if(fpath)
	{
		ft_path.tdata = fpath;
		ft_path.tsize = (unsigned long)str_size(fpath);
	}else{
		ft_path.tdata = 0;
		ft_path.tsize = 0;
	}

	ft_path.tmode = tag_memmode_static;

	if(fpath)
	{
#	ifdef fennec_mode_multibyte
		_splitpath(fpath, 0, 0, fname, 0);
#	else
		_wsplitpath(fpath, 0, 0, fname, 0);
#	endif

		ft_name.tdata = fname;
		ft_name.tsize = (unsigned long)str_size(fname);

	}else{

		ft_name.tdata = 0;
		ft_name.tsize = 0;
	}

	ft_name.tmode = tag_memmode_static;

	mtxt = (string) sys_mem_alloc(mz * sizeof(letter));
	i    = 0;

point_selecttag:

	i++;

	switch(i)
	{
	case 1:
		ct = &tags->tag_title;
		str_cpy(fstr, uni("<title-x>"));
		goto point_applytag;
	case 2:
		ct = &tags->tag_album;
		str_cpy(fstr, uni("<album-x>"));
		goto point_applytag;
	case 3:
		ct = &tags->tag_artist;
		str_cpy(fstr, uni("<artist-x>"));
		goto point_applytag;
	case 4:
		ct = &tags->tag_origartist;
		str_cpy(fstr, uni("<artist.o-x>"));
		goto point_applytag;
	case 5:
		ct = &tags->tag_composer;
		str_cpy(fstr, uni("<composer-x>"));
		goto point_applytag;
	case 6:
		ct = &tags->tag_lyricist;
		str_cpy(fstr, uni("<lyricist-x>"));
		goto point_applytag;
	case 7:
		ct = &tags->tag_band;
		str_cpy(fstr, uni("<band-x>"));
		goto point_applytag;
	case 8:
		ct = &tags->tag_copyright;
		str_cpy(fstr, uni("<copyright-x>"));
		goto point_applytag;
	case 9:
		ct = &tags->tag_publish;
		str_cpy(fstr, uni("<publish-x>"));
		goto point_applytag;
	case 10:
		ct = &tags->tag_encodedby;
		str_cpy(fstr, uni("<encodedby-x>"));
		goto point_applytag;
	case 11:
		ct = &tags->tag_genre;
		str_cpy(fstr, uni("<genre-x>"));
		goto point_applytag;
	case 12:
		ct = &tags->tag_year;
		str_cpy(fstr, uni("<year-x>"));
		goto point_applytag;
	case 13:
		ct = &tags->tag_url;
		str_cpy(fstr, uni("<url-x>"));
		goto point_applytag;
	case 14:
		ct = &tags->tag_offiartisturl;
		str_cpy(fstr, uni("<url.artist.o-x>"));
		goto point_applytag;
	case 15:
		ct = &ft_path;
		str_cpy(fstr, uni("<file.path-x>"));
		goto point_applytag;
	case 16:
		ct = &ft_name;
		str_cpy(fstr, uni("<file.name-x>"));
		goto point_applytag;
	case 17:
		ct = &tags->tag_comments;
		str_cpy(fstr, uni("<comments-x>"));
		goto point_applytag;
	case 18:
		ct = &tags->tag_lyric;
		str_cpy(fstr, uni("<lyrics-x>"));
		goto point_applytag;
	case 19:
		ct = &tags->tag_bpm;
		str_cpy(fstr, uni("<bpm-x>"));
		goto point_applytag;
	case 20:
		ct = &tags->tag_tracknum;
		str_cpy(fstr, uni("<tracknum-x>"));
		goto point_applytag;
	}

	sys_mem_free(mtxt);
	return 1;

point_applytag:

	if(ct->tdata && ct->tsize)
	{
		if(mz < ct->tsize + 1)
		{
			if(ct->tsize > 0x100000 /* 1MB */)goto point_invalidtag;

			mz = ct->tsize + 10;
			mtxt = (string) sys_mem_realloc(mtxt, mz * sizeof(letter));
		}

		str_cpy(mtxt, ct->tdata);
		mtxt[ct->tsize] = 0; /* null terminated string */

		fstrz = (unsigned int) str_len(fstr);

		fstr[fstrz - 2] = uni('d');
		tags_str_replace(mem, mtxt, fstr);
	
		fstr[fstrz - 2] = uni('r');
		tags_str_replace(mem, mtxt, fstr);

		fstr[fstrz - 2] = uni('p');
		tags_str_propercase(mtxt, mz);
		tags_str_replace(mem, mtxt, fstr);
		
		fstr[fstrz - 2] = uni('u');
		str_upper(mtxt);
		tags_str_replace(mem, mtxt, fstr);
		
		fstr[fstrz - 2] = uni('l');
		str_lower(mtxt);
		tags_str_replace(mem, mtxt, fstr);

	}else{

point_invalidtag:

		fstrz = (unsigned int) str_len(fstr);

		fstr[fstrz - 2] = uni('r');
		tags_str_replace(mem, uni("Unknown"), fstr);

		fstr[fstrz - 2] = uni('d');
		tags_str_replace(mem, uni(""), fstr);
		
		fstr[fstrz - 2] = uni('p');
		tags_str_propercase(mtxt, mz);
		tags_str_replace(mem, uni(""), fstr);
		
		fstr[fstrz - 2] = uni('u');
		str_upper(mtxt);
		tags_str_replace(mem, uni(""), fstr);
		
		fstr[fstrz - 2] = uni('l');
		str_lower(mtxt);
		tags_str_replace(mem, uni(""), fstr);
	}

	goto point_selecttag;
}
Пример #18
0
int vis_lyrics_loadcurrent(void)
{
	int                     id, i;
	struct fennec_audiotag  ctag;
	const string            fpath = skin.shared->audio.output.playlist.getsource(skin.shared->audio.output.playlist.getcurrentindex());


	if(!fpath)return 0;
	if(str_icmp(vis_lyrics_lastfile, fpath) == 0)return 0;

	str_cpy(vis_lyrics_lastfile, fpath);

	vis_lyric_tag_len = 0;
	vis_lyric_current_text = 0;
	vis_lyric_current_text_len = 0;
	vis_lyric_current_text_pos = 0;
	vis_lyric_current_action = 0;
	vis_markers = 0;
	vis_marker_last = 0;


	if(vis_lyric_tag)sys_mem_free(vis_lyric_tag);
		vis_lyric_tag = 0;

	id = skin.shared->audio.input.tagread(fpath, &ctag);

	if(ctag.tag_lyric.tsize)
	{
		vis_lyric_tag = (string) sys_mem_alloc((ctag.tag_lyric.tsize + 16) * sizeof(letter));

		str_cpy(vis_lyric_tag, ctag.tag_lyric.tdata);
	}else{
		if(vis_lyric_tag)sys_mem_free(vis_lyric_tag);
		vis_lyric_tag = 0;
	}

	skin.shared->audio.input.tagread_known(id, 0, &ctag);


	if(vis_lyric_tag)
	{
		vis_lyric_tag_len = (int)str_len(vis_lyric_tag);
		for(i=0; i<vis_lyric_tag_len; i++)
		{
			if(vis_lyric_tag[i] == uni('\r'))vis_lyric_tag[i] = uni('\0');
			else if(vis_lyric_tag[i] == uni('\n'))vis_lyric_tag[i] = uni('\0');

			if(!vis_markers)
			{
				if(vis_lyric_tag[i] == uni('[') && (vis_lyric_tag_len - i) > 9)
				{
					if(str_ncmp(vis_lyric_tag + i, uni("[markers:"), 9) == 0)
					{
						vis_markers = vis_lyric_tag + i;
						vis_marker_pos = 9;
						vis_marker_show = -1;
						vis_marker_hide = -1;
						vis_lyric_current_text_pos = 0;
					}
				}
			}
		}
	}

	return 1;
}
Пример #19
0
/*
 * load file/stream.
 */
int internal_output_loadfile(const string spath)
{
	int perror_on_decoder = 1;

	/* history, oh, fading away */

	if(player.state != v_audio_playerstate_init)
		audio_stop();

	
	/* "this is my turn" */

	sys_thread_share_request(&internal_output_share);

	/* this state would be a message to the user */

	player.state = v_audio_playerstate_opening;


	/* load default values */

	player.output_bitdepth = settings.audio_output.bit_depth;
	player.output_float    = settings.audio_output.bit_depth_float;
	player.output_signed   = settings.audio_output.bit_depth_signed;


	/* select input plugin */

	player.input_plugin = audio_input_selectinput(spath);

	/* no! */

	if(player.input_plugin == fennec_invalid_index) goto point_error;


	/* initialize the plugin */

	audio_input_plugin_initialize(player.input_plugin);
	audio_input_plugin_loadfile(player.input_plugin, spath, &player.stream_handle);

	/* file corrupted? ain't implemented? or ... */

	if(player.stream_handle == fennec_invalid_index) goto point_error;

	/* cool to be remembered */

	str_cpy(player.current_file, spath);
	

	/* get format information */


	if(!audio_input_plugin_getformat(player.input_plugin, player.stream_handle, &player.samplerate, &player.bitdepth, &player.channels)) goto point_error;

	/* zero samples a second with zero channels and/or zero bit depth? what a cool sound! */

	if(!player.samplerate || !player.bitdepth || !player.channels) goto point_error;


	/* allocate memory */

	player.prebuffersize = (settings.audio_output.buffer_memory * player.samplerate * player.channels * (player.bitdepth / 8) ) / 1000;
	player.buffersize    = (settings.audio_output.buffer_memory * player.samplerate * player.channels * (player.output_bitdepth/ 8) ) / 1000;

	if(!player.buffersize || !player.prebuffersize) goto point_error;

	player.prebuffer = (char*) sys_mem_alloc(player.prebuffersize);
	player.buffer    = (char*) sys_mem_alloc(player.buffersize);
	
	/* now we've done with decoder stuff */

	perror_on_decoder = 0;

	/* start working with audio output system */

	
	{
		unsigned int devi = v_sys_media_driver_default;

		if(settings.audio_output.output_device_id != -1 && settings.audio_output.output_device_id != 0)
			devi = settings.audio_output.output_device_id - 1; /* cuz the default device replaces 0 */

		player.audio_handle = sys_media_stream_init(devi, player.samplerate, player.channels, player.output_bitdepth);
	
		if(player.audio_handle == v_error_sys_media_stream_init) goto point_error;
	
	}

	/* reset equalizer history */

	equalizer_reset();

	/* the state (remember, the message) */

	player.state           = v_audio_playerstate_loaded;
	player.loaded          = 1;
	player.written_samples = 0;
	player.bufferpos       = 0;
	player.stopping        = 0;

	{
		unsigned long  rlen = player.prebuffersize;

		local_readdata(player.input_plugin, player.stream_handle, &rlen, player.prebuffer, 1, &player);
		local_downsample(player.buffer, player.prebuffer, rlen);
	}

	sys_thread_share_release(&internal_output_share);

	return 1;


	/* - - - - - - - - - - - - - - - */

point_error:

	if(!perror_on_decoder)
		MessageBox(0, text(oooo_e_files_invalid_format), text(oooo_error), MB_ICONEXCLAMATION);

	sys_thread_share_release(&internal_output_share);
	return 0;
}
Пример #20
0
/*
 * Audio joining function, same as the routine above but a little bit
 * splited.
 *
 * actually into three parts:
 *     o. start. (start the routine and join one file).
 *     o. push. (add another file, somehow there's no 'pop' function :-) ).
 *     o. end. (finish).
 */
int audiojoining_start(const string infile, string outfile, unsigned long eid, unsigned int bsize, int* cancelop, int* pauseop, double spos, double epos, audioconvert_file_pfunc cfunc)
{
	int           format_blocksize;
	unsigned int  current_size;           /* current file size */
	unsigned int  processed_size = 0;     /* bytes encoded */
	unsigned int  rsize;
	int           readreturn;
	void*         ehandle;                /* equalizer handle */


	if(joining_started)return 0; /* already started */

	/* set flag pointers */

	joining_data.cancelop = cancelop;
	joining_data.pauseop  = pauseop;
	joining_data.cfunc    = cfunc;

	/* input selection */

	joining_data.converter_playerhandle = audio_input_selectinput(infile);

	/* can we read the input file? */
	if(joining_data.converter_playerhandle == (unsigned long)-1)return 0;

	audio_input_plugin_initialize(joining_data.converter_playerhandle);

	/* first, we gotta get some information */

	if(!audio_input_plugin_loadfile(joining_data.converter_playerhandle, infile, &joining_data.converter_streamhandle))return 0;

	/* calculate padding (we need to allocate a buffer to store all samples, not halves) */

	audio_input_plugin_getformat(joining_data.converter_playerhandle, joining_data.converter_streamhandle, &joining_data.format_freq, &joining_data.format_bps, &joining_data.format_chan);

	/* calculate block size for padding */

	format_blocksize = (joining_data.format_bps / 8) * joining_data.format_chan;

	/* allocate the buffer */

	if(bsize % format_blocksize) /* don't need to add padding */
		joining_data.buffersize = bsize;
	else
		joining_data.buffersize = bsize + (format_blocksize - (bsize % format_blocksize));
	
	joining_data.buffer = (char*) sys_mem_alloc(joining_data.buffersize);

	/* allright? */

	if(!joining_data.buffer)
	{
		audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle);
		return 0;
	}

	current_size = audio_input_plugin_getduration_ms(joining_data.converter_playerhandle, joining_data.converter_streamhandle) * /* bytes per ms */ ((joining_data.format_freq / 1000) * (joining_data.format_bps / 8) * joining_data.format_chan);

	audio_input_plugin_setposition(joining_data.converter_playerhandle, joining_data.converter_streamhandle, spos);
	current_size = (unsigned int)((((double)current_size) * epos) - (((double)current_size) * spos));

	/* we need an encoder too */

	if(!encoder_initialize())
	{
		sys_mem_free(joining_data.buffer);
		audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle);
		return 0;
	}

	/* which encoder? */

	joining_data.encoder_playerhandle = eid;

	encoder_plugin_initialize(joining_data.encoder_playerhandle);

	/* create a file */

	joining_data.encoder_streamhandle = encoder_plugin_file_create(joining_data.encoder_playerhandle, outfile);

	if(joining_data.encoder_streamhandle == -1)
	{
		sys_mem_free(joining_data.buffer);
		audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle);
		encoder_uninitialize();
		return 1;
	}

	/* we gotta clear out the equalizer history buffer */

	ehandle = equalize_buffer_variable_init(&settings.conversion.equalizer_bands, joining_data.format_chan, joining_data.format_freq);


	/* start conversion */

	for(;;)
	{
		
		/* first of all, we gotta check those pause/cancel flags */

		if(*cancelop)goto point_end;
		if(*pauseop) goto point_continue;

		/* set buffer size to be read */

		if(((int)current_size) - (int)(processed_size) > (int)joining_data.buffersize)
			rsize = joining_data.buffersize;
		else if(((int)current_size) - (int)(processed_size) > 0)
			rsize = (((int)current_size) - (int)(processed_size));
		else
			rsize = 0;

		/*
		   read data, on eof, error; 'read data' returns zero .
		   and we can also determine it using 'rsize'.
		*/

		readreturn = audio_input_plugin_readdata(joining_data.converter_playerhandle, joining_data.converter_streamhandle, (unsigned long*)&rsize, joining_data.buffer);

		/* end of the file? */
		if(!readreturn)goto point_end;

		/* set block volume, gain */
		if(settings.conversion.volume < 0.98f)
		{
			convert_setblock_volume((fennec_sample*) joining_data.buffer, joining_data.format_freq, joining_data.format_chan, joining_data.format_bps, rsize, (float)settings.conversion.volume);
		}else if(settings.conversion.volume_gain > 0.02f){
			convert_setblock_volume((fennec_sample*) joining_data.buffer, joining_data.format_freq, joining_data.format_chan, joining_data.format_bps, rsize, (float)settings.conversion.volume + 1.0f);
		}

		/* equalize block */

		if(settings.joining.use_equalizer)
		{
			equalize_buffer_variable(joining_data.buffer, 0, joining_data.format_chan, joining_data.format_freq, joining_data.format_bps, rsize, ehandle);
		}

		/* copy data to the output file */

		encoder_plugin_file_write(joining_data.encoder_playerhandle, joining_data.encoder_streamhandle, joining_data.buffer,
			                      joining_data.format_freq,
								  joining_data.format_bps,
								  joining_data.format_chan, rsize);

		/* call set position to dispaly some info */

		processed_size += rsize;
		if(cfunc && current_size)cfunc((double)processed_size / (double)current_size);
		
		/* sleep awhile |-) */

		sys_pass();
		
		/* now check for eof */

		if(rsize < joining_data.buffersize)goto point_end;

		/* continue if paused */

		goto point_continue_fast;

point_continue:
		sys_sleep(100);

point_continue_fast:;

	}

point_end:


	/* finish! */

	if(cfunc)cfunc(1.0f);

	audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle);

	joining_started = 1;
	return 1;
}