Tag Archives: Convert

How to convert pcm files to wav in Linux

Over the weekend I had to make a recording on my Android phone. I used the app Virtual Recorder  thinking I’d be able to just share the file afterwards but Virtual Recorder creates pcm files not typical mp3 files. I sent the file over to my Linux laptop, running Linux mint, to convert it.

Initially I had some trouble getting the conversion to work. Here are the steps I took.

Open a terminal window and navigate to the where the pcm file is. If you don’t know how to do this use the GUI file explorer to navigate to the directory where the pcm file is and then right click on white space and click on the option to open a terminal window. The terminal will open already set to run against the directory the pcm file is located in.

If you try to run any of the commands below and you don’t have ffmpeg installed you will be notified ffmpeg needs to be installed and it will give you the command to type in and run to install it.

If you want to convert a Virtual Recorder file specially you can use this terminal command below changing the file names to what you need.

ffmpeg -f s16le -ar 11250 -ac 2 -i YouInputFileName.pcm -ar 44100 -ac 2 YouOutputFileName.wav

Converting pcm files created by other applications may have varying results due to the sample rate of the source file. For example if you replace 11250 with 22500 as in the command below your output file pitch and speed will be increased. So you may need to play around with sample rates to get the output right.

ffmpeg -f s16le -ar 22500 -ac 2 -i YouInputFileName.pcm -ar 44100 -ac 2 YouOutputFileName.wav

How to get the hour from a datetime string (T-SQL)

Often data is entered into the database as a string (varchar), when a more appropriate data type should have been applied.

Here’s a snippet of T-SQL for dealing with datetime data, stored as varchar, when what you really need is the hour. 

DECLARE @DateTime AS VARCHAR(25)

-- GET THE CURRENT DATETIME AND CONVERT INTO A STRING
SET @DateTime = (
		SELECT CONVERT(VARCHAR(25), GETDATE(), 120)
		)

--PRINT @DateTime
-- GET HOUR FROM DATETIME AS A STRING
SELECT DATEPART(HOUR, CONVERT(DATETIME, CONVERT(VARCHAR(13), @DateTime, 120) + ':00')) AS ConvertedHour

 

Why would data be stored as a varchar instead of using the appropriate data type in the first place?

The most common reason might be that XML files have been loaded without any data type conversions being applied, i.e. dates have been entered as strings along with everything else.

Why would you need this code?

Should you be confronted with data in this raw string form you would be unable to apply a clause regarding a specific hour. Ideally there should be some sort of staging table to convert the fields into the appropriate data types but if you simply wanted to apply some clauses to select specific data, which will be outputted to an excel file for example, that additional effort may be unnecessary.