Author Topic: BASS for ARM Linux  (Read 209863 times)

Ian @ un4seen

  • Administrator
  • Posts: 22059
Re: BASS for ARM Linux
« Reply #225 on: 2 Oct '14 - 12:59 »
From what you say, it seems like Mono may be loading the libraries based on the order that the code is parsed (rather than executed), and it's parsing the inner blocks first, so BASS_Mixer_StreamCreate before BASS_Init. Hence adding a BASS call (BASS_GetVersion) at the top of the BASS_Mixer_StreamCreate block gets BASS loaded before BASSmix.

Anyway, at least you've got it working now, even if exactly how is a mystery!

niston

  • Posts: 38
Re: BASS for ARM Linux
« Reply #226 on: 2 Oct '14 - 22:16 »
Yeah, it's rather weird. Might be pointed out to others that want to work with mono, so I dedicated a blog post to it:

http://niston.wordpress.com/2014/10/02/black-magic-programming

In any case Ian: Thank you again for your patience. No doubt I'll have more questions along the way  :)

niston

  • Posts: 38
Re: BASS for ARM Linux
« Reply #227 on: 3 Oct '14 - 01:08 »
Found an AAC stream that, when I try to play it on the arm version, CreateStreamUrl() will hang.
I know there is no ARM AAC codec atm, but isn't CreateStreamUrl() supposed to return a ERROR_FILEFORM instead of hanging indefinitely (I've left it like that overnight, and when I returned it still hung)?

Stream in question is: http://yp.shoutcast.com/sbin/tunein-station.pls?id=647391

Ian @ un4seen

  • Administrator
  • Posts: 22059
Re: BASS for ARM Linux
« Reply #228 on: 3 Oct '14 - 13:42 »
I don't seem to be able to reproduce that here. Perhaps it's caused by an add-on. Are you loading any via BASS_PluginLoad? If so, please try removing them one at a time until you find the culprit (if indeed one of them is).

By the way, AAC support is available via the BASS_AAC add-on, which is available in the 1st post :)

Ian @ un4seen

  • Administrator
  • Posts: 22059
Re: BASS for ARM Linux
« Reply #229 on: 6 Oct '14 - 15:55 »
The latest version (2.4.12) of the BASSenc add-on is now up in the 1st first, adding support for user-provided encoders.

zittergie

  • Posts: 31
Re: BASS for ARM Linux
« Reply #230 on: 9 Oct '14 - 19:27 »
Is it possible to bring basscd to linux ARM?

Ian @ un4seen

  • Administrator
  • Posts: 22059
Re: BASS for ARM Linux
« Reply #231 on: 10 Oct '14 - 14:23 »
Yep, an ARM Linux version of the BASSCD add-on is now up in the 1st post.

zittergie

  • Posts: 31
Re: BASS for ARM Linux
« Reply #232 on: 10 Oct '14 - 21:19 »
Many thanks...

niston

  • Posts: 38
Re: BASS for ARM Linux
« Reply #233 on: 11 Oct '14 - 14:18 »
I don't seem to be able to reproduce that here. Perhaps it's caused by an add-on. Are you loading any via BASS_PluginLoad? If so, please try removing them one at a time until you find the culprit (if indeed one of them is).

Ian, sorry for the late reply. I was busy building some hardware :)
Can't reproduce the issue either. I suspect it was something wrong with my code.

BassCD now for ARM? Great!

JRfromFL

  • Posts: 16
Re: BASS for ARM Linux
« Reply #234 on: 16 Oct '14 - 11:24 »
Hi Ian,

I found a note in the BASS documentation, that BASS under Linux uses Realtime Priorities for its threads. Can you tell me the used priority and also the policy ? Or can I request the priority using a function ? I use a BASS stream to output audio on a Raspberry Pi. The audio is coming from a DVB-T radio via USB receiver and is processed by a thread. I now would like to run this thread with the same policy and priority as the outputting BASS thread.
By the way, is there a chance for updating the OPUS decoder to version 1.1 for the RaspPi ?

Thanks !

JRfromFL

Ian @ un4seen

  • Administrator
  • Posts: 22059
Re: BASS for ARM Linux
« Reply #235 on: 16 Oct '14 - 15:11 »
On Linux, only the device thread (which produces the final output mix) is actually set to realtime priority (if permissions allow). The other BASS threads (including update threads) are left at normal priority, so you should probably leave your threads at normal priority too. If you would still like to match the device thread's priority, it uses the SCHED_RR policy with priority=2.

The latest ARM Linux BASSOPUS version is now up in the 1st post.

JRfromFL

  • Posts: 16
