First, just want to mention that I'm using Bass.Net. I have audio pcm data in a 32-bit floating point array. I would like to encode this data without outputting it as this is done all server side. Here's the code I've written in an attempt at this:
public static void SaveSample(float[] floatData, string fullPath)
{
var sampleStream = Bass.BASS_StreamCreate(44100, 2, BASSFlag.BASS_STREAM_DECODE, BASSStreamProc.STREAMPROC_PUSH);
Bass.BASS_StreamPutData(sampleStream, floatData, length);
EncodeToOgg(sampleStream, floatData.length * 4, fullPath);
}
private static void EncodeToOgg(int channel, int length, string saveToFile)
{
var data = new float[length / 4];
var encoder = new Un4seen.Bass.Misc.EncoderOGG(channel)
{
OutputFile = saveToFile,
EncoderDirectory = EncoderPath
};
if (encoder.EncoderExists)
{
encoder.Start(null, IntPtr.Zero, false);
var errorCode = Bass.BASS_ChannelGetData(channel, data, length);
encoder.Stop();
}
else
{
throw new Exception("Encoder cannot be found");
}
}
Initially, I put the BASS_StreamCreate flag as BASSFlag.BASS_SAMPLE_FLOAT but then I get a BASS_ERROR_NOTAVAIL error. Using the decode flag obviously doesn't work since the data is already decoded. Most likely I'm going about this the wrong way and could use a quick pointer on how to do this correctly. Thanks in advance for any help.