25 May '13 - 21:53 *
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] 2  All
  Reply  |  Print  
Author Topic: Opus codec  (Read 3820 times)
Xire
Posts: 234


« on: 17 Jul '12 - 17:32 »
Reply with quoteQuote

Hi Ian,

Would be nice to have support for http://opus-codec.org/ in BASS Wink

Xire
Logged
CoRoNe
Posts: 13


« Reply #1 on: 17 Jul '12 - 18:13 »
Reply with quoteQuote

I second that! Afaik only Foobar (latest beta version) as 3th party software has support for Opus at the moment. DirectShow (Lav Filters, FFDShow, MPC-HC internal filters) has no support so far. With Opus support in BASS, I can integrate it into DC-Bass Source Mod and you can offer people Opus support in any DirectShow player.
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #2 on: 18 Jul '12 - 17:35 »
Reply with quoteQuote

I'll see what can be done Smiley
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #3 on: 26 Jul '12 - 17:21 »
Reply with quoteQuote

OK. Here's a new BASSOPUS add-on to try out...

   www.un4seen.com/stuff/bassopus.zip

All of the usual stuff should be supported, including internet and custom file streaming, but one thing to note is that the length won't be available (BASS_ChannelGetLength will fail) when streaming from the internet (or a buffered custom file) until the entire file has been decoded/played, and seeking won't be possible until then either. The seeking side of that will probably be tweaked to allow seeking within the currently downloaded portion, but it will require a little BASS.DLL update (to let BASSOPUS inspect the downloaded portion more efficiently).

The Opus file format is Ogg-based, so the BASS_TAG_OGG and BASS_TAG_VENDOR tag types apply to Opus too, as does the BASS_SYNC_OGG_CHANGE sync.

Please report any problems encountered with it.
Logged
Xire
Posts: 234


« Reply #4 on: 27 Jul '12 - 09:13 »
Reply with quoteQuote

Thanks Wink
I tried it and it works OK in a single thread, but crashes, when multiple decoding threads are started.
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #5 on: 27 Jul '12 - 12:28 »
Reply with quoteQuote

That's strange. Do you have any details on the crashing, eg. call stacks and registers? I tried to reproduce the problem by modifying the BASSTEST example to load BASSOPUS and then playing 2 Opus files at the same time with "2 update threads" enabled, but that seemed to work fine.
Logged
Xire
Posts: 234


« Reply #6 on: 27 Jul '12 - 13:31 »
Reply with quoteQuote

Here's the sample code. I'm using BASS_StreamCreateFileUser with custom procedures.
Crash happens at BASS_ChannelGetData. If I uncomment that sleep(100), crash is not happening.
I tried with mp3 files as well using the same approach and it worked fine.

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, bass;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TBassThread = class(TThread)
  private
    FFileName: string;
    FFileStream: TFileStream;
    FMemo: TMemo;
    FInfo: string;
    procedure CreateDecoder(var h: HSTREAM);
    procedure Info;
  public
    constructor Create(const FileName: string; Memo: TMemo);
    procedure Execute; override;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  TBassThread.Create('C:\converted\output\01.opus', Memo1);
  TBassThread.Create('C:\converted\output\02.opus', Memo1);
  //TBassThread.Create('C:\converted\output\01.mp3', Memo1);
  //TBassThread.Create('C:\converted\output\02.mp3', Memo1);
  //TBassThread.Create('C:\converted\output\01.mp3', Memo1);
  //TBassThread.Create('C:\converted\output\02.mp3', Memo1);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  BASS_Init(-1, 44100, 0, Form1.handle, nil);
  if BASS_PluginLoad(PWideChar(ExtractFilePath(ParamStr(0)) + 'bassopus.dll'), BASS_UNICODE) = 0 then begin
    MessageDlg('BASS_PluginLoad failed.', mtError, [mbOK], 0);
  end;
end;

{ TBassThread }

procedure FILECLOSEPROC(user: pointer); stdcall;
begin
end;

function FILELENPROC(user: pointer): QWORD; stdcall;
begin
  Result := TFileStream(user).size;
end;

function FILEREADPROC(buffer: pointer; length: DWORD; user: pointer): DWORD; stdcall;
begin
  Result := TFileStream(user).Read(buffer^, length);
end;

function FILESEEKPROC(offset: QWORD; user: pointer): BOOL; stdcall;
begin
  Result := TFileStream(user).Seek(offset, soFromBeginning) = offset;
end;

constructor TBassThread.Create(const FileName: string; Memo: TMemo);
begin
  FFileName := FileName;
  FMemo := Memo;
  FreeOnTerminate := True;
  inherited Create(False);
end;

procedure TBassThread.CreateDecoder(var h: HSTREAM);
var
  procs: BASS_FILEPROCS;
  flags: DWORD;
begin
  h := 0;
  procs.close := FILECLOSEPROC;
  procs.length := FILELENPROC;
  procs.Read := FILEREADPROC;
  procs.Seek := FILESEEKPROC;
  flags := BASS_STREAM_DECODE;
  FFileStream := TFileStream.Create(FFileName, fmOpenRead or fmShareDenyWrite);
  h := BASS_StreamCreateFileUser(STREAMFILE_NOBUFFER, flags, procs, FFileStream);
  if h = 0 then begin
    Exit;
  end;
end;

procedure TBassThread.Info;
begin
  FMemo.Lines.Add(FInfo);
end;

procedure TBassThread.Execute;
var
  h: HSTREAM;
  buf: pointer;
  i: DWORD;
