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

Jocelynk

  • Guest
Re: BASS for ARM Linux
« Reply #150 on: 15 Dec '13 - 11:39 »
Hi,

Yes I actually save the return from the function, I just did not copied it here. And yes the BASS_ChannelGetData is called inside a loop.

Chris

  • Posts: 1810
Re: BASS for ARM Linux
« Reply #151 on: 15 Dec '13 - 13:53 »
by the way
Quote
Like the Android and Windows CE versions, BASS for ARM Linux uses fixed-point rather than floating-point, so some things are a bit different to the "normal" Linux version... The BASS_SAMPLE_FLOAT flag isn't supported

Jocelynk

  • Guest
Re: BASS for ARM Linux
« Reply #152 on: 15 Dec '13 - 14:15 »
Oh ok, thanks ! But if I remove this flag from the call, my fft return 0 for each bin..

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for ARM Linux
« Reply #153 on: 16 Dec '13 - 15:22 »
I'm trying to use Bass on my Beaglebone (ARM) to compute a simple fft, but this is not working like expected... The operation I try to make after is
Code: [Select]
BASS_ChannelGetData(chan,fft,32);

To receive FFT data from BASS_ChannelGetData, you should use one of the BASS_DATA_FFT flags in the call. Note the returned data will be in 8.24 fixed-point form. If you would like to convert it to floating-point, here is some example code for doing that...

   www.un4seen.com/forum/?topic=13804.msg99735#msg99735

Jocelynk

  • Posts: 7
Re: BASS for ARM Linux
« Reply #154 on: 16 Dec '13 - 19:15 »
Hi Ian,

Well, I only need a few bins so I thought I could set my own value at the call.

I tried your code but I'm still seeing 0.0 everywhere, I don't use hardfp version because it makes a segmentation fault when I run my program. Here is my code :

Code: [Select]
int main()
{
   // check the correct BASS was loaded
    if (HIWORD(BASS_GetVersion())!=BASSVERSION) {
        std::cout << "An incorrect version of BASS was loaded" << std::endl;
        return 0;
    }

    // initialize BASS
    if (!BASS_Init(0,0,0,NULL,NULL)) {
        std::cout << "Can't initialize device" << std::endl;
        return 0;
    }

    DWORD chan;

    if (!(chan=BASS_StreamCreateFile(FALSE,"eminem.mp3",0,0,BASS_SAMPLE_LOOP|BASS_STREAM_DECODE)) ) 
    {
        std::cout << "Can't play file: Error = " << BASS_ErrorGetCode() << std::endl;
        BASS_Free();
        return 0;
    }

    BASS_ChannelPlay(chan,FALSE);
    while(1)
    {
        int fft[512]; // fft data buffer
        DWORD res = BASS_ChannelGetData(chan, fft, BASS_DATA_FFT1024);
        if (res==-1)
        {
            std::cout << "Can't compute fft: Error = " << BASS_ErrorGetCode() << std::endl;
            BASS_Free();
            return 0;
        }else
            std::cout << res << std::endl;
       
        int i;
        for (i=0; i<512; i++) {
            float f=(float)fft[i]/(1<<24);
            printf("%f ", f);
        }

        sleep(2);
    }

    BASS_Free();
    return 0;
}

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for ARM Linux
« Reply #155 on: 18 Dec '13 - 17:55 »
That seems strange. Do the 0 results continue thoughout the file, not just at the start? MP3 files can have some silence/delay at the start. Please also try a WAV file and see if you get the 0 results with that too.

If you don't need so many bins, you could replace BASS_DATA_FFT1024 with BASS_DATA_FFT256 in the BASS_ChannelGetData call; 256 bins (first 128 returned) is currently the minimum that BASS allows.

Jocelynk

  • Posts: 7
Re: BASS for ARM Linux
« Reply #156 on: 19 Dec '13 - 20:36 »
Hi Ian,

Thanks for your help, I'm positive it's not a silence at the start. I've tried with a wav file and it works so I tried with an other mp3 file and it works... Strange, just bad luck with the first file I guess.

I'll continue my investigation, thanks for your time !
« Last Edit: 21 Dec '13 - 13:28 by Jocelynk »

Jocelynk

  • Posts: 7
Re: BASS for ARM Linux
« Reply #157 on: 21 Dec '13 - 13:28 »
I find very different results when I run the code on my beaglebone or on my computer, I don't mean the values, I know on ARM version the output format is 8.24 fixed point form; but in the higher part of the fft array result, on beaglebone I have a lot of zeros whereas on computer I have non zero values. My aim is to make an spectrum visualizer, but I have a lots of difficulties with output values.

