MCPcopy Create free account
hub / github.com/DamRsn/NeuralNote / convert

Method convert

Lib/Model/Notes.cpp:14–234  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12}
13
14std::vector<Notes::Event> Notes::convert(const std::vector<std::vector<float>>& inNotesPG,
15 const std::vector<std::vector<float>>& inOnsetsPG,
16 const std::vector<std::vector<float>>& inContoursPG,
17 const ConvertParams& inParams,
18 bool inNewAudio)
19{
20 std::vector<Event> events;
21 events.reserve(1024);
22
23 const auto n_frames = static_cast<int>(inNotesPG.size());
24 if (n_frames == 0) {
25 return events;
26 }
27
28 const auto n_notes = static_cast<int>(inNotesPG[0].size());
29 assert(n_frames == inOnsetsPG.size());
30 assert(n_frames == inContoursPG.size());
31 assert(n_notes == inOnsetsPG[0].size());
32 assert(n_notes == NUM_FREQ_OUT);
33
34 std::vector<std::vector<float>> inferred_onsets;
35 auto onsets_ptr = &inOnsetsPG;
36 if (inParams.inferOnsets) {
37 inferred_onsets = _inferredOnsets<float>(inOnsetsPG, inNotesPG);
38 onsets_ptr = &inferred_onsets;
39 }
40 auto& onsets = *onsets_ptr;
41
42 if (inParams.melodiaTrick) {
43 if (inNewAudio) {
44 // Copy
45 mRemainingEnergy = inNotesPG;
46
47 // Fill mRemainingEnergyIndex
48 mRemainingEnergyIndex.clear();
49 mRemainingEnergyIndex.reserve(static_cast<size_t>(n_frames) * static_cast<size_t>(NUM_FREQ_OUT));
50
51 for (int frame_idx = 0; frame_idx < n_frames; frame_idx++) {
52 for (int freq_idx = 0; freq_idx < NUM_FREQ_OUT; freq_idx++) {
53 mRemainingEnergyIndex.push_back(
54 {&mRemainingEnergy[static_cast<size_t>(frame_idx)][static_cast<size_t>(freq_idx)],
55 frame_idx,
56 freq_idx});
57 }
58 }
59
60 mRemainingEnergyIndex.shrink_to_fit();
61 } else {
62 // Copy without changing the location of the original data
63 assert(mRemainingEnergy.size() == n_frames);
64 for (size_t f = 0; f < n_frames; f++) {
65 assert(inNotesPG[f].size() == NUM_FREQ_OUT);
66 assert(mRemainingEnergy[f].size() == NUM_FREQ_OUT);
67
68 std::copy(inNotesPG[f].begin(), inNotesPG[f].end(), mRemainingEnergy[f].begin());
69 }
70 }
71 }

Callers 3

notes_testFunction · 0.80
transcribeToMIDIMethod · 0.80
updateMIDIMethod · 0.80

Calls 2

hzToMidiFunction · 0.85
clearMethod · 0.45

Tested by 1

notes_testFunction · 0.64