Sound API Ubuntu Linux - c++

I want to write some native C/C++ code that takes some uncompressed PCM audio data and plays it out through my speakers on Ubuntu Linux 12.04. Can you tell me what are the different default audio APIs/libraries that are installed? What is their low-level architecture and how do they interarct with the kernel? (which syscalls)
(I've heard different terms like ALSA, PulseAudio, OSS, and so on, but I don't really have a clear picture of which does what and how they fit together.)

On Linux, you have LOTS of Linux audio APIs to choose from. Here is a graph I made a few years ago demonstrating the relationships among the various Linux audio APIs.
However, if you are only targeting Ubuntu Linux and using C/C++, and you don't need anything too fancy (just taking raw PCM data and shoving it out to the speakers), I would recommend using PulseAudio and sticking to the "simple" API. A trivial example can be found here. It's the path of least resistance to getting a proof of concept working.

In very simple terms, ALSA provides the low level infrastructure for audio in Linux, and Pulse provides the higher (more desktop-friendly) level. As far as most mainstream Linux distributions are concerned (Ubuntu included), OSS is obsolete.
You ask about syscalls. You don't use audio in Linux via syscalls. If you choose to use ALSA directly (not a good idea for simple audio playback), you'd employ its userspace library libasound2 (even OSS would be used via /dev/ files rather than syscalls).
If you are targeting modern Linux distros only, consider using the Pulse API. If you want more flexibility as to what distro you are targeting and the potential for cross-platform support, you could try a library which abstracts away the OS-specific audio API - for example, PortAudio (http://www.portaudio.com/).
If you've never done any audio development, you may find a library such as PortAudio easier to work with than addressing PulseAudio directly.

FMOD should be great for you. It's fairly easy to integrate to any C++ project (and many more languages) and runs under Windows, Linux (32bit and 64bit), Mac, Android, PS3, Xbox, etc. Also FMOD Ex provides both a low-level API and data-driven API.
It is free to use if you are not planning on making money with your application. Otherwise you might have to pay for a license starting at about 100$.

Related

How would I reproduce the functionality of the Windows winusb driver on Linux? Do I even need to?

I need to implement an application on Linux that drives a USB connected device (a medical instrument). The application will be written in C++ (2011 standard).
The current application is written for Windows 10 in C# and uses the standard Winusb driver enumerated for the device. I have a complete protocol specification for the commands and the events/interrupts coming back. Unfortunately, I'm not sure how I can pass these to the USB layer in Linux. If it was a simple serial device, there would be no problem but I'm guessing the command responses and the interrupt events are multiplexed by the driver using the functionality in the Winusb driver.
Where's the best place to start in terms of documentation? Alternatively, is there a Linux library (or driver) that provides more or less the same functionality as winusb for Linux?
Any help appreciated. Thanks
Alternatively, is there a Linux library (or driver) that provides more or less the same functionality as winusb for Linux?
One way is using directly the generic kernel API for USB (see the Asynchronous I/O parts to get the interrupts):
https://www.kernel.org/doc/html/v4.15/driver-api/usb/usb.html
This is the strict Linux equivalent of WinUSB.
The potentially less hard way is using libusb, which also get you cross-platform features.
(I am assuming your device is recognized correctly by the kernel, and doesn't need a custom driver)
Is there a Linux library (or driver) that provides more or less the same functionality as winusb for Linux?
Yes. libusb is a popular USB abstraction library that supports Linux, macOS, and Windows. I also wrote a similar library called libusbp with a different set of features that were more useful for my applications. These are C libraries so it will take some work to interoperate with them from C#, but once you do that, you can probably use the same code on either Windows or Linux (so you wouldn't have to maintain your code for calling WinUSB).

What is Linux’s native GUI API?

Both Windows (Win32 API) and OS X (Cocoa) have their own APIs to handle windows, events and other OS stuff. I have never really got a clear answer as to what Linux’s equivalent is?
I have heard some people say GTK+, but GTK+ being cross platform. How can it be native?
In Linux the graphical user interface is not a part of the operating system. The graphical user interface found on most Linux desktops is provided by software called the X Window System, which defines a device independent way of dealing with screens, keyboards and pointer devices.
X Window defines a network protocol for communication, and any program that knows how to "speak" this protocol can use it. There is a C library called Xlib that makes it easier to use this protocol, so Xlib is kind of the native GUI API. Xlib is not the only way to access an X Window server; there is also XCB.
Toolkit libraries such as GTK+ (used by GNOME) and Qt (used by KDE), built on top of Xlib, are used because they are easier to program with. For example they give you a consistent look and feel across applications, make it easier to use drag-and-drop, provide components standard to a modern desktop environment, and so on.
How X draws on the screen internally depends on the implementation. X.org has a device independent part and a device dependent part. The former manages screen resources such as windows, while the latter communicates with the graphics card driver, usually a kernel module. The communication may happen over direct memory access or through system calls to the kernel. The driver translates the commands into a form that the hardware on the card understands.
As of 2013, a new window system called Wayland is starting to become usable, and many distributions have said they will at some point migrate to it, though there is still no clear schedule. This system is based on OpenGL/ES API, which means that in the future OpenGL will be the "native GUI API" in Linux. Work is being done to port GTK+ and QT to Wayland, so that current popular applications and desktop systems would need minimal changes. The applications that cannot be ported will be supported through an X11 server, much like OS X supports X11 apps through Xquartz. The GTK+ port is expected to be finished within a year, while Qt 5 already has complete Wayland support.
To further complicate matters, Ubuntu has announced they are developing a new system called Mir because of problems they perceive with Wayland. This window system is also based on the OpenGL/ES API.
Linux is a kernel, not a full operating system. There are different windowing systems and gui's that run on top of Linux to provide windowing. Typically X11 is the windowing system used by Linux distros.
Wayland is also worth mentioning as it is mostly referred as a "future X11 killer".
Also note that Android and some other mobile operating systems don't include X11 although they have a Linux kernel, so in that sense X11 is not native to all Linux systems.
Being cross-platform has nothing to do with being native. Cocoa has also been ported to other platforms via GNUStep but it is still native to OS X / macOS.
Strictly speaking, the API of Linux consists of its system calls. These are all of the kernel functions that can be called by a user-mode (non-kernel) program. This is a very low-level interface that allows programs to do things like open and read files. See http://en.wikipedia.org/wiki/System_call for a general introduction.
A real Linux system will also have an entire "stack" of other software running on it, in order to provide a graphical user interface and other features. Each element of this stack will offer its own API.
To aid in what has already been mentioned there is a very good overview of the Linux graphics stack at this blog: http://blog.mecheye.net/2012/06/the-linux-graphics-stack/
This explains X11/Wayland etc and how it all fits together. In addition to what has already been mentioned I think it's worth adding a bit about the following API's you can use for graphics in Linux:
Mesa - "Mesa is many things, but one of the major things it provides that it is most famous for is its OpenGL implementation. It is an open-source implementation of the OpenGL API."
Cairo - "cairo is a drawing library used either by applications like Firefox directly, or through libraries like GTK+, to draw vector shapes."
DRM (Direct Rendering Manager) - I understand this the least but its basically the kernel drivers that let you write graphics directly to framebuffer without going through X
I suppose the question is more like "What is linux's native GUI API".
In most cases X (aka X11) will be used for that: http://en.wikipedia.org/wiki/X_Window_System.
You can find the API documentation here
XWindows is probably the closest to what could be called 'native' :)
The linux kernel graphical operations are in /include/linux/fb.h as struct fb_ops. Eventually this is what add-ons like X11, Wayland, or DRM appear to reference. As these operations are only for video cards, not vector or raster hardcopy or tty oriented terminal devices, their usefulness as a GUI is limited; it's just not entirely true you need those add-ons to get graphical output if you don't mind using some assembler to bypass syscall as necessary.
Wayland
As you might hear, wayland is the featured choice of many distros these days, because of its protocol is simpler than the X.
Toolkits of wayland
Toolkits or gui libraries that wayland suggests are:
QT 5
GTK+
LSD
Clutter
EFL
The closest thing to Win32 in linux would be the libc, as you mention not only the UI but events and "other os stuff"
GUI is a high level abstraction of capability, so almost everything from XOrg server to OpenGL is ported cross-platform, including for Windows platform. But if by GUI API you mean *nix graphics API then you might be wandering around "Direct Rendering Infrastructure".

Playing sound in C++ using native system calls?

So in Windows, you can use the PlaySound function to play an MP3 file in a C++ application. What would be some similar functions available for use in Mac OS X/Linux? I would also appreciate it if you could link to some sample Hello-World type programs demonstrating this.
You can just open("/dev/dsp") and write to it. That's as "native syscall" as you can get, I believe.
Concerning Audio: Linux != Mac, so I will answer both separately.
MacOS uses the core audio framework for low level audio. Building on that there are several higher level APIs. If you just want to play a sound file the AV Foundation Framework is most likely the way to go. Here you find an example to build a simple app for iOS, which can be ported to MacOS easily.
For Linux the whole situation is quite delicate. There exist many different frameworks and libraries and it very unclear which is low and which is high level, since some of them are emulating the others. Basically there is ALSA and OSS for low level audio. Both of them are crap. Jack is aiming to provide a framework for professional audio but it's not very portable (at least if you are interested in embedded devices). Most Linux OS currently are using PulseAudio as their audio server, which has also a simple API for just playing a single sound and a very difficult API for low level stuff. And then there is the gstreamer library, which is rather portable and has a half way descent API and is especially designed for playing audio & video files and streams, and so probably the way to go on linux.
I personally recommend to use PortAudio, which is a library that provides – as the name states – an audio framework which is portable across several operating systems and audio frameworks. PortAudio is also well designed and has a simple but flexible API.
Well, I'm not sure if current desktops have some more advanced services/libraries that play audio files, but if you really want to do some low-level OS audio output, start looking here. Maybe this is a little too low-level for your needs.

Cross Platform MIDI library supporting iOS CoreMIDI

I'm looking for a cross-platform C or C++ MIDI library. Just to send/receive MIDI note events, control codes and timing, not to generate sound.
The main target is iOS/iPad so it has to support CoreMIDI on iOS, which I know is fairly recent. I can use CoreMidi directly but if there's something lightweight out there it would be nice to use something portable so I could easily port the project to PC's.
Failing that, please mention if there's a good, lightweight one that's open source it might be easier for me to add CoreMIDI support than to roll my own.
Clarification: I'm looking for something similar to MidiIO or PortMIDI that has good iOS support.
You might want to take a look at RtMidi.
It provides a cross-platform API for realtime MIDI input/output, and makes use of the native API's for each platform (winmm, ALSA, CoreMidi).
I haven't used it with CoreAudio/CoreMidi, but it's worked flawlessly for me on Windows and Linux.
I don't know MIDI thing in iOS dev. To my understanding, sending/receiving MIDI note events to/from MIDI devices should be a pure OS API problem. And parsing/generating MIDI messages is about MIDI spec. I suppose neither leads to a need of a library.

OpenCV on Embedded Platform

Can some suggest a test/development embedded platform to use with OpenCV.
I would like to develop an embedded video analytics solution, but I don't know where to start.
Some suggestion/ideas/hw starter kits?
Maybe some Pc-104 solutions with Intel Atom? Has someone made some test about performances on this platform or any other embedded platform?
Thanks
A Pentium/PC built OpenCV application will run on any Atom platform with the same OS unmodified. This is because Atoms natively run Pentium executables.
If you are looking for a more embedded solution, there are OpenCV ports for the BeagleBoard. SInce OpenCV is portable code, it can be compiled to most systems that provide a C/C++ compiler. I have successfully used OpenCV on ARM, MIPS and XScale processors.
As for mobile platforms, there are ports to the iPhone, Android and various Windows CE/Mobile/Embdeed versions.
If you're looking for a very small option, I strongly recommend the Gumstix Overo series. I use them for my Computer Vision research, and they work really well. There are a couple of options for processors, I'd recommend the Overo Tide module, which has 512 MB of RAM, and an onboard DSP for offloading some CV operations. Combine this with a Tobi expansion board and a few cables, and you've got a full embedded computer vision research platform for ~$350. They also sell a small camera, which I'm still getting around to trying out. What's nice about the Gumstix is you can just build OpenCV onboard, which saves you some of the headaches with BitBake type solutions.
I'd personally recommend TI OMAP platforms - Beagleboard xM and PandaBoard.
Those boards have embedded video input, run Linux, and have more than enough performance to run OpenCV. They are also extremely portable and have good community support.
Do you mean OpenCV the computer vision library originally developed by Intel? I would be inclined to start with Moblin, Intel's embedded Linux, at moblin.org and for hw use a netbook or any PC that Moblin supports. Hook up a supported webcam from the list at www.qbik.ch/usb/devices/search_res.php?pattern=webcam .
There is a Wikipedia entry that might help. Your project sounds like fun!
cheers -- Rick
You can use the Blackfin kit from Analog Devices. Analog Devices have created a library similar to opencv for the blackfin DSP processor.
you can use Symbian Simulator for this they Nokia have there Open CV for Symbian for hardware testing you have to drop the mail to them they will provide u the hardware through the telnet for given time of time
OpenCV does not need any "special" hardware to function. You can use it fully using images from normal files (e.g. JPG)
Have you looked at some of the tutorials/code? Do they require something specific that you do not have?
Vision Components seem to support the OpenCV in their Smart Cameras (see this article).
I guess I am late to answer.
I have recently used opencv3.4.6 with PC-104 boards (PCM3365) for an INDUSTRIAL Application.
Only thing to note is that when i start webcamera using cv::Videocapture, it takes a long time to open (around 30-40secs), otherwise everything is fine.
Good Luck