Ex of values :
0.232064 0.0137933 0.00367022 0.00106418 0.00133717 0 0.000422835 0.000244141 0 0.000244141 0 0 0 0.000244141 0.000422835 0.000422835 0.000244141 0.000244141 0 0 0.000244141 0 0.000244141 0 0 0 0 0.00034523 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0
« Last Edit: 21 Dec '13 - 17:42 by Jocelynk »

Grosche

  • Posts: 3
Re: BASS for ARM Linux
« Reply #158 on: 1 Jan '14 - 16:45 »
Hi,

thank you for the great port to the ARM (especially the Raspberry Pi). Playing music using the BASS_StreamCreateFile method works fine,
but I did not get recording samples to work. My target is to record samples and process them, so I would like to get them as float values.

I am confused about the BASS_RecordStart function. E.g. on Windows, no flag would lead in 16 bit signed integer samples.
If I am right, on the Raspberry Pi, this would lead in 32 bit fixed point integer samples.

When I do the trick mentioned by Ian converting the samples from int to float using
float f=(float)recorded_samples/(1<<24); (where recorded_samples are the 32 bit fixed point integer values)
I am getting large values for the samples (outside the range -1 to 1).
When I normalize them, I get something like the attached image that represents the sample values over time (recording a sinus).


It would be nice if anyone could post a short example code that explains how to record samples as float values.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for ARM Linux
« Reply #159 on: 2 Jan '14 - 17:31 »
Only 16-bit and 8-bit recording is currently supported in the ARM Linux version; the BASS_SAMPLE_FLOAT flag isn't supported by BASS_RecordStart. If you would like to have the recorded data in floating-point anyway, you would record in 16-bit and then divide the 16-bit values by 32768...

Code: [Select]
BOOL CALLBACK MyRecordProc(HRECORD handle, const void *buffer, DWORD length, void *user)
{
float *fbuf=(float*)malloc(length*2);
for (int a=0; a<length/2; a++)
fbuf[a]=((short*)buffer)[a]/32768.f;
// do something with floating-point data in "fbuf" here
free(fbuf);
return TRUE; // continue recording
}

...

HRECORD record=BASS_RecordStart(44100, 2, 0, MyRecordProc, NULL); // start recording

Grosche

  • Posts: 3
Re: BASS for ARM Linux
« Reply #160 on: 3 Jan '14 - 10:02 »
Hi Ian,

thank you very much for your hint.

My fault was to try to record using one channel like this:
Code: [Select]
HRECORD record=BASS_RecordStart(44100, 1, 0, MyRecordProc, NULL);

This works perfectly with a Windows PC but produces junk on the Raspberry Pi.
Using two channels for recording works perfectly.

Some more information what I am trying:
I want to record what I hear from the PC respectively Raspberry Pi.
On the PC, there is the "Stereomix" provided by my sound card (seems to "natively" provide stereo).
On the Raspberry Pi, I am using PulseAudio to loop back what I hear (also seems to "natively" provide stereo).


So attached are some measurements I made:
- I recorded a 440 sinus wave
- shown are 512 samples
- samplerate was 44100 Hz

Raspberry Pi - recording stereo, samplerate 44100 Hz, 512 samples - 440 Hz sinus.png:
- Raspberry Pi
- recording two channels (stereo)
- shown are both channels at once (512 samples I get from the BASS dll)
- Expected: 440Hz / 44100Hz * 512 Samples = ca. 5 sinus waves
- Result: ca. 2.5 sinus waves because the samples of two channels are mixed together.
- Works perfectly

Windows PC - recording mono, samplerate 44100 Hz, 512 samples - 440 Hz sinus.png
- Windows PC
- recording one channel (mono)
- shown is the single channel (512 samples I get from the BASS dll)
- Expected: 440Hz / 44100Hz * 512 Samples = ca. 5 sinus waves
- Result: what expected
- Works perfectly

Raspberry Pi - recording mono, samplerate 44100 Hz, 512 samples - 440 Hz sinus.png
- Raspberry Pi
- recording one channel (mono)
- shown is the single channel (512 samples I get from the BASS dll)
- Expected: 440Hz / 44100Hz * 512 Samples = ca. 5 sinus waves
- Result: something with 5 Periods but not a sinus
- Does not work for me

Summary:
Something seems to go wrong mixing stereo to mono on the Raspberry Pi. Maybe this could be a problem of PulseAudio..
As a workaround, I will record two channels and mix them together on my own.

