=======================================================================
| 104 | |
| 105 | //======================================================================= |
| 106 | void loadAudioFileAndProcessSamples() |
| 107 | { |
| 108 | //--------------------------------------------------------------- |
| 109 | std::cout << "**********************" << std::endl; |
| 110 | std::cout << "Running Example: Load Audio File and Process Samples" << std::endl; |
| 111 | std::cout << "**********************" << std::endl << std::endl; |
| 112 | |
| 113 | //--------------------------------------------------------------- |
| 114 | // 1. Set a file path to an audio file on your machine |
| 115 | const std::string inputFilePath = std::string (PROJECT_BINARY_DIR) + "/test-audio.wav"; |
| 116 | |
| 117 | //--------------------------------------------------------------- |
| 118 | // 2. Create an AudioFile object and load the audio file |
| 119 | |
| 120 | AudioFile<float> a; |
| 121 | bool loadedOK = a.load (inputFilePath); |
| 122 | |
| 123 | /** If you hit this assert then the file path above |
| 124 | probably doesn't refer to a valid audio file */ |
| 125 | assert (loadedOK); |
| 126 | |
| 127 | //--------------------------------------------------------------- |
| 128 | // 3. Let's apply a gain to every audio sample |
| 129 | |
| 130 | float gain = 0.5f; |
| 131 | |
| 132 | for (int i = 0; i < a.getNumSamplesPerChannel(); i++) |
| 133 | { |
| 134 | for (int channel = 0; channel < a.getNumChannels(); channel++) |
| 135 | { |
| 136 | a.samples[channel][i] = a.samples[channel][i] * gain; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | //--------------------------------------------------------------- |
| 141 | // 4. Write audio file to disk |
| 142 | |
| 143 | std::string outputFilePath = "quieter-audio-file.wav"; // change this to somewhere useful for you |
| 144 | a.save (outputFilePath, AudioFileFormat::Wave); |
| 145 | } |
| 146 | } |
no test coverage detected