SDL_Mixer set sound position - c

I was wondering if there is a functionality in the SDL_Mixer lib to skip to a certain position in a wav file. I've found out the there is a function called Mix_SetMusicPosition but it won't work with .wav files and it won't let you choose a channel.
Any suggestions would be greatly appreciated.
EDIT:
I figured out how to do it. Instead of calling an additional function I just changed the start pointer of the abuf variable located in Mix_Chunk structure. I calculated how many bytes are in a second in a 16 bit .wav file playing at 44khz and changed the starting pointer of abuf with that number times how many seconds I want to skip. And then changed the length of alen, also a variable located in the Mix_Chunk struct, with the same number of bytes.

I just read the docs for SDL Music and apparently Mix_SetMusicPosition only supports OGG, MP3 and MOD files.
Link: http://jcatki.no-ip.org:8080/SDL_mixer/SDL_mixer_65.html#SEC65
Obvious solution; convert your wav. files to your favorite previously mentioned file format.

Related

Playing a Frequency in OpenAL in C

I am trying to write a program to play a frequency for a time. I can't find any way of simply just playing a certain frequency. How do I go about doing this in OpenAL?
I eventually found a video on properly reading form a WAV file (huge credit to this video) and how a WAV file is formatted (explained here in detail) and did some trial-and-error work until I figured out how to do it. I figured that if I could make a WAV-style file with the frequencies in them and set up the OpenAL buffer and source manually, it would work.
I ran into some trouble when I found that the format differed from the first explanation of WAV file format I found, as some apparently have additional meta-data, which I had to test for and skip over when trying to load a WAV file. Then I made a WAV file containing the frequencies and played it, which worked as well as I could have hoped for.
Here's another article about how bit-depth works that really helped me understand what I was doing.
Hopefully this helps anyone else who is trying to do something similar to this!

Gstreamer- Duration query error on mp3

I am working on a simple application using Gstreamer on C, that involves playing a song and show some info about it on terminal. Thta info includes the total length of the song in seconds. As usual, I used the function gst_element_query_duration to get this data. The thing is, when I run my program, sometimes it shows the right time on screen, but then I run it again and the total time showed is about 6 seconds less. Because is just a simple trial application, I am using playbin as the general bin for reproduction, so I tried with different file extensions and it seems this only happens with mp3 files. Have anyone ever experienced this? Any ideas on how to fix it?
MP3 has the problem that there is no duration stored inside the file (usually). With constant bitrate files you can simply check the bitrate and the file size, but for variable bitrate files you can only do an approximation based on that. Your problem is probably exactly that.
The only way to know the exact duration of a variable bitrate MP3 file without header information with the duration (see Xing header) is to parse the file until the end and count the exact duration. With playbin you should get the accurate duration at the end of the file.

List the content in the root directory [C programming]

I am looking for a way to extract the data from the 'Root Directory'.
This is using a FAT 12 floppy image. This is with Ubuntu Version 14.04.2.
I would like to be able to read the root entries found in the root sector (from what I understand this is sector 19 - 32), I would then like to be able to display the content stored in the entries (file names, directory names). This needs to be for system level programming.
traverse(){
unsinged char buf[1000];
int fd = open("CDBOOT1.IMG", O_RDONLY);
lseek(fd, 19 * 512, SEEK_SET);
read(fd, buf, 512);
}
I would like some information on how I can parse out the information in the buf array to get the information I desire. This is for a homework assignment, so I am not looking for a concrete answer, but maybe some resources on how to do this.
Update:
From advice, I used some of the other code (already written by someone else) so that it would print the HEX data of the sector I am trying to get the root data from (I can post the code for that if it is necessary). With the HEX table, I am still unsure how to interpret the data in order to get the file information, directory information, date created, etc.
I've done some parsing of FAT in the past. It can be tricky if you're not used to it.
One thing I'd strongly recommend is doing a hex dump of what you read in C and, save it in in a file and then bring it up in a good hex editor so you can verify that your algorithms are right and things are laid out as you expect. That everything cross-checks which what you get from the spec.
Here is a spec:
http://www.maverick-os.dk/FileSystemFormats/FAT12_FileSystem.html
You are really looking for two things here. The FAT contains data the represents clusters and fragments of clusters. But you also want to read the DET ( Directory Entry Table ) to get names and things like that.
So what you REALLY need to do is start here:
http://en.wikipedia.org/wiki/File_Allocation_Table
and read up on how these things are designed. This is neither simple or trivial code, even with an image file. The image file may even have things embedded in it for the software that reads and writes it.