Re: BASS for ARM Linux
« Reply #236 on: 17 Oct '14 - 12:53 »
many thanks !

zittergie

  • Posts: 31
Re: BASS for ARM Linux
« Reply #237 on: 17 Oct '14 - 19:50 »
Yep, an ARM Linux version of the BASSCD add-on is now up in the 1st post.

And it works fine on the 'odroid u3'

niston

  • Posts: 38
Re: BASS for ARM Linux
« Reply #238 on: 18 Oct '14 - 01:24 »
Ian,

I would like to add resampling capability (ie 44k1 stream in -> 48k S/PDIF out) to my radio, and I think that BassMix can be used to do this.
So I try this:

Code: [Select]
Bass.BASS_ChannelSetAttribute(_MixerStream, BASSAttribute.BASS_ATTRIB_FREQ, value);
However, this makes the stream play back faster or slower and changes pitch - which is not what I want.

How could I achieve my goal without interrupting audio?





goobliata

  • Posts: 28
Re: BASS for ARM Linux
« Reply #239 on: 10 Nov '14 - 03:11 »
Using the latest and older versions of BASSMIDI on Raspberry Pi, my music sounds out of tune. Works fine on other platforms including Android. I guess it could be an optimization in which case it might be Ok as-is.

Ian @ un4seen

  • Administrator
  • Posts: 22059
Re: BASS for ARM Linux
« Reply #240 on: 10 Nov '14 - 15:01 »
That's strange. Are you using the same code and soundfont(s) in each case? If so, please upload a MIDI file where the difference is most noticeable to have a look at here...

   ftp.un4seen.com/incoming/

goobliata

  • Posts: 28
Re: BASS for ARM Linux
« Reply #241 on: 10 Nov '14 - 15:04 »
Yes, same code and soundfont. I uploaded abw.mid, but it occurs with all songs (about 18 of them).

goobliata

  • Posts: 28
Re: BASS for ARM Linux
« Reply #242 on: 10 Nov '14 - 15:14 »
Oops! I just noticed there is one difference in code. On Raspberry Pi I initialize the audio like this:

