How to play sound in lua - audio

How to play sound in lua? Is there any simple trick how to do it?
My goal is to play some ogg (or mp3) files during playing my game, which is programmed in lua. It's running on windows.

Lua does not have any built-in sound APIs. As you are on Windows, you have these options:
Write bindings for a sound system of choice (OpenAL or something more high-level — as a separate non-Lua-specific question if you need help picking one).
Use LuaJIT2 FFI to directly access DLL functions of the sound system of choice.
Otherwise, if you do not use LuaJIT2, use Alien FFI library.
Or, indeed, use LuaCOM to play some sound (with DirectSound?), if you're familiar with COM stuff.

Lua doesn't have any native sound APIs. If there is a plugin/extension for Lua to accomplish audio control/playback, you'd have to go dig that up seperately. Or if Lua supports COM, you could speak to the Windows audio facilities directly.

proteaAudio is a pretty easy library for lua to play audio or even generate audio on the fly.

You can use the Corona library:
--Loads the selected audio (make sure the name is the same as the .wav file)
local audio1 = audio.loadSound( "audio1.wav" )
--Plays the audio on any available channel (theres up to 32 channels)
local audio1Channel = audio.play( audio1 )
source: http://docs.coronalabs.com/api/library/audio/play.html

In windows, use luacom
require('luacom').CreateObject("wmplayer.ocx").URL="my.mp3"--Need to keep host process alive, not to close.

Related

Corona Lua waveform sound synthesis

I would like to make a sound synth using the Corona SDK, which means in pure Lua. All the Lua synth programs rely on an underlying C program. Is there any Lua library that generates waveforms?
I have no experience when it comes to Audio.
But here are a couple of links to get you started!
http://www.coronalabs.com/blog/2011/07/27/the-secretundocumented-audio-apis-in-corona-sdk/
http://developer.coronalabs.com/forum/2012/02/09/drone-fx
I don't know if Corona has an audio API that would allow that, but the MOAI SDK is a free, open source, Lua-based engine that targets iOS (+ Android, PC, Mac, Linux) which you could add anything you want to.
Unfortunately, Corona SDK has very weak sound support, and there are not good Lua audio libraries that I know of. MOAI appears to be dead, or mostly dead.
AudioKit seems like the way to write synthesis these days, but it is Swift & Objective-C only. Would love to see it in Lua, but there does not seem to be a push in that direction:
http://audiokit.io/

Crossplatform Offline Audio Processing Library

I am looking for an audio dsp library for cleaning up some speech (voice) recording. I have not decided which language to use yet.
Here are the feature I am looking for:
Work in Linux and Windows
Importing MP3
Working with multiple channels mixing
Noise Filter
Bandpass filter
Compressor
I love to have these as well, but I can write my own if they are not available:
De-esser
multi-band compressor
Expender
Envelopes
(if you can suggest an application that do these in scripting / one mouse click, I will accept your answer too)
What about something like SoX?? http://sox.sourceforge.net/
Take a look at Juce from Raw Material Software.
It is free for non-commercial use, and very reasonably priced for commercial use. it also has a lot of built in audio capabilities (mixing, file I/O, etc.) and has a nice cross platform GUI toolkit as well.
Audacity does most of those things.

Looking for an expressive audio programming language or library

I'm looking for an audio processing language or library which will allow me to experiment with different synthesis techniques. I've looked at Processing which I think is great at what it does, but haven't found any inspiring (and simple) audio libraries.
As a baseline, I want to simply create my own sample buffers and play them back (ideally in realtime). As a plus, the ability to handle MIDI events would be great. I'm an experienced C++ programmer so I could do it natively on but had hoped there was a more DSL (domain specific language) approach.
I have access to Windows, Mac or Linux so not too bothered yet about platform. Other languages I can deal with are C#, Java & Python.
Thanks
James
Depending on how much you want to stay out of the low-level housekeeping details, you may want to look at CSound , or if you want to not actually write code, the patching-based system PureData is great to work with. As #Lou points out, ChucK is interesting (but was too buggy to use the last time I checked it out).
If you really do want to write code, look at the Synthesis Toolkit, a set of C++ classes for audio processing and synthesis.
For an app framework, I recommend JUCE, which has incredibly nice cross-platform handling of audio/midi IO and GUI elements.
Max MSP is an audio production tool that is highly expressive.
I guess you could say it's a high-level tool, and not a low-level programming language. My impression of it is that it's geared towards the technical musician or the artistic engineer, but anyway it kicks ass and you could go low-level with it if you want.
I've always been a big fan of SuperCollider. It's designed for Mac OS X but also works on Linux.
The language is mostly based on SmallTalk, and it's pretty easy to pick up if you understand the basics of functional programming. The quality of the sound output by the SC Server is very good and there is plenty of documentation both built into the app environment and available online.
One interesting point of SuperCollider is the usage on android devices, and it's intercommunication with python trough out other modules.
Here goes an example
I know you didn't say Ruby, but check out Archaeopteryx
https://github.com/gilesbowkett/archaeopteryx/wiki
or ChucK
http://chuck.cs.princeton.edu/
Have a look at NAudio, an open source .NET audio SDK for working with audio files and devices in Windows. Some features include:
http://naudio.codeplex.com/
NAudio Features:
Play back audio using a variety of APIs
Decompress audio from different Wave Formats
Record audio using WaveIn, WASAPI or ASIO
Read and Write standard .WAV files
Mix and manipulate audio streams using a 32 bit floating mixing engine
Extensive support for reading and writing MIDI files
Full MIDI event model
Basic support for Windows Mixer APIs
A collection of useful Windows Forms Controls
Some basic audio effects, including a compressor

