Esempio n. 1
0
        // the recording callback
        private unsafe bool MyRecoring(int handle, IntPtr buffer, int length, IntPtr user)
        {
            // user will contain our encoding handle
            if (length > 0 && buffer != IntPtr.Zero)
            {
                if (checkBoxMonitor.Checked)
                {
                    monBuffer.Write(buffer, length);
                }

                if (!this.buttonStartRec.Enabled)
                {
                    // if recording started...write the data to the encoder
                    BassWma.BASS_WMA_EncodeWrite(user.ToInt32(), buffer, length);
                }
                // get and draw our live recording waveform
                WF.RenderRecording(buffer, length);
                //WF.RenderRecording();  // old style

                // get the rec level...
                int    maxL = 0;
                int    maxR = 0;
                short *data = (short *)buffer;
                for (int a = 0; a < length / 2; a++)
                {
                    // decide on L/R channel
                    if (a % 2 == 0)
                    {
                        // L channel
                        if (data[a] > maxL)
                        {
                            maxL = data[a];
                        }
                    }
                    else
                    {
                        // R channel
                        if (data[a] > maxR)
                        {
                            maxR = data[a];
                        }
                    }
                }
                // limit the maximum peak levels to 0bB = 32768
                // the peak levels will be int values, where 32768 = 0dB!
                if (maxL > 32768)
                {
                    maxL = 32768;
                }
                if (maxR > 32768)
                {
                    maxR = 32768;
                }

                this.BeginInvoke(new UpdateDelegate(UpdateDisplay), new object[] { maxL, maxR });
                // you might instead also use "this.Invoke(...)", which would call the delegate synchron!
            }
            return(true);            // always continue recording
        }
Esempio n. 2
0
 public override void DSPCallback(int handle, int channel, IntPtr buffer, int length, IntPtr user)
 {
     try
     {
         _streamBuffer.Write(buffer, length);
     }
     catch (Exception ex)
     {
         Log.Error("Caught Exception in DSPCallBack. {0}", ex.Message);
     }
 }
Esempio n. 3
0
        public int EnqueueSamples(int channels, int rate, byte[] samples, int frames)
        {
            int consumed = 0;

            if (basbuffer == null)
            {
                Bass.BASS_Init(-1, rate, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
                basbuffer     = new BASSBuffer(0.5f, rate, channels, 2);
                streamproc    = Reader;
                currentHandle = Bass.BASS_StreamCreate(rate, channels, BASSFlag.BASS_DEFAULT, streamproc, IntPtr.Zero);
                Bass.BASS_ChannelPlay(currentHandle, false);
            }

            if (basbuffer.Space(0) > samples.Length)
            {
                basbuffer.Write(samples, samples.Length);
                consumed = frames;
            }

            return(consumed);
        }