Author Topic: EncoderWMA  (Read 1664 times)

cameronbraidwood

  • Posts: 35
EncoderWMA
« on: 31 Mar '08 - 10:34 »
Hi,
I am trying to record whatever is coming through the default windows recording device, a live recording, I have checked my windows settings and they seem ok, certainly another sound recording app uses them no problem (just the stereo mix + medium level)...

Firstly, will it record whatever is coming through the default recording device ? the stereo mix ? or does it need to be pointed towards a file or stream specifically ?

I have looked at various samples but cant get this to work at all, I keep getting BASS_ERROR_UNKNOWN, error 2 in the test code below ...

Code: [Select]
                Bass.BASS_RecordInit(-1);

                if (Bass.BASS_ErrorGetCode() == BASSError.BASS_OK)
                {

                    _recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE | BASSFlag.BASS_SAMPLE_FLOAT, null, IntPtr.Zero);

                    if (Bass.BASS_ErrorGetCode() == BASSError.BASS_OK)
                    {
                        wma = new EncoderWMA(_recHandle);
                        wma.InputFile = null;               // use STDIN
                        wma.OutputFile = "t:\test.wma";   // the output filename
                        wma.WMA_UseVBR = true;
                        wma.WMA_VBRQuality = 100;  // lossless
                        wma.Start(null, IntPtr.Zero, false);
                    }
                    else
                        MessageBox.Show("2:" + Bass.BASS_ErrorGetCode().ToString());
                }
                else
                    MessageBox.Show("1:" + Bass.BASS_ErrorGetCode().ToString());

Will this simple approach work or do I need a callback function to process chunks of data every so often. Am I right in thinking that the EncoderWma does this anyway ?

cameronbraidwood

  • Posts: 35
Re: EncoderWMA
« Reply #1 on: 31 Mar '08 - 11:21 »
if I use :

Code: [Select]

_recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, null, IntPtr.Zero);


I get no immediate errors ... but ...

then I get an access violation exception when I call wma.start(...);

cameronbraidwood

  • Posts: 35
Re: EncoderWMA
« Reply #2 on: 31 Mar '08 - 11:27 »
This is the exception :

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Un4seen.Bass.AddOn.Wma.BassWma.BASS_WMA_EncodeOpenFileUnicode(Int32 freq, Int32 chans, BASSWMAEncode flags, Int32 bitrate, String file)
   at Un4seen.Bass.AddOn.Wma.BassWma.BASS_WMA_EncodeOpenFile(Int32 freq, Int32 chans, BASSWMAEncode flags, Int32 bitrate, String file)
   at Un4seen.Bass.Misc.EncoderWMA.Start(ENCODEPROC proc, IntPtr user, Boolean paused)

radio42

  • Posts: 4576
Re: EncoderWMA
« Reply #3 on: 31 Mar '08 - 12:32 »
Beside the fact, that a system access violation is thrown (which sounds like a little BASS glitch), you should provide a RECORDINGPROC with your BASS_RecordStart call.

Without a RECORDINGPROC you only get the recorded data on demand via the BASS_ChannelGetData function.
The encoder doesn't call BASS_ChannelGetData internally or automatically.

cameronbraidwood

  • Posts: 35
Re: EncoderWMA
« Reply #4 on: 31 Mar '08 - 12:47 »
Hi,

within the EncoderWMa documentation it says :

Quote
As with all encoders in this framework also this WMA encoder always automatically encodes sample data (by using a DSP callback). So there is no need to manually send any sample data to the encoder.

and the encoder specifies an output file ... test.wma ... so doesnt this just get written out once started.

once EncoderWMA is started against the default recording device, does the data only get written out via the encoder when the RECORDINGPROC is invoked periodically ?

if so, how does the data get to the encoder from the RECORDINGPROC ? is it just visible to the encoder ?



cameronbraidwood

  • Posts: 35
Re: EncoderWMA
« Reply #5 on: 31 Mar '08 - 13:29 »
got it. the problem was the filename, originally : t:\test.wma ... needed the extra \ (escape sequence).


