Writing data from buffer to wave file on disk [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm writing a program which play wave file using waveOutOpen and PlaySound. Now I must write a function to record voice from microphone in Wave file on disk. I use writeInOpen and waveInAddBuffer to record sound in buffer but i can't find an easy class to manipulate on wave file and copy buffer content to file .wav. Thanks for suggestions!

You have to create the file yourself.
You can use the Multimedia File I/O API, specifically at mmioOpen(), mmioCreateChunk(), mmioAscend(), and mmioWrite() functions. You need a good understanding of how the WAVE file format works, how the WAVEFORMAT/EX structures work, etc so you know which pieces to write and how to write them correctly.
Or use DirectX's DirectSound API, specifically the IDirectSoundCaptureBuffer8 interface and the CWaveFile helper class:
Writing to a WAV file
Until you have an understanding of either approach, you should consider using an existing library to do the hard work for you, for example:
Wave Class for Playing and Recording Wave Files

Related

How do I make PlaySound load only some parts of the song C++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a 424 mb wav file, which I want to play, but it takes a lot of time to load, and it uses 425.6 mb of ram. Way too much ram for a dos format program. I want to load only a part of the song, then when it's almost at the final, load the second part, when the second part is played, remove from ram the first part, and etc. For this I should use 50 parts.
Here is the line of code:
PlaySound("../music/main.wav", NULL, SND_FILENAME|SND_LOOP|SND_ASYNC);
I mention that I need to run this in background, while the other commands do their roles.
PlaySound is a fairly high-level function, so it's tricky to get behavior like this. In particular, you will likely experience small silent gaps between playing back the different parts. So the best solution would be to go to a lower-level API that allows more sophisticated managing of sound playback buffers. OpenAL is a good library for doing this, the modern Windows native solution is WASAPI, which unfortunately is quite complicated to use.
With PlaySound itself, first adjust your program to load the .wav file to memory and then use SND_MEMORY for playing it from memory (example).
Now, instead of loading the whole .wav file at once, you just load the header and as many soundframes as fill your buffer. You then create your own .wav header for just those loaded samples and put it all in a contiguous buffer. You basically build your own, smaller .wav file in memory. Then you call PlaySound(..., SND_MEMORY) on that buffer. Rinse and repeat for the remaining samples from the original file.
Note that you will need your own .wav file format parser for this, but the file format is not that complicated, so hopefully this should not be too much of an issue.

How to create an avi file from scratch? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
My task is to create an avi file by saving n number of frames in c++ .
There are many inbuilt function which can be used to create .avi file as given in below link .
https://learn.microsoft.com/en-us/windows/desktop/multimedia/avifile-reference
Using them we can create our own avifile , one such example.is
http://www.wischik.com/lu/programmer/avi_utils.html
But i want to create it without using Windows.h and vfw.h as they are very extensive.
So i need to make my own function of avifilewrite , appendframes etc
But i can't find any reference link on internet .
Can anyone please explain how can i build avifile without using Windows.h and vfw.h .
Thank you ,
How to create an ... file ...?
You can use the standard file stream API to create a file. To write a binary file, you'll need to use an unformatted output function such as std::ofstream::write().
... an avi file from scratch?
The AVI format is specified by Microsoft: https://learn.microsoft.com/en-us/windows/desktop/directshow/avi-riff-file-reference
However, you can save a lot of effort by using an existing API.

How do I open and display a file with any file extension in C++? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I'm doing a program where I have to read information from a file and it can be a file with any extension. Do you know any way in C++ to read and display the information from a file different than the .txt extension?
There is actually no real difference that would be made by a file extension, so you can - in theory - open any file you want, for example by using std::ifstream. However, files that are not using a human-readable encoding (like txt/json/... files), you propably want to open it in binary mode (you can specify this to std::ifstream).
However, if you actually want some usefull information of some specific, not human readable file (like for example the dimensions of a images saved as a png file), you need way more detailled code. To read, for example, information from an png file, you have to open it in binary mode using std::ifstream, and then interpret the read bytes yourself to get any usefull information out of it. So you actually have to know how the specific file format you want to read is encoded, and need to have (or to implement yourself) a decoder for that specific file format.

How can I analyze file and detect if the file is in H.264 video format? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I write software C/C++ to recover deleted files, and I need to identify files according to their binary content, so my question is there a simple way to know if a particular file is H.264 format video? is H.264 has an signature?
I saw the code of FFMPEG here, but can it help me, how?
For those who encounter this question but are looking for a cli solution you can use ffprobe:
ffprobe -loglevel error -select_streams v -show_entries stream=codec_name -of default=nw=1:nk=1 input.mkv
Outputs:
h264
The problem is that H.264 is not a file format, it is a video compression standard, and as such it can be found in multiple file formats. You can have a .f4v encoded with H.264 as much as you can have .mp4 with H.264.
So, how do you solve your issue? Well, I strongly advise you to use a library that does that for you. libavformat, for example, should do the trick (check the AVStream and AVFormatContext structures, and the avformat_open_input function).
Now, if you absolutely want to do it without libraries, you can check out the documentation for each video container format that supports H.264 to see how to retrieve the encoding information of the video stream, but expect this to take you at least a month or two.
If you want to use FFmpeg - avformat_find_stream_info() should help you. An there is an example.

How to parse RTP H264 packet using FFMpeg [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am new to this forum,
i hope someone can help me with my problem.
I need to convert RTP H264 packets using FFMpeg to BMP files, i have achieved the following until now :
-Reading H264 file and convert it to BMP files using FFMpeg.
-Receiving raw RTP H264 packets.
I would really appreciate if someone can help me decode RTP H264 packets using FFMpeg,
i have done lots of searchs over the internet, and found the following solutions:
libavformat using rtp_h264.c, i could not download the library anywhere, although the file is there, but no way to use it without downloading the library, can someone please provide a download link and an example if possible?
live555 using H264VideoRTPSource, after downloading the library, i did not understand how to use this code, should i instantiate the class? or inhert it? is there an example over the internet on using H264VideoRTPSource?
Is there any other way to do it WITHOUT reading all the standards (RFC3984 and RFC6184)
Thank you.