sampling wav files in to get amplitude at a specific time - audio

i am wondering if there is any way to cycle through a .wav file to get the amplitude/DB of a specific point in the wav file. i am reading it into a byte array now but that has no help to me from what i can see.
i am using this in conjunction with some hardware i have developed that encodes light data into binary and outputs audio. i wont get into the details but i need to be able to do this in c# or c++. i cant find any info on this anywhere. i have never programmed anything relating to audio so excuse me if this is a very easy thing.
i dont have anything started since this is the starting point so if anybody can point me to some functions, libraries, or methods to being able to collect the amplitude of the wave at a specific time in the file, i would greatly appreciate it.
i hope this is enough info, and thank you in advance if you are kind enough to help.

It is possible and it is done in a straightforward way: the file with PCM audio contains one value for every channel, for every (1/sample-rate) of second.
The values however might vary: 8-bit, 16-bit, single precision floating point values. You certainly have to take this into account and this is the reason you cannot take the bytes from byte array directly.
The .WAV file also has a header preceding the actual payload.

Related

Reading and understanding a raw audio file(specifically MP3)

I am trying to understand what the raw data from an audio file looks like and how to get that data. I want to take the data and analyze it and see if I am able to make a program that can recognize patterns in a song such as in a hip hop song, finding the same beat in a chorus. In my head I think this could be a doable task if the data is in an integer form.
I've looked up many tutorials for this but all the tutorials use other libraries or don't explain it in a way I understand(more than likely the source of my issue).
I am wondering if there is someone out there that can help me understand a few things.
1). In an MP3 file, what is actually being stored in the file. Is it an integer that tells the radio/amp/audioPlayer a frequency, another integer for amplitude, etc...(over simplified because I don't know what other data is stored in an audio file).
2). If it is stored in an integer format, is there a way to read the integers and analyze it. If it is not stored in an integer format, how is it stored, and is there a way to convert it to an integer format?
3). In visual representations of an audio files like this one, it seems more clear what is what. It seems like the frequency is where on the circle the audio is represented, and the amplitude is how high it jumps. Is this right? Or does it just appear that way and I am understanding it incorrectly.
4). Is this task harder than I think it is? Considering I haven't found any good explanations or tutorials on how to do so, I am skeptical on how easy this would be.
(Sorry if this was poorly phrased, first question on stack and I am just illiterate :^)

How to decrease pitch of audio file in nodejs server side?

I have a .MP3 file stored on my server, and I'd like to modify it to be a bit lower in pitch. I know this can be achieved by increasing the length of the audio, however, I don't know of any libraries in node that can do this.
I've tried using the node web audio api, and soundbank-pitch-shift, but the former doesn't seem to have the capabilities of pitch shifting (AFAIK), and the latter seems designed toward client
I need the solution within the realm of node ONLY- that means no external programs, etc., and it needs to be automated as well, so I can't manually pitch shift.
An ideal solution would be a function that takes a file/filepath as an input, and then creates (or overwrites) another MP3 file but with the pitch shifted by x amount, but really, any solution that produces something with a lower pitch than the original, works.
I'm totally lost here. Please help.
An audio file is basically a list of numbers. Those numbers are read one at a time at a particular speed called the 'sample rate'. The sample rate is otherwise defined as the number of audio samples read every second e.g. if an audio files sample rate is 44100, then there are 44100 samples (or numbers) read every second.
If you are with me so far, the simplest way to lower the pitch of an audio file is to play the file back at a lower sample rate (which is normally fixed in place). In most cases you wont be able to do this, so you need to achieve the same effect by resampling the file i.e adding new samples to the file in between the old samples to make it literally longer. For this you would need to understand interpolation.
The drawback to this technique in either case is that the sound will also play back at a slower speed, as well as at a lower pitch. If it is a problem that the sound has slowed down as well as lowered in pitch as a result of your processing, then you will also have to use a timestretching algorithm to fix the playback speed.
You may also have problems doing this using MP3 files. In this case you may have to uncompress the data in the MP3 file before you can operate on it in such a way that changes the pitch of the file. WAV files are more ideal in audio processing. In any case, you essentially need to turn the file into a list of floating point numbers, and change those numbers to be effectively read back at a slower rate.
Other methods of pitch shifting would probably need to involve the use of ffts, and would be a more complicated affair to say the least.
I am not familiar with nodejs I'm afraid.
I managed to get it working with help from Ollie M's answer and node-lame.
I hadn't known previously that sample rate could affect the speed, but thanks to Ollie, suddenly this problem became a lot more simple.
Using node-lame, all I did was take one of the examples (mp32wav.js), and make it so that I change the parameter sampleRate of the format object, so that it is lower than the base sample rate, which in my application was always a static 24,000. I could also make it dynamic since node-lame can grab the parameters of the input file in the format object.
Ollie, however perfectly describes the drawback with this method
The drawback to this technique in either case is that the sound will
also play back at a slower speed, as well as at a lower pitch. If it
is a problem that the sound has slowed down as well as lowered in
pitch as a result of your processing, then you will also have to use a
timestretching algorithm to fix the playback speed.
I don't have a particular need to implement a time stretching algorithm at the moment (thankfully, because that's a whole other can of worms), since I have the ability to change the initial speed of the file, but others may in the future.
See https://www.npmjs.com/package/audio-decode, https://github.com/audiojs/audio-buffer, and related linked at bottom of audio-buffer readme.

