uos icon indicating copy to clipboard operation
uos copied to clipboard

No external libraries

Open JonnyTech opened this issue 3 years ago • 9 comments

I am looking for a solution that generates an audio test tone (1kHz sine wave) in pure pascal code without any additional libraries. Is uos capable of that? It seems to have dependencies on lots of external libraries.

JonnyTech avatar Jan 17 '21 01:01 JonnyTech

Hello.

Of course you may generate waves (sine, square, tooth) with uos for Linux, Windows, MacOSX, FreeBSD, Rpi. You will need only the PortAudio library (that is included in uos package but you may also use the one provided by nearly all Unix distribution).

You may take a look at example consolesynth.pas: https://github.com/fredvs/uos/blob/master/examples/consolesynth.pas

Only one dependency is needed; for example in Linux:

PA_FileName :=  '../lib/Linux/64bit/LibPortaudio-64.so';
uos_LoadLib(PChar(PA_FileName), nil, nil, nil, nil, nil);

If you prefer to use the library installed on the system:

uos_LoadLib(PChar('system'), nil, nil, nil, nil, nil);

With uos you may load only the libraries you need.

PortAudio to communicate with the sound-card and produce synthesized sound. SndFile to decode-encode wav, ogg, flac audio files. Mpg123 to decode and web-stream of mp3 files. OpusFile to decode and web-stream of opus files. Mp4ff to decode and web-stream of Apple files.

Now if you need to have something for Linux that produces waves using the less library, you may take a look at: https://github.com/fredvs/alsa_sound

It uses only libasound.so system library that is installed in nearly all Linux distros.

fredvs avatar Jan 17 '21 01:01 fredvs

Thank you for your quick reply, but as stated, I am needing to do it purely in code without external libraries. This is because I am developing without an operating system aka bare metal. Is the pascal source for the PortAudio library available? I can then generate a PCM stream and pass it to the hardware sink. If a simple test tone works then I can think about decoding other file formats using a similar method.

JonnyTech avatar Jan 17 '21 11:01 JonnyTech

Hello.

I fear that that it will be difficult to access the sound card (input/output) without any dependencies. PortAudio has a Pascal translation of the C header (see uos_portaudio.pas).

How do you do to pass the PCM to the hardware? Could you explain what is your goal, do you want to create your own OS? If yes, is it a completely new OS or is it based on a other, like Unix?

fredvs avatar Jan 17 '21 12:01 fredvs

The framework produces a kernel image that talks to the hardware, no intermediate OS involved: ultibo.org

Audio is passed as a PCM stream. That works well.

There is some reliance on c libraries to do encoding/decoding of certain formats.

I like a pure pascal implementation and saw that uos offered open source solutions so was hoping to use it.

Hence start with generating a test tone. If that works then decode mp3, etc. All done without external reliance.

If uos is not suitable then can you recommend an alternative?

JonnyTech avatar Jan 17 '21 13:01 JonnyTech

Ha ok, you will use Ultibo. There was a forum about this (you need a Ultibo account). (ultibo.org forum / Board/ index / General / Feature requests)

https://ultibo.org/forum/viewtopic.php?f=12&t=497

I did propose to add libmpg123 and libsndfile. I dont know if they commit it because Ultibo seems to be "paused".

fredvs avatar Jan 17 '21 13:01 fredvs

Note that here is a work-in-progress to make fpGUI compatible with Ultibo.

Also there was plan to make MSEgui part of Ultibo. Martin was busy on this with Ultibo team just before to leave us. This affect a lot all of us (and seriously damaged our enthusiasm to continue Ultibo develop). I really hope that Ultibo will still be developed.

fredvs avatar Jan 17 '21 14:01 fredvs

Thanks for the links. Ultibo seems to mature enough for my needs. It is on pause until the fpc team transistion from svn to git. Not a big deal.

I do not use it with a display so currently do not care about gui. A headless setup with some audio output is my first real test.

But I am a purist and looking to do it all in open source pascal code, hence my reluctance to use c libs. Although a challenge, it should be possible.

JonnyTech avatar Jan 17 '21 17:01 JonnyTech

Hello.

Yes, it would be good to have a full Pascal IO audio library.

Martin and I did a project to access audio. It is in C but would be easy to translate in Pascal. https://github.com/fredvs/pcaudiolib_io

Here the Pascal header: https://github.com/fredvs/pcaudiolib_pas

It is based on a GPL library, I dont know if you take inspiration from it and convert it into Pascal what would append with the license.

fredvs avatar Jan 17 '21 17:01 fredvs

My c is rubbish but I shall certainly take a look if I cannot find an alternative.

JonnyTech avatar Jan 17 '21 18:01 JonnyTech