Scott Hanselman

That Sinking Feeling and Repairing a Corrupt WAV File

November 09, 2007 Comment on this post [15] Posted in Podcast | Tools
Sponsored By

I've been up on campus talking at the PNPSummit and in my spare time recording podcasts with interesting people. A particularly cool show that'll be coming up very soon ran pretty long, and filled up my 1 gig CF Card. I had to transfer that now "part 1" off that disk and keep recording "part 2." My editor Lawrence will then stitch the two files together and make the transition sound natural.

I uploaded the two parts and went along with my day. However, I got a call from the guys saying that the file wouldn't open and that it might be corrupt. Yikes. This has happened before, but it's usually just a transmission error. I opened the original file and....crap!

Windows Media Player

It won't open. Hm. Well, I figured that some WAV file programs are more strict than others. Perhaps I could open it in another program.

Well, shoot. It's not opening in any programs. That's not cool. I tried WAV Saver and while I see on the net that lots of folks have had success with it, for me it crashed as I clicked repair. Apparently my file was messed up in a special way.

As I Googled around for answers and the program "GoldWave" kept coming up. It's apparently very well thought of.

When I dragged the corrupt file into GoldWave I got this friendly dialog:

File Format

This is cool because here I can get to the RAW PCM data. I just needed to tell the system what the original recording was in. Since we're on Intel, we're little endian. The recording was in stereo, at 44.1kHz and was 24-bit. Also, anything over 12-bit is usually signed. So, I'm feeling good at this point. However:

GoldWave - [mel sampat part 2 - ORIGINAL.wav]

...I ended up with a screen full of white noise. Bummer. At this point, I'm getting close to giving up. Then, on a whim, I remembered that you can click the tiny down arrow next to the Open button in the Visual Studio Open File Dialog.

image

I selected Binary Editor and got this:

mel sampat part 2 - ORIGINAL.wav - Microsoft Visual Studio

Now, I'm not an expert on the WAV file format, but I understand it's just a header and some RAW PCM data. It's supposed to be pretty simple, but ALL ZEROS is simpler than even I expected. :)

So, I opened up Part 1, the valid WAV file, and looked at its header. Then I selected it on a word boundary (guessing) and copied it to the clipboard. Then I flipped over to the broken WAV and pasted in the first 48 bytes of the header of the working file, up to and including the "data" chunk.

mel sampat part 1.wav - Microsoft Visual Studio (2)

Then, I saved the file with a new name and opened it in GoldWave.

GoldWave

Amazing, it worked! Notice the correct WAV format listed in the status bar. This trick worked, because I stole the WAV Header from a file that was encoded in the identical way. It wouldn't have worked with different files. There was a small warning from GoldWave that the header's length differed from reality, but this was fixed by File|Save As with a new filename.

Miracle of miracles. I thought the show was ruined. This technique was lucky because apparently only the header was missing and I had a header available with the same format. I hope this helps someone with the same problem.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
November 09, 2007 10:55
Wow, nice work Sherlock!
November 09, 2007 13:36
For a second, I thought I was reading MacGyver's blog!
November 09, 2007 14:51
Good work!
November 09, 2007 18:30
Hey Now Scott,
This is a good example of you you can make things work. I don't think I"ll have to do what you did anytime soon, but thx for the info.
Hanselminutes Fan,
Catto
November 09, 2007 18:30
LOL @ Dave

Seriously, Scott you need to get out more ;)

I think I would of gave up after trying to open the file in a few different programs...nice work.
November 09, 2007 19:19
Definitely Macgyver!
November 09, 2007 19:45
I once did that AVI files. Ofcourse the code codecs and the formats need to be the same.

I sometimes remove headers of the personal files to intentionally corrupt them which I can recover later. :)
November 09, 2007 20:57
Congratulations on successfully debugging your issue there. I expect I wouldn't have gone to these lengths, but I'd like to think that if I had, that I would have been capable of figuring it out.

Also, I'll second the recommendation of GoldWave. We used it in college to mess around with various types of sound files in our Digital Signal processing course. And I still use its filtering capabilities from time to time to clean up noise in recordings I make with my hand-held digital voice recorder. Very capable, full-featured app.
November 09, 2007 21:24
Nice work. I did simpler work like renaming an extension to get a file to load.

When you opened the good wav file in Goldwave, doesn't it tell you what kind of wav it is and use that info to fix the bad file? You were lucky with this simple wav file. If it were a file where there was no gap between the header and data or there's more info than a simple header, it would have been more of a trial and error intense work.
November 09, 2007 23:56
PCM wave? Wow that must've been a large file to upload.

If you're looking for a recording app, I can't recommend Adobe's Audition enough. It has crash recovery. Made for long, live recordings. Can save to MP3.

It's about $150, but should pay for itself easily if you do lots of podcasts.
November 12, 2007 10:59
Try VLC (http://www.videolan.org/vlc/)
You no longer need to do any trickery, unless u really want to do some hacking ;0)

November 12, 2007 19:33
I think Sony SoundForge would have corrected this for you. It's an amazing program. It's like the Adobe Photoshop counterpart for working with audio.
November 13, 2007 9:15
Nice bit of digital wizardry. One thing - what I see from the pictures is that, after the header, wav is basically just a string of 0's :-p
December 04, 2007 22:29
Very Good Work , you have saved my life with this very simple trick..
December 08, 2007 0:46
Scott!

I was having the same trouble as you and I was giving up too.
Fortunatly I found your solution! I got a binary editor and a good header file.
After some try and errors, the file is perfect!

Thank you very much.

Paulo S. Rosa

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.