Scott Hanselman

That Sinking Feeling and Repairing a Corrupt WAV File

November 9, '07 Comments [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. I am a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by ORCS Web
Friday, November 09, 2007 6:55:29 AM UTC
Wow, nice work Sherlock!
Friday, November 09, 2007 9:36:21 AM UTC
For a second, I thought I was reading MacGyver's blog!
Friday, November 09, 2007 10:51:05 AM UTC
Good work!
Friday, November 09, 2007 2:30:01 PM UTC
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
Friday, November 09, 2007 2:30:44 PM UTC
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.
Friday, November 09, 2007 3:19:15 PM UTC
Definitely Macgyver!
GuyIncognito
Friday, November 09, 2007 3:45:26 PM UTC
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. :)
Friday, November 09, 2007 4:57:30 PM UTC
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.
Friday, November 09, 2007 5:24:09 PM UTC
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.
Abdu
Friday, November 09, 2007 7:56:07 PM UTC
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.
Minh
Monday, November 12, 2007 6:59:55 AM UTC
Try VLC (http://www.videolan.org/vlc/)
You no longer need to do any trickery, unless u really want to do some hacking ;0)

dhananjay123
Monday, November 12, 2007 3:33:44 PM UTC
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.
Tuesday, November 13, 2007 5:15:09 AM UTC
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
Tuesday, December 04, 2007 6:29:47 PM UTC
Very Good Work , you have saved my life with this very simple trick..
wbeimar
Friday, December 07, 2007 8:46:40 PM UTC
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
Paulo S. Rosa (Brazil)
Comments are closed.

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