Converting Audio From Unknown Format

I would like to create a utility in either PHP or Perl to convert an audio file created by the Nortel's Callpilot voice mail system into a wave file. The problem is that the format, which has the .vbk file extension, is unknown to virtually any audio player. To date, I have not found one that will play a .vbk file. I've looked at audio file conversion libraries in CPAN and tried many of them, they don't recognize the file. I was not successful with PHP's audio formats manipulation either. Nortel does provide a converter, however, it does not suite my needs. I would like to have this run via cron on a CentOS system. I don't know how to reverse engineer this format. There seems to be just scraps of info on this format on the web. This page indicates that it is "based on the H.232 format":
https://www.odesk.com/o/jobs/job/Reverse-Engineer-Nortel-VBK-Audio-Format_~~f501f11679f3f6bb/
I know this is a very old thread, but I've recently been looking into converting Nortel's vbk format as well. Importing the vbk files into Audacity with raw data option, Encoding: U-Law, Byte order: little-endian, Channels: 1 Channel (Mono), Sample rate: 8000 Hz. Not sure if they have multiple formats for their vbk files, but mine were from a BCM50 phone system.
Well, this is the joy of closed proprietary systems. But there is a chance they could play nice. Try to contact Callpilot and see if they'll give you the format specs. It's worth a shot.
As for reverse engineering, you need to be able to generate known content. Like a constant tone at 60Hz for exactly 1 second. Then at 50Hz. Then at 10 seconds. Compare them. Isolate the data from the metadata. There is going to be compression involved, so try a handful of common compression schemes, maybe research into Nortel's practices will probably tell you more. If you can feed that into a player and get a tone back out, you're on your way.
There's probably more informed and structured ways to go about reverse engineering, but from my experience it's a lot of trial and error.

basic wav data chunk

I have a question about the basic wav file data chunk.
I know that each 2 bytes in the data chunk section represent mono sound and left and right channel is alternately stored, but I still have no idea how to understand the 2 byte value.
Is it high and low?
value 0000 => lowest?
value FFFF => highest?
value 8FFF => no sound?
If so, when I want to reduce volume 50%, is all I have to do just classfy low and high
and divive by 2?
WAV files can contain samples at different bit depths and encodings, but one of the most commonly used is 16 bit PCM. With 16 bit PCM data in a WAV file, each two bytes should be interpreted as a short (i.e. a signed, two-byte number). In WAV files, the samples are always "little-endian". If you tag your question with a language, someone might be able to provide some simple sample code. In C/C++, you would cast your array of data read from the file into a (short *), allowing you to easily access each sample.
To answer the second part of your question, yes you can reduce the volume by halving the value of each sample.
Your understanding seems fine. The only thing I can think to say is one byte will be a most significant byte, and one will be least significant. Other than that, you seem spot on.
And your question is fine (In my opinion anyway!) Although more useful answers might be gotten if you were to ask a specific programming question, but I can see how that might not be possible.

Estimating the time-position in an audio using data?

I am wondering on how to estimate where I am currently in an audio with regards to time, by using the data.
For example, I read data by byte[8192] blocks. How can I know how much byte[8192] is equivalent to in time?
If this is some sort of raw-ish encoding, like PCM, this is simple. The length in time is a function of the sample rate, bit depth, and number of channels. 30 seconds of 16-bit audio at 44.1kHz in mono is 2.5MB. However, you also need to factor in headers and container format crapola. WAV files for example can have a lot of other stuff in them.
Compressed formats are much more tricky. You can never be sure where you are without playing through the file to get to where you are. Of course you can always guesstimate based on the percentage of the file length, if that is good enough for your case.
I think this is not what he was asking.
First you have to tell us what kind of data you are using. WAV? MP3? Usually without knowing where that block came from - so you know if you have some kind of frame information and where to find it - you are not able to determine that block's position.
If you have the full stream and this data then you can do a search

Resources