int cmd_listall(int argc, char **argv, struct mpd_connection *conn) { const char * listall = ""; int i = 0; if (argc > 0) listall = charset_to_utf8(argv[i]); do { char *tmp = strdup(listall); strip_trailing_slash(tmp); if (options.custom_format) { if (!mpd_send_list_all_meta(conn, tmp)) printErrorAndExit(conn); print_entity_list(conn, MPD_ENTITY_TYPE_UNKNOWN); } else { if (!mpd_send_list_all(conn, tmp)) printErrorAndExit(conn); print_filenames(conn); } my_finishCommand(conn); free(tmp); } while (++i < argc && (listall = charset_to_utf8(argv[i])) != NULL); return 0; }
static int do_search ( int argc, char ** argv, mpd_Connection * conn, int exact ) { Constraint *constraints; int numconstraints; int i; if (argc % 2 != 0) DIE("arguments must be pairs of search types and queries\n"); numconstraints = get_constraints(argc, argv, &constraints); if (numconstraints < 0) return -1; mpd_startSearch(conn, exact); for (i = 0; i < numconstraints; i++) { mpd_addConstraintSearch(conn, constraints[i].type, charset_to_utf8(constraints[i].query)); } free(constraints); mpd_commitSearch(conn); printErrorAndExit(conn); print_filenames(conn); my_finishCommand(conn); return 0; }
static int do_search ( int argc, char ** argv, struct mpd_connection *conn, int exact ) { mpd_search_db_songs(conn, exact); if (!add_constraints(argc, argv, conn)) return -1; if (!mpd_search_commit(conn)) printErrorAndExit(conn); print_filenames(conn); my_finishCommand(conn); return 0; }
int cmd_listall ( int argc, char ** argv, mpd_Connection * conn ) { const char * listall = ""; int i=0; if (argc > 0) listall = charset_to_utf8(argv[i]); do { mpd_sendListallCommand(conn,listall); printErrorAndExit(conn); print_filenames(conn); my_finishCommand(conn); } while (++i < argc && (listall = charset_to_utf8(argv[i])) != NULL); return 0; }
int main (int argc, char **argv) { set_program_name (argv[0]); idh.idh_file_name = 0; #if ENABLE_NLS /* Set locale according to user's wishes. */ setlocale (LC_ALL, ""); /* Tell program which translations to use and where to find. */ bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); #endif atexit (close_stdout); for (;;) { int optc = getopt_long (argc, argv, "f:S:", long_options, (int *) 0); if (optc < 0) break; switch (optc) { case 0: break; case 'f': idh.idh_file_name = optarg; break; case 'S': separator_style = parse_separator_style (optarg); break; default: usage (); } } if (show_version) { printf ("%s - %s\n", program_name, PACKAGE_VERSION); exit (EXIT_SUCCESS); } if (show_help) help_me (); if (separator_style == ss_contextual) { if (isatty (STDOUT_FILENO)) separator_style = DEFAULT_SEPARATOR_STYLE; else separator_style = ss_newline; } argc -= optind; argv += optind; if (argc == 0) { static char star[] = "*"; static char *starp = star; argc = 1; argv = &starp; } /* Look for the ID database up the tree */ idh.idh_file_name = locate_id_file_name (idh.idh_file_name); if (idh.idh_file_name == 0) error (EXIT_FAILURE, errno, _("can't locate `ID'")); init_idh_obstacks (&idh); init_idh_tables (&idh); cw_dlink = get_current_dir_link (); { struct file_link **members = read_id_file (idh.idh_file_name, &idh); struct file_link **members_N = &members[idh.idh_files]; struct file_link **flinkv_0 = xmalloc (sizeof(struct file_link *) * (idh.idh_files + 1)); struct file_link **flinkv = flinkv_0; char **patv_0 = xmalloc (sizeof(char *) * (argc * 2)); char **patv_N; char **patv = patv_0; char *file_name = alloca (PATH_MAX); for ( ; argc; argc--, argv++) { char *arg = *argv; *patv++ = arg; if (*arg != '*' && *arg != '/') { char *pat = xmalloc (strlen (arg) + 2); sprintf (pat, "*/%s", arg); *patv++ = pat; } } patv_N = patv; for ( ; members < members_N; members++) { maybe_relative_file_name (file_name, *members, cw_dlink); for (patv = patv_0; patv < patv_N; patv++) { if (fnmatch (*patv, file_name, MAYBE_FNM_CASEFOLD) == 0) { *flinkv++ = *members; break; } } } *flinkv = 0; print_filenames (flinkv_0, separator_style); } return 0; }
int main(int argc, char **argv) { twolame_options *encopts = NULL; audioin_t *inputfile = NULL; FILE *outputfile = NULL; short int *pcmaudio = NULL; unsigned int frame_count = 0; unsigned int total_frames = 0; unsigned int frame_len = 0; unsigned int total_bytes = 0; unsigned char *mp2buffer = NULL; int samples_read = 0; int mp2fill_size = 0; int audioReadSize = 0; // Allocate memory for the PCM audio data if ((pcmaudio = (short int *) calloc(AUDIO_BUF_SIZE, sizeof(short int))) == NULL) { fprintf(stderr, "Error: pcmaudio memory allocation failed\n"); exit(ERR_MEM_ALLOC); } // Allocate memory for the encoded MP2 audio data if ((mp2buffer = (unsigned char *) calloc(MP2_BUF_SIZE, sizeof(unsigned char))) == NULL) { fprintf(stderr, "Error: mp2buffer memory allocation failed\n"); exit(ERR_MEM_ALLOC); } // Initialise Encoder Options Structure encopts = twolame_init(); if (encopts == NULL) { fprintf(stderr, "Error: initializing libtwolame encoder failed.\n"); exit(ERR_MEM_ALLOC); } // Get options and parameters from the command line parse_args(argc, argv, encopts); // Display the filenames print_filenames(twolame_get_verbosity(encopts)); // Open the input file if (use_raw) { // use raw input handler inputfile = open_audioin_raw(inputfilename, &sfinfo, sample_size); } else { // use libsndfile inputfile = open_audioin_sndfile(inputfilename, &sfinfo); } // Display input information if (twolame_get_verbosity(encopts) > 1) { inputfile->print_info(inputfile); } // Use information from input file to configure libtwolame twolame_set_num_channels(encopts, sfinfo.channels); twolame_set_in_samplerate(encopts, sfinfo.samplerate); // Open the output file outputfile = open_output_file(outputfilename); // initialise twolame with this set of options if (twolame_init_params(encopts) != 0) { fprintf(stderr, "Error: configuring libtwolame encoder failed.\n"); exit(ERR_INVALID_PARAM); } // display encoder settings twolame_print_config(encopts); // Only encode a single frame of mpeg audio ? if (single_frame_mode) audioReadSize = TWOLAME_SAMPLES_PER_FRAME; else audioReadSize = AUDIO_BUF_SIZE; // Calculate the size and number of frames we are going to encode frame_len = twolame_get_framelength(encopts); if (sfinfo.frames) total_frames = sfinfo.frames / TWOLAME_SAMPLES_PER_FRAME; // Now do the reading/encoding/writing while ((samples_read = inputfile->read(inputfile, pcmaudio, audioReadSize)) > 0) { int bytes_out = 0; // Force byte swapping if requested if (byteswap) { int i; for (i = 0; i < samples_read; i++) { short tmp = pcmaudio[i]; char *src = (char *) &tmp; char *dst = (char *) &pcmaudio[i]; dst[0] = src[1]; dst[1] = src[0]; } } // Calculate the number of samples we have (per channel) samples_read /= sfinfo.channels; // Do swapping of left and right channels if requested if (channelswap && sfinfo.channels == 2) { int i; for (i = 0; i < samples_read; i++) { short tmp = pcmaudio[(2 * i)]; pcmaudio[(2 * i)] = pcmaudio[(2 * i) + 1]; pcmaudio[(2 * i) + 1] = tmp; } } // Encode the audio to MP2 mp2fill_size = twolame_encode_buffer_interleaved(encopts, pcmaudio, samples_read, mp2buffer, MP2_BUF_SIZE); // Stop if we don't have any bytes (probably don't have enough audio for a full frame of // mpeg audio) if (mp2fill_size == 0) break; if (mp2fill_size < 0) { fprintf(stderr, "error while encoding audio: %d\n", mp2fill_size); exit(ERR_ENCODING); } // Check that a whole number of frame was written // if (mp2fill_size % frame_len != 0) { // fprintf(stderr,"error while encoding audio: non-whole number of frames written\n"); // exit(ERR_ENCODING); // } // Write the encoded audio out bytes_out = fwrite(mp2buffer, sizeof(unsigned char), mp2fill_size, outputfile); if (bytes_out != mp2fill_size) { perror("error while writing to output file"); exit(ERR_WRITING_OUTPUT); } total_bytes += bytes_out; // Only single frame ? if (single_frame_mode) break; // Display Progress frame_count += (mp2fill_size / frame_len); if (twolame_get_verbosity(encopts) > 0) { fprintf(stderr, "\rEncoding frame: %i", frame_count); if (total_frames) { fprintf(stderr, "/%i (%i%%)", total_frames, (frame_count * 100) / total_frames); } fflush(stderr); } } // Was there an error reading the audio? if (inputfile->error_str(inputfile)) { fprintf(stderr, "Error reading from input file: %s\n", inputfile->error_str(inputfile)); } // // flush any remaining audio. (don't send any new audio data) There // should only ever be a max of 1 frame on a flush. There may be zero // frames if the audio data was an exact multiple of 1152 // mp2fill_size = twolame_encode_flush(encopts, mp2buffer, MP2_BUF_SIZE); if (mp2fill_size > 0) { int bytes_out = fwrite(mp2buffer, sizeof(unsigned char), mp2fill_size, outputfile); frame_count++; if (bytes_out <= 0) { perror("error while writing to output file"); exit(ERR_WRITING_OUTPUT); } total_bytes += bytes_out; } if (twolame_get_verbosity(encopts) > 1) { char *filesize = format_filesize_string(total_bytes); fprintf(stderr, "\nEncoding Finished.\n"); fprintf(stderr, "Total bytes written: %s.\n", filesize); free(filesize); } // Close input and output streams inputfile->close(inputfile); fclose(outputfile); // Close the libtwolame encoder twolame_close(&encopts); // Free up memory free(pcmaudio); free(mp2buffer); return (ERR_NO_ERROR); }