For a project that I intend to start on soon, I will need to play back compressed and uncompressed audio files. To do that, I intend to use the Core Audio framework. However, I have no prior experience in audio programming, and I'm really not sure where to start. Are there any beginner level resources or sample projects that can demonstrate how to build a simple audio player using Core Audio?
A preview of a book on Core Audio just came out. I've started reading it and as a beginner myself I find it helpful.
It has a tutorial style teaching method and is very clear in its explanations. I highly recommend it.
Although the questiona has already been answered.. I would like to add in a little more tips since I've struggled with the same issue for months:
Here is a very simple example code I created based on sample code on the learning core audio book.
The Matt Gallagher audio streaming tutorial is a definite must.. in addition to providing an excellent example of streaming audio live.. its also provides a simple example of multi-threading.. which brings me to the next VERY IMPORTANT point
In Apple's concurrency guide.. they advise against using multithreading.. and give you a host of suggestions like GCD and NSOperations etc etc.. NOT A GOOD IDEA when it comes to core audio.. at least real time audio.. b/c real time audio is extremely sensitive to any kind of blocking or expensive operations.. more than you can imagine (ie sometimes even simple NSLog statements can make the audio break up or even not play at all!!) Here is an indispensable read regarding this part of audio.
Audio programming is a different kind of programming than what most of us are used to. Hence take your time to understand concepts.. a lot of them will take time to sink in.. for example the difference between an audio file format and an audio streaming format.. the difference between compressed audio and PCM (non-compressed) audio.. examples abound.
One key point that took me a while to comprehend: to access audio files within the iPad library.. the only way to read them is via the AVAssetReader API methods.. not through the other APIs like AudioFileReadPackets etc.. (although if you store a file manually in your project.. then you can).. the AVAssetReader is a lot less user friendly than the other API.. but once the concepts of core audio sink in.. you won't find much of a difference.. My example uses AVAssetReader
See the discussion I've been having with Justin here.. in it you'll see a lot of pitfalls that i've fallen into and you'll get an idea on how to avoid them. Remember, especially with Core Audio.. it's not about knowing how to solve the problem.. it's about knowing what problem to solve in first place.
If you or any one else has any questions with regards to core audio please feel free to write up a question on stack overflow and point it out to me by commenting on one of my own questions just to bring it to my attention.. i've been helped a lot by the community here and i really wanna offer help in return
I wrote some sample code after spending a long time trying to figure out a similar problem as yours.
The sample code allows the user to select a song from their iPod library, it then creates an uncompressed (LPCM) copy of the file (using AVAssetReader/AVAssetWriter), and plays it back using AudioUnit (which is part of CoreAudio).
If you want to play an arbitrary file, just remove the bits of my code that create the uncompressed copy (look for AVAssetReader/AVAssetWriter), and instead have the class point to some other song file.
http://www.libsdl.org/
i think for your requirement you can get better support from above link
Related
I'm encoding images as video using FFmpeg using custom C code rather than linux commands because I am developing the code for an embedded system.
I am currently following through the first dranger tutorial and the code provided in the following question.
How to encode a video from several images generated in a C++ program without writing the separate frame images to disk?
I have found some "less abstract" code in the following github location.
https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/encode_video.c
And I plan to use it as well.
My end goal is simply to save video on an embedded system using embedded C source code, and I am coming up the curve too slowly. So in summary my question is, Does it seem like I am following the correct path here? I know that my system does not come with hardware for video codec conversion, which means I need to do it with software, but I am unsure if FFmpeg is even a feasible option for embedded work because I am yet to compile.
The biggest red flag for me thus far is that FFmpeg uses dynamic memory allocation. I am unfamiliar with how to assess the amount of dynamic memory that it uses. This is very important information to me, and if anyone is familiar with the amount of memory used or how to assess it before compiling, I would greatly appreciate the input.
After further research, it seems to me that encoding video is often a hardware intensive task that can use multiple processors and mega-gigbyte sizes of RAM. In order to avoid this I am performing a minimal amount of compression by utilizing the AVI format.
I have found that FFmpeg can't readily be utilized for raw-metal embedded systems because the initial "make" of the library sets up configuration settings specific to the computer compiling, which conflicts with the need to cross compile. I can see that there are cross compilation flags available, but I have not found any documentation describing how to use them. Either way I want to avoid big heaps and multi-threading, so I moved on.
I decided to look for more basic source code elsewhere. mikekohn.net/file_formats/libkohn_avi.php Is a great resource for very basic encoding without any complicated library dependencies or multi-threading. I am yet to implement, so no guarantees, but best of luck. This is actually one of the only understandable encoding source codes that I have found for image to video applications, other than https://www.jonolick.com/home/mpeg-video-writer. However, Jon Olick's source code uses lossy encoding and a minimum framerate (inherent to MPEG), both of which I am trying to avoid.
I'm looking for a simple-ish library for outputting audio. I'd like it to meet these criteria:
Licensed under LPGL/zlib/MIT or something similar – i'm going to use it in an indie commercial application and i don't have the money for a license.
Written in C, but C++ is fine.
Cross-platform (Windows, Linux, maybe OSX)
Able to read from some sort of audio file (i'd prefer WAV or OGG but i will gladly use less popular formats if need be) in memory (i've seen the use of a memfile struct and user-defined I/O callbacks). I need the file to be in memory because i put all my resources into a .zip archive, and i use another library to load those archived files into memory.
Supports playing multiple sounds at the same time, having a max of 8 or so is ok.
I'd really like to either have the source code or a static library (MinGW/GCC lib???.a), but if nothing else is available i will use a shared library.
I must have come accross two dozen different audio libraries in my search, all of which haven't quite met these criteria...
I would recommend PortAudio + libsndfile. Very popular combo, meets your requirements. Used by many other software applications including audacity.
Some of the candidates that immediately spring to my mind are:
SDL (there is a tutorial that demonstrates how to play a .wav format sound)
libav
ffmpeg
libao
OpenAL Soft
Jack Audio
You may have already looked at these and eliminated them, though. Can you give some more detail about the libraries that you have eliminated from consideration and why? This will help narrow down our recommendations.
You might want to look into SDL and SDL_mixer. Here is a good tutorial.
I've used SDL_mixer and it makes it easy to play background sounds or music and play multiple simultaneous sounds without having a need to write your own sound sample mixer.
I ended up using PortAudio (very low-level, flexible license) and wrote a mixer myself. See this topic i made on the C++ forums for some other people's tips on writing a custom mixer. It's not hard at all, really; i'm surprised that there are so many mixer libraries out there. For a breakdown of the WAV format (ready-to-stream raw audio data with a 44-byte header) see this.
I've got a need to write a Linux application that does the following:
1- Continuously play a WAV file in the background. So the entire
time the application is running this background music plays.
2- Be able to play short sounds when certain events happen while the background music continues to play.
What is required to mix in the additional event sounds when they happen with the background music so that both are heard at the same time?
I've never written Linux sound code, so this is ALL new to me. I'm assuming that I will need to write to the ALSA API? Or some other library that will facilitate this?
If somebody could provide sample code to get me started I would greatly appreciate it. After a few days I will create a bounty and provide a good deal of reputation for sample code that does what is needed.
You usually don't want to use ALSA API directly. It's hard to use, and not really portable (since ALSA is specific to Linux).
If you are using some specific libraries in your application (like Qt or something like that), there may be already a counter-part sound library for playing sounds.
If you are looking for a good, general-use sound library, I suggest you take a look at SDL. It's quite nice, small and portable; very popular for games. They have quite a nice example code on their site to get you started.
For the part of playing sounds, one library that I used which is easy to learn, use and has a good example in its documentation is fmod. The documentation that comes with the download has a very easy to understand example which you can modify and get your sounds played very quickly.
can anyone guide me the steps and knowledge needed to port a codec in ARM board. Like a development board below
http://www.arm9board.net/sel/prddetail.aspx?id=348&pid=200&AspxAutoDetectCookieSupport=1
i want to gain expertise in audio and video codec for embedded systems. My experience level is novice but i am ready to learn.
Need the pointers to start with
If you are looking to run on linux for example then there really is nothing to it, just compile as if you were running on a desktop/server. You might have performance issues, but those can and have been worked through in many ways.
If you are looking to go embedded, there are a lot more resources out there now than when I tried to do exactly what you are trying. In particular open source fixed point solutions. With arm becoming the leading processor in the world and most of them being fixed point this was solved many times over so there is plenty of code out there to play with.
That is a nice board you have found, on initial glance I didnt see if their core has a fpu or not, for that core it is optional. Just from the advertising I would assume out of the box that board/package does video and audio and all you need to do is turn it on and copy your videos our audio files over and play them.
If you want to learn the nuts and bolts of the codecs, then purchase the specs from ISO/IEC, probably a hundred to two hundred bucks each. And refresh your calculus, there is a lot of it.
Try to look at this project: http://embdev.net/articles/ARM_MP3/AAC_Player It's a MP3/AAC player based on AT91SAM7S256 microcontroller.
Check also this https://datatype.helixcommunity.org/Mp3dec decoder. It's optimized for ARM.
I'm trying to write a program to randomly generate music based on a simple set of rules. I would like the program to be able to generate its own sounds, as opposed to having a file with audio for each note. Does anyone know a simple way of doing this? It would be nice (but not essential) for the sound to be polytonal, and I would like a solution for Linux, using C.
I suggest you try the PortAudio library. It is a lean cross-platform library that abstracts the audio-output functionality.
It comes with a bunch of small examples. One of them plays a single sine-wave, one plays a bunch of sine-waves at the same time. Since the examples already do 90% of what you need you should have your audio up and running in less than half an hour.
Hint: The best documentation of PortAudio is in the headerfile!
Here is an ALSA example that plays a pure sine-wave tone. Accidentally, I guess, it also demonstrates why you might not want to do this directly against the ALSA library.
You can try to find a C midi sequencer (such as MIDI Sequencer). Also look into building .au formatted audio files (i.e. look at the specs for .au headers and sound data format). You won't be able to use .wav format because it requires a length in the header to be filled in before playback.