begin
  CreateDecoder(h);
  if h = 0 then begin
    Exit;
  end;
  GetMem(buf, 4 * 1024);
  repeat
    i := BASS_ChannelGetData(h, buf, 4 * 1024);
    //Sleep(100);
  until (i = 0) or (i = DWORD(-1));
  FreeMem(buf);
  Finfo := Format('Done %s', [FFilename]);
  Synchronize(Info);
end;

end.
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #7 on: 27 Jul '12 - 16:31 »
Reply with quoteQuote

Ah, I think I see the cause of the problem (a missing macro definition when building the Opus decoder). Here's an update to try...

   www.un4seen.com/stuff/bassopus.zip

Let me know if the problem still occurs with that.
Logged
Xire
Posts: 234


« Reply #8 on: 27 Jul '12 - 18:04 »
Reply with quoteQuote

That did it. No more crashes. Thanks Smiley
Could you, please, create a 64bit version of it as well?
Logged
JesseW
Posts: 6


« Reply #9 on: 27 Jul '12 - 20:23 »
Reply with quoteQuote

The Bassopus.dll also works fine here. Also streaming Opus with the inbuild HTTP server in BassEnc works great.
Logged
CoRoNe
Posts: 13


« Reply #10 on: 27 Jul '12 - 21:11 »
Reply with quoteQuote

Seems to be working great in DirectShow. Thanks a lot, Ian!
Logged
Ian @ un4seen
Administrator
Posts: 15276


« Reply #11 on: 30 Jul '12 - 16:59 »
Reply with quoteQuote

Could you, please, create a 64bit version of it as well?

You have probably already noticed it by now, but a 64-bit version was being posted in the Win64 thread while you were posting in this thread Smiley

   www.un4seen.com/forum/?topic=9038
Logged
Xire
Posts: 234


« Reply #12 on: 31 Jul '12 - 11:44 »
Reply with quoteQuote

Yep, and it's working fine as well Smiley
Logged
PapaBearPW
Posts: 33


« Reply #13 on: 4 Aug '12 - 00:42 »
Reply with quoteQuote

Hi,

Just trying this one out. Is this an Addon or plugin? Trying to figure out how to load it in my C# project and can't seem to get .opus to show up in the supported audio types.

Any help would be great.

Thanks,
Paul
Logged
Chris
Posts: 1507


« Reply #14 on: 4 Aug '12 - 02:12 »
Reply with quoteQuote

Its a Plugin.
Opus is based on OGG bit with better sound.
You have to add

const
  // BASS_CHANNELINFO type
  BASS_CTYPE_STREAM_OPUS        = $11200;
Chris
Logged
PapaBearPW
Posts: 33


« Reply #15 on: 4 Aug '12 - 05:14 »
Reply with quoteQuote

Ok, so, I've done some more testing and I'm fairly certain that bassopus.dll is being loaded along with any other plugins in my plugin folder (targetPath in the code below). If I try to load it by itself after PluginLoadDirectory, BASS_ErrorGetCode() returns BASS_ERROR_ALREADY. So I know it is loading. But, when I check for supported file extensions I find no reference for *.opus ...

loadedPlugInsX = Bass.BASS_PluginLoadDirectory(targetPath);
filters = Utils.BASSAddOnGetSupportedFileExtensions(loadedPlugInsX, true);

MessageBox.Show(filters);

I could always add it manually I suppose, but I thought I'd check first if maybe I'm doing something wrong.
Logged
Chris
Posts: 1507


« Reply #16 on: 4 Aug '12 - 09:33 »
Reply with quoteQuote

Ok, so, I've done some more testing and I'm fairly certain that bassopus.dll is being loaded along with any other plugins in my plugin folder (targetPath in the code below). If I try to load it by itself after PluginLoadDirectory, BASS_ErrorGetCode() returns BASS_ERROR_ALREADY. So I know it is loading. But, when I check for supported file extensions I find no reference for *.opus ...

loadedPlugInsX = Bass.BASS_PluginLoadDirectory(targetPath);
filters = Utils.BASSAddOnGetSupportedFileExtensions(loadedPlugInsX, true);

MessageBox.Show(filters);
I could always add it manually I suppose, but I thought I'd check first if maybe I'm doing something wrong.

 
BASSAddOnGetSupportedFileExtensions
is a Function/procedure from Radio42 Bass_Net Wrapper you have to wait til the newest Bass_Net Realease from Radio42.

Chris



« Last Edit: 4 Aug '12 - 09:38 by Chris » Logged
PapaBearPW
Posts: 33


« Reply #17 on: 4 Aug '12 - 11:56 »
Reply with quoteQuote

Ah, I see. Makes sense. I'll just add it manually for now then. Thanks for the heads-up Chris.
Logged
PapaBearPW
Posts: 33


« Reply #18 on: 4 Aug '12 - 13:38 »
Reply with quoteQuote

The Bassopus.dll also works fine here. Also streaming Opus with the inbuild HTTP server in BassEnc works great.

Hi,

Mind if I ask how exactly you set up encoding for Opus?

Edit: Nevermind, I think I missunderstood what you wrote. I'm trying to figure out how to encode in opus to an icecast server...
« Last Edit: 4 Aug '12 - 13:48 by PapaBearPW » Logged
Chris
Posts: 1507


« Reply #19 on: 5 Aug '12 - 17:28 »
Reply with quoteQuote

Hi
 here you can read the possible switches of opusenc.
by the way Icecast has as version 2.4 Support for Ogg Opus streams
Chris
« Last Edit: 5 Aug '12 - 17:41 by Chris » Logged
Pages: [1] 2  All
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines