Quantcast
Channel: naudio Work Item Rss Feed
Viewing all articles
Browse latest Browse all 738

Commented Unassigned: raw file play very fast using NAudio Library [16425]

$
0
0
i m successfully write raw data to serial port with NAudio Library here is my code,

Dim rawStream = File.OpenRead("c:\myfile.raw")
Dim waveFormat = New NAudio.Wave.WaveFormat(8000, 16, 1)

Dim rawSource = New RawSourceWaveStream(rawStream, waveFormat)

Dim buffer As Byte() = New Byte(rawSource.Length) {}

Dim n As Integer = 2
For x As Integer = 0 To buffer.Length - n - 1 Step n
Application.DoEvents()
Dim bytesRead As Integer = rawSource.Read(buffer, 0, x)
If bytesRead > 0 Then

SP1.Write(buffer, 0, bytesRead)

End If

Thread.Sleep(40)

Next
this code works fine only problem i m able to hear raw file to my mobile but play raw file very fast i use thread.sleep and application.DoEvents() but it still play very fast please guide me how to write data with normal speed
Comments: to change the sample rate, you need to resample. To change the bit depth, you need to examine each sample and convert it to the new range. To change the number of channels there are lots of techniques. If you have a Pluralsight account, I'd recommend watching module 4 of my [Audio Programming with NAudio course](http://pluralsight.com/training/Courses/TableOfContents/audio-programming-naudio).

Viewing all articles
Browse latest Browse all 738

Trending Articles