PDA

View Full Version : cross platform audio project possible in pascal?



laggyluk
30-03-2013, 01:26 PM
I'm thinking about music creation tool that would run on pc, android and ios. something in flavour of sunvox
http://www.warmplace.ru/soft/sunvox/
You guys think that it would be possible to do it in pascal? So far for mobile projects I used engines like unity or marmalade but this time I'd stick to pascal if possible. Not sure where to start though..

phibermon
30-03-2013, 04:57 PM
Sunvox is awesome :) been playing around with that and yes, it's perfectly possible to create a cross platform DAW/Sequencer using freepascal. You'll need to support sound out on all OSes however and MIDI or at least OSC support would be a good idea. There are existing audio frameworks that you can examine to get started :

Audorra - http://audorra.sourceforge.net/ (http://audorra.svn.sourceforge.net/viewvc/audorra/src/)

An incomplete yet fully usable audio lib, supports various audio API's but hasn't been updated in a while. It does however have a nice design and is coded very well. Last time I checked it lacked support for ASIO (windows) CoreAudio (OSX) and ALSA and JackD (Posix systems, Linux etc) so it's not suitable if you're looking for low latency, realtime processing for live performance etc also doesn't have any support for things like Rewire (Win) or Lash (Posix) and doesn't handle MIDI. It's perfect for games however and by the looks of some of the classes it does look like the devs were thinking about it's use outside of games (FFT etc)

Delphi ASIO & VST packages - http://sourceforge.net/p/delphiasiovst/code/1707/tree/ (You must check out the latest version from the revision server as the standard releases are old now)

Now this is more like it, filled with algorithms I do not understand but clearly they do very, very well. Intended for Object pascal coders looking to work with ASIO, audio processing and VST plugins (and writing VST plugins) has support for MIDI (for VSTs etc) this is filled with all the code you could ever need to study to become an audio dev. it has an extensive DSP part with all manner of things such as Oscillators, Modulators, Spectral Filters, Vocoders, Reverb + Delay etc as well as a an extensive GUI lib intended for the creation of VST plugins and what not. It also has the beginnings of a modular synth setup, plus stuff I don't understand.

Unfortuantly this project is windows focused, no support for any other OSes however much of their code can be used cross platform but you'll be managing the interface with audio hardware yourself, plus doing a lot of refactoring! But highly reccomended!

Now I've been producing music for many years and in between my game engine development work I've been working on a cross platform sequencer/DAW, what I've basically done is written my own audio lib similar to Audorra (design not dis-similar and as I learned things from audorra I do link it and credit it in my docs) but focused supporting the music grade API's on the various platforms, so I have my own ASIO driver, my own CoreAudio driver and ALSA and Jack on linux. I also support OpenAL and I'm adding support for other Windows techs (for completeness).

I'm linking to (and refactoring where necessary) as much of DelphiASIOVST as I can so my software can make use of the high end code developed by those awesome people but only in areas that are abstractions away from platform specifics, so algorithms and things from the DSP, useful things I've learned from their ASIO helper classes etc

GUI is the question, I'm currently using my JUI gui (OpenGL, per surface buffers) but that means I'm forcing an OpenGL requirment on users (however I am working on a software renderer because of this). And it's difficult to create things that look nice in Lazarus without pretty much rendering everything yourself, so if you have dreams of creating the next FL Studio 10 or Ableton Live 9 you must understand that the level of work required there will dwarf an audio engine (but not match it for complexity)

Obviously it doesn't really matter what it looks like to an audiophile but I'd argue that win32 widget driven apps like Cubase 5 and Sonar X2 suffer for it in terms of usability. Compare the FL Studio piano roll to cubases for example, FL is so well designed that it's super fast to make changes and work on new ideas. Cubase you're messing about for 3 times as long before you can listen to it and decide you don't like it.

Anyway, yes do it! work on a cross platform audio app be sure to keep your internals seperate from your driver bits so you can swap in better support for alternate platforms at a later stage and then just use somthing that gives you sound buffers to write to (BASS, Audorra, FMod whatever)

Focus on the bits where you can innovate such as the layout of the mixing chain or the interface etc

Or of course join me on the dark side, nobody ever does however despite me asking and hinting. Everybody likes to work on their own stuff (that's why we have like 30 odd unfinshed engines floating about here instead of just a few Ogre competiors) I guess everybodies code and designs are better than everybody elses ;)

EDIT : incidently FL Studio up to the very latest version 10, is written in Delphi! they still use the OpenASIO.dll that was written years ago too. The DelphiASIOVST people support OpenASIO, but it looks as if they've come up with their own solution that uses a bit of ASM code to retrive the COM interface without a C wrapper. I'm not sure if that's correct but it does look that way. The boss as Image Line should really hire those guys. (and me, hire me please, you're my heros) Anyway, that's why you've not seen a mac version of FL Studio yet although I suspect the long period of time since FL Studio 10's release is an indication that they may be working on some major changes which might include using the latest delphi to finally support macs.

laggyluk
30-03-2013, 07:04 PM
wow a lot of info, thanks! I'm a guitar player and what I have in mind is something between guitar pro and sequencer. It would serve for prototyping music rather than producing. So no vst support needed, maybe recording audio input but not necessary with live monitoring. In terms of interface I don't need anything fancy, sunvox for example has it really simplisitc but it does the job.
What worries me is the gap between my pc and ios ;p or android for that matter. I'd need to make the build separatley on win, mac os and linux I guess? Since all I need is opengl es and access to raw sound buffer maybe there is some library that would help with the platform dependend code. Like sdl or sth? not much info on the audorra page

Super Vegeta
30-03-2013, 11:03 PM
Not really, you can cross-compile for other systems. The easiest is definitely cross-compiling from Linux to other platforms (hell, I actually can't remember the last time I compiled windows program under windows). You can easily do that, just slap the windows units to fpc search path and basically you're done. Unfortunately, since Apple are separatist bastards, this can't be done for Mac.

Cross-compiling to Mac OS X could be done for older (PowerPC) versions, but not for newer Intel versions, since Apple doesn't release the assembler and linker sources anymore.

phibermon
31-03-2013, 12:43 AM
Whatever gives you output (and input to record) is fine. but bare in mind that you still need to be able to calculate the latencies for input/output so you can correctly synchronize recording to any tracks (such as drums etc).

As a guitarist you'll notice anything above 30-40ms, much more than that and it'll be obviously out of sync. Top of the line guitar pedals (like the boss GT6) are 20-30ms in terms of realtime latency. ASIO on a decent PC can be expected to be usable from 4-15ms with a few effects without buffer under-runs (buffer becoming empty because you're not filling it fast enough, due to effects etc)

The important thing to note here is that things like WaveOut in windows and similar software or basic mixing / audio out have much higher latencies, can be anything from 80ms to 400ms. I'm guessing SDL doesn't make use of ASIO and certainly you can't expect the latencies to be anywhere near consistant across platforms.

And in addition you might not be able to use SDL as it may not expose latency information to you due to the nature of it's design methodology (keep it simple) or again it might do, I don't know I'm afraid.

But latency calculation is important for any music recording where at the very least, you need to be in time to a click track. And it must be done for the recording session and not afterwards as you don't want to have to modify the recorded data just for syncing, chopping off samples for example would be a big no no.

I'm no expert in the topic but the techniques and considerations should be the same regardless of language so you shouldn't have any problems finding relevant info plus the devs of DelphiASIOVST might be inclined to offer recommendations considering they follow the open source ideology but obviously I can't speak for them.