static track_t *track_create(const char *path, AVFormatContext *avctx, int track_index) { track_t *track; char *tmp; /*av_dump_format(avctx, 0, NULL, 0);*/ /* For each metadata first try container-level metadata. If no value is * found, try stream-specific metadata. */ track = track_new(); track->file = strcopy(path); track->title = copy_metadata(avctx, "title") ? : copy_metadata(avctx, "song"); if (!track->title) { /* No title in metadata, use plain filename (no basename, it's crap). */ for (tmp = (char *)path + strlen(path); tmp > path && *(tmp - 1) != '/'; --tmp) { } track->title = strcopy(tmp); } track->trackindex = track_index; tmp = get_metadata(avctx, "track"); if (tmp) { sscanf(tmp, "%d", &track->track); } else { track->track = track_index; } track->artist = copy_metadata(avctx, "artist") ? : copy_metadata(avctx, "author"); track->album = copy_metadata(avctx, "album") ? : copy_metadata(avctx, "game"); track->albumartist = copy_metadata(avctx, "albumartist"); if (avctx->duration > 0) { track->duration = avctx->duration / (double)AV_TIME_BASE; } else { track->duration = avctx->streams[0]->duration * av_q2d(avctx->streams[0]->time_base); } if (track->duration <= 0) { track_free(track); track = NULL; } return track; }
Mesh::Ptr from_draco_point_cloud(std::unique_ptr<draco::PointCloud> draco_pc) { assert(draco_pc); size_t dim; VectorF vertices = extract_vertices(draco_pc, dim); VectorI faces; VectorI voxels; auto mesh = MeshFactory().load_data(vertices, faces, voxels, dim, 3, 4).create(); copy_metadata(draco_pc, mesh); return mesh; }
/*! Creates a duplicate of the \a buffer. The new buffer does not share internal storage; they are completely independent from each other. */ static net_buffer * duplicate_buffer(net_buffer *_buffer) { net_buffer_private *buffer = (net_buffer_private *)_buffer; net_buffer* duplicate = create_buffer(0); if (duplicate == NULL) return NULL; if (append_data(duplicate, buffer->data, buffer->size) != B_OK) { free_buffer(duplicate); return NULL; } copy_metadata(duplicate, buffer); return duplicate; }
int main (int argc, char * argv []) { char *progname, *infilename, *outfilename ; SNDFILE *infile = NULL, *outfile = NULL ; SF_INFO sfinfo ; int k, outfilemajor, outfileminor = 0, infileminor ; progname = strrchr (argv [0], '/') ; progname = progname ? progname + 1 : argv [0] ; if (argc < 3 || argc > 5) { print_usage (progname) ; return 1 ; } ; infilename = argv [argc-2] ; outfilename = argv [argc-1] ; if (strcmp (infilename, outfilename) == 0) { printf ("Error : Input and output filenames are the same.\n\n") ; print_usage (progname) ; return 1 ; } ; if (infilename [0] == '-') { printf ("Error : Input filename (%s) looks like an option.\n\n", infilename) ; print_usage (progname) ; return 1 ; } ; if (outfilename [0] == '-') { printf ("Error : Output filename (%s) looks like an option.\n\n", outfilename) ; print_usage (progname) ; return 1 ; } ; for (k = 1 ; k < argc - 2 ; k++) { if (! strcmp (argv [k], "-pcms8")) { outfileminor = SF_FORMAT_PCM_S8 ; continue ; } ; if (! strcmp (argv [k], "-pcmu8")) { outfileminor = SF_FORMAT_PCM_U8 ; continue ; } ; if (! strcmp (argv [k], "-pcm16")) { outfileminor = SF_FORMAT_PCM_16 ; continue ; } ; if (! strcmp (argv [k], "-pcm24")) { outfileminor = SF_FORMAT_PCM_24 ; continue ; } ; if (! strcmp (argv [k], "-pcm32")) { outfileminor = SF_FORMAT_PCM_32 ; continue ; } ; if (! strcmp (argv [k], "-float32")) { outfileminor = SF_FORMAT_FLOAT ; continue ; } ; if (! strcmp (argv [k], "-ulaw")) { outfileminor = SF_FORMAT_ULAW ; continue ; } ; if (! strcmp (argv [k], "-alaw")) { outfileminor = SF_FORMAT_ALAW ; continue ; } ; if (! strcmp (argv [k], "-ima-adpcm")) { outfileminor = SF_FORMAT_IMA_ADPCM ; continue ; } ; if (! strcmp (argv [k], "-ms-adpcm")) { outfileminor = SF_FORMAT_MS_ADPCM ; continue ; } ; if (! strcmp (argv [k], "-gsm610")) { outfileminor = SF_FORMAT_GSM610 ; continue ; } ; if (! strcmp (argv [k], "-dwvw12")) { outfileminor = SF_FORMAT_DWVW_12 ; continue ; } ; if (! strcmp (argv [k], "-dwvw16")) { outfileminor = SF_FORMAT_DWVW_16 ; continue ; } ; if (! strcmp (argv [k], "-dwvw24")) { outfileminor = SF_FORMAT_DWVW_24 ; continue ; } ; printf ("Error : Not able to decode argunment '%s'.\n", argv [k]) ; exit (1) ; } ; if ((infile = sf_open (infilename, SFM_READ, &sfinfo)) == NULL) { printf ("Not able to open input file %s.\n", infilename) ; puts (sf_strerror (NULL)) ; return 1 ; } ; infileminor = sfinfo.format & SF_FORMAT_SUBMASK ; if ((sfinfo.format = guess_output_file_type (outfilename, sfinfo.format)) == 0) { printf ("Error : Not able to determine output file type for %s.\n", outfilename) ; return 1 ; } ; outfilemajor = sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_ENDMASK) ; if (outfileminor == 0) outfileminor = sfinfo.format & SF_FORMAT_SUBMASK ; if (outfileminor != 0) sfinfo.format = outfilemajor | outfileminor ; else sfinfo.format = outfilemajor | (sfinfo.format & SF_FORMAT_SUBMASK) ; if ((sfinfo.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_XI) switch (sfinfo.format & SF_FORMAT_SUBMASK) { case SF_FORMAT_PCM_16 : sfinfo.format = outfilemajor | SF_FORMAT_DPCM_16 ; break ; case SF_FORMAT_PCM_S8 : case SF_FORMAT_PCM_U8 : sfinfo.format = outfilemajor | SF_FORMAT_DPCM_8 ; break ; } ; if (sf_format_check (&sfinfo) == 0) { printf ("Error : output file format is invalid (0x%08X).\n", sfinfo.format) ; return 1 ; } ; /* Open the output file. */ if ((outfile = sf_open (outfilename, SFM_WRITE, &sfinfo)) == NULL) { printf ("Not able to open output file %s : %s\n", outfilename, sf_strerror (NULL)) ; return 1 ; } ; /* Copy the metadata */ copy_metadata (outfile, infile) ; if ((outfileminor == SF_FORMAT_DOUBLE) || (outfileminor == SF_FORMAT_FLOAT) || (infileminor == SF_FORMAT_DOUBLE) || (infileminor == SF_FORMAT_FLOAT)) copy_data_fp (outfile, infile, sfinfo.channels) ; else copy_data_int (outfile, infile, sfinfo.channels) ; sf_close (infile) ; sf_close (outfile) ; return 0 ; } /* main */
/** * * @param orig * @param dest * @return */ int Transcode::transcode(string orig, string dest, TID3Tags *tags) { AVFormatContext *input_format_context = NULL, *output_format_context = NULL; AVCodecContext *input_codec_context = NULL, *output_codec_context = NULL; SwrContext *resample_context = NULL; AVAudioFifo *fifo = NULL; int ret = AVERROR_EXIT; this->pts = 0; if (orig.empty() || dest.empty()) { fprintf(stderr, "Files to process not especified\n"); return ret; } /* Register all codecs and formats so that they can be used. */ av_register_all(); /* Open the input file for reading. */ if (open_input_file(orig.c_str(), &input_format_context, &input_codec_context)) goto cleanup; /* Open the output file for writing. */ if (open_output_file(dest.c_str(), input_codec_context, &output_format_context, &output_codec_context)) goto cleanup; /**Copy the metadata if exist*/ copy_metadata(input_format_context, output_format_context, tags); /* Initialize the resampler to be able to convert audio sample formats. */ if (init_resampler(input_codec_context, output_codec_context, &resample_context)) goto cleanup; /* Initialize the FIFO buffer to store audio samples to be encoded. */ if (init_fifo(&fifo, output_codec_context)) goto cleanup; /* Write the header of the output file container. */ if (write_output_file_header(output_format_context)) goto cleanup; /* Loop as long as we have input samples to read or output samples * to write; abort as soon as we have neither. */ while (1) { /* Use the encoder's desired frame size for processing. */ const int output_frame_size = output_codec_context->frame_size; int finished = 0; /* Make sure that there is one frame worth of samples in the FIFO * buffer so that the encoder can do its work. * Since the decoder's and the encoder's frame size may differ, we * need to FIFO buffer to store as many frames worth of input samples * that they make up at least one frame worth of output samples. */ while (av_audio_fifo_size(fifo) < output_frame_size) { /* Decode one frame worth of audio samples, convert it to the * output sample format and put it into the FIFO buffer. */ if (read_decode_convert_and_store(fifo, input_format_context, input_codec_context, output_codec_context, resample_context, &finished)) goto cleanup; /* If we are at the end of the input file, we continue * encoding the remaining audio samples to the output file. */ if (finished) break; } /* If we have enough samples for the encoder, we encode them. * At the end of the file, we pass the remaining samples to * the encoder. */ while (av_audio_fifo_size(fifo) >= output_frame_size || (finished && av_audio_fifo_size(fifo) > 0)) /* Take one frame worth of audio samples from the FIFO buffer, * encode it and write it to the output file. */ if (load_encode_and_write(fifo, output_format_context, output_codec_context)) goto cleanup; /* If we are at the end of the input file and have encoded * all remaining samples, we can exit this loop and finish. */ if (finished) { int data_written; /* Flush the encoder as it may have delayed frames. */ do { if (encode_audio_frame(NULL, output_format_context, output_codec_context, &data_written)) goto cleanup; } while (data_written); break; } } /* Write the trailer of the output file container. */ if (write_output_file_trailer(output_format_context)) goto cleanup; ret = 0; cleanup: if (fifo) av_audio_fifo_free(fifo); swr_free(&resample_context); if (output_codec_context) avcodec_free_context(&output_codec_context); if (output_format_context) { avio_closep(&output_format_context->pb); avformat_free_context(output_format_context); } if (input_codec_context) avcodec_free_context(&input_codec_context); if (input_format_context) avformat_close_input(&input_format_context); return ret; }
int main (int argc, char * argv []) { const char *progname, *infilename, *outfilename ; SNDFILE *infile = NULL, *outfile = NULL ; SF_INFO sfinfo ; int k, outfilemajor, outfileminor = 0, infileminor ; int override_sample_rate = 0 ; /* assume no sample rate override. */ progname = program_name (argv [0]) ; if (argc < 3 || argc > 5) { usage_exit (progname) ; return 1 ; } ; infilename = argv [argc-2] ; outfilename = argv [argc-1] ; if (strcmp (infilename, outfilename) == 0) { printf ("Error : Input and output filenames are the same.\n\n") ; usage_exit (progname) ; return 1 ; } ; if (strlen (infilename) > 1 && infilename [0] == '-') { printf ("Error : Input filename (%s) looks like an option.\n\n", infilename) ; usage_exit (progname) ; return 1 ; } ; if (outfilename [0] == '-') { printf ("Error : Output filename (%s) looks like an option.\n\n", outfilename) ; usage_exit (progname) ; return 1 ; } ; for (k = 1 ; k < argc - 2 ; k++) { if (! strcmp (argv [k], "-pcms8")) { outfileminor = SF_FORMAT_PCM_S8 ; continue ; } ; if (! strcmp (argv [k], "-pcmu8")) { outfileminor = SF_FORMAT_PCM_U8 ; continue ; } ; if (! strcmp (argv [k], "-pcm16")) { outfileminor = SF_FORMAT_PCM_16 ; continue ; } ; if (! strcmp (argv [k], "-pcm24")) { outfileminor = SF_FORMAT_PCM_24 ; continue ; } ; if (! strcmp (argv [k], "-pcm32")) { outfileminor = SF_FORMAT_PCM_32 ; continue ; } ; if (! strcmp (argv [k], "-float32")) { outfileminor = SF_FORMAT_FLOAT ; continue ; } ; if (! strcmp (argv [k], "-ulaw")) { outfileminor = SF_FORMAT_ULAW ; continue ; } ; if (! strcmp (argv [k], "-alaw")) { outfileminor = SF_FORMAT_ALAW ; continue ; } ; if (! strcmp (argv [k], "-ima-adpcm")) { outfileminor = SF_FORMAT_IMA_ADPCM ; continue ; } ; if (! strcmp (argv [k], "-ms-adpcm")) { outfileminor = SF_FORMAT_MS_ADPCM ; continue ; } ; if (! strcmp (argv [k], "-gsm610")) { outfileminor = SF_FORMAT_GSM610 ; continue ; } ; if (! strcmp (argv [k], "-dwvw12")) { outfileminor = SF_FORMAT_DWVW_12 ; continue ; } ; if (! strcmp (argv [k], "-dwvw16")) { outfileminor = SF_FORMAT_DWVW_16 ; continue ; } ; if (! strcmp (argv [k], "-dwvw24")) { outfileminor = SF_FORMAT_DWVW_24 ; continue ; } ; if (! strcmp (argv [k], "-vorbis")) { outfileminor = SF_FORMAT_VORBIS ; continue ; } ; if (strstr (argv [k], "-override-sample-rate=") == argv [k]) { const char *ptr ; ptr = argv [k] + strlen ("-override-sample-rate=") ; override_sample_rate = atoi (ptr) ; continue ; } ; printf ("Error : Not able to decode argunment '%s'.\n", argv [k]) ; exit (1) ; } ; memset (&sfinfo, 0, sizeof (sfinfo)) ; if ((infile = sf_open (infilename, SFM_READ, &sfinfo)) == NULL) { printf ("Not able to open input file %s.\n", infilename) ; puts (sf_strerror (NULL)) ; return 1 ; } ; /* Update sample rate if forced to something else. */ if (override_sample_rate) sfinfo.samplerate = override_sample_rate ; infileminor = sfinfo.format & SF_FORMAT_SUBMASK ; if ((sfinfo.format = sfe_file_type_of_ext (outfilename, sfinfo.format)) == 0) { printf ("Error : Not able to determine output file type for %s.\n", outfilename) ; return 1 ; } ; outfilemajor = sfinfo.format & (SF_FORMAT_TYPEMASK | SF_FORMAT_ENDMASK) ; if (outfileminor == 0) outfileminor = sfinfo.format & SF_FORMAT_SUBMASK ; if (outfileminor != 0) sfinfo.format = outfilemajor | outfileminor ; else sfinfo.format = outfilemajor | (sfinfo.format & SF_FORMAT_SUBMASK) ; if ((sfinfo.format & SF_FORMAT_TYPEMASK) == SF_FORMAT_XI) switch (sfinfo.format & SF_FORMAT_SUBMASK) { case SF_FORMAT_PCM_16 : sfinfo.format = outfilemajor | SF_FORMAT_DPCM_16 ; break ; case SF_FORMAT_PCM_S8 : case SF_FORMAT_PCM_U8 : sfinfo.format = outfilemajor | SF_FORMAT_DPCM_8 ; break ; } ; if (sf_format_check (&sfinfo) == 0) { printf ("Error : output file format is invalid (0x%08X).\n", sfinfo.format) ; return 1 ; } ; /* Open the output file. */ if ((outfile = sf_open (outfilename, SFM_WRITE, &sfinfo)) == NULL) { printf ("Not able to open output file %s : %s\n", outfilename, sf_strerror (NULL)) ; return 1 ; } ; /* Copy the metadata */ copy_metadata (outfile, infile, sfinfo.channels) ; if ((outfileminor == SF_FORMAT_DOUBLE) || (outfileminor == SF_FORMAT_FLOAT) || (infileminor == SF_FORMAT_DOUBLE) || (infileminor == SF_FORMAT_FLOAT) || (infileminor == SF_FORMAT_VORBIS) || (outfileminor == SF_FORMAT_VORBIS)) sfe_copy_data_fp (outfile, infile, sfinfo.channels) ; else sfe_copy_data_int (outfile, infile, sfinfo.channels) ; sf_close (infile) ; sf_close (outfile) ; return 0 ; } /* main */
bool transposition_based_synthesis( circuit& circ, const binary_truth_table& spec, properties::ptr settings, properties::ptr statistics ) { // Settings parsing // Run-time measuring timer<properties_timer> t; if ( statistics ) { properties_timer rt( statistics ); t.start( rt ); } unsigned bw = spec.num_outputs(); circ.set_lines( bw ); copy_metadata( spec, circ ); std::map<unsigned, unsigned> values_map; for ( binary_truth_table::const_iterator it = spec.begin(); it != spec.end(); ++it ) { binary_truth_table::cube_type in( it->first.first, it->first.second ); binary_truth_table::cube_type out( it->second.first, it->second.second ); values_map.insert( std::make_pair( truth_table_cube_to_number( in ), truth_table_cube_to_number( out ) ) ); } // Set of cycles std::vector<std::vector<unsigned> > cycles; while ( !values_map.empty() ) { unsigned start_value = values_map.begin()->first; // first key in values_map std::vector<unsigned> cycle; unsigned target = start_value; do { cycle += target; unsigned old_target = target; target = values_map[target]; values_map.erase( old_target ); // erase this entry } while ( target != start_value ); cycles += cycle; } for ( auto& cycle : cycles ) { unsigned max_distance = 0u; unsigned max_index = 0u; for ( unsigned i = 0u; i < cycle.size(); ++i ) { unsigned first = cycle.at(i); unsigned second = cycle.at( (i + 1u) % cycle.size() ); unsigned distance = hamming_distance( first, second ); if ( distance > max_distance ) { max_distance = distance; max_index = i; } } std::vector<unsigned> tmp; std::copy( cycle.begin() + ( max_index + 1u ), cycle.end(), std::back_inserter( tmp ) ); std::copy( cycle.begin(), cycle.begin() + ( max_index + 1u ), std::back_inserter( tmp ) ); std::copy( tmp.begin(), tmp.end(), cycle.begin() ); std::reverse( cycle.begin(), cycle.end() ); } // TODO create transpositions function for ( auto& cycle : cycles ) { for ( unsigned i = 0u; i < cycle.size() - 1; ++i ) { circuit transposition_circ( spec.num_inputs() ); unsigned first = cycle.at(i); unsigned second = cycle.at( (i + 1) % cycle.size() ); boost::dynamic_bitset<> first_bits( spec.num_inputs(), first ); boost::dynamic_bitset<> second_bits( spec.num_inputs(), second ); transposition_to_circuit( transposition_circ, first_bits, second_bits ); append_circuit( circ, transposition_circ); } } return true; }