Skip to content

Commit

Permalink
Merge pull request #435 from guiv42/fix431
Browse files Browse the repository at this point in the history
fix audio export
  • Loading branch information
guiv42 committed Jun 22, 2024
2 parents eaf794e + 1e2268d commit fab1d5c
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void write(TGSongWriterHandle handle) throws TGFileFormatException {
TGSynthSequenceHandler midiSequenceHandler = new TGSynthSequenceHandler(tgSong.countTracks());
midiSequenceParser.parse(midiSequenceHandler);
if(!midiSequenceHandler.getEvents().isEmpty()) {

TGSynthModel synthModel = new TGSynthModel(this.context);
TGAudioBufferProcessor audioProcessor = new TGAudioBufferProcessor(synthModel);
ByteArrayOutputStream audioBuffer = new ByteArrayOutputStream();
Expand All @@ -64,17 +63,15 @@ public void write(TGSongWriterHandle handle) throws TGFileFormatException {
this.loadSynthPrograms(synthModel, tgSong);

sequence.start();
long duration = 0;
while(!sequence.isEnded()) {
sequence.dispatchEvents();

audioProcessor.process();
audioBuffer.write(audioProcessor.getBuffer().getBuffer(), 0, audioProcessor.getBuffer().getLength());

duration += audioProcessor.getBuffer().getLength();
sequence.forward();
}

long duration = (long) (TGAudioLine.AUDIO_FORMAT.getFrameRate() * ((sequence.getLength() / 1000.00)));

ByteArrayInputStream byteBuffer = new ByteArrayInputStream(audioBuffer.toByteArray());
AudioInputStream sourceStream = new AudioInputStream(byteBuffer, TGAudioLine.AUDIO_FORMAT, duration);
AudioInputStream targetStream = AudioSystem.getAudioInputStream(settings.getFormat(), sourceStream);
Expand Down

0 comments on commit fab1d5c

Please sign in to comment.