Transcoding Audio on iOS - cocoa-touch

I'm grabbing song data from the iOS music library (as an NSData object), but when the data is not that of an MP3 file, I'd like to transcode it.
I have two questions about the transcoding process:
Is there something built in to do, say M4A to MP3 transcoding, or will I have to use something like ffmpeg or other external libraries? If the latter, are there any examples of doing this on iOS knocking about?
What's the best way to do this that doesn't load everything into memory? Obviously a large song file will exhaust the memory and the app will be terminated.

maybe libSOX fits to your needs.
the features of the tool are available [here][2]
to compile for iOS, check out the thread building libsox for iOS question
[2]: http://sox.sourceforge.net/Docs/Features "here"
i think ffmpeg is the choice
for iOS http://code.google.com/p/ffmpeg4iphone/
http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2009-October/076618.html
http://fobs.sourceforge.net/ is another choice (C++ wrapper to FFMPEG). Its home page has a reference to m4a files. To use it you could wrap up C++ in Objective-C in a .mm file.

How about LAME + libsndfile?
See:
http://lame.cvs.sourceforge.net/viewvc/lame/lame/doc/html/index.html
http://www.mega-nerd.com/libsndfile/

Related

Playing MIDI files in VB.NET

How can I play MIDI files with VB.NET? I tried using WAV, but they are too big. Any help?
look at this article i used it before and it works.
http://www.codeproject.com/Articles/8506/Simple-VB-NET-MIDI-Wave-Play-Class
just copy paste that code in your project.
create variable which holds your midi and
call the play method.
you can also try this.(not sure about it.)
http://support.microsoft.com/kb/141756
Using MIDI files can be a good idea in regard to size, but IMO a horrible idea when it comes to actual sound (or lack there-of :) ). You can find users which do music too, and has a little better alternative set up or connected to their system, but to make users fire up their MIDI instruments and so forth to listen to a MIDI-track in a software can be a bad idea if unexpected.
Most users though are stuck with the built in wave synth from Microsoft which is a torture instrument (pun intended) and should probably not be used ;)
Why not consider compressing your wave data instead using MP3 or some other excellent compressor such as AAC, Ogg Vorbis ?
This will reduce the original data amount to at least 1/10 of the original size and unless you are providing a whole album, should be overcome-able.
You can find various ways to do this, from simple such as this one using the Media Player, or more low-level such as this one which decodes the MP3 file.
Also take a look at SlimDX.

iOS Localization of large files like movies

I am creating a new iOS project, where I have to include a video in my app. We need to access this video also in offline mode - so I need to include it as video file in my project.
The question - what is the best practice for such large file localization? App will be in at least 7 languages and I can not decide - include video in 7 languages which would dramatically change size of app or include it only in English and localize other stuff? Probably someone knows - if my phone language is for example Spanish and I download localizable app - does this app include videos in all languages or only in my selected?
Any answer will be appropriated and thank you in advance.
You could do something nifty with bundling the video and audio separated. You could then play the correct audio for each localization. The same could be done with subtitles.
Most optimized way would be to not bundle any video in the application and just allow the users to download the video for the current localization from within the app. That's what I think.
A single video can have multiple audio streams. So you can simply create one video with multiple audio streams. Audio is general smaller compared to video. So should not hurt as much. User can then select the audio langauage [or program can preselect based on some preference] to play it out.
Almost all container formats can contain more than 1 audio stream. [Almost all, definitely mp4 which is what I guess you are using.]
EDIT: You can possibly also have two files. One with half the languages which are the most common and one with other half which are less common to reduce some size.

Protobuf vs binary plists for network trafficking in a iOS game

I'm developing experimental multiplayer roguelike for iOS. Players will be connected via GameKit API and they'll be put in one dungeon. There is various actions that players can perform, so I want to make one device be a host, and to implement some sort of RPC for sending/receiving of this actions (and pretty complicated state of dungeon when game starts)
I need some compact and fast serialization. I'm choosing between protobuf and binary plists. Binary plists looks pretty simple to use for objc objects serialization/deserialization (this is important point, cause its experimental non commercial project), but it looks inefficient. Protobuf looks efficient, but totally alien. Any alternatives?
Edit: just found http://msgpack.org/. Looks like a way to go
Protocol buffer serialization should be faster than binary plist.
Also, if you want to make the game again on android or any other platform then protocol buffers will be your friend. (platform independence)
Working with protocol buffers on ios can be a pain in the beginning. Just setting up the project with XCode takes up a lot of time.
Initially i tried to work with objective c version of protobuf, but i had to drop it completely because of some limitations in the library.
I have now added the google source code directly on Xcode, ands its working perfectly. check out this answer. Through this you'll be able to start working with protobufs in your project easily.

Detect BPM of Mp3

I want to know if there is a way in c++ or objective-c to get the BPM of a Mp3 file.
i found until now a source code for stuff that do it on wav files and not on mp3 file,
BPM (or beat) detection is a complicated algorithm that involves analyzing the sound stream in different ways. For this to happen, at least internally the MP3 must be decoded. Typically these are things you'd actually write in a language such as but not limited to C++ or Objective-C.
There are many libraries / pieces of code available that solve both problems, or in the case of beat detection: take a shot at it.
There's certainly no way to do BPM detection in the core C++ or Objective-C languages. You need to write the functionality yourself or take advantage of one of the many libraries that provide it.
If you can't find a suitable library that supports MP3 directly then you're going to have to decode to PCM first.

How do you read/write/update m4u and mp3 file meta data using cocoa/objective c?

Are there some particular library files available on OS/X that are relevant, I am just not sure where to start.
You'd probably want to use the QuickTime for that. There is some sample code that does this. However, it's not the nicest way to access metadata. The newer QTKit Framework somehow still requires you to fall back to the C-based APIs. There is another example from Apple embedding meta data writing into a Objective-C method. This might be the best starting point for you.