Author Topic: Using BASS with language Ada 2012  (Read 139 times)

AdaLovelace

  • Posts: 1
Using BASS with language Ada 2012
« on: 28 Nov '21 - 12:47 »
Hello all!

I am primary and Ada programmer but do know some C. I can use BASS with the C language to create a command line single program to play a WAV file (using PlaySound) or
use this function:

Code: [Select]
int
playBGM (char *filename)
{
   FILE *fptr = fopen (filename, "r");

   if (fptr == NULL)
      {
         fclose (fptr);
         return EXIT_FAILURE;
      }
   else
      {
         
        BASS_Init(-1, 44100, 0, 0, NULL);
        BASS_SetVolume(1);
        HSAMPLE sample = BASS_SampleLoad(FALSE, filename, 0, 0, 1, BASS_SAMPLE_MONO);
        HCHANNEL channel=BASS_SampleGetChannel(sample, FALSE);
        BASS_ChannelPlay (channel, FALSE);
      }
   fclose(fptr);
   return EXIT_SUCCESS;
}

which plays a full mp3 file. Everything will work as expected.

Now, I would love to continue to use BASS with the Ada language, and although it does not fully support it - in the documentation it explains you can use other languages with BASS.
I do not know if many (or any) of you guys are familiar with the Ada language, but Ada is fully compatible with C. I am currently running a test program to see if I can create a command line program to use the above function but have the calling procedure written in Ada. To give you a better understanding, here is the code in full.

audio.h
Code: [Select]
#ifndef AUDIO_H
#define AUDIO_H

#pragma comment(lib, "-winmm");
#pragma comment(lib, "C:/Users/Amynu/OneDrive/Documents/Not Again Alice/Codex/ExternalLibs/bass24/x64/bass");
#pragma comment(lib,"C:/Users/Amynu/OneDrive/Documents/Not Again Alice/Codex/ExternalLibs/bass24/c/bass");

#include <windows.h>
#include <mmsystem.h>
#include <bass.h>

#define MUSIC_PATH ""

int playBGM (char *);
int playSFX (char *);

#endif

audio.c
Code: [Select]
#include "audio.h"
#include <stdio.h>
#include <stdlib.h>

extern int playBGM (char *f);

int
playBGM (char *filename)
{
   FILE *fptr = fopen (filename, "r");

   if (fptr == NULL)
      {
         fclose (fptr);
         return EXIT_FAILURE;
      }
   else
      {
         
        BASS_Init(-1, 44100, 0, 0, NULL);
        BASS_SetVolume(1);
        HSAMPLE sample = BASS_SampleLoad(FALSE, filename, 0, 0, 1, BASS_SAMPLE_MONO);
        HCHANNEL channel=BASS_SampleGetChannel(sample, FALSE);
        BASS_ChannelPlay (channel, FALSE);
      }
   fclose(fptr);
   return EXIT_SUCCESS;
}

int
playSFX (char *filename)
{
   FILE *fptr = fopen (filename, "r");

   if (fptr == NULL)
      {
         fclose (fptr);
         return EXIT_FAILURE;
      }
   else
      {
         PlaySound (TEXT (filename), NULL, SND_ALIAS | SND_APPLICATION);
      }
   fclose (fptr);
   
   return EXIT_SUCCESS;
}

Main.adb
Code: [Select]
with Interfaces.C; use Interfaces.C;

procedure Main is
    res : Integer := 0;
    f : String := "";
   
    function Play_BGM(f : in String) return Integer with
    Import => True, Convention => C, External_Name => "playBGM";
begin
   res := Play_BGM(f);
end Main;


Here is the error messages:

Code: [Select]
gprbuild -d -PC:\Users\Amynu\OneDrive\Documents\Not Again Alice\Codex\notagainalice.gpr
Compile
   [C]            audio.c
Link
   [archive]      libnotagainalice.a
   [index]        libnotagainalice.a
   [link]         main.adb
c:/gnat/2021/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.1/ld.exe: libnotagainalice.a(audio.o):audio.c:(.text+0x5d): undefined reference to `BASS_Init'
c:/gnat/2021/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.1/ld.exe: libnotagainalice.a(audio.o):audio.c:(.text+0x6a): undefined reference to `BASS_SetVolume'
c:/gnat/2021/bin/../libexec/gcc/x86_64-w64-mingw32/10.3.1/ld.exe: libnotagainalice.a(audio.o):audio.c:(.text+0x94): undefined reference to `BASS_SampleLoad'

If I compile this using "GNAT Community Edition 2021", which uses the GNAT compiler for the Ada code and the GCC compiler for the C code - it does compile. My problem, is the Linker
has problems locating the function definitions of the BASS libraries to play the music, even though the <bass.h> header is included and the code witihin it compiles. I would love any
help on how to fix this issue.

Also, if anyone else knows how to get Ada OpenAL to work properly, then bonus kudos!

Thank you in advance for any help or suggestions.

Sorry for the lengthy post - but I needed to be clear where the problem is.