(
score: Score,
fileName: string,
prepareOptions: (options: AudioExportOptions) => void
)
| 143 | }); |
| 144 | |
| 145 | async function testAudioExport( |
| 146 | score: Score, |
| 147 | fileName: string, |
| 148 | prepareOptions: (options: AudioExportOptions) => void |
| 149 | ) { |
| 150 | // add a fake sync point to get time range (if there are not already sync points) |
| 151 | const syncPoints = score.exportFlatSyncPoints(); |
| 152 | if (syncPoints.length === 0) { |
| 153 | score.applyFlatSyncPoints([ |
| 154 | { |
| 155 | barIndex: 0, |
| 156 | barOccurence: 0, |
| 157 | barPosition: 0, |
| 158 | millisecondOffset: 0 |
| 159 | } |
| 160 | ]); |
| 161 | } |
| 162 | |
| 163 | const soundFont = await TestPlatform.loadFile('test-data/audio/default.sf2'); |
| 164 | const synth = new AlphaSynth(new TestOutput(), 500); |
| 165 | |
| 166 | const midi: MidiFile = new MidiFile(); |
| 167 | const generator: MidiFileGenerator = new MidiFileGenerator( |
| 168 | score, |
| 169 | new Settings(), |
| 170 | new AlphaSynthMidiFileHandler(midi) |
| 171 | ); |
| 172 | generator.applyTranspositionPitches = false; |
| 173 | generator.generate(); |
| 174 | |
| 175 | const exportOptions = new AudioExportOptions(); |
| 176 | exportOptions.masterVolume = 1; |
| 177 | exportOptions.metronomeVolume = 0; |
| 178 | exportOptions.sampleRate = 44100; |
| 179 | exportOptions.soundFonts = [soundFont]; |
| 180 | prepareOptions(exportOptions); |
| 181 | |
| 182 | const exporter = synth.exportAudio(exportOptions, midi, generator.syncPoints, generator.transpositionPitches); |
| 183 | |
| 184 | let generated: Float32Array = new Float32Array( |
| 185 | exportOptions.sampleRate * |
| 186 | (generator.syncPoints[generator.syncPoints.length - 1].syncTime / 1000) * |
| 187 | SynthConstants.AudioChannels |
| 188 | ); |
| 189 | |
| 190 | let totalSamples = 0; |
| 191 | while (true) { |
| 192 | const chunk = exporter.render(300); |
| 193 | if (chunk === undefined) { |
| 194 | break; |
| 195 | } |
| 196 | |
| 197 | const neededSize = totalSamples + chunk.samples.length; |
| 198 | if (generated.length < neededSize) { |
| 199 | const needed = neededSize - generated.length; |
| 200 | const newBuffer = new Float32Array(generated.length + needed); |
| 201 | newBuffer.set(generated, 0); |
| 202 | generated = newBuffer; |
no test coverage detected