Hello, I'm trying to make a static class that will be used to write a wav file. It would have one variable, representing the data input, that can be set, and one public method that would be called to write the file.
The WriteFile class(WriteFile.Data and WriteFile.writefile() ) is supposed to take a byte[] and make a .wav(something.wav) file out of it. In the Main I take a song (Tvojneko.mp3) and read it into a byte[] (buffer). And that is what's supposed to be played and written into something.wav. But instead, what's played and written into something.wav is some noise.
static void Main(string[] args)
{
try
{
FileStream fs = File.OpenRead("Tvojneko.mp3");
// get the legth of the file
int length = (int)fs.Length;
// create the buffer which will keep the file in memory
byte[] buffer = new byte[length];
// read the file into the buffer
fs.Read(buffer, 0, length);
// buffer is filled, file can be closed
fs.Close();
WriteFile.Data = buffer;
WriteFile.writefile();
Console.ReadKey();
}
catch
{
Console.ReadLine();
}
}
static class WriteFile
{
static byte[] data;
static public byte[] Data
{
get { return data; }
set { data = value; }
}
public static void writefile()
{
try
{
if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero))
{
STREAMPROC streamcreate = new STREAMPROC(WaveformProc1);
int stream = Bass.BASS_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT, streamcreate, IntPtr.Zero);
BassEnc.BASS_Encode_Start(stream, "something.wav", BASSEncode.BASS_ENCODE_PCM, null, IntPtr.Zero);
Bass.BASS_ChannelPlay(stream, false);
Console.ReadKey();
Bass.BASS_StreamFree(stream);
Bass.BASS_Free();
}
}
catch
{
Console.ReadLine();
}
}
private static int WaveformProc1(int handle, IntPtr buffer, int length, IntPtr user)
{
int waveCalculated = length;
Marshal.Copy(data, 0, buffer, length);
return waveCalculated;
}
}
I'm sure Tvojneko.mp3 is real music not some noise. I guess you can ignore the try... catch blocks. Yeah, I know I have excessive Console.ReadKey()'s.
It doesn't show any error message when I run the program. It all seems to work perfectly except for the fact that it gives noise instead of Tvojneko.mp3.