Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
I want to provide save file dialog box to save wav file. It perfectly works with text file, but what do I have to do for .wav file?
My code is:
C#
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();

saveFileDialog1.Filter = "wav (*.wav)|*.wav|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;

if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{           
    if ((myStream = saveFileDialog1.OpenFile()) != null)
    {
        // Code to write the stream goes here.
        myStream.Write(record.wav);
        myStream.Close();
    }
}
mciSendString("save recsound c:\\record.wav", "", 0, 0);
mciSendString("close recsound ", "", 0, 0);
Computer c = new Computer();
c.Audio.Stop();
Posted
Updated 24-Oct-17 6:07am
v2
Comments
Fabio V Silva 17-May-11 7:23am    
Do you get any errors?
BobJanova 17-May-11 8:37am    
The save dialog doesn't actually do anything. It will work the same for any file extension. What are you actually asking?
Albert Holguin 17-May-11 11:20am    
see my solution, I think that's what he's asking...
Mark Salsbery 17-May-11 16:06pm    
LOL yeah that's one way to interpret the question. But the code shows the OP knows how to save a WAV file using MCI....just not sure why it's called with a hard-coded pathname instead of using the pathname chosen by the user through the SaveFileDialog...

What I see is the question needs clarifying! :)
Albert Holguin 17-May-11 16:19pm    
true, didn't read down that far in the question, just saw the mystream.write() and assumed he was trying to write a wav file directly... oops

1 solution

If you have an audio bitstream that you want to play back as WAV file, then you need to add the WAV header to specify what type of audio it is:

http://en.wikipedia.org/wiki/WAV[^]
http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html[^]
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 17-May-11 18:25pm    
Well, based on guesswork... the question got my 1, too bad.
My 5 for this answer.
--SA
Albert Holguin 17-May-11 18:26pm    
it is pretty bad phrasing, don't think anyone really understood the problem... thanks though... :)
Sergey Alexandrovich Kryukov 17-May-11 19:30pm    
Agree. You just provided useful information which can help.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900