Unknown Master List .dat file, issues retrieving information

I come to you completely stumped. I do some side work for a company that uses an old DOS based program to input and retrieve data. This is a legacy piece of software, and they have since moved to either QuickBooks or Outlook for all of their address or billing related needs. However there have been some changes made, and they work with this database fairly regularly. Since the computer that this software is on, is running XP (and none of the other computers in the office can run it) they're looking to phase this software out for when the computer inevitably explodes.
TLDR; I have an old .csv file (roughly two years) that has a good chunk of information on it, but again it's two years old. I have another file called ml.dat (I'm assuming masterlist.dat) that's in the same folder as this legacy software. I open it with notepad and excel and am presented with information like this:
S;Û).;PÃS;*p(â'a,µ,
The above chunk of text is recognized much less within notepad or excel. It's a lot more of the unrecognized squares.
Some of the information is actually readable however. I can for example read the occasional town name, or person's name but I'm unable to get all of the information since there's a lot missing. Perhaps the data isn't in unicode or something? I have no idea. Any suggestions? I'm ultimately trying to take this information and toss it into either quickbooks or outlook.
Please help!
Thanks
Edit: I'm guessing the file might be encrypted since .dat's are usually clear text? Any thoughts?
.DAT files can be anything, they are usually just application data. Since there is readable text, then it is very unlikely that this file is encrypted. Instead you are seeing ASCII representations of the bytes of other content. http://www.asciitable.com/ Assuming single byte values, the number 77 might appear in the file somewhere as M.
Your options:
Search for some utility to load and translate the dat file for that application.
Set up an appropriate dos emulator so you can run this application on another box, or even a virtual machine running freedos or something.
Figure out the file format and then write a program to translate the data.
For #3, you can attach a debugger to the application to trace how the file is read and written. Alternatively you can try to figure out record boundaries (if all the records are the same size, then things are a little bit easier.) Then you can use known values to try to find field boundaries. If you can find (or reverse compile) the source code, then that could also give you insight into the file format.
1 is your best bet, and #2 will buy you some time so that you don't need that original machine anymore. #3 would likely be something to outsource.
If you can find the source or file format, then you just recreate whatever data structure was dumped to the file and read the file into it.
To find which exe opens it, you can do something like:
for %f in (*.exe) do find "ml.dat" %f -c
Assuming the original application was written in C then there would be code something like this to read the first record from the file:
struct SecretData
{
int first;
double money;
char city[10];
};
FILE* input;
struct SecretData secretdata;
input = fopen("ml.dat", "rb");
fread(&data, sizeof(data), 1, input);
fclose(input);
(The file would have been written with fwrite.) Basically you need to figure out the innards of the SecretData structure to be able to read the file.
There likely wasn't a separate utility used to make the file, dumping data and reading it back from a file is relatively easy in most languages.

File archiver in C

i would like to know how could I possibly use the programming language C to create a file archiver such as tar.
Im stuck on the first bit on how to copy a bunch of files into one file, and then extrating them back out of that one file.
Any help would be appreciated thanks.
It's a good idea to read up on the tar format for some inspiration.
http://en.wikipedia.org/wiki/Tar_%28file_format%29
http://www.gnu.org/software/automake/manual/tar/Standard.html
It's quite simple and shouldn't be too hard to implement yourself, if you got a good grasp of basic C I/O.
Assuming you don't want compression, which is pretty hard, and just want's something REALLY simple, you are gonna need to do the following:
Create a file to hold all the files you want.
Fetch one of the files you want to archive, get it's name, name_size and it's size.
Write the name_size of the name, name, size of the file, and the size * bytes of the file into the archive one.
Repeat to all of the files you want to archive.
To get the files back from the one archive, you are gonna need to read the name's size, create that file with the next name_size next bytes, then read the size of the file bytes, and write them to the single file you created.
You would have this:
File1:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
FileN:
yyyyyyyyyyyyyyyyyyyy
After the archiving you would have:
5File1size of File1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5FileNsizeof FileNyyyyyyyyyyyyyyyyyyyy

Resources