Ejemplo n.º 1
0
/*
 * stop playback.
 */
int internal_output_stop(void)
{
	if(player.input_plugin != fennec_invalid_index)
	{
		sys_thread_share_request(&internal_output_share);

		player.state = v_audio_playerstate_stopped;

		if(player.loaded)
		{
			if(player.audio_handle != v_error_sys_media_main_init)
			{
				sys_media_stream_clear(player.audio_handle);
				sys_media_stream_uninit(player.audio_handle);
			}
		}

		player.loaded = 0;

		if(player.stream_handle != fennec_invalid_index)
			audio_input_plugin_unloadfile(player.input_plugin, player.stream_handle);
	
		player.stream_handle = (unsigned long)fennec_invalid_index;
		player.input_plugin  = (unsigned long)fennec_invalid_index;

		sys_mem_free(player.prebuffer);
		sys_mem_free(player.buffer);

		player.state = v_audio_playerstate_stopped;
		
		sys_thread_share_release(&internal_output_share);
	}
	return 1;
}
Ejemplo n.º 2
0
/*
 * uninitialize internal output engine
 * and everything associated with it.
 */
int internal_output_uninitialize(void)
{
	if(!internal_output_initialized) return 0;

	internal_output_stop();

	player.state       = v_audio_playerstate_notinit;
	player.initialized = 0;

	/* happy holidays */

	sys_thread_share_request(&internal_output_share);
	thread_audio_terminate = 1;
	sys_thread_share_release(&internal_output_share);

	/* just wait awhile */

	while(thread_audio_terminate) sys_pass();

	/* clear the DSP buffer */

	if(player.dsp_prebuffer)
	{
		sys_mem_free(player.dsp_prebuffer);
		player.dsp_prebuffer = 0;
	}


	internal_output_initialized = 0;
	return 1;
}
Ejemplo n.º 3
0
int plugin_settings_unload(void)
{
	if(!plugin_settings_mem)return -1;
	if(!plugin_settings_init)return 1; /* warning: already uninitialized */

	sys_mem_free(plugin_settings_mem);
	plugin_settings_init = 0;
	return 0;
}
Ejemplo n.º 4
0
int encoder_uninitialize(unsigned long id)
{
	if(!pestreams[id].firstwrite)
	{
		faacEncClose(pestreams[id].enchandle);

		sys_mem_free(pestreams[id].floatbuffer);
		sys_mem_free(pestreams[id].obuffer);
		sys_mem_free(pestreams[id].cachebuffer);


		if(!pestreams[id].ismp4)
		{
			sys_file_close(pestreams[id].fhandle);
		}else{
			MP4Close(pestreams[id].mp4file);
		}

		pestreams[id].firstwrite = 1;
	}
	return 1;
}
Ejemplo n.º 5
0
int audiojoining_end(int hjoin /* not used */)
{
	if(!joining_started)return 0;

	sys_mem_free(joining_data.buffer);
	audio_input_plugin_unloadfile(joining_data.converter_playerhandle, joining_data.converter_streamhandle);
	encoder_plugin_file_close(joining_data.encoder_playerhandle, joining_data.encoder_streamhandle);
	/*encoder_plugin_uninitialize(joining_data.encoder_playerhandle);
	  encoder_uninitialize(); */
	joining_started = 0;

	return 1;
}
Ejemplo n.º 6
0
int uninit_userp(void)
{
    int ret;
    while (!list_empty(&dqlist))
    {
            struct data_buf *pbuffer;

            pbuffer = list_entry(dqlist.next,
                           struct data_buf, list);
            if ((ret = sys_mem_free(pbuffer->p_ion_handle)))
                  return ret;

            list_del_init(&(pbuffer->list));
    }
    return 0;
}
Ejemplo n.º 7
0
/*
 * uninitialize plugin and unload all streams.
 */
