Hi
I have made a program that reads a raw pcm file and plays it.
The function itself is working (finally) but when i play the sound a lot of noise is playing along. Writing the array to harddrive before playing proves that it's the reading to the array that is the problem, right? (check code)
there is no problem with the orginal wav file with header because the directsound buffer reads the header itself weather I like it or not.
The reason why i deleted the wav header is because the intention of the finished program will be reading pcm files with a different header. (not there yet)
Imports Microsoft.DirectX.DirectSound
Imports System.IO
Public Class Form2
Private device As New Device
Private buffer As SecondaryBuffer
Private bufdes As BufferDescription
Private format As WaveFormat
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenFileDialog1.ShowDialog() ' opening the raw pcm data
Dim file As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)
Dim read As New BinaryReader(file)
Dim data(470401) As Byte
device.SetCooperativeLevel(Me.Handle, CooperativeLevel.Priority)
'give it a wav header from the orginal so it can be played in external player later
Dim file0 As New FileStream("C:\Users\Johan\Desktop\test\Heavy Jungle Amen 28936.wav", FileMode.Open, FileAccess.Read)
Dim read0 As New BinaryReader(file0)
Dim sss(43) As Byte
For t = 0 To 43
sss(t) = read0.ReadByte
Next
My.Computer.FileSystem.WriteAllBytes("C:\CustomerData", sss, True)
read0.Close()
'actual reading of the raw pcm, is this where it mess up?
For k = 0 To 470401
data(k) = read.ReadByte
Next
My.Computer.FileSystem.WriteAllBytes("C:\CustomerData", data, True)
'format of the raw pcm file
format = New WaveFormat()
format.BitsPerSample = 16
format.Channels = 1
format.BlockAlign = 2
format.FormatTag = WaveFormatTag.Pcm
format.SamplesPerSecond = 44100
format.AverageBytesPerSecond = format.SamplesPerSecond * format.BlockAlign()
'buffer
bufdes = New BufferDescription(format)
bufdes.BufferBytes = 470401
buffer = New Microsoft.DirectX.DirectSound.SecondaryBuffer(bufdes, device)
buffer.Write(0, data, LockFlag.EntireBuffer)
read.Close()
file.Close()
buffer.Play(0, BufferPlayFlags.Default)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
buffer.Stop()
Me.Close()
End Sub
End Class
The output result is attached as a wav file. Orginal first, then the noisy one from my app and then I played the noisy with the orginal but with inverted peaks wich makes you hear the noise only. Play in wmplayer so you can see that the noise is peaks between zero and max
Now to my question: What is wrong and what can i do to fix it ? :)