Capturing audio input from microphone, with Haskell?

Is there a mature library that could enable audio input and output and work within Haskell? (A nice wrapper is fine, of course.)
I'm looking for something that can easily capture microphone input and, perhaps, play various audio files as well.
easily capture microphone input and, perhaps, play various audio files as well..
It will strongly depend on your OS platform: there are standard C libraries for this functionality on each OS, and you'll be looking for Haskell bindings to them (e.g. PulseAudio, etc). Look in the Sound category on Hackage:
http://hackage.haskell.org/packages/archive/pkg-list.html#cat:sound
E.g. HSndFile for audio file writing, http://hackage.haskell.org/package/HSoundFile
the module pulse-simple exposes bindings to capture sound from the microphone, see the second example at the top of the page;
https://hackage.haskell.org/package/pulse-simple-0.1.13/docs/Sound-Pulse-Simple.html
pulse audio libraries required by cabal are obtainable via cygwin (search "pulse" in the cygwin installer).
there is a also binding to sox, which looks promising.
https://hackage.haskell.org/package/sox
im sure there are other api wrappers to be found in hackage sound category.
for linux there is a binding to jack, has "unix" as a dependency, it WILL NOT build on windows...
Just in case you're not familiar with hackage: http://hackage.haskell.org/packages/archive/pkg-list.html
It looks like there is some audio-related stuff there. Not sure if there is anything that will meet your needs. But most "mature" haskell libraries will be there.
You can do it with OpenAL and ALUT. I managed to install both on Windows 8, although it wasn't exactly effortless; ALUT requires the underlying C library to be compiled manually into a DLL.
Installing OpenAL - on the other hand - is as simple as downloading the SDK and typing cabal install OpenAL in the command prompt.
With ALUT, you can create OpenAL buffers from audio files (including WAV) and memory views.
I found an example of recording and audio playback here. It should be fairly straightforward to adapt the code to your needs.
Let me know if I left something out and I'll try to elaborate.

How to programmatically create videos?

Is there a freely available library to create a MPEG (or any other simple video format) out of an image sequence ?
It must run on Linux too, and ideally have Python bindings.
I know there's mencoder (part of the mplayer project), and ffmpeg, which both can do this.
ffmpeg is a great (open source) program for building all kinds of video, and converting one type of video (a sequence of images in this case) into other types of video.
Usually it is utilized from the command line, but that is really just a wrapper around its internal libraries. It is expressly available to be used from within another program.
There are also python bindings that wrap the c api, though this particular project doesn't seem to be getting the best support (there are probably other projects out there doing the same thing).
There's also this link where someone has used ffmpeg to do something similar to what you're looking for.
GStreamer is a popular choice. It's a full multimedia framework much like DirectShow or QuickTime, has the advantage of having legally licensed codecs available, and has excellent Python bindings.
in c++ OpenCV (open source Computer Vision library from Intel) let you create an AVI file and just push frames inside...
but it's like shooting with a cannon to a fly.
Not a library, but mplayer has the ability to encode JPEG sequences to any kind of format. It runs on Linux, Windows, BSD and other platforms and you can write a python script if you want to use it with python.
ffmpeg has an API and also python bindings, seems to be the way to go !
Thanks
ffmpeg minimal runnable C example
I have provided a full runnable example at: How to resize a picture using ffmpeg's sws_scale()?

Resources