Exemple #1
0
void quicktime_read_stsd_audio(quicktime_t *file, 
	quicktime_stsd_table_t *table, 
	quicktime_atom_t *parent_atom)
{
	quicktime_atom_t leaf_atom;

	table->version = quicktime_read_int16(file);
	table->revision = quicktime_read_int16(file);
	quicktime_read_data(file, table->vendor, 4);
	table->channels = quicktime_read_int16(file);
	table->sample_size = quicktime_read_int16(file);
	table->compression_id = quicktime_read_int16(file);
	table->packet_size = quicktime_read_int16(file);
	table->sample_rate = quicktime_read_fixed32(file);

// Kluge for fixed32 limitation
if(table->sample_rate + 65536 == 96000 ||
	table->sample_rate + 65536 == 88200) table->sample_rate += 65536;


// Version 1 fields
	if(table->version > 0)
	{
		table->samples_per_packet = quicktime_read_int32(file);
		table->bytes_per_packet = quicktime_read_int32(file);
		table->bytes_per_frame = quicktime_read_int32(file);
		table->bytes_per_sample = quicktime_read_int32(file);

// Skip another 20 bytes
		if(table->version == 2)
		{
			quicktime_set_position(file, quicktime_position(file) + 0x14);
		}

		while(quicktime_position(file) < parent_atom->end)
		{
			quicktime_atom_read_header(file, &leaf_atom);

			if(quicktime_atom_is(&leaf_atom, "wave"))
			{
				read_wave(file, table, &leaf_atom);
			}
			else
			{
				quicktime_atom_skip(file, &leaf_atom);
			}
		}
	}

// FFMPEG says the esds sometimes contains a sample rate that overrides
// the sample table.
	quicktime_esds_samplerate(table, &table->esds);
}
Exemple #2
0
int main(int argc, char *argv[])
{
	int	out;
	const int bit=9;

	char in_name[MAX_STR_LNGTH], out_name[MAX_STR_LNGTH];
	short *wave;
	short *new_wave;

	unsigned int freq_in, bits_in;
	unsigned int n_wave;
	unsigned int i;
	FILE *prt; 

	struct Waveheader header;


	if ( (argc != 3) && (argc != 5) )
	{
		fprintf(stderr, "Usage: %s -i infile [-o outfile]\n", argv[0]);
		exit(1);
	}
	else
	{
		strcpy(in_name, argv[2]);
		out=0;
		out_name[0]='\0';

		if (argc == 5)
		{
			strcpy(out_name, argv[4]);
			out=1;
		}
	}

	fprintf(stderr,"infile: %s outfile: %s\n", in_name, out_name);


	read_wave(&wave, &n_wave, &freq_in, &bits_in, in_name, &header);

	// --------- 2.1 output curve to ascii file --------------
	
	/*prt = fopen ("prt.txt","wt"); 

	for(i=0 ; i<n_wave;i++){ 
		fprintf(prt,"%i \n",wave[i]); 
	} 
	fclose(prt); */

	// -------- 2.1 output curve to ascii file end ----------

	// -------------- 2.4 downsampling ----------------------
	
	/*for (i=0; i < n_wave / 2; i++){
		wave[i] = wave[i*2];
	}
	freq_in /= 2;
	n_wave /= 2;*/

	// -------------- 2.4 downsampling end ------------------

	// --------------3.2 bit reduction ----------------------

	/*for (i =0; i < n_wave; i++){
		wave[i] /= 512;
		wave[i] *= 512;
	}*/
	// -------------- 3.2 bit reduction end -----------------

	// -------------- 3.4 difference signal ------------------

	new_wave = (short*)malloc(n_wave*sizeof(short));

	for(i=0; i<n_wave; i++){
		new_wave[i] = wave[i];
		wave[i] /= pow(2.0,bit);
		wave[i] *= pow(2.0,bit);
		wave[i] -= new_wave[i];
		wave[i] *= pow(2.0, 16-bit-1);
	}

	// -------------- 3.4 difference signal end --------------

	if (out)
		write_wave(wave, n_wave, freq_in, bits_in, out_name, &header);

	free(wave);

	return(1);
}
void *complete_encode_worker(void* arg)
{
	int ret;
	ENC_WRK_ARGS *args = (ENC_WRK_ARGS*)arg; // parse argument struct

	while (true) {
#ifdef __VERBOSE_
		cout << "Checking for work\n";
#endif
		// determine which file to process next
		bool bFoundWork = false;
		int iFileIdx = -1;

		pthread_mutex_lock(&mutFilesFinished);
		for (int i = 0; i < args->iNumFiles; i++) {
			if (!args->pbFilesFinished[i]) {
				args->pbFilesFinished[i] = true; // mark as being worked on
				iFileIdx = i;
				bFoundWork = true;
				break;
			}
		}
		pthread_mutex_unlock(&mutFilesFinished);

		if (!bFoundWork) {// done yet?
			return NULL; // break
		}
		string sMyFile = args->pFilenames->at(iFileIdx);
		string sMyFileOut = sMyFile.substr(0, sMyFile.length() - 3) + "mp3";

		// start working
		FMT_DATA *hdr = NULL;
		short *leftPcm = NULL, *rightPcm = NULL;
		// init encoding params
		lame_global_flags *gfp = lame_init();
		lame_set_brate(gfp, 192); // increase bitrate
		lame_set_quality(gfp, 3); // increase quality level
		lame_set_bWriteVbrTag(gfp, 0);

		// parse wave file
#ifdef __VERBOSE_
		printf("Parsing %s ...\n", sMyFile.c_str());
#endif
		int iDataSize = -1;
		ret = read_wave(sMyFile.c_str(), hdr, leftPcm, rightPcm, iDataSize);
		if (ret != EXIT_SUCCESS) {
			printf("Error in file %s. Skipping.\n", sMyFile.c_str());
			continue; // see if there's more to do
		}

		lame_set_num_channels(gfp, hdr->wChannels);
		lame_set_num_samples(gfp, iDataSize / hdr->wBlockAlign);
		// check params
		ret = lame_init_params(gfp);
		if (ret != 0) {
			cerr << "Invalid encoding parameters! Skipping file." << endl;
			continue;
		}

		// encode to mp3
		ret = encode_to_file(gfp, hdr, leftPcm, rightPcm, iDataSize, sMyFileOut.c_str());
		if (ret != EXIT_SUCCESS) {
			cerr << "Unable to encode mp3: " << sMyFileOut.c_str() << endl;
			continue;
		}

		printf("[:%i][ok] .... %s\n", args->iThreadId, sMyFile.c_str());
		++args->iProcessedFiles;

		lame_close(gfp);
		if (leftPcm != NULL) delete[] leftPcm;
		if (rightPcm != NULL) delete[] rightPcm;
		if (hdr != NULL) delete hdr;
	}

	pthread_exit((void*)0);
}