15 using namespace Nsound;
27 f_in = std::fopen(filename.c_str(),
"r");
43 <<
"usage: ns_vocoder OPTIONS voice_wave carrier_wave output_wave" << endl
45 <<
"Options are:" << endl
47 <<
" -h|--help Prints this message" << endl
48 <<
" -v|--verbose Verbose" << endl
49 <<
" -n|--bands N The number of frequency bands to use" << endl
50 <<
" -w|--window S The window duration in seconds for calculating the envelope" << endl
51 <<
" -m|--fmax F The maximum frequency in the filter bank" << endl
57 main(
int argc,
char ** argv)
65 std::vector<std::string> args;
67 for(
int32 i = 1; i < argc; ++i)
69 args.push_back(argv[i]);
73 uint32 specific_n_bands = 0;
76 boolean verbose =
false;
78 std::vector<std::string>::iterator itor;
79 std::vector<std::string>::iterator end;
80 std::vector<std::string> files;
82 for(itor = args.begin(), end = args.end();
86 if(*itor ==
"-h" || *itor ==
"--help")
91 if(*itor ==
"-m" || *itor ==
"--fmax")
93 std::stringstream ss(*(itor + 1));
98 if(*itor ==
"-n" || *itor ==
"--bands")
100 std::stringstream ss(*(itor + 1));
101 ss >> specific_n_bands;
105 if(*itor ==
"-w" || *itor ==
"--window")
107 std::stringstream ss(*(itor + 1));
108 ss >> specific_window;
112 if(*itor ==
"-v" || *itor ==
"--verbose")
118 files.push_back(*itor);
122 if(files.size() != 3)
124 cerr <<
"Wrong number of arguments!\n";
128 std::string voice_file = files[0];
129 std::string carrier_file = files[1];
130 std::string output_file = files[2];
134 cerr <<
"ns_vocoder: can't find the file \"" << voice_file
142 cerr <<
"ns_vocoder: can't find the file \"" << voice_file
176 if(specific_window > 0)
178 window = specific_window;
181 if(specific_n_bands > 0)
183 n_bands = specific_n_bands;
186 if(specific_fmax > 0)
188 fmax = specific_fmax;
193 cout <<
"voice wav = " << voice_file << endl
194 <<
"carrier wav = " << carrier_file << endl
195 <<
"output wav = " << output_file << endl
196 <<
"n bands = " << n_bands << endl
197 <<
"window sec = " << window << endl
198 <<
"fmax = " << fmax << endl;
201 Vocoder vocoder(sr, window, n_bands, fmax);
218 temp << vocoder.
filter(*v, *c);
232 output >> output_file.c_str();
float64 getSampleRate() const
Returns the sample rate of the stream.
A circulator iterator for class Buffer.
boolean file_exists(const std::string filename)
uint32 getNChannels(void) const
Returns the number of audio channels in the stream.
void mono()
Collapses all channels into one Buffer making it mono.
void resample2(float64 new_sample_rate)
Resample to the specified sample rate.
int main(int argc, char **argv)
A Buffer for storing audio samples.
FloatVector::iterator iterator
Buffer filter(const Buffer &voice, const Buffer &carrier)