Record mp3 frames to a file - c

This is really an intellectual exercise, since C is my favourite language, and I need more experience hacking things.
I have a program that gets MP3 files as frames. I want to write a single C file with a header file that has functions that I can simply "plug in" at various points in the overall program. A single function call, because the program itself tends to be updated, and I want to be able to take my program from one version of the code to the next, with the minimal amount of hacking time each time.
So, how do I turn MP3 frames into an MP3 file? I am a complete newbie at this.

Related

How to Combine and work with data from two files?

VERY new to Python. I was programming in RPG and COBOL professionally decades ago so I have a programming background but haven't for years and now learning Python ......
I have two simple CSV files I open and work in. Then I want to combine the results and do more but it doesn't seem to let me.
(1) Currently I have defined a function (PROFDATA) to open first file (simple file of students marks from a professor). I access data and do some calculations and manipulations. Works great!
(2) I next define another function (TADATA) open the second file which has more marks for the students. I access do stuff and when I print, it gives me what I want from that file.
I want to combine my results from both files and then do more things but I don't seem to know best method. I know keeping them as FUNCTIONS means that the variables aren't available elsewhere.
Should I be writing data that I need from each file to a 3rd file?
Not sure of the best approach. Sorry up front as I know this must be a big time beginner question.
Tami

How to change the name of a file in C?

Currently, I am taking some measurements and saving the data in a txt file. My C program is supposed to run without interruptions and it writes several files, one after the other. On another machine I want to have a routine to copy the files that are done writing and are ready to be analysed. To distinguish between them, I want the files to be written with a tag, something like: *.part.txt.
I was thinking of using the rename() function. My problem is, I do not know how to easily change the string from *.part.txt to just *.txt.
This would be much easier using Python, but I have to use C for this one and sadly, I lack the necessary experience to solve this by myself.

Why do application folders contain so many files?

I have a general question about finished applications. When I go into the files of a windows computer application, some files make sense as to why they are there, such as the executable, various media files, .dll files, etc. However, what I don't understand is how there's potentially thousands of different files, located in hundreds of different directories (counting hierarchy) with anywhere between dozens and hundreds of different filetypes. Some of the filetypes don't even seem like actual files, the extension could be something completely obscure. How does the application know how to work with that? Are all of those files hand-written and compiled or are many of them supplied automatically upon generating a desktop application (which would vary based on the application, of course)? I've never actually compiled an application in any language, as I've been studying JavaScript as a starting point, and I recognize that JavaScript is not intended for creating standalone applications, it's used to implement inside HTML. This is why I have so many questions about the generation of the application itself.
To provide an example, a few of the file extensions I see contained in the Audacity application folder which I don't recognize are as follows: .lsp .raw .mo .ny .exp
Even that is a very short list compared to the amount of filetypes/extensions I usually encounter which I have no knowledge of. So, all in all, my main question is why there's such a crazy amount of files, folders, and filetypes/extensions being used by an application. Hopefully someone can help me understand.
Extra question, for those who might care to answer it:
What does it mean when you open a file in an application like Notepad++ (or a .plist editor) and it's just a bunch of unreadable characters? I'm assuming that means it's a compiled file, but I could use some clarification. This happens when I try to open an .exe, a .dll, etc. I understand why I can't edit things like that in a text editor of course, yet why all the strange symbols and characters? Why wouldn't it just throw an error upon trying to open it? Are all the strange characters just a way of attempting to interpret already compiled code?
Bear with me, I'm pretty new to programming and I'm trying to get a better understanding of the process behind actually generating a GUI-based desktop application. As I said before, my current knowledge doesn't extend to the point of actually compiling an application.
Thank you for any help, I really appreciate it.
Focusing on your extra question: you have to learn what a binary file and a text file is, but in short: Imagine you have a simple calculator program that stores the result in a file. Lets say the result you want to store is the number 64. You have to options to do it: saving it as text (characteres 6 and 4) or as a binary data.
If you store it as a text, you need two bytes: one for the code of the character 6 and other for the character 4. You can open that file with the notepad and you'll see that two characteres '64'.
If you store it as a binary value, you only need one byte, but if you open it with the notepad, you'll see the character whose code is 64: 'A'
Most of such "strange" files are resources needed by parts of the application. A complex application is constructed very modular, and each component may need to load different additional resources, often depending on conditions decided at runtime.
For example, on startup if a Qt-based application reads it should use German translation, it may load trans/de_DE.qm from a directory also containing other language files. Or a game may load level by level from different files depending on how far you've come.
Your second question is quite simple. Most resource files are read by an application function as stream of bytes. If e.g. such stream contains '005a' as 4 bytes, you'll see strange symbols in notepade.exe since that editor interprets such bytes as ASCII code, which means it prints the symbols it finds at place 0, 0, 5, and a in the ASCII table. But the application actually reads it in as 4 x 8 bits = 32bit value, which may mean a 32bit integer value of a variable in my simple example. So the variable value is set to 0x5a wich is decimal 90.

Reading wave files for mono conversion (Minix 3)

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.

How are files (especially audio files) organized internally?

I try to grok that: Apple is talking about "packets" in audio files, and there is a fancy function called AudioFileReadPackets which takes a lot of arguments. One of them specifies the "start packet", and another one the number of packets which you want to read.
So I imagine an audio file to look like this, internally: It's made up of a lot of packets. If it's an audio file which has an variable bit rate format, then every packet may have a different size. If the file has an constant bit rate format, then every packet is the same size. So an audio file is like a truck full of boxes, and every box contains some interesting stuff.
Is that correct? Does it apply to any kind of file? Is this how files actually look like?
The question (even with the "especially audio files" qualification) is far too broad; different file formats are, well, different!
So to answer the question you will first have to specify a particular file type; then the answer to the question will invariably to look at its specification. Proprietary formats may not have a publicly available specification.
Specifications for many files (official and reverse engineered) can be found at the brilliant Wotsit's Format site.
AAC used by Apple iTunes and others is defined by ISO/IEC 13818-7:2006. The document will cost you 252 Swiss Francs (about US$233)! You'd have to be really interested (commercially) to pay that rather than use an existing AAC Codec.
"Packet" is a term commonly used in data transmission, so may be more applicable to audio streaming than audio files, where a "frame" may be more appropriate, or for data files in general a "record", but the terminology is flexible because it means whatever the person that wrote it thought it meant! If enough people misuse a term, it essentially becomes redefined (or multiply defined) to mean that, so I would not get too hung up on that. The author was do doubt using it to define a unit that has a defined format within a file that has multiple such units repeated sequentially.
"Packet" looks to me like Apple-specific terminology. I just did a lot of reading and coding to process WAV and MP3 files and I don't believe I saw the term "packet" once.
Files contain whatever the application that created them chose to place in them. Files are essentially a sequence of bytes. Any further organisation is a semantic distinction made by the program that created them. It is untrue to think of all files containing the same structure.
That said, certain data storage problems are similar enough to be solved in similar ways, and patterns start to emerge. Splitting data into records or packets is an example of that.
That's pretty much what audio files look like: a series of chunks of data, or frames. AudioFileReadPacketData and AudioFileReadPackets shield you from the details of, for instance, how big a frame might be in bytes (because you might be reading from a WAV file, which has a different structure to an MP3 file, or your MP3 file uses a variable bit rate).
The concept of frames doesn't apply in general to any file, but then you wouldn't be using the Audio File Services API to access just any old file.
For MP3 (and MP1, MP2) the file consists of frames. And yes, your understanding is correct - in VBR files packets have different size. In WAV files packets have the same length if memory serves (I wrote a decoder / player 11 years ago,).

Resources