I'm creating a simple midi based game in C and I am wondering if there are any libraries to load a midi file, play and also manipulate it by getting the note values.
Thanks in advance!
Check SDL. More especifically, SDL_mixer.
Description:
SDL_mixer is a sample multi-channel audio mixer library.
It supports any number of simultaneously playing channels of 16 bit stereo audio, plus a single channel of music, mixed by the popular MikMod MOD, Timidity MIDI, Ogg Vorbis, and SMPEG MP3 libraries.
If you want to manipulate the MIDI and process its contents yourself rather than just playing it, SDL_Mixer might not be what you want. In this case I would just read the spec and write your own code. MIDI is an extremely simple format and you can probably write whatever code you need in 15 minutes or so... :-)
I realize this question has already been answered, but I would have to agree with #R.. in that SDL is probably overkill for what you are trying to do. You should also take a look at jdksmidi, a much smaller MIDI library written in C++.
Related
I have a series of jpegs,I would like to pack and compress them to a Video.
I use tool mpeg streamclip, but it double the whole play time.
If I have 300 jpegs, set fixed fps 30, I expect to get a video of 10s length . but using stream clip I get a 20s long video.
One answer is to get someone who understands programming. The programming APIs (application interfaces, the way client programs call libraries) to the lig libraries like ffmeg have ways in which frame rate can be controlled, and it's usually quite a simple matter to modify a program to produce fewer intermediate frames if you are creating a video from a list of JPEGs.
But the best answer is probably to find a tool that supports what you want to do. That's not a question to ask a programmer especially. Ask someone who knows about video editing. (It would take me about two days to write such a tool from scratch on top of my own JPEG codec and ffmpeg, so obviously I can't do it in response to this question, but that's roughly the level of work you're looking at).
After searching on various search engines, and also here, there is very little information applicable to my situation.
Basically I want to make a program in C that does the following:
Open an Audio File (flac Mp3 and wav, to represent a bit of variety)
Filter and cut out a specific set of frequencies (for Example 4000-5200hz, the frequencies should be entered upon inquiry)
Save the new file (without the filtered frequencies) in the same format as the input file.
Things that would be of interest to me:
Open-Source examples of software that does the same or a similar thing, preferably in C
ANY literature on audio programming in C
Explanations on how the different formats are structured, any sources appreciated
Ps.: I apologise if some parts of the question can be easily googled, but I tried, and there wasn't anything that described this well in detail.
Thanks a lot!!
Answers:
FFmpeg does a lot of audio slicing and dicing, and it's written in pure C. It's pretty big, though, and might be difficult to digest in one go.
"Audio programming" is a bit vague. But from the rest of your question, it sounds like you want to open an audio file from disk, apply some transformations to the audio, and write the data to a new file. (Other areas under the "audio programming" umbrella would include accessing platform-specific APIs to read from a microphone and write audio to an output device).
Broad topic again, but we'll start simple.
I suggest getting (or generating) a .WAV file to start with. WAV files are probably the simplest audio files to read and write manually. Here is a page that describes what you need to know about the WAV format.
Pulse code modulation (PCM) is the simplest audio format to work with since you don't need to worry about decompressing it first. Here is a page (that I wrote) describing different PCM formats.
As for filtering and cutting different frequencies, I think what you're looking for would be low-pass, high-pass, or band-pass filters.
I hope that helps you get started. Ask more questions here on Stack Overflow as needed.
I'm about to start working on a project for Minix 3 (in C).
My idea is to create some kind of a music player. I want to be able to read files (WAV) and then convert them to a stream of frequencies send to the Timer 2.
Since, has far as I know, there is no easy way to read real music files, I thought of approaching the real frequencies in a block, to a simple mono curve sent to the timer 2.
Ok, issues:
I read and learned, how to read wav headers, but, I can't find anywhere what's the meaning of the data in the data chunk. How should I interpret it?
My initial idea was to make a real music player, but, in my classes we didn't learned how to work with the sound board in Minix 3. Is there some tutorial, anything where I can learn it?
As far as I could realize, C as already a library to manage sound (BASS). Can and How I install it in Minix 3?
Finally, Is it a way to make all this simpler?
A WAV files is not a "stream of frequencies". It contains a series of samples formatted according to the information written in the header.
In best of worlds you just set up your sound card to handle the data format specified in the header, then you just have to keep providing the raw data in the "DATA" chunks to your sound cards data buffers.
How this is done in Minix 3 is out of bounds for this answer (I just don't know how Minix handles sound at all) but I'm sure it will be to great help for understanding the basics of digital audio.
Does anybody know a good C sample that loads bitmaps and handles all the cases: rle, b/w bitmaps, so on?
Code should be cross-platform.
Thanks.
I would suggest using a library like SDL image
If you are looking for a minimal bmp loader this link will give you all you need to know about the BMP format, data structures and sample code without any library dependency to load:
http://paulbourke.net/dataformats/bmp/.
It also contains code to see the loaded BMP in a open gl texture, so pretty much all you need...
Chris Backhouse made a functional little BMP loader (with an eye to using them as OpenGL textures). It's C++, not C, and he admits it's not cross platform. However, it's small and easy to understand, so I thought I'd add the link here:
http://users.ox.ac.uk/~orie1330/bmploader.html
You need some external library to do this (I recommend ImageMagick). The ImageMagick web site also includes documentation and examples.
Check out for OpenCV Library developed by Intel .
If you are tied to the BMP file format, it's pretty simple to look at the header yourself and get the pixels. See this google search. One of the more interesting matches is here. The most counter-intuitive part is that every line of pixels is 4-byte aligned. Also, watch out for compressed BMPs... (My experience is that many third-party tools have trouble with compressed BMPs, so maybe some libraries you encounter will also..)
If you aren't tied to the BMP file format, I recommend libpng. The manual provides some sample code which is pretty clear.
As others suggested you might want to use an external library like SDL. If you want to learn something and do it yourself, see my answer to this very similar question: Getting RGB values for each pixel from a 24bpp Bitmap for conversion to GBA format in C where you'll find C code which prints out each pixel, and have a look at the wikipedia page about bmp files, because it's very good.
I'm writing some physics simulations in c for university, and now I output a series of hundreds of png that I then watch in fast sequence... is there a way to merge them to a video in c with some simple lossless codec library?
P.S. I'm using cairo graphics and have very little experience in graphics programming in general
If you want to avoid using an external program, libavcodec is probably the best way to generate video. It's in C, and quite well documented (see the above link).
More documentation on Jonas' solution using mencoder is here.
Not exactly what you are asking for but I wouldn't roll my own, I would use mencoder:
mencoder mf://*.png -mf w=800:h=600:fps=25:type=png -ovc raw -oac copy -o output.avi
PS. mencoder is part of MPlayer and is Open Source. DS.
You just want to watch some PNGs as a video? You don't need to merge them:
mplayer -fps 2 mf://*.png
There are fast lossless codecs in ffmpeg's libavcodec, if you want to do that instead of write PNGs. e.g. ffvhuff, or huffyuv.
Or if you don't want to use libavcodec, you could write y4m raw output and pipe it to something. yuv4mpeg is a header with the frame rate and frame size, and then the uncompressed pixels for each frame just raw.