22 May '13 - 01:30 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: Encoding Audio PCM data with "no sound" output device  (Read 499 times)
elnels
Posts: 4


« on: 7 Jun '12 - 22:31 »
Reply with quoteQuote

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.
« Last Edit: 8 Jun '12 - 16:08 by elnels » Logged
elnels
Posts: 4


« Reply #1 on: 8 Jun '12 - 16:07 »
Reply with quoteQuote

Maybe I should simplify the question.  Is there any way to encode raw pcm data to an .Ogg file when using the "no sound" device when initializing Bass?  It seems like this should be possible by sending this data to the encoder but I am unable to figure out how.
Logged
Ian @ un4seen
Administrator
Posts: 15259


« Reply #2 on: 8 Jun '12 - 16:25 »
Reply with quoteQuote

To send raw PCM data to an encoder, you can use a "dummy" stream (with the same sample format). Something like this...

dummy=BASS_StreamCreate(freq, chans, BASS_SAMPLE_FLOAT|BASS_STREAM_DECODE, STREAMPROC_DUMMY, 0); // create a dummy stream
BASS_Encode_Start(dummy, "oggenc -o output.ogg -", BASS_ENCODE_AUTOFREE, 0, 0); // set an OGG encoder on it
...
BASS_Encode_Write(dummy, databuf, datalen); // send some data to the encoder
...
BASS_StreamFree(dummy); // free the dummy stream (and encoder due to AUTOFREE)
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines