Converting From 4-bit RAW Audio to WAV (or another output format) - audio

Okay, so I've got some .raw files from an old game (Zork Nemesis) and determined that they're audio files, however I'm having trouble converting them into something meaningful.
With a bit of trial and error in Audacity I've found that I can listen to a still noisy version of the audio using raw file input settings of 8-bit signed PCM in stereo with a sample rate of 22050hz. However, my suspicion is that the files may in fact be encoded in 4-bits with a sample rate of 44100hz, but I'm having trouble finding a tool that can handle this.
What I'm looking for is either a tool that can handle 4-bit raw formats, or even a tool that can determine (or guess at) the format of a given .raw file, so I know for sure what I'm dealing with (as I'm just going by trial and error so far).
I've tried sox, but I'm most likely doing something wrong as it complains of an unsupported size:
sox -r 44100 -e signed -b 4 -c 2 in.raw out.wav
I was also going to try ffmpeg, but I can't find the appropriate format/codec to set.
In case it gives any further clues; I've tried various combinations of settings, increasing sample size while decreasing sample rate increases the (white-)noise, and even 8-bit is still noisy, which is why I'm thinking 4-bit. I've tried signed and unsigned, which strangely doesn't seem to make much of a difference

sox expects .raw input with 8-bit or higher encoding. So if you run
sox -r 44100 -e signed -b 8 -c 2 in.raw out.wav
it should work just fine. So either the file is actually 8(+)-bit encoded or you need find a converter which accepts this form of input.

Related

File information of .raw audio files using terminal in linux

How to get file information like sampling rate, bit rate etc of .raw audio files using terminal in linux? Soxi works for .wav files but it isn't working for .raw.
If your life depended on discovering an answer you could make some assumption to tease apart the unknowns ... however there is no automated way since the missing header would give you the easy answers ...
The audio analysis tool called audacity allows you to open up a RAW file, make some guesses and play the track
http://www.audacityteam.org
In audacity goto File -> Import -> Raw Data...
Above settings are typical for audio ripped from a CD ... toy with trying stereo vs mono for starters.
Those picklist widgets give you wiggle room to discover the format of your PCM audio given that the source audio is something when properly rendered is recognizable ... would be harder if the actual audio was noise
However if you need a programmatic method then rolling your own solution to ask those same questions which appear in above window is possible ... is that what you need or will audacity work for you ? We can go down the road of writing code to play off the unknowns mentioned in #Frank Lauterwald's comment
To kick start discovering this information programmatically, if the binary raw audio is 16 bit then each audio sample (point on the audio curve) will consume two bytes of your PCM file. For mono audio then the following two bytes would be your next sample, however if its stereo then these two following bytes would be the sample from the other channel. If more than two channels then just repeat. Typical audio is little endian. Sampling rate is important when rendering the audio, not when programmatically parsing raw bytes. One approach would be to create an output file with a WAV header followed by your source PCM data. Populate the header with answers from your guesswork. This way you could listen to this output file to help confirm your guesses.
Here is a sample 500k mono PCM audio file signed 16 bit which can be imported into audacity or used as input to rolling your own identification code
The_Constructus_Corporation_Long_Street-ycexQvMy03k_excerpt_mono.pcm

How to change pitch and tempo together, reliably with ffmpeg

I know how to change tempo with atempo, but the audio file becomes distorted a bit, and I can't find a reliable way to change pitch. (say, increase tempo and pitch together 140%)
Sox has a speed option, but truncates the volume AND isn't as widely available as ffmpeg. mplayer has a speed option which works perfectly, but I can't output without additional libraries.
I seem to understand ffmpeg doesn't have a way to change pitch (maybe it does recently?) but is there a way to change frequency or some other flags to emulate changing pitch? Looked quite far and can't find a decent solution.
Edit: asetrate:48k*1.4 (assuming originally 48k) doesn't seem to work, still distortion and pitch doesn't really change much.
Edit2: https://superuser.com/a/1076762 this answer sort of works, but the quality is so much lower than sox speed 1.4 option
ffmpeg -i <input file name> -filter:a "asetrate=<new frequency>" -y <output file name> seems to be working for me. I checked the properties of both input and output files with ffprobe and there doesn't seem to be any differences that could affect its quality. Although it's true that I've run it a few times and the resulting file on some of those had some artifacts, even if the line of code was the same, so it may be caused by some ffmpeg bug; try to run it again if you aren't satisfied with the quality.
As of 2022 (though contributed in 2015), FFmpeg has a rubberband filter that works out of the box without any aforementioned ugly, allegedly slow and poor quality and unintuitive workarounds.
To change the pitch using the rubber band filter, you will have to specify the pitch using the frequency ratio of a semi-tone. This is based on using the formula (2^x/12), where x represents the number of semitones you would like to transpose.
For example, to transpose up by one semitone you would use the following command:
ffmpeg -i my.mp3 -filter:a "rubberband=pitch=1.059463094352953" -acodec copy my-up.mp3
To transpose down, simply use a negative number for x.
To alter both properties simultaneously, specify tempo and pitch values. The tempo value is specified as a multiple of the original speed.
The following command transposes down by one semitone and bumps the speed up 4x:
ffmpeg -i slow.mp3 -filter:a "rubberband=pitch=0.9438743126816935, rubberband=tempo=4" -acodec copy fast.mp3
Quality degradation is imperceptible unless measured statistically.

Storing multiple channels with different encoding/sampling in a single WAV file

I have two RTP streams (one for each call direction) that I want to mix in a single WAV file.
The problem is that the two streams may use different codecs (and therefore different sampling frequency, encoding, etc).
Is it possible to store the two RTP streams in a WAV file using two channels (i.e. stereo)? Asked differently, is there a way to store multiple channels with different encoding, sampling frequency, etc?
Structure of the WAV file assumes that sampling rate and channel bitness is the same for all channels of the feed. Encoding applies the entire feed (with many encodings/formats/codecs you cannot separate a channel without decoding the feed).
You will need to store feeds in separate files, or you need a file format which supports multiple audio tracks (MP4, MKV for example) though they all have their own restrictions.
As Roman R. mentioned it is not immediate. You will need to take an extra step in between to convert whatever you have on your RTP stream into a proper WAV file. The idea is to use a software like ffmpeg to do so:
2 × mono → stereo: ffmpeg -i left.mp3 -i right.mp3 -ac 2 output.wav
After that you could try something of the flavor (untested):
ffmpeg -i rtp://leftrtp -i rtp://rightrtp -ac 2 output.wav
Most likely you will need to tune the codec settings to make it work as you want. You can Google around and find some infos on the subject or read the ffmpeg doc.

.wac to .wav conversion

I've been asked to sample some data in a .wac file type. I'm not familiar with this standard and there is very little on the internet with regards to this format. I got given the .wav file but I don't think it was converted correctly, in that there was a none existent of the RIFF header so no .wav reader was able to read it.
Could anyone therefore shed some light into how I could possibly convert the .wac file into a .wav file? Doing some research, I cannot seem to find a converter tool on the internet, and, MatLab does not have a module for reading in .wac data.
NOTE: I've put the tag "game-engine" because according to this website: Here it is used in the infinity game engine.
I've come up with the following solution, however, massive thanks to #jpaari for his input.
Basically, I used sox:
sox -r 44100 -e unsigned -b 8 -c 1 input.raw output.wav
I was able to re-name the file to .raw and this worked. I'm going to update the Sample Rate to what #Aybe posted.
Try this http://www.shsforums.net/topic/39117-ps-gui-v304/
I think Audacity can do it aswell. Also the "unity3d" tag is not quite right.

How do i sample an audio file say .wav , in an 8 bit 8khz parameter

i am not that big on programming and i need to sample an audio file that is recorded via a mobile, i understand that the mobile device records the voice, and there are sample rates and each sample has a 8bit or 16 bit sample size. i need 8 bit sample size in 8khz. the programming environment is lua but that doesnt matter really the basic deal is sampling. Any help would be appreciated.
You need to either set your recording parameters at the time that you record the sound sample to 8 bits # 8 kHz, or, if you can't, or don't have any control over the actual recording process, then you will need to resample the original recording to get it into the format that you need. You can do this off-line with a tool such as SoX, or you can write code that does this on-the-fly. If you give more detail in your question then I can add more specific detail in my answer.
I don't know about lua, but as suggested by Paul R, you can always post-process your audio files using SoX or ffmpeg. On linux, just install ffmpeg :
sudo apt-get install ffmpeg
Then :
ffmpeg -i trenet.wav -ar 8000 trenet-8k.wav
This resamples your audio at 8000 Hz. I did not find how to deal with the bits/sample parameter but you can always tune the bitrate. For documentation :
man ffmpeg

Resources