Code: [Select]
if (!BASS_Init(cfg.audio_device, 22050, 0, NULL, NULL)) {

I'll try 44100 in a bit and see if that fixes things.

goobliata

  • Posts: 28
Re: BASS for ARM Linux
« Reply #243 on: 10 Nov '14 - 18:31 »
Ok, I tried it at 44100 Hz, now the code is identical, and it still sounds out of tune. Seems that some spots in songs are more out of tune than others, but I'm not sure why.

Ian @ un4seen

  • Administrator
  • Posts: 22059
Re: BASS for ARM Linux
« Reply #244 on: 11 Nov '14 - 17:36 »
I didn't notice anything obviously different when playing that MIDI file on ARM Linux and Windows. Is there a position that a difference should be most noticeable at?

What soundfont are you using, and does changing that make any difference? One thing I notice is that the MIDI file is using the flute preset, which I think is a bit detuned in the ChoriumRevA soundfont, so if you are using that soundfont then perhaps that's what you're hearing.

goobliata

  • Posts: 28
Re: BASS for ARM Linux
« Reply #245 on: 11 Nov '14 - 17:42 »
I'll try a different soundfont and report back. I think I did upload the soundfont to you at one point (retro.sf2). If the problem were occuring for you you would definitely notice it, it sounds very different with that MIDI.

Ian @ un4seen

  • Administrator
  • Posts: 22059
Re: BASS for ARM Linux
« Reply #246 on: 12 Nov '14 - 17:45 »
Ah yes, I can hear the difference when using the RETRO.SF2 soundfont. It was caused by the ARM Linux compiler defaulting to treating "char" as unsigned while BASSMIDI expects it to be signed. A BASSMIDI update to fix that is now up in the 1st post. This update also includes the SFZ support introduced here: www.un4seen.com/forum/?topic=12405

goobliata

  • Posts: 28
Re: BASS for ARM Linux
« Reply #247 on: 12 Nov '14 - 17:49 »
Awesome! Thanks a lot.

Ian @ un4seen

  • Administrator
  • Posts: 22059
Re: BASS for ARM Linux
« Reply #248 on: 9 Dec '14 - 17:41 »
The ARM Linux versions of the recent BASSFLAC (2.4.2) and BASSMIDI (2.4.9) releases are now up in the 1st post.

mikem

  • Posts: 2
Re: BASS for ARM Linux
« Reply #249 on: 22 Dec '14 - 13:21 »
Hi there, I started using the library today - fantastic. I've got 90% of what I need to get done - done, however I've found one problem that I can't resolve.

I'm using a C# application with BASS.Net (v2.4, downloaded 23DEC2014). I'm using the Mono framework, and it's all running on Arch Linux on a Raspberry Pi.

The BASS 2.4 library was also downloaded from this site on the same day.

If I use the Windows BASS.Net and BASS libraries, my little console test application works perfectly on windows.
If I switch the .NET reference to the BASS.Net.Linux library and run it with mono on Linux, it has a small problem. Based on the fact that the same code works on Windows - I'm wondering if this is an issue with the library on ARM Linux. I couldn't find a previous version of the library to try however.

Here's a quick rundown of the code. For reasons that don't really matter to the problem, I'm:
1. receiving a small segment of audio data via a TCP stream into a byte array.
2. determining the size of that audio data, and then putting the byte array into a memorystream.
3. using BASS_StreamCreate and a STREAMPROC to read the data from the memorystream.

This works perfectly! The whole thing then repeats waiting for the next audio stream to come in over the network. Here's where the problem starts.

On windows, it simply plays the second stream, and the third, and fourth etc. On Linux, the screen output *looks* like it's working properly, but I don't hear any audio. In fact, the only way I can get the code to play audio the second/third/fourth time - is if I call BASS_Free() and then re-call BASS_Init() after I play each stream. Windows - its fine though. Ideally I want to be able to keep playing audio streams without having to reinitialize the BASS library each time.

Really appreciate the help - I can't work out what I'm doing wrong. I've also tried:
1. Push streams - re-using the one stream, and then just sending more push data as new audio comes in from the network.
2. Push streams - creating and releasing a new stream each time.
3. pausing/resuming stream after each occurrence.
4. checking if stream is stalling/running properly - which it appears to. it stalls after the first audio stream has finished, then once more data comes in it runs again.

All of these have the same result - it reports that its working correctly, but I just don't hear any audio after the first stream has played.

Here's the code. It is messy - this is purely the 'proof of concept' test code before I turn it into something pretty and error checking, good practices etc.

using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Runtime.InteropServices;
using Un4seen;
using Un4seen.Bass;
using Un4seen.BassAsio;
using Un4seen.BassWasapi;

namespace SpeechTestHarness
{
   class Program
   {
      static NetworkStream networkStream;
      static int iAudioSize;
      static MemoryStream _fs;
      private static STREAMPROC _myStreamCreate;
      private static byte[] _data = null;

      private static int MyFileProc(int handle, IntPtr buffer, int length, IntPtr user)
      {
         Console.WriteLine("MyFileProc()");

         if (_data == null || _data.Length < length)
            _data = new byte[length];

         int bytesread = _fs.Read(_data, 0, length);
         Marshal.Copy(_data, 0, buffer, bytesread);
         if (bytesread < length)
         {
            bytesread |= (int)BASSStreamProc.BASS_STREAMPROC_END;
            networkStream.Close();
         }

         return bytesread;
      }
   
      static void Main(string[] args)
      {
         Un4seen.Bass.BassNet.Registration("email", "key");
         
         if (!Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
            Console.Write("BASS_Init() failed");

         while (true)
         {
            // Endless loop
            run();
         }

         //Bass.BASS_Free();
      }
      
      static void run()
      {
         byte[] bytes;
         byte[] btSize = (byte[])Array.CreateInstance(typeof(byte), 4);
         int iCounter = 0;

         TcpClient tcpClient = new TcpClient();

         Console.WriteLine("run");
         _myStreamCreate = new STREAMPROC(MyFileProc);

         // Get Audio Stream
         tcpClient.Connect("172.16.51.20", 64004);

         networkStream = tcpClient.GetStream();

         // First 4 bytes contain size of audio segment
         if (networkStream.Read(btSize, 0, 4) != 4)
         {
            Console.WriteLine("run - couldn't get audio size");
            return;
         }

         iAudioSize = BitConverter.ToInt32(btSize, 0);
         Console.WriteLine("Audio Size: " + iAudioSize.ToString());

         // Allocate overly large receive buffer
         bytes = new byte[1280000];

         while (iCounter < iAudioSize)
         {
            // read 32k chunk
            int z = networkStream.Read(bytes, iCounter, (int)32000);

            iCounter += z;
         }

         _fs = new MemoryStream(bytes, 0, iAudioSize);

         // create stream
         int channel = Bass.BASS_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT, _myStreamCreate, IntPtr.Zero);
         Bass.BASS_ChannelPlay(channel, false);         

         // wait for audio to finish
         System.Threading.Thread.Sleep(3000);

         Bass.BASS_StreamFree(channel);
      }
   }
}