| 77 | } |
| 78 | |
| 79 | void SourceAudioManager::startRecording() |
| 80 | { |
| 81 | // If already recording (should not happen but if it does, simply return) |
| 82 | if (mIsRecording.load()) { |
| 83 | jassertfalse; |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | // Prepare files to be written |
| 88 | if (!mNeuralNoteDir.isDirectory()) { |
| 89 | bool res = mNeuralNoteDir.createDirectory(); |
| 90 | jassertquiet(res); |
| 91 | } |
| 92 | |
| 93 | mDroppedFilename = ""; |
| 94 | |
| 95 | String timestamp = Time::getCurrentTime().formatted("%Y-%m-%d_%H-%M-%S"); |
| 96 | |
| 97 | mSourceFile = mNeuralNoteDir.getChildFile("recorded_audio" + timestamp + ".wav"); |
| 98 | mRecordedFileDown = mNeuralNoteDir.getChildFile("recorded_audio" + timestamp + "_downsampled.wav"); |
| 99 | |
| 100 | size_t i = 1; |
| 101 | |
| 102 | while (mSourceFile.existsAsFile() || mRecordedFileDown.existsAsFile()) { |
| 103 | mSourceFile = mNeuralNoteDir.getChildFile("recorded_audio" + timestamp + "_" + String(i) + ".wav"); |
| 104 | mRecordedFileDown = |
| 105 | mNeuralNoteDir.getChildFile("recorded_audio" + timestamp + "_" + String(i) + "_downsampled.wav"); |
| 106 | i += 1; |
| 107 | } |
| 108 | |
| 109 | Result file_creation_result = mSourceFile.create(); |
| 110 | Result file_creation_result_down = mRecordedFileDown.create(); |
| 111 | |
| 112 | if (!file_creation_result.wasOk() || !file_creation_result_down.wasOk()) { |
| 113 | mProcessor->clear(); |
| 114 | NativeMessageBox::showMessageBoxAsync( |
| 115 | MessageBoxIconType::NoIcon, "Error", "File creation for recording failed."); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | mFilesToDelete.push_back(mSourceFile); |
| 120 | mFilesToDelete.push_back(mRecordedFileDown); |
| 121 | |
| 122 | // Init first writer at native sample rate (stereo) |
| 123 | WavAudioFormat format; |
| 124 | StringPairArray meta_data_values; |
| 125 | |
| 126 | auto* wav_writer = format.createWriterFor(new FileOutputStream(mSourceFile), |
| 127 | mSampleRate, |
| 128 | std::min(mProcessor->getTotalNumInputChannels(), 2), |
| 129 | 16, |
| 130 | meta_data_values, |
| 131 | 0); |
| 132 | |
| 133 | mWriterThread.startThread(); |
| 134 | mThreadedWriter = std::make_unique<AudioFormatWriter::ThreadedWriter>(wav_writer, mWriterThread, 32768); |
| 135 | |
| 136 | // Init second writer at basic pitch sample rate (mono) |
no test coverage detected