Author Topic: windows 11 BASS_ERROR_FILEOPEN  (Read 210 times)

pzs7602

  • Posts: 80
windows 11 BASS_ERROR_FILEOPEN
« on: 23 Oct '22 - 04:04 »
I can use Bass.Net(2.4.17) and its add-on .dll libraries to play audio files(flac,ape,...). But if I just use Bass libraries(2.4.17), BASS_FLAC_StreamCreateFile(or other audio format's StreamCreateFile method) return  BASS_ERROR_FILEOPEN, the audio file does exist.
My env:
Windows 11
dotnet 6.0.400
Bass 2.4.17 X64 dll lib
bassflac.dll X64 version

My code:
Code: [Select]
// BassAPI.cs
using System.Runtime.InteropServices;
namespace music.console;

class Bass
{
    public delegate void BASSFileProc(int Handle, int Channel, int Data, IntPtr User);
   
    public const string BassAssembly = "./bass.dll";
   
    //HSTREAM BASSDEF(BASS_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
    [DllImport(Bass.BassAssembly)]
    public static extern  uint BASS_StreamCreateFile(bool mem, IntPtr file,uint offset,uint length,uint flags);

    [DllImport(Bass.BassAssembly)]
    public static extern uint BASS_Init(int device, uint freq, uint flags, uint win, IntPtr dsguid);

    [DllImport(Bass.BassAssembly)]
    // int BASSDEF(BASS_ErrorGetCode)();
    public static extern int BASS_ErrorGetCode();

    [DllImport(Bass.BassAssembly)]
    public static extern bool BASS_ChannelPlay(uint handle, bool restart);

    // override method for convienience
    public static uint BASS_StreamCreateFile(string file, uint offset, uint length, uint flags)
    {
        IntPtr stringPointer = Marshal.StringToHGlobalAuto(file);
        var code = BASS_StreamCreateFile(mem: false, stringPointer, offset, length, flags);
        Marshal.FreeHGlobal(stringPointer);
        return code;
    }

}

public class BassFlac
{
    public const string BassAssembly = "./bassflac.dll";
    //HSTREAM BASSDEF(BASS_FLAC_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags);
    [DllImport(BassFlac.BassAssembly)]
    public static extern  uint BASS_FLAC_StreamCreateFile(bool mem, IntPtr file,uint offset,uint length,uint flags);

    // override method for convienience. BASS_ERROR_FILEOPEN error may have relation with this implementation.
    public static uint BASS_FLAC_StreamCreateFile(string file, uint offset, uint length, uint flags)
    {
        IntPtr stringPointer = Marshal.StringToHGlobalAuto(file);
        var code = BASS_FLAC_StreamCreateFile(mem: false, stringPointer, offset, length, flags);
        Marshal.FreeHGlobal(stringPointer);
        return code;
    }

}

// Program.cs

using music.console;
// BASS_Init OK
uint code1 = Bass.BASS_Init(-1, 44100, 0, win: 0,IntPtr.Zero);
if (code1 == 0)
{
    Console.WriteLine("Error returned from BASS_INIT");
}
else
{
    Console.WriteLine("BASS_INIT OK");
}
// BASS_ERROR_FILEOPEN returned here. c:\CD\test.flac exists and can be played by other audio player
uint stream = BassFlac.BASS_FLAC_StreamCreateFile("c:\\CD\\test.flac", 0, 0, 0);
if (stream == 0)
{
    int error = Bass.BASS_ErrorGetCode();
    Console.WriteLine("stream create error=" + error);

}

bool result = Bass.BASS_ChannelPlay(stream, false);
if (!result)
{
    int error = Bass.BASS_ErrorGetCode();
    Console.WriteLine("stream play error=" + error);
}


I also try other audio format file, same error.
What's the problem in my code?
« Last Edit: 23 Oct '22 - 04:11 by pzs7602 »

Ian @ un4seen

  • Administrator
  • Posts: 24789
Re: windows 11 BASS_ERROR_FILEOPEN
« Reply #1 on: 24 Oct '22 - 12:24 »
I believe the "QWORD" parameters should be translated to "ulong" rather than "uint" in C#. So, for example:

Code: [Select]
    [DllImport(Bass.BassAssembly)]
    public static extern  uint BASS_StreamCreateFile(bool mem, IntPtr file, ulong offset, ulong length, uint flags);

dateq

  • Posts: 6
Re: windows 11 BASS_ERROR_FILEOPEN
« Reply #2 on: 25 Oct '22 - 13:19 »
Try using BASS_UNICODE

uint stream = BassFlac.BASS_FLAC_StreamCreateFile("c:\\CD\\test.flac", 0, 0, BASS_UNICODE);