Thank you again for your support.

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for ARM Linux
« Reply #161 on: 6 Jan '14 - 17:55 »
That's strange. I guess you're using PulseAudio's "Monitor of..." input device option to record from? Unfortunately, PulseAudio isn't currently setup on an RPi device here, but I tried mono recording from PulseAudio's "Monitor of..." input on desktop Linux and that worked fine. BASS doesn't handle the stereo to mono conversion itself, but rather just tells ALSA what sample format is wanted and lets it take care of any necessary conversion (BASS_RecordStart will fail if the requested format is rejected by ALSA). To help narrow down the source of the problem, can you try recording in mono from any other devices, eg. a USB soundcard? If so, also try recording directly via ALSA rather than PulseAudio, eg. use device=1 rather than device=0 (or -1) in your BASS_RecordInit call.

Grosche

  • Posts: 3
Re: BASS for ARM Linux
« Reply #162 on: 8 Jan '14 - 16:07 »
Hi Ian,

thank you very much again for your reply.
It is correct, that I am using the "Monitor of ..." input from PulseAudio.

I am sorry that I don't have any USB soundcard here to test what you mentioned. Unfortunately, it may be a while until I will get one because the workaround works so far and I have some other stuff to do before.
I will come back here, as soon as I will have tested a USB soundcard.

serkanp

  • Posts: 67
Re: BASS for ARM Linux
« Reply #163 on: 10 Jan '14 - 15:34 »
hi ian :)
we have raspberry pi as you know (or might not remember) :))
anyway, we now also have cubieboard 2, which is armv7 , and this build does not work on cubieboard 2 device, because it is armv6..  :))
i know your face become red and you are angry.. grr.. why again a new platform to maintenence..etc..

why we are using cubieboard 2:
Some difference highlights from specs  (cb2 vs rpi):
1G ARMv7 cortex-A8 processor (2x as fast per clock), NEON, VFPv3, 256KB L2 cache vs 700MHz ARMv6
Mali400, OpenGL ES GPU (lima reverse-engineered drivers) vs VideoCoreIV (free "shim")
1GB DDR3 @480MHz vs 512MB DDR2
10/100M Ethernet MAC built in the SoC vs USB 10/100M ethernet
4GB Nand Flash vs nothing
SATA2 port vs none
2 USB Host vs 2 USB + ethernet from 1 USB via builtin hub
MicroSD vs SD
Costs $59, ~$45.

so do you plan to support arm v7?
today i compiled my app, and see that there is something happening , and giving errors..

serkanp

  • Posts: 67
Re: BASS for ARM Linux
« Reply #164 on: 10 Jan '14 - 15:36 »
by the way, i am using hardfp cubian (debian 7.x wheezy) on cubieboard 2

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for ARM Linux
« Reply #165 on: 10 Jan '14 - 17:37 »
What error messages are you getting? ARMv7 is back-compatible with ARMv6, so I don't think that's the issue.

Serkan Polat

  • Guest
Re: BASS for ARM Linux
« Reply #166 on: 10 Jan '14 - 17:56 »
bass unknown error on init

serkanp

  • Posts: 67
Re: BASS for ARM Linux
« Reply #167 on: 13 Jan '14 - 13:51 »
cubie@Cubian:~$ sudo ldconfig -p |grep bass
        libbassopus.so (libc6,hard-float) => /usr/lib/libbassopus.so
        libbassmix.so (libc6,hard-float) => /usr/lib/libbassmix.so
        libbassflac.so (libc6,hard-float) => /usr/lib/libbassflac.so
        libbassenc.so (libc6,hard-float) => /usr/lib/libbassenc.so
        libbass.so (libc6,hard-float) => /usr/lib/libbass.so

Code: [Select]
BassNet.Registration("xxx@xxx.com", "xxxxxxxxxx");
            try
            {
                // Console.WriteLine("registered bass" + Bass.BASS_GetVersion());
                if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
                {

                    Console.WriteLine("Bass init success");
                    BASS_INFO info = new BASS_INFO();
                    Console.WriteLine("Bass info success");
                    Bass.BASS_GetInfo(info);
                    Console.WriteLine("Bass info printed");
                    Console.WriteLine(info.ToString());
                }
                else
                {
                    Console.WriteLine("Create error" + Bass.BASS_ErrorGetCode());
                }

               

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Create error" + Bass.BASS_ErrorGetCode());
            }


when calling:
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)

Bass.BASS_ErrorGetCode() says : BASS_ERROR_UNKNOWN


same code, same so files , everything same..
one runs on raspberry pi without any problem.
cubieboard 2 gives the error..

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for ARM Linux
« Reply #168 on: 13 Jan '14 - 16:31 »
when calling:
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)

Bass.BASS_ErrorGetCode() says : BASS_ERROR_UNKNOWN

Is ALSA playback working in other programs, eg. in aplay? If so, I'll send you a debug BASS version to get some more information on what's going wrong in BASS's case.

