I have a Stream of audio data coming from my mic for which I would like to display the current recording volume level. From what I've gathered, I need to store X number of bytes in an array and then I can use that data to process that one sample from the recording. How do I determine what X is, and what do I need to do to get the volume level from that data?
I'm working in C# but even pseudo code would be very helpful
WAV files are amplitude-modulated, so each sample value is the relative volume. Average across time and you get an average volume.
Things to watch out for:
The above only applies to uncompressed LPCM data. WAV files can be compressed, in which case you'd need to implement whatever decoder is needed to get uncompressed data to work with.
WAV files can be both 8-bit or 16-bit
WAV files do have some header info to skip past, the file format is well-documented (https://ccrma.stanford.edu/courses/422/projects/WaveFormat/)
Watch your endians when reading the header
Here's some sample .NET code for reading WAV files:
http://www.codeproject.com/KB/audio-video/WaveEdit.aspx
Related
Thanks in advance ,I am converting rtsp live stream to .wav file using ffmpeg.Its converting good but i want to convert .wav file to byte stream parallely at the time of converting rtsp to .wav file
1)Launch ffmpeg as a Proceas with the option to decode to standard output in the Arguments (usually a '-' at the end of the arguments)
2) Read the standard output from that Process in accordance with the output format being written.
This keeps the output in memory and allows you to consume it just after its been provided to stdout.
See this question for an example commanf of how to get raw audio from ffmpeg.
Can ffmpeg convert audio to raw PCM? If so, how?
You can't expect a player to understand the datastrucutes without the wav headers because the sample size and rate are not defined in a raw pcm stream.
Finally I think you'll see that it's better to output wav format and read the wav format which will contain everything a player needs to playback the audio.
You would them provide wav audio instead of pcm which will work in naudio as well as many other players quite easily.
in my windows phone gaming apps, I have to use lots of sound. Now I have seen that Windows phone does not support mp3 files. So I need to use the wav files. Any mp3 file which is just 500 kb size in mp3 format, when convert that to ".wav" it becomes min 2.5MB. It's actually eating up my apps size and unnecessarily the size of my apps is getting bigger.
Anyone know how can I use the mp3 file? In my solution I have a Asset folder and inside this folder all the ".wav" files are located.
How I am doing this let me write a code
SoundEffect effect;
Iinside constructor-
{
...
var soundFile = "Assets/Jump.wav";
Stream stream = TitleContainer.OpenStream(soundFile);
effect = SoundEffect.FromStream(stream);
And in the code
effect.Play();
Is there any better approach. In some thread I come to know that doing this is not a better way coding as it creates object and used up the system space. Please suggest what to do, how do I add mp3 files and write better code for working with sound files.
you can use BackgroundAudioPlayer to play your wav and mp3 files. SoundEffect class cannot play mp3 data
Go through this it's an entire app on it's own.
Background Audio WP
To use an MP3 file you would have to decode the MP3 into PCM in memory, and use that resulting stream in the SoundEffect.FromStream method.
Another thing you could try is encoding the wav files as ADPCM. This usually compresses the wave file at ratio of 4:1. If you can't use the stream directly, decoding of ADPCM is much more straightforward than decoding an mp3 file.
And one more thing you could try to save space is converting the uncompressed wave files into mono, and a lower sampling rate. You can perform listening tests on the sounds after the conversion to make sure that the loss in quality is acceptable or not.
I have a scenario where I have to play certain segment from multiple video files. When I am trying to achieve it the complete video gets buffered into my temp folder. Because the files that I am using are very large files(> 500MB), it is taking time to buffer and during buffering playback is not smooth. Since I only have to play a small segment from the video, is it possible to buffer only the specified segment and not the complete file?
It would be great if you could tell me how I could save a byte[] to a wav file. Sometimes I need to set different samplerate, number of bits and channels.
Thanks for your help.
You have to set up the wav header data which contains info about sample rate, file size, sample size, stereo or mono etc. Then write the actual audio data.
Then you just have to write it out as a binary file with '.wav' file extension.
I know of many utilities that can tell me the bitrate of an MP3 file, but I've never seen one that can tell me whether or not the MP3 file is VBR (variable bit rate - the bit rate fluctuates within the file) or a CBR (constant bit rate - the bit rate stays the same within the file). My guess is that most programs aren't interested in finding this out since it involves analyzing the file somewhat to see if the bitrate changes, which takes away from speed.
So, in lieu of finding a utility, I'd like to write one - so how could I programmatically determine whether or not an MP3 file is VBR or CBR? I have about 15,000 files to go through to find this out for, so I need to automate the process.
MP3 files are essentially build of so called frames. Each frame has a small header that stores information about the frame. The header also stores which bitrate was used for the frame. In CBR files, all frames use the same bitrate and therefore every header has the same bitrate information.
To detect if a file uses VBR, you have to go through every frame of the file, look at the header and check if the bitrate field changes. If it does, its an VBR MP3.
A full description of the MP3 format is here: http://www.mpgedit.org/mpgedit/mpeg_format/mpeghdr.htm
Check this MP3Header Class, it has a method that tells you if the mp3 file is VBR, and all the mp3 header information...
...
boolVBitRate = LoadVBRHeader(bytVBitRate);
...