Author Topic: Save audio (WMA?)  (Read 158 times)

Wayne

  • Guest
Save audio (WMA?)
« on: 20 Nov '17 - 13:31 »
I have my MIDI/audio player I wrote using BASS/BASSMIDI and now have need of an option to save the play result as audio. I just can't find simple instructions or a simple example of what is required to do this.  I can't get my head around what is actually needed from what I have found. Can someone point to the right reference, or a good example, or anything that might help me work this out.  Thanks in anticipation.

Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: Save audio (WMA?)
« Reply #1 on: 20 Nov '17 - 15:24 »
The easiest way to write files is with the BASSenc add-on. Do you want to write the file during playback, or as quickly as possible? For the former, you only need to add a BASS_Encode_Start call before BASS_ChannelPlay. For example, to write an MP3 file you could do this:

Code: [Select]
BASS_Encode_Start(midistream, "lame - output.mp3", BASS_ENCODE_AUTOFREE|BASS_ENCODE_FP_24BIT, NULL, 0); // set an MP3 encoder (LAME) on the MIDI stream
BASS_ChannelPlay(midistream, 0); // start the MIDI stream playing & encoding

For writing as fast as possible, you will need to add the BASS_STREAM_DECODE flag to the MIDI stream to make it a "decoding channel". You can then repeatedly call BASS_ChannelGetData to process it, something like this:

Code: [Select]
BASS_Encode_Start(midistream, "lame - output.mp3", BASS_ENCODE_AUTOFREE|BASS_ENCODE_FP_24BIT, NULL, 0); // set an MP3 encoder (LAME) on the MIDI stream
// processing loop
while (1) {
BYTE buf[20000]; // processing buffer
int r = BASS_ChannelGetData(midistream, buf, sizeof(buf)); // process the MIDI stream
if (r == -1) break; // done
}

Please see the BASS_Encode_Start documentation for details. If you happen to want FLAC/OGG/OPUS encoding, also see the BASSenc_FLAC/OGG/OPUS add-ons (you would simply replace the BASS_Encode_Start call when using them).

Wayne

  • Guest
Re: Save audio (WMA?)
« Reply #2 on: 20 Nov '17 - 21:25 »
Thanks Ian.  I thought there was probably something simple among the more complex options.  I read something that suggested to me that Windows 10 won't allow the BASSenc lame technique.  I may have been extrapolating a wrong conclusion, but can you confirm for me that BASSenc with lame/mp3 will work in all Windows versions?

Ian @ un4seen

  • Administrator
  • Posts: 20427
Re: Save audio (WMA?)
« Reply #3 on: 21 Nov '17 - 16:42 »
Yes, LAME works fine on Windows 10. To quickly check that there, you could try running the pre-compiled examples included in the BASSenc package (C\BIN folder). They all use LAME for MP3 encoding.

Wayne

  • Guest
Re: Save audio (WMA?)
« Reply #4 on: 21 Nov '17 - 20:35 »
Thanks Ian, champion as always!  None of the computers I have access to are running Windows 10, hence the question.  I have implemented the play-speed encoding of mp3, exactly as easily as you described.