25 May '13 - 04:13 *
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: Asio gives already BASS_ERROR_ALREADY  (Read 403 times)
anihilator
Posts: 3


« on: 2 Jun '12 - 00:19 »
Reply with quoteQuote

Hi, dont understand, why this simple code alredy give me: BASS_ERROR_ALREADY. Can someone test it?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Un4seen.Bass;
using Un4seen.BassAsio;
using System.Threading;
using System.Windows.Forms;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Bass.BASS_Init(-1, 192000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            BassAsio.BASS_ASIO_Init(1, BASSASIOInit.BASS_ASIO_DEFAULT);
            BassAsioHandler asio = new BassAsioHandler(false, 1, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_16BIT, 192000);

            Bass.BASS_RecordInit(0);
            //int stream = Bass.BASS_StreamCreateFile("test.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
            int stream = Bass.BASS_RecordStart(192000, 2, BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);
            if (stream != 0)
            {
                // now setup ASIO
                _myAsioProc = new ASIOPROC(AsioCallback);
                // enable 1st output channel...(0=first)
                BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, new IntPtr(stream));
                // and join the next channels to it
                BassAsio.BASS_ASIO_ChannelJoin(false, 1, 0);

                // and start playing it...start output using default buffer/latency
                BassAsio.BASS_ASIO_Start(0);
            }
            else
                System.Windows.Forms.MessageBox.Show("Fail " + Bass.BASS_ErrorGetCode());
            while (true)
            {
                Thread.Sleep(10);
            }
        }
        private static ASIOPROC _myAsioProc; // make it global, so that it can not be removed by the Garbage Collector
        private static int AsioCallback(bool input, int channel, IntPtr buffer, int length, IntPtr user)
        {
            // Note: 'user' contains the underlying stream channel (see above)
            // We can simply use the bass method to get some data from a decoding channel
            // and store it to the asio buffer in the same moment...
            return Bass.BASS_ChannelGetData(user.ToInt32(), buffer, length);
        }
    }
}
Logged
hwahrmann
Posts: 116


« Reply #1 on: 2 Jun '12 - 09:31 »
Reply with quoteQuote

It is probably the BassInit causing it.
You are using the default device (-1), but as you want playback via ASIO you shoud use the "Nosound Device" (0).
So change it do:

Bass.BASS_Init(0, 192000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
Logged
anihilator
Posts: 3


« Reply #2 on: 2 Jun '12 - 13:24 »
Reply with quoteQuote

Nope, it doesn't solve the problem. I need simply record from input and play it trough asio out. I don't see anything wrong.
Logged
anihilator
Posts: 3


« Reply #3 on: 2 Jun '12 - 13:27 »
Reply with quoteQuote

I finally found solution. First start record, then initialise ASIO.

            Bass.BASS_Init(-1, 192000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);

            Bass.BASS_RecordInit(0);
            int stream = Bass.BASS_RecordStart(192000, 2, BASSFlag.BASS_DEFAULT, null, IntPtr.Zero);
            if (stream != 0)
            {
                BassAsio.BASS_ASIO_Init(1, BASSASIOInit.BASS_ASIO_DEFAULT);
                BassAsioHandler asio = new BassAsioHandler(false, 1, 0, 2, BASSASIOFormat.BASS_ASIO_FORMAT_16BIT, 192000);
                // now setup ASIO
                _myAsioProc = new ASIOPROC(AsioCallback);
                // enable 1st output channel...(0=first)
                BassAsio.BASS_ASIO_ChannelEnable(false, 0, _myAsioProc, new IntPtr(stream));
                // and join the next channels to it
                BassAsio.BASS_ASIO_ChannelJoin(false, 1, 0);

                // and start playing it...start output using default buffer/latency
                BassAsio.BASS_ASIO_Start(0);
            }
            else
                System.Windows.Forms.MessageBox.Show("Fail " + Bass.BASS_ErrorGetCode());
            Application.Run(new Form1());
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines