@@ -58,9 +58,6 @@ SoundListener::SoundListener()
5858 PA_ADD_OPTION (STOP_ON_DETECTED_SOUND);
5959}
6060
61-
62- // void search_alpha_roar_from_audio_dump();
63-
6461void SoundListener::program (SingleSwitchProgramEnvironment& env, SwitchControllerContext& context){
6562 // search_alpha_roar_from_audio_dump();
6663 // return;
@@ -97,100 +94,6 @@ void SoundListener::program(SingleSwitchProgramEnvironment& env, SwitchControlle
9794}
9895
9996
100- // A function used to search for the alpha roar on LA audio dump.
101- // But we didn't find the shound sound :P
102- void search_alpha_roar_from_audio_dump (){
103-
104- const size_t SAMPLE_RATE = 48000 ;
105-
106- SpectrogramMatcher matcher (
107- " Alpha Roar" ,
108- AudioTemplateCache::instance ().get_throw (" PokemonBDSP/AlphaRoar" , SAMPLE_RATE),
109- SpectrogramMatcher::Mode::RAW, SAMPLE_RATE,
110- 100.0
111- );
112-
113- // std::string file_listFile = "./scripts/short_audio_files.txt";
114- std::string file_listFile = " 1.txt" ;
115- // std::string file_listFile = "./scripts/all_audio_files.txt";
116- std::ifstream fin (file_listFile.c_str ());
117- std::vector<std::string> file_list;
118- while (!fin.eof ()){
119- std::string line;
120- std::getline (fin, line);
121- file_list.push_back (line);
122- fin >> std::ws;
123- }
124- std::cout << " File num " << file_list.size () << std::endl;
125-
126- std::map<float , std::string> closest_files;
127-
128- std::ofstream fout (" file_check_output.txt" );
129-
130- for (size_t fileIdx = 0 ; fileIdx < file_list.size (); fileIdx++){
131- matcher.clear ();
132-
133-
134- const auto & path = file_list[fileIdx];
135- std::ostringstream os;
136- os << " File " << fileIdx << " /" << file_list.size () << " " << path << " " ;
137- AudioTemplate audio = loadAudioTemplate (path);
138- if (audio.numWindows () == 0 ){
139- os << " Fail" << std::endl;
140- fout << os.str ();
141- std::cout << os.str () << std::flush;
142- continue ;
143- }
144-
145- // audio.scale(2.0);
146-
147- os << " #W " << audio.numWindows () << " " ;
148-
149- // match!
150- float minScore = FLT_MAX;
151- std::vector<AudioSpectrum> new_spectrums;
152- size_t numStreamWindows = std::max (matcher.numMatchedWindows (), audio.numWindows ());
153- for (size_t audioIdx = 0 ; audioIdx < numStreamWindows; audioIdx++){
154- new_spectrums.clear ();
155- AlignedVector<float > freqVector (audio.numFrequencies ());
156- if (audioIdx < audio.numWindows ()){
157- const float * freq = audio.getWindow (audioIdx);
158- memcpy (freqVector.data (), freq, sizeof (float ) * audio.numFrequencies ());
159- }else {
160- // add zero-freq window
161- }
162- new_spectrums.emplace_back (
163- audioIdx, SAMPLE_RATE,
164- std::make_unique<AlignedVector<float >>(std::move (freqVector))
165- );
166- float score = matcher.match (new_spectrums);
167- minScore = std::min (score, minScore);
168- } // end audio Idx
169-
170- os << " dist " << minScore << std::endl;
171- fout << os.str ();
172- std::cout << os.str () << std::flush;
173-
174- closest_files.emplace (minScore, path);
175- }
176-
177- fout.close ();
178-
179- auto it = closest_files.begin ();
180- std::cout << " --------------" << std::endl;
181- fout.open (" file_check_output_sorted.txt" );
182- for (int i = 0 ; it != closest_files.end (); i++, it++){
183- if (i < 40 )
184- std::cout << it->first << " , " << it->second << std::endl;
185- fout << it->first << " , " << it->second << std::endl;
186- }
187- fout.close ();
188- return ;
189- }
190-
191-
192-
193-
19497
19598}
19699}
0 commit comments