pgruebele

  • Posts: 34
Re: EncoderWMA
« Reply #6 on: 27 Nov '17 - 19:52 »
Did you ever find the cause/resolution for this issue?  I am seeing the exact same issue.  It happens randomly - usually after quite a bit of streaming.

In my case I am using callbacks as follows:

Code: [Select]
bassFileProcs = new BASS_FILEPROCS(CallbackFileClose, CallbackFileLength, CallbackFileRead, CallbackFileSeek);
StreamHandle = Un4seen.Bass.AddOn.Opus.BassOpus.BASS_OPUS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, flags, bassFileProcs, gcHandle);




private void CallbackFileClose(IntPtr user)
{
var us = this;

if (us.stream != null)
{
us.stream.Dispose();
us.stream = null;
}

return;
}

private long CallbackFileLength(IntPtr user)
{
var us = this;

return us.stream.Length;
}

private int CallbackFileRead(IntPtr buffer, int length, IntPtr user)
{
var us = this;

try
{
us.byteBuffer = new byte[length];

if (us.stream.Length > 0)
{
int count = us.stream.Read(us.byteBuffer, 0, length);
Marshal.Copy(us.byteBuffer, 0, buffer, count);
return count;
}

// for now just return silence if no audio is ready
ZeroBuffer(buffer, length);
return length;
}
catch
{
return 0;
}
}

private bool CallbackFileSeek(long offset, IntPtr user)
{
var us = this;

try
{
if (us.stream.CanSeek)
{
if (offset < 0)
return false;

us.stream.Seek(offset, SeekOrigin.Begin);

return true;
}

return false;
}
catch
{
return false;
}
}
   


In case it helps, here is the stack trace into BASS_ChannelGetData when the exception happens.  I am using the latest Windows libraries.  If you send me PDB files I can give you a better stack trace next time it happens.

Code: [Select]
ntdll.dll!775ee78c() Unknown No symbols loaded.
  [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll] Annotated Frame
  KernelBase.dll!7618ebe9() Unknown No symbols loaded.
  ntdll.dll!77609d62() Unknown No symbols loaded.
  ntdll.dll!77609d34() Unknown No symbols loaded.
  ntdll.dll!775e1223() Unknown No symbols loaded.
> ntdll.dll!775f0bf6() Unknown No symbols loaded.
  ntdll.dll!775eed4c() Unknown No symbols loaded.
  ntdll.dll!775ded32() Unknown No symbols loaded.
  ntdll.dll!775efd2c() Unknown No symbols loaded.
  ntdll.dll!77609f35() Unknown No symbols loaded.
  ntdll.dll!775efd2c() Unknown No symbols loaded.
  ntdll.dll!77609f35() Unknown No symbols loaded.
  ntdll.dll!775eed1c() Unknown No symbols loaded.
  KernelBase.dll!761a1293() Unknown No symbols loaded.
  ntdll.dll!775efd2c() Unknown No symbols loaded.
  ntdll.dll!77609f35() Unknown No symbols loaded.
  ntdll.dll!775eed4c() Unknown No symbols loaded.
  ntdll.dll!775ded32() Unknown No symbols loaded.
  combase.dll!74a17ef3() Unknown No symbols loaded.
  combase.dll!74a181d5() Unknown No symbols loaded.
  ntdll.dll!775eed4c() Unknown No symbols loaded.
  ntdll.dll!775dd68c() Unknown No symbols loaded.
  ntdll.dll!775ee8cc() Unknown No symbols loaded.
  mscorlib.ni.dll!71335b80() Unknown No symbols loaded.
  mscorlib.ni.dll!7145c6ea() Unknown No symbols loaded.
  mscorlib.ni.dll!718347be() Unknown No symbols loaded.
  bass.dll!165dd99e() Unknown No symbols loaded.
  bass.dll!165e2af1() Unknown No symbols loaded.
  [Managed to Native Transition] Annotated Frame

Cheers
Philip
« Last Edit: 27 Nov '17 - 22:08 by pgruebele »