int callc fennec_plugin_uninitialize(void)
{
	unsigned long i;

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

	pstreams_count = 0;
	sys_mem_free(pstreams);
	return 1;
}
Ejemplo n.º 8
0
int tagread(const string fname, struct fennec_audiotag* rtag)
{
	if(!rtag)return 0;

	if(!fname)
	{
		if(rtag->tag_title.tsize         ) { sys_mem_free(rtag->tag_title.tdata         ); rtag->tag_title.tsize         = 0; }
		if(rtag->tag_album.tsize         ) { sys_mem_free(rtag->tag_album.tdata         ); rtag->tag_album.tsize         = 0; }
		if(rtag->tag_artist.tsize        ) { sys_mem_free(rtag->tag_artist.tdata        ); rtag->tag_artist.tsize        = 0; }
		if(rtag->tag_origartist.tsize    ) { sys_mem_free(rtag->tag_origartist.tdata    ); rtag->tag_origartist.tsize    = 0; }
		if(rtag->tag_composer.tsize      ) { sys_mem_free(rtag->tag_composer.tdata      ); rtag->tag_composer.tsize      = 0; }
		if(rtag->tag_lyricist.tsize      ) { sys_mem_free(rtag->tag_lyricist.tdata      ); rtag->tag_lyricist.tsize      = 0; }
		if(rtag->tag_band.tsize          ) { sys_mem_free(rtag->tag_band.tdata          ); rtag->tag_band.tsize          = 0; }
		if(rtag->tag_copyright.tsize     ) { sys_mem_free(rtag->tag_copyright.tdata     ); rtag->tag_copyright.tsize     = 0; }
		if(rtag->tag_publish.tsize       ) { sys_mem_free(rtag->tag_publish.tdata       ); rtag->tag_publish.tsize       = 0; }
		if(rtag->tag_encodedby.tsize     ) { sys_mem_free(rtag->tag_encodedby.tdata     ); rtag->tag_encodedby.tsize     = 0; }
		if(rtag->tag_genre.tsize         ) { sys_mem_free(rtag->tag_genre.tdata         ); rtag->tag_genre.tsize         = 0; }
		if(rtag->tag_year.tsize          ) { sys_mem_free(rtag->tag_year.tdata          ); rtag->tag_year.tsize          = 0; }
		if(rtag->tag_url.tsize           ) { sys_mem_free(rtag->tag_url.tdata           ); rtag->tag_url.tsize           = 0; }
		if(rtag->tag_offiartisturl.tsize ) { sys_mem_free(rtag->tag_offiartisturl.tdata ); rtag->tag_offiartisturl.tsize = 0; }
		if(rtag->tag_filepath.tsize      ) { sys_mem_free(rtag->tag_filepath.tdata      ); rtag->tag_filepath.tsize      = 0; }
		if(rtag->tag_filename.tsize      ) { sys_mem_free(rtag->tag_filename.tdata      ); rtag->tag_filename.tsize      = 0; }
		if(rtag->tag_comments.tsize      ) { sys_mem_free(rtag->tag_comments.tdata      ); rtag->tag_comments.tsize      = 0; }
		if(rtag->tag_lyric.tsize         ) { sys_mem_free(rtag->tag_lyric.tdata         ); rtag->tag_lyric.tsize         = 0; }
		if(rtag->tag_bpm.tsize           ) { sys_mem_free(rtag->tag_bpm.tdata           ); rtag->tag_bpm.tsize           = 0; }
		if(rtag->tag_tracknum.tsize      ) { sys_mem_free(rtag->tag_tracknum.tdata      ); rtag->tag_tracknum.tsize      = 0; }
		
		return 1;
	}

	rtag->tag_title.tsize         = 0;
	rtag->tag_album.tsize         = 0;
	rtag->tag_artist.tsize        = 0;
	rtag->tag_origartist.tsize    = 0;
	rtag->tag_composer.tsize      = 0;
	rtag->tag_lyricist.tsize      = 0;
	rtag->tag_band.tsize          = 0;
	rtag->tag_copyright.tsize     = 0;
	rtag->tag_publish.tsize       = 0;
	rtag->tag_encodedby.tsize     = 0;
	rtag->tag_genre.tsize         = 0;
	rtag->tag_year.tsize          = 0;
	rtag->tag_url.tsize           = 0;
	rtag->tag_offiartisturl.tsize = 0;
	rtag->tag_filepath.tsize      = 0;
	rtag->tag_filename.tsize      = 0;
	rtag->tag_comments.tsize      = 0;
	rtag->tag_lyric.tsize         = 0;
	rtag->tag_bpm.tsize           = 0;
	rtag->tag_tracknum.tsize      = 0;
	return 1;
}
Ejemplo n.º 9
0
int equalize_buffer_variable_uninit(void *eqd)
{
	sys_mem_free(eqd);
	return 1;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
uint64_t
sys_mem_used(void)
{
	return sys_mem_total() - sys_mem_free();
}
Ejemplo n.º 13
0
Archivo: misc.c Proyecto: hownam/fennec
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);
}
Ejemplo n.º 14
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;
}
Ejemplo n.º 15
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;
}