BASS for WinCE

Started by Ian @ un4seen,

radio42

Yes, please check the sample as provided in the BASS.NET docs!!!

private GCHandle _hGCFile;
...
// open a file
FileStream fs = File.OpenRead( "test.mp3" );
// get the legth of the file
long length = fs.Length;
// create the buffer which will keep the file in memory
byte[] buffer = new byte[length];
// read the file into the buffer
fs.Read(buffer, 0, length);
// buffer is filled, file can be closed
fs.Close();

// now create a pinned handle, so that the Garbage Collector will not move this object
_hGCFile = GCHandle.Alloc( buffer, GCHandleType.Pinned );
// create the stream (AddrOfPinnedObject delivers the necessary IntPtr)
int stream = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(),
                  0L, length, BASSFlag.BASS_SAMPLE_FLOAT);

if (stream != 0 && Bass.BASS_ChannelPlay(stream, false) )
{
    // playing...
}
else
{
    Console.WriteLine("Error = {0}", Bass.BASS_ErrorGetCode());
}
...
// when playback has ended and the pinned object is not needed anymore,
// we need to free the handle!
// Note: calling this method to early will crash the application,
// since the buffer would be stolen from BASS while still playing!
_hGCFile.Free();

hc_dondon

@radio24, i will check again my code and will use this one.
do you know of an encoder that converts wav to mp3 or  wav to wma?
we are pretty new to wince development, this is painless in win32 but not in wince.  :'(

hc_dondon

   private void SetFileName(string AFileName)
        {
            FFileName = AFileName;           
            //Open file
            FileStream fs = File.OpenRead(AFileName);               
            //get length of the file
            long length = fs.Length;
            //create memory buffer
            byte[] buffer = new byte[length];           
            fs.Read(buffer, 0, (int)length);
            fs.Close();                       
           
            if (this.GetState() == 1) this.Stop();           
            Bass.BASS_StreamFree(playBackStream);
            // now create a pinned handle, so that the Garbage Collector will not move this object
            _hGCFile = GCHandle.Alloc(buffer, GCHandleType.Pinned);
            // create the stream (AddrOfPinnedObject delivers the necessary IntPtr)
            playBackStream = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(), 0L, length, BASSFlag.BASS_SAMPLE_FLOAT);
            //playBackStream = Bass.BASS_StreamCreateFile(pval, 0, 0, BASSFlag.BASS_UNICODE); //BASS_UNICODE
            FPLength = Bass.BASS_ChannelGetLength(playBackStream, BASSMode.BASS_POS_BYTES);

            FTotalTime = Decimal.Truncate(Convert.ToDecimal(Bass.BASS_ChannelBytes2Seconds(playBackStream, FPLength) * 1000));
            FStopPosition = Convert.ToInt32(FTotalTime);
            //_hGCFile.Free();       
}

playbackstream returns -1

radio42

What error code do you get when you call BASS_ErrorGetCode right after the BASS_StreamCreateFile call?

hc_dondon

it worked, i checked the code and it returns invalid format. I just changed it to BASSFlag.BASS_UNICODE..

playBackStream = Bass.BASS_StreamCreateFile(_hGCFile.AddrOfPinnedObject(), 0L, length, BASSFlag.BASS_UNICODE);

thanks radio..

hc_dondon

i just want to ask why it wont play in another device. This code play no problem with a china based Device, i tried korean and it shows the error.(iStation PMP WincE5.0)

