1 /* wavbreaker - A tool to split a wave file up into multiple wave.
2  * Copyright (C) 2002-2006 Timothy Robinson
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18 
19 #include <config.h>
20 
21 #include <stdio.h>
22 #include <string.h>
23 #include <sys/stat.h>
24 
25 #include "sample.h"
26 #include "wav.h"
27 
usage()28 void usage() {
29     printf("Must pass filenames of wave files to merge.\n");
30     printf("Usage: wavmerge [-o outfile] mergefiles...\n");
31 }
32 
main(int argc,char * argv[])33 int main(int argc, char *argv[])
34 {
35     int ret;
36     char *merge_filename;
37     int num_files;
38     char **filenames;
39 
40     if (argc > 1 && strcmp(argv[1], "-o") == 0) {
41         if (argc < 5) {
42             usage();
43             return 1;
44         }
45         merge_filename = g_strdup(argv[2]);
46         num_files = argc - 3;
47         filenames = &argv[3];
48     } else {
49         if (argc < 3) {
50             usage();
51             return 1;
52         }
53         merge_filename = g_strdup("merged.wav");
54         num_files = argc - 1;
55         filenames = &argv[1];
56     }
57 
58     if (g_file_test(merge_filename, G_FILE_TEST_EXISTS)) {
59         fprintf(stderr, "ERROR: The output file %s already exists.\n", merge_filename);
60         return 2;
61     }
62 
63     ret = wav_merge_files(merge_filename, num_files, filenames, DEFAULT_BUF_SIZE, NULL);
64 
65     if (ret != 0) {
66         fprintf(stderr,
67 "ERROR: The files are not of the same format.\n\n"
68 "This means that the sample rate, bits per sample, etc. are different.\n"
69 "Please use a tool, like sox, to convert the files to the same format and\n"
70 "try again.\n"
71 );
72         return 1;
73     }
74 
75     g_free(merge_filename);
76 
77     return 0;
78 }
79 
80