What does the device list look like, ie. via BASS_GetDeviceInfo?

serkanp

  • Posts: 67
Re: BASS for ARM Linux
« Reply #169 on: 14 Jan '14 - 07:47 »
0-No sound
1-Default
2-sunxi-CODEC: sunxi PCM
3-sunxi-sndhdmi:


mplayer, ffplay and vlc plays audio files without any problem..

aplay plays buggy.. there is a noisy sound comes when playback..

serkanp

  • Posts: 67
Re: BASS for ARM Linux
« Reply #170 on: 14 Jan '14 - 08:06 »
this is the mplayer output:

cubie@Cubian:~$ mplayer love1.mp3
MPlayer svn r34540 (Debian), built with gcc-4.6 (C) 2000-2012 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.

Playing love1.mp3.
libavformat version 53.21.1 (external)
Mismatching header version 53.19.0
Audio only file format detected.
Clip info:
 Title: L-O-V-E
 Artist: Nat King Cole
 Album: The Unforgettable Nat King Col
 Year:
 Comment:
 Track: 5
 Genre: Unknown
Load subtitles in ./
==========================================================================
Requested audio codec family [mpg123] (afm=mpg123) not available.
Enable it at compilation.
Opening audio decoder: [ffmpeg] FFmpeg/libavcodec audio decoders
libavcodec version 53.35.0 (external)
Mismatching header version 53.32.2
AUDIO: 44100 Hz, 1 ch, floatle, 320.2 kbit/22.69% (ratio: 40025->176400)
Selected audio codec: [ffmp3float] afm: ffmpeg (FFmpeg MPEG layer-3 audio)
==========================================================================
AO: [pulse] Init failed: Connection refused
Failed to initialize audio driver 'pulse'
AO: [alsa] 44100Hz 1ch floatle (4 bytes per sample)
Video: no video
Starting playback...
A:   8.8 (08.8) of 153.0 (02:33.0)  1.7%




serkanp

  • Posts: 67
Re: BASS for ARM Linux
« Reply #171 on: 14 Jan '14 - 08:33 »
ok now i have some interesting results..
after installing alsa-base alsa-utils pulseaudio mpg123 pavucontrol
 
Bass started working
Bass init success
Bass info success
Bass info printed
Speakers=2, MinRate=0, MaxRate=0, DX=0, EAX=False
devices installed:
0-No sound
1-Default
2-sunxi-CODEC: sunxi PCM
3-sunxi-sndhdmi:
device print finished


but:
Code: [Select]
_stream = Bass.BASS_StreamCreateFile("/home/cubie/love1.mp3", 0, 0, BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_SAMPLE_FLOAT);
 Bass.BASS_ChannelPlay(_stream, false);

 Bass.BASS_ErrorGetCode() gives BASS_ERROR_FORMAT

if i use :
Code: [Select]
_stream = Bass.BASS_StreamCreateFile("/home/cubie/love1.mp3", 0, 0, BASSFlag.BASS_DEFAULT);
or
 _stream = Bass.BASS_StreamCreateFile("/home/cubie/love1.mp3", 0, 0, BASSFlag.BASS_STREAM_PRESCAN );


it plays the file without any problem..

so our problem is here: BASSFlag.BASS_SAMPLE_FLOAT


ps: aplay still the same, a buggy noise comes when playing any mp3.. others works without any problem (mplayer, ffplay, vlc)


« Last Edit: 14 Jan '14 - 08:38 by serkanp »

Ian @ un4seen

  • Administrator
  • Posts: 20437
Re: BASS for ARM Linux
« Reply #172 on: 14 Jan '14 - 16:14 »
Yep, floating-point output (eg. BASS_SAMPLE_FLOAT) isn't supported in the ARM Linux version of BASS. Apart from that, is it working OK now? :)

serkanp

  • Posts: 67
Re: BASS for ARM Linux
« Reply #173 on: 19 Feb '14 - 14:21 »
i forgot to answer..
yes it works perfect now.. :) thank you..
ps: you have to write in help files or somewhere that it does not support floating-point on arm :)))

zittergie

  • Posts: 31
Re: BASS for ARM Linux
« Reply #174 on: 21 Feb '14 - 20:24 »
Hi,
Just received my odroid-u3 board running Ubuntu 13.10 arm, so I tried the BASS library on it, but all i got is crackled sound.
Works perfectly on the Raspberry Pi.

This Linux distro uses Pulseaudio.  Changing the Pulseaudio to none and Changing it back to duplex output while playing the audio fixes the problem.  When fixed, as long as the music plays, even loading New songs work fine. When the playback stops and you start a new song, the crackled sound comes back.

Other apps play like it should.

What do you need to solve this problem?