private void InitWavHeader(){           
FFileStream = new FileStream(FFileName,FileMode.Create,FileAccess.Write);
         FBinaryWriter = new BinaryWriter(FFileStream);
         FBinaryWriter.Write(new char[4] { 'R', 'I', 'F', 'F' });
         FBinaryWriter.Write((int)36);  //Chunksize
            FBinaryWriter.Write(new char[8] {'W','A','V','E','f','m','t',' '}); //format
            FBinaryWriter.Write((int)16); // SubChunk1Size : 16 for PCM
            FBinaryWriter.Write((short)1); //AudioFormat: 1 for PCM
            FBinaryWriter.Write((short)1); // NumChannels: 1 for Mono, 2 for Stereo
            FBinaryWriter.Write((int)22050); //Sample Rate
            FBinaryWriter.Write((int)88200); //Byte Rate
            FBinaryWriter.Write((short)2); //Block Align
            FBinaryWriter.Write((short)16); // Bits per Sample
            FBinaryWriter.Write(new char[4]{'d','a','t','a'});
            FBinaryWriter.Write((int)0); //Data Length: Initialize length to 0;
}

recordStream = Bass.BASS_RecordStart(22050, 1, BASSFlag.BASS_RECORD_PAUSE, myRecordProc, IntPtr.Zero);
i checked the error code after the call and it returned BASS_ERROR_FORMAT

Ian @ un4seen

BASS_ERROR_FORMAT indicates that the device doesn't support the requested sample format, eg. 22050hz mono 16-bit in your example. Are you able to record in that format on that device with other software? Also, if you call BASS_RecordGetInfo, what "formats" value do you get?

hc_dondon

yes, the device has a built in recorder that records wav also. I haven't tried BASS_RecordGetInfo yet. i will try it today. thanks.

hc_dondon

Hi, here is the recordgetinfo result on this device. format is WAVE_FORMAT_UNKNOWN
i have tried also making it to 44100 still same result.

hc_dondon


this is the sample file details that was recorded using the built-in recorder of the device that doesn't work.

Ian @ un4seen

Quote from: hc_dondoni have tried also making it to 44100 still same result.

Did you also try stereo, ie. 44100hz stereo 16-bit, as in your recording from the built-in recorder?

recordStream = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, myRecordProc, IntPtr.Zero);

hc_dondon

@Ian
 i tried it using the info you gave me, it can record and create the file..but when i tried to copy the recorded audio and open it in wavosaur(free audio editing) it has no peaks, i tried to open it through mediaplayer but it just silence.

hc_dondon

I tried also to use EncodeWav to create the wav instead of my own waveheader. It can record but i can't hear my voice.
this is the sample output file now but can't hear anything on it.

<a href=http://www.filedropper.com/record><img src=http://www.filedropper.com/download_button.png width=127 height=145 border=0/></a><br /> <div style=font-size:9px;font-family:Arial, Helvetica, sans-serif;width:127px;font-color:#44a854;> <a href=http://www.filedropper.com > FileDropper Free File Hosting</a></div>

pls help.

Ian @ un4seen

Another user had a similar issue with a particular device, which required some special code to enable recording, so perhaps the built-in recorder is doing something like that on your device. Are you able to capture sound on it with any other 3rd-party software? Btw, I guess the built-in recorder is capturing sound?

Please also post your code, just to be sure there isn't a problem in that.

hc_dondon

It is indeed very strange, even the spectrum code, won't show any peaks. When i tried same code in another device it will record and functioning very well. i will try to post my code here. I did not try any third party except from the builtin recorder that the device has provided. I will try to find 3rd party recorder and try it in that device. I also ask for the code from the maker of that device they provided me C++ code but i don't know how to use it. if you want i can email it for you. would you give me email so that i can just email you my code.

Ian @ un4seen

If the problem also affects the included examples (eg. LIVESPEC and RECTEST), then it isn't something specific to your code, but if you would like me to have a look at the code provided by the device manufacturer, you can upload that here...

   ftp.un4seen.com/incoming/

hc_dondon

i have uploaded all files in your ftp: all filenames start with hc_dondon text.

kindly look at it

thanks again.

Ian @ un4seen

It looks like the device has a "Set_DQ_AudInput" function to set the recording input, but it's in a LIB file and I don't think you can use LIB files directly with .Net? Perhaps, if you ask, they could provide you a DLL to use instead.

hc_dondon

It is working great now. :)
I get the dll and use it using dll import

Thanks guys.