26 May '13 - 03:01 *
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: WMA to memory  (Read 1228 times)
John Cleary
Guest
« on: 13 Nov '03 - 15:39 »
Reply with quoteQuote

Hi

I am using BASS WMA compression with c# using the nBass wrappers. There seems to be two methods to Output the compressed data to a file and as an audio stream. I encode sound directly from the line in on my sound card. I want to store the WMA data in a database. At the moment I encode it into a temp folder and then read the file in and store it in the database. What I would like to do is encode into memory and then save the data from memory into the database not needing a temporary file. Any ideas or suggestions would be appreciated.

Thanks
John Cleary.
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #1 on: 13 Nov '03 - 16:12 »
Reply with quoteQuote

Encoding to memory (a callback function) is possible with BASSWMA 2.0

nBASS is not currently compatible with 2.0, but you could use the .Net APIs available on the BASS page.
Logged
John Cleary
Guest
« Reply #2 on: 14 Nov '03 - 22:38 »
Reply with quoteQuote

Thanks im going to use that. I am trying to write a cut down version of the nBass Record.cs but I keep getting an invalid handle when I try and read the left or right level could somebody take a look please. This is the code I am using.

using System;
using System.Runtime.InteropServices;

namespace nBASS
{
   public class Recorder
   {
      public bool disposed;
      public Int32 Handle;
      
      [DllImport("bass.dll", EntryPoint = "BASS_RecordInit")]
      static extern int _Init(int device);
      
      [DllImport("bass.dll", EntryPoint = "BASS_RecordStart")]
      static extern int _Start(int freq, int flags, GetRecordCallBack proc, int user);
      
      [DllImport("bass.dll", EntryPoint = "BASS_ChannelStop")]
      static extern int _Stop(IntPtr handle);
      
      [DllImport("bass.dll", EntryPoint = "BASS_ChannelPause")]
      static extern int _Pause(IntPtr handle);

      [DllImport("bass.dll", EntryPoint = "BASS_ChannelResume")]
      static extern int _Resume(IntPtr handle);
      
      [DllImport("bass.dll", EntryPoint = "BASS_ChannelGetLevel")]
      static extern int _GetLevel(IntPtr handle);
      
      [DllImport("bass.dll", EntryPoint = "BASS_RecordFree")]                                                   
      static extern void _Free();
      
      [DllImport("bass.dll", EntryPoint = "BASS_ChannelIsActive")]
      static extern int _IsActive(IntPtr handle);
      
      [DllImport("bass.dll", EntryPoint = "BASS_RecordSetInput")]
      static extern int _SetInput(int inputn, int setting);
      
      public Recorder(int device) : base(new IntPtr(1))
      {
         int i = _Init(device) ;
         if (i == 0) throw new BASSException();
         disposed = false;
         Handle = new Int32(1);
      }
      
      public void SetInput(int inputn, InputFlags flags)
      {
         if (this.disposed)
            throw new ObjectDisposedException(this.ToString());

         if (_SetInput(inputn, (int) flags) == 0) throw new BASSException();
      }
      public void Start(int freq, RecordFlags flags, GetRecordCallBack callback, int user)
      {
         if (this.disposed)
            throw new ObjectDisposedException(this.ToString());

         if (_Start(freq, (int) flags, callback, (int) flags) == 0 )
            throw new BASSException();
      }
            
      public void Stop()
      {
         if (this.disposed)
            throw new ObjectDisposedException(this.ToString());

         if (_Stop(this.Handle) == 0) throw new BASSException();   

      }

      public void Pause()
      {
         if (this.disposed)
            throw new ObjectDisposedException(this.ToString());

         if (_Pause(this.Handle) == 0) throw new BASSException();      
      }

      public void Resume()
      {
         if (this.disposed)
            throw new ObjectDisposedException(this.ToString());

         if (_Resume(this.Handle) == 0) throw new BASSException();      
      }   
      
      public State ActivityState
      {
         get
         {
            if (this.disposed)
               throw new ObjectDisposedException(this.ToString());

            return (State)_IsActive(this.Handle);
         }
      }

      public int LeftLevel
      {
         get
         {
            if (this.disposed)
               throw new ObjectDisposedException(this.ToString());
            int result = _GetLevel(this.Handle);
            if(result < 0) throw new BASSException();
            return Helper.LoWord(result);
         }
      }

      public int RightLevel
      {
         get
         {
            if (this.disposed)
               throw new ObjectDisposedException(this.ToString());

            int result = _GetLevel(this.Handle);
            if(result < 0) throw new BASSException();
            return Helper.HiWord(result);
         }
      }
      public void Dispose()
      {
         if (!this.disposed)
         {
            _Free();
            disposed = true;
         }
      }

   }